rubabel 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c407acb50267d5d801e3b17c7ca6c9090f09935
4
- data.tar.gz: dc4f917d5688fd3be0b593bb34d3f25edce5b362
3
+ metadata.gz: 77fb1221a3d565301bacfe578f1840d1cfa429f6
4
+ data.tar.gz: 451550b29cf66ac52eed7ded68e12f4861c323f1
5
5
  SHA512:
6
- metadata.gz: 618fb4a2d529cdbf7c3ec1ae1fc85088a92cd4b554d43f95bfa527bb15c1cae946a45474c1553db0a4ab456cf70a7cd5c6566a47856a0a4f4656c251378ff067
7
- data.tar.gz: eeb366cb6d73da968fd54dae44e6f64d3edc485a0913742713846ed7b28dabdb89708533d145dfc6ad6bf6b164a6584f8288120e45dc19e82c7af9e9410fa8a2
6
+ metadata.gz: 1314697e1606dc64c98d61a7e9e04b58b7644fc48fb9f41387f961640383962473a57bf8d837b4a6ea946d073fd76c919ca1cc68adeeeee2adfb1c3b5a44b9c5
7
+ data.tar.gz: c57d7f5c444885ac58956642eb05306168ba68741a6861bc54d596f703f755484c54663069b6781600862eec507b2e598f359c72414f97429c9e06291f0334b7
data/README.md CHANGED
@@ -4,6 +4,8 @@ Ruby interface to the OpenBabel ruby bindings (or the openbabel gem). The
4
4
  interface attempts to be a ruby-ish analogue of
