<p>Try <code>seqkit grep</code></p>
<pre><code>seqkit grep --by-seq --invert-match --pattern '*' seq.fa
</code></pre>
<p><code>--by-seq</code> search by seq</p>
<p>It will output sequences without an asterisk.</p>

CC BY-SA 4.0
2022-07-15T16:45:20.743Z
This technically answers the question, if we assume OP is not in an XY problem and removing valid sequences that they don't understand (which is highly probable given that they call them "sequences with an asterisk" and not "sequenced containing stop codons".
Ram RS
CC BY-SA 4.0
2022-07-15T14:06:11.463Z
2022-07-15T14:32:06.223Z
2022-07-15T14:32:06.223Z
Forrest Vigor
<p>It’s  good you brought up the question.</p>
<h3><code>*</code> are stop codons</h3>
<p>Don't simply parse out the <code>*</code> symbol. If done incorrectly, it could constitute <strong>'tampering'</strong> and that’s a <em>red line</em> in biology.</p>
<p>The <code>*</code> means a stop codon in the middle of a protein sequence. There are quite a number of reasons why there is an <code>*</code>, i.e., a stop codon in the sequence, for example, in no particular order:</p>
<ul>
<li>the open reading frame is out of frame which is part of the natural molecular biology, i.e., there can be multiple reading frames in a gene</li>
<li>the open reading frame is out of frame due to a sequencing error and poor annotation (which is common);</li>
<li>the wrong reading frame was used (very, very common);</li>
<li>the locus isn't translated, e.g., it’s an intron or UTR (untranslated region)</li>
</ul>
<p>The list goes on, e.g., it could be expression regulation ...</p>
<hr />
<ol>
<li><p>If it is not an intron/UTR the way you might 'remove' <code>*</code> is by changing the reading frame, e.g., try using the second codon position (then the third) as the opening reading frame: if the <code>*</code> '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.</p>
</li>
<li><p>There's a second possibility if the reading frame is correct, which is to treat each locus between the <code>*</code> as a separate protein. That way the <code>*</code> is 'removed' because their a multiple proteins within the locus. In that case, a <code>\n</code> would replace the <code>*</code> (Mac and Linux), i.e., carriage return.</p>
</li>
</ol>

CC BY-SA 4.0
2022-07-15T16:47:05.017Z
I don't think they're looking to tamper, but they probably don't understand the significance of the `*`. 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.
Ram RS
CC BY-SA 4.0
2022-07-15T15:18:01.320Z
2022-07-16T13:56:58.370Z
2022-07-16T13:56:58.370Z
M__
<p>You could use Biopython for this. It makes FASTA parsing really easy.</p>
<pre><code>'''
Python version: 3.10.0
Biopython version: 1.79
'''
from Bio import SeqIO
for seq_record in SeqIO.parse(&quot;input.fasta&quot;, &quot;fasta&quot;):
    if &quot;*&quot; not in (seq_record.seq):
        print(&quot;&gt;&quot;,seq_record.id)
        print(seq_record.seq)
</code></pre>

CC BY-SA 4.0
2022-07-16T19:38:17.097Z
2022-07-16T19:38:17.097Z
Supertech
<p>I have several protein sequences with an asterisk in the middle of the sequence, and I'd like to remove those sequences.</p>
<p>In the example below, I have three sequences:</p>
<p><a href="https://i.sstatic.net/NXLBh.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/NXLBh.png" alt="Enter image description here" /></a></p>
<p>From this example, I would like to obtain only the following output:</p>
<p><a href="https://i.sstatic.net/nuMbc.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/nuMbc.png" alt="Enter image description here" /></a></p>

CC BY-SA 4.0
2022-07-15T16:47:28.067Z
Why do you want to remove sequences with `*` in them?
Ram RS
<fasta><phylogenetics><proteins><phylogeny><sequence>
How can I remove FASTA sequences with an asterisk inside the sequence?
# How can I remove FASTA sequences with an asterisk inside the sequence?

(Asked by: username_0 on 2022-07-15)

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:

[![Enter image description here](https://i.sstatic.net/NXLBh.png)](https://i.sstatic.net/NXLBh.png)

From this example, I would like to obtain only the following output:

[![Enter image description here](https://i.sstatic.net/nuMbc.png)](https://i.sstatic.net/nuMbc.png)

**Tags:** fasta, phylogenetics, proteins, phylogeny, sequence
> **Comments:**
> **username_1**: Why do you want to remove sequences with `*` in them?  

---

## 3 answers

### Answer by username_2 on 2022-07-15. Score: 4

Try seqkit grep
seqkit grep --by-seq --invert-match --pattern '*' seq.fa

--by-seq search by seq
It will output sequences without an asterisk.

> **Comments:**
> **username_1**: This technically answers the question, if we assume OP is not in an XY problem and removing valid sequences that they don't understand (which is highly probable given that they call them "sequences with an asterisk" and not "sequenced containing stop codons".  

---

### Answer by username_3 on 2022-07-15. Score: 4

It’s good you brought up the question.

### `*` are stop codons

Don'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 open reading frame is out of frame which is part of the natural molecular biology, i.e., there can be multiple reading frames in a gene
* the open reading frame is out of frame due to a sequencing error and poor annotation (which is common);
* the wrong reading frame was used (very, very common);
* the locus isn't translated, e.g., it’s an intron or UTR (untranslated region)

The list goes on, e.g., it could be expression regulation ...

---

1. 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.
2. 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.

> **Comments:**
> **username_1**: I don't think they're looking to tamper, but they probably don't understand the significance of the `*`. 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.  

---

### Answer by username_4 on 2022-07-16. Score: 1

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)


---

