Module: Sylfy::Service::PubChem::REST

Defined in:
lib/sylfy/service/pubchemrest.rb

Constant Summary collapse

@@baseuri =
"http://pubchem.ncbi.nlm.nih.gov/rest/pug"
@@output_type =
[:XML, :ASNT, :ASNB, :JSON, :JSONP, :SDF, :CSV, :PNG, :TXT]
@@main_oper =
[:record, :aids, :sids, :cids]
@@cmp_property =
["MolecularFormula", "MolecularWeight", "CanonicalSMILES", "IsomericSMILES", "InChI", "InChIKey", "IUPACName", "XLogP", "ExactMass", \
"MonoisotopicMass", "TPSA", "Complexity", "Charge", "HBondDonorCount", "HBondAcceptorCount", "RotatableBondCount", "HeavyAtomCount", \
"IsotopeAtomCount", "AtomStereoCount", "DefinedAtomStereoCount", "UndefinedAtomStereoCount", "BondStereoCount", "DefinedBondStereoCount", \
"UndefinedBondStereoCount", "CovalentUnitCount", "Volume3D", "XStericQuadrupole3D", "YStericQuadrupole3D", "ZStericQuadrupole3D", "FeatureCount3D", \
"FeatureAcceptorCount3D", "FeatureDonorCount3D", "FeatureAnionCount3D", "FeatureCationCount3D", "FeatureRingCount3D", "FeatureHydrophobeCount3D", \
"ConformerModelRMSD3D", "EffectiveRotorCount3D", "ConformerCount3D"]
@@xref_ns =
['RegistryID', 'RN', 'PubMedID', 'MMDBID', 'ProteinGI', 'NucleotideGI', 'TaxonomyID', 'MIMID', 'GeneID', 'ProbeID', 'PatentID']
@@xref_oper =
['RegistryID', 'RN', 'PubMedID', 'MMDBID', 'DBURL', 'SBURL', 'ProteinGI', 'NucleotideGI', 'TaxonomyID', 'MIMID', 'GeneID', 'ProbeID', 'PatentID']
@@assay_type =
['all', 'confirmatory', 'doseresponse', 'onhold', 'panel', 'rnai', 'screening', 'summary']

Class Method Summary collapse

Class Method Details

.assay(identifiers, namespace, operation = '', output = :JSON, option = nil) ⇒ Object

Method for setting inchi data member

Parameters:

id

LipidMap id to search

:id, :dataPrimarySource, :xrefs, :relations :inchi, :formula, :smiles, :inchiKey :names



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/sylfy/service/pubchemrest.rb', line 182

