Skip to content

Commit

Permalink
fixing translation of protein sequences, empirical formule, molecular…
Browse files Browse the repository at this point in the history
… weights
  • Loading branch information
jonrkarr committed Nov 14, 2018
1 parent f99fe5e commit 87578e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
16 changes: 9 additions & 7 deletions tests/test_prokaryote_schema.py
Expand Up @@ -189,28 +189,30 @@ def test_constructor(self):
self.assertEqual(protein.cell, None)

def test_get_seq(self):

# Use table 4 since example genes are from mycoplasma genitallium
# Use translation table 4 since example genes are from
# Mycoplasma genitallium

# MPN001
self.assertEqual(self.prot1.get_seq()[0:10], 'MKVLINKNEL')
self.assertEqual(self.prot1.get_seq()[-10:], 'ELKEILVPSK')

# MPN011
self.assertEqual(self.prot2.get_seq()[0:10], 'MKFKFLLTPL')
self.assertEqual(self.prot2.get_seq()[-10:], 'LFRYLVYLIE')

def test_get_empirical_formula(self):
# MPN001
self.assertEqual(self.prot1.get_empirical_formula(),
chem.EmpiricalFormula('C1980H3144N510O595S7'))
chem.EmpiricalFormula('C1980H3146N510O596S7'))
# MPN011
self.assertEqual(self.prot2.get_empirical_formula(),
chem.EmpiricalFormula('C1246H1926N306O351S3'))
chem.EmpiricalFormula('C1246H1928N306O352S3'))

def test_get_mol_wt(self):
# MPN001
self.assertAlmostEqual(self.prot1.get_mol_wt(), 43838.327, delta=0.3)
self.assertAlmostEqual(self.prot1.get_mol_wt(), 43856.342, delta=0.3)
# MNP011
self.assertAlmostEqual(self.prot2.get_mol_wt(), 26905.085, delta=0.3)
self.assertAlmostEqual(self.prot2.get_mol_wt(), 26923.100, delta=0.3)

def test_get_charge(self):
self.assertEqual(self.prot1.get_charge(), 1)
Expand Down Expand Up @@ -309,4 +311,4 @@ def test_ComplexSpeciesType(self):
self.assertAlmostEqual(complex1.get_mol_wt(),
(2*prot1.get_mol_wt() + 3 * prot2.get_mol_wt()))
self.assertEqual(complex1.get_empirical_formula(),
chem.EmpiricalFormula('C7698H12066N1938O2243S23'))
chem.EmpiricalFormula('C7698H12076N1938O2248S23'))
18 changes: 9 additions & 9 deletions wc_kb/prokaryote_schema.py
Expand Up @@ -119,22 +119,22 @@ class Meta(obj_model.Model.Meta):
attribute_order = ('id', 'name', 'gene', 'rna', 'circular', 'double_stranded',
'half_life', 'comments', 'references', 'database_references')

def get_seq(self, cds=False):
def get_seq(self, cds=True):
""" Get the sequence
Returns:
:obj:`Bio.Seq.Seq`: sequence
"""
return self.gene.get_seq().translate(table=self.cell.knowledge_base.translation_table, cds=cds)
seq = self.gene.get_seq().translate(table=self.cell.knowledge_base.translation_table, cds=cds)
return seq

def get_empirical_formula(self, cds=False):
def get_empirical_formula(self, cds=True):
""" Get the empirical formula
Returns:
:obj:`chem.EmpiricalFormula`: empirical formula
"""

seq = self.get_seq(cds)
seq = self.get_seq(cds=cds)
l = len(seq)

n_a = seq.count('A') # Ala: Alanine (C3 H7 N O2)
Expand Down Expand Up @@ -186,13 +186,13 @@ def get_empirical_formula(self, cds=False):
formula.S = n_c + n_m
return formula

def get_charge(self, cds=False):
def get_charge(self, cds=True):
""" Get the charge at physiological pH
Returns:
:obj:`int`: charge
"""
seq = self.get_seq(cds)
seq = self.get_seq(cds=cds)

n_r = seq.count('R')
n_h = seq.count('H')
Expand All @@ -202,13 +202,13 @@ def get_charge(self, cds=False):

return (n_r + n_h + n_k) - (n_d + n_e)

def get_mol_wt(self, cds=False):
def get_mol_wt(self, cds=True):
""" Get the molecular weight
Returns:
:obj:`float`: molecular weight
"""
return self.get_empirical_formula(cds).get_molecular_weight()
return self.get_empirical_formula(cds=cds).get_molecular_weight()


#####################
Expand Down

0 comments on commit 87578e9

Please sign in to comment.