This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Changing Fasta Header

Dear Colleagues,

I would like to change my FASTA file header from this :

oreNil2_augustusGene_g25.t1 range=chrLG1:1047971-1161345 5'pad=0 3'pad=0 strand=+ repeatMasking=none

to this :

oreNil2_augustusGene_g25.t1

Basically removing all the lines after the space.

I know we can do this with sed or awk but my knowledge with this two commands are elementary at best. Any help here will be awesome!

regards,

Zi Yi

fasta header awk sed

This perl script may help to solve your porblem:

open F,"<genome.fa";
open OUT,">new_genome.fa";
while(<F>){
     print OUT $_ unless ($_=~/^>/);
     print OUT "$1\n" if ($_=~/^(>.*)\s+range.*/);
}
close(F);close(OUT);

This was answered too many times on this forum. Here is one solution

sed '/>/ s/\s.*$//' foo.fa > out.fa

Hello wanziyi89!

We believe that this post does not fit the main topic of this site.

Please read the multitude of identical posts here.

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!

2 answers

You can use the BBMap package for this:

reformat.sh in=sequences.fasta out=renamed.fasta trd

"trd" stands for "trim read description" and will truncate everything after the first whitespace.

sed '/>/ s/\s.*$//' input.fasta > u.fasta

Log in to answer this question.