Module: Ensembl::Core::Sliceable

Overview

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

Instance Method Details

#lengthInteger

The Sliceable#length method returns the length of the feature (based on seq_region_start and seq_region_end.

Returns:

  • (Integer)

    Length of the slice



141
142
143
# File 'lib/bio-ensembl/core/activerecord.rb', line 141

def length
  return self.stop - self.start + 1
end

#project(coord_system_name) ⇒ Array<Slice,Gap>

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.

Examples:

# 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')

Parameters:

  • coord_system_name (String)

    Name of coordinate system to project coordinates to

Returns:

  • (Array<Slice,Gap>)

    an array consisting of Slices and, if necessary, Gaps



168
169
170
# File 'lib/bio-ensembl/core/activerecord.rb', line 168

def project(coord_system_name)
  return self.slice.project(coord_system_name)
end

#seqString

The Sliceable#seq method takes the coordinates on a reference, transforms onto the seqlevel coordinate system if necessary, and retrieves the sequence.

Returns:

  • (String)

    sequence



109
110
111
# File 'lib/bio-ensembl/core/activerecord.rb', line 109

def seq
  return self.slice.seq
end

#sliceEnsembl::Core::Slice

The Sliceable#slice method takes the coordinates on a reference and creates a Ensembl::Core::Slice object.

Returns:



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# 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

#startInteger

The Sliceable#start method is a convenience method and returns self.seq_region_start.

Returns:

  • (Integer)

    seq_region_start



117
118
119
# File 'lib/bio-ensembl/core/activerecord.rb', line 117

def start
  return self.seq_region_start
end

#stopInteger

The Sliceable#stop method is a convenience method and returns self.seq_region_end.

Returns:

  • (Integer)

    seq_region_end



125
126
127
# File 'lib/bio-ensembl/core/activerecord.rb', line 125

def stop
  return self.seq_region_end
end

#strandNumeric

The Sliceable#strand method is a convenience method and returns self.seq_region_strand.

Returns:

  • (Numeric)

    seq_region_strand



133
134
135
# File 'lib/bio-ensembl/core/activerecord.rb', line 133

def strand
  return self.seq_region_strand
end

#transform(coord_system_name) ⇒ Object

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.

Examples:

# 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

Parameters:

  • coord_system_name (String)

    Name of the coordinate system to transform the coordinates to

Returns:

  • Nil or an object of the same class as self



66
67
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
# 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