This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Concatenating 1000s of pairs of fasta files

Hi,

I have one folder with 25000 fasta files named Rnor.01.fa, Rnor.02.fa, ... and another folder with 25000 fasta files named Rrat.01.fa, Rrat.02.fa, ....

I want to concatenate Rnor.01.fa and Rrat.01.fa into a file Rnor_Rrat.01.fa and likewise Rnor.02.fa with Rrat.02.fa to ultimately have 25000 files each containing fasta sequences from each species.

I am new to programing and can't seem to figure out how to use cat to be able to do so.

Any help would be appreciated. Thank you

fasta unix

1 answer

Assuming that naming convention holds for all of your files:

mkdir tmp
ls -1 | cut -f 2 -d . | sort | uniq | while read i;do cat $(ls -1 *.$i.fa)  > $(ls -1 *.$i.fa | cut -f 1 -d . | perl -pe 's/\n/_/g').$i.fa; mv $(ls -1 *.$i.fa | grep -v _) tmp;done

Untested, and typed on my phone, so check with some echo statements before running it for real. (should preserve your original files in the tmp folder)

Glad to hear it. If you find an answer helpful, remember to mark it as accepted to help the next people to find the thread.

Log in to answer this question.