[BioRuby-cvs] bioruby/lib/bio/db/kegg kgml.rb,1.3,1.4

Katayama Toshiaki k at dev.open-bio.org
Tue Jul 25 19:17:41 UTC 2006


Update of /home/repository/bioruby/bioruby/lib/bio/db/kegg
In directory dev.open-bio.org:/tmp/cvs-serv28050/lib/bio/db/kegg

Modified Files:
	kgml.rb 
Log Message:
* please note that the method names of some accessors are changed!
* bug fixed
* @dom is obsoleted

Note:
# === Incompatible attribute names with KGML tags
#
# <entry>
#  :id -> :entry_id
#  :type -> :entry_type 
#  names()
#  <graphics>
#  :name -> :label
#  :type -> :shape
# <relation>
#  :entry1 -> :node1
#  :entry2 -> :node2
#  :type -> :rel
#  <subtype>
#  edge()
# <reaction>
#  :name -> :entry_id
#  :type -> :direction



Index: kgml.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/db/kegg/kgml.rb,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** kgml.rb	8 May 2006 14:25:25 -0000	1.3
--- kgml.rb	25 Jul 2006 19:17:39 -0000	1.4
***************
*** 12,18 ****
  # See http://www.genome.jp/kegg/xml/ for more details on KGML.
  #
  # === Examples
  #
! #  file = ARGF.read
  #  kgml = Bio::KEGG::KGML.new(file)
  #
--- 12,37 ----
  # See http://www.genome.jp/kegg/xml/ for more details on KGML.
  #
+ # === Incompatible attribute names with KGML tags
+ #
+ # <entry>
+ #  :id -> :entry_id
+ #  :type -> :entry_type
+ #  names()
+ #  <graphics>
+ #  :name -> :label
+ #  :type -> :shape
+ # <relation>
+ #  :entry1 -> :node1
+ #  :entry2 -> :node2
+ #  :type -> :rel
+ #  <subtype>
+ #  edge()
+ # <reaction>
+ #  :name -> :entry_id
+ #  :type -> :direction
+ #
  # === Examples
  #
! #  file = ARGF.read("kgml/hsa/hsa00010.xml")
  #  kgml = Bio::KEGG::KGML.new(file)
  #
***************
*** 27,82 ****
  #  kgml.entries.each do |entry|
  #    # <entry> attributes
! #    puts entry.id
  #    puts entry.name
! #    puts entry.names
! #    puts entry.type
  #    puts entry.link
  #    puts entry.reaction
  #    puts entry.map
  #    # <graphics> attributes
! #    puts entry.label	# This is an accessor for <graphics name="">
  #    puts entry.x
  #    puts entry.y
- #    puts entry.type
  #    puts entry.width
  #    puts entry.height
  #    puts entry.fgcolor
  #    puts entry.bgcolor
  #  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
- #    # or
- #    relation.subtype.each do |value, name|
- #      puts value, name
- #    end
  #  end
  #
  #  kgml.reactions.each do |reaction|
  #    # <reaction> attributes
! #    puts reaction.name
! #    puts reaction.type
  #    # <substrate> attributes
! #    reaction.substrates.each do |name|
! #      puts name
  #      # <alt> attributes
! #      altnames = reaction.alt[name]
! #      altnames.each do |altname|
! #        puts altname
  #      end
  #    end
  #    # <product> attributes
! #    reaction.products.each do |name|
! #      puts name
  #      # <alt> attributes
! #      altnames = reaction.alt[name]
! #      altnames.each do |altname|
! #        puts altname
  #      end
  #    end
--- 46,100 ----
  #  kgml.entries.each do |entry|
  #    # <entry> attributes
! #    puts entry.entry_id
  #    puts entry.name
! #    puts entry.entry_type
  #    puts entry.link
  #    puts entry.reaction
  #    puts entry.map
  #    # <graphics> attributes
! #    puts entry.label	      # name
! #    puts entry.shape         # type
  #    puts entry.x
  #    puts entry.y
  #    puts entry.width
  #    puts entry.height
  #    puts entry.fgcolor
  #    puts entry.bgcolor
+ #    # methood
+ #    puts entry.names
  #  end
  #
  #  kgml.relations.each do |relation|
  #    # <relation> attributes
! #    puts relation.node1      # entry1
! #    puts relation.node2      # entry2
! #    puts relation.rel        # type
! #    # method
! #    puts relation.edge
  #    # <subtype> attributes
  #    puts relation.name
  #    puts relation.value
  #  end
  #
  #  kgml.reactions.each do |reaction|
  #    # <reaction> attributes
