PythonExtract多个Fasta文件的最长序列?

2024-09-30 16:36:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经看到这个问题在其他地方已经有了答案,但这涉及到使用生物制品。我不想包括额外的库,因为它会减慢我的实现。有谁能提出解决这个问题的办法吗。在


Tags: 答案地方办法生物制品
1条回答
网友
1楼 · 发布于 2024-09-30 16:36:04

FASTA是一种非常简单的格式,因此您可以在几行代码中运行自己的解析器,例如

def iter_fasta(path):
    with open(path) as handle:
        header = None
        buf = []
        for line in handle:
            if line.isspace():
                continue  # Omit empty lines.

            line = line.strip()
            if line.startswith(">"):
                if buf:
                    assert header is not None
                    yield header, "".join(buf)
                    del buf[:]

                header = line[1:]  # Drop the '>'.
            else:
                buf.append(line)

        # Handle the last record.
        if buf:
            yield header, "".join(buf)

最长的序列是

^{pr2}$

相关问题 更多 >