我试图从python中的pdb输入文件中打印预定义的序列,但是我没有得到预期的结果。我是python的新手,我也有导入目录,但它不能工作。没有显示任何东西(找不到错误)。它只是运行而没有任何输出。
import os
os.chdir('C:\Users\Vishnu\Desktop\Test_folder\Input')
for path, dirs, pdbfile in os.walk('/C:\Users\Vishnu\Desktop\Test_folder\Input'):
for line in pdbfile:
if line[:6] != "HETATM":
continue
chainID = line[21:22]
atomID = line[13:16].strip()
if chainID not in ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'):
continue
if atomID not in ('C4B', 'O4B', 'C1B', 'C2B', 'C3B'):
continue
with open('C:\Users\Vishnu\Desktop\Test_folder\Input', 'r') as fh:
new = [line.rstrip() for line in fh]
with open('C:\Users\Vishnu\Desktop\Test_folder\Output', 'w') as fh:
[fh.write('%s\n' % line) for line in new]
fh.write((line.rstrip()))预期产出:
HETATM 3788 C4B NAI A 302 52.695 15.486 8.535 1.00 57.28 C
HETATM 3789 O4B NAI A 302 52.258 14.631 7.456 1.00 56.26 O
HETATM 3794 C1B NAI A 302 53.348 13.816 7.022 1.00 53.44 C
HETATM 3792 C2B NAI A 302 54.537 14.748 7.190 1.00 50.93 C
HETATM 3789 O4B NAI A 302 52.258 14.631 7.456 1.00 56.26 O
HETATM 3794 C1B NAI A 302 53.348 13.816 7.022 1.00 53.44 C
HETATM 3792 C2B NAI A 302 54.537 14.748 7.190 1.00 50.93 C
HETATM 3790 C3B NAI A 302 54.225 15.525 8.465 1.00 52.99 C
HETATM 3794 C1B NAI A 302 53.348 13.816 7.022 1.00 53.44 C
HETATM 3792 C2B NAI A 302 54.537 14.748 7.190 1.00 50.93 C
HETATM 3790 C3B NAI A 302 54.225 15.525 8.465 1.00 52.99 C
HETATM 3788 C4B NAI A 302 52.695 15.486 8.535 1.00 57.28 C
HETATM 3792 C2B NAI A 302 54.537 14.748 7.190 1.00 50.93 C
HETATM 3790 C3B NAI A 302 54.225 15.525 8.465 1.00 52.99 C
HETATM 3788 C4B NAI A 302 52.695 15.486 8.535 1.00 57.28 C
HETATM 3789 O4B NAI A 302 52.258 14.631 7.456 1.00 56.26 O
HETATM 3790 C3B NAI A 302 54.225 15.525 8.465 1.00 52.99 C
HETATM 3788 C4B NAI A 302 52.695 15.486 8.535 1.00 57.28 C
HETATM 3789 O4B NAI A 302 52.258 14.631 7.456 1.00 56.26 O
HETATM 3794 C1B NAI A 302 53.348 13.816 7.022 1.00 53.44 C B链的格式也一样。
如何打印预定义的序列?第21:22行是否有链ID,链ID可以是A到H ?如何定义A到H链ID?
我无法按顺序打印,有人能让我知道如何在python中打印预定义的序列吗?
回答后的:
我已经用以下代码更新了上述代码:
n = 4
for chain, atoms in d.items():
for atom, line in atoms.items():
for i in range(len(atom)-n+1):
for j in range(n):
print d[chain][atomIDs[i+j]]
print我想再延长两段,但不能得到预期的产出。
发布于 2016-10-13 08:00:45
以下是我的评论,综合起来回答如下:
with open('1AHI.pdb') as pdbfile:
for line in pdbfile:
if line[:6] != "HETATM":
continue
chainID = line[21:22]
atomID = line[13:16].strip()
if chainID not in ('A', 'B'):
continue
if atomID not in ('C4B', 'O4B', 'C1B', 'C2B', 'C3B'):
continue
## Either:
print(line, end='')
## Or:
print(line.rstrip(), end='\n')
## Or if Python2.x:
print line.rstrip()我的第一行代码是十多年前编写的,解析PDB文件。别绝望。你前面有一段漫长而美丽的旅程。
我觉得mmCIF比PDB现在更喜欢.确保您阅读了这两种文件格式的规范。
我已经更新了答案,但请注意,这个网站是为了解决具体的问题,而不是其他人为你做的工作。人们普遍看不起它。
d = {}
chainIDs = ('A', 'B',)
atomIDs = ('C4B', 'O4B', 'C1B', 'C2B', 'C3B', 'C4B')
with open('1AHI.pdb') as pdbfile:
for line in map(str.rstrip, pdbfile):
if line[:6] != "HETATM":
continue
chainID = line[21:22]
atomID = line[13:16].strip()
if chainID not in chainIDs:
continue
if atomID not in atomIDs:
continue
try:
d[chainID][atomID] = line
except KeyError:
d[chainID] = {atomID: line}
n = 4
for chainID in chainIDs:
for i in range(len(atomIDs)-n+1):
for j in range(n):
print d[chainID][atomIDs[i+j]]
printhttps://stackoverflow.com/questions/40015183
复制相似问题