- #1
Bala06
- 10
- 0
Dear Members
I would like to match numbers in two files of extensions .lw & .pw and put the results according to matching numbers.
For example, the .lw file contains data as
59880 SPC X2d12G 4714 UNK X 900B
and .pw file has
59474 SPC X2c8bG 991 ILE A 118B
59726 SPC X2cdfG 1803 SER A 168B
59876 SPC X2d11G 4055 ASP A 356B
59879 SPC X2d12G 3849 ASN A 344B
I want to match according to this number "X2d12G" and put in output as
For example like this (result):
431-hydrogen-bond-frame.dat.c.d.pw [(4714, 'UNK', 'X 900B', 59880, 'SPC', 'X2d12G', 59879, 'SPC', 'X2d12G', 4186, 'ASN', 'A 344B')]
453-hydrogen-bond-frame.dat.c.d.pw [(4714, 'UNK', 'X 900B', 59880, 'SPC', 'X2d12G', 59879, 'SPC', 'X2d12G', 4186, 'ASN', 'A 344B')]
Since the attachments is limited, I couldn't attached thos file 453-hydrogen-bond-frame_lw.txt. It also contains the same data as 431-hydrogen-bond-frame_lw.txt.
When ever I run my python code, I'm not getting the result as expected.
I'm running python script as (python water_cont.py > summary.txt)
I 'm posting the python code for your reference.
Kindly advice.
Many Thanks
Balaji
I would like to match numbers in two files of extensions .lw & .pw and put the results according to matching numbers.
For example, the .lw file contains data as
59880 SPC X2d12G 4714 UNK X 900B
and .pw file has
59474 SPC X2c8bG 991 ILE A 118B
59726 SPC X2cdfG 1803 SER A 168B
59876 SPC X2d11G 4055 ASP A 356B
59879 SPC X2d12G 3849 ASN A 344B
I want to match according to this number "X2d12G" and put in output as
For example like this (result):
431-hydrogen-bond-frame.dat.c.d.pw [(4714, 'UNK', 'X 900B', 59880, 'SPC', 'X2d12G', 59879, 'SPC', 'X2d12G', 4186, 'ASN', 'A 344B')]
453-hydrogen-bond-frame.dat.c.d.pw [(4714, 'UNK', 'X 900B', 59880, 'SPC', 'X2d12G', 59879, 'SPC', 'X2d12G', 4186, 'ASN', 'A 344B')]
Since the attachments is limited, I couldn't attached thos file 453-hydrogen-bond-frame_lw.txt. It also contains the same data as 431-hydrogen-bond-frame_lw.txt.
When ever I run my python code, I'm not getting the result as expected.
I'm running python script as (python water_cont.py > summary.txt)
I 'm posting the python code for your reference.
Code:
#! /usr/bin/env python
import sys, os, math, glob
# Run as: python water_cont.py
# This script will provide the summary of waters along the trajectory.
# Use it after the run of python_water_cont.py
# Bala 28 May. 2011
#
def read_lig_wat(file):
file = open (file, "r")
data=file.readlines()
atom_number1 = map(lambda x: int(x[0:7]), data)
resname1 = map(lambda x: x[10:13], data)
res_number1=map(lambda x: x[17:23], data)
atom_number2=map(lambda x: int(x[27:36]), data)
resname2=map(lambda x: x[37:40], data)
res_number2= map(lambda x: x[44:50], data)
return atom_number1, resname1, res_number1, atom_number2, resname2, res_number2 def read_prot_wat(file1):
file1 = open (file, "r")
data1=file.readlines()
atom_number11 = map(lambda x: int(x[0:7]), data)
resname11 = map(lambda x: x[10:13], data)
res_number11=map(lambda x: x[17:23], data)
atom_number22=map(lambda x: int(x[27:36]), data)
resname22=map(lambda x: x[37:40], data)
res_number22= map(lambda x: x[44:50], data)
return atom_number11, resname11, res_number11, atom_number22, resname22, res_number22
for filename in glob.glob1("/home/water", "*.lw"):
atom_number1, resname1, res_number1, atom_number2, resname2, res_number2 =read_lig_wat(filename)
# column_file=summary+".lw"
# file2=open( column_file, "w")
text=len(atom_number1)
for filename in glob.glob1("/home/water", "*.pw"):
atom_number11, resname11, res_number11, atom_number22, resname22, res_number22 =read_lig_wat(filename)
# column_file=filename+".lw"
# file2=open( column_file, "w")
text1=len(atom_number11)
List=[]
for i in range(text):
for j in range(text1):
# print res_number2[i], res_number22[j]
# if res_number2[i]==res_number11[j]:
# print res_number1[i], res_number2[i]
if res_number1[i]==res_number11[j] or res_number1[i]==res_number22[j]\
or res_number2[i]==res_number11[j] or res_number2[i]==res_number22[j]:
# print atom_number1[i], resname1[i], res_number1[i], atom_number2[i], resname2[i], res_number2[i]
List.append((atom_number1[i], resname1[i], res_number1[i], atom_number2[i], resname2[i], res_number2[i], atom_number11[j], resname11[j], res_number11[j], atom_number22[j], resname22[j], res_number22[j]))
# print List
print filename, List
# file2.write("%5i%8s%11s%8i%8s%11s%5i%8s%11s%8i%8s%11s \n" % (atom_number1[i], resname1[i], res_number1[i], atom_number2[i], resname2[i], res_number2[i], atom_number11[i], resname11[i], res_number11[i], atom_number22[i], resname22[i], res_number22[i] ))
Kindly advice.
Many Thanks
Balaji
Attachments
Last edited: