This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Rename and move Spades assemblies in batch

Hi.

I have a folder called "spades" with many subdirectories generated by Spades (each with the name of the sequenced strain). I would like to rename the "contigs.fasta" file with the name of the folder (for ex. DI21.fasta that is in the "DI21" folder) and move the renamed fasta file to a different directory where I want to collect all the fasta files of the different strains. How can i do it in batch? I am working in bash on a mac.

Thank you.

Laura

batch bash spades

1 answer

I guess you can use a bash script to do that. Something like:

for f in */contigs.fasta; do cp $f /destination/dir/${f%/contigs.fasta}.fasta; done

The % removes the following text from the variable so the contigs.fasta will be changed to the folder name.

(I didn't test it but it should work)

This worked perfectly, thank you very much Asaf!! :)

Log in to answer this question.