Class: Ruspider::ChemSpider

Inherits:
Object
  • Object
show all
Includes:
InchIAPI, MassSpecAPI, SpectraAPI
Defined in:
lib/ruspider/chemspider.rb

Overview

ChemSpider Ruby interface

Constant Summary

Constants included from SpectraAPI

SpectraAPI::API, SpectraAPI::FIELDS

Constants included from MassSpecAPI

MassSpecAPI::API, MassSpecAPI::FIELDS

Constants included from InchIAPI

InchIAPI::API

Instance Method Summary collapse

Methods included from SpectraAPI

#all_spectra, #all_spectra_info, #get_compound_spectra_info, #get_spectra_info_list, #get_spectrum_info

Methods included from MassSpecAPI

#databases, #get_extended_compound_info, #get_extended_compound_info_list

Methods included from XmlUtils

#array_from_xml, #get_first_node, #get_nodes, #hash_from_string, #hash_from_xml

Methods included from InchIAPI

#get_original_mol, #inchi_key_to_csid, #inchi_to_csid

Constructor Details

#initialize(token = '', header = {}) ⇒ ChemSpider

Returns a new instance of ChemSpider.



17
18
19
20
21
22
# File 'lib/ruspider/chemspider.rb', line 17

def initialize(token = '', header = {})
  @rest = RestClient.new(token, header)
  InchIAPI.instance_method(:initialize).bind(self).call(@rest)
  MassSpecAPI.instance_method(:initialize).bind(self).call(@rest)
  SpectraAPI.instance_method(:initialize).bind(self).call(@rest)
end

Instance Method Details

#get_compound(csid) ⇒ Object



24
25
26
# File 'lib/ruspider/chemspider.rb', line 24

def get_compound(csid)
  Compound.new(csid, self)
end

#get_compound_spectra(csid) ⇒ Object



40
41
42
43
44
# File 'lib/ruspider/chemspider.rb', line 40

def get_compound_spectra(csid)
  get_spectra_info_list([csid]).map do |x|
    Spectrum.from_info_dict(x, self)
  end
end

#get_compounds(csids) ⇒ Object



28
29
30
# File 'lib/ruspider/chemspider.rb', line 28

def get_compounds(csids)
  csids.map { |x| Compound.new(x, self) }
end

#get_spectra(spectrum_ids) ⇒ Object



36
37
38
# File 'lib/ruspider/chemspider.rb', line 36

def get_spectra(spectrum_ids)
  spectrum_ids.map { |x| Spectrum.new(x, self) }
end

#get_spectrum(spectrum_id) ⇒ Object



32
33
34
# File 'lib/ruspider/chemspider.rb', line 32

def get_spectrum(spectrum_id)
  Spectrum.new(spectrum_id, self)
end