How to append numbers only on duplicates sequence names? I have a reference database with contains 100s of sequences in fasta format. Some of these sequences have duplicate names like so:

&gt;1_uniqueGeneName
atgc
&gt;1_anotherUniqueGeneName
atgc
&gt;1_duplicateName
atgc
&gt;1_duplicateName
atgc


Is is possible to run through a large file like this and change the names of only the duplicates?

&gt;1_uniqueGeneName
atgc
&gt;1_anotherUniqueGeneName
atgc
&gt;1_duplicateName_1
atgc
&gt;1_duplicateName_2
atgc
And here’s a solution using R (with the Bioconductor):

fa = ShortRead::readFasta(infile)
ids = as.character(ShortRead::id(fa))
fa@id = Biostrings::BStringSet(make.unique(ids, sep = '_'))
ShortRead::writeFasta(fa, outfile)