def assay(identifiers, namespace, operation = '', output = :JSON, option = nil)
	oper = @@main_oper + [:description]
	ns = [:aid, :listkey]
	
	tmp_operation = ""
	
	if ns.include?(namespace.to_sym)
		namespace = namespace.to_s
	else
		namespace = namespace.split(/\//)
		if namespace[0] == 'type' && @@assay_type.include?(namespace[1])
			namespace = namespace[0..1].join('/')
		elsif namespace[0] == 'sourceall'
			namespace = namespace[0..1].join('/')
		else
			raise ServiceException::ParameterError, "Wrong domain type. Should be #{ns.join(', ')}, \
				type/{#{@@assay_type.join(' | ')}} or sourceall/<source name>"
		end
	end
	
	if oper.include?(operation.to_sym)
		tmp_operation = operation.to_s
	elsif operation.to_s =~ /^targets\/([\w,]+)/ #target_type = {ProteinGI, ProteinName, GeneID, GeneSymbol}
		tmp_operation = operation.to_s
	elsif operation.to_s =~ /^doseresponse\/([\w,]+)/ #doseresponse/sid
		tmp_operation = operation.to_s
	else
		tmp_operation = ""
	end
	
	begin
		return perform("assay/#{namespace}/#{identifiers.to_s}", tmp_operation, output, option)
	rescue OpenURI::HTTPError
		return {}
	end
	
end

.compound(identifiers, namespace, operation = '', output = :JSON, option = nil) ⇒ Object

Method for setting inchi data member

Parameters:

id

LipidMap id to search

:id, :dataPrimarySource, :xrefs, :relations :inchi, :formula, :smiles, :inchiKey :names



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/sylfy/service/pubchemrest.rb', line 134

def compound(identifiers, namespace, operation = '', output = :JSON, option = nil)
	oper = @@main_oper + [:synonyms, :assaysummary, :classification]
	ns = [:cid, :name, :smiles, :inchi, :sdf, :inchikey, :listkey]
	
	tmp_operation = ""
	
	if ns.include?(namespace.to_sym)
		namespace = namespace.to_s
	else
		namespace = namespace.to_s.split(/\//)
		if ['substructure', 'superstructure', 'similarity', 'identity'].include?(namespace[0]) && ['smiles', 'inchi', 'sdf', 'cid'].include?(namespace[1])
			namespace = namespace[0..1].join('/')
		elsif namespace[0] == 'xref' && @@xref_ns.include?(namespace[1])
			namespace = namespace[0..2].join('/')
		else
			raise ServiceException::ParameterError, "Wrong domain type. Should be #{ns.join(', ')}, \
				xref/{#{@@xref_ns.join(' | ')}} or \
				{substructure | superstructure | similarity | identity}/{smiles | inchi | sdf | cid}"
		end
	end
	
	if oper.include?(operation.to_sym)
		tmp_operation = operation.to_s
	else
		operation = operation.to_s.split(/\//)
		if operation[0] == 'property' #&& @@cmp_property.repeated_permutation(n).include?()
			tmp_operation = operation[0..1].join('/')
		elsif operation[0] == 'xrefs' && @@xref_oper.include?(operation[1])
			tmp_operation = operation[0..1].join('/')
		else
			tmp_operation = ""
		end
	end
	
	begin
		return perform("compound/#{namespace}/#{identifiers.to_s}", tmp_operation, output, option)
	rescue OpenURI::HTTPError
		return {}
	end
	
end

.idconv(id) ⇒ Object

Method for setting inchi data member

Parameters:

id

LipidMap id to search

:id, :dataPrimarySource, :xrefs, :relations :inchi, :formula, :smiles, :inchiKey :names



226
227
228
# File 'lib/sylfy/service/pubchemrest.rb', line 226

def idconv(id)
	return JSON.load(compound(id, 'xref/RegistryID', "cids"))["IdentifierList"]["CID"]
end

.perform(input, operation = '', output = :JSON, option = nil) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/sylfy/service/pubchemrest.rb', line 60

def perform(input, operation = '', output = :JSON, option = nil)
	
	option_text = []
	option.each_pair{|k, v| option_text.push("#{k.to_s}=#{v.to_s}")} if option.class == Hash
	
	if @@output_type.include?(output.to_sym)
		uri = "#{@@baseuri}/#{URI.escape(input, "[] ")}"
		uri += "/#{operation}" if operation != nil && operation != ''
		uri += "/#{output}"
		uri += "?#{option_text.join(',')}" if option_text.length > 0
		
		case output.to_sym
		when :JSON
			JSON.parse(URI.parse(uri).read().strip())
		else
			return URI.parse(uri).read().strip()
		end
		
	else
		raise Sylfy::Service::ParameterError, "Wrong output type. Should be #{@@output_type.inspect}"
	end
	
end

.substance(identifiers, namespace, operation = '', output = :JSON, option = nil) ⇒ Object

Method for setting inchi data member

Parameters:

id

LipidMap id to search

:id, :dataPrimarySource, :xrefs, :relations :inchi, :formula, :smiles, :inchiKey :names



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/sylfy/service/pubchemrest.rb', line 90

def substance(identifiers, namespace, operation = '', output = :JSON, option = nil)
	
	oper = @@main_oper + [:synonyms, :assaysummary, :classification]
	ns = [:sid, :name, :listkey]
	
	tmp_operation = ""
	
	if ns.include?(namespace.to_sym)
		namespace = namespace.to_s
	else
		namespace = namespace.to_s.split(/\//)
		if ['sourceid', 'sourceall'].include?(namespace[0])
			namespace = namespace.join('/')
		elsif namespace[0] == 'xref' && @@xref_ns.include?(namespace[1])
			namespace = namespace[0..2].join('/')
		else
			raise ServiceException::ParameterError, "Wrong domain type. Should be #{ns.join(', ')}, \
				xref/{#{@@xref_ns.join(' | ')}}, \
				sourceid/<source name> or sourceall/<source name>"
		end
	end
	
	if oper.include?(operation.to_sym)
		tmp_operation = operation.to_s
	else
		tmp_operation = ""
	end
	
	
	
	begin
		return perform("substance/#{namespace}/#{identifiers.to_s}", tmp_operation, output, option)
	rescue OpenURI::HTTPError
		return {}
	end
	
end