This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How do I remove certain sequences in fasta based on header?

I have a fasta file like this:

>XM_0000001.1 
actact
>XR_0000001.1
atcatc

How do I remove all the sequences with a XR header?

I only want to keep:

>XM_0000001.1
actact
fasta sequence rna-seq

3 answers

If you do it on linux,it will be easy.

  1. Step 1: grep “>” file.fa | sed 's/>//g' > file.fa.id
  2. Step 2: grep -v 'XR_' file.fa.id > file.fa.id.final
  3. step 3: seqtk subseq file.fa file.fa.id.final > final.fa

PS: Seqtk is a software that you need to install.

edit:formatting.

try with gnu-sed on ubuntu/mint:

$ sed  -e '/^>XR/,+1d' test.fa

If you have multiline fasta, use seqkit:

$ seqkit grep -rvip "^XR" test.fa

You can try SEDA (https://www.sing-group.org/seda/). The Pattern filtering operation (https://www.sing-group.org/seda/manual/operations.html#pattern-filtering) would allow you to do this if you configure a Not contains pattern with the "^XR_" text.

Log in to answer this question.