Exemple #1
0
def codon_usage_for(seq, strand = 1, frame = 0):
    """
    Return a count list of codon usage for a given gene.
    """
    hist = empty_codon_dict()

    for codon in codons_for_frame(seq, strand, frame):
        if 'N' not in codon:
            hist[codon] += 1

    return hist
Exemple #2
0
def weighted_codon_usage_for(gene, seq, expression):
    """
    Return a count list of codon usage for a given gene, weighted by the
    expression base mean of the gene.
    """
    if expression == 0:
        return empty_codon_dict()

    hist = codon_usage_for(seq)
    return dict((codon, freq * expression)
                for codon, freq in hist.items())
Exemple #3
0
def histogram(transcripts, genes):
    """
    Calculate the weighted frequencies of all occurring in the transcripts.

    The transcripts are weighed by their transcription level.
    Returns a dictionary of codons and their frequency.
    """
    def add_to_total(total, hist):
        for key, value in hist.items():
            total[key] += value

    total = empty_codon_dict()
    failures = 0
    for expression in genes:
        gene = expression[0]
        seq = transcripts[gene]
        if seq is None or seq == '':
            failures += 1
            continue

        hist = weighted_codon_usage_for(gene, seq, expression[1])
        add_to_total(total, hist)

    return total