This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Editing header of a fasta file

Hello everybody, I've been using sed but for simple steps and now I can't do this: I have this header:

>ENSP00000451042.1 pep chromosome:GRCh38:14:22438547:22438554:1 gene:ENSG00000223997.1 transcript:ENST00000415118.1 gene_biotype:TR_D_gene transcript_biotype:TR_D_gene gene_symbol:TRDD1 description:T cell receptor delta diversity 1 [Source:HGNC Symbol;Acc:HGNC:12254]

and I would like to obtein this:

>gene_symbol:TRDD1

Does anybody can help me?

headers fasta

1 answer

try (assuming that gene_symbol is always followed by description:

$ sed -re '/^>/ s/.*(gene_symbol:.*)\sdes.*$/>\1/'  input.fa
$ seqkit replace -ip '.*(gene_symbol:.*)\sdesc.*' -r \${1} input.fa
$ awk '/^>/ {print ">"$8};!/>/{print}' input.fa
$ awk  '{print ($0 ~ /^>/) ? ">"$8 :$0 }' input.fa

Log in to answer this question.