Skip to content

Commit

Permalink
add strandedness to the sequence fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
James Casbon committed Apr 30, 2010
1 parent 2320b2a commit 4cdadc1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
14 changes: 13 additions & 1 deletion ensembl/core/base.py
@@ -1,4 +1,5 @@
from django.db import models
from ensembl.utils import reverse_complement


class StableIdManager(models.Manager):
Expand Down Expand Up @@ -38,6 +39,7 @@ class Meta:
seq_region = models.ForeignKey('SeqRegion')
seq_region_start = models.IntegerField()
seq_region_end = models.IntegerField()
seq_region_strand = models.IntegerField()

def sequence_level_assemblies(self):
"""return the set of assemblies at the sequence level for this object"""
Expand All @@ -62,10 +64,20 @@ def projected_coords(self, assemblies):
@property
def sequence(self):
"""return the sequence for this object"""

# fetch the component assemblies and their DNA and project coords into those
components = self.sequence_level_assemblies().select_related('cmp_seq_region__dna').all()
coords = self.projected_coords(components)
return ''.join([

# build the sequence from the component parts
sequence = ''.join([
component.cmp_seq_region.dna.sequence[start:end]
for (component,(start, end)) in zip(components, coords)
])

# reverse complement if necessary
if self.seq_region_strand == -1:
sequence = reverse_complement(sequence)

return sequence

6 changes: 3 additions & 3 deletions ensembl/core/models.py
Expand Up @@ -178,7 +178,7 @@ class Exon(HasSeqRegion, HasStableId):
# seq_region_id = models.IntegerField()
# seq_region_start = models.IntegerField()
# seq_region_end = models.IntegerField()
seq_region_strand = models.IntegerField()
# seq_region_strand = models.IntegerField()
phase = models.IntegerField()
end_phase = models.IntegerField()
is_current = models.IntegerField()
Expand Down Expand Up @@ -241,7 +241,7 @@ class Gene(HasSeqRegion, HasStableId):
# seq_region_id = models.IntegerField()
# seq_region_start = models.IntegerField()
# seq_region_end = models.IntegerField()
seq_region_strand = models.IntegerField()
# seq_region_strand = models.IntegerField()
display_xref_id = models.IntegerField(null=True, blank=True)
source = models.CharField(max_length=60)
status = models.CharField(max_length=57, blank=True)
Expand Down Expand Up @@ -653,7 +653,7 @@ class Transcript(HasSeqRegion, HasStableId):
# seq_region_id = models.IntegerField()
# seq_region_start = models.IntegerField()
# seq_region_end = models.IntegerField()
seq_region_strand = models.IntegerField()
# seq_region_strand = models.IntegerField()
display_xref_id = models.IntegerField(null=True, blank=True)
biotype = models.CharField(max_length=120)
status = models.CharField(max_length=57, blank=True)
Expand Down
2 changes: 1 addition & 1 deletion ensembl/core/routers.py
@@ -1,10 +1,10 @@
class EnsemblRouter(object):
""" Base class for routing, allows reads and prevents everything else"""

app = None
database = None

def db_for_read(self, model, **hints):
print model, model._meta.app_label
if model._meta.app_label == self.app:
return self.database
return None
Expand Down
6 changes: 5 additions & 1 deletion ensembl/utils.py
@@ -1,5 +1,5 @@
import unittest
from django.db import models
import string


class BasicTest(object):
Expand Down Expand Up @@ -28,3 +28,7 @@ def test_sequence_lookup_returns_object_of_correct_length(self):
# def test_sequence_lookup_returns_object_in_correct_orientation(self):
# assert(False)


_rc_trans = string.maketrans('ACGTN', 'TGCAN')
def reverse_complement(seq):
return string.translate(str(seq), _rc_trans)[::-1]
2 changes: 1 addition & 1 deletion ensembl/variation/models.py
Expand Up @@ -243,7 +243,7 @@ class VariationFeature(HasSeqRegion):
# seq_region_id = models.IntegerField()
# seq_region_start = models.IntegerField()
# seq_region_end = models.IntegerField()
seq_region_strand = models.IntegerField()
# seq_region_strand = models.IntegerField()
variation = models.ForeignKey('Variation')
allele_string = models.TextField(blank=True)
variation_name = models.CharField(max_length=765, blank=True)
Expand Down

0 comments on commit 4cdadc1

Please sign in to comment.