python - 如何使用 Biopython 获得多个序列比对的共识?

标签 python bioinformatics biopython

我正在尝试从多重比对s文件(fasta格式)中获取一致序列。

我有一些 fasta 文件,每个文件都包含多个序列比对。当我尝试运行下面的这个函数时,我得到一个 AttributeError: 'generator' object has no attribute 'get_alignment_length'

我无法找到任何使用 AlignIO.parse 的代码示例,我只看到使用 AlignIO.read 的示例。

def get_consensus_seq(filename):

    alignments = (AlignIO.parse(filename,"fasta"))
    summary_align = AlignInfo.SummaryInfo(alignments)
    consensus_seq = summary_align.dumb_consensus(0.7,"N")
    print(consensus_seq)

最佳答案

如果我理解你的情况正确,问题是无法从多个对齐中获取 SummaryInfo 。他们应该合而为一。

from __future__ import annotations
from pathlib import Path
from itertools import chain

import Bio
from Bio import AlignIO
from Bio.Align import MultipleSeqAlignment
from Bio.Align.AlignInfo import SummaryInfo


SeqRecord = Bio.SeqRecord.SeqRecord


def get_consensus_seq(filename: Path | str) -> SeqRecord:
    common_alignment = MultipleSeqAlignment(
        chain(*AlignIO.parse(filename, "fasta"))
    )
    summary = SummaryInfo(common_alignment)
    consensus = summary.dumb_consensus(0.7, "N")
    return consensus

关于python - 如何使用 Biopython 获得多个序列比对的共识?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73702044/

相关文章:

python - 如何识别基因组中特定位置的特征

python - Biopython安装问题: "ImportError: No module named bio"

python - 使用 tensorflow 2 实现梯度惩罚损失

python - 强制代码流转到 except block

Bash 脚本循环只运行一次

java - 您可以使用 BufferedWriter 选择要写入的行吗?

linux - 如何用file2中的相同编号替换file1中的相同编号

python - Django 保存空白值

python - 加载模型时出现意外错误: problem in predictor - ModuleNotFoundError: No module named 'torchvision'

python - 一次又一次编辑python脚本文件