Codon usage analysis for whole genomes
This python script will remove all stop codons from your fasta file. I called it remove_stops.py

#!/usr/bin/env python3
import sys
from Bio import SeqIO
stop_codons = ["TAG", "TGA", "TAA", "UAG", "UGA", "UAA"]

fasta_it = SeqIO.parse(open(sys.argv[1]), 'fasta')
for fasta in fasta_it:
    name, sequence = fasta.description, str(fasta.seq)
    try:
        assert(len(sequence) % 3 == 0)
    except:
        raise IOError("length of sequence {} was not divisible by three".format(name))
    print("&gt;{}".format(name))
    print("".join([sequence[i:i+3] for i in range(0, len(sequence) - 3 + 1, 3)
                   if sequence[i:i+3] not in stop_codons]))


You can run it like so:

python remove_stops.py stop_codons.fasta &gt; filtered.fasta


This program won't work if there are any fasta records that do not have a length divisible by three. This indicates a sliding translation stop and these sequences should be trimmed individually. Also, all the genes must be in the 5'->3' direction.

It works by looking at each codon [sequence[i:i+3] for i in range(0, len(sequence) - 3 + 1, 3), then just makes sure they are not a stop codon: if sequence[i:i+3] not in stop_codons]