Class: PubChemAPI::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/pubchem_api.rb

Constant Summary collapse

COMPOUND_OPERATIONS =

Constants for allowed values

%w[record property synonyms sids aids classification description conformers]
SUBSTANCE_OPERATIONS =
%w[record synonyms cids aids classification description]
ASSAY_OPERATIONS =
%w[record concise description summary doseresponse targets]
OUTPUT_FORMATS =
%w[XML JSON JSONP ASNT ASNB SDF CSV TXT PNG]
OUTPUT_FORMATS_SIMPLE =
%w[XML JSON]
SEARCH_TYPES =
%w[fastsubstructure fastsuperstructure fastsimilarity_2d fastidentity fastformula]
NAMESPACES =
%w[smiles inchi sdf cid]
ID_TYPES =
%w[cid sid aid patent geneid protein taxonomyid pathwayid cellid]
TARGET_TYPES =
%w[ProteinGI ProteinName GeneID GeneSymbol]
DEFAULT_OUTPUT =
'JSON'

Instance Method Summary collapse

Instance Method Details

#compound_fastsubstructure_search(smiles, cachekey, output = DEFAULT_OUTPUT, options = {}) ⇒ Object

Search within a previous result using cache key



252
253
254
255
256
257
258
259
# File 'lib/pubchem_api.rb', line 252

def compound_fastsubstructure_search(smiles, cachekey, output = DEFAULT_OUTPUT, options = {})
  validate_output_format(output, OUTPUT_FORMATS)
  smiles_encoded = CGI.escape(smiles)
  path = "/compound/fastsubstructure/smiles/#{smiles_encoded}/cids/#{output}"
  options = options.merge('cachekey' => cachekey)
  response = self.class.get(path, query: options)
  parse_response(response, output)
end

#compound_structure_search(search_type, namespace, identifier, output = DEFAULT_OUTPUT, options = {}) ⇒ Object

Compound structure search operations



280
281
282
283
284
285
286
287
288
# File 'lib/pubchem_api.rb', line 280

def compound_structure_search(search_type, namespace, identifier, output = DEFAULT_OUTPUT, options = {})
  validate_value(search_type, SEARCH_TYPES, 'search type')
  validate_value(namespace, NAMESPACES, 'namespace')
  validate_output_format(output, OUTPUT_FORMATS)
  identifier_encoded = CGI.escape(identifier)
  path = "/compound/#{search_type}/#{namespace}/#{identifier_encoded}/cids/#{output}"
  response = self.class.get(path, query: options)
  parse_response(response, output)
end

#get_assay_by_aid(aid, operation, output = DEFAULT_OUTPUT, options = {}) ⇒ Object

Retrieve assay data by AID



175
176
177
178
179
180
181
# File 'lib/pubchem_api.rb', line 175

def get_assay_by_aid(aid, operation, output = DEFAULT_OUTPUT, options = {})
  validate_operation(operation, ASSAY_OPERATIONS)
  validate_output_format(output, OUTPUT_FORMATS)
  path = "/assay/aid/#{aid}/#{operation}/#{output}"
  response = self.class.get(path, query: options)
  parse_response(response, output, 'AssayRecord')
end

#get_assay_doseresponse(aid, output = DEFAULT_OUTPUT, options = {}) ⇒ Object

Retrieve assay dose-response data



209
210
211
212
213
214
# File 'lib/pubchem_api.rb', line 209

def get_assay_doseresponse(aid, output = DEFAULT_OUTPUT, options = {})
  validate_output_format(output, OUTPUT_FORMATS)
  path = "/assay/aid/#{aid}/doseresponse/#{output}"
  response = self.class.get(path, query: options)
  parse_response(response, output)
end

#get_assay_targets(aid, target_type, output = DEFAULT_OUTPUT, options = {}) ⇒ Object

Retrieve assay targets by target type



217
218
219
220
221
222
223
# File 'lib/pubchem_api.rb', line 217

def get_assay_targets(aid, target_type, output = DEFAULT_OUTPUT, options = {})
  validate_value(target_type, TARGET_TYPES, 'target type')
  validate_output_format(output, OUTPUT_FORMATS)
  path = "/assay/aid/#{aid}/targets/#{target_type}/#{output}"
  response = self.class.get(path, query: options)
  parse_response(response, output)
end

#get_classification_nodes(hnid, idtype, list_return, output = DEFAULT_OUTPUT, options = {}) ⇒ Object

Retrieve classification nodes as cache key



262
263
264
265
266
267
268
269
# File 'lib/pubchem_api.rb', line 262

def get_classification_nodes(hnid, idtype, list_return, output = DEFAULT_OUTPUT, options = {})
  validate_value(idtype, ID_TYPES, 'ID type')
  validate_output_format(output, OUTPUT_FORMATS_SIMPLE)
  path = "/classification/hnid/#{hnid}/#{idtype}/#{output}"
  options = options.merge('list_return' => list_return)
  response = self.class.get(path, query: options)
  parse_response(response, output)
end

#get_compound_by_cid(cid, operation, output = DEFAULT_OUTPUT, options = {}) ⇒ Object

Retrieve compound data by CID



147
148
149
150
151
152
153
# File 'lib/pubchem_api.rb', line 147

def get_compound_by_cid(cid, operation, output = DEFAULT_OUTPUT, options = {})
  validate_operation(operation, COMPOUND_OPERATIONS)
  validate_output_format(output, OUTPUT_FORMATS)
  path = "/compound/cid/#{cid}/#{operation}/#{output}"
  response = self.class.get(path, query: options)
  parse_response(response, output, 'CompoundRecord')
