Class: Chem::KEGG::KeggReaction

Inherits:
Object
  • Object
show all
Defined in:
lib/chem/db/kcf.rb

Defined Under Namespace

Classes: ReactionEntry

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ KeggReaction

Returns a new instance of KeggReaction.



101
102
103
# File 'lib/chem/db/kcf.rb', line 101

def initialize input
  @input = input
end

Class Method Details

.open(filename) ⇒ Object



105
106
107
# File 'lib/chem/db/kcf.rb', line 105

def KeggReaction.open filename
  KeggReaction.new(File.open(filename))
end

Instance Method Details

#eachObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/chem/db/kcf.rb', line 109

def each
  while ! @input.eof?
    entry = ReactionEntry.new
    state = :INITIAL
    while ! /\/\/\//.match(line = @input.readline)
      #case line[0...12]
      type = line[0...12]
      if 'ENTRY       ' == type
        entry.entry = line[12...-1]
      elsif 'NAME        ' == type || state == :NAME
        state = :NAME
        entry.name = line[12...-1]
      elsif 'DEFINITION  '  == type || state == :DEFINITION
        state = :DEFINITION
        entry.definition.push(line[12...-1])
      elsif 'EQUATION    ' == type
        ary = line[12...-1].split('<=>')
        entry.reactants = ary[0].split('+').collect{|mol| mol.strip}
        entry.products = ary[1].split('+').collect{|mol| mol.strip}
      elsif 'RPAIR       ' == type
        entry.rpair = line[12...-1]
      elsif 'ENZYME      ' == type
        entry.ec = line[12...-1].split('.').collect{|n| n.to_i}
      elsif 'COMMENT     ' == type || state == :COMMENT
        state = :COMMENT
        entry.comment.push(line[12...-1])
      elsif 'PATHWAY     ' == type || state == :PATHWAY
        state = :PATHWAY
      else
        puts "Error Unknown line : %s" % line
      end
    end
    yield entry
  end
end