module Bio::Map::ActsLikeMarker

Description

The Bio::Map::ActsLikeMarker module contains methods that are typical for marker-like things:

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

Public Instance Methods

add_mapping_as_marker(map, 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::Marker object called marker_a
marker_a.add_mapping_as_marker(Bio::Map::SimpleMap.new('my_map'), '5')

Arguments:

  • map (required): Bio::Map::SimpleMap object

  • location: location of mapping. Should be a string, not a number.

Returns

itself

# File lib/bio/map.rb, line 203
def add_mapping_as_marker(map, location = nil)
  unless map.class.include?(Bio::Map::ActsLikeMap)
    raise "[Error] map is not object that implements Bio::Map::ActsLikeMap"
  end
  my_mapping = (location.nil?) ? Bio::Map::Mappings.new(map, self, nil) : Bio::Map::Mapping.new(map, self, Bio::Locations.new(location))
  if ! self.mapped_to?(map)
    self.mappings_as_marker.push(my_mapping)
    map.mappings_as_map.push(my_mapping)
  else
    already_mapped = false
    self.positions_on(map).each do |loc|
      if loc.equals?(Bio::Locations.new(location))
        already_mapped = true
      end
    end
    if ! already_mapped
      self.mappings_as_marker.push(my_mapping)
      map.mappings_as_map.push(my_mapping)
    end
  end
end
mapped_to?(map) click to toggle source

Check whether this marker is mapped to a given Bio::Map::SimpleMap.


Arguments:

Returns

true or false

# File lib/bio/map.rb, line 230
def mapped_to?(map)
  unless map.class.include?(Bio::Map::ActsLikeMap)
    raise "[Error] map is not object that implements Bio::Map::ActsLikeMap"
  end
          
  mapped = false
  self.mappings_as_marker.each do |mapping|
    if mapping.map == map
      mapped = true
      return mapped
    end
  end

  return mapped
end
mappings_on(map) click to toggle source

Return all mappings of this marker on a given map.


Arguments:

Returns

array of Bio::Map::Mapping objects

# File lib/bio/map.rb, line 271
def mappings_on(map)
  unless map.class.include?(Bio::Map::ActsLikeMap)
    raise "[Error] map is not object that implements Bio::Map::ActsLikeMap"
  end
  
  m = Array.new
  self.mappings_as_marker.each do |mapping|
    if mapping.map == map
      m.push(mapping)
    end
  end
  
  return m
end
positions_on(map) click to toggle source

Return all positions of this marker on a given map.


Arguments:

Returns

array of Bio::Location objects

# File lib/bio/map.rb, line 251
def positions_on(map)
  unless map.class.include?(Bio::Map::ActsLikeMap)
    raise "[Error] map is not object that implements Bio::Map::ActsLikeMap"
  end
  
  positions = Array.new
  self.mappings_as_marker.each do |mapping|
    if mapping.map == map
      positions.push(mapping.location)
    end
  end
  
  return positions
end