5
5
  [pybel](http://openbabel.org/docs/current/UseTheLibrary/Python_PybelAPI.html). Works with ruby 1.9 and 2.0.
6
6
 
7
+ **NOTE: Lipid fragmentation code has been moved to the [msplinter](https://github.com/princelab/msplinter).**
8
+
7
9
  ## Examples
8
10
 
9
11
  The [Chemistry Toolkit Rosetta Wiki](http://ctr.wikia.com/wiki/Chemistry_Toolkit_Rosetta_Wiki) has a lot of examples you can check out.
@@ -23,13 +25,14 @@ serine = Rubabel::Molecule.from_string("C(C(C(=O)O)N)O")
23
25
  # also any other format openbabel supports, for example inchi
24
26
  serine = Rubabel["InChI=1S/C3H7NO3/c4-2(1-5)3(6)7/h2,5H,1,4H2,(H,6,7)", :inchi]
25
27
 
26
- # from the internet:
27
- mol = Rubabel[some_molecule, Rubabel.format_from_mime(some_mime_type)]
28
+ # from an InChI Key or other id (such as LipidMaps ID) [requires internet]
29
+ serine = Rubabel["MTCFGRXMJLQNBG-REOHCLBHSA-N", :inchikey]
28
30
 
29
31
  Find out all the formats Rubabel supports (hash is format key pointing to the description):
30
32
 
31
33
  hash = Rubabel.in_formats
32
34
  hash = Rubabel.out_formats
35
+ hash = Rubabel.id_formats # molecule retrieved by web-lookup
33
36
  ```
34
37
 
35
38
  #### From a file
@@ -25,8 +25,16 @@ module Rubabel
25
25
 
26
26
  class << self
27
27
 
28
+ # accepts a string specifying the molecule (calling Rubabel::Molecule.from_string)
29
+ # or an id (calls Rubabel::Molecule.from_id)
28
30
  def [](string, type=Rubabel::Molecule::DEFAULT_IN_TYPE)
29
- Rubabel::Molecule.from_string(string, type)
31
+ methd =
32
+ if type && Rubabel::Molecule::ID_TYPE_KEYS.include?(type)
33
+ :from_id
34
+ else
35
+ :from_string
36
+ end
37
+ Rubabel::Molecule.send(methd, string, type)
30
38
  end
31
39
 
32
40
  def force_field(type=DEFAULT_FORCEFIELD)
@@ -45,6 +53,11 @@ module Rubabel
45
53
  @out_formats ||= formats_to_hash(OpenBabel::OBConversion.new.get_supported_output_format)
46
54
  end
47
55
 
56
+ # returns the formats retrievable by url lookup of the id or key
57
+ def id_formats
58
+ Rubabel::Molecule::ID_TYPES
59
+ end
60
+
48
61
  # returns the format Symbol that can be used for conversion, or nil if
49
62
  # the extension is not recognized.
50
63
  def format_from_ext(filename)
@@ -1,3 +1,5 @@
1
+ require 'open-uri'
2
+ require 'rexml/document'
1
3
  require 'openbabel'
2
4
  require 'rubabel'
3
5
  require 'rubabel/atom'
@@ -76,6 +78,12 @@ module Rubabel
76
78
  DEFAULT_FINGERPRINT = "FP2"
77
79
  DEFAULT_OUT_TYPE = :can
78
80
  DEFAULT_IN_TYPE = :smi
81
+ DEFAULT_ID_TYPE = :pubchem
82
+ ID_TYPES = {
83
+ inchikey: "InChI key",
84
+ lmid: "LipidMaps ID"
85
+ }
86
+ ID_TYPE_KEYS = ID_TYPES.keys
79
87
 
80
88
  # the OpenBabel::OBmol object
81
89
  attr_accessor :ob
@@ -92,6 +100,9 @@ module Rubabel
92
100
  end
93
101
 
94
102
  def from_string(string, type=DEFAULT_IN_TYPE)
103
+ if type == :inchi
104
+ string.prepend("InChI=") unless string[/^InChI=/]
105
+ end
95
106
  obmol = OpenBabel::OBMol.new
96
107
  obconv = OpenBabel::OBConversion.new
97
108
  obconv.set_in_format(type.to_s) || raise(ArgumentError, "invalid format #{type}")
@@ -99,6 +110,34 @@ module Rubabel
99
110
  self.new(obmol)
100
111
  end
101
112
 
113
+ def retrieve_info_from_url(url)
114
+ begin
115
+ info = open(url) {|io| io.read }
116
+ rescue => e
117
+ puts "Some kind of internet connectivity error. Check your connection!"
118
+ raise e
119
+ end
120
+ info
121
+ end
122
+
123
+ # requires an internet connection
124
+ def from_id(id, type=DEFAULT_ID_TYPE)
125
+ case type
126
+ when :inchikey
127
+ url = "http://www.chemspider.com/InChI.asmx/InChIKeyToInChI?inchi_key=" + URI::encode(id)
128
+ doc_string = retrieve_info_from_url(url)
129
+ doc = REXML::Document.new( doc_string )
130
+ inchi_string = doc.root.children.first.to_s
131
+ raise(ArgumentError, "did not retrieve a valid inchi string") unless inchi_string[/^InChI=/]
132
+ from_string(inchi_string, :inchi)
133
+ when :lmid # lipidmaps id
134
+ url = "http://www.lipidmaps.org/data/LMSDRecord.php?OutputType=SDF&Mode=File&LMID=" + id
135
+ doc_string = retrieve_info_from_url(url)
136
+ from_string(doc_string, :sdf)
137
+ end
138
+ end
139
+ alias_method :from_key, :from_id
140
+
102
141
  def from_atoms_and_bonds(atoms=[], bonds=[])
103
142
  obj = self.new( OpenBabel::OBMol.new )
104
143
  atoms.each {|atom| obj.add_atom(atom) }
@@ -1,3 +1,3 @@
1
1
  module Rubabel
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -30,7 +30,6 @@ interface attempts to be a ruby-ish analogue of pybel.}
30
30
  ["bundler", "~> 1.3"],
31
31
  ["rspec", "~> 2.13.0"],
32
32
  ["rdoc", "~> 3.12"],
33
- ["jeweler", "~> 1.8.3"],
34
33
  ["simplecov"],
35
34
  ["rake"]
36
35
  ].each do |args|
@@ -4,6 +4,12 @@ require 'rubabel/molecule'
4
4
 
5
5
  describe Rubabel::Molecule do
6
6
  describe 'creation' do
7
+ it 'can be made from scratch' do
8
+ mol = Rubabel::Molecule.new
9
+ mol.atoms.size == 0
10
+ mol.title.should == ''
11
+ end
12
+
7
13
  it 'can be made with Rubabel[]' do
8
14
  mol = Rubabel["CC(O)O"]
9
15
  mol.csmiles.should == "CC(O)O"
@@ -14,11 +20,45 @@ describe Rubabel::Molecule do
14
20
  mol_dup = Rubabel::Molecule.new(mol.ob)
15
21
  end
16
22
 
17
- it 'can be made fresh' do
18
- mol = Rubabel::Molecule.new
19
- mol.atoms.size == 0
20
- mol.title.should == ''
23
+ describe 'creation from different input strings' do
24
+ before(:all) do
25
+ @exp = Rubabel["CC(=O)O"]
26
+ end
27
+
28
+ # same as Rubabel::Molecule.from_string *args
29
+ specify 'smiles' do
30
+ Rubabel["CC(=O)O"].should == @exp
31
+ end
32
+
33
+ specify 'inchi' do
34
+ Rubabel["InChI=1S/C2H4O2/c1-2(3)4/h1H3,(H,3,4)", :inchi].should == @exp
35
+ end
36
+
37
+ specify 'inchi with no InChI= leader okay!' do
38
+ Rubabel["1S/C2H4O2/c1-2(3)4/h1H3,(H,3,4)", :inchi].should == @exp
39
+ end
40
+
41
+ describe 'creation with web lookup of ID or keys' do
42
+ before(:all) do
43
+ @exp = Rubabel["CC(=O)O"]
44
+ end
45
+
46
+ specify 'inchi key' do
47
+ Rubabel::Molecule.from_id( 'QTBSBXVTEAMEQO-UHFFFAOYSA-N', :inchikey ).should == @exp
48
+ Rubabel['QTBSBXVTEAMEQO-UHFFFAOYSA-N', :inchikey].should == @exp
49
+ end
50
+
51
+ specify 'lipidmaps id' do
52
+ Rubabel::Molecule.from_id( 'LMFA01010002', :lmid ).should == @exp
53
+ Rubabel['LMFA01010002', :lmid].should == @exp
54
+ end
55
+
56
+ specify 'pubchem id'
57
+
58
+ end
59
+
21
60
  end
61
+
22
62
  end
23
63
 
24
64
  #xit 'can add a hydrogen to the formula' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubabel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John T. Prince
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-18 00:00:00.000000000 Z
11
+ date: 2013-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: openbabel
@@ -94,20 +94,6 @@ dependencies:
94
94
  - - ~>
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3.12'
97
- - !ruby/object:Gem::Dependency
98
- name: jeweler
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ~>
102
- - !ruby/object:Gem::Version
103
- version: 1.8.3
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ~>
109
- - !ruby/object:Gem::Version
110
- version: 1.8.3
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: simplecov
113
99
  requirement: !ruby/object:Gem::Requirement
@@ -150,7 +136,6 @@ files:
150
136
  - LICENSE
151
137
  - README.md
152
138
  - Rakefile
153
- - VERSION
154
139
  - lib/rubabel.rb
155
140
  - lib/rubabel/atom.rb
156
141
  - lib/rubabel/bond.rb
@@ -214,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
199
  version: '0'
215
200
  requirements: []
216
201
  rubyforge_project:
217
- rubygems_version: 2.0.2
202
+ rubygems_version: 2.0.3
218
203
  signing_key:
219
204
  specification_version: 4
220
205
  summary: Ruby interface to the openbabel ruby bindings (or the openbabel gem). The
@@ -243,4 +228,3 @@ test_files:
243
228
  - spec/testfiles/cholesterol.mol
244
229
  - spec/testfiles/cholesterol.sdf
245
230
  - spec/testfiles/two.sdf
246
- has_rdoc:
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.3.1