# how to remove range from fasta header

Could you please suggest me how I can remove range from fasta header:like these number from below sequences which has some colons indicating the range of the genome

:147010-147657

:149201-149845

> FVJT01000004.1:147010-147657 Mycobacterium abscessus subsp. massiliense strain 974
GTGACCAGCAGCGCAGACCGATCCCCCGTCGAGGCGATGGTGAGCCACGCCGAGGGCGCCATCTCCGAGG
ATGACATCGTCGCCGCCGCCCGGGAACGTGCCGTTGACCTGGGCGCGGGCCCGGTGACACCCGCGGTAGG

>FSAX01000002.1:149201-149845 Mycobacterium abscessus subsp. bolletii strain 286 genome
ATGACGACGCCCGTCAGCTTCGATAACAGATTCTTCTCCGCAACGTGGTCTGCTATCGCGCGGCGCGAAC
CTCAGGAGATCAAGGAGCTGCGTGCGGAGAATCTACGCGGCCTGACCGGCCACGTTCTGGAGGTGGGAGC


Invest some time in learning unix tools such as grep, sed and awk.

sed -r '/^>/s/:[0-9]+-[0-9]+//' input.fasta > output.fasta


This line of code matches the pattern :<numbers>-<numbers> on lines that start with > (FASTA sequence headers) and replaces that pattern with '', essentially removing text that matches the pattern.

• Thanks Ram, could you please suggest any book related to unix command line that can explain all these small problems related to bioinformatics. Jul 3, 2019 at 22:26
• I'd recommend looking at Rosalind, but I think that's mostly python. Unix utilities are learnt as you stumble upon problems, as there's seldom some sort of comprehensive exercise to learn these utilities. Try googling "learn sed" or "learn grep" or "learn awk" and following tutorials that pop up. For awk, you can start with an Excel sheet of data, export the data to a tab-separated text file and use awk to do things you'd normally use Excel filters to do. Jul 3, 2019 at 23:01

Alternatively, Perl provides a slightly simpler regular expression syntax (\d instead of [0-9]) that I prefer over sed.

perl -pe 's/:\d+-\d+//' input.fasta > output.fasta

• Using -pe is even simpler: perl -pe 's/^(>\S+):\d+-\d+/\$1/' input.fasta > output.fasta Jul 9, 2019 at 23:20