Skip to content

Instantly share code, notes, and snippets.

@raivivek
Created January 30, 2015 08:42
Show Gist options
  • Save raivivek/6563a557d6d6a77a4ffe to your computer and use it in GitHub Desktop.
Save raivivek/6563a557d6d6a77a4ffe to your computer and use it in GitHub Desktop.
code
#!/usr/bin/python3
# -*- coding: utf-8 -*-
""" Calculates the number and percentage composition of different
types of amino acid residues within a protein."""
HYDROPHOBIC_AA = ['ALA', 'GLY', 'VAL', 'ILE', 'LEU', 'PRO']
POSITIVE_AA = ['ARG', 'HIS']
NEGATIVE_AA = ['ASP', 'GLU']
NEUTRAL_AA = ['SER', 'THR', 'HIS', 'CYS', 'MET', 'ASN', 'GLN']
AROMATIC_AA = ['PHE', 'TYR', 'TRP']
def get_composition(pdb_file):
count = {
'TOTAL_AA' : 0,
'HYDROPHOBIC_AA' : 0,
'POSITIVE_AA' : 0,
'NEGATIVE_AA' : 0,
'NEUTRAL_AA' : 0,
'AROMATIC_AA' : 0
}
for line in pdb_file.readlines():
if line.startswith('SEQRES'):
residues = line.split()[4:]
count['TOTAL_AA'] += len(residues)
for residue in residues:
if residue in HYDROPHOBIC_AA:
count['HYDROPHOBIC_AA'] += 1
elif residue in POSITIVE_AA:
count['POSITIVE_AA'] += 1
elif residue in NEGATIVE_AA:
count['NEGATIVE_AA'] += 1
elif residue in NEUTRAL_AA:
count['NEUTRAL_AA'] += 1
elif residue in AROMATIC_AA:
count['AROMATIC_AA'] += 1
return count
if __name__ == "__main__":
with open('12AS.pdb', 'r', encoding='utf-8') as f:
print(get_composition(f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment