Module: Ensembl::Core::Sliceable
- Included in:
- AssemblyException, DnaAlignFeature, Exon, Gene, Intron, Karyotype, MarkerFeature, MiscFeature, OligoFeature, PredictionExon, PredictionTranscript, ProteinAlignFeature, ProteinFeature, RegulatoryFeature, RepeatFeature, SimpleFeature, Transcript
- Defined in:
- lib/ensembl/core/activerecord.rb,
lib/ensembl/core/transform.rb
Overview
DESCRIPTION
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.
Instance Method Summary collapse
-
#length ⇒ Object
DESCRIPTION The Sliceable#length method returns the length of the feature (based on seq_region_start and seq_region_end. — Arguments:: none Returns:: sequence.
-
#project(coord_system_name) ⇒ Object
DESCRIPTION The Sliceable#project method is used to transfer coordinates from one coordinate system to another.
-
#seq ⇒ Object
DESCRIPTION The Sliceable#seq method takes the coordinates on a reference, transforms onto the seqlevel coordinate system if necessary, and retrieves the sequence.
-
#slice ⇒ Object
DESCRIPTION The Sliceable#slice method takes the coordinates on a reference and creates a Ensembl::Core::Slice object.
-
#start ⇒ Object
DESCRIPTION The Sliceable#start method is a convenience method and returns self.seq_region_start.
-
#stop ⇒ Object
DESCRIPTION The Sliceable#stop method is a convenience method and returns self.seq_region_end.
-
#strand ⇒ Object
DESCRIPTION The Sliceable#strand method is a convenience method and returns self.seq_region_strand.
-
#transform(coord_system_name) ⇒ Object
DESCRIPTION The #transform method is used to transfer coordinates for a feature from one coordinate system to another.
Instance Method Details
#length ⇒ Object
DESCRIPTION
The Sliceable#length method returns the length of the feature (based on seq_region_start and seq_region_end.
- Arguments
-
none
- Returns
-
sequence
153 154 155 |
# File 'lib/ensembl/core/activerecord.rb', line 153 def length return self.stop - self.start + 1 end |
#project(coord_system_name) ⇒ Object
DESCRIPTION
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.
USAGE
# 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')
Arguments:
- coord_system_name
-
name of coordinate system to project
coordinates to
- Returns
-
an array consisting of Slices and, if necessary, Gaps
185 186 187 |
# File 'lib/ensembl/core/activerecord.rb', line 185 def project(coord_system_name) return self.slice.project(coord_system_name) end |
#seq ⇒ Object
DESCRIPTION
The Sliceable#seq method takes the coordinates on a reference, transforms onto the seqlevel coordinate system if necessary, and retrieves the sequence.
- Arguments
-
none
- Returns
-
sequence
113 114 115 |
# File 'lib/ensembl/core/activerecord.rb', line 113 def seq return self.slice.seq end |
#slice ⇒ Object
DESCRIPTION
The Sliceable#slice method takes the coordinates on a reference and creates a Ensembl::Core::Slice object.
- Arguments
-
none
- Returns
-
Ensembl::Core::Slice object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/ensembl/core/activerecord.rb', line 88 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 |
#start ⇒ Object
DESCRIPTION
The Sliceable#start method is a convenience method and returns self.seq_region_start.
- Arguments
-
none
- Returns
-
sequence
123 124 125 |
# File 'lib/ensembl/core/activerecord.rb', line 123 def start return self.seq_region_start end |
#stop ⇒ Object
DESCRIPTION
The Sliceable#stop method is a convenience method and returns self.seq_region_end.
- Arguments
-
none
- Returns
-
sequence
133 134 135 |
# File 'lib/ensembl/core/activerecord.rb', line 133 def stop return self.seq_region_end end |
#strand ⇒ Object
DESCRIPTION
The Sliceable#strand method is a convenience method and returns self.seq_region_strand.
- Arguments
-
none
- Returns
-
sequence
143 144 145 |
# File 'lib/ensembl/core/activerecord.rb', line 143 def strand return self.seq_region_strand end |
#transform(coord_system_name) ⇒ Object
DESCRIPTION
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.
USAGE
# 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
Arguments:
- coord_system_name
-
name of coordinate system to transform to
coordinates to
- Returns
-
nil or an object of the same class as self
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ensembl/core/transform.rb', line 68 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 |