2
$\begingroup$

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
$\endgroup$
6
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Thanks Ram, could you please suggest any book related to unix command line that can explain all these small problems related to bioinformatics. $\endgroup$ – Dr.Yogesh Jul 3 at 22:26
  • $\begingroup$ 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. $\endgroup$ – Ram RS Jul 3 at 23:01
1
$\begingroup$

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
$\endgroup$
  • 2
    $\begingroup$ Using -pe is even simpler: perl -pe 's/^(>\S+):\d+-\d+/$1/' input.fasta > output.fasta $\endgroup$ – user172818 Jul 9 at 23:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.