code: def translate(records, translate):
      
      logging.info('Applying translation generator: '
                   'operation to perform is ' + translate + '.')
  
      to_stop = translate.endswith('stop')
  
      source_type = translate[:3]
      alphabet = {'dna': IUPAC.ambiguous_dna, 'rna': IUPAC.ambiguous_rna}[source_type]
  
      # Get a translation table
      table = {'dna': CodonTable.ambiguous_dna_by_name["Standard"],
               'rna': CodonTable.ambiguous_rna_by_name["Standard"]}[source_type]
  
      # Handle ambiguities by replacing ambiguous codons with 'X'
      # TODO: this copy operation causes infinite recursion with python3.6 -
      # not sure why it was here to begin with.
      # table = copy.deepcopy(table)
      table.forward_table = CodonWarningTable(table.forward_table)
  
      for record in records:
          sequence = str(record.seq)
          seq = Seq(sequence, alphabet)
          protein = seq.translate(table, to_stop=to_stop)
          yield SeqRecord(protein, id=record.id, description=record.description)
docs: Perform translation from generic DNA/RNA to proteins.  Bio.Seq
      does not perform back-translation because the codons would
      more-or-less be arbitrary.  Option to translate only up until
      reaching a stop codon.  translate must be one of the following:
          dna2protein
          dna2proteinstop
          rna2protein
          rna2proteinstop