我想裁剪这个gi|1168222|sp|P46098.1|5HT3A_HUMAN
来得到这个P46098
,但是对于这类的任何序列gi|"RANDOM"|sp|"SEQUENCE"|"RANDOM"
。
举个例子:
gi|1168222|sp|P46098.1|5HT3A_HUMAN
gi|1168223|sp|P35563.2|5HT3A_RAT
gi|112809|sp|P23979.1|5HT3A_MOUSE
gi|24211440|sp|O70212.1|5HT3A_CAVPO
gi|113067|sp|P22770|ACHA7_CHICK
我只想在sp|
和.
之间,或者|
如果没有.
这就是我现在得到的:
from Bio import SeqIO
import re
handle = open("seqdumpsp.txt", "rU")
for record in SeqIO.parse(handle, "fasta") :
line = record.id
i1 = line.index('sp|')
i2 = line.index('.')
line = line.replace(line[:i1], '', line)
line = line.replace(x[i2:], '')
print line
handle.close()
但是这不起作用,因为我不能使用i1和i2来替换
你可以说
line.split('|')[3]
通过字符串处理:
for
循环迭代内容中的每一行李>演示:
输出:
通过CSV
演示:
输出:
相关问题 更多 >
编程相关推荐