How do I re-name the headers of my Fasta file? I appologize for asking this, but I really am really bad with regex...

Can someone help me transform the headers of my fasta files from this:

&gt;Agaricus_chiangmaiensis|JF514531|SH174817.07FU|reps|k__Fungi;p__Basidiomycota;c__Agaricomycetes;o__Agaricales;f__Agaricaceae;g__Agaricus;s__Agaricus_chiangmaiensis


to this:

&gt;JF514531|SH174817.07FU;tax=d:Fungi,p:Basidiomycota,c:Agaricomycetes,o:Agaricales,f:Agaricaceae,g:Agaricus,s:Agaricus_chiangmaiensis_SH174817.07FU;


seems like I could use the command 

sed 's/__/:/g;s/;/,/g;s/.*|/|/g' 


to substitute : for __, and , for ;.  I'm not entirely sure how to proceed from there though...

Thank you
If awk is good as well:

$ awk -v FS="|" -v OFS="|" '/&gt;/{
    gsub(";",",", $5); 
    gsub("__",":",$5); 
    print "&gt;"$2,$3";tax="$5"_"$3";";
    next;
}1' file.fa
&gt;JF514531|SH174817.07FU;tax=k:Fungi,p:Basidiomycota,c:Agaricomycetes,o:Agaricales,f:Agaricaceae,g:Agaricus,s:Agaricus_chiangmaiensis_SH174817.07FU;


This relies on the order of the parts separated by |.

I don't understand why k__Fungi becomes d:Fungi, so I ignored it for now. 

Some explanation for what awkis doing.


| is defined as a field (column) separator for the input and output
If the line contains a &gt; the code between { and } is executed.
the first gsub replaces ; with , in the 5th field
the second gsub replaces __ with : in the 5th field
then we print the new header line. The $2, $3 and $5 get replaced by the values of the second, third and 5th field of the input. , get replaced by the defined output field separator
with next we tell awk to go to the next input line and repeat the code
The 1 is in equivalent to print $0 for printing the whole input line. In our code this is only executed if the line is no header line.