This is a test version of Biostars. For the public version, visit https://www.biostars.org.
covert pandas dataframe into fasta file

How to covert pandas dataframe into fasta file with python script?

I have data in pandas data frame as which contains below data.

dataframe content

I want to store above "df" dataframe content to fasta file.

fasta pandas

please, take the time to write a correct title for your question. Also, show us what you tried.

"Title" refers to a title for your question, not your job title.

added the correct title

1 answer

The FASTA format is very loosely defined - all it needs is a single line header with a ">" and sequence in the next line. You can join/concatenate all fields except sequence using a delimiter (say _ or __ or even blank space but I recommend using a non-blank-space delimiter). Append this concatenated string to > and print it, then print sequence in the next line. Rinse and repeat.

I've outlined the approach for you, writing the code should be trivial.

Log in to answer this question.