我试着在一行中定位一个特殊的字符“r”,然后检索它两侧的35个字符。可能不止一个“r”,所以我正在尝试获取所有的r。我一直在尝试这个代码,但我只得到了标题,我不能搞清楚。有什么建议吗
fhand=open("input.txt")
target = open ("output.txt", "a")
for line in fhand:
name, id, seq= line.split("\t")
while atpos < len(seq):
if atpos == -1:
break
atpos = seq.find ("r")
seq2 = seq[(atpos-35):(atpos+36)]
line2= name + "\t"+ id + "\t" + seq2 + "\n"
target.write(line2)
atpos += 1
print ("Sequences obtained successfully")
target.close()
相关问题 更多 >
编程相关推荐