pyjanitor-devs/pyjanitor

[ENH] to_fasta as part of janitor.biology

Open

#646 geöffnet am 12. März 2020

Auf GitHub ansehen
 (1 Kommentar) (0 Reaktionen) (0 zugewiesene Personen)Python (164 Forks)batch import
available for hackingenhancementgood first issue

Repository-Metriken

Stars
 (1.217 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 2T 12h) (4 gemergte PRs in 30 T)

Beschreibung

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")

Contributor Guide