How to add file name after > in a multi-fasta file?
3
0
Entering edit mode
18 months ago

Hi, I have a multi-fastafile called HTH_7.fasta.

>W1DFQ1_KLEPN/141-185
 GRKKSLSSERIAELRQRVEAGEQKTKLAREFGISRETLYQYLRTD
>HIN_SALAE/139-183
GHPRAINRHEQEQISRLLEKGHPRQQLAIIFGIGVSTLYRYFPAS
>GIN_BPMU/138-182
GRPPKLTKAEWEQAGRLLAQGIPRKQVALIYDVALSTLYKKHPAK
>CIN_BPP1/138-182
GRRPKYQEETWQQMRRLLEKGIPRKQVAIIYDVAVSTLYKKFPAS
>UVP1_ECOLX/144-189
GRKPSLSEDDINEMKILLADPEMTVGAVAKRFNVSRMTIYRYTTKG

I want to paste the file name HTH_7 after each of the "> header"

>W1DFQ1_KLEPN/141-185_HTH_7
 GRKKSLSSERIAELRQRVEAGEQKTKLAREFGISRETLYQYLRTD
>HIN_SALAE/139-183_HTH_7
GHPRAINRHEQEQISRLLEKGHPRQQLAIIFGIGVSTLYRYFPAS

I tried as following but it is not served my purpose. because i=the file name also pasted after the fasta sequence. How to remove that?

awk '{print $0 "_"FILENAME}' HTH_7.fasta | sed "s/.fasta//" | head
>W1DFQ1_KLEPN/141-185_HTH_7
GRKKSLSSERIAELRQRVEAGEQKTKLAREFGISRETLYQYLRTD_HTH_7
>HIN_SALAE/139-183_HTH_7
GHPRAINRHEQEQISRLLEKGHPRQQLAIIFGIGVSTLYRYFPAS_HTH_7
>GIN_BPMU/138-182_HTH_7
 GRPPKLTKAEWEQAGRLLAQGIPRKQVALIYDVALSTLYKKHPAK_HTH_7
>CIN_BPP1/138-182_HTH_7
GRRPKYQEETWQQMRRLLEKGIPRKQVAIIYDVAVSTLYKKFPAS_HTH_7
>UVP1_ECOLX/144-189_HTH_7
GRKPSLSEDDINEMKILLADPEMTVGAVAKRFNVSRMTIYRYTTKG_HTH_7

Thanks in advance

sequence fasta rename header • 941 views
ADD COMMENT
0
Entering edit mode

try:

$ sed '/^>/ s/$/_HTH_7$/g' input.fa
ADD REPLY
1
Entering edit mode
18 months ago

awk '/>/{sub(">","&"FILENAME"_");sub(/\.fasta/,x)}1' sample_1.fasta

ADD COMMENT
0
Entering edit mode
18 months ago

using seqkit

seqkit replace -p '(.+)' -r '${1}_HTH_7' sample_1.fasta

ADD COMMENT
0
Entering edit mode
18 months ago
Hugo ▴ 340

You can use SEDA, an open source application for processing FASTA files containing DNA and protein sequences. The Rename header operation has an Add prefix/suffix mode (https://www.sing-group.org/seda/manual/operations.html#add-prefix-suffix) that allows you to add the text you want at the beginning of the headers.

ADD COMMENT

Login before adding your answer.

Traffic: 1611 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6