This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Renaming Entry In Fasta File

I want to change my entries in my fasta file, but I want to keep certain numbers. I work with Linux

For example

Current names:

>NODE_1_length_140009_cov_0.223002

>NODE_2_length_119367_cov_0.245541

>NODE_3_length_108076_cov_0.169347

And I want them to change to:

>lclav_contig 1 lengte 140009 cov 0.223002

>lclav_contig 2 lengte 119367 cov 0.245541

>lclav_contig 3 lengte 108076 cov 0.169347

I know i have to work with awk but I'm stuck at the moment. Thank you for the help in advance!

fasta linux

You can use sed to make two changes. Replace _ with space and then NODE with lclav_contig. I assume lengte is an error but if not that will be the third replacement.

Thank you!

lengte is length in my native langue so no error ;)

2 answers

sed 's/NODE/lclav_contig/' {INPUT FILE} | sed 's/_/ /g' | sed 's/ /_/1' > {OUTPUT FILE}

*Apologies, should have replied inline.

You can accept this answer (green checkmark) to provide closure to this thread.

echo '>NODE_1_length_140009_cov_0.223002' | sed -re 's/>[A-Z]+_([0-9])_[a-z]+_([0-9]+)_([a-z]+)_(.*)/>lclav_contig \1 lengte \2 \3 \4/g'

>lclav_contig 1 lengte 140009 cov 0.223002

Most of the tools stop handling characters after first space. New headers (new format) may create a problem, in future.

Log in to answer this question.