Class: Chem::KEGG::KeggReactionMapParser

Inherits:
Object
  • Object
show all
Includes:
KeggFormat, Enumerable
Defined in:
lib/chem/db/kegg.rb

Overview

Instance Method Summary collapse

Methods included from KeggFormat

#compound_folder=, #each_entry

Constructor Details

#initialize(filename) ⇒ KeggReactionMapParser

Returns a new instance of KeggReactionMapParser.


418
419
420
421
422
423
424
425
# File 'lib/chem/db/kegg.rb', line 418

def initialize filename
  @input = open(filename)
  @reactions = @input.inject({}) do |ret, line|
    ary = line.split(":")
    ret[ary[0]] = ary[1..-1]
    ret
  end
end

Instance Method Details

#[](r_number) ⇒ Object


433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
# File 'lib/chem/db/kegg.rb', line 433

def [](r_number)
  return nil if @reactions[r_number] == nil
  map_number, comps = @reactions[r_number]
  rxn = KEGGReaction.new
  #          r_number, map_number, comps = line.split(":")
  rxn.entry = r_number
  cc = comps.split(/(<?=>?)/)
  case cc[1]
  when "<="
    rxn.direction = -1
  when "<=>"
    rxn.direction = 0
  when "=>"
    rxn.direction = 1
  end
  reactant = cc[0].split("+").collect do |c|
    #compound = KeggCompound.new
    #compound.entry = c.strip
    [c.strip, 1]
  end
  product = cc[2].split("+").collect do |c|
    #compound = KeggCompound.new
    #compound.entry = c.strip
    [c.strip, 1]
  end
  rxn.compounds = [reactant, product]
  rxn
end

#eachObject


427
428
429
430
431
# File 'lib/chem/db/kegg.rb', line 427

def each
  @reactions.each do |r_number, (map_number, comps)|
    yield self[r_number]
  end
end