This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Rename fasta headers with file name + original header

Hi.

I wanted to rename some 200 fasta files' headers with the file name plus their original headers with seperation in between.

For example, if the file name of a fasta file is DP16D_E2, and the headers are >NODE_1_length_281463_cov_31.3018 >NODE_2_length_281037_cov_32.253 >NODE_3_length_274463_cov_32.7402

The resulting header names will be >DP16D_E2_NODE_1_length_281463_cov_31.3018 >DP16D_E2_NODE_2_length_281037_cov_32.253 >DP16D_E2_NODE_3_length_274463_cov_32.7402

Is there any code that could help achieve this objective?

Thanks so much.

H.

python fasta

1 answer

Hi Metaxo,

Try:

for fa in *.fasta; do
  fn=$(basename ${fa} .fasta)
  sed "s/^>/>${fn}_/" ${fa} > reID_${fa}
done

It worked! Thanks !

Log in to answer this question.