-
Notifications
You must be signed in to change notification settings - Fork 1
/
extract_loops.py
35 lines (30 loc) · 1.02 KB
/
extract_loops.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
import os
import pandas as pd
from read_pdb import read_pdb
loopDefs = pd.read_excel('table_loopDefs.xlsx')
PDB = {}
ATOMS = ['C', 'CA', 'N']
# reading pdb data
for fpdb in os.listdir('pdb'):
if not fpdb.endswith('.pdb.gz'):
continue
pdbCode = fpdb.split('.')[0]
fpdb = os.path.join('pdb', fpdb)
pdbDataFrame = read_pdb(fpdb)
PDB[pdbCode] = pdbDataFrame
# creating instances
for i, loop in loopDefs.iterrows():
if loop.pdbCode not in PDB:
print('PDB not found (%s)' % loop.pdbCode)
continue
df = PDB[loop.pdbCode]
df = df[loop.resSeqFirst <= df['resSeq']]
df = df[loop.resSeqLast >= df['resSeq']]
df = df.query("chainID=='%s'" % loop.chainID)
df = df.query("name=='C' | name=='CA' | name=='N'")
df = df.query("altLoc==' ' | altLoc=='A'")
wdir = 'DATA_LOOP_%02d' % loop.loopSize
if not os.path.isdir(wdir):
os.mkdir(wdir)
fcsv = os.path.join(wdir, loop.pdbCode + '.csv')
df.to_csv(fcsv,index=False)