pyjanitor-devs/pyjanitor

[ENH] to_fasta as part of janitor.biology

Open

#646 创建于 2020年3月12日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)Python (164 fork)batch import
available for hackingenhancementgood first issue

仓库指标

Star
 (1,217 star)
PR 合并指标
 (平均合并 2天 12小时) (30 天内合并 4 个 PR)

描述

janitor.biology could do with a to_fasta function, I think. The intent here would be to conveniently export a dataframe of sequences as a FASTA file, using one column as the fasta header.

strawman implementation below:

import pandas_flavor as pf
from Bio.SeqRecord import SeqRecord
from Bio.Seq import Seq
from Bio import SeqIO

@pf.register_dataframe_method
def to_fasta(df, identifier_column_name, sequence_column_name, filename):
    seq_records = []
    for r, d in df.iterrows():
        seq = Seq(d[sequence_column_name])
        seq_record = SeqRecord(seq, id=d[identifier_column_name], description="", name="")
        seq_records.append(seq_record)
    SeqIO.write(seq_records, filename, format="fasta")

贡献者指南