sylfy 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/Rakefile +13 -0
  4. data/lib/sylfy.rb +12 -25
  5. data/lib/sylfy/add.rb +10 -0
  6. data/lib/sylfy/add/bio_kegg_kgml.rb +108 -0
  7. data/lib/sylfy/datamodel.rb +141 -0
  8. data/lib/sylfy/feature.rb +128 -0
  9. data/lib/sylfy/mathf.rb +40 -0
  10. data/lib/sylfy/pattern.rb +14 -0
  11. data/lib/sylfy/service.rb +34 -0
  12. data/lib/sylfy/service/biocycrest.rb +41 -0
  13. data/lib/sylfy/service/cactusncirest.rb +64 -0
  14. data/lib/sylfy/service/cbioportal.rb +156 -0
  15. data/lib/sylfy/service/chembl.rb +106 -0
  16. data/lib/sylfy/service/ebisoap.rb +55 -0
  17. data/lib/sylfy/service/ensemblrest.rb +64 -0
  18. data/lib/sylfy/service/ensemblrest/archive.rb +35 -0
  19. data/lib/sylfy/service/ensemblrest/comparative.rb +146 -0
  20. data/lib/sylfy/service/ensemblrest/xrefs.rb +73 -0
  21. data/lib/sylfy/service/hgncrest.rb +52 -0
  22. data/lib/sylfy/service/keggrest.rb +6 -19
  23. data/lib/sylfy/service/keggrest/conv.rb +64 -40
  24. data/lib/sylfy/service/keggrest/find.rb +27 -48
  25. data/lib/sylfy/service/keggrest/get.rb +82 -0
  26. data/lib/sylfy/service/keggrest/link.rb +17 -37
  27. data/lib/sylfy/service/keggrest/list.rb +18 -50
  28. data/lib/sylfy/service/lipidmaprest.rb +228 -0
  29. data/lib/sylfy/service/pubchem.rb +71 -0
  30. data/lib/sylfy/service/pubchemrest.rb +249 -0
  31. data/lib/sylfy/service/rest.rb +26 -0
  32. data/lib/sylfy/service/soapwsdl.rb +78 -0
  33. data/lib/sylfy/service/unichemrest.rb +106 -0
  34. data/lib/sylfy/utils.rb +18 -0
  35. data/lib/sylfy/utils/keyhash.rb +1149 -0
  36. data/lib/sylfy/utils/reactionkey.rb +197 -0
  37. data/lib/sylfy/version.rb +1 -1
  38. data/sylfy.gemspec +11 -15
  39. data/test/test_kegg_rest.rb +58 -0
  40. data/test/test_reactionkey.rb +37 -0
  41. metadata +87 -15
  42. data/lib/sylfy/math.rb +0 -24
  43. data/lib/sylfy/service/keggrest/restKegg_get.rb +0 -130
