-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCAdist_AF.py
More file actions
executable file
·128 lines (99 loc) · 3.39 KB
/
CAdist_AF.py
File metadata and controls
executable file
·128 lines (99 loc) · 3.39 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""
ProtMapPep.py
Created by Pathmanaban Ramasamy on 18th Sep 2018
Copyright (c) 2018 Pathmanaban Ramasamy. All rights reserved.
"""
from Bio.PDB import *
import numpy
import sys, getopt
import csv,os,argparse
from collections import defaultdict
import itertools
def ca_dist(res1,res2):
ca1 = res1['CA']
ca2 = res2['CA']
# Simply subtract the CA atoms to get their distance
distance = ca1 - ca2
return distance
# ~ x=0
# ~ keyerr=[]
def pdbparse(protid,pos1,pos2):
# ~ global x
# ~ global keyerr
parser = PDBParser()
curwd=os.getcwd()
pdbid1="AF-"+protid+"-F1-model_v2.pdb"
filepath=curwd+"/PDB/"+pdbid1
if os.path.isfile(filepath):
structure = parser.get_structure(protid, filepath)
model=structure[0]
chain = model['A']
pos1,pos2=int(pos1),int(pos2)
#print chain[238]
try:
residue1 = chain[pos1]
residue2 = chain[pos2]
aadist=ca_dist(residue1,residue2)
return aadist
except KeyError as e:
# ~ x+=1
print (e.args[0])
# ~ keyer.append([protid,pos1,pos2])
def CAdist():
parser = argparse.ArgumentParser(description='CA distance ')
parser.add_argument('-i','--ifile', help='specify the infile name with extension', required=True)
parser.add_argument('-o','--ofile', help='specify the outfile name with extension', required=True)
parser.add_argument('-p1','--pos1',help='column index of first residue position in infile',required=True)
parser.add_argument('-p2','--pos2',help='column index of second residue in infile',required=True)
parser.add_argument('-a','--acc',help='column index of protein accession in infile',required=True)
args = vars(parser.parse_args())
if len(args)==5:
infile=args['ifile']
outfile=args['ofile']
mut_pos=int(args['pos1'])
ptm_pos=int(args['pos2'])
accession=int(args['acc'])
with open(infile,'r') as infile,open(outfile,'w') as outfile1:
writer = csv.writer(outfile1,delimiter='\t')
writer.writerow(['ACC_ID','residue1','residue2','CAdist(A)'])
next(infile,None)
datalis=defaultdict(list)
for line in infile:
line=line.split(',')
protid=line[accession]
ptmpos=line[ptm_pos]
mutpos=line[mut_pos]
if protid not in datalis:
datalis[protid]=[(mutpos,ptmpos)]
elif protid in datalis:
#print datalis[pdbid][0],chain
datalis[protid].append((mutpos,ptmpos))
for acc,poslist in datalis.items():
pdbid=acc
poslist=list(set(poslist))
print ("Calculating for Protein: ", pdbid)
if poslist:
for elem in poslist:
#print elem
ca_dist=pdbparse(pdbid,elem[0],elem[1])
writer.writerow([pdbid,int(elem[0]),int(elem[1]),float(ca_dist)])
# ~ print ("total keyerrors",x)
# ~ print (keyerr)
print ("\n")
print ("#################### Program finished ##############\n")
print ("Your results are available in the file: ", outfile)
print ("\n")
print ("*****************************************************")
print (" Thanks for using CAdist ")
print ("*****************************************************")
else:
print ("Some argument missing")
sys.exit()
if __name__ == "__main__":
print ("\n")
print ("**************************************************")
print (" CAdist version 1.0 ")
print ("**************************************************")
print ("\n")
print ("Measuring CA distance.....please wait..............")
CAdist()