how to combine multiple fasta file into a larger fasta file
2
0
Entering edit mode
7.2 years ago
bio90029 ▴ 10

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 • 16k views
ADD COMMENT
1
Entering edit mode

use command line : cat * > all.fasta

ADD REPLY
0
Entering edit mode

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?

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
2
Entering edit mode
7.2 years ago
lessismore ★ 1.4k

Youll find your answer here : Concatenate Multiple .Fasta Files

ADD COMMENT
0
Entering edit mode
7.2 years ago

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()
ADD COMMENT

Login before adding your answer.

Traffic: 2119 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6