Module Bio::Map::ActsLikeMarker
In: lib/bio/map.rb

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

Methods

Public Instance methods

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

[Source]

     # File lib/bio/map.rb, line 203
203:       def add_mapping_as_marker(map, location = nil)
204:         unless map.class.include?(Bio::Map::ActsLikeMap)
205:           raise "[Error] map is not object that implements Bio::Map::ActsLikeMap"
206:         end
207:         my_mapping = (location.nil?) ? Bio::Map::Mappings.new(map, self, nil) : Bio::Map::Mapping.new(map, self, Bio::Locations.new(location))
208:         if ! self.mapped_to?(map)
209:           self.mappings_as_marker.push(my_mapping)
210:           map.mappings_as_map.push(my_mapping)
211:         else
212:           already_mapped = false
213:           self.positions_on(map).each do |loc|
214:             if loc.equals?(Bio::Locations.new(location))
215:               already_mapped = true
216:             end
217:           end
218:           if ! already_mapped
219:             self.mappings_as_marker.push(my_mapping)
220:             map.mappings_as_map.push(my_mapping)
221:           end
222:         end
223:       end

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


Arguments:

Returns:true or false

[Source]

     # File lib/bio/map.rb, line 230
230:       def mapped_to?(map)
231:         unless map.class.include?(Bio::Map::ActsLikeMap)
232:           raise "[Error] map is not object that implements Bio::Map::ActsLikeMap"
233:         end
234:                 
235:         mapped = false
236:         self.mappings_as_marker.each do |mapping|
237:           if mapping.map == map
238:             mapped = true
239:             return mapped
240:           end
241:         end
242: 
243:         return mapped
244:       end

Return all mappings of this marker on a given map.


Arguments:

Returns:array of Bio::Map::Mapping objects

[Source]

     # File lib/bio/map.rb, line 271
271:       def mappings_on(map)
272:         unless map.class.include?(Bio::Map::ActsLikeMap)
273:           raise "[Error] map is not object that implements Bio::Map::ActsLikeMap"
274:         end
275:         
276:         m = Array.new
277:         self.mappings_as_marker.each do |mapping|
278:           if mapping.map == map
279:             m.push(mapping)
280:           end
281:         end
282:         
283:         return m
284:       end

Return all positions of this marker on a given map.


Arguments:

Returns:array of Bio::Location objects

[Source]

     # File lib/bio/map.rb, line 251
251:       def positions_on(map)
252:         unless map.class.include?(Bio::Map::ActsLikeMap)
253:           raise "[Error] map is not object that implements Bio::Map::ActsLikeMap"
254:         end
255:         
256:         positions = Array.new
257:         self.mappings_as_marker.each do |mapping|
258:           if mapping.map == map
259:             positions.push(mapping.location)
260:           end
261:         end
262:         
263:         return positions
264:       end

[Validate]