pyjanitor-devs/pyjanitor

[ENH] to_fasta as part of janitor.biology

Open

#646 aperta il 12 mar 2020

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)Python (164 fork)batch import
available for hackingenhancementgood first issue

Metriche repository

Star
 (1217 star)
Metriche merge PR
 (Merge medio 2g 12h) (4 PR mergiate in 30 g)

Descrizione

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

Guida contributor