Thanks a lot! It solved my problem.
• 0 views
•
link
Hello, I have a list of sequences in a fasta file which looks like this:
>WP00001_00001 HP Protein 1
ATGCATGATCAGTTGACGT
>WP00002_00022 Protein Like/Protein1
ATGACTGACGTTGACGTAC
>WP00002_00007 Protein cluster2
ATGGCTAGCCATGTACATT
I want to replace the first white space with a pipe (|) and then replace all other white space in the header (description) with an underscore (_). So that the final output file should look like this:
>WP00001_00001|HP_Protein_1
ATGCATGATCAGTTGACGT
>WP00002_00022|Protein_Like/Protein1
ATGACTGACGTTGACGTAC
>WP00002_00007|Protein_cluster2
ATGGCTAGCCATGTACATT
Could you please help me with that?
Regards, PSP
Perl-one-liner:
$ perl -pe 'if(/>/) { s/\s/|/; s/\s/_/g; s/_$/\n/ }' < in.fasta
>WP00001_00001|HP_Protein_1
ATGCATGATCAGTTGACGT
>WP00002_00022|Protein_Like/Protein1
ATGACTGACGTTGACGTAC
>WP00002_00007|Protein_cluster2
ATGGCTAGCCATGTACATT
Thanks a lot! It solved my problem.
Log in to answer this question.
What have you tried? The forum has a number of "edit FASTA/Q header" posts.