lib/bio/db/go.rb in bio-1.3.1 vs lib/bio/db/go.rb in bio-1.4.0
- old
+ new
@@ -3,11 +3,11 @@
#
# Copyright:: Copyright (C) 2003
# Mitsuteru C. Nakao <n@bioruby.org>
# License:: The Ruby License
#
-# $Id: go.rb,v 1.11 2007/04/05 23:35:40 trevor Exp $
+# $Id:$
#
# == Gene Ontology
#
# == Example
#
@@ -87,11 +87,11 @@
# constructing adjaency list for the given ontology
def dag_edit_format_parser(str)
stack = []
adj_list = []
- str.each {|line|
+ str.each_line {|line|
if /^!(.+?):\s+(\S.+)$/ =~ line # Parsing head lines
tag = $1
value = $2
tag.gsub!(/-/,'_')
next if tag == 'type'
@@ -196,17 +196,17 @@
# Retruns an Array of parsed gene_association flatfile.
# Block is acceptable.
def self.parser(str)
if block_given?
- str.each(DELIMITER) {|line|
+ str.each_line(DELIMITER) {|line|
next if /^!/ =~ line
yield GeneAssociation.new(line)
}
else
galist = []
- str.each(DELIMITER) {|line|
+ str.each_line(DELIMITER) {|line|
next if /^!/ =~ line
galist << GeneAssociation.new(line)
}
return galist
end
@@ -409,73 +409,5 @@
-if __FILE__ == $0
-
- require 'net/http'
-
- def wget(url)
- if /http:\/\/(.+?)\// =~ url
- host = $1
- path = url[(url.index(host) + host.size)..url.size]
- else
- raise ArgumentError, "Invalid URL\n#{url}"
- end
-
- result = Net::HTTP.new(host).get(path).body
- end
-
-
-
- go_c_url = 'http://www.geneontology.org/ontology/component.ontology'
- ga_url = 'http://www.geneontology.org/gene-associations/gene_association.sgd.gz'
- e2g_url = 'http://www.geneontology.org/external2go/spkw2go'
-
-
-
- puts "\n #==> Bio::GO::Ontology"
- p go_c_url
- component_ontology = wget(go_c_url)
- comp = Bio::GO::Ontology.new(component_ontology)
-
- [['0003673', '0005632'],
- ['0003673', '0005619'],
- ['0003673', '0004649']].each {|pair|
- puts
- p pair
- p [:pair, pair.map {|i| [comp.id2term[i], comp.goid2term(i)] }]
- puts "\n #==> comp.bfs_shortest_path(pair[0], pair[1])"
- p comp.bfs_shortest_path(pair[0], pair[1])
- }
-
-
- puts "\n #==> Bio::GO::External2go"
- p e2g_url
- spkw2go = Bio::GO::External2go.new(wget(e2g_url))
-
- puts "\n #==> spkw2go.db"
- p spkw2go.db
-
- puts "\n #==> spkw2go[1]"
- p spkw2go[1]
-
-
-
- require 'zlib'
- puts "\n #==> Bio::GO::GeenAssociation"
- p ga_url
- ga = Zlib::Inflate.inflate(wget(ga_url))
- ga = Bio::GO::GeneAssociation.parser(ga)
-
- puts "\n #==> ga.size"
- p ga.size
-
- puts "\n #==> ga[100]"
- p ga[100]
-
-
-
-
-
-end