sylfy 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/Rakefile +13 -0
- data/lib/sylfy.rb +12 -25
- data/lib/sylfy/add.rb +10 -0
- data/lib/sylfy/add/bio_kegg_kgml.rb +108 -0
- data/lib/sylfy/datamodel.rb +141 -0
- data/lib/sylfy/feature.rb +128 -0
- data/lib/sylfy/mathf.rb +40 -0
- data/lib/sylfy/pattern.rb +14 -0
- data/lib/sylfy/service.rb +34 -0
- data/lib/sylfy/service/biocycrest.rb +41 -0
- data/lib/sylfy/service/cactusncirest.rb +64 -0
- data/lib/sylfy/service/cbioportal.rb +156 -0
- data/lib/sylfy/service/chembl.rb +106 -0
- data/lib/sylfy/service/ebisoap.rb +55 -0
- data/lib/sylfy/service/ensemblrest.rb +64 -0
- data/lib/sylfy/service/ensemblrest/archive.rb +35 -0
- data/lib/sylfy/service/ensemblrest/comparative.rb +146 -0
- data/lib/sylfy/service/ensemblrest/xrefs.rb +73 -0
- data/lib/sylfy/service/hgncrest.rb +52 -0
- data/lib/sylfy/service/keggrest.rb +6 -19
- data/lib/sylfy/service/keggrest/conv.rb +64 -40
- data/lib/sylfy/service/keggrest/find.rb +27 -48
- data/lib/sylfy/service/keggrest/get.rb +82 -0
- data/lib/sylfy/service/keggrest/link.rb +17 -37
- data/lib/sylfy/service/keggrest/list.rb +18 -50
- data/lib/sylfy/service/lipidmaprest.rb +228 -0
- data/lib/sylfy/service/pubchem.rb +71 -0
- data/lib/sylfy/service/pubchemrest.rb +249 -0
- data/lib/sylfy/service/rest.rb +26 -0
- data/lib/sylfy/service/soapwsdl.rb +78 -0
- data/lib/sylfy/service/unichemrest.rb +106 -0
- data/lib/sylfy/utils.rb +18 -0
- data/lib/sylfy/utils/keyhash.rb +1149 -0
- data/lib/sylfy/utils/reactionkey.rb +197 -0
- data/lib/sylfy/version.rb +1 -1
- data/sylfy.gemspec +11 -15
- data/test/test_kegg_rest.rb +58 -0
- data/test/test_reactionkey.rb +37 -0
- metadata +87 -15
- data/lib/sylfy/math.rb +0 -24
- data/lib/sylfy/service/keggrest/restKegg_get.rb +0 -130
@@ -0,0 +1,71 @@
|
|
1
|
+
#
|
2
|
+
# UniSysDB library in Ruby
|
3
|
+
# Copyright (C) 2012
|
4
|
+
#
|
5
|
+
# @author Natapol Pornputtapong <natapol@chalmers.se>
|
6
|
+
#
|
7
|
+
require 'open-uri'
|
8
|
+
require 'net/http'
|
9
|
+
require 'json'
|
10
|
+
|
11
|
+
require 'sylfy/service/pubchemrest'
|
12
|
+
|
13
|
+
module Sylfy
|
14
|
+
|
15
|
+
module Service
|
16
|
+
|
17
|
+
module PubChem
|
18
|
+
|
19
|
+
module_function
|
20
|
+
|
21
|
+
# Method for setting inchi data member
|
22
|
+
#
|
23
|
+
# == Parameters:
|
24
|
+
# id::
|
25
|
+
# LipidMap id to search
|
26
|
+
# :id, :dataPrimarySource, :xrefs, :relations :inchi, :formula, :smiles, :inchiKey :names
|
27
|
+
def idbyinchi(inchi)
|
28
|
+
result = []
|
29
|
+
if inchi =~ /^InChI\=1S\/[A-Za-z0-9]+(\/[cnpqbtmsih][A-Za-z0-9\-\+\(\)\,]+)+$/
|
30
|
+
REST::compound(Rubabel[inchi, :inchi].write(:inchikey), 'inchikey', "cids")["IdentifierList"]["CID"].each {|e| result.push("urn:miriam:pubchem.compound:#{e}")}
|
31
|
+
elsif inchi =~ /^[A-Z]{14}\-[A-Z]{10}(\-[A-N])?/
|
32
|
+
REST::compound(inchi, 'inchikey', "cids")["IdentifierList"]["CID"].each {|e| result.push("urn:miriam:pubchem.compound:#{e}")}
|
33
|
+
end
|
34
|
+
|
35
|
+
return result
|
36
|
+
end
|
37
|
+
|
38
|
+
# Method for setting inchi data member
|
39
|
+
#
|
40
|
+
# == Parameters:
|
41
|
+
# id::
|
42
|
+
# LipidMap id to search
|
43
|
+
# :id, :dataPrimarySource, :xrefs, :relations :inchi, :formula, :smiles, :inchiKey :names
|
44
|
+
def getnames(inchi)
|
45
|
+
result = []
|
46
|
+
inchi = Rubabel[inchi, :inchi].to_s(:inchikey) if inchi =~ /^InChI\=1S\/[A-Za-z0-9]+(\/[cnpqbtmsih][A-Za-z0-9\-\+\(\)\,]+)+$/
|
47
|
+
|
48
|
+
if inchi =~ /^[A-Z]{14}\-[A-Z]{10}(\-[A-N])?/
|
49
|
+
Sylfy::Service::PubChem::REST.compound(inchi, :inchikey, "property/IUPACName")["PropertyTable"]["Properties"].each {|e| result.push(e["IUPACName"])}
|
50
|
+
Sylfy::Service::PubChem::REST.compound(inchi, :inchikey, :synonyms)["InformationList"]["Information"].each {|e| result += e["Synonym"]}
|
51
|
+
end
|
52
|
+
|
53
|
+
return result.uniq[0..21]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
#require 'json'
|
62
|
+
#require './unisys.rb'
|
63
|
+
|
64
|
+
#http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/aid/1000/sids/XML?sids_type=inactive
|
65
|
+
|
66
|
+
#p JSON.load(Unisys::Service::RESTPubChem.assay("1000", :aid, :sids, :JSON ,{:sids_type => :inactive}))
|
67
|
+
#p JSON.load(Unisys::Service::RESTPubChem.substance("747285", "sourceid/DTP.NCI"))
|
68
|
+
#p JSON.load(Unisys::Service::RESTPubChem.compound("2244", :cid, "property/MolecularFormula,CanonicalSMILES,InChI,InChIKey,IUPACName", "JSON"))
|
69
|
+
#p Unisys::Service::RESTPubChem.getSmallMolecule(2244, :cid)
|
70
|
+
#p Unisys::Service::RESTPubChem.idconv('D00001')
|
71
|
+
#p JSON.load(Unisys::Service::RESTPubChem.compound("LMFA08040013", 'xref/RegistryID', "property/MolecularFormula,CanonicalSMILES,InChI,InChIKey,IUPACName", "JSON"))
|
@@ -0,0 +1,249 @@
|
|
1
|
+
#
|
2
|
+
# UniSysDB library in Ruby
|
3
|
+
# Copyright (C) 2012
|
4
|
+
#
|
5
|
+
# @author Natapol Pornputtapong <natapol@chalmers.se>
|
6
|
+
#
|
7
|
+
require 'open-uri'
|
8
|
+
require 'net/http'
|
9
|
+
require 'json'
|
10
|
+
|
11
|
+
module Sylfy
|
12
|
+
|
13
|
+
module Service
|
14
|
+
|
15
|
+
|
16
|
+
module PubChem
|
17
|
+
|
18
|
+
module REST
|
19
|
+
@@baseuri = "http://pubchem.ncbi.nlm.nih.gov/rest/pug"
|
20
|
+
@@output_type = [:XML, :ASNT, :ASNB, :JSON, :JSONP, :SDF, :CSV, :PNG, :TXT]
|
21
|
+
@@main_oper = [:record, :aids, :sids, :cids]
|
22
|
+
@@cmp_property = ["MolecularFormula", "MolecularWeight", "CanonicalSMILES", "IsomericSMILES", "InChI", "InChIKey", "IUPACName", "XLogP", "ExactMass", \
|
23
|
+
"MonoisotopicMass", "TPSA", "Complexity", "Charge", "HBondDonorCount", "HBondAcceptorCount", "RotatableBondCount", "HeavyAtomCount", \
|
24
|
+
"IsotopeAtomCount", "AtomStereoCount", "DefinedAtomStereoCount", "UndefinedAtomStereoCount", "BondStereoCount", "DefinedBondStereoCount", \
|
25
|
+
"UndefinedBondStereoCount", "CovalentUnitCount", "Volume3D", "XStericQuadrupole3D", "YStericQuadrupole3D", "ZStericQuadrupole3D", "FeatureCount3D", \
|
26
|
+
"FeatureAcceptorCount3D", "FeatureDonorCount3D", "FeatureAnionCount3D", "FeatureCationCount3D", "FeatureRingCount3D", "FeatureHydrophobeCount3D", \
|
27
|
+
"ConformerModelRMSD3D", "EffectiveRotorCount3D", "ConformerCount3D"]
|
28
|
+
@@xref_ns = ['RegistryID', 'RN', 'PubMedID', 'MMDBID', 'ProteinGI', 'NucleotideGI', 'TaxonomyID', 'MIMID', 'GeneID', 'ProbeID', 'PatentID']
|
29
|
+
@@xref_oper = ['RegistryID', 'RN', 'PubMedID', 'MMDBID', 'DBURL', 'SBURL', 'ProteinGI', 'NucleotideGI', 'TaxonomyID', 'MIMID', 'GeneID', 'ProbeID', 'PatentID']
|
30
|
+
|
31
|
+
@@assay_type = ['all', 'confirmatory', 'doseresponse', 'onhold', 'panel', 'rnai', 'screening', 'summary']
|
32
|
+
|
33
|
+
#http://pubchem.ncbi.nlm.nih.gov/rest/pug/<input specification>/<operation specification>/[<output specification>][?<operation_options>]
|
34
|
+
|
35
|
+
#<input specification> = <domain>/<namespace>/<identifiers>
|
36
|
+
# <domain> = substance | compound | assay | <other inputs>
|
37
|
+
# compound domain <namespace> = cid | name | smiles | inchi | sdf | inchikey | <structure search> | <xref> | listkey
|
38
|
+
# <structure search> = {substructure | superstructure | similarity | identity}/{smiles | inchi | sdf | cid}
|
39
|
+
# <xref> = xref/{RegistryID | RN | PubMedID | MMDBID | ProteinGI | NucleotideGI | TaxonomyID | MIMID | GeneID | ProbeID | PatentID}
|
40
|
+
# substance domain <namespace> = sid | sourceid/<source name> | sourceall/<source name> | name | <xref> | listkey
|
41
|
+
# <source name> = any valid PubChem depositor name
|
42
|
+
# assay domain <namespace> = aid | listkey | type/<assay type> | sourceall/<source name>
|
43
|
+
# <assay type> = all | confirmatory | doseresponse | onhold | panel | rnai | screening | summary
|
44
|
+
# <other inputs> = sources/[substance, assay]
|
45
|
+
# <identifiers> = comma-separated list of positive integers (cid, sid, aid) or identifier strings (source, inchikey, listkey); single identifier string (name, smiles, xref; inchi, sdf by POST only)
|
46
|
+
#
|
47
|
+
#
|
48
|
+
#compound domain <operation specification> = record | <compound property> | synonyms | sids | cids | aids | assaysummary | classification
|
49
|
+
# <compound property> = property / [comma-separated list of property tags]
|
50
|
+
#substance domain <operation specification> = record | synonyms | sids | cids | aids | assaysummary | classification
|
51
|
+
#assay domain <operation specification> = record | aids | sids | cids | description | targets/<target type> | <doseresponse> | summary
|
52
|
+
# target_type = {ProteinGI, ProteinName, GeneID, GeneSymbol}
|
53
|
+
# <doseresponse> = doseresponse/sid
|
54
|
+
#
|
55
|
+
#
|
56
|
+
#<output specification> = XML | ASNT | ASNB | JSON | JSONP [ ?callback=<callback name> ] | SDF | CSV | PNG | TXT
|
57
|
+
|
58
|
+
module_function
|
59
|
+
|
60
|
+
def perform(input, operation = '', output = :JSON, option = nil)
|
61
|
+
|
62
|
+
option_text = []
|
63
|
+
option.each_pair{|k, v| option_text.push("#{k.to_s}=#{v.to_s}")} if option.class == Hash
|
64
|
+
|
65
|
+
if @@output_type.include?(output.to_sym)
|
66
|
+
uri = "#{@@baseuri}/#{URI.escape(input, "[] ")}"
|
67
|
+
uri += "/#{operation}" if operation != nil && operation != ''
|
68
|
+
uri += "/#{output}"
|
69
|
+
uri += "?#{option_text.join(',')}" if option_text.length > 0
|
70
|
+
|
71
|
+
case output.to_sym
|
72
|
+
when :JSON
|
73
|
+
JSON.parse(URI.parse(uri).read().strip())
|
74
|
+
else
|
75
|
+
return URI.parse(uri).read().strip()
|
76
|
+
end
|
77
|
+
|
78
|
+
else
|
79
|
+
raise Sylfy::Service::ParameterError, "Wrong output type. Should be #{@@output_type.inspect}"
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
# Method for setting inchi data member
|
85
|
+
#
|
86
|
+
# == Parameters:
|
87
|
+
# id::
|
88
|
+
# LipidMap id to search
|
89
|
+
# :id, :dataPrimarySource, :xrefs, :relations :inchi, :formula, :smiles, :inchiKey :names
|
90
|
+
def substance(identifiers, namespace, operation = '', output = :JSON, option = nil)
|
91
|
+
|
92
|
+
oper = @@main_oper + [:synonyms, :assaysummary, :classification]
|
93
|
+
ns = [:sid, :name, :listkey]
|
94
|
+
|
95
|
+
tmp_operation = ""
|
96
|
+
|
97
|
+
if ns.include?(namespace.to_sym)
|
98
|
+
namespace = namespace.to_s
|
99
|
+
else
|
100
|
+
namespace = namespace.to_s.split(/\//)
|
101
|
+
if ['sourceid', 'sourceall'].include?(namespace[0])
|
102
|
+
namespace = namespace.join('/')
|
103
|
+
elsif namespace[0] == 'xref' && @@xref_ns.include?(namespace[1])
|
104
|
+
namespace = namespace[0..2].join('/')
|
105
|
+
else
|
106
|
+
raise ServiceException::ParameterError, "Wrong domain type. Should be #{ns.join(', ')}, \
|
107
|
+
xref/{#{@@xref_ns.join(' | ')}}, \
|
108
|
+
sourceid/<source name> or sourceall/<source name>"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
if oper.include?(operation.to_sym)
|
113
|
+
tmp_operation = operation.to_s
|
114
|
+
else
|
115
|
+
tmp_operation = ""
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
begin
|
121
|
+
return perform("substance/#{namespace}/#{identifiers.to_s}", tmp_operation, output, option)
|
122
|
+
rescue OpenURI::HTTPError
|
123
|
+
return {}
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
# Method for setting inchi data member
|
129
|
+
#
|
130
|
+
# == Parameters:
|
131
|
+
# id::
|
132
|
+
# LipidMap id to search
|
133
|
+
# :id, :dataPrimarySource, :xrefs, :relations :inchi, :formula, :smiles, :inchiKey :names
|
134
|
+
def compound(identifiers, namespace, operation = '', output = :JSON, option = nil)
|
135
|
+
oper = @@main_oper + [:synonyms, :assaysummary, :classification]
|
136
|
+
ns = [:cid, :name, :smiles, :inchi, :sdf, :inchikey, :listkey]
|
137
|
+
|
138
|
+
tmp_operation = ""
|
139
|
+
|
140
|
+
if ns.include?(namespace.to_sym)
|
141
|
+
namespace = namespace.to_s
|
142
|
+
else
|
143
|
+
namespace = namespace.to_s.split(/\//)
|
144
|
+
if ['substructure', 'superstructure', 'similarity', 'identity'].include?(namespace[0]) && ['smiles', 'inchi', 'sdf', 'cid'].include?(namespace[1])
|
145
|
+
namespace = namespace[0..1].join('/')
|
146
|
+
elsif namespace[0] == 'xref' && @@xref_ns.include?(namespace[1])
|
147
|
+
namespace = namespace[0..2].join('/')
|
148
|
+
else
|
149
|
+
raise ServiceException::ParameterError, "Wrong domain type. Should be #{ns.join(', ')}, \
|
150
|
+
xref/{#{@@xref_ns.join(' | ')}} or \
|
151
|
+
{substructure | superstructure | similarity | identity}/{smiles | inchi | sdf | cid}"
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
if oper.include?(operation.to_sym)
|
156
|
+
tmp_operation = operation.to_s
|
157
|
+
else
|
158
|
+
operation = operation.to_s.split(/\//)
|
159
|
+
if operation[0] == 'property' #&& @@cmp_property.repeated_permutation(n).include?()
|
160
|
+
tmp_operation = operation[0..1].join('/')
|
161
|
+
elsif operation[0] == 'xrefs' && @@xref_oper.include?(operation[1])
|
162
|
+
tmp_operation = operation[0..1].join('/')
|
163
|
+
else
|
164
|
+
tmp_operation = ""
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
begin
|
169
|
+
return perform("compound/#{namespace}/#{identifiers.to_s}", tmp_operation, output, option)
|
170
|
+
rescue OpenURI::HTTPError
|
171
|
+
return {}
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
# Method for setting inchi data member
|
177
|
+
#
|
178
|
+
# == Parameters:
|
179
|
+
# id::
|
180
|
+
# LipidMap id to search
|
181
|
+
# :id, :dataPrimarySource, :xrefs, :relations :inchi, :formula, :smiles, :inchiKey :names
|
182
|
+
def assay(identifiers, namespace, operation = '', output = :JSON, option = nil)
|
183
|
+
oper = @@main_oper + [:description]
|
184
|
+
ns = [:aid, :listkey]
|
185
|
+
|
186
|
+
tmp_operation = ""
|
187
|
+
|
188
|
+
if ns.include?(namespace.to_sym)
|
189
|
+
namespace = namespace.to_s
|
190
|
+
else
|
191
|
+
namespace = namespace.split(/\//)
|
192
|
+
if namespace[0] == 'type' && @@assay_type.include?(namespace[1])
|
193
|
+
namespace = namespace[0..1].join('/')
|
194
|
+
elsif namespace[0] == 'sourceall'
|
195
|
+
namespace = namespace[0..1].join('/')
|
196
|
+
else
|
197
|
+
raise ServiceException::ParameterError, "Wrong domain type. Should be #{ns.join(', ')}, \
|
198
|
+
type/{#{@@assay_type.join(' | ')}} or sourceall/<source name>"
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
if oper.include?(operation.to_sym)
|
203
|
+
tmp_operation = operation.to_s
|
204
|
+
elsif operation.to_s =~ /^targets\/([\w,]+)/ #target_type = {ProteinGI, ProteinName, GeneID, GeneSymbol}
|
205
|
+
tmp_operation = operation.to_s
|
206
|
+
elsif operation.to_s =~ /^doseresponse\/([\w,]+)/ #doseresponse/sid
|
207
|
+
tmp_operation = operation.to_s
|
208
|
+
else
|
209
|
+
tmp_operation = ""
|
210
|
+
end
|
211
|
+
|
212
|
+
begin
|
213
|
+
return perform("assay/#{namespace}/#{identifiers.to_s}", tmp_operation, output, option)
|
214
|
+
rescue OpenURI::HTTPError
|
215
|
+
return {}
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
# Method for setting inchi data member
|
221
|
+
#
|
222
|
+
# == Parameters:
|
223
|
+
# id::
|
224
|
+
# LipidMap id to search
|
225
|
+
# :id, :dataPrimarySource, :xrefs, :relations :inchi, :formula, :smiles, :inchiKey :names
|
226
|
+
def idconv(id)
|
227
|
+
return JSON.load(compound(id, 'xref/RegistryID', "cids"))["IdentifierList"]["CID"]
|
228
|
+
end
|
229
|
+
|
230
|
+
|
231
|
+
end
|
232
|
+
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
#require 'json'
|
240
|
+
#require './unisys.rb'
|
241
|
+
|
242
|
+
#http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/aid/1000/sids/XML?sids_type=inactive
|
243
|
+
|
244
|
+
#p JSON.load(Unisys::Service::RESTPubChem.assay("1000", :aid, :sids, :JSON ,{:sids_type => :inactive}))
|
245
|
+
#p JSON.load(Unisys::Service::RESTPubChem.substance("747285", "sourceid/DTP.NCI"))
|
246
|
+
#p JSON.load(Unisys::Service::RESTPubChem.compound("2244", :cid, "property/MolecularFormula,CanonicalSMILES,InChI,InChIKey,IUPACName", "JSON"))
|
247
|
+
#p Unisys::Service::RESTPubChem.getSmallMolecule(2244, :cid)
|
248
|
+
#p Unisys::Service::RESTPubChem.idconv('D00001')
|
249
|
+
#p JSON.load(Unisys::Service::RESTPubChem.compound("LMFA08040013", 'xref/RegistryID', "property/MolecularFormula,CanonicalSMILES,InChI,InChIKey,IUPACName", "JSON"))
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# @author Natapol Pornputtapong <natapol@chalmers.se>
|
2
|
+
#
|
3
|
+
require 'open-uri'
|
4
|
+
require 'net/http'
|
5
|
+
require 'rexml/document'
|
6
|
+
require 'json'
|
7
|
+
require 'yaml'
|
8
|
+
|
9
|
+
require 'sylfy/service/ensemblrest/xrefs.rb'
|
10
|
+
require 'sylfy/service/ensemblrest/archive.rb'
|
11
|
+
require 'sylfy/service/ensemblrest/comparative.rb'
|
12
|
+
|
13
|
+
module Sylfy
|
14
|
+
|
15
|
+
module Service
|
16
|
+
|
17
|
+
module RESTInclude
|
18
|
+
|
19
|
+
def resolve(args)
|
20
|
+
#code
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#
|
2
|
+
# Systems biology library for Ruby (Sylfy)
|
3
|
+
# Copyright:: Copyright (C) 2006
|
4
|
+
# Toshiaki Katayama <k@bioruby.org>
|
5
|
+
# Copyright (C) 2012-2013
|
6
|
+
#
|
7
|
+
# author: Natapol Pornputtapong <natapol@chalmers.se>
|
8
|
+
#
|
9
|
+
# Documentation: Natapol Pornputtapong (RDoc'd and embellished by William Webber)
|
10
|
+
#
|
11
|
+
|
12
|
+
# raise "Please, use ruby 1.9.0 or later." if RUBY_VERSION < "1.9.0"
|
13
|
+
|
14
|
+
require 'savon'
|
15
|
+
#namespaces = {
|
16
|
+
# "xmlns:v2" => "http://v2.example.com",
|
17
|
+
#}
|
18
|
+
#
|
19
|
+
#Savon.client(namespaces: namespaces)
|
20
|
+
# debug log_level: :debug, log: true, pretty_print_xml: true
|
21
|
+
module Sylfy
|
22
|
+
# A module supports as interfaces for web services
|
23
|
+
module Service
|
24
|
+
|
25
|
+
class SOAPWSDL
|
26
|
+
# Initialize SOAP service
|
27
|
+
#
|
28
|
+
# == Parameters:
|
29
|
+
# wsdl::
|
30
|
+
#
|
31
|
+
# options::
|
32
|
+
#
|
33
|
+
def initialize(wsdl, options = {})
|
34
|
+
@options = options
|
35
|
+
@options[:wsdl] = wsdl
|
36
|
+
@options[:log] = false if !@options.has_key?(:log)
|
37
|
+
@options[:pretty_print_xml] = true if @options.has_key?(:log_level) && @options[:log_level] == :debug
|
38
|
+
@client = Savon.client(@options)
|
39
|
+
end
|
40
|
+
|
41
|
+
# List of methods defined by WSDL
|
42
|
+
def list_methods
|
43
|
+
@client.operations
|
44
|
+
end
|
45
|
+
|
46
|
+
def method_missing(m, *args, &block)
|
47
|
+
response = @client.call(m, message: args[0])
|
48
|
+
if @options[:log_level] == :debug
|
49
|
+
puts response.body
|
50
|
+
puts response.success? # => false
|
51
|
+
puts response.soap_fault? # => true
|
52
|
+
puts response.http_error?
|
53
|
+
end
|
54
|
+
|
55
|
+
if response.body[:"#{m}_response"].has_key?(:"#{m}_return")
|
56
|
+
result = response.body[:"#{m}_response"][:"#{m}_return"]
|
57
|
+
else
|
58
|
+
result = response.body[:"#{m}_response"][:return]
|
59
|
+
end
|
60
|
+
|
61
|
+
if result.class == Hash
|
62
|
+
result.delete_if {|k, v| k.to_s =~ /^@/}
|
63
|
+
return result.empty? ? "" : result
|
64
|
+
else
|
65
|
+
return result
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
private :method_missing
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
#a = Sylfy::Service::SOAPWSDL.new('http://www.ebi.ac.uk/webservices/chebi/2.0/webservice?wsdl')
|
77
|
+
#p a.list_methods
|
78
|
+
#p a.get_complete_entity(chebiId: '15377').keys #to_xml
|
@@ -0,0 +1,106 @@
|
|
1
|
+
#
|
2
|
+
# Sylfy library in Ruby
|
3
|
+
# Copyright (C) 2012
|
4
|
+
#
|
5
|
+
# @author Natapol Pornputtapong <natapol@chalmers.se>
|
6
|
+
#
|
7
|
+
require 'open-uri'
|
8
|
+
require 'net/http'
|
9
|
+
require 'json'
|
10
|
+
|
11
|
+
|
12
|
+
module Sylfy
|
13
|
+
|
14
|
+
module Service
|
15
|
+
|
16
|
+
module UniChem
|
17
|
+
|
18
|
+
module REST
|
19
|
+
|
20
|
+
@@baseuri = "https://www.ebi.ac.uk/unichem/rest"
|
21
|
+
NAMEURIMAPPING = {
|
22
|
+
chembl: "chembl.compound",
|
23
|
+
drugbank: "drugbank",
|
24
|
+
pdb: "pdb",
|
25
|
+
iuphar: "iuphar.ligand",
|
26
|
+
kegg_ligand: "kegg.compound",
|
27
|
+
chebi: "chebi",
|
28
|
+
#emolecules: "",
|
29
|
+
#ibm: "",
|
30
|
+
#atlas: "",
|
31
|
+
#patents: "",
|
32
|
+
#fdasrs: "",
|
33
|
+
#surechem: "",
|
34
|
+
pharmgkb: "pharmgkb.drug",
|
35
|
+
#pubchem_tpharma: "",
|
36
|
+
hmdb: "hmdb",
|
37
|
+
pubchem: "pubchem.compound"
|
38
|
+
#mcule: ""
|
39
|
+
}
|
40
|
+
|
41
|
+
module_function
|
42
|
+
|
43
|
+
def perform(input)
|
44
|
+
|
45
|
+
uri = "#{@@baseuri}/#{input}"
|
46
|
+
|
47
|
+
begin
|
48
|
+
return JSON.parse(open(uri, "content_type" => 'application/json').read().strip())
|
49
|
+
rescue OpenURI::HTTPError
|
50
|
+
return JSON.parse("{}")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def src_compound_id(src_cpd_id, src_id = 1, to_src_id = nil, all = false)
|
55
|
+
input = "src_compound_id#{all == true ? "_all" : ''}/#{src_cpd_id}/#{src_id}#{to_src_id != nil ? "/#{to_src_id}" : ""}"
|
56
|
+
return perform(input)
|
57
|
+
end
|
58
|
+
|
59
|
+
def src_compound_id_all(src_cpd_id, src_id = 1, to_src_id = nil)
|
60
|
+
return src_compound_id(src_cpd_id, src_id, to_src_id, true)
|
61
|
+
end
|
62
|
+
|
63
|
+
def mapping(src_id, to_src_id)
|
64
|
+
input = "mapping/#{src_id}/#{to_src_id}"
|
65
|
+
return perform(input)
|
66
|
+
end
|
67
|
+
|
68
|
+
def inchikey(key, all = false)
|
69
|
+
input = "inchikey#{all == true ? "_all" : ''}/#{key}"
|
70
|
+
return perform(input)
|
71
|
+
end
|
72
|
+
|
73
|
+
def inchikey_all(key)
|
74
|
+
return inchikey(key, true)
|
75
|
+
end
|
76
|
+
|
77
|
+
def structure(src_cpd_id, src_id)
|
78
|
+
input = "structure/#{src_cpd_id}/#{src_id}"
|
79
|
+
return perform(input)
|
80
|
+
end
|
81
|
+
|
82
|
+
def verbose_inchikey(key)
|
83
|
+
input = "verbose_inchikey/#{key}"
|
84
|
+
return perform(input)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
module_function
|
89
|
+
|
90
|
+
def idbyinchi(inchi)
|
91
|
+
result = []
|
92
|
+
inchi = Rubabel[inchi, :inchi].to_s(:inchikey) if inchi =~ Sylfy::Pattern::INCHI
|
93
|
+
|
94
|
+
if inchi =~ Sylfy::Pattern::INCHIKEY
|
95
|
+
REST.verbose_inchikey(inchi).each do |entry|
|
96
|
+
if REST::NAMEURIMAPPING.has_key?(entry["name"].to_sym)
|
97
|
+
entry["src_compound_id"].each {|e| result.push("urn:miriam:#{REST::NAMEURIMAPPING[entry["name"].to_sym]}:#{e}")}
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
return result
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|