end

#get_compound_by_name(name, operation, output = DEFAULT_OUTPUT, options = {}) ⇒ Object

Retrieve compound data by name



156
157
158
159
160
161
162
163
# File 'lib/pubchem_api.rb', line 156

def get_compound_by_name(name, operation, output = DEFAULT_OUTPUT, options = {})
  validate_operation(operation, COMPOUND_OPERATIONS)
  validate_output_format(output, OUTPUT_FORMATS)
  name_encoded = CGI.escape(name)
  path = "/compound/name/#{name_encoded}/#{operation}/#{output}"
  response = self.class.get(path, query: options)
  parse_response(response, output, 'CompoundRecord')
end

#get_compound_conformers(cid, output = DEFAULT_OUTPUT, options = {}) ⇒ Object

Retrieve compound conformers by CID



244
245
246
247
248
249
# File 'lib/pubchem_api.rb', line 244

def get_compound_conformers(cid, output = DEFAULT_OUTPUT, options = {})
  validate_output_format(output, OUTPUT_FORMATS)
  path = "/compound/cid/#{cid}/conformers/#{output}"
  response = self.class.get(path, query: options)
  parse_response(response, output)
end

#get_compounds_by_listkey(listkey, output = DEFAULT_OUTPUT, options = {}) ⇒ Object

Retrieve compounds by listkey with pagination



272
273
274
275
276
277
# File 'lib/pubchem_api.rb', line 272

def get_compounds_by_listkey(listkey, output = DEFAULT_OUTPUT, options = {})
  validate_output_format(output, OUTPUT_FORMATS)
  path = "/compound/listkey/#{listkey}/cids/#{output}"
  response = self.class.get(path, query: options)
  parse_response(response, output)
end

#get_gene_summary_by_geneid(geneid, output = DEFAULT_OUTPUT, options = {}) ⇒ Object

Retrieve gene summary by GeneID



184
185
186
187
188
189
# File 'lib/pubchem_api.rb', line 184

def get_gene_summary_by_geneid(geneid, output = DEFAULT_OUTPUT, options = {})
  validate_output_format(output, OUTPUT_FORMATS_SIMPLE)
  path = "/gene/geneid/#{geneid}/summary/#{output}"
  response = self.class.get(path, query: options)
  parse_response(response, output, 'GeneSummary')
end

#get_gene_summary_by_synonym(synonym, output = DEFAULT_OUTPUT, options = {}) ⇒ Object

Retrieve gene summary by synonym



226
227
228
229
230
231
232
# File 'lib/pubchem_api.rb', line 226

def get_gene_summary_by_synonym(synonym, output = DEFAULT_OUTPUT, options = {})
  validate_output_format(output, OUTPUT_FORMATS_SIMPLE)
  synonym_encoded = CGI.escape(synonym)
  path = "/gene/synonym/#{synonym_encoded}/summary/#{output}"
  response = self.class.get(path, query: options)
  parse_response(response, output, 'GeneSummary')
end

#get_pathway_summary_by_pwacc(pwacc, output = DEFAULT_OUTPUT, options = {}) ⇒ Object

Retrieve pathway summary by pathway accession



200
201
202
203
204
205
206
# File 'lib/pubchem_api.rb', line 200

def get_pathway_summary_by_pwacc(pwacc, output = DEFAULT_OUTPUT, options = {})
  validate_output_format(output, OUTPUT_FORMATS_SIMPLE)
  pwacc_encoded = CGI.escape(pwacc)
  path = "/pathway/pwacc/#{pwacc_encoded}/summary/#{output}"
  response = self.class.get(path, query: options)
  parse_response(response, output, 'PathwaySummary')
end

#get_protein_summary_by_synonym(synonym, output = DEFAULT_OUTPUT, options = {}) ⇒ Object

Retrieve protein summary by synonym



235
236
237
238
239
240
241
# File 'lib/pubchem_api.rb', line 235

def get_protein_summary_by_synonym(synonym, output = DEFAULT_OUTPUT, options = {})
  validate_output_format(output, OUTPUT_FORMATS_SIMPLE)
  synonym_encoded = CGI.escape(synonym)
  path = "/protein/synonym/#{synonym_encoded}/summary/#{output}"
  response = self.class.get(path, query: options)
  parse_response(response, output, 'ProteinSummary')
end

#get_substance_by_sid(sid, operation, output = DEFAULT_OUTPUT, options = {}) ⇒ Object

Retrieve substance data by SID



166
167
168
169
170
171
172
# File 'lib/pubchem_api.rb', line 166

def get_substance_by_sid(sid, operation, output = DEFAULT_OUTPUT, options = {})
  validate_operation(operation, SUBSTANCE_OPERATIONS)
  validate_output_format(output, OUTPUT_FORMATS)
  path = "/substance/sid/#{sid}/#{operation}/#{output}"
  response = self.class.get(path, query: options)
  parse_response(response, output, 'SubstanceRecord')
end

#get_taxonomy_summary_by_taxid(taxid, output = DEFAULT_OUTPUT, options = {}) ⇒ Object

Retrieve taxonomy summary by TaxonomyID



192
193
194
195
196
197
# File 'lib/pubchem_api.rb', line 192

def get_taxonomy_summary_by_taxid(taxid, output = DEFAULT_OUTPUT, options = {})
  validate_output_format(output, OUTPUT_FORMATS_SIMPLE)
  path = "/taxonomy/taxid/#{taxid}/summary/#{output}"
  response = self.class.get(path, query: options)
  parse_response(response, output, 'TaxonomySummary')
end