This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Fasta file name change: Change contig to annotated name

Hello All,

I have two files a fasta file with:

>Contig1
atgcatgcatgcaatgcagcga
>Contig2
atagtagtattagcatcgatcgt
>Contig3
atgcagcagcgacg

AND

a text or .csv file with:

Contig1-metalloprotease
Contig2-serpin
Contig3-cystatin

Does anyone know how to match and replace:

>Contig1 with >Contig1-metalloprotease?

Any help would be much appreciated. Thanks in advance!

assembly fasta

1 answer

I would just have a table:

Contig1 <tab> Contig1-metallo...

same for all contigs, tab delimited.

Then:

awk 'NR==FNR{array[">"$1]=(">" $1 "-" $2);next} {if($1 in array){$1=array[$1]}}1' Table.file original.fasta > annotated.fasta

Log in to answer this question.