Class: Chem::KEGG::KCFRXN
- Inherits:
-
Object
- Object
- Chem::KEGG::KCFRXN
show all
- Defined in:
- lib/chem/db/kcf.rb
Defined Under Namespace
Classes: RXNEdge, RXNNode
Instance Method Summary
collapse
Constructor Details
#initialize(reactant, product) ⇒ KCFRXN
Returns a new instance of KCFRXN.
147
148
149
150
151
152
153
|
# File 'lib/chem/db/kcf.rb', line 147
def initialize reactant, product
@reactant = reactant
@product = product
@matched_reactants = []
@matched_products = []
@nodes = []
end
|
Instance Method Details
#corresponds(from, to) ⇒ Object
155
156
157
158
159
|
# File 'lib/chem/db/kcf.rb', line 155
def corresponds from, to
@matched_reactants.push(@reactant.atoms[from])
@matched_products.push(@product.atoms[from])
@nodes.push(RXNNode.new(@reactant.atoms[from], @product.atoms[to]))
end
|
#setup_bonds ⇒ Object
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
# File 'lib/chem/db/kcf.rb', line 161
def setup_bonds
@edges = []
@reactant.atoms.each do |atom|
if atom && ! @matched_reactants.member?(atom)
@nodes.push(RXNNode.new(atom, nil))
end
end
@product.atoms.each do |atom|
if atom && ! @matched_products.member?(atom)
@nodes.push(RXNNode.new(nil, atom))
end
end
@reactant.bonds.each do |bond|
bond.e.next_atom[bond.b] = bond
bond.b.next_atom[bond.e] = bond
end
@product.bonds.each do |bond|
bond.e.next_atom[bond.b] = bond
bond.b.next_atom[bond.e] = bond
end
@nodes.each_with_index do |node, index|
index.upto(@nodes.length - 1) do |n|
r_edge = p_edge = nil
if @nodes[n].reactant_node && @nodes[n].reactant_node.next_atom.has_key?(node.reactant_node)
r_edge = @nodes[n].reactant_node.next_atom[node.reactant_node]
end
if @nodes[n].product_node && @nodes[n].product_node.next_atom.has_key?(node.product_node)
p_edge = @nodes[n].product_node.next_atom[node.product_node]
end
if r_edge || p_edge
edge = RXNEdge.new
edge.reactant_edge = r_edge
edge.product_edge = p_edge
@edges.push(edge)
end
end
end
@edges.each do |edge|
from = edge.reactant_edge ? edge.reactant_edge.multiplicity : 0
to = edge.product_edge ? edge.product_edge.multiplicity : 0
puts "%3d %3d" % [from, to]
end
end
|