scbi_go 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83904a2d1485297ab2d08126daf42483ef2c0ed4
4
+ data.tar.gz: 860216b0165531eec340e9899bd491b129125813
5
+ SHA512:
6
+ metadata.gz: 082e8c723d017e82c631044455b9624864c3ea409841da476de9db94b789610dad4eb2b3e0ddcb1fe0559b7f3eb7f7e711e8e3e93fe89ebd7f79c4c5d05db018
7
+ data.tar.gz: 71812aeb8eac6e72485c681ebcc94a2eab2c0843640f51a850ad2130bba48ef8e4c537e0a50e26e7f1fee195eccf6b56384080174859dc10a8090530ac2b2b58
data/.autotest ADDED
@@ -0,0 +1 @@
1
+ require "autotest/bundler"
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in scbi_go.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,32 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ watch(%r{^spec/.+_spec\.rb$})
29
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
30
+ watch(%r{^lib/.*/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
31
+ watch('spec/spec_helper.rb') { "spec" }
32
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 dariogf
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # ScbiGo
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'scbi_go'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install scbi_go
20
+
21
+ ## Usage
22
+
23
+ See spec files to usage examples
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/scbi_go/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
8
+
Binary file
@@ -0,0 +1,25 @@
1
+ module ScbiGo
2
+ class AncestorsGraph < BaseGraph
3
+
4
+ # override the way that nodes are painted in dot
5
+ def build_dot_lines(nodes)
6
+
7
+ res =[]
8
+ res << "digraph #{@graph_name} {"
9
+ nodes.each do |node|
10
+ res << "#{node.id.gsub(':','_')}[label=\"#{node.id}\n#{node.name}\"];"
11
+ end
12
+
13
+ nodes.each do |node|
14
+
15
+ node.is_a.each do |parent|
16
+ res << "#{parent.id.gsub(':','_')} -> #{node.id.gsub(':','_')} ;"
17
+ end
18
+ end
19
+
20
+ res << "}"
21
+ return res
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,37 @@
1
+ module ScbiGo
2
+ class BaseGraph
3
+
4
+ #create a dot file and optional pdf file
5
+ def initialize(nodes, file_name=nil, name='my_graph', generate_pdf=false)
6
+ @graph_name=name
7
+
8
+ if !nodes.empty?
9
+ res =[]
10
+ res += build_dot_lines(nodes)
11
+ if !file_name.nil?
12
+ f=File.new(file_name,'w')
13
+ f.puts res
14
+ f.close
15
+
16
+ if generate_pdf
17
+ system("dot -Tpdf #{file_name} -o #{file_name}.pdf")
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+
24
+ # define the way that nodes are painted in dot
25
+ def build_dot_lines(nodes)
26
+
27
+ res =[]
28
+ res << "graph #{@graph_name} {"
29
+ nodes.each do |node|
30
+ res << "#{node.id.gsub(':','_')}[label=\"#{node.id}\n#{node.name}\"];"
31
+ end
32
+ res << "}"
33
+ return res
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,24 @@
1
+ module ScbiGo
2
+ class DescendantsGraph < BaseGraph
3
+
4
+ # override the way that nodes are painted in dot
5
+ def build_dot_lines(nodes)
6
+ res = []
7
+ res << "digraph #{@graph_name} {"
8
+
9
+ nodes.each do |node|
10
+ res << "#{node.id.gsub(':','_')}[label=\"#{node.id}\n#{node.name}\"];"
11
+ end
12
+ nodes.each do |node|
13
+ node.children.each do |child|
14
+ res << "#{node.id.gsub(':','_')} -> #{child.id.gsub(':','_')} ;"
15
+ end
16
+ end
17
+
18
+ res << "}"
19
+
20
+ return res
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,104 @@
1
+ require 'zlib'
2
+
3
+ module ScbiGo
4
+ class GeneOntology
5
+
6
+ attr_accessor :gos, :header, :base_terms
7
+
8
+ # load a new gene ontology fiel in obo format, in gz or un-gzipped format
9
+ def initialize(filename='lib/data/go.obo.gz')
10
+
11
+ if !File.exists?(filename)
12
+ raise "File does not exists: #{filename}"
13
+ end
14
+ #t1=Time.now
15
+ @filename=filename
16
+ begin
17
+ my_obo_file=Zlib::GzipReader.open(filename)
18
+ rescue Zlib::GzipFile::Error # not in gzip file
19
+ my_obo_file=File.open(@filename) # open as normal file
20
+ end
21
+
22
+
23
+ #@cache_filename='/dev/shm/'+File.basename(@filename)+'.dump'
24
+ @base_terms=[]
25
+ @gos={}
26
+ @header=nil
27
+
28
+ # if File.exists?(@cache_filename)
29
+ # puts "using cache: #{@cache_filename}"
30
+ # o=Marshal.load(File.new(@cache_filename))
31
+
32
+ # @base_terms=o.base_terms
33
+ # @gos=o.gos
34
+ # @header=o.header
35
+
36
+ # else
37
+
38
+ # Parse Obo data file with external lib
39
+ obo = Obo::Parser.new(filename)
40
+ go_list = obo.elements(my_obo_file).to_a
41
+ obo=nil
42
+
43
+ #first element is header
44
+ @header = ScbiGo::Header.new(go_list.shift)
45
+
46
+ # other elements are go terms
47
+ go_list.each do |go_term|
48
+ add_go_term(go_term)
49
+ end
50
+
51
+ add_children_relations
52
+
53
+ go_list=nil
54
+
55
+ #save cache file
56
+ # Marshal.dump(self, File.new(@cache_filename,'w'))
57
+ # end
58
+ #puts "Load time #{Time.now-t1} seg"
59
+ end
60
+
61
+ # find a go_term by it name
62
+ def find_go(go_id)
63
+ @gos[go_id]
64
+ end
65
+
66
+ # add new term
67
+ def add_go_term(go_term)
68
+ if go_term.name =='Term' && go_term['is_obsolete'].nil?
69
+ new_term=ScbiGo::GoTerm.new(go_term, self)
70
+ @gos[go_term['id']] = new_term
71
+ if new_term.base_term?
72
+ @base_terms<<new_term
73
+ end
74
+ end
75
+ end
76
+
77
+ #convert a list of go names to terms, ignore not found gos
78
+ def go_list_to_terms(go_list)
79
+ res=[]
80
+
81
+ go_list.each do |s|
82
+ if s.is_a?(GoTerm)
83
+ res << s
84
+ else
85
+ res << find_go(s)
86
+ end
87
+ end
88
+
89
+ return res.compact
90
+ end
91
+
92
+ private
93
+
94
+ # add children links to parents once Go file is loaded
95
+ def add_children_relations
96
+ @gos.each do |go_id, go|
97
+ go.is_a.each do |parent|
98
+ parent.add_child(go)
99
+ end
100
+ end
101
+ end
102
+
103
+ end
104
+ end
@@ -0,0 +1,90 @@
1
+ module ScbiGo
2
+ class GoListReducer < GeneOntology
3
+
4
+
5
+ # return the subset of branches not contained in another branch of the list
6
+ def simplify_branches(branches)
7
+ res=[]
8
+
9
+ # inverse sort branches by length
10
+ sorted_b = branches.sort{|b1,b2| -b1.length<=>-b2.length}
11
+
12
+ # simplify by iteration from larger to smaller
13
+
14
+ sorted_b.each do |branch|
15
+ # select other branches in res that contains all elements of this branch
16
+ matches=res.select{|e| (e & branch).length==branch.length}
17
+
18
+ # add it to res if no match found
19
+ if matches.empty?
20
+ res << branch
21
+ end
22
+ end
23
+
24
+ return res
25
+ end
26
+
27
+
28
+ # given a go_list, returns the leaves of all the branches defined by them
29
+ def reduce_branches(go_list)
30
+ terms = go_list_to_terms(go_list)
31
+
32
+ res=[]
33
+ branches=[]
34
+
35
+ if !terms.empty?
36
+ #get all branches for each terms
37
+ terms.each do |term|
38
+ branches += term.all_branches_to_top
39
+ end
40
+
41
+ branches=simplify_branches(branches)
42
+
43
+ #return first unique element of each branch
44
+ res=branches.map{|b| b.first}.uniq
45
+ end
46
+
47
+ return res
48
+ end
49
+
50
+ # return all branches that match with the elements of go_list
51
+ # is the same as reduce_branches, but returning whole branches
52
+ def all_matching_branches(go_list)
53
+ leaves = reduce_branches(go_list)
54
+ res=[]
55
+
56
+ leaves.each do |leave|
57
+ res += leave.all_branches_to_top
58
+ end
59
+
60
+ return simplify_branches(res)
61
+ end
62
+
63
+ # get the branch/es that match more elements in the go_list
64
+ def best_matching_branches(go_list)
65
+ matching_count = {}
66
+
67
+ terms=go_list_to_terms(go_list)
68
+
69
+ leaves = reduce_branches(go_list)
70
+
71
+ branches = leaves.first.all_branches_to_top
72
+
73
+ branches.each do |branch|
74
+ intersect_count = (branch & terms).count
75
+
76
+ if intersect_count>0
77
+ matching_count[intersect_count] = [] if matching_count[intersect_count].nil?
78
+ matching_count[intersect_count] << branch
79
+ end
80
+ end
81
+
82
+ res = []
83
+ if m=matching_count.keys.max
84
+ res = matching_count[m]
85
+ end
86
+
87
+ return res
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,113 @@
1
+ module ScbiGo
2
+ class GoTerm
3
+ attr_accessor :id, :name, :def, :namespace, :subset, :comment, :consider, :synonym
4
+
5
+ def initialize(go_term, gene_ontology)
6
+
7
+ @term_type=go_term.name
8
+ @gene_ontology=gene_ontology
9
+ @id=go_term['id']
10
+ @name=go_term['name']
11
+ @def=go_term['def']
12
+ @namespace=go_term['namespace']
13
+
14
+ #to save is_a relation as strings, cannot save objects directly because they may be not loaded yet.
15
+ @is_a_str=[]
16
+ # tmp var to save a cache with is_a relation as objects
17
+ @is_a=nil
18
+ if go_term['is_a'].is_a?(Array)
19
+ @is_a_str=go_term['is_a']
20
+ elsif !go_term['is_a'].nil?
21
+ @is_a_str=[go_term['is_a']]
22
+ end
23
+
24
+ @subset=go_term['subset']
25
+ @comment=go_term['comment']
26
+ @consider=go_term['consider']
27
+ @synonym=go_term['synonym']
28
+ @children = []
29
+ end
30
+
31
+ #base terms have no parents
32
+ def base_term?
33
+ return @is_a_str.count==0
34
+ end
35
+
36
+ def is_a
37
+ convert_is_a_to_terms! if @is_a.nil?
38
+ @is_a
39
+ end
40
+
41
+ # add another node ad child
42
+ def add_child(child)
43
+ @children << child
44
+ end
45
+
46
+ def inspect
47
+ "#{@term_type}:#{@id}, #{@name}, is_a: #{@is_a}"
48
+ end
49
+
50
+ def parents
51
+ is_a
52
+ end
53
+
54
+ def children
55
+ @children
56
+ end
57
+
58
+
59
+ # get list of descendants for a node
60
+ def descendants
61
+ res=children
62
+ children.each {|c| res += c.descendants}
63
+ return res.uniq
64
+ end
65
+
66
+ # include myself in descendants
67
+ def self_and_descendants
68
+ res = [self] + self.descendants
69
+ return res.uniq
70
+ end
71
+
72
+ # get list of ancestors for a node
73
+ def ancestors
74
+ res=parents
75
+ parents.each {|c| res += c.ancestors}
76
+ return res.uniq
77
+ end
78
+
79
+ # include myself in ancestors
80
+ def self_and_ancestors
81
+ res = [self] + self.ancestors
82
+ return res.uniq
83
+ end
84
+
85
+ # recursive function to get all branches from myself to top of the ontology
86
+ def all_branches_to_top
87
+
88
+ res=[]
89
+ if parents.count == 0
90
+ res = [[self]]
91
+ else
92
+ parents.each do |parent|
93
+ parent_b = parent.all_branches_to_top
94
+ parent_b.each do |pb|
95
+ res << pb.unshift(self)
96
+ end
97
+ end
98
+ end
99
+
100
+ return res
101
+
102
+ end
103
+
104
+ private
105
+
106
+ # cache is_a terms
107
+ def convert_is_a_to_terms!
108
+ @is_a = @is_a_str.map { |ia| @gene_ontology.find_go(ia) }
109
+ end
110
+
111
+
112
+ end
113
+ end
@@ -0,0 +1,15 @@
1
+ module ScbiGo
2
+
3
+ class Header
4
+ attr_accessor :format_version
5
+
6
+ def initialize(header)
7
+ @format_version=header['format-version']
8
+ end
9
+
10
+ def inspect
11
+ puts "GO HEADER: #{@format_version}"
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module ScbiGo
2
+ VERSION = "0.0.1"
3
+ end
data/lib/scbi_go.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "scbi_go/version"
2
+ require 'obo'
3
+ require 'json'
4
+ require 'scbi_go/header'
5
+ require 'scbi_go/base_graph'
6
+ require 'scbi_go/ancestors_graph'
7
+ require 'scbi_go/descendants_graph'
8
+ require 'scbi_go/go_term'
9
+ require 'scbi_go/gene_ontology'
10
+ require 'scbi_go/go_list_reducer'
11
+
12
+
13
+ module ScbiGo
14
+
15
+ end
data/scbi_go.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'scbi_go/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "scbi_go"
8
+ spec.version = ScbiGo::VERSION
9
+ spec.authors = ["dariogf"]
10
+ spec.email = ["dariogf@gmail.com"]
11
+ spec.summary = %q{GeneOntology tools.}
12
+ spec.description = %q{GeneOntology tools to summarize and graph go terms}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ #spec.add_development_dependency "autotest"
25
+ spec.add_development_dependency "guard-rspec"
26
+
27
+ spec.add_runtime_dependency "obo"
28
+
29
+ #spec.add_runtime_dependency "gene_ontology"
30
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe ScbiGo::AncestorsGraph do
4
+ before(:all) do
5
+ @go=ScbiGo::GeneOntology.new
6
+
7
+ end
8
+
9
+ it "Should make a graph and dot file" do
10
+ g=@go.find_go('GO:0001071');
11
+ g=@go.find_go('GO:0031323')
12
+ file_name="/tmp/dot_#{Time.now.strftime('%s')}.dot"
13
+ @graph=ScbiGo::AncestorsGraph.new(g.self_and_ancestors,file_name,'grafica',true)
14
+ expect(File).to exist(file_name)
15
+ expect(File).to exist(file_name+'.pdf')
16
+
17
+ end
18
+
19
+
20
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe ScbiGo::BaseGraph do
4
+ before(:all) do
5
+ @go=ScbiGo::GeneOntology.new
6
+ end
7
+
8
+ it "Should make graph and dot file" do
9
+ g1=@go.find_go('GO:0001071');
10
+ g2=@go.find_go('GO:0001074');
11
+
12
+ file_name="/tmp/dot_#{Time.now.strftime('%s')}.dot"
13
+
14
+ @graph=ScbiGo::BaseGraph.new([g1,g2],file_name,'grafica',true)
15
+ expect(File).to exist(file_name)
16
+ expect(File).to exist(file_name+'.pdf')
17
+
18
+ end
19
+
20
+
21
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe ScbiGo::DescendantsGraph do
4
+ before(:all) do
5
+ @go=ScbiGo::GeneOntology.new
6
+
7
+ end
8
+
9
+ it "Should make a graph and dot file" do
10
+ g=@go.find_go('GO:0001071');
11
+ file_name="/tmp/dot_#{Time.now.strftime('%s')}.dot"
12
+ @graph=ScbiGo::DescendantsGraph.new(g.self_and_descendants,file_name,'grafica',true)
13
+ expect(File).to exist(file_name)
14
+ expect(File).to exist(file_name+'.pdf')
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe ScbiGo::GeneOntology do
4
+ before(:all) do
5
+ @go=ScbiGo::GeneOntology.new
6
+ end
7
+
8
+
9
+ it "Should load obo file version 1.2" do
10
+ expect(@go.header.format_version).to eq('1.2')
11
+ end
12
+
13
+ it "Should have 41250 Go terms loaded" do
14
+ expect(@go.gos.count).to be 41250
15
+ end
16
+
17
+ it "Should find a go term object by a name string" do
18
+ go_term = @go.find_go('GO:0016765')
19
+ expect(go_term).not_to be_nil
20
+ end
21
+
22
+ it "Should return nil when a go term cannot be found by name" do
23
+
24
+ go_term = @go.find_go('GO:0016765_noexiste')
25
+ expect(go_term).to be_nil
26
+ end
27
+
28
+ it "Should have 3 base terms without ancestors" do
29
+
30
+ expect(@go.base_terms.count).to eq(3)
31
+ expect(@go.base_terms.map(&:id)).to match_array(["GO:0003674", "GO:0005575", "GO:0008150"])
32
+
33
+ @go.base_terms.each do |baset|
34
+ expect(baset.ancestors.count).to be(0)
35
+ end
36
+
37
+ end
38
+
39
+ it "Should convert a list of go names as strings to go terms " do
40
+ go_list=["GO:0003674", "GO:0005575", "GO:0008150"]
41
+
42
+ expect(@go.go_list_to_terms(go_list).count).to eq(go_list.count)
43
+ expect(@go.go_list_to_terms(go_list).map(&:id)).to match_array(["GO:0003674", "GO:0005575", "GO:0008150"])
44
+
45
+ end
46
+
47
+ it "Should not convert a list of go_terms" do
48
+ # use a list of go_terms
49
+ go_list=@go.base_terms
50
+ expect(@go.go_list_to_terms(go_list).map(&:id)).to match_array(["GO:0003674", "GO:0005575", "GO:0008150"])
51
+
52
+ end
53
+
54
+
55
+ it "Should convert a mix of go names as strings and go_terms to go_terms" do
56
+
57
+ # use a list of go_terms
58
+ go_list = @go.base_terms
59
+ go_list << "GO:0009889"
60
+ expect(@go.go_list_to_terms(go_list).map(&:id)).to match_array(["GO:0003674", "GO:0005575", "GO:0008150", "GO:0009889"])
61
+ end
62
+
63
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe ScbiGo::GoListReducer do
4
+ before(:all) do
5
+ @glr=ScbiGo::GoListReducer.new
6
+ end
7
+
8
+ it "Should reduce a complete ordered branch to the lower GO" do
9
+ go_list = ["GO:2001141", "GO:0031326", "GO:0009889", "GO:0019222", "GO:0050789", "GO:0065007", "GO:0008150"]
10
+
11
+ g=@glr.reduce_branches(go_list);
12
+ expect(g.map(&:id)).to match_array(["GO:2001141"])
13
+ end
14
+
15
+ it "Should reduce a complete un-ordered branch to the lower GO" do
16
+ go_list = ["GO:0050789", "GO:0009889", "GO:0019222", "GO:0031326", "GO:0065007","GO:2001141", "GO:0008150"]
17
+
18
+ g=@glr.reduce_branches(go_list);
19
+ expect(g.count).to eq(1)
20
+ expect(g.map(&:id)).to match_array(["GO:2001141"])
21
+ end
22
+
23
+ #http://www.ebi.ac.uk/QuickGO/GTerm?id=GO:2001141#term=ancchart
24
+ it "Should not reduce empty list" do
25
+ go_list=[]
26
+ g=@glr.reduce_branches(go_list);
27
+ expect(g.count).to eq(0)
28
+ expect(g.map(&:id)).to match_array([])
29
+ end
30
+
31
+ #http://www.ebi.ac.uk/QuickGO/GTerm?id=GO:0010556#term=ancchart
32
+ it "Should reduce a list of gos to only the leaves of their branches" do
33
+
34
+ leaves=["GO:0010556", "GO:0019219"]
35
+
36
+ input_go_list = ["GO:0010556", "GO:0060255", "GO:0019219"]
37
+
38
+ g=@glr.reduce_branches(input_go_list);
39
+
40
+ expect(g.map(&:id)).to match_array(leaves)
41
+ end
42
+
43
+
44
+ #http://www.ebi.ac.uk/QuickGO/GTerm?id=GO:2001141#term=ancchart
45
+ it "For a list of gos, Should find best_matching branches" do
46
+
47
+ original_go_paths = [["GO:2001141", "GO:0031326", "GO:0009889", "GO:0019222", "GO:0050789", "GO:0065007", "GO:0008150"],
48
+ ["GO:2001141", "GO:0031326", "GO:0031323", "GO:0019222", "GO:0050789", "GO:0065007", "GO:0008150"]]
49
+
50
+ input_go_list = ["GO:2001141", "GO:0031326", "GO:0019222", "GO:0065007", "GO:0008150"]
51
+
52
+ g=@glr.best_matching_branches(input_go_list);
53
+
54
+ expect(g.map{|e| e.map(&:id)}).to match_array(original_go_paths)
55
+ end
56
+
57
+ #http://www.ebi.ac.uk/QuickGO/GTerm?id=GO:2001141#term=ancchart
58
+ it "Should get all matching branches for a list of input gos" do
59
+
60
+ all_branches=[
61
+ ["GO:0010556", "GO:0009889", "GO:0019222", "GO:0050789", "GO:0065007", "GO:0008150"],
62
+ ["GO:0010556", "GO:0060255", "GO:0019222", "GO:0050789", "GO:0065007", "GO:0008150"],
63
+ ["GO:0019219", "GO:0031323", "GO:0019222", "GO:0050789", "GO:0065007", "GO:0008150"],
64
+ ["GO:0019219", "GO:0031323", "GO:0050794", "GO:0050789", "GO:0065007", "GO:0008150"],
65
+ ["GO:0019219", "GO:0051171", "GO:0019222", "GO:0050789", "GO:0065007", "GO:0008150"],
66
+ ["GO:0019219", "GO:0080090", "GO:0019222", "GO:0050789", "GO:0065007", "GO:0008150"]
67
+ ]
68
+
69
+
70
+ input_go_list = ["GO:0010556", "GO:0060255", "GO:0019219"]
71
+
72
+ g=@glr.all_matching_branches(input_go_list);
73
+
74
+ expect(g.map{|e| e.map(&:id)}).to match_array(all_branches)
75
+ end
76
+
77
+ end
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+
3
+ describe ScbiGo::GoTerm do
4
+ before(:all) do
5
+ @go=ScbiGo::GeneOntology.new
6
+ end
7
+
8
+ it "GO:0000011 Should have two is_a to their parents" do
9
+ term=@go.find_go('GO:0000011')
10
+
11
+ expect(term).not_to be_nil
12
+ expect(term.is_a.first).to be_a(ScbiGo::GoTerm)
13
+ expect(term.is_a.count).to eq(2)
14
+ expect(term.is_a.map(&:id)).to match_array(["GO:0007033", "GO:0048308"])
15
+ end
16
+
17
+ it "GO:0016765 Should have 67 children" do
18
+ term=@go.find_go('GO:0016765')
19
+
20
+ expect(term).not_to be_nil
21
+ expect(term.children.count).to eq(67)
22
+ expect(term.children.first).to be_a(ScbiGo::GoTerm)
23
+ expect(term.children.first.id).to eq('GO:0000010')
24
+ expect(term.children.last.id).to eq('GO:0098601')
25
+ end
26
+
27
+
28
+ it "GO:0016043 Should have 2 descendants with class GoTerm" do
29
+ term=@go.find_go('GO:0016043')
30
+
31
+ expect(term.descendants.first).to be_a(ScbiGo::GoTerm)
32
+ expect(term.descendants.map(&:id)).to end_with ["GO:0075503", "GO:0072565"]
33
+ end
34
+
35
+ it "GO:0016043 Should have self and descendants" do
36
+ term=@go.find_go('GO:0016043')
37
+ expect(term.self_and_descendants.map(&:id)).to start_with [term.id]
38
+ expect(term.self_and_descendants.map(&:id)).to end_with ["GO:0075503", "GO:0072565"]
39
+ end
40
+
41
+
42
+ it "GO:0016043 Should have 2 ancestors with class GoTerm" do
43
+ term=@go.find_go('GO:0016043')
44
+ expect(term.ancestors.first).to be_a(ScbiGo::GoTerm)
45
+ expect(term.ancestors.map(&:id)).to end_with ["GO:0071840", "GO:0008150"]
46
+ end
47
+
48
+ it "GO:0016043 Should have self and ancestors" do
49
+ term=@go.find_go('GO:0016043')
50
+ expect(term.self_and_ancestors.map(&:id)).to start_with [term.id]
51
+ expect(term.self_and_ancestors.map(&:id)).to end_with ["GO:0071840", "GO:0008150"]
52
+ end
53
+
54
+ #http://www.ebi.ac.uk/QuickGO/GTerm?id=GO:0050789#term=ancchart
55
+ it "GO:0050789 Should have only one branch to top" do
56
+ term=@go.find_go('GO:0050789')
57
+ expect(term.all_branches_to_top.map{|e| e.map(&:id)}).to match_array([['GO:0050789','GO:0065007','GO:0008150']])
58
+ expect(term.all_branches_to_top.count).to eq 1
59
+ end
60
+
61
+ #http://www.ebi.ac.uk/QuickGO/GTerm?id=GO:0031323#term=ancchart
62
+ it "GO:0031323 Should have two branches to top" do
63
+ term=@go.find_go('GO:0031323')
64
+ expect(term.all_branches_to_top.map{|e| e.map(&:id)}).to match_array([["GO:0031323","GO:0019222","GO:0050789","GO:0065007","GO:0008150"],["GO:0031323","GO:0050794","GO:0050789","GO:0065007","GO:0008150"]])
65
+ expect(term.all_branches_to_top.count).to eq 2
66
+ end
67
+
68
+ it "GO:0003674 Should have a branch to top with only me" do
69
+ term=@go.find_go('GO:0003674')
70
+ expect(term.all_branches_to_top.map{|e| e.map(&:id)}).to match_array([["GO:0003674"]])
71
+ end
72
+
73
+ it "GO:2001141 Should have 10 branches to top" do
74
+ term=@go.find_go('GO:2001141')
75
+ expect(term.all_branches_to_top.count).to eq 10
76
+ res = [["GO:2001141", "GO:0010556", "GO:0009889", "GO:0019222", "GO:0050789", "GO:0065007", "GO:0008150"],
77
+ ["GO:2001141", "GO:0010556", "GO:0060255", "GO:0019222", "GO:0050789", "GO:0065007", "GO:0008150"],
78
+ ["GO:2001141", "GO:0031326", "GO:0009889", "GO:0019222", "GO:0050789", "GO:0065007", "GO:0008150"],
79
+ ["GO:2001141", "GO:0031326", "GO:0031323", "GO:0019222", "GO:0050789", "GO:0065007", "GO:0008150"],
80
+ ["GO:2001141", "GO:0031326", "GO:0031323", "GO:0050794", "GO:0050789", "GO:0065007", "GO:0008150"],
81
+ ["GO:2001141", "GO:0051252", "GO:0019219", "GO:0031323", "GO:0019222", "GO:0050789", "GO:0065007", "GO:0008150"],
82
+ ["GO:2001141", "GO:0051252", "GO:0019219", "GO:0031323", "GO:0050794", "GO:0050789", "GO:0065007", "GO:0008150"],
83
+ ["GO:2001141", "GO:0051252", "GO:0019219", "GO:0051171", "GO:0019222", "GO:0050789", "GO:0065007", "GO:0008150"],
84
+ ["GO:2001141", "GO:0051252", "GO:0019219", "GO:0080090", "GO:0019222", "GO:0050789", "GO:0065007", "GO:0008150"],
85
+ ["GO:2001141", "GO:0051252", "GO:0060255", "GO:0019222", "GO:0050789", "GO:0065007", "GO:0008150"]]
86
+
87
+ expect(term.all_branches_to_top.map{|e| e.map(&:id)}).to match_array(res)
88
+ end
89
+ end
90
+
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe ScbiGo::Header do
4
+ before(:all) do
5
+ @go=ScbiGo::GeneOntology.new
6
+ end
7
+
8
+ it "Should load obo file version 1.2" do
9
+ expect(@go.header.format_version).to eq('1.2')
10
+ end
11
+
12
+ end
@@ -0,0 +1 @@
1
+ require 'scbi_go'
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scbi_go
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - dariogf
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: obo
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: GeneOntology tools to summarize and graph go terms
84
+ email:
85
+ - dariogf@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".autotest"
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - Guardfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - lib/data/go.obo.gz
98
+ - lib/scbi_go.rb
99
+ - lib/scbi_go/ancestors_graph.rb
100
+ - lib/scbi_go/base_graph.rb
101
+ - lib/scbi_go/descendants_graph.rb
102
+ - lib/scbi_go/gene_ontology.rb
103
+ - lib/scbi_go/go_list_reducer.rb
104
+ - lib/scbi_go/go_term.rb
105
+ - lib/scbi_go/header.rb
106
+ - lib/scbi_go/version.rb
107
+ - scbi_go.gemspec
108
+ - spec/lib/ancestors_graph_spec.rb
109
+ - spec/lib/base_graph_spec.rb
110
+ - spec/lib/descendants_graph_spec.rb
111
+ - spec/lib/gene_ontology_spec.rb
112
+ - spec/lib/go_list_reducer_spec.rb
113
+ - spec/lib/go_term_spec.rb
114
+ - spec/lib/header_spec.rb
115
+ - spec/spec_helper.rb
116
+ homepage: ''
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.4.4
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: GeneOntology tools.
140
+ test_files:
141
+ - spec/lib/ancestors_graph_spec.rb
142
+ - spec/lib/base_graph_spec.rb
143
+ - spec/lib/descendants_graph_spec.rb
144
+ - spec/lib/gene_ontology_spec.rb
145
+ - spec/lib/go_list_reducer_spec.rb
146
+ - spec/lib/go_term_spec.rb
147
+ - spec/lib/header_spec.rb
148
+ - spec/spec_helper.rb