This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Rename fasta-header based on a list

Hey everyone,

I have a multi-fasta file like this

>NZ_CP023010.1_3129429..3372047
atattgagctaa..
>NZ_MRWY01000004.1_16177..110237
tcagtcgactcct...
...

And a list of fasta-headers like this

>NZ_CP023010_Elizabethkingia anophelis FDAARGOS_198
>NZ_MRWY01000004_Klebsiella michiganensis_CAV1755
...

I would like to create a script, so that I could rename my multi-fasta file like this

>NZ_CP023010_Elizabethkingia anophelis FDAARGOS_198_3129429..3372047
atattgagctaa..
>NZ_MRWY01000004_Klebsiella michiganensis_CAV1755_16177..110237
tcagtcgactcct...
...

Could you help me out? Thanks!

genome sequence

Hello genomes_and_MGEs!

You have already asked this question a couple of times before this with minor variations. Please don't open new threads with similar questions. We are here to help but we like to see some effort on your part to solve questions. If you get stuck show what you have tried and someone will step in to help.

Outputting strain name on prokka annotation
Add strain name directly on fasta header

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

Hey, sorry for insisting on this, but I still haven't solved this problem... So, I'm trying to optimize the seqkit replace command to replace the fasta-headers. Can you help me out?

Just for given sample data.

$ sed 's/^>//' headers.txt  | perl -pne 's/(\w+_\w+)_/$1\t/' >  headers.tsv

$ cat headers.tsv 
NZ_CP023010     Elizabethkingia anophelis FDAARGOS_198
NZ_MRWY01000004 Klebsiella michiganensis_CAV1755

$ seqkit replace -p '^(.+?)\..+_' -k headers.tsv -r '{kv}_' seqs.fa 
>Elizabethkingia anophelis FDAARGOS_198_3129429..3372047
atattgagctaa..
>Klebsiella michiganensis_CAV1755_16177..110237
tcagtcgactcct...

This looks great, but I also need the accession number on the fasta header, such as

>Elizabethkingia anophelis_FDAARGOS_198_NZ_CP023010_3129429..3372047
atattgagctaa..
>Klebsiella michiganensis_CAV1755_NZ_MRWY01000004_16177..110237
tcagtcgactcct...

Can you help me optimize this?

depending on what the purpose of this fasta header reformatting is , I advise you to think it through before doing. The examples you give here are bound to give you troubles when processing this fasta file.

Keep in mind that for fasta format the first part of the header (== up to the first space) is the unique(!!) identifier, which in your current example will (I assume there might be others sequences from the same genus) likely not be unique enough. The given example will for instance certainly mess up any blastDB formatting of that fasta file.

0 answers

No answers yet.

Log in to answer this question.