[BioRuby-cvs] bioruby/lib/bio pathway.rb,1.32,1.33

Katayama Toshiaki k at pub.open-bio.org
Fri Nov 4 12:39:46 EST 2005


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

Modified Files:
	pathway.rb 
Log Message:
* bug fix patch contributed by Moses Hohman which was kept in
  test/unit/bio/test_pathway.rb is ported.
  note that this module is broken by the previous changes (nodes/edges?)
  and still not pass the unit tests...


Index: pathway.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/pathway.rb,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** pathway.rb	23 Oct 2005 09:48:58 -0000	1.32
--- pathway.rb	4 Nov 2005 17:39:44 -0000	1.33
***************
*** 2,9 ****
  # = bio/pathway.rb - Binary relations and Graph algorithms
  #
! # Author::	Toshiaki Katayama <k at bioruby.org>
! #		Shuichi Kawashima <shuichi at hgc.jp>
  #		Nobuya Tanaka <t at chemruby.org>
- # Copyright::	Copyright (c) 2001, 2005 BioRuby project
  # License::	LGPL
  #
--- 2,9 ----
  # = bio/pathway.rb - Binary relations and Graph algorithms
  #
! # Copyright::	Copyright (c) 2001, 2005
! # 		Toshiaki Katayama <k at bioruby.org>,
! #		Shuichi Kawashima <shuichi at hgc.jp>,
  #		Nobuya Tanaka <t at chemruby.org>
  # License::	LGPL
  #
***************
*** 53,58 ****
  
    #--
!   #require 'chem'
!   #include Chem::Graph
    #++
  
--- 53,58 ----
  
    #--
!   # require 'chem'
!   # include Chem::Graph
    #++
  
***************
*** 295,301 ****
      @graph.each do |from, hash|
        next unless @label[from]
        hash.each do |to, relation|
          next unless @label[to]
!         sub_graph.append(Relation.new(from, to, relation))
        end
      end
--- 295,302 ----
      @graph.each do |from, hash|
        next unless @label[from]
+       sub_graph.graph[from] = {}
        hash.each do |to, relation|
          next unless @label[to]
!         sub_graph.graph[from][to] = relation
        end
      end
***************
*** 322,337 ****
    #
    def cliquishness(node)
      neighbors = @graph[node].keys
!     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
!       return 0.0
      end
    end
  
  
    # Returns frequency of the nodes having same number of edges as hash
--- 323,348 ----
    #
    def cliquishness(node)
+     if not undirected?
+       raise "Can't calculate cliquishness in directed graph"
+     end
      neighbors = @graph[node].keys
!     case neighbors.size
!     when 0
!       return Float::NaN
!     when 1
!       return 1
      else
!       num_neighbor_edges = subgraph_adjacency_matrix(neighbors).flatten.sum / 2
!       num_complete_edges = neighbors.size * (neighbors.size - 1) / 2
!       return num_neighbor_edges.to_f / num_complete_edges.to_f
      end
    end
  
+   def subgraph_adjacency_matrix(nodes)
+     adjacency_matrix = to_matrix(0).to_a
+     node_indices = nodes.collect {|x| @index[x]}
+     subgraph = adjacency_matrix.values_at(*node_indices)
+     subgraph.collect!{|row| row.values_at(*node_indices)}
+   end
  
    # Returns frequency of the nodes having same number of edges as hash



More information about the bioruby-cvs mailing list