Class: Chem::KEGG::KeggReactionMapParser
- Inherits:
-
Object
- Object
- Chem::KEGG::KeggReactionMapParser
- Includes:
- KeggFormat, Enumerable
- Defined in:
- lib/chem/db/kegg.rb
Overview
Instance Method Summary collapse
- #[](r_number) ⇒ Object
- #each ⇒ Object
-
#initialize(filename) ⇒ KeggReactionMapParser
constructor
A new instance of KeggReactionMapParser.
Methods included from KeggFormat
#compound_folder=, #each_entry
Constructor Details
#initialize(filename) ⇒ KeggReactionMapParser
Returns a new instance of KeggReactionMapParser.
384 385 386 387 388 389 390 391 |
# File 'lib/chem/db/kegg.rb', line 384 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
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
# File 'lib/chem/db/kegg.rb', line 399 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 |
#each ⇒ Object
393 394 395 396 397 |
# File 'lib/chem/db/kegg.rb', line 393 def each @reactions.each do |r_number, (map_number, comps)| yield self[r_number] end end |