text: user3061: I have a bunch of sequences created with Roary which I want to preprocess. When I read the sequences (genomics data) I want to translate them to protein sequences using:
  import pandas as pd
  from Bio.Seq import Seq
  from Bio import SeqIO
  
  def read_fasta_file(fn):
      with open(fn,'r') as file:
          fasta_sequences = SeqIO.parse(file, 'fasta')
          sequences = pd.DataFrame([{
              'filename': basename(fn),
              'id': rec.id,
              'seq': str(rec.seq.translate())} for rec in fasta_sequences])
      return sequences
  
  The problem is that .translate() fails with:
  
  TranslationError: Codon 'T--' is invalid
  
  Is there a build-in function to ignore the dashes?
  
  user3061: I think the .ungap() is what I was looking for.
  def read_fasta_file(fn):
      with open(fn,'r') as file:
          fasta_sequences = SeqIO.parse(file, 'fasta')
          sequences = pd.DataFrame([{
              'filename': basename(fn),
              'id': rec.id,
              'seq': str(rec.seq.ungap().translate())} for rec in fasta_sequences])
      return sequences
  
  
original_text: 3061: <p>I have a bunch of sequences created with <code>Roary</code> which I want to preprocess. When I read the sequences (genomics data) I want to translate them to protein sequences using:</p>
  <pre><code>import pandas as pd
  from Bio.Seq import Seq
  from Bio import SeqIO
  
  def read_fasta_file(fn):
      with open(fn,'r') as file:
          fasta_sequences = SeqIO.parse(file, 'fasta')
          sequences = pd.DataFrame([{
              'filename': basename(fn),
              'id': rec.id,
              'seq': str(rec.seq.translate())} for rec in fasta_sequences])
      return sequences
  </code></pre>
  <p>The problem is that <code>.translate()</code> fails with:</p>
  <blockquote>
  <p>TranslationError: Codon 'T--' is invalid</p>
  </blockquote>
  <p>Is there a build-in function to ignore the dashes?</p>
   3061: <p>I think the <code>.ungap()</code> is what I was looking for.</p>
  <pre><code>def read_fasta_file(fn):
      with open(fn,'r') as file:
          fasta_sequences = SeqIO.parse(file, 'fasta')
          sequences = pd.DataFrame([{
              'filename': basename(fn),
              'id': rec.id,
              'seq': str(rec.seq.ungap().translate())} for rec in fasta_sequences])
      return sequences
  </code></pre>
  