Method: Bio::Map::ActsLikeMap#add_mapping_as_map

Defined in:
lib/bio/map.rb

#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