Thank you! This works well on Linux (couldn't make it run on OSX before and therefore hoped to find a raw/executable script here).
Hi all, I am looking for a way that allows me to filter out (remove) some sequences from a fasta file (with aligned protein sequences) based on a list of headers given as separate input file. I am aware that there are similar questions here but in most cases, the given answers show how to get and not how to remove the sequences. I also tried the suggested software (e.g., BBMap) but this was either destroying my alignment or/and replacing “-“ by “N”, which is particularly bad for protein alignments. Any idea how to do this? A bash, python, or perl script would be great. Many thanks in advance!
### fasta file ###
>Species_X
PFEAIQIINLPHRYGANTFKLHRLPVPRPGQVLGLVGTNGIGKSTALKILAGKLKPNLGR
FTSPPDWQEILTHFRGSELQNYFTRILEDNLKAIIKPQYVDHIPLSGGELQRFAIAVVAI
QNAEIYMFDEPSSYLDVKQRLKAAQVVRSYVIVVEHDLSVLDYLSDFICCLYGKPGAYGV
VTLPFSVREGINIFLAGFVPTENLRFRDESLTFKGEFTDSQIIVMLGENGTGKTTFIRML
AGLLNVSYKPQKISPKFQNSVRHLLHQKIRDSYMHPQFMSDVMKPLQIEQLMDQEVVNLS
GGELQRVALTLCLGKPADIYLIDEPSAYLDSEQRIVASKVIKRFILHAKKTAFVVEHDFI
MATYLADRVIVYEGQPSIDCTANCPQSLLSGMNLFLSHLNITFRRDPTNFRPRINKLEST
KDREQKSAGSYY
>Species_Y
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
--------------------------------------------MLGENGTGKTTFIRML
AG--NVSYKPQ--------TVRQLLHDKIRDAYTHPQFVSDVIRPLQIEQLLDQVVKTLS
GGEKQRVAITLCLGKPADIYLIDEPSAHLDSEQRITASKVIKRFILHAKKTAFIVEHDFI
MATYLADRVIVYEGQPAVKCIAHSPQSLLSGMNLFLSHLNITFRRDPTNFRPRINKLESI
KDKEQKTAGSYY
>Species_Z
PFGAIHIINLPHRYSANSFKLHRLPMPRPGQVLGLVGTNGIGKSTALKILSGKLKPNLGR
FDNPPDWEEILKYFRGSELQNYFTKVLEDDLKAVVKPQYVDQIPLSGGELQRFAIGLVCV
QKADVYMFDEPSSYLDVKQRLAAARSIREYVIVVEHDLSVLDYLSDFVCVLYGRPALYGV
VTLPASVREGINIFLDGHIPTENLRFREESLTFRGSFTDSEIIVMMGENGTGKTTFCKML
AGAENISMKPQKITPKFQGTVRQLFFKRIKAAFLSPQFQTDVYKPLKIDDFIDQEVQNLS
GGELQRVAIVLALGIPADIYLIDEPSAYLDSEQRIVASRVIKRFIMHTKKTAFIVEHDFI
MATYLADRVIVFDGQPSVDAHANAPESLVTGCNTFLKNLDVTFRRDPNSYRPRINKYQSQ
MDQEQKLAGNY-
### to_remove.txt ###
Species_X
Species_Z
### desired output ###
>Species_Y
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
--------------------------------------------MLGENGTGKTTFIRML
AG--NVSYKPQ--------TVRQLLHDKIRDAYTHPQFVSDVIRPLQIEQLLDQVVKTLS
GGEKQRVAITLCLGKPADIYLIDEPSAHLDSEQRITASKVIKRFILHAKKTAFIVEHDFI
MATYLADRVIVYEGQPAVKCIAHSPQSLLSGMNLFLSHLNITFRRDPTNFRPRINKLESI
KDKEQKTAGSYY
1 answer
Get faSomeRecords utility from Jim Kent. Add execute permissions if needed (chmod u+x faSomeRecords).
Run it like this: ./faSomeRecords -exclude your_original.fa id_to_exclude final.fa
List id's to exclude in id_to_exclude file, one on each line.
Here is a link to macOS version of the same program in case someone finds this thread in future. Rest of the instructions are the same.
Log in to answer this question.
Did you search yourself already for a solution on this site? This is asked a zillion times already and answered as well.
Hello jan!
Please search Biostars (use Google) for prior solutions for this common request.
For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.
If you disagree please tell us why in a reply below, we'll be happy to talk about it.
Cheers!
I found a similar question asked by the users Ginsea Chen and Seta. If you check the answers, however, you will see that it has been shown how to remove sequences based on provided short sequences that are matching or to remove sequences with a given pattern in the IDs/header. There are also answers suggestion a particular software that didn't work in my case (i.e., the alignment wasn't preserved). I think a raw python, perl, or bash script filtering out the sequences in question by keeping the alignment would be appreciated by many users.