Class: Chem::KEGG::KeggReactionLstParser

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

Instance Method Summary collapse

Methods included from KeggFormat

#compound_folder=, #each_entry

Constructor Details

#initialize(filename) ⇒ KeggReactionLstParser

Returns a new instance of KeggReactionLstParser.


371
372
373
# File 'lib/chem/db/kegg.rb', line 371

def initialize filename
  @input = open(filename)
end

Instance Method Details

#eachObject


375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# File 'lib/chem/db/kegg.rb', line 375

def each
  @input.each do |line|
    rxn = KEGGReaction.new
    r_number, comps = line.split(":")
    rxn.entry = r_number
    cc = comps.split(/<=>/)

    reactant = cc[0].split("+").collect do |c|
      ary = c.split
      #compound = KeggCompound.new
      if ary.length == 1
        #compound.entry = c.strip
        [c.strip, 1]
      else
        #compound.entry = ary[1].strip
        [c.strip, ary[0].to_i]
      end
    end
    product = cc[1].split("+").collect do |c|
      ary = c.split
      #compound = KeggCompound.new
      if ary.length == 1
        #compound.entry = c.strip
        [c.strip, 1]
      else
        #compound.entry = ary[1].strip
        [c.strip, ary[0].to_i]
      end
    end
    rxn.compounds = [reactant, product]
    yield rxn
  end
  
end