Skip to content

Commit

Permalink
Add residue codes
Browse files Browse the repository at this point in the history
  • Loading branch information
samirelanduk committed May 17, 2018
1 parent 1c75fb1 commit e676eb2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
17 changes: 17 additions & 0 deletions atomium/structures/molecules.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,17 @@ def full_name(self):
return RESIDUES.get(self._name.upper(), self._name)


@property
def code(self):
"""Returns the amino acid code of the reside if it is one of the 20
canonical amino acids - otherwise it just returns 'X'.
:rtype: ``str``"""

if self._name:
return CODES.get(self._name.upper(), "X")


@property
def next(self):
"""Residues can be linked to each other in a linear chain. This property
Expand Down Expand Up @@ -832,3 +843,9 @@ def chain(self):
"ASP": "aspartic acid", "GLU": "glutamic acid", "LYS": "lysine",
"ARG": "arginine", "HIS": "histidine", "HOH": "water"
}

CODES = {
"VAL":"V", "ILE":"I", "LEU":"L", "GLU":"E", "GLN":"Q", "ASP":"D", "ASN":"N",
"HIS":"H", "TRP":"W", "PHE":"F", "TYR":"Y", "ARG":"R", "LYS":"K", "SER":"S",
"THR":"T", "MET":"M", "ALA":"A", "GLY":"G", "PRO":"P", "CYS":"C"
}
4 changes: 4 additions & 0 deletions tests/integration/test_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,12 @@ def test_atoms_in_molecules(self):
self.assertEqual(res1.full_name, "valine")
self.assertEqual(res2.full_name, "glutamic acid")
self.assertEqual(res3.full_name, "tryptophan")
self.assertEqual(res1.code, "V")
self.assertEqual(res2.code, "E")
self.assertEqual(res3.code, "W")
res3.name = "XYZ"
self.assertEqual(res3.full_name, "XYZ")
self.assertEqual(res3.code, "X")

# Copies
copy = molecule.copy()
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/structure_tests/test_residues.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ def test_can_lookup_full_name(self):



class ResidueCodeTests(ResidueTest):

def test_can_get_generic_code(self):
res = Residue(self.atom1, self.atom2, self.atom3)
self.assertIsNone(res.code)
res._name = "XMP"
self.assertEqual(res.code, "X")


def test_can_lookup_code(self):
res = Residue(self.atom1, self.atom2, self.atom3)
res._name = "met"
self.assertEqual(res.code, "M")



class ResidueNextTests(ResidueTest):

def test_next_gets_next(self):
Expand Down

0 comments on commit e676eb2

Please sign in to comment.