This is a test version of Biostars. For the public version, visit https://www.biostars.org.
change headers from fasta files

Hello, I'm trying to trim the next fasta headers

  >ID:CHARACTERS | [Genus specie] | strain | gene_name | length | NCBI_ID | other | other | other|
>ID:CHARACTERS | [Genus specie | strain | gene_name | length | NCBI_ID | other | other | other|

And I 'd like to trim them like the following example

>ID:CHARACTERS | [Genus specie] | strain | gene_name |

the ID:CHARATERS, [Genus specie], strain and gene_name are variables accross the headers, but always are separated by "space|space"

sequence

I'm trying to trim the next fasta headers

And can you elaborate on what you tried and how that didn't deliver the result you had in mind?

Your fasta headers are identical, this will create problems for most downstream tools. You can do what you want with sed:

sed "s/ length | NCBI_ID | other | other | other|//" file.fasta

2 answers

This works if you aren't bothered about keeping the last pipe symbol...

cat myseqs.fa | cut -d '|' -f -4
>ID:CHARACTERS | [Genus specie] | strain | gene_name
TCCACGATCGAATAAATGTGCGATTAGCACCTGTAGAACCATACAAGCTAAGCCGCCTCACGGGCATGTTAACGAGATTA
>ID:CHARACTERS | [Genus specie | strain | gene_name
TATTAATTTTAGTAAAACATAGCGTCGGAGACGGGCCGACACCAACGATCCGTTACCCCACATGCACCGGAGTAAGCGAC

I'll let you exert some effort to keep the last delimiter if you want it ...

I'll add that you really should use the search function as this type of question is Biostar's 'public enemy number one'.

You're lucky it's easy and I'm sat in front of a terminal though ;)

$ cat test.fa 
>ID:CHARACTERS | [Genus specie | strain | gene_name | length | NCBI_ID | other | other | other|
atgc

$ sed '/^>/ s/|\s\w\+\s*//3g' test.fa 
>ID:CHARACTERS | [Genus specie | strain | gene_name |
atgc

Log in to answer this question.