$LOAD_PATH << 'gems/1.8/gems/bio-1.2.1/lib'
$LOAD_PATH << 'site_ruby/1.8'
$LOAD_PATH << 'site_ruby'
$LOAD_PATH << '1.8'
$LOAD_PATH << '1.8/java'
$LOAD_PATH << 'jruby'
require 'set'
require 'java'
require 'bio'
include_class 'java.util.ArrayList'
include_class 'cytoscape.Cytoscape'
include_class 'cytoscape.data.CyAttributes'
include_class 'cytoscape.CyNode'
include_class 'cytoscape.CyEdge'
include_class 'cytoscape.CyNetwork'
nodes = Cytoscape.getCyNodesList
attrs = Cytoscape.getNodeAttributes
serv = Bio::KEGG::API.new
cBuffer = ""
rBuffer = ""
cBgetResults = ""
rBgetResults = ""
canonicalHash = Hash.new
nodes.each{|node|
keggId = attrs.getAttribute(node.getIdentifier, "canonicalName")
if canonicalHash[keggId] then
canonicalHash[keggId] << node.getIdentifier
else
canonicalHash[keggId] = [node.getIdentifier]
end
case keggId
when /^R/
rBuffer = rBuffer + keggId.gsub!("R", "rn:R") + " "
when /^C/
cBuffer = cBuffer + keggId.gsub!("C", "cpd:C") + " "
end
}
rBgetResults = serv.bget(rBuffer.strip)
cBgetResults = serv.bget(cBuffer.strip)
cAnnotationList = cBgetResults.split("\n///\n")
rAnnotationList = rBgetResults.split("\n///\n")
cAnnotationList.each{|annotation|
annt = Bio::KEGG::COMPOUND.new(annotation)
canonicalHash[annt.entry_id].each{|nodeId|
attrs.setAttribute(nodeId, "formula", annt.formula)
attrs.setAttribute(nodeId, "enzymes", annt.enzymes.join(', '))
attrs.setAttribute(nodeId, "mass", annt.mass)
attrs.setAttribute(nodeId, "name", annt.name)
attrs.setAttribute(nodeId, "pathways", annt.pathways.join(', '))
}
}
rAnnotationList.each{|annotation|
annt = Bio::KEGG::REACTION.new(annotation)
canonicalHash[annt.entry_id].each{|nodeId|
attrs.setAttribute(nodeId, "enzymes", annt.enzymes.join(', '))
attrs.setAttribute(nodeId, "equation", annt.equation)
attrs.setAttribute(nodeId, "pathways", annt.pathways.join(', '))
}
}
p "ok."