Class: Chem::KEGG::KeggReactionParser

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) ⇒ KeggReactionParser

Returns a new instance of KeggReactionParser.



302
303
304
# File 'lib/chem/db/kegg.rb', line 302

def initialize filename
  @input = File.open(filename)
end

Instance Method Details

#eachObject



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/chem/db/kegg.rb', line 324

def each
  reaction = nil
  each_entry do |str, state|
    case state
    when "ENTRY"
#          reaction = Reaction.find(:first, :conditions => ["entry = ?", str.split[0]])
#            if reaction == nil
      reaction = KEGGReaction.new
      reaction.entry = str.split[0]
#          end
    when "NAME"
      reaction.name = str
    when "DEFINITION"
      #@definition = str
    when "EQUATION"
      c = str.split("<=>")
      reaction.compounds << parse_compounds(c[0])
      reaction.compounds << parse_compounds(c[1])
    when "RPAIR"
      # @rpair = str
    when "ENZYME"
      str.split.each do |e|
        ec = KeggEc.new
        ec.entry = "EC" + e
        sp = e.split(".")
        ec.number = sp.collect{|i| i.to_i}
        reaction.ecs << ec
      end
    when "///"
      #          reaction.save
      yield reaction
    when "PATHWAY"
    when "COMMENT"
    when "REFERENCE"
    else
      p state
    end
  end
end

#parse_compounds(species) ⇒ Object



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/chem/db/kegg.rb', line 306

def parse_compounds species
  ary = []
  species.split(" + ").each do |mol|
    stoichiometry = 1
    if m = /(\d+) *[CG]/.match(mol)
      stoichiometry = m[1].to_i
    end
    compound_entry = ""
    if m = /(C\d+)/.match(mol)
      compound_entry = m[1]
    elsif m = /(G\d+)/.match(mol)
      compound_entry = m[1]
    end
    ary.push([compound_entry, stoichiometry])
  end
  ary
end