0

I need to run a program using 2 files as input expecting 1 output having 6000 files ranging from abc0000.faa/abc0000.fna to abc6000.faa/abc6000.fna. I also need the output file to have the same file name as the inputs but .paml extension.

This is an example of the full command just for files 0000.

./pal2nal.pl abc0000.faa abc0000.fna -codontable 11 -output paml > abc0000.paml

Is there a way of running the same command for all files automatically? Something like a for-in-do?

Thanks!

2

You can loop over one of the sets of input files (the .faa files for example) and generate the other input file and output file names from those:

for f in *.faa; do
    ./pal2nal.pl "$f" "${f%.faa}.fna" -codontable 11 -output paml > "${f%.faa}.paml"
done

The ${f%word} syntax removes the shortest trailing component matching word.

2

The command

seq -w 0 6000

will generate all the numbers from 0 to 6000; if a number has fewer than four digits it will be padded with 0s on the left. You can use command substitution to wrap your command in a for-loop:

for n in $(seq -w 0 6000) ;do
  ./pal2nal.pl abc$n.faa abc$n.fna -codontable 11 -output paml > abc$n.paml
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.