Module: Bio::Map::ActsLikeMarker

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

Overview

Description

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

  • map it to one or more maps

  • check if it's mapped to a given map and can be mixed into other classes (e.g. Bio::Map::Marker)

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

Instance Method Summary collapse

Instance Method Details

#add_mapping_as_marker(map, location = nil) ⇒ Object

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



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# 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) ⇒ Boolean

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


Arguments:

  • map: a Bio::Map::SimpleMap object

Returns

true or false

Returns:

  • (Boolean)


230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# 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) ⇒ Object

Return all mappings of this marker on a given map.


Arguments:

  • map: an object that mixes in Bio::Map::ActsLikeMap

Returns

array of Bio::Map::Mapping objects



271
272
273
274
275
276
277
278
279
280
281
282
283
284
# 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) ⇒ Object

Return all positions of this marker on a given map.


Arguments:

  • map: an object that mixes in Bio::Map::ActsLikeMap

Returns

array of Bio::Location objects



251
252
253
254
255
256
257
258
259
260
261
262
263
264
# 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