对于像这样的序列:
NM_001003443 chr11 + 5925152 5926098 5925152 5926098 2 5925152,5925652, 5925404,5926098,
我想要一条如下所示的信息行(未拼接,意味着 sys.argv 中有一个“-s”):
>NM_00100343|chr11(+):5925152Z5926098
或(拼接,sys.argv 中没有“-s”):
>NM_00100343|chr11(+):5925152Z5926098|5925151Z5925404,5925652Z5926098
我试图这样做,但一直得到不正确的匹配,有人可以查看我的正则表达式并查看它是否看起来和/或匹配正确吗?
我已经写了:
p = '(NM_\d+)\s+(chr\d+)\s+([+|-])\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+ (\d+)\s+(\d+),(\d+),\s+(\d+),(\d+),'
并尝试通过(文件中的每一行看起来像上面给出的行示例,由 fp = open(infile, 'r') 打开:
for line in fp:
r = search(p, line)
if '-s' in sys.argv and r:
wp.write('>'+r.group(1)+'|'+r.group(2)+'('+r.group(3)+')'+':'+r.group(4)+'-'+r.group(5))
else:
wp.write('>'+r.group(1)+'|'+r.group(2)+'('+r.group(3)+')'+':'+r.group(4)+'-'+r.group(5)+'|'+r.group(6)+'-'+r.group(11)+','+r.group(9)+'-'+r.group(12))
编辑,这似乎是正确的?
for line in fp:
line = line.replace(',',' ')
tokens = line.split()
if '-s' in sys.argv and r:
wp.write('>'+tokens[0]+'|'+tokens[1]+'('+tokens[2]+')'+':'+tokens[3]+'-'+tokens[4])
else:
wp.write('>'+tokens[0]+'|'+tokens[1]+'('+tokens[2]+')'+':'+tokens[3]+'-'+tokens[4]+'|'+tokens[5]+'-'+tokens[10]+','+tokens[8]+'-'+tokens[11])