summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2012-08-20 14:38:08 +0200
committerChristoph Helma <helma@in-silico.ch>2012-08-20 14:38:08 +0200
commit24199c21ed6e1c6267592b85f3dc5efd731e114b (patch)
treea4237ef5bf56261775f0d43900807ea009c19a4c
parent2c28ce19166bd4f2329a1726eead602d6ec2f8c8 (diff)
parentfdad1b78a4ec89c160bff710f0374614c22cda56 (diff)
Merge branch 'feature/mra' into development
-rw-r--r--VERSION2
-rw-r--r--lib/compound.rb56
-rw-r--r--lib/dataset.rb2
3 files changed, 40 insertions, 20 deletions
diff --git a/VERSION b/VERSION
index 3eefcb9..8c5ba87 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.0.0
+5.0.0pre1
diff --git a/lib/compound.rb b/lib/compound.rb
index 7d84a3c..127a6ee 100644
--- a/lib/compound.rb
+++ b/lib/compound.rb
@@ -11,6 +11,7 @@ module OpenTox
# @param [String] smiles Smiles string
# @return [OpenTox::Compound] Compound
def self.from_smiles service_uri, smiles, subjectid=nil
+ @smiles = smiles
Compound.new RestClientWrapper.post(service_uri, smiles, {:content_type => 'chemical/x-daylight-smiles', :subjectid => subjectid})
end
@@ -18,6 +19,7 @@ module OpenTox
# @param [String] smiles InChI string
# @return [OpenTox::Compound] Compound
def self.from_inchi service_uri, inchi, subjectid=nil
+ @inchi = inchi
Compound.new RestClientWrapper.post(service_uri, inchi, {:content_type => 'chemical/x-inchi', :subjectid => subjectid})
end
@@ -33,60 +35,78 @@ module OpenTox
# compound = OpenTox::Compound.from_name("Benzene")
# @param [String] name name can be also an InChI/InChiKey, CAS number, etc
# @return [OpenTox::Compound] Compound
+ #
def self.from_name service_uri, name, subjectid=nil
- Compound.new RestClientWrapper.post(service_uri, name, {:content_type => 'text/plain', :subjectid => subjectid})
+ @inchi = RestClientWrapper.get File.join(CACTUS_URI,URI.escape(name),"stdinchi")
+ Compound.new RestClientWrapper.post(service_uri, @inchi, {:content_type => 'chemical/x-inchi', :subjectid => subjectid})
end
# Get InChI
# @return [String] InChI string
- def to_inchi
- RestClientWrapper.get(@uri,{},{:accept => 'chemical/x-inchi'}).chomp
+ def inchi
+ @inchi ||= RestClientWrapper.get(@uri,{},{:accept => 'chemical/x-inchi'}).chomp
+ end
+
+ # Get InChIKey
+ # @return [String] InChI string
+ def inchikey
+ @inchikey ||= RestClientWrapper.get(@uri,{},{:accept => 'chemical/x-inchikey'}).chomp
end
# Get (canonical) smiles
# @return [String] Smiles string
- def to_smiles
- RestClientWrapper.get(@uri,{},{:accept => 'chemical/x-daylight-smiles'}).chomp
+ def smiles
+ @smiles ||= RestClientWrapper.get(@uri,{},{:accept => 'chemical/x-daylight-smiles'}).chomp
end
# Get sdf
# @return [String] SDF string
- def to_sdf
+ def sdf
RestClientWrapper.get(@uri,{},{:accept => 'chemical/x-mdl-sdfile'}).chomp
end
# Get gif image
# @return [image/gif] Image data
- def to_gif
- RestClientWrapper.get("#{CACTUS_URI}#{to_inchi}/image")
+ def gif
+ RestClientWrapper.get File.join(CACTUS_URI,inchi,"image")
end
# Get png image
# @example
- # image = compound.to_png
+ # image = compound.png
# @return [image/png] Image data
- def to_png
+ def png
RestClientWrapper.get(File.join @uri, "image")
end
# Get URI of compound image
# @return [String] Compound image URI
- def to_image_uri
+ def image_uri
File.join @uri, "image"
end
# Get all known compound names. Relies on an external service for name lookups.
# @example
- # names = compound.to_names
+ # names = compound.names
# @return [String] Compound names
- def to_names
- begin
- RestClientWrapper.get("#{CACTUS_URI}#{to_inchi}/names").split("\n")
- rescue
- "CACTVS service not responding."
- end
+ def names
+ RestClientWrapper.get("#{CACTUS_URI}#{inchi}/names").split("\n")
end
+ def cid
+ pug_uri = "http://pubchem.ncbi.nlm.nih.gov/rest/pug/"
+ @cid ||= RestClientWrapper.post(File.join(pug_uri, "compound", "inchi", "cids", "TXT"),{:inchi => inchi}).strip
+ end
+
+ def chebi
+ end
+
+ def chemblid
+ # https://www.ebi.ac.uk/chembldb/ws#individualCompoundByInChiKey
+ uri = "http://www.ebi.ac.uk/chemblws/compounds/smiles/#{smiles}.json"
+ @chemblid = JSON.parse(RestClientWrapper.get(uri))["compounds"].first["chemblId"]
+ end
+
=begin
# Match a smarts string
# @example
diff --git a/lib/dataset.rb b/lib/dataset.rb
index e0f2d5a..4816b5a 100644
--- a/lib/dataset.rb
+++ b/lib/dataset.rb
@@ -22,7 +22,7 @@ module OpenTox
CSV.generate do |csv|
csv << ["SMILES"] + @features.collect{|f| f.title}
@compounds.each_with_index do |c,i|
- csv << [c.to_smiles] + @data_entries[i]
+ csv << [c.smiles] + @data_entries[i]
end
end
end