module Ensembl::Core::Sliceable
The Sliceable
mixin holds the get_slice method and can be included in any class that lends itself to having a position on a SeqRegion
.
Public Instance Methods
The Sliceable#length
method returns the length of the feature (based on seq_region_start and seq_region_end.
@return [Integer] Length of the slice
# File lib/bio-ensembl/core/activerecord.rb, line 141 def length return self.stop - self.start + 1 end
The Sliceable#project
method is used to transfer coordinates from one coordinate system to another. Suppose you have a feature on a contig in human (let's say on contig AC000031.6.1.38703) and you want to know the coordinates on the chromosome. This is a projection of coordinates from a higher ranked coordinate system to a lower ranked coordinate system. Projections can also be done from a chromosome to the contig level. However, it might be possible that more than one contig has to be included and that there exist gaps between the contigs. The output of this method therefore is an array of Slice
and Gap
objects.
At the moment, projections can only be done if the two coordinate systems are linked directly in the 'assembly' table.
@example
# Get a contig slice in cow and project to scaffold level # (i.e. going from a high rank coord system to a lower rank coord # system) original_feature = Gene.find(85743) target_slices = original_feature.project('scaffold')
@param [String] coord_system_name Name of coordinate system to project coordinates to @return [Array<Slice,Gap>] an array consisting of Slices and, if necessary, Gaps
# File lib/bio-ensembl/core/activerecord.rb, line 168 def project(coord_system_name) return self.slice.project(coord_system_name) end
The Sliceable#seq
method takes the coordinates on a reference, transforms onto the seqlevel coordinate system if necessary, and retrieves the sequence.
@return [String] sequence
# File lib/bio-ensembl/core/activerecord.rb, line 109 def seq return self.slice.seq end
The Sliceable#slice
method takes the coordinates on a reference and creates a Ensembl::Core::Slice
object.
@return [Ensembl::Core::Slice] Ensembl::Core::Slice
object
# File lib/bio-ensembl/core/activerecord.rb, line 86 def slice start, stop, strand = nil, nil, nil if self.class == Ensembl::Core::Intron or self.class.column_names.include?('seq_region_start') start = self.seq_region_start end if self.class == Ensembl::Core::Intron or self.class.column_names.include?('seq_region_end') stop = self.seq_region_end end if self.class == Ensembl::Core::Intron or self.class.column_names.include?('seq_region_strand') strand = self.seq_region_strand else #FIXME: we shouldn't do this, but can't #project if no strand given strand = 1 end return Ensembl::Core::Slice.new(self.seq_region, start, stop, strand) end
The Sliceable#start
method is a convenience method and returns self.seq_region_start.
@return [Integer] seq_region_start
# File lib/bio-ensembl/core/activerecord.rb, line 117 def start return self.seq_region_start end
The Sliceable#stop
method is a convenience method and returns self.seq_region_end.
@return [Integer] seq_region_end
# File lib/bio-ensembl/core/activerecord.rb, line 125 def stop return self.seq_region_end end
The Sliceable#strand
method is a convenience method and returns self.seq_region_strand.
@return [Numeric] seq_region_strand
# File lib/bio-ensembl/core/activerecord.rb, line 133 def strand return self.seq_region_strand end
The transform
method is used to transfer coordinates for a feature from one coordinate system to another. It basically creates a clone of the original feature and changes the seq_region, start position, stop position and strand.
Suppose you have a feature on a contig in human (let's say on contig AC000031.6.1.38703) and you want to know the coordinates on the chromosome. This is a transformation of coordinates from a higher ranked coordinate system to a lower ranked coordinate system. Transformations can also be done from a chromosome to the contig level.
In contrast to the project
method of Sliceables, the coordinates of a feature can only transformed to the target coordinate system if there is no ambiguity to which SeqRegion
.
For example, gene A can be transferred from the chromosome system to the clone coordinate system, whereas gene B can not.
gene A gene B |---<=====>--------------------<=====>----------------| chromosome |-----------| |-------| |---------| clones |-----------| |-------| |--------| gene_a.transform('clone') --> gene gene_b.transform('clone') --> nil
At the moment, transformations can only be done if the two coordinate systems are linked directly in the 'assembly' table.
@example
# Get a gene in cow and transform to scaffold level # (i.e. going from a high rank coord system to a lower rank coord # system) # Cow scaffold Chr4.10 lies on Chr4 from 8030345 to 10087277 on the # reverse strand source_gene = Gene.find(2408) target_gene = source_gene.transform('scaffold') puts source_gene.seq_region.name #--> 4 puts source_gene.seq_region_start #--> 8104409 puts source_gene.seq_region_end #--> 8496477 puts source_gene.seq_region_strand #--> -1 puts target_gene.seq_region.name #--> Chr4.003.10 puts target_gene.seq_region_start #--> 1590800 puts target_gene.seq_region_end #--> 1982868 puts target_gene.seq_region_strand #--> 1
@param [String] coord_system_name Name of the coordinate system to
transform the coordinates to
@return Nil or an object of the same class
as self
# File lib/bio-ensembl/core/transform.rb, line 66 def transform(coord_system_name) #- # There are two things I can do: # (1) just use project # (2) avoid doing all the calculations in project if the source slice # covers multiple target slices, and _then_ go for project. # Let's go for nr 1 for the moment and optimize later. #+ if self.slice.seq_region.coord_system.name == coord_system_name return self end target_slices = self.slice.project(coord_system_name) if target_slices.length > 1 return nil else clone = self.clone clone.seq_region_id = target_slices[0].seq_region.id clone.seq_region_start = target_slices[0].start clone.seq_region_end = target_slices[0].stop clone.seq_region_strand = target_slices[0].strand * self.strand return clone end end