Пример #1
0
def consolidate(usages):
    """Sums frequencies of a list of usages into one usage."""
    result = CodonUsage()
    for u in usages:
        result += u
    result.normalize()
    return result
Пример #2
0
def adapt_pr2_bias(codon_usages, block="GC", bin_lowbound=0.0, bin_upbound=1.0, binwidth=0.1):
    """Returns the bin midpoint and the PR2 biases for each bin of GC3."""
    result = []
    for i, bin in enumerate(bin_by_p3(codon_usages, bin_lowbound, bin_upbound, binwidth)):
        if not bin:
            continue
        try:
            tot_usage = CodonUsage()
            for c in bin:
                tot_usage += c
            curr_pr2 = tot_usage.pr2bias(block)
            midbin = bin_lowbound + (i + 0.5) * binwidth
            result.append([midbin] + list(curr_pr2))
        except (ZeroDivisionError, FloatingPointError):
            pass
    return array(result)
Пример #3
0
def adapt_pr2_bias(codon_usages, block='GC', bin_lowbound=0.0, bin_upbound=1.0,\
    binwidth=0.1):
    """Returns the bin midpoint and the PR2 biases for each bin of GC3."""
    result = []
    for i, bin in enumerate(bin_by_p3(codon_usages, bin_lowbound, bin_upbound, \
        binwidth)):
        if not bin:
            continue
        try:
            tot_usage = CodonUsage()
            for c in bin:
                tot_usage += c
            curr_pr2 = tot_usage.pr2bias(block)
            midbin = bin_lowbound + (i+0.5)*binwidth
            result.append([midbin]+list(curr_pr2))
        except (ZeroDivisionError, FloatingPointError):
            pass
    return array(result)
Пример #4
0
def adapt_fingerprint(codon_usages, which_blocks="quartets", include_mean=True, normalize=True):
    """takes a sequence of CodonUsage objects
    and returns an array for a fingerprint plot with:
    x: the g3/(g3+c3)
    y: the a3/(a3+u3)
    frequency: total of the base/total of all

    in the order:
    alanine, arginine4, glycine, leucine4,
    proline, serine4, threonine, valine (if quartets_only is True).

    codon_usages:   list of CodonUsage objects
    quartets_only:  return only the quartets that all code for the same aa(True)
    quartets_only set to false yeilds a 16 fingerprint
    include_mean:   include a point for the mean in the result (True)
    normalize:      ensure the frequencies returned sum to 1 (True)
    """
    tot_codon_usage = CodonUsage()
    for idx, c in enumerate(codon_usages):
        tot_codon_usage += c
    return tot_codon_usage.fingerprint(which_blocks=which_blocks, include_mean=include_mean, normalize=normalize)
Пример #5
0
def adapt_fingerprint(codon_usages, which_blocks='quartets', \
    include_mean=True, normalize=True):
    """takes a sequence of CodonUsage objects
    and returns an array for a fingerprint plot with:
    x: the g3/(g3+c3)
    y: the a3/(a3+u3)
    frequency: total of the base/total of all

    in the order:
    alanine, arginine4, glycine, leucine4,
    proline, serine4, threonine, valine (if quartets_only is True).

    codon_usages:   list of CodonUsage objects
    quartets_only:  return only the quartets that all code for the same aa(True)
    quartets_only set to false yeilds a 16 fingerprint
    include_mean:   include a point for the mean in the result (True)
    normalize:      ensure the frequencies returned sum to 1 (True)
    """
    tot_codon_usage = CodonUsage()
    for idx, c in enumerate(codon_usages):
        tot_codon_usage += c
    return tot_codon_usage.fingerprint(which_blocks=which_blocks, \
        include_mean=include_mean, normalize=normalize)