Question: alignment of multiple multifasta files- MAFFT command line
gravatar for Wilber0x
12 months ago by
Wilber0x10 wrote:

I have a folder with around 100 multifasta files. I want to align each multifasta file inidividually using MAFFT. Each multifasta file ends with .unaligned.fasta I would like to change those file endings to aligned.fasta.

I have tried using MAFFT normally on the command line as so, with asterisks to allow for multiple characters where necessary:

mafft --quiet *.unaligned.fasta > *.aligned.fasta

However, I get error messages like this one

Unknown option:  beaverHb.unaligned.fasta

for all of my multifasta files.

How can I align all my multifasta files using MAFFT in the command line?

mafft sequence alignment • 1.2k views
ADD COMMENTlink modified 12 months ago by h.mon31k • written 12 months ago by Wilber0x10

Some more general advice, this isn't a quirk of MAFFT, what you're trying to do with that command won't work more broadly.

The shell doesn't know what *.aligned.fasta means for example, so you need to help it out by building the filenames from variables etc (or use parallel's {.} syntax).

I'd advise doing some more reading about working with wildcards and loops in the shell as what you're going to do here is likely end up overwriting most if not all of your data at some point.

ADD REPLYlink written 12 months ago by Joe18k
gravatar for h.mon
12 months ago by
h.mon31k wrote:

Simplest solution: use a for loop.

for i in *.unaligned.fasta
    mafft --quiet $i > ${i%.unaligned.fasta}.aligned.fasta

Be a bit fancier with GNU Parallel:

parallel -j 4 'mafft --quiet {} > {.}.aligned.fasta' ::: *.unaligned.fasta

This will run 4 simultaneous mafft alignments - be sure to have the cores and memory for the parallel tasks, though.

ADD COMMENTlink written 12 months ago by h.mon31k

If you are using (t)csh instead of bash:

foreach i ( *.unaligned.fasta )
mafft --quiet $i > $i:r:r.aligned.fasta
ADD REPLYlink modified 12 months ago • written 12 months ago by Mensur Dlakic7.3k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1550 users visited in the last hour