This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to remove gap-containing sequences from a fasta file?

I trimmed poor aligned regions from a MSA file, using trimAl. Now, I would like to remove all gap-containing sequences, and keep only those sequences with no gaps. It would be something like this:

input:

>seq_1
LSAIFQQPLAALLSN--------QQ-----------------------------------

>seq_2
-----------------------------GPLLTGALVTEDVAASALRIMIVALKVIIDA
ASVSELCATLLVELSVAGIVNVMNCAL 

>seq_3
IKVLSEQALGQHLTQIQNCLWTLNLSAATGQILVTQLGDDNMATGILSNLVTQVEALIHV
LDVEPAVCALLTPVGLALLREALINAL

Output:

>seq_3
IKVLSEQALGQHLTQIQNCLWTLNLSAATGQILVTQLGDDNMATGILSNLVTQVEALIHV
LDVEPAVCALLTPVGLALLREALINAL

Does anyone know how to do it? I will appreciate any help. Thanks!

alignment

Are the sequence name and sequence all contained within one line in the file? Or are there line breaks like in your post?

EDIT: It appears to be a fasta file after the post was edited, and if so the answer was kindly provided by @genomax.

1 answer

Linearize the fasta file | remove lines containing gaps `grep -v "-"` | reformat back to fasta.

Code for fasta manipulation (courtesy of @yokofakun):

You can accept the answer to provide closure to this thread (green check mark).

Log in to answer this question.