@@ -0,0 +1,55 @@
1
+ #
2
+ # Systems biology library for Ruby (Sylfy)
3
+ #
4
+ # author: Natapol Pornputtapong <natapol@chalmers.se>
5
+ #
6
+ # Documentation: Natapol Pornputtapong (RDoc'd and embellished by William Webber)
7
+ #
8
+
9
+ # raise "Please, use ruby 1.9.0 or later." if RUBY_VERSION < "1.9.0"
10
+
11
+
12
+ require 'sylfy/service/soapwsdl'
13
+
14
+ module Sylfy
15
+ # A module supports as interfaces for web services
16
+ module Service
17
+ module ChEBI
18
+ class SOAP < Sylfy::Service::SOAPWSDL
19
+ def initialize(options = {})
20
+ super('http://www.ebi.ac.uk/webservices/chebi/2.0/webservice?wsdl', options)
21
+ end
22
+
23
+ end
24
+
25
+ module_function
26
+
27
+ # Search ChEBI database using InChI
28
+ #
29
+ # == Parameters:
30
+ # inchi::
31
+ # inchi string to search
32
+ def idbyinchi(inchi)
33
+ output = Sylfy::Service::ChEBI::SOAP.new.get_structure_search(structure: Rubabel[inchi, :inchi].to_s(:can), type: 'SMILES', structureSearchCategory: 'IDENTITY')
34
+ return output != nil ? ["urn:miriam:chebi:#{output[:list_element][:chebi_id]}"] : []
35
+ end
36
+
37
+ end
38
+
39
+ module Miriam
40
+ class SOAP < Sylfy::Service::SOAPWSDL
41
+ def initialize(options = {})
42
+ super('http://www.ebi.ac.uk/miriamws/main/MiriamWebServices?wsdl', options)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+
50
+ #p Sylfy::Service::PubChem::REST.compound('QIQXTHQIDYTFRH-UHFFFAOYSA-N', :inchikey, 'xrefs/SBURL')["InformationList"]["Information"][0]["SBURL"]
51
+ #p Sylfy::Service::ChEBI::SOAP.new().get_complete_entity(chebiId: "CHEBI:15377")
52
+ #p Sylfy::Service::Miriam::SOAP.new().get_official_data_type_uri("nickname" => "ChEBI")
53
+ #p Sylfy::Service::Miriam::SOAP.new().convert_url(string: "urn:miriam:chebi:CHEBI:28842")
54
+ #p Sylfy::Service::Miriam::SOAP.new().get_official_data_type_uri(nickname: "chebi")
55
+ #p Sylfy::Service::Miriam::SOAP.new().get_miriam_uri(uri: "http://www.ebi.ac.uk/chebi/#CHEBI:17891")
@@ -0,0 +1,64 @@
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 ENSEMBL
18
+ module REST
19
+
20
+ BASEURI = URI.parse("http://beta.rest.ensembl.org")
21
+ HTTP = Net::HTTP.new(BASEURI.host, BASEURI.port)
22
+
23
+ module_function
24
+
25
+ # internal method supporting all ENSEMBLREST service
26
+ #
27
+ # @param get_path [String] service get_path
28
+ #
29
+ # @param option_type [Array] list of option type of service
30
+ #
31
+ # @param option [String] option of service please consult {http://beta.rest.ensembl.org/documentation/info/xref_id}
32
+ #
33
+ # @return [array of Hash] results
34
+ #
35
+ def service(get_path, option_type = [], option={})
36
+
37
+ optionList = []
38
+
39
+ option.each do |k, v|
40
+ optionList.push("#{k}=#{v}") if option_type.include?(k.to_sym)
41
+ end
42
+
43
+
44
+ get_path += "?#{optionList.join(";")}" if !optionList.empty?
45
+
46
+ request = Net::HTTP::Get.new(get_path, {'Content-Type' => option.has_key?('content-type') ? option['content-type'] : 'application/json'})
47
+ response = HTTP.request(request)
48
+
49
+ if response.code != "200"
50
+ #raise ParameterError, "Invalid response: #{response.code}"
51
+ else
52
+ if option.has_key?('content-type') && option['content-type'] != 'application/json'
53
+ return response.body
54
+ else
55
+ return JSON.parse(response.body)
56
+ end
57
+ end
58
+
59
+ end
60
+ end
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,35 @@
1
+ # @author Natapol Pornputtapong <natapol@chalmers.se>
2
+ #
3
+ require 'json'
4
+
5
+ module Sylfy
6
+
7
+ module Service
8
+
9
+ module ENSEMBLREST
10
+ module REST
11
+ module Archive
12
+
13
+ SERVICENAME = 'archive'
14
+
15
+ module_function
16
+
17
+ # Uses the given identifier to return the archived sequence
18
+ #
19
+ # @param id [String] The stable identifier of the entity you wish to retrieve overlapping features
20
+ #
21
+ # @param option [String] option of service please consult {http://beta.rest.ensembl.org/documentation/info/archive_id}
22
+ #
23
+ # @return [array of Hash] results
24
+ #
25
+ def id(id, option = {})
26
+ option_type = [:callback]
27
+ get_path = "/#{SERVICENAME}/id/#{id}"
28
+ return Sylfy::Service::ENSEMBLREST::service(get_path, option_type, option)
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,146 @@
1
+ # @author Natapol Pornputtapong <natapol@chalmers.se>
2
+ #
3
+ require 'json'
4
+
5
+ module Sylfy
6
+
7
+ module Service
8
+
9
+ module ENSEMBL
10
+ module REST
11
+ module Alignment
12
+
13
+ SERVICENAME = 'alignment'
14
+
15
+ module_function
16
+
17
+ # Retrieves genomic alignments as separate blocks based on its location
18
+ #
19
+ # @param species [String] Registry name/aliases used to restrict searches by
20
+ #
21
+ # @param region [String] The region to retrieve sequence for. A maximum of
22
+ # 10Mb is allowed to be requested at any one time
23
+ #
24
+ # @param option [String] option of service please consult {http://beta.rest.ensembl.org/documentation/info/xref_id}
25
+ #
26
+ # @return [array of Hash] results
27
+ #
28
+ def block(species, region, option = {})
29
+ option_type = [:callback, :compact, :compara, :display_species_set, :mask, :method, :species_set, :species_set_group]
30
+ get_path = "/#{SERVICENAME}/block/region/#{species}/#{region}"
31
+ return Sylfy::Service::ENSEMBLREST::service(get_path, option_type, option)
32
+ end
33
+
34
+ # Retrieves genomic alignments as a single slice based on its location
35
+ #
36
+ # @param species [String] Registry name/aliases used to restrict searches by
37
+ #
38
+ # @param region [String] The region to retrieve sequence for. A maximum of
39
+ # 10Mb is allowed to be requested at any one time
40
+ #
41
+ # @param option [String] option of service please consult {http://beta.rest.ensembl.org/documentation/info/xref_id}
42
+ #
43
+ # @return [array of Hash] results
44
+ #
45
+ def slice(species, region, option = {})
46
+ option_type = [:callback, :compact, :compara, :display_species_set, :expanded, :mask, :method, :overlap, :species_set, :species_set_group]
47
+ get_path = "/#{SERVICENAME}/slice/region/#{species}/#{region}"
48
+ return Sylfy::Service::ENSEMBLREST::service(get_path, option_type, option)
49
+ end
50
+
51
+ end
52
+
53
+ module Genetree
54
+
55
+ SERVICENAME = 'genetree'
56
+
57
+ module_function
58
+
59
+ # Retrieves Gene Tree dumps for a given Gene Tree stable identifier
60
+ #
61
+ # @param id [String] Ensembl GeneTree ID
62
+ #
63
+ # @param option [String] option of service please consult {http://beta.rest.ensembl.org/documentation/info/xref_id}
64
+ #
65
+ # @return [array of Hash] results
66
+ #
67
+ def id(id, option = {})
68
+ option_type = [:aligned, :nh_format , :sequence]
69
+ get_path = "/#{SERVICENAME}/id/#{id}"
70
+ option['Content-Type'] = 'text/x-nh'
71
+ return Sylfy::Service::ENSEMBLREST::service(get_path, option_type, option)
72
+ end
73
+
74
+ # Retrieves the Gene Tree that contains the given stable identifier
75
+ #
76
+ # @param id [String] Ensembl gene ID
77
+ #
78
+ # @param option [String] option of service please consult {http://beta.rest.ensembl.org/documentation/info/xref_id}
79
+ #
80
+ # @return [array of Hash] results
81
+ #
82
+ def member(id, option = {})
83
+ option_type = [:db_type, :object_type , :species]
84
+ get_path = "/#{SERVICENAME}/member/id/#{id}"
85
+ option['Content-Type'] = 'text/x-phyloxml+xml'
86
+ return Sylfy::Service::ENSEMBLREST::service(get_path, option_type, option)
87
+ end
88
+
89
+ # Retrieves a Gene Tree containing the Gene identified by the given symbol
90
+ #
91
+ # @param species [String] Registry name/aliases used to restrict searches by
92
+ #
93
+ # @param symbol [String] The external name/symbol to search for
94
+ #
95
+ # @param option [String] option of service please consult {http://beta.rest.ensembl.org/documentation/info/xref_id}
96
+ #
97
+ # @return [array of Hash] results
98
+ #
99
+ def symbol(species, symbol, option = {})
100
+ option_type = [:db_type, :external_db, :object_type]
101
+ get_path = "/#{SERVICENAME}/member/symbol/#{species}/#{symbol}"
102
+ option['Content-Type'] = 'text/x-phyloxml+xml'
103
+ return Sylfy::Service::ENSEMBLREST::service(get_path, option_type, option)
104
+ end
105
+ end
106
+
107
+ module Homology
108
+
109
+ SERVICENAME = 'homology'
110
+
111
+ module_function
112
+
113
+ # Retrieves homology information by ensembl gene id
114
+ #
115
+ # @param id [String] Ensembl GeneTree ID
116
+ #
117
+ # @param option [String] option of service please consult {http://beta.rest.ensembl.org/documentation/info/xref_id}
118
+ #
119
+ # @return [array of Hash] results
120
+ #
121
+ def id(id, option = {})
122
+ option_type = [:aligned, :callback, :format, :sequence, :species, :target_species, :target_taxon, :type]
123
+ get_path = "/#{SERVICENAME}/id/#{id}"
124
+ return Sylfy::Service::ENSEMBLREST::service(get_path, option_type, option)
125
+ end
126
+
127
+ # Retrieves homology information by symbol
128
+ #
129
+ # @param species [String] Registry name/aliases used to restrict searches by
130
+ #
131
+ # @param symbol [String] The external name/symbol to search for
132
+ #
133
+ # @param option [String] option of service please consult {http://beta.rest.ensembl.org/documentation/info/xref_id}
134
+ #
135
+ # @return [array of Hash] results
136
+ #
137
+ def symbol(species, symbol, option = {})
138
+ option_type = [:aligned, :callback, :compara, :external_db, :format, :sequence, :target_species, :target_taxon, :type]
139
+ get_path = "/#{SERVICENAME}/symbol/#{species}/#{symbol}"
140
+ return Sylfy::Service::ENSEMBLREST::service(get_path, option_type, option)
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,73 @@
1
+ # @author Natapol Pornputtapong <natapol@chalmers.se>
2
+ #
3
+ require 'json'
4
+
5
+ module Sylfy
6
+
7
+ module Service
8
+
9
+ module ENSEMBL
10
+ module REST
11
+
12
+ module Xrefs
13
+
14
+ SERVICENAME = 'xrefs'
15
+
16
+ module_function
17
+
18
+ # Perform lookups of Ensembl Identifiers and retrieve their external cross references
19
+ # in other databases
20
+ #
21
+ # @param id [String] ENSEMBL id
22
+ #
23
+ # @param option [String] option of service please consult {http://beta.rest.ensembl.org/documentation/info/xref_id}
24
+ #
25
+ # @return [array of Hash] results
26
+ #
27
+ def id(id, option = {})
28
+ option_type = [:all_levels, :callback, :db_type, :external_db, :object_type, :species]
29
+ get_path = "/#{SERVICENAME}/id/#{id}"
30
+ return Sylfy::Service::ENSEMBLREST::service(get_path, option_type, option)
31
+ end
32
+
33
+ # Performs a lookup based upon the primary accession or display label of an external
34
+ # reference and returning the information we hold about the entry
35
+ #
36
+ # @param species [String] Registry name/aliases used to restrict searches by
37
+ #
38
+ # @param name [String] The external name/primary accession to search for
39
+ #
40
+ # @param option [String] option of service please consult {http://beta.rest.ensembl.org/documentation/info/xref_id}
41
+ #
42
+ # @return [array of Hash] results
43
+ #
44
+ def name(species, name, option = {})
45
+ option_type = [:callback, :db_type, :external_db]
46
+ get_path = "/#{SERVICENAME}/name/#{species}/#{name}"
47
+ return Sylfy::Service::ENSEMBLREST::service(get_path, option_type, option)
48
+ end
49
+
50
+ # Looks up an external symbol and returns all Ensembl objects linked to it.
51
+ # This can be a display name for a gene/transcript/translation, a synonym or an
52
+ # externally linked reference. If a Gene's transcript is linked to the supplied
53
+ # symbol the service will return both Gene and Transcript (it supports transient
54
+ # links).
55
+ #
56
+ # @param species [String] Registry name/aliases used to restrict searches by
57
+ #
58
+ # @param symbol [String] The external name/symbol to search for
59
+ #
60
+ # @param option [String] option of service please consult {http://beta.rest.ensembl.org/documentation/info/xref_id}
61
+ #
62
+ # @return [array of Hash] results
63
+ #
64
+ def symbol(species, symbol, option = {})
65
+ option_type = [:callback, :db_type, :external_db, :object_type]
66
+ get_path = "/#{SERVICENAME}/symbol/#{species}/#{symbol}"
67
+ return Sylfy::Service::ENSEMBLREST::service(get_path, option_type, option)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,52 @@
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
+ module Sylfy
10
+
11
+ module Service
12
+
13
+ module ENSEMBL
14
+
15
+ module REST
16
+
17
+ BASEURI = URI.parse('http://rest.genenames.org')
18
+ HTTP = Net::HTTP.new(BASEURI.host, BASEURI.port)
19
+
20
+ module_function
21
+ # internal method supporting all ENSEMBLREST service
22
+ #
23
+ # @param get_path [String] service get_path
24
+ #
25
+ # @param option_type [Array] list of option type of service
26
+ #
27
+ # @param option [String] option of service please consult {http://beta.rest.ensembl.org/documentation/info/xref_id}
28
+ #
29
+ # @return [array of Hash] results
30
+ #
31
+ def info()
32
+ request = Net::HTTP::Get.new(get_path, {'Content-Type' => option.has_key?('content-type') ? option['content-type'] : 'application/json'})
33
+ response = HTTP.request(request)
34
+
35
+ if response.code != "200"
36
+ #raise ParameterError, "Invalid response: #{response.code}"
37
+ else
38
+ #return YAML::dump(JSON.parse(response.body))
39
+ if option.has_key?('content-type') && option['content-type'] != 'application/json'
40
+ return response.body
41
+ else
42
+ return JSON.parse(response.body)
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -1,7 +1,3 @@
1
- #
2
- # UniSysDB library in Ruby
3
- # Copyright (C) 2012
4
- #
5
1
  # @author Natapol Pornputtapong <natapol@chalmers.se>
