我正在使用以下代码来组合两个文本文件:
def combine_acpd_ccs(self, ccs_file, acps_file, out_file):
with open(ccs_file, 'r') as in_file1:
with open(acps_file, 'r') as in_file2:
with open(out_file, 'w') as out1:
out1.write('PDB\tPA\tEHSS\tACPS\n')
for line in in_file1:
segs = line.split()
for i in in_file2:
sse_score = i.split()
#print line
#print segs
if segs[0][:-4] == sse_score[0]:
out1.write(segs[0][:-4]+'\t'+segs[1]+'\t'+segs[2]+'\t'+sse_score[1]+'\n')
示例数据如下所示:
ccs_file:
1b0o.pdb 1399.0 1772.0
1b8e.pdb 1397.0 1764.0
acps_文件:
1b0o 0.000756946316066
1b8e 8.40662008775
1b0o 6.25931529116
我希望我的输出是这样的:
PDB PA EHSS ACPS
1b0o 1399.0 1772.0 0.000756946316066
1b0o 1399.0 1772.0 6.25931529116
1b8e 1397.0 1764.0 8.40662008775
但是我的代码只生成了我预期输出的前两行。segs
如果我在第二个循环中打印,则for
仅将第一行ccs_file
传递给循环。有什么想法我哪里出错了吗?