I have results from Dimplot in two files named filename1 and filename2 in my program. The results look like:
1a2y HIS A 30 PO4 C 130 S_S 1
1a2y ASN C 19 THR A 53 S_S 1
1a2y GLN C 121 PHE A 91 S_M 1
1a2y SER A 93 GLN C 121 M_S 1
I have separate folders with results for each PDB file (X).
I am interested in creating an output file containing the complete set of residues from a PDB file and matching that with the results from the file which I have divided as two dictionaries, A and B, i.e. A contains (HIS A 30 ): { SS: 1} B contains (PO4 C 130 ):{ SS: 1}, also the same for C and D.
I want to match the residues from file X and if it matches with A or B or C or D then to update the value of MS, SS, MM, SM defined as interactions , and write 1 if present and 0 if not there.
So final output is something like:
Res C ResN SS SM MS MM
MET A 1 0 1 0 0
GLN A 2 0 0 0 0
LYS A 3 0 0 0 0
TYR A 4 0 0 0 0
GLU A 5 0 0 1 0
LYS A 6 0 0 0 0
LEU A 7 1 0 0 1
GLU A 8 0 0 0 0
My script is below: #!/usr/bin/python # read the list of PDB chains and create folder # change dir and create filenames for each combinatoion of .hhb and .nnb #parse lines and rearrange data
import re
import string
import os
pdblist = "/home/sami/Desktop/new_pdb4.txt"
diroutput = "/home/sami/Desktop/dimplot/output/"
pdbs = {}
pdbrec = '/data/bio/db/pdb/'
def read_pdb_list(pdblist, pdbs):
#read the list of PDBs and input PDB_ID and chains into dictionary
fh = open(pdblist, 'r')
all_line=fh.read()
fh.close()
lines=all_line.split("\n")
# print lines
for line in lines:
# print line
if string.find(string.letters, line):
columns =line.split()
chains= columns[1:3]
chains.sort()
if len(columns) > 0 :
pdbs.setdefault(columns[0],{})
pdbs[columns[0]].setdefault(chains[0],{})
pdbs[columns[0]][chains[0]].setdefault(chains[1],line)
def for_pbs(pdbid, chain1, chain2):
name = pdbid + chain1 + chain2 + ".hhb"
read_pdb_list(pdblist,pdbs)
for p in pdbs.keys():
each_pdb= diroutput + p + '/'
# print p
if not os.path.isdir(each_pdb):
os.mkdir(each_pdb)
for c1 in pdbs[p].keys():
for c2 in pdbs[p][c1].keys():
filename1 = p + c1 + c2 +".hhb" + "parsedhhb.txt"
filename2 = p + c1 + c2 +".nnb" + "parse.txt"
pdb_name = pdbrec+'pdb'+p.lower()+'.ent'
work_dir = each_pdb
os.chdir(work_dir)
for line in open(pdb_name):
D = {}
Dl = {}
if re.match('ATOM', line[0:4]):
mylist = line.split()
a = mylist[3]
b= mylist[4]
c = mylist[5]
d = []
d.append(c)
d.append(a)
d.append(b)
d = tuple(d)
D.setdefault(c, {})
D[c].setdefault(a, {})
D[c][a].setdefault(b, {})
Dl.setdefault(d, {})
for line in open(filename1):
mylist2 = line.split()
res1 = mylist2[1]
chain1 = mylist2[2]
resn1 = mylist2[3]
res2 = mylist2[4]
chain2 = mylist2[5]
resn2 = mylist2[6]
prop = mylist2[7]
propr = mylist2[8]
A = {}
a = []
b = []
a.append(resn1)
a.append(res1)
a.append(chain1)
a = tuple(a)
b.append(resn2)
b.append(res2)
b.append(chain2)
b = tuple(b)
B = {}
A.setdefault(a, {})
A[a].setdefault(prop)
A[a][prop] = propr
B.setdefault(b, {})
B[b].setdefault(prop)
B[b][prop] = propr
for line in open(filename2):
mylist3 = line.split()
res11 = mylist3[1]
chain11 = mylist3[2]
resn11 = mylist3[3]
res22 = mylist3[4]
chain22 = mylist3[5]
resn22 = mylist3[6]
prop1 = mylist3[7]
propr1 = mylist3[8]
E = {}
e = []
f = []
e.append(resn11)
e.append(res11)
e.append(chain11)
e = tuple(e)
f.append(resn22)
f.append(res22)
f.append(chain22)
f = tuple(f)
F = {}
E.setdefault(e, {})
E[e].setdefault(prop1)
E[e][prop1] = propr1
F.setdefault(f, {})
F[f].setdefault(prop1)
F[f][prop1] = propr1
outfile_f = open('result2.txt', 'w')
g = Dl.keys()
h = A.keys()
i = B.keys()
j = E.keys()
k = F.keys()
for l in g:
if (l in h) or (l in i) or (l in j) or (l in k):
try:
bb = A[l].keys()
cc = A[l].values()
except KeyError:
bb = '_'
cc = 0
try:
bb = B[l].keys()
cc = B[l].values()
except KeyError:
bb = '_'
cc = 0
try:
bb = E[l].keys()
cc = E[l].values()
except KeyError:
bb = '_'
cc = 0
try:
bb = F[l].keys()
cc = F[l].values()
except KeyError:
bb = '_'
cc = 0
if bb == ['S_S']:
outfile_f.write("%-3s\t%-5s\t%-4s\t%-3s\t%-3s\t%-3s\t%-3s\n" %(l[1],l[2],l[0],cc,0, 0,0))
elif bb == ['S_M']:
outfile_f.write("%-3s\t%-5s\t%-4s\t%-3s\t%-3s\t%-3s\t%-3s\n" %(l[1],l[2],l[0],0,cc, 0,0))
elif bb == ['M_S']:
outfile_f.write("%-3s\t%-5s\t%-4s\t%-3s\t%-3s\t%-3s\t%-3s\n" %(l[1],l[2],l[0],0,0, cc,0))
elif bb == ['M_M'] :
outfile_f.write("%-3s\t%-5s\t%-4s\t%-3s\t%-3s\t%-3s\t%-3s\n" %(l[1],l[2],l[0],cc,0, 0,0))
else:
outfile_f.write("%-3s\t%-5s\t%-4s\t%-3s\t%-3s\t%-3s\t%-3s\n" %(l[1],l[2],l[0],0,0, 0,0))
outfile_f.close()
The problem is my program shows a blank result file as output.
Just a reminder to everyone: indent your code with at least 4 spaces, or it won't be correctly formatted and displayed.
The problem is my program shows a blank result file as output.
I've changed the title, remember to explain which software you are referring to.
Thanks, i will keep that in mind for the next question.