Skip to content

Biostumblematic

A biophysicist teaches himself how to code

<insert ramble about how long it’s been since the last post here>

So I’m back to working with Django, and once again something that seems simple is killing me.  I simply want to be able to define the various conserved domains in the protein, then be able to automatically pull out the amino acid sequence of a given domain.  The problem (which I’ve dealt with before) is getting the python classes to talk to one another.

Here is some simple code to illustrate:

class Protein(models.Model):
    uniprot = models.CharField('Uniprot accession code', max_length=6, blank=True)
    sequence = models.TextField('Amino acid sequence')

class Domain(models.Model):
    protein = models.ForeignKey(Protein)
    domain = models.CharField('Domain Name', max_length=25, blank=True)
    domain_start = models.IntegerField('Domain start residue', blank=True)
    domain_stop = models.IntegerField('Domain end residue', blank=True)

So what I want to do looks like this in my head, but doesn’t work:

class Domain(models.Model):
...
    def domain_FASTA(self):
        amino_clean = re.sub("\s+", "", protein.sequence)
        domain_sstart = self.domain_start - 1 # lists start from 0
        domain_sstop = self.domain_stop - 1
        domain_seq = amino_clean[domain_sstart:domain_sstop]
        fasta = '> '+protein.uniprot+' - '+self.domain+' '+str(self.domain_start)+'-'+str(self.domain_stop)+'\n'+domain_seq
        return fasta

I’ve been banging on this for hours, and have managed to fairly thoroughly break the things that I did have working. Fortunately I’m older and wiser than I once was, so I managed to restore them. I’m pretty well stumped on how to solve this one, though.

Advertisements

Tags: , ,

%d bloggers like this: