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.
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,40 @@
1
+ #
2
+ # UniSysDB library in Ruby
3
+ # Copyright (C) 2012
4
+ #
5
+ # author: Natapol Pornputtapong <natapol@chalmers.se>
6
+ #
7
+ # Documentation: Natapol Pornputtapong (RDoc'd and embellished by William Webber)
8
+ #
9
+
10
+ require 'gsl'
11
+
12
+ module Sylfy
13
+ # additional Mathematic function
14
+ module Mathf
15
+
16
+ # calculate log factorial
17
+ # @param n [Int]
18
+ def self.lnfactorial(n)
19
+ return GSL::Sf::lngamma(n+1)
20
+ end
21
+
22
+ # calculate log combinatorial
23
+ # @param n [Int] the population size
24
+ # @param r [Int] the number of draws
25
+ def self.lncombinatorial(n, r)
26
+ return lnfactorial(n) - lnfactorial(r) - lnfactorial(n-r)
27
+ end
28
+
29
+ # hypergeometric function
30
+ # @param nn [Int] the population size
31
+ # @param kk [Int] the number of success states in the population
32
+ # @param n [Int] the number of draws
33
+ # @param k [Int] the number of successes
34
+ def self.hypergeometric(k, nn, kk, n)
35
+ log_h = lncombinatorial(kk, k) + lncombinatorial(nn-kk, n-k) - lncombinatorial(nn, n)
36
+ return (Math::E ** log_h)
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,14 @@
1
+ #
2
+ # Sylfy library in Ruby
3
+ # Copyright (C) 2012
4
+ #
5
+ # @author Natapol Pornputtapong <natapol@chalmers.se>
6
+ #
7
+
8
+ module Sylfy
9
+ module Pattern
10
+ INCHI = /^InChI\=1S\/[A-Za-z0-9\.\+]+(\/[cnpqbtmsih][A-Za-z0-9\-\+\(\)\,\?\*\;\.]+)*$/
11
+ SPINCHI = /^InChI\=1[S]?\/[A-Za-z0-9\.\+]+(\/[cnpqbtmsih][A-Za-z0-9\-\+\(\)\,\?\*\;\.]+)*$/
12
+ INCHIKEY = /^[A-Z]{14}\-[A-Z]{10}(\-[A-N])?/
13
+ end
14
+ end
@@ -0,0 +1,34 @@
1
+ #
2
+ # UniSysDB library in Ruby
3
+ # Copyright (C) 2012
4
+ #
5
+ # author: Natapol Pornputtapong <natapol.por@gmail.com>
6
+ #
7
+ # Documentation: Natapol Pornputtapong (RDoc'd and embellished by William Webber)
8
+ #
9
+
10
+ require 'rubabel'
11
+
12
+ #require 'sylfy/service/keggrest'
13
+ require 'sylfy/service/ensemblrest'
14
+ require 'sylfy/service/pubchem'
15
+ require 'sylfy/service/ebisoap'
16
+ require 'sylfy/service/lipidmaprest'
17
+ require 'sylfy/service/unichemrest'
18
+ require 'sylfy/service/biocycrest'
19
+ require 'sylfy/service/cactusncirest'
20
+ require 'sylfy/service/rest'
21
+
22
+ module Sylfy
23
+ # A module supports as interfaces for web services
24
+ module Service
25
+ # Raise when puts wrong parameter
26
+ class ParameterError < Exception
27
+
28
+ end
29
+ # Raise when services return 404 error
30
+ class DataNotFound < Exception
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,41 @@
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 'rexml/document'
9
+
10
+ module Sylfy
11
+
12
+ module Service
13
+
14
+ module Biocyc
15
+ module REST
16
+ @@baseuri = 'http://websvc.biocyc.org/apixml?'
17
+ #~ @@prefix = { 'CAS Registry Number'=>'cas:', 'KEGG COMPOUND'=>'kegg.compound:', 'KEGG DRUG'=>'kegg.drug:', 'DrugBank'=>'drugbank:', 'PDBeChem'=>'pdb-ccd:' }
18
+
19
+ module_function
20
+
21
+ def apixml(apifn, id, detail = 'none')
22
+ detail = 'none' if !['none', 'low', 'full'].include?(detail)
23
+ uri = "#{@@baseuri}fn=#{apifn}&id=#{id}&detail=#{detail}"
24
+ begin
25
+ doc = REXML::Document.new(URI.parse(uri).read().strip())
26
+ rescue OpenURI::HTTPError
27
+ raise Unisys::ServiceException, "Id #{id} not found."
28
+ end
29
+
30
+ return doc
31
+
32
+ end
33
+
34
+ def reaction_reactants_and_products(id, detail = 'none')
35
+ RESTBioCyc.apixml('enzymes-of-reaction', id, detail)
36
+ #~ RESTBioCyc.apixml('reaction-reactants-and-products', id, detail)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,64 @@
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 CIR
17
+
18
+ module REST
19
+ @@baseuri = "http://cactus.nci.nih.gov/chemical/structure"
20
+ @@representation_type = [:stdinchi, :stdinchikey, :smiles, :ficts, :ficus, :uuuuu, :sdf, :names, :hashisy, :image, :iupac_name]
21
+
22
+ module_function
23
+
24
+ def perform(identifier, representation, xml = false)
25
+ if @@representation_type.include?(representation.to_sym)
26
+ uri = "#{@@baseuri}/#{URI.escape(identifier, "[] ")}/#{representation.to_s}"
27
+
28
+ begin
29
+ return URI.parse(uri).read().strip().chomp.split(/\n/)
30
+ rescue OpenURI::HTTPError
31
+ return []
32
+ end
33
+
34
+ else
35
+ raise Sylfy::Service::ParameterError, "Wrong representation type. Should be #{@@representation_type.join(', ')}"
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ module_function
42
+
43
+ def getnames(inchi)
44
+ result = []
45
+ inchi = Rubabel[inchi, :inchi].to_s(:inchikey) if inchi =~ /^InChI\=1S\/[A-Za-z0-9]+(\/[cnpqbtmsih][A-Za-z0-9\-\+\(\)\,]+)+$/
46
+
47
+ if inchi =~ /^[A-Z]{14}\-[A-Z]{10}(\-[A-N])?/
48
+ result += REST.perform(inchi, :iupac_name)
49
+ result += REST.perform(inchi, :names)
50
+ end
51
+
52
+ return result.uniq[0..21]
53
+ end
54
+
55
+ end
56
+ end
57
+ end
58
+
59
+ #require './unisys.rb'
60
+ #
61
+ #a = Unisys::Service::RESTCactusNCI
62
+ #puts a.perform('Aspirin', :stdinchi)
63
+ #puts a.perform('(2E)-eicosenoyl-CoA', :stdinchi)
64
+ #puts a.perform('18-HEPE', :names)
@@ -0,0 +1,156 @@
1
+ # @author Natapol Pornputtapong <natapol@chalmers.se>
2
+ #
3
+ require 'open-uri'
4
+ require 'net/http'
5
+ require 'rexml/document'
6
+ require 'csv'
7
+
8
+ module Sylfy
9
+
10
+ module CBioPortal
11
+
12
+ module REST
13
+
14
+ BASEURI = URI.parse('http://www.cbioportal.org')
15
+ #BASEURI = URI.parse('http://www.cbioportal.org/public-portal/webservice.do?')
16
+ HTTP = Net::HTTP.new(BASEURI.host, BASEURI.port)
17
+
18
+ module_function
19
+ # internal method supporting all ENSEMBLREST service
20
+ #
21
+ # @param get_path [String] service get_path
22
+ #
23
+ # @param option_type [Array] list of option type of service
24
+ #
25
+ # @param option [String] option of service please consult {http://beta.rest.ensembl.org/documentation/info/xref_id}
26
+ #
27
+ # @return [array of Hash] results
28
+ #
29
+ def service(get_path, csv_opts = {})
30
+ request = Net::HTTP::Get.new(get_path)
31
+ response = HTTP.request(request)
32
+
33
+ if response.code != "200"
34
+ raise Sylfy::Service::ParameterError, "Invalid response: #{response.code}"
35
+ else
36
+ return CSV.parse(response.body, {col_sep: "\t", skip_lines: /^#/, headers: true}.merge(csv_opts))
37
+ end
38
+ end
39
+
40
+ # internal method supporting all ENSEMBLREST service
41
+ #
42
+ # @param get_path [String] service get_path
43
+ #
44
+ # @param option_type [Array] list of option type of service
45
+ #
46
+ # @param option [String] option of service please consult {http://beta.rest.ensembl.org/documentation/info/xref_id}
47
+ #
48
+ # @return [array of Hash] results
49
+ #
50
+ def getTypesOfCancer()
51
+ get_path = "/public-portal/webservice.do?cmd=getTypesOfCancer"
52
+ return Sylfy::CBioPortal::REST.service(get_path)
53
+ end
54
+
55
+ # internal method supporting all ENSEMBLREST service
56
+ #
57
+ # @param get_path [String] service get_path
58
+ #
59
+ # @param option_type [Array] list of option type of service
60
+ #
61
+ # @param option [String] option of service please consult {http://beta.rest.ensembl.org/documentation/info/xref_id}
62
+ #
63
+ # @return [array of Hash] results
64
+ #
65
+ def getCancerStudies()
66
+ get_path = "/public-portal/webservice.do?cmd=getCancerStudies"
67
+ return Sylfy::CBioPortal::REST.service(get_path)
68
+ end
69
+
70
+ # internal method supporting all ENSEMBLREST service
71
+ #
72
+ # @param cancer_study_id [String] service get_path
73
+ #
74
+ # @return [array of Hash] results
75
+ #
76
+ def getGeneticProfiles(cancer_study_id)
77
+ get_path = "/public-portal/webservice.do?cmd=getGeneticProfiles&cancer_study_id=#{cancer_study_id}"
78
+ return Sylfy::CBioPortal::REST.service(get_path)
79
+ end
80
+
81
+ # internal method supporting all ENSEMBLREST service
82
+ #
83
+ # @param cancer_study_id [String] service get_path
84
+ #
85
+ # @return [array of Hash] results
86
+ #
87
+ def getCaseLists(cancer_study_id)
88
+ get_path = "/public-portal/webservice.do?cmd=getCaseLists&cancer_study_id=#{cancer_study_id}"
89
+ return Sylfy::CBioPortal::REST.service(get_path)
90
+ end
91
+
92
+
93
+ # internal method supporting all ENSEMBLREST service
94
+ #
95
+ # @param case_set_id [String] case set ID (required)
96
+ #
97
+ # @param genetic_profile_id [String] one or more genetic profile IDs (required). Multiple genetic profile IDs must be separated by comma (,) characters, or URL encoded spaces, e.g. +
98
+ #
99
+ # @param gene_list [String] one or more genes, specified as HUGO Gene Symbols or Entrez Gene IDs (required). Multiple genes must be separated by comma (,) characters, or URL encoded spaces, e.g. +
100
+ #
101
+ # @return [array of Hash] results
102
+ #
103
+ def getProfileData(case_set_id, genetic_profile_id, gene_list)
104
+ get_path = "/public-portal/webservice.do?cmd=getProfileData&case_set_id=#{case_set_id}&genetic_profile_id=#{genetic_profile_id}&gene_list=#{gene_list}"
105
+ return Sylfy::CBioPortal::REST.service(get_path)
106
+ end
107
+
108
+ # internal method supporting all ENSEMBLREST service
109
+ #
110
+ # @param case_set_id [String] case set ID (required)
111
+ #
112
+ # @param genetic_profile_id [String] one or more genetic profile IDs (required). Multiple genetic profile IDs must be separated by comma (,) characters, or URL encoded spaces, e.g. +
113
+ #
114
+ # @param gene_list [String] one or more genes, specified as HUGO Gene Symbols or Entrez Gene IDs (required). Multiple genes must be separated by comma (,) characters, or URL encoded spaces, e.g. +
115
+ #
116
+ # @return [array of Hash] results
117
+ #
118
+ def getMutationData(case_set_id, genetic_profile_id, gene_list)
119
+ get_path = "/public-portal/webservice.do?cmd=getMutationData&case_set_id=#{case_set_id}&genetic_profile_id=#{genetic_profile_id}&gene_list=#{gene_list}"
120
+ return Sylfy::CBioPortal::REST.service(get_path)
121
+ end
122
+
123
+ # internal method supporting all ENSEMBLREST service
124
+ #
125
+ # @param case_set_id [String] case set ID (required)
126
+ #
127
+ # @return [array of Hash] results
128
+ #
129
+ def getClinicalData(case_set_id)
130
+ get_path = "/public-portal/webservice.do?cmd=getClinicalData&case_set_id=#{case_set_id}"
131
+ return Sylfy::CBioPortal::REST.service(get_path)
132
+ end
133
+
134
+ # internal method supporting all ENSEMBLREST service
135
+ #
136
+ # @param case_set_id [String] case set ID (required)
137
+ #
138
+ # @param genetic_profile_id [String] one or more genetic profile IDs (required). Multiple genetic profile IDs must be separated by comma (,) characters, or URL encoded spaces, e.g. +
139
+ #
140
+ # @param gene_list [String] one or more genes, specified as HUGO Gene Symbols or Entrez Gene IDs (required). Multiple genes must be separated by comma (,) characters, or URL encoded spaces, e.g. +
141
+ #
142
+ # @return [array of Hash] results
143
+ #
144
+ def getMutationData(case_set_id, genetic_profile_id, gene_list)
145
+ get_path = "/public-portal/webservice.do?cmd=getMutationData&case_set_id=#{case_set_id}&genetic_profile_id=#{genetic_profile_id}&gene_list=#{gene_list}"
146
+ return Sylfy::CBioPortal::REST.service(get_path)
147
+ end
148
+ end
149
+
150
+ end
151
+
152
+
153
+ end
154
+
155
+
156
+ Sylfy::CBioPortal::REST.getMutationData("BRAF", "skcm_tcga_mutations").each {|e| p e; exit}
@@ -0,0 +1,106 @@
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 ChEMBL
17
+ module REST
18
+
19
+
20
+ @@baseuri = "https://www.ebi.ac.uk/chemblws"
21
+
22
+ module_function
23
+
24
+ def perform(input)
25
+
26
+ uri = "#{@@baseuri}/#{input}"
27
+ p uri
28
+ begin
29
+ return URI.parse(uri).read().strip()
30
+ rescue OpenURI::HTTPError => e
31
+ raise ServiceException, e
32
+ end
33
+ end
34
+
35
+ private :perform
36
+ # Method for setting inchi data member
37
+ #
38
+ # == Parameters:
39
+ # id::
40
+ # LipidMap id to search
41
+ # :id, :dataPrimarySource, :xrefs, :relations :inchi, :formula, :smiles, :inchiKey :names
42
+
43
+ def compounds(id, domain = '', target = '', json = true)
44
+ input = 'compounds'
45
+ if [:stdinchikey, :smiles, :substructure].include?(domain.to_sym)
46
+ input += "/#{domain}/#{id}"
47
+ input += ".json" if json
48
+ elsif domain.to_sym == :similaritiy
49
+ input += target.class == Integer ? "/#{domain}/#{id}/#{target}" : "/#{domain}/#{id}"
50
+ input += ".json" if json
51
+ elsif target.to_sym == :bioactivities
52
+ input += "/#{id}/bioactivities"
53
+ input += ".json" if json
54
+ elsif target == :image || target =~ /^image?dimensions=(\d+)$/ || target =~ /^image=(\d+)$/
55
+ if $1
56
+ input += "/#{id}/image?dimensions=#{$1}"
57
+ else
58
+ input += "/#{id}/image?dimensions=300"
59
+ end
60
+ else
61
+ input += "/#{id}"
62
+ input += ".json" if json
63
+ end
64
+
65
+ return perform(input)
66
+
67
+ end
68
+
69
+ def targets(id, domain = '', bioactiv = false, json = true)
70
+ input = 'targets'
71
+ if id == ''
72
+
73
+ elsif [:uniprot, :refseq].include?(domain.to_sym)
74
+ input += "/#{domain}/#{id}"
75
+
76
+ elsif bioactiv
77
+ input += "/#{id}/bioactivities"
78
+ else
79
+ input += "/#{id}"
80
+ end
81
+
82
+ input += ".json" if json
83
+ return perform(input)
84
+
85
+ end
86
+
87
+ def assays(id, bioactiv = false, json = true)
88
+ input = "assays/#{id}"
89
+ input += "/bioactivities" if bioactiv
90
+ input += ".json" if json
91
+ return perform(input)
92
+
93
+ end
94
+ end
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+
101
+ #require 'json'
102
+ #require './unisys.rb'
103
+ #
104
+ #p JSON.load(Unisys::Service::RESTChEMBL.compounds('CHEMBL1'))
105
+ #p JSON.load(Unisys::Service::RESTChEMBL.targets('CHEMBL2477'))
106
+ #p JSON.load(Unisys::Service::RESTChEMBL.assays('CHEMBL1217643'))