class Bio::Relation

Bio::Relation is a simple object storing two nodes and the relation of them. The nodes and the edge (relation) can be any Ruby object. You can also compare Bio::Relation objects if the edges have Comparable property.

Attributes

edge[RW]
node[RW]

Public Class Methods

new(node1, node2, edge) click to toggle source

Create new binary relation object consists of the two object 'node1' and 'node2' with the 'edge' object as the relation of them.

    # File lib/bio/pathway.rb
718 def initialize(node1, node2, edge)
719   @node = [node1, node2]
720   @edge = edge
721 end

Public Instance Methods

<=>(rel) click to toggle source

Used by the each method to compare with another Bio::Relation object. This method is only usable when the edge objects have the property of the module Comparable.

    # File lib/bio/pathway.rb
773 def <=>(rel)
774   unless self.edge.kind_of? Comparable
775     raise "[Error] edges are not comparable"
776   end
777   if self.edge > rel.edge
778     return 1
779   elsif self.edge < rel.edge
780     return -1
781   elsif self.edge == rel.edge
782     return 0
783   end
784 end
===(rel) click to toggle source

Compare with another Bio::Relation object whether havind same edges and same nodes. The == method compares Bio::Relation object's id, however this case equality === method compares the internal property of the Bio::Relation object.

    # File lib/bio/pathway.rb
747 def ===(rel)
748   if self.edge == rel.edge
749     if self.node[0] == rel.node[0] and self.node[1] == rel.node[1]
750       return true
751     elsif self.node[0] == rel.node[1] and self.node[1] == rel.node[0]
752       return true
753     else
754       return false
755     end
756   else
757     return false
758   end
759 end
Also aliased as: eql?
eql?(rel)

Method eql? is an alias of the === method and is used with hash method to make uniq arry of the Bio::Relation objects.

a1 = Bio::Relation.new('a', 'b', 1)
a2 = Bio::Relation.new('b', 'a', 1)
a3 = Bio::Relation.new('b', 'c', 1)

p [ a1, a2, a3 ].uniq

Alias for: ===
from() click to toggle source

Returns one node.

    # File lib/bio/pathway.rb
725 def from
726   @node[0]
727 end
hash() click to toggle source

Used by eql? method

    # File lib/bio/pathway.rb
739 def hash
740   @node.sort.push(@edge).hash
741 end
relation() click to toggle source
    # File lib/bio/pathway.rb
734 def relation
735   @edge
736 end
to() click to toggle source

Returns another node.

    # File lib/bio/pathway.rb
730 def to
731   @node[1]
732 end