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.



268
269
270
# File 'lib/chem/db/kegg.rb', line 268

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

Instance Method Details

#eachObject



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/chem/db/kegg.rb', line 290

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



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/chem/db/kegg.rb', line 272

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