class Bio::GO::External2go

Container class for files in geneontology.org/go/external2go/*2go.

The line syntax is:

database:<identifier> > GO:<term> ; GO:<GO_id>

Example

spkw2go = Bio::GO::External2go.new(File.read("spkw2go"))
spkw2go.size
spkw2go.each do |relation|
  relation # -> {:db => "", :db_id => "", :go_term => "", :go_id => ""}
end
spkw2go.dbs

SAMPLE

!date: 2005/02/08 18:02:54
!Mapping of SWISS-PROT KEYWORDS to GO terms.
!Evelyn Camon, SWISS-PROT.
!
SP_KW:ATP synthesis > GO:ATP biosynthesis ; GO:0006754
...

Attributes

header[R]

Returns aHash of the external2go header information

Public Class Methods

new() click to toggle source

Constructor. relation := {:db => aStr, :db_id => aStr, :go_term => aStr, :go_id => aStr}

Calls superclass method
# File lib/bio/db/go.rb, line 354
def initialize
  @header = {:date => '', :desc => []}
  super
end
parser(str) click to toggle source

Constructor from parsing external2go file.

# File lib/bio/db/go.rb, line 334
def self.parser(str)
  e2g = self.new
  str.each_line do |line|
    line.chomp!
    if line =~ /^\!date: (.+)/
      e2g.header[:date] = $1
    elsif line =~ /^\!(.*)/
      e2g.header[:desc] << $1
    elsif ary = line.scan(/^(.+?):(.+) > GO:(.+) ; (GO:\d{7})/).first
      e2g << {:db_id => ary[1], :db => ary[0], :go_term => ary[2], :go_id => ary[3]}
    else
      raise("Invalid Format Line: \n #{line.inspect}\n")
    end
  end
  return e2g
end

Public Instance Methods

db_ids() click to toggle source

Returns ary of database IDs.

# File lib/bio/db/go.rb, line 389
def db_ids
  self.map {|rel| rel[:db_id] }.uniq
end
dbs() click to toggle source

Returns ary of databases.

# File lib/bio/db/go.rb, line 383
def dbs
  self.map {|rel| rel[:db] }.uniq
end
go_ids() click to toggle source

Returns ary of GO IDs.

# File lib/bio/db/go.rb, line 399
def go_ids
  self.map {|rel| rel[:go_id] }.uniq
end
go_terms() click to toggle source

Returns ary of GO Terms.

# File lib/bio/db/go.rb, line 394
def go_terms
  self.map {|rel| rel[:go_term] }.uniq
end
set_date(value) click to toggle source

#set_date

# File lib/bio/db/go.rb, line 361
def set_date(value)
  @header[:date] = value
end
set_desc(ary) click to toggle source

#set_desc

# File lib/bio/db/go.rb, line 367
def set_desc(ary)
  @header[:desc] = ary
end
to_str() click to toggle source

#to_str Returns the contents in the external2go format.

# File lib/bio/db/go.rb, line 374
def to_str
  ["!date: #{@header[:date]}",
   @header[:desc].map {|e| "!#{e}" },
    self.map { |e| [e[:db], ':', e[:db_id], ' > GO:', e[:go_term], ' ; ', e[:go_id]].join }
  ].join("\n")
end