This is a test version of Biostars. For the public version, visit https://www.biostars.org.
how to change scaffold number

I used seqkit to replace my multifasta files as below

"seqkit replace -p .+ -r "scaffold_{nr}" input.fa -o rename.fa"

This is giving me output file like this below

>scaffold_1 
ATCGTCGATACGCGA 
>scaffold_2 
GCGTACGATAC 
>scaffolt_3
ACTATCTACTTCA 

etc...

how can I change the scaffold numbering 1 to 0001

seqkit fasta

3 answers

You can also do:

seqkit replace -p .+ -r "scaffold_{nr}" --nr-width 4 input.fa -o rename.fa

pipe into:

awk -F '_' '/^>/ {printf("%s_%04d\n",$1,$2);next;} {print}'

biostars want some text

If you would like to use sed, you can do sth like this-

cat output.txt
>scaffold_1 
ATCGTCGATACGCGA 
>scaffold_2 
GCGTACGATAC
>scaffolt_3
ACTATCTACTTCA

cat output.txt | sed 's/>*_\([0-9]\)/_000\1/' 
>scaffold_0001
ATCGTCGATACGCGA 
>scaffold_0002 
GCGTACGATAC
>scaffolt_0003
ACTATCTACTTCA 

it just adds '000' I don't think this is what SO wants (he wants '0100' not '000100' )

Log in to answer this question.