This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Batch rename contigs in multiple assembly files

Hi,

Having hundreds of assemblies with between 50-100 contigs. All contigs are named Contig_1, Contig_2 etc ... But the assemblies themselves have an ID I want on the contigs as well for the downstream analysis. So the ID of the file should be included before the contig. I.e:

<fileid>_Contig_1 instead of only Contig_1

Please help!

assembly

1 answer

you could run sed 's/>/fileid>/g' on your files, providing the fileid you want to use.

Integrate this in a bash loop if you want to run it on a whole list of files.

awk '/>/{sub(">","&"FILENAME"_");sub(/\.fasta/,x)}1' sample_1.fasta

That worked great, how do I now put it in a loop for all .fasta in my directory?

(Definitely signing up for an intro to bash scripting) :D

for i in *.fasta ; do
  <your awk command >
done

Log in to answer this question.