pyjanitor-devs/pyjanitor

[ENH] to_fasta as part of janitor.biology

Open

#646 ouverte le 12 mars 2020

Voir sur GitHub
 (1 commentaire) (0 réactions) (0 assignés)Python (164 forks)batch import
available for hackingenhancementgood first issue

Métriques du dépôt

Stars
 (1 217 stars)
Métriques de merge PR
 (Merge moyen 2j 12h) (4 PRs mergées en 30 j)

Description

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

Guide contributeur