6
2
  #
7
3
  require 'open-uri'
@@ -11,6 +7,7 @@ require 'rexml/document'
11
7
 
12
8
  require 'sylfy/service/keggrest/conv'
13
9
  require 'sylfy/service/keggrest/find'
10
+ require 'sylfy/service/keggrest/get'
14
11
  require 'sylfy/service/keggrest/link'
15
12
  require 'sylfy/service/keggrest/list'
16
13
 
@@ -18,16 +15,14 @@ module Sylfy
18
15
 
19
16
  module Service
20
17
 
21
-
22
- # http://rest.kegg.jp/<operation>/<argument>/<argument2 or option>
23
- # <operation> = info | list | find | get | conv | link
24
- # <argument> = <database> | <dbentries>
25
-
18
+ # interface to KEGG API
19
+ # {http://www.kegg.jp/kegg/rest/keggapi.html}
20
+ # info | list | find | get | conv | link
26
21
  module KEGGREST
27
22
 
28
- @@baseuri = "http://rest.kegg.jp"
23
+ BASEURI = "http://rest.kegg.jp"
29
24
 
30
- @@db = [:pathway, :brite, :module, :disease, :drug, :environ,
25
+ DB = [:pathway, :brite, :module, :disease, :drug, :environ,
31
26
  :ko, :genome, :compound, :glycan, :reaction, :rpair,
32
27
  :rclass, :enzyme, :genomes, :genes, :ligand, :kegg, :organism]
33
28
 
@@ -39,12 +34,4 @@ module Sylfy
39
34
  end
40
35
  end
41
36
 
42
- #require '../unisys.rb'
43
-
44
- #p Unisys::Service::RESTKegg.list('hsa:10458+ece:Z5100')
45
- #p Unisys::Service::RESTKegg.find(:genes, 'shiga+toxin')
46
- #p Unisys::Service::RESTKegg.conv('hsa:10458+ece:Z5100','ncbi-gi')
47
- #p Unisys::Service::RESTKegg.get(:G00092)
48
- #Unisys::Service::RESTKegg.getSmallMolecule(:G00092)
49
- #p Unisys::Service::RESTKegg.link('hsa:10458+ece:Z5100', 'pathway')
50
37