module Bio::Map::ActsLikeMap

Description

The Bio::Map::ActsLikeMap module contains methods that are typical for map-like things:

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

Public Instance Methods

add_mapping_as_map(marker, location = nil) click to toggle source

Description

Adds a Bio::Map::Mappings object to its array of mappings.

Usage

# 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
116 def add_mapping_as_map(marker, location = nil)
117   unless marker.class.include?(Bio::Map::ActsLikeMarker)
118     raise "[Error] marker is not object that implements Bio::Map::ActsLikeMarker"
119   end
120   my_mapping = ( location.nil? ) ? Bio::Map::Mapping.new(self, marker, nil) : Bio::Map::Mapping.new(self, marker, Bio::Locations.new(location))
121   if ! marker.mapped_to?(self)
122     self.mappings_as_map.push(my_mapping)
123     marker.mappings_as_marker.push(my_mapping)
124   else
125     already_mapped = false
126     marker.positions_on(self).each do |loc|
127       if loc.equals?(Bio::Locations.new(location))
128         already_mapped = true
129       end
130     end
131     if ! already_mapped
132       self.mappings_as_map.push(my_mapping)
133       marker.mappings_as_marker.push(my_mapping)
134     end
135   end
136 
137   return self
138 end
contains_marker?(marker) click to toggle source

Checks whether a Bio::Map::Marker is mapped to this Bio::Map::SimpleMap.


Arguments:

Returns

true or false

    # File lib/bio/map.rb
147 def contains_marker?(marker)
148   unless marker.class.include?(Bio::Map::ActsLikeMarker)
149     raise "[Error] marker is not object that implements Bio::Map::ActsLikeMarker"
150   end
151   contains = false
152   self.mappings_as_map.each do |mapping|
153     if mapping.marker == marker
154       contains = true
155       return contains
156     end
157   end
158   return contains
159 end