Module: Bio::Map::ActsLikeMap

Included in:
SimpleMap
Defined in:
lib/bio/map.rb

Overview

Description

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

Instance Method Summary collapse

Instance Method Details

#add_mapping_as_map(marker, location = nil) ⇒ Object

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



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# 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

#contains_marker?(marker) ⇒ Boolean

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


Arguments:

  • marker: a Bio::Map::Marker object

Returns

true or false

Returns:

  • (Boolean)


147
148
149
150
151
152
153
154
155
156
157
158
159
# 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