[BioRuby-cvs] bioruby/lib/bio pathway.rb,1.30,1.31

Katayama Toshiaki k at pub.open-bio.org
Sun Oct 23 05:11:30 EDT 2005


Update of /home/repository/bioruby/bioruby/lib/bio
In directory pub.open-bio.org:/tmp/cvs-serv18742

Modified Files:
	pathway.rb 
Log Message:
* nodes method returns list of nodes intead of number of nodes
* edges method returns list of edges using @relations instead of @graph
  * use nodes.length and edges.length instead of nodes and edges method
* removed clear_relations!, to_relations to ensure edges method works
* removed accessor for @relations to ensure user can't change it


Index: pathway.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/pathway.rb,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** pathway.rb	8 Sep 2005 01:22:08 -0000	1.30
--- pathway.rb	23 Oct 2005 09:11:27 -0000	1.31
***************
*** 28,31 ****
--- 28,34 ----
    class Pathway
  
+     #require 'chem'
+     #include Chem::Graph
+ 
      # Initial graph (adjacency list) generation from the list of Relation
      def initialize(relations, undirected = false)
***************
*** 37,41 ****
        self.to_list		# generate adjacency list
      end
!     attr_reader :relations, :graph, :index
      attr_accessor :label
  
--- 40,44 ----
        self.to_list		# generate adjacency list
      end
!     attr_reader :graph, :index
      attr_accessor :label
  
***************
*** 62,81 ****
      end
  
-     # clear @relations to reduce the memory usage
-     def clear_relations!
-       @relations.clear
-     end
- 
-     # reconstruct @relations from the adjacency list @graph
-     def to_relations
-       @relations.clear
-       @graph.each_key do |from|
-         @graph[from].each do |to, w|
-           @relations << Relation.new(from, to, w)
-         end
-       end
-       return @relations
-     end
- 
  
      # Graph (adjacency list) generation from the Relations
--- 65,68 ----
***************
*** 108,120 ****
  
      def nodes
!       @graph.keys.length
      end
  
      def edges
!       edges = 0
!       @graph.each_value do |v|
!         edges += v.size
!       end
!       edges
      end
  
--- 95,103 ----
  
      def nodes
!       [ @graph.keys + @graph.values ].sort.uniq
      end
  
      def edges
!       @relations
      end
  
***************
*** 131,140 ****
  
        matrix = Array.new
!       nodes.times do
!         matrix.push(Array.new(nodes, default_value))
        end
  
        if diagonal_value
!         nodes.times do |i|
            matrix[i][i] = diagonal_value
          end
--- 114,123 ----
  
        matrix = Array.new
!       nodes.length.times do
!         matrix.push(Array.new(nodes.length, default_value))
        end
  
        if diagonal_value
!         nodes.length.times do |i|
            matrix[i][i] = diagonal_value
          end
***************
*** 224,230 ****
        sg = subgraph(neighbors)
        if sg.graph.size != 0
!         edges = sg.edges / 2.0
!         nodes = sg.nodes
!         complete = (nodes * (nodes - 1)) / 2.0
          return edges/complete
        else
--- 207,213 ----
        sg = subgraph(neighbors)
        if sg.graph.size != 0
!         edges = sg.edges.length / 2.0
!         nodes = sg.nodes.length
!         complete = (nodes.length * (nodes.length - 1)) / 2.0
          return edges/complete
        else
***************
*** 374,378 ****
      def bellman_ford(root)
        distance, predecessor = initialize_single_source(root)
!       for i in 1 ..(self.nodes - 1) do
          @graph.each_key do |u|
            @graph[u].each do |v, w|
--- 357,361 ----
      def bellman_ford(root)
        distance, predecessor = initialize_single_source(root)
!       for i in 1 ..(self.nodes.length - 1) do
          @graph.each_key do |u|
            @graph[u].each do |v, w|
***************
*** 404,408 ****
        m = self.to_matrix(inf, 0)
        d = m.dup
!       n = self.nodes
        for k in 0 .. n - 1 do
          for i in 0 .. n - 1 do
--- 387,391 ----
        m = self.to_matrix(inf, 0)
        d = m.dup
!       n = self.nodes.length
        for k in 0 .. n - 1 do
          for i in 0 .. n - 1 do
***************
*** 498,501 ****
--- 481,488 ----
      attr_accessor :node, :edge
  
+     def [](n)
+       [@node, @edge].flatten[n]
+     end
+ 
      def from
        @node[0]
***************
*** 730,736 ****
  instance variable @relations) redundantly.
  
! Note: you can clear the @relations list by calling clear_relations! method to
! reduce the memory usage, and the content of the @relations can be re-generated
! from the @graph by to_relations method.
  
  --- Bio::Pathway.new(list, undirected = false)
--- 717,724 ----
  instance variable @relations) redundantly.
  
! # *** OBSOLETED ***
! #Note: you can clear the @relations list by calling clear_relations! method to
! #reduce the memory usage, and the content of the @relations can be re-generated
! #from the @graph by to_relations method.
  
  --- Bio::Pathway.new(list, undirected = false)
***************
*** 745,752 ****
          g = Bio::Pathway.new(list, 'undirected')
  
! --- Bio::Pathway#relations
! 
!       Read-only accessor for the internal list of the Bio::Relation objects
!       '@relations'.
  
  --- Bio::Pathway#graph
--- 733,741 ----
          g = Bio::Pathway.new(list, 'undirected')
  
! # *** OBSOLETED ***
! #--- Bio::Pathway#relations
! #
! #      Read-only accessor for the internal list of the Bio::Relation objects
! #      '@relations'.
  
  --- Bio::Pathway#graph
***************
*** 788,796 ****
        to_relations first.
  
! --- Bio::Pathway#clear_relations!
! --- Bio::Pathway#to_relations
! 
!       Clear @relations array and re-generate @relations from @graph.
!       Useful when you want to reduce the memory usage of the object.
  
  --- Bio::Pathway#to_list
--- 777,786 ----
        to_relations first.
  
! # *** OBSOLETED ***
! #--- Bio::Pathway#clear_relations!
! #--- Bio::Pathway#to_relations
! #
! #      Clear @relations array and re-generate @relations from @graph.
! #      Useful when you want to reduce the memory usage of the object.
  
  --- Bio::Pathway#to_list
***************
*** 813,817 ****
  --- Bio::Pathway#edges
  
!       Returns the number of the nodes or edges in the graph.
  
  --- Bio::Pathway#to_matrix(default_value = nil, diagonal_value = nil)
--- 803,808 ----
  --- Bio::Pathway#edges
  
!       Returns the nodes or edges in the graph.  Use Bio::Pathway#nodes.length
!       and Bio::Pathway#edges.length to have numbers of nodes and edges.
  
  --- Bio::Pathway#to_matrix(default_value = nil, diagonal_value = nil)



More information about the bioruby-cvs mailing list