如何从BLAST输出中获取无缺口序列?

1 投票
3 回答
607 浏览
提问于 2025-04-17 02:22

我想从BLAST的输出结果中获取没有间隙的序列,并且希望以FASTA格式保存。我原本以为可以用hsps_no_gap这个方法,但它没有奏效。请问有没有其他方法可以实现这个目标?

3 个回答

0

如果你想选择没有空隙的序列,可以试试使用

for records in blast:
   if records.alignments:
   for align in records.alignments:
      if align.hsps.gap == 0
      print ("These ID have ungapped alignment : %s" % records.query)
0

我假设你的序列是存储在 SeqIO.Seq 对象里的。

你可能想用 SeqIO.Seq 里的 ungap 方法。这个 文档写得很不错。使用 ungap() 比用字符串替换要好,因为它可以根据序列的字母表自动识别缺口字符。

示例代码:

from Bio import SeqIO

seq_records = SeqIO.parse("input.fasta", format='fasta')
for record in seq_records:
    seq_ungapped = record.seq.ungap('-')
0

BLAST的输出格式是什么?是XML格式吗?你可以从BLAST的输出中提取hsps(高评分片段对),然后进行以下操作:

for alignment in blast_record.alignments:
    for hsp in alignment.hsps:
        query_no_gaps = hsp.query.replace("-","")
        sbjct_no_gaps = hsp.sbjct.replace("-","")

接着,使用这些新变量来写入fasta格式。

撰写回答