trim fasta header, remove after hash (#)
this is my fasta file
>BEL-3_Dvir#LINE/BelPao
GTAATTCTTGTGGTAGTTTTATGTTCTATGCAGGTTCAATATCGTACGCGCTCTGTGATG
CCCGCGCAGTACGCGTTTGTTTCCGATAGTTGATAACAAGTAATCGGTACAAATCGATAT
>P-2_Dmel#LINE/P
AATCTCTATATATAAAACTGTTTGTCCTGACTGACTGACTGACTGACTGACTGACTGACT
GACTGATTGGTGATCAACGCACAGCCCAAACCGTAAGAGCTAGGAAGCTGAAATTTTCAC
TGTAGCTACCTTATGTGATGTAGGTGCACGTTAAGACGGGGTTTCGGGAAATTCCACCCG
I want to remove the header after the hash:
>BEL-3_Dvi
GTAATTCTTGTGGTAGTTTTATGTTCTATGCAGGTTCAATATCGTACGCGCTCTGTGATG
CCCGCGCAGTACGCGTTTGTTTCCGATAGTTGATAACAAGTAATCGGTACAAATCGATAT
>P-2_Dme
AATCTCTATATATAAAACTGTTTGTCCTGACTGACTGACTGACTGACTGACTGACTGACT
GACTGATTGGTGATCAACGCACAGCCCAAACCGTAAGAGCTAGGAAGCTGAAATTTTCAC
TGTAGCTACCTTATGTGATGTAGGTGCACGTTAAGACGGGGTTTCGGGAAATTCCACCCG
I tried this code
sed -r -i 's/^>/.*#/\1/' file.fasta
the error is
-e expression #1, char 10: unknown option to `s'
how to fix this?
• 1,247 views
•
link
1 answer
$ awk '/^>/ {sub(/#.*$/,"",$0)}1' test.fa
$ awk -F "#" '{print $1}' test.fa
$ sed -r '/^>/ s/#.*//' test.fa
$ cut -d '#' -f 1 test.fa
Code you pasted has several issues. Never use -i if you are not sure of code.
• 0 views
•
link
Log in to answer this question.
also, be extremely careful when using the
-ioption ( the in-file modification parameter) , if something goes awol you lost your input file. Always work on a copy of the original file or send the sed output to a new file.