! #    puts reaction.entry_id   # name
! #    puts reaction.direction  # type
  #    # <substrate> attributes
! #    reaction.substrates.each do |entry_id|
! #      puts entry_id
  #      # <alt> attributes
! #      altnames = reaction.alt[entry_id]
! #      altnames.each do |name|
! #        puts name
  #      end
  #    end
  #    # <product> attributes
! #    reaction.products.each do |entry_id|
! #      puts entry_id
  #      # <alt> attributes
! #      altnames = reaction.alt[entry_id]
! #      altnames.each do |name|
! #        puts name
  #      end
  #    end
***************
*** 84,88 ****
  #
  
! require 'rexml/document'
  
  module Bio
--- 102,106 ----
  #
  
! autoload :REXML, 'rexml/document'
  
  module Bio
***************
*** 92,123 ****
  
    def initialize(xml)
!     @dom = REXML::Document.new(xml)
!     parse_root
!     parse_entry
!     parse_relation
!     parse_reaction
    end
    attr_reader :name, :org, :number, :title, :image, :link
!   attr_reader :entries, :relations, :reactions		# Array
  
    class Entry
!     attr_accessor :id, :name, :names, :type, :link, :reaction, :map
!     attr_accessor :label, :x, :y, :type, :width, :height, :fgcolor, :bgcolor
    end
  
    class Relation
!     attr_accessor :entry1, :entry2, :type
      attr_accessor :name, :value
!     attr_accessor :subtype      			# Hash
    end
  
    class Reaction
!     attr_accessor :name, :type
!     attr_accessor :substrates, :products		# Array
!     attr_accessor :alt					# Hash
    end
  
!   def parse_root
!     root    = @dom.root.attributes
      @name   = root["name"]
      @org    = root["org"]
--- 110,148 ----
  
    def initialize(xml)
!     dom = REXML::Document.new(xml)
!     parse_root(dom)
!     parse_entry(dom)
!     parse_relation(dom)
!     parse_reaction(dom)
    end
    attr_reader :name, :org, :number, :title, :image, :link
!   attr_accessor :entries, :relations, :reactions
  
    class Entry
!     attr_accessor :entry_id, :name, :entry_type, :link, :reaction, :map
!     attr_accessor :label, :shape, :x, :y, :width, :height, :fgcolor, :bgcolor
!     def names
!       @name.split(/\s+/)
!     end
    end
  
    class Relation
!     attr_accessor :node1, :node2, :rel
      attr_accessor :name, :value
!     def edge
!       @value.to_i
!     end
    end
  
    class Reaction
!     attr_accessor :entry_id, :direction
!     attr_accessor :substrates, :products	# Array
!     attr_accessor :alt				# Hash
    end
  
!   private
! 
!   def parse_root(dom)
!     root    = dom.root.attributes
      @name   = root["name"]
      @org    = root["org"]
***************
*** 128,155 ****
    end
  
!   def parse_entry
      @entries = Array.new
  
!     @dom.elements.each("/pathway/entry") { |node|
        attr = node.attributes
        entry = Entry.new
!       entry.id        = attr["id"].to_i
!       entry.map       = attr["map"]
!       entry.name      = attr["name"]
!       entry.names     = entry.name.split(/\s+/)
!       entry.type      = attr["type"]
!       entry.link      = attr["link"]
!       entry.reaction  = attr["reaction"]
  
        node.elements.each("graphics") { |graphics|
          attr = graphics.attributes
!         entry.x       = attr["x"].to_i
!         entry.y       = attr["y"].to_i
!         entry.type    = attr["type"]
!         entry.label   = attr["label"]	# name
!         entry.width   = attr["width"].to_i
!         entry.height  = attr["height"].to_i
!         entry.fgcolor = attr["fgcolor"]
!         entry.bgcolor = attr["bgcolor"]
        }
        @entries << entry
--- 153,180 ----
    end
  
!   def parse_entry(dom)
      @entries = Array.new
  
!     dom.elements.each("/pathway/entry") { |node|
        attr = node.attributes
        entry = Entry.new
!       entry.entry_id   = attr["id"].to_i
!       entry.name       = attr["name"]
!       entry.entry_type = attr["type"]
!       # implied
!       entry.link       = attr["link"]
!       entry.reaction   = attr["reaction"]
!       entry.map        = attr["map"]
  
        node.elements.each("graphics") { |graphics|
          attr = graphics.attributes
!         entry.x        = attr["x"].to_i
!         entry.y        = attr["y"].to_i
!         entry.shape    = attr["type"]
!         entry.label    = attr["name"]
!         entry.width    = attr["width"].to_i
!         entry.height   = attr["height"].to_i
!         entry.fgcolor  = attr["fgcolor"]
!         entry.bgcolor  = attr["bgcolor"]
        }
        @entries << entry
***************
*** 157,194 ****
    end
  
!   def parse_relation
      @relations = Array.new
  
!     @dom.elements.each("/pathway/relation") { |node|
        attr = node.attributes
        relation = Relation.new
!       relation.entry1 = attr["entry1"].to_i
!       relation.entry2 = attr["entry2"].to_i
!       relation.type   = attr["type"]
  
-       hash = Hash.new
        node.elements.each("subtype") { |subtype|
          attr = subtype.attributes
!         relation.name  = name  = attr["name"]
!         relation.value = value = attr["value"].to_i
!         hash[value] = name
        }
-       relation.subtype = hash
        @relations << relation
      }
    end
  
!   def parse_reaction
      @reactions = Array.new
  
!     @dom.elements.each("/pathway/reaction") { |node|
        attr = node.attributes
        reaction = Reaction.new
!       reaction.name = attr["name"]
!       reaction.type = attr["type"]
  
        substrates = Array.new
        products   = Array.new
!       hash       = Hash.new
  
        node.elements.each("substrate") { |substrate|
--- 182,216 ----
    end
  
!   def parse_relation(dom)
      @relations = Array.new
  
!     dom.elements.each("/pathway/relation") { |node|
        attr = node.attributes
        relation = Relation.new
!       relation.node1   = attr["entry1"].to_i
!       relation.node2   = attr["entry2"].to_i
!       relation.rel     = attr["type"]
  
        node.elements.each("subtype") { |subtype|
          attr = subtype.attributes
!         relation.name  = attr["name"]
!         relation.value = attr["value"]
        }
        @relations << relation
      }
    end
  
!   def parse_reaction(dom)
      @reactions = Array.new
  
!     dom.elements.each("/pathway/reaction") { |node|
        attr = node.attributes
        reaction = Reaction.new
!       reaction.entry_id  = attr["name"]
!       reaction.direction = attr["type"]
  
        substrates = Array.new
        products   = Array.new
!       hash        = Hash.new
  
        node.elements.each("substrate") { |substrate|
***************
*** 208,215 ****
          }
        }
- 
        reaction.substrates = substrates
!       reaction.products   = products
!       reaction.alt        = hash
  
        @reactions << reaction
--- 230,236 ----
          }
        }
        reaction.substrates = substrates
!       reaction.products = products
!       reaction.alt = hash
  
        @reactions << reaction
***************
*** 218,281 ****
  
  end # KGML
  end # KEGG
  end # Bio
  
  
- if __FILE__ == $0
-   require 'pp'
-   xml = ARGF.read
-   pp Bio::KEGG::KGML.new(xml)
- end
- 
- 
- =begin
- 
- # This is a test implementation which reflects original KGML data structure.
- 
- class KGML
- 
-   class Pathway
-     attr_accessor :name, :org, :number, :title, :image, :link
-     attr_accessor :entries, :relations, :reactions
- 
-     class Entry
-       attr_accessor :id, :name, :type, :link, :reaction, :map
-       attr_accessor :components, :graphics
- 
-       class Component
-         attr_accessor :id
-       end
- 
-       class Graphics
-         attr_accessor :name, :x, :y, :type, :width, :height, :fgcolor, :bgcolor
-       end
-     end
- 
-     class Relation
-       attr_accessor :entry1, :entry2, :type
-       attr_accessor :
- 
-       class Subtype
-         attr_accessor :name, :value
-       end
-     end
- 
-     class Reaction
-       attr_accessor :name, :type
- 
-       class Substrate
-         attr_accessor :name
-       end
- 
-       class Product
-         attr_accessor :name
-       end
- 
-       class Alt
-         attr_accessor :name
-       end
-     end
-   end
- 
- end
- =end
--- 239,245 ----
  
  end # KGML
+ 
  end # KEGG
  end # Bio
  
  




More information about the bioruby-cvs mailing list