This is a test version of Biostars. For the public version, visit https://www.biostars.org.
how to combine multiple fasta file into a larger fasta file

Hi, I have about 93 fasta file that I would like to combine in a single bigger one without losing any sequence in the process. I had a look around but I have only seen perl or bash, and I would like to do this with python. Any suggestions on how I can do this, please?

python biopython

I would like to do this with python

When you specify exacting requirements like this you should also say why. This can't be an assignment since it is too simple a problem to need python. Perhaps you are not telling us the complete story?

Sorry to disappoint you but I use python as my prefer language, and the one I understand the most.

Coding in Python can be beneficial in many ways. I myself, code in Python. However, command-line tools will make a task easier, and faster than you could do with Python. In Linux, these are essential to a bioinformatician.

2 answers

Youll find your answer here : Concatenate Multiple .Fasta Files

As genomax said, this task is too simple for Python. However, if you still insist on solving this with Python, here's the solution:

import os

DIR = 'fasta_files/'

oh = open('one_fasta_file.fasta', 'w')
for f in os.listdir(DIR):
    fh = open(os.path.join(DIR, f))
    for line in fh:
        oh.write(line)
    fh.close()
oh.close()

Log in to answer this question.