This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to run pal2nal on many files?

I am trying to automate pal2nal but I am struggling to understand.

I have many nucleotide and protein alignment files with the same names and different extensions. For example:

file1.fa file1.msa

I can run pal2nal by:

pal2nal.pl file1.msa file1.fa -output paml > file1.cds

I need to create a for loop to do this to hundreds of files. How do I do this when the extension changes for the 2 input files and for the output file?

script forloop pal2nal perl commandline

1 answer

If your files are named just the way you show them then something like following will work

for i in `ls -1 *.fa`; do name=$(basename ${i} .fa); echo ${name}; pal2nal.pl ${name}.msa ${name}.fa -output paml > ${name}.cds; done

Log in to answer this question.