The Bio::Map::ActsLikeMap module contains methods that are typical for map-like things:
add markers with their locations (through Bio::Map::Mappings)
check if a given marker is mapped to it, and can be mixed into other classes (e.g. Bio::Map::SimpleMap)
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
Adds a Bio::Map::Mappings object to its array of mappings.
# suppose we have a Bio::Map::SimpleMap object called my_map my_map.add_mapping_as_map(Bio::Map::Marker.new('marker_a'), '5')
Arguments:
marker (required): Bio::Map::Marker object
location: location of mapping. Should be a string, not a number.
Returns |
itself |
# File lib/bio/map.rb, line 116 def add_mapping_as_map(marker, location = nil) unless marker.class.include?(Bio::Map::ActsLikeMarker) raise "[Error] marker is not object that implements Bio::Map::ActsLikeMarker" end my_mapping = ( location.nil? ) ? Bio::Map::Mapping.new(self, marker, nil) : Bio::Map::Mapping.new(self, marker, Bio::Locations.new(location)) if ! marker.mapped_to?(self) self.mappings_as_map.push(my_mapping) marker.mappings_as_marker.push(my_mapping) else already_mapped = false marker.positions_on(self).each do |loc| if loc.equals?(Bio::Locations.new(location)) already_mapped = true end end if ! already_mapped self.mappings_as_map.push(my_mapping) marker.mappings_as_marker.push(my_mapping) end end return self end
Checks whether a Bio::Map::Marker is mapped to this Bio::Map::SimpleMap.
Arguments:
marker: a Bio::Map::Marker object
Returns |
true or false |
# File lib/bio/map.rb, line 147 def contains_marker?(marker) unless marker.class.include?(Bio::Map::ActsLikeMarker) raise "[Error] marker is not object that implements Bio::Map::ActsLikeMarker" end contains = false self.mappings_as_map.each do |mapping| if mapping.marker == marker contains = true return contains end end return contains end
Generated with the Darkfish Rdoc Generator 2.