-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructure_prop.py
73 lines (60 loc) · 2.31 KB
/
structure_prop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/env python
from parse_pdb import Pdb
from Bio.PDB import *
from Bio.PDB.ResidueDepth import get_surface, residue_depth
# Compute the diameter of the protein.
def get_diameter(pdb):
return pdb.count_width()
# Compute the ratio of surface and buried amino acids.
def get_surface_aa(pdb):
surface = get_surface(pdb.structure)
surface_aa = [r for r in pdb.structure.get_residues() if residue_depth(r,surface) < 2 and r.get_resname() != 'HOH']
return surface_aa
def get_buried_aa(pdb):
surface = get_surface(pdb.structure)
buried_aa = [r for r in pdb.structure.get_residues() if residue_depth(r,surface) > 2 and r.get_resname() != 'HOH']
return buried_aa
def get_ratio(pdb):
surface = len(get_surface_aa(pdb))
buried = len(get_buried_aa(pdb))
total = surface + buried
return (surface/total, buried/total)
def get_buried_counts(pdb):
buried_aa = get_buried_aa(pdb)
buried_names = [aa.get_resname() for aa in buried_aa]
aa_names = {aa.get_resname() for aa in buried_aa}
counts = [(buried_names.count(aa),aa) for aa in aa_names]
counts.sort(reverse=True)
return counts
def get_surface_counts(pdb):
surface_aa = get_surface_aa(pdb)
surface_names = [aa.get_resname() for aa in surface_aa]
aa_names = set(surface_names)
counts = [(surface_names.count(aa),aa) for aa in aa_names]
counts.sort(reverse=True)
return counts
POLAR = ['ARG','ASN','ASP','CYS','GLN','GLU','HIS','LYS','SER','THR','TYR']
def count_polar_on_surface(pdb):
surface_aa = get_surface_aa(pdb)
surface_names = [aa.get_resname() for aa in surface_aa]
polar_aa = [aa for aa in surface_names if aa in POLAR]
return len(polar_aa)/len(surface_aa)
def count_polar_buried(pdb):
buried_counts = get_buried_counts(pdb)
total = 0
num = 0
for count, aa in buried_counts:
total += count
if aa in POLAR:
num += count
return num/total
if __name__ == "__main__":
p = Pdb('1B0B.pdb')
#print(get_diameter(p))
print('surface aa:',len(get_surface_aa(p)))
print('buried aa:',len(get_buried_aa(p)))
#print(len(list(p.structure.get_residues())))
print('surface vs buried:',get_ratio(p))
#print(get_buried_counts(p))
print('polar on surface:',count_polar_on_surface(p))
print('polar buried:',count_polar_buried(p))