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



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

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

Instance Attribute Details

#headerObject (readonly)

Returns aHash of the external2go header information



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

def header
  @header
end

Class Method Details

.parser(str) ⇒ Object

Constructor from parsing external2go file.



335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/bio/db/go.rb', line 335

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.



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

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

#dbsObject

Returns ary of databases.



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

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

#go_idsObject

Returns ary of GO IDs.



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

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

#go_termsObject

Returns ary of GO Terms.



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

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

#set_date(value) ⇒ Object

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



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

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

#set_desc(ary) ⇒ Object

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



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

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

#to_strObject

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



375
376
377
378
379
380
# File 'lib/bio/db/go.rb', line 375

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