class Bio::KEGG::KGML
KGML
(KEGG
XML) parser¶ ↑
See www.genome.jp/kegg/xml/ for more details on KGML
.
Note for older version users¶ ↑
-
Most of incompatible attribute names with
KGML
tags are now deprecated. Use the names ofKGML
tags instead of old incompatible names that will be removed in the future.-
Bio::KGML::Entry#id (entry_id is deprecated)
-
Bio::KGML::Entry#type (category is deprecated)
-
Bio::KGML::Relation#entry1 (node1 is deprecated)
-
Bio::KGML::Relation#entry2 (node2 is deprecated)
-
Bio::KGML::Relation#type (rel is deprecated)
-
Bio::KGML::Reaction#name (entry_id is deprecated)
-
Bio::KGML::Reaction#type (direction is deprecated)
-
-
New class Bio::KGML::Graphics and new method Bio::KGML::Entry#graphics. Because two or more graphics elements may exist, following attribute methods in Bio::KGML::Entry are now deprecated and will be removed in the future. See rdoc of these methods for details.
-
Incompatible changes:
Bio::KEGG::KGML::Reaction#substrates
now returns an array containingBio::KEGG::KGML::Substrate
objects, andBio::KEGG::KGML::Reaction#products
now returns an array containingBio::KEGG::KGML::Product
objects. The changes enable us to get id of substrates and products.
Incompatible attribute names with KGML
tags¶ ↑
<entry> :map -> :pathway names() <subtype> edge()
Examples¶ ↑
file = File.read("kgml/hsa/hsa00010.xml") kgml = Bio::KEGG::KGML.new(file) # <pathway> attributes puts kgml.name puts kgml.org puts kgml.number puts kgml.title puts kgml.image puts kgml.link kgml.entries.each do |entry| # <entry> attributes puts entry.id puts entry.name puts entry.type puts entry.link puts entry.reaction # <graphics> attributes entry.graphics.each do |graphics| puts graphics.name puts graphics.type puts graphics.x puts graphics.y puts graphics.width puts graphics.height puts graphics.fgcolor puts graphics.bgcolor end # <component> attributes puts entry.components # methood puts entry.names end kgml.relations.each do |relation| # <relation> attributes puts relation.entry1 puts relation.entry2 puts relation.type # <subtype> attributes puts relation.name puts relation.value end kgml.reactions.each do |reaction| # <reaction> attributes puts reaction.name puts reaction.type # <substrate> attributes reaction.substrates.each do |substrate| puts substrate.id puts substrate.name # <alt> attributes altnames = reaction.alt[entry_id] altnames.each do |name| puts name end end # <product> attributes reaction.products.each do |product| puts product.id puts product.name # <alt> attributes altnames = reaction.alt[entry_id] altnames.each do |name| puts name end end end
References
¶ ↑
Attributes
entry elements (Array containing KGML::Entry
objects, or nil)
image URL of this pathway map (String or nil) ('pathway' element)
information URL of this pathway map (String or nil) ('pathway' element)
KEGG-style ID string of this pathway map (String or nil) ('pathway' element)
map number (String or nil) ('pathway' element)
reaction elements (Array containing KGML::Reactions objects, or nil)
relation elements (Array containing KGML::Relations objects, or nil)
title (String or nil) ('pathway' element)
Public Class Methods
Creates a new KGML
object.
Arguments:
-
(required) str: String containing xml data
- Returns
-
Bio::KEGG::KGML
object
# File lib/bio/db/kegg/kgml.rb 141 def initialize(xml) 142 dom = REXML::Document.new(xml) 143 parse_root(dom) 144 parse_entry(dom) 145 parse_relation(dom) 146 parse_reaction(dom) 147 end
Private Instance Methods
# File lib/bio/db/kegg/kgml.rb 542 def parse_entry(dom) 543 @entries = Array.new 544 545 dom.elements.each("/pathway/entry") { |node| 546 attr = node.attributes 547 entry = Entry.new 548 entry.id = attr["id"].to_i 549 entry.name = attr["name"] 550 entry.type = attr["type"] 551 # implied 552 entry.link = attr["link"] 553 entry.reaction = attr["reaction"] 554 entry.pathway = attr["map"] 555 556 node.elements.each("graphics") { |graphics| 557 g = Graphics.new 558 attr = graphics.attributes 559 g.x = attr["x"].to_i 560 g.y = attr["y"].to_i 561 g.type = attr["type"] 562 g.name = attr["name"] 563 g.width = attr["width"].to_i 564 g.height = attr["height"].to_i 565 g.fgcolor = attr["fgcolor"] 566 g.bgcolor = attr["bgcolor"] 567 if str = attr["coords"] then 568 coords = [] 569 tmp = str.split(',') 570 tmp.collect! { |n| n.to_i } 571 while xx = tmp.shift 572 yy = tmp.shift 573 coords.push [ xx, yy ] 574 end 575 g.coords = coords 576 else 577 g.coords = nil 578 end 579 entry.graphics ||= [] 580 entry.graphics.push g 581 } 582 583 node.elements.each("component") { |component| 584 attr = component.attributes 585 entry.components ||= [] 586 entry.components << attr["id"].to_i 587 } 588 589 @entries << entry 590 } 591 end
# File lib/bio/db/kegg/kgml.rb 612 def parse_reaction(dom) 613 @reactions = Array.new 614 615 dom.elements.each("/pathway/reaction") { |node| 616 attr = node.attributes 617 reaction = Reaction.new 618 reaction.id = attr["id"].to_i 619 reaction.name = attr["name"] 620 reaction.type = attr["type"] 621 622 substrates = Array.new 623 products = Array.new 624 hash = Hash.new 625 626 node.elements.each("substrate") { |substrate| 627 id = substrate.attributes["id"].to_i 628 name = substrate.attributes["name"] 629 substrates << Substrate.new(id, name) 630 substrate.elements.each("alt") { |alt| 631 hash[name] ||= Array.new 632 hash[name] << alt.attributes["name"] 633 } 634 } 635 node.elements.each("product") { |product| 636 id = product.attributes["id"].to_i 637 name = product.attributes["name"] 638 products << Product.new(id, name) 639 product.elements.each("alt") { |alt| 640 hash[name] ||= Array.new 641 hash[name] << alt.attributes["name"] 642 } 643 } 644 reaction.substrates = substrates 645 reaction.products = products 646 reaction.alt = hash 647 648 @reactions << reaction 649 } 650 end
# File lib/bio/db/kegg/kgml.rb 593 def parse_relation(dom) 594 @relations = Array.new 595 596 dom.elements.each("/pathway/relation") { |node| 597 attr = node.attributes 598 relation = Relation.new 599 relation.entry1 = attr["entry1"].to_i 600 relation.entry2 = attr["entry2"].to_i 601 relation.type = attr["type"] 602 603 node.elements.each("subtype") { |subtype| 604 attr = subtype.attributes 605 relation.name = attr["name"] 606 relation.value = attr["value"] 607 } 608 @relations << relation 609 } 610 end
# File lib/bio/db/kegg/kgml.rb 532 def parse_root(dom) 533 root = dom.root.attributes 534 @name = root["name"] 535 @org = root["org"] 536 @number = root["number"] 537 @title = root["title"] 538 @image = root["image"] 539 @link = root["link"] 540 end