Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Edit FASTA header of the sequences

I have some fasta sequences as shown below.

>contig_0,length=363,cov=3.6,min=5,max=7,gc=0.413,left=F_BRANCH_1.0,right=F_BRANCH_1.0 rightEdges=(95156-1-1-2-A)
CTTCATTTTTCCCTAGTCCCTTTCCTGGTATATATCCCATCTTGGTCATGATTTTTTGACTCGTGGGGCT
A
>contig_1,length=359,cov=4.8,min=2,max=8,gc=0.482,left=DEAD_END,right=DEAD_END
CATGGTCTCAATTTTCAACCAACCATGAGACAAAGAAGCTCACGGGAAGCCATCATTCACCCAGCACAAC
ACCTACGAGTAGGAAATCGGCAATGGGCTTCGATATGTGACACCCAGGCAGACGTGCCCTCAACCTAATG
>contig_2,length=363,cov=3.6,min=5,max=7,gc=0.413,left=F_BRANCH_1.0,right=F_BRANCH_1.0 rightEdges=(95156-1-1-2-A)
TACTTTGATACACTTCTGAGGCTGTGCCTATGCCGACAAGTCCTGTAACAGCCTTTTGTTTAGGCCAATT
TTTTGGCCACTGATTTAAAGCAATCCAATTTTTTGGCCACTGATTTAAAGCAATGATAGAGACATCTGCT
CCAGTGTCTACCA

I would like to edit the header of the fasta sequence in the following way. Your suggestions would be appreciated.

>contig_0
CTTCATTTTTCCCTAGTCCCTTTCCTGGTATATATCCCATCTTGGTCATGATTTTTTGACTCGTGGGGCT
A
>contig_1
CATGGTCTCAATTTTCAACCAACCATGAGACAAAGAAGCTCACGGGAAGCCATCATTCACCCAGCACAAC
ACCTACGAGTAGGAAATCGGCAATGGGCTTCGATATGTGACACCCAGGCAGACGTGCCCTCAACCTAATG
>contig_2
TACTTTGATACACTTCTGAGGCTGTGCCTATGCCGACAAGTCCTGTAACAGCCTTTTGTTTAGGCCAATT
TTTTGGCCACTGATTTAAAGCAATCCAATTTTTTGGCCACTGATTTAAAGCAATGATAGAGACATCTGCT
CCAGTGTCTACCA

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Identify the lines starting with the > pattern, and the split the header fields on the , separator and then re-populate the whole line with the fist field alone.

awk '/^>/{split($0,arr,","); $0 = arr[1]}1' file.fasta

Or simply substitute the contents from the first , to the end of the line

awk '/^>/{sub(/,.*/, "")}1' file.fasta
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading