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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d2d470deb529a4e69442709c0205f1e6f69b09f
|
4
|
+
data.tar.gz: a8861d929296e449c5269131f5d5ba428c6001b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04fd7926e7d18992116e4f09c5019d020457a16f3872d13cdae8fffbbd959aa1485a7e853afa0939d57c6dbf160d6f7579627b3cbbb371cf22a5173bbbbe9c0a
|
7
|
+
data.tar.gz: e934410e8654a74c486cd2a69af9d18f1228914d9cdb5f4a80b77d54d6814a5db43ae5a373529a2be003202956bd0b39b8bda71fc236fd974e26037f7980e9d9
|
data/README.md
CHANGED
@@ -1,2 +1,4 @@
|
|
1
1
|
sylfy
|
2
2
|
=====
|
3
|
+
|
4
|
+
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US">Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License</a>.
|
data/Rakefile
ADDED
data/lib/sylfy.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
|
-
#
|
3
|
-
# Copyright (C) 2012
|
2
|
+
# Systems biology library for Ruby (Sylfy)
|
3
|
+
# Copyright (C) 2012-2013
|
4
4
|
#
|
5
5
|
# author: Natapol Pornputtapong <natapol@chalmers.se>
|
6
6
|
#
|
@@ -9,35 +9,22 @@
|
|
9
9
|
|
10
10
|
# raise "Please, use ruby 1.9.0 or later." if RUBY_VERSION < "1.9.0"
|
11
11
|
|
12
|
-
# == Overview
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# == Introduction
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
# == Queries
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# === Environmental Variables
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
# === Parameters
|
29
|
-
#
|
30
|
-
#
|
31
12
|
|
32
|
-
$: << File.join(File.expand_path(File.dirname(__FILE__)))
|
33
13
|
|
34
|
-
|
14
|
+
$: << File.join(File.expand_path(File.dirname(__FILE__)))
|
35
15
|
|
16
|
+
require 'csv'
|
36
17
|
|
18
|
+
require 'bio'
|
37
19
|
|
38
|
-
require 'sylfy/
|
20
|
+
require 'sylfy/mathf'
|
21
|
+
require 'sylfy/service'
|
22
|
+
require 'sylfy/feature'
|
23
|
+
require 'sylfy/add'
|
24
|
+
require 'sylfy/utils'
|
25
|
+
require 'sylfy/pattern'
|
39
26
|
|
40
27
|
module Sylfy
|
41
28
|
|
42
29
|
|
43
|
-
end
|
30
|
+
end
|
data/lib/sylfy/add.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
# additional module of bio ruby library
|
4
|
+
module Bio
|
5
|
+
# Class Bio::KEGG
|
6
|
+
class KEGG
|
7
|
+
# Class Bio::KEGG::KGML
|
8
|
+
class KGML
|
9
|
+
# convert KGML to mjson (map json)
|
10
|
+
def to_mjson()
|
11
|
+
mjson = {:identifier => :id}
|
12
|
+
|
13
|
+
# <pathway> attributes
|
14
|
+
mjson[:name] = @name
|
15
|
+
mjson[:org] = @org
|
16
|
+
mjson[:number] = @number
|
17
|
+
mjson[:title] = @title
|
18
|
+
mjson[:link] = @link
|
19
|
+
|
20
|
+
|
21
|
+
mjson[:image] = {}
|
22
|
+
mjson[:image][:source] = @image
|
23
|
+
|
24
|
+
begin
|
25
|
+
dim = open(@image).read()[0x10..0x18].unpack('NN')
|
26
|
+
mjson[:image][:width] = dim[0]
|
27
|
+
mjson[:image][:height] = dim[1]
|
28
|
+
rescue
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
# <entry> attributes
|
34
|
+
@entries.each do |entry|
|
35
|
+
entryinfo = {:id => entry.id, :entryname => entry.name, :link => entry.link, :entrytype => entry.type, :keggid => entry.names}
|
36
|
+
|
37
|
+
entryinfo[:reaction] = entry.reaction if entry.reaction
|
38
|
+
|
39
|
+
# <graphics> attributes
|
40
|
+
graphicinfo = {}
|
41
|
+
if entry.graphics.length == 1
|
42
|
+
graphicinfo[:fill] = entry.graphics[0].bgcolor if entry.graphics[0].bgcolor
|
43
|
+
graphicinfo[:stroke] = entry.graphics[0].fgcolor if entry.graphics[0].fgcolor
|
44
|
+
graphicinfo[:name] = entry.graphics[0].name if entry.graphics[0].name
|
45
|
+
|
46
|
+
case entry.graphics[0].type
|
47
|
+
when 'rectangle'
|
48
|
+
graphicinfo[:type] = :rect
|
49
|
+
graphicinfo[:width] = entry.graphics[0].width
|
50
|
+
graphicinfo[:height] = entry.graphics[0].height
|
51
|
+
graphicinfo[:x] = entry.graphics[0].x
|
52
|
+
graphicinfo[:y] = entry.graphics[0].y
|
53
|
+
when 'roundrectangle'
|
54
|
+
graphicinfo[:type] = :rect
|
55
|
+
graphicinfo[:width] = entry.graphics[0].width
|
56
|
+
graphicinfo[:height] = entry.graphics[0].height
|
57
|
+
graphicinfo[:x] = entry.graphics[0].x
|
58
|
+
graphicinfo[:y] = entry.graphics[0].y
|
59
|
+
graphicinfo[:r] = 10
|
60
|
+
when 'circle'
|
61
|
+
graphicinfo[:type] = :circle
|
62
|
+
graphicinfo[:r] = entry.graphics[0].width/2
|
63
|
+
graphicinfo[:cx] = entry.graphics[0].x
|
64
|
+
graphicinfo[:cy] = entry.graphics[0].y
|
65
|
+
when 'line'
|
66
|
+
graphicinfo[:type] = :path
|
67
|
+
paths = []
|
68
|
+
entry.graphics[0].coords.each {|coord| paths.push(coord.join(" "))}
|
69
|
+
graphicinfo[:fill] = entry.graphics[0].bgcolor if entry.graphics[0].bgcolor
|
70
|
+
graphicinfo[:stroke] = entry.graphics[0].fgcolor if entry.graphics[0].fgcolor
|
71
|
+
graphicinfo[:name] = entry.graphics[0].name if entry.graphics[0].name
|
72
|
+
graphicinfo[:d] ||= ""
|
73
|
+
graphicinfo[:d] += "M #{paths.join("L")}" if !paths.empty?()
|
74
|
+
graphicinfo[:"stroke-width"] = 3
|
75
|
+
graphicinfo[:"stroke-linecap"] = "square"
|
76
|
+
end
|
77
|
+
|
78
|
+
else
|
79
|
+
entry.graphics.each do |graph|
|
80
|
+
if graph.type == 'line'
|
81
|
+
paths = []
|
82
|
+
graph.coords.each {|coord| paths.push(coord.join(" "))}
|
83
|
+
graphicinfo[:type] = :path
|
84
|
+
graphicinfo[:fill] = graph.bgcolor if graph.bgcolor
|
85
|
+
graphicinfo[:stroke] = graph.fgcolor if graph.fgcolor
|
86
|
+
graphicinfo[:name] = graph.name if graph.name
|
87
|
+
graphicinfo[:d] ||= ""
|
88
|
+
graphicinfo[:d] += "M #{paths.join("L")}" if !paths.empty?()
|
89
|
+
graphicinfo[:"stroke-width"] = 3
|
90
|
+
graphicinfo[:"stroke-linecap"] = "square"
|
91
|
+
else
|
92
|
+
raise "Graphic parsinf error to #{id}:#{entry.id}"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
entryinfo[:graphic] = graphicinfo
|
98
|
+
mjson[graphicinfo[:type]] ||= []
|
99
|
+
mjson[graphicinfo[:type]].push(entryinfo)
|
100
|
+
|
101
|
+
# <component> attributes
|
102
|
+
|
103
|
+
end
|
104
|
+
return mjson
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
# author: Natapol Pornputtapong <natapol.por@gmail.com>
|
2
|
+
#
|
3
|
+
# Documentation: Natapol Pornputtapong (RDoc'd and embellished by William Webber)
|
4
|
+
#
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module Sylfy
|
8
|
+
# Model template
|
9
|
+
class DataModel
|
10
|
+
|
11
|
+
class DuplicateError < Exception
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :data
|
16
|
+
# Initialize function
|
17
|
+
# @param data [Hash] data object
|
18
|
+
def initialize(data = nil)
|
19
|
+
@data = {class: self.class.to_sym}
|
20
|
+
if data
|
21
|
+
data.each_pair do |field, value|
|
22
|
+
self.send "#{field}=".to_sym, value if self.method_defined?(field)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
# convert data object to JSON
|
29
|
+
# @return [JSON]
|
30
|
+
def to_json()
|
31
|
+
return @data.to_json
|
32
|
+
end
|
33
|
+
# @return [String]
|
34
|
+
def to_str()
|
35
|
+
return JSON::pretty_generate(@data)
|
36
|
+
end
|
37
|
+
# @return [Hash]
|
38
|
+
def to_hash()
|
39
|
+
return @data
|
40
|
+
end
|
41
|
+
# Test if data object is valid
|
42
|
+
def valid?()
|
43
|
+
if @@validates
|
44
|
+
result = true
|
45
|
+
@@validates.each_pair do |field, rules|
|
46
|
+
rules.each_pair do |type, rule|
|
47
|
+
case type.to_sym
|
48
|
+
when :type
|
49
|
+
if rule.kind_of?(Array)
|
50
|
+
rule.each {|e| result &&= self.assert_type_of?(e, @data[field.to_sym])}
|
51
|
+
else
|
52
|
+
result &&= self.assert_type_of?(rule, @data[field.to_sym])
|
53
|
+
end
|
54
|
+
when :presence
|
55
|
+
result &&= !(rule ^ (@data[field.to_sym] != nil && !@data[field.to_sym].empty?))
|
56
|
+
when :format
|
57
|
+
if rule.kind_of?(Array)
|
58
|
+
rule.each {|e| result &&= self.assert_match?(e, @data[field.to_sym])}
|
59
|
+
else
|
60
|
+
result &&= self.assert_match?(rule, @data[field.to_sym])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
return result
|
66
|
+
else
|
67
|
+
return true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def assert_type_of?(crass, value)
|
72
|
+
if crass < DataModel
|
73
|
+
return crass.new(value).valid?
|
74
|
+
else
|
75
|
+
return value.kind_of?(crass)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
protected :assert_type_of?
|
80
|
+
|
81
|
+
def assert_match?(pattern, value)
|
82
|
+
return value.kind_of?(String) && value =~ pattern ? true : false
|
83
|
+
end
|
84
|
+
|
85
|
+
protected :assert_match?
|
86
|
+
|
87
|
+
def self.has_one(*attrs)
|
88
|
+
@@has_one ||= []
|
89
|
+
attrs.each do |attr|
|
90
|
+
if !self.method_defined?(attr)
|
91
|
+
@@has_one.push(attr)
|
92
|
+
self.class_eval do
|
93
|
+
define_method(attr) do
|
94
|
+
@data[attr]
|
95
|
+
end
|
96
|
+
|
97
|
+
define_method("#{attr}=") do |param|
|
98
|
+
@data[attr] = param.kind_of?(DataModel) ? param.to_hash : param
|
99
|
+
end
|
100
|
+
end
|
101
|
+
else
|
102
|
+
raise DuplicateError, "#{attr.inspect} is already defined."
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.has_many(*attrs)
|
108
|
+
@@has_many ||= []
|
109
|
+
attrs.each do |attr|
|
110
|
+
if !self.method_defined?(attr)
|
111
|
+
@@has_many.push(attr)
|
112
|
+
self.class_eval do
|
113
|
+
define_method(attr) do
|
114
|
+
@data[attr] = []
|
115
|
+
end
|
116
|
+
|
117
|
+
define_method("#{attr}=") do |*param|
|
118
|
+
@data[attr] = param.flatten
|
119
|
+
end
|
120
|
+
|
121
|
+
define_method("#{attr}_add") do |*param|
|
122
|
+
@data[attr] += param.flatten
|
123
|
+
end
|
124
|
+
end
|
125
|
+
else
|
126
|
+
raise DuplicateError, "#{attr.inspect} is already defined."
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def self.validates(*attrs, rules)
|
132
|
+
@@validates ||= {}
|
133
|
+
attrs.each do |attr|
|
134
|
+
@@validates[attr] ||= {}
|
135
|
+
@@validates[attr].merge!(rules)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
#class << self;self;end.send :protected, :subjects_xml, :subjects_html
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,128 @@
|
|
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
|
+
# This class is used by Ondine
|
10
|
+
|
11
|
+
module Sylfy
|
12
|
+
|
13
|
+
class Feature
|
14
|
+
|
15
|
+
attr_reader :member, :listnumber, :length
|
16
|
+
|
17
|
+
def initialize(listnumber, member, length)
|
18
|
+
@listnumber = listnumber
|
19
|
+
@member = member
|
20
|
+
@length = length
|
21
|
+
end
|
22
|
+
|
23
|
+
protected :initialize
|
24
|
+
|
25
|
+
def self.open(filename, options)
|
26
|
+
#@listnumber = {:path => { "path:map00010"=>["Glycolysis / Gluconeogenesis"], ...}, "gene" => {"path:map00010"=>["ko:K00001", "ko:K00002", ...], ...}, "comp" => {... }
|
27
|
+
#"ko:K02790"=>{"gene"=>["path:map00010", "path:map00500", "path:map02060"]}
|
28
|
+
listnumber = {}
|
29
|
+
member = {}
|
30
|
+
length = {}
|
31
|
+
# type group member
|
32
|
+
CSV.open(filename, "rb", options).readlines.each do |row|
|
33
|
+
length[row[0]] = 0 if !length.has_key?(row[0])
|
34
|
+
listnumber[row[0]] = {} if !listnumber.has_key?(row[0])
|
35
|
+
listnumber[row[0]][row[1]] = [] if !listnumber[row[0]].has_key?(row[1])
|
36
|
+
listnumber[row[0]][row[1]].push(row[2])
|
37
|
+
|
38
|
+
if row[0] != 'path'
|
39
|
+
if !member.has_key?(row[2]) &&
|
40
|
+
member[row[2]] = {}
|
41
|
+
member[row[2]].default = []
|
42
|
+
length[row[0]] += 1
|
43
|
+
end
|
44
|
+
|
45
|
+
member[row[2]][row[0]] = [] if !member[row[2]].has_key?(row[0])
|
46
|
+
member[row[2]][row[0]].push(row[1])
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
return Sylfy::Feature.new(listnumber, member, length)
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.fromKEGG(species = 'ref')
|
54
|
+
|
55
|
+
listnumber = {}
|
56
|
+
member = {}
|
57
|
+
complist = Service::KEGGREST.link("compound/pathway")
|
58
|
+
|
59
|
+
if species == 'ref'
|
60
|
+
pathwaylist = Service::KEGGREST.list("pathway")
|
61
|
+
genelist = Service::KEGGREST.link("ko/pathway")
|
62
|
+
genelist.delete_if{|k, v| k !~ /^path:map/ }
|
63
|
+
complist.delete_if{|k, v| k !~ /^path:map/ }
|
64
|
+
|
65
|
+
else
|
66
|
+
pathwaylist = Service::KEGGREST.list("pathway/#{species}")
|
67
|
+
genelist = Service::KEGGREST.link("#{species}/pathway")
|
68
|
+
tmp = {}
|
69
|
+
complist.each_pair do |k, v|
|
70
|
+
tmp["path:#{species}#{k[-6..-1]}"] = v if !tmp.has_key?("path:#{species}#{k[-6..-1]}")
|
71
|
+
end
|
72
|
+
complist = tmp
|
73
|
+
end
|
74
|
+
|
75
|
+
listnumber["path"] = pathwaylist
|
76
|
+
listnumber["gene"] = genelist
|
77
|
+
listnumber["comp"] = complist
|
78
|
+
|
79
|
+
length = {"path" => pathwaylist.length}
|
80
|
+
genelist.each_pair do |k, v|
|
81
|
+
v.each do |entry|
|
82
|
+
if !member.has_key?(entry)
|
83
|
+
member[entry] = {}
|
84
|
+
member[entry].default = []
|
85
|
+
end
|
86
|
+
|
87
|
+
member[entry]["gene"] = [] if !member[entry].has_key?("gene")
|
88
|
+
member[entry]["gene"].push(k)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
@length["gene"] = member.length
|
93
|
+
|
94
|
+
complist.each_pair do |k, v|
|
95
|
+
v.each do |entry|
|
96
|
+
if !member.has_key?(entry)
|
97
|
+
member[entry] = {}
|
98
|
+
member[entry].default = []
|
99
|
+
end
|
100
|
+
|
101
|
+
member[entry]["comp"] = [] if !member[entry].has_key?("comp")
|
102
|
+
member[entry]["comp"].push(k)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
@length["comp"] = member.length - @length["gene"]
|
107
|
+
|
108
|
+
return Sylfy::Feature.new(listnumber, member, length)
|
109
|
+
|
110
|
+
end
|
111
|
+
#def enrichAnal(array, type = [])
|
112
|
+
# featureCount = {}
|
113
|
+
# array.each do |entry|
|
114
|
+
# if featureMember.has_key?(entry[1])
|
115
|
+
#
|
116
|
+
# end
|
117
|
+
#
|
118
|
+
# featureMember[entry[0]]
|
119
|
+
# featureCount[row[0]] = {} if !featureCount.has_key?(row[0])
|
120
|
+
# featureCount[row[0]][row[1]] = 0 if !featureCount[row[0]].has_key?(row[1])
|
121
|
+
# end
|
122
|
+
#
|
123
|
+
#end
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
|