生物信息学与算法

双序列比对后统计插入与删除(indels)的数量

2018-10-02  本文已影响16人  小明的数据分析笔记本
#导入re和SeqIO模块,re模块用来写正则表达式,SeqIO模块用来解析fasta文件
import re
from Bio import SeqIO
#分别将比对后的两条序列存入到列表中
seq = []
for record in SeqIO.parse("aligned.fasta","fasta"):
  seq.append(str(record.seq))
#使用正则表达式匹配序列中出现“-”的位置,然后输出到文件中
motif = "-+"
regexp = re.compile(motif)
#统计第一条序列中是 “-” 的位置
match1 = regexp.finditer(seq[0])
fw1 = open("indels_1.txt","w")
i = 0
for s in match1:
  i = i + 1
  location = list(s.span())
  fw1.write(str(i)+"\n")
  fw1.write(seq[0][location[0]:location[1]]+"\n")
  fw1.write(seq[1][location[0]:location[1]]+"\n")
fw1.close()
#统计第二条序列中是 “-” 的位置,输出到文件中
match2 = regexp.finditer(seq[1])
fw2 = open("indels_2.txt","w")
i = 0
for s in match2:
  i = i + 1
  location = list(s.span())
  fw2.write(str(i)+"\n")
  fw2.write(seq[0][location[0]:location[1]]+"\n")
  fw2.write(seq[1][location[0]:location[1]]+"\n")
fw2.close()
未完待续。。。。。。
上一篇 下一篇

猜你喜欢

热点阅读