Class: Bio::GO::External2go

Inherits:
Array
  • Object
show all
Defined in:
lib/bio/db/go.rb

Overview

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
...

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExternal2go

Constructor. relation := => aStr, :db_id => aStr, :go_term => aStr, :go_id => aStr



354
355
356
357
# File 'lib/bio/db/go.rb', line 354

def initialize
  @header = {:date => '', :desc => []}
  super
end

Instance Attribute Details

#headerObject (readonly)

Returns aHash of the external2go header information



331
332
333
# File 'lib/bio/db/go.rb', line 331

def header
  @header
end

Class Method Details

.parser(str) ⇒ Object

Constructor from parsing external2go file.



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# 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

Instance Method Details

#db_idsObject

Returns ary of database IDs.



389
390
391
# File 'lib/bio/db/go.rb', line 389

def db_ids
  self.map {|rel| rel[:db_id] }.uniq
end

#dbsObject

Returns ary of databases.



383
384
385
# File 'lib/bio/db/go.rb', line 383

def dbs
  self.map {|rel| rel[:db] }.uniq
end

#go_idsObject

Returns ary of GO IDs.



399
400
401
# File 'lib/bio/db/go.rb', line 399

def go_ids
  self.map {|rel| rel[:go_id] }.uniq
end

#go_termsObject

Returns ary of GO Terms.



394
395
396
# File 'lib/bio/db/go.rb', line 394

def go_terms
  self.map {|rel| rel[:go_term] }.uniq
end

#set_date(value) ⇒ Object

Bio::GO::External2go#set_date(value)



361
362
363
# File 'lib/bio/db/go.rb', line 361

def set_date(value)
  @header[:date] = value
end

#set_desc(ary) ⇒ Object

Bio::GO::External2go#set_desc(ary)



367
368
369
# File 'lib/bio/db/go.rb', line 367

def set_desc(ary)
  @header[:desc] = ary
end

#to_strObject

Bio::GO::External2go#to_str Returns the contents in the external2go format.



374
375
376
377
378
379
# 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