[BioRuby-cvs] bioruby/lib/bio map.rb,1.6,1.7

Jan Aerts aerts at dev.open-bio.org
Tue Jun 27 12:37:44 UTC 2006


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

Modified Files:
	map.rb 
Log Message:
Removed Enumerable mixin from ActsLikeMap and ActsLikeMarker, because 'def each' would be ambiguous.
Included examples for using ActsLikeMap and ActsLikeMarker.


Index: map.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/map.rb,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** map.rb	7 Jun 2006 12:55:50 -0000	1.6
--- map.rb	27 Jun 2006 12:37:42 -0000	1.7
***************
*** 6,10 ****
  # Licence::     Ruby's
  #
! # $Id$
  require 'bio/location'
  
--- 6,10 ----
  # Licence::     Ruby's
  #
! # $Id:
  require 'bio/location'
  
***************
*** 65,74 ****
    #  puts "Does my_map2 contain marker3? => " + my_map2.contains_marker?(my_marker3).to_s
    #  
!   #  my_map1.sort.each do |mapping|
!   #    puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location[0].from.to_s + ".." + mapping.location[-1].to.to_s
    #  end
!   #  puts my_map1.min.marker.name
!   #  my_map2.each do |mapping|
!   #    puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location[0].from.to_s + ".." + mapping.location[-1].to.to_s
    #  end
    module Map
--- 65,74 ----
    #  puts "Does my_map2 contain marker3? => " + my_map2.contains_marker?(my_marker3).to_s
    #  
!   #  my_map1.mappings_as_map.sort.each do |mapping|
!   #    puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location.from.to_s + ".." + mapping.location.to.to_s
    #  end
!   #  puts my_map1.mappings_as_map.min.marker.name
!   #  my_map2.mappings_as_map.each do |mapping|
!   #    puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location.from.to_s + ".." + mapping.location.to.to_s
    #  end
    module Map
***************
*** 81,84 ****
--- 81,94 ----
    # 
    # Classes that include this mixin should provide an array property called mappings_as_map.
+   # For example:
+   #   class MyMapThing
+   #     include Bio::Map::ActsLikeMap
+   #     
+   #     def initialize (name)
+   #       @name = name
+   #       @mappings_as_maps = Array.new
+   #     end
+   #     attr_accessor :name, :mappings_as_map
+   #    end
      module ActsLikeMap
        include Enumerable
***************
*** 138,147 ****
        end
        
-       # Go through all Bio::Map::Mapping objects linked to this Bio::Map::SimpleMap.
-       def each
-         self.mappings_as_map.each do |mapping|
-           yield mapping
-         end
-       end
      end #ActsLikeMap
  
--- 148,151 ----
***************
*** 154,157 ****
--- 158,171 ----
      # 
      # Classes that include this mixin should provide an array property called mappings_as_marker.
+     # For example:
+     #   class MyMarkerThing
+     #     include Bio::Map::ActsLikeMarker
+     #     
+     #     def initialize (name)
+     #       @name = name
+     #       @mappings_as_marker = Array.new
+     #     end
+     #     attr_accessor :name, :mappings_as_marker
+     #    end
      module ActsLikeMarker
        include Enumerable
***************
*** 189,199 ****
          end
        end
- 
-       # Go through all Mapping objects linked to this marker.
-       def each
-         self.mappings_as_marker.each do |mapping|
-           yield mapping
-         end
-       end
        
        # Check whether this marker is mapped to a given Bio::Map::SimpleMap.
--- 203,206 ----
***************
*** 238,241 ****
--- 245,249 ----
        end
        
+ 
      end #ActsLikeMarker
  	  
***************
*** 253,257 ****
        # * _marker_: a Bio::Map::Marker object
        # * _location_: a Bio::Locations object
- 
        def initialize (map, marker, location = nil)
          @map, @marker, @location = map, marker, location
--- 261,264 ----
***************
*** 259,280 ****
        attr_accessor :map, :marker, :location
        
! #       # Compares the location of this mapping to another mapping.
! #       # ---
! #       # *Arguments*:
! #       # * other_mapping: Bio::Map::Mapping object
! #       # *Returns*::
! #       # * 1 if self < other location
! #       # * -1 if self > other location
! #       # * 0 if both location are the same
! #       # * nil if the argument is not a Bio::Location object
! #       def <=>(other)
! #         unless other.kind_of?(Bio::Map::Mapping)
! #           raise "[Error] markers are not comparable"
! #         end
! #         unless @map.equal?(other.map)
! #           raise "[Error] maps have to be the same"
! #         end
! #         return self.location<=>(other.location) # FIXME: no <=>-method in Bio::Locations
! #       end
      end # Mapping
      
--- 266,288 ----
        attr_accessor :map, :marker, :location
        
!       # Compares the location of this mapping to another mapping.
!       # ---
!       # *Arguments*:
!       # * other_mapping: Bio::Map::Mapping object
!       # *Returns*::
!       # * 1 if self < other location
!       # * -1 if self > other location
!       # * 0 if both location are the same
!       # * nil if the argument is not a Bio::Location object
!       def <=>(other)
!         unless other.kind_of?(Bio::Map::Mapping)
!           raise "[Error] markers are not comparable"
!         end
! 	    unless @map.equal?(other.map)
!           raise "[Error] maps have to be the same"
!         end
! 
!         return self.location.<=>(other.location)
!       end
      end # Mapping
      




More information about the bioruby-cvs mailing list