-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixhisname
More file actions
executable file
·76 lines (68 loc) · 1.95 KB
/
Copy pathfixhisname
File metadata and controls
executable file
·76 lines (68 loc) · 1.95 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
#!/usr/bin/python
# fixhisname.py
usage='''
usage: $0 in.pdb out.pdb
This script is used to fix his name :
To modify HIS to : HID if only exist HD1
HIE if only exist HE2
HIP if both HD1 and HE2 exist
by Qiuyu Fu 2014
'''
import sys,os
# Read in parameters
if len(sys.argv)<3:
print usage
sys.exit()
infile,outfile=sys.argv[1:3]
# Find HIS first (include HID ,HIE,HIP . for check use)
hisresi=dict()
for line in os.popen("""grep ATOM %s |grep -v REMARK|grep -E 'HIS|HID|HIE|HIP' |cut -b 22-26|uniq """%(infile,)):
hisresi[line[:-1]]= set()
print hisresi
# Determine HIS type (scan infile first time)
ifp=open(infile,"r")
for line in ifp:
lineitems=line.split()
if lineitems[0]!="ATOM":continue
# chain=line[21].strip()
# index=line[22:26].strip()
# resiindex="%s %s"%(chain,index)
resiindex=line[21:26]
if not hisresi.has_key(resiindex):continue
atomtype=line[12:16].strip()
if atomtype=="HD1":
hisresi[resiindex].add("HD1")
if atomtype=="HE2":
hisresi[resiindex].add("HE2")
ifp.close()
print hisresi
# trans "HD1HE" to "HIP"
for key in hisresi:
if hisresi[key]==set(("HD1","HE2")):
hisresi[key]="HIP"
elif hisresi[key]==set(("HD1",)):
hisresi[key]="HID"
elif hisresi[key]==set(("HE2",)):
hisresi[key]="HIE"
else:
hisresi[key]="HIS"
# Reload in.pdb and correct HIS name and write in to out.pdb
ifp=open(infile,"r")
ofp=open(outfile,"w")
for line in ifp:
lineitems=line.split()
if lineitems[0]!="ATOM":
ofp.write(line)
else:
# chain=line[21].strip()
# index=line[22:26].strip()
# resiindex="%s %s"%(chain,index)
resiindex=line[21:26]
if not hisresi.has_key(resiindex):
ofp.write(line)
else:
histype=hisresi[resiindex]
# print histype
ofp.write(line.replace("HIS",histype))
ifp.close()
ofp.close()