I have several protein sequences with an asterisk in the middle of the sequence, and I'd like to remove those sequences.
In the example below, I have three sequences:
From this example, I would like to obtain only the following output:
Try seqkit grep
seqkit grep --by-seq --invert-match --pattern '*' seq.fa
--by-seq
search by seq
It will output sequences without an asterisk.
It’s good you brought up the question.
*
are stop codonsDon't simply parse out the *
symbol. If done incorrectly, it could constitute 'tampering' and that’s a red line in biology.
The *
means a stop codon in the middle of a protein sequence. There are quite a number of reasons why there is an *
, i.e., a stop codon in the sequence, for example, in no particular order:
The list goes on, e.g., it could be expression regulation ...
If it is not an intron/UTR the way you might 'remove' *
is by changing the reading frame, e.g., try using the second codon position (then the third) as the opening reading frame: if the *
'disappear' it was very likely just a reading frame issue. How to do that is a separate question. The resulting amino acid sequence will of course be very different.
There's a second possibility if the reading frame is correct, which is to treat each locus between the *
as a separate protein. That way the *
is 'removed' because their a multiple proteins within the locus. In that case, a \n
would replace the *
(Mac and Linux), i.e., carriage return.
*
. Your point should help them avoid an XY problem if they're in one - I hope they read your answer before proceeding in whatever direction they're headed.
$\endgroup$
You could use Biopython for this. It makes FASTA parsing really easy.
'''
Python version: 3.10.0
Biopython version: 1.79
'''
from Bio import SeqIO
for seq_record in SeqIO.parse("input.fasta", "fasta"):
if "*" not in (seq_record.seq):
print(">",seq_record.id)
print(seq_record.seq)
*
in them? $\endgroup$