コード例 #1
0
def main():
    # create the alignment object
    print 'creating the alignment...'
    alignment_string = Fasta.brown_example_alignment.strip()
    alignment = Fasta.Alignment(StringIO(alignment_string))
    # create a tree object
    print 'creating the tree...'
    tree_string = Newick.brown_example_tree
    tree = Newick.parse(tree_string, Newick.NewickTree)
    # create a rate matrix object
    print 'creating the rate matrix object...'
    distribution = {'A': .25, 'C': .25, 'G': .25, 'T': .25}
    kappa = 2.0
    row_major_rate_matrix = RateMatrix.get_unscaled_hky85_rate_matrix(
        distribution, kappa).get_row_major_rate_matrix()
    rate_matrix = RateMatrix.FastRateMatrix(row_major_rate_matrix,
                                            list('ACGT'))
    rate_matrix.normalize()
    # get the mle_rates
    print 'getting the mle rates...'
    mle_rates = get_mle_rates(tree, alignment, rate_matrix)
    print 'mle rates:'
    print mle_rates
    print 'stockholm string:'
    print get_stockholm_string(tree, alignment, mle_rates)
コード例 #2
0
def get_response_content(fs):
    # get the tree
    tree = Newick.parse(fs.tree, Newick.NewickTree)
    tree.assert_valid()
    # get the nucleotide distribution
    distribution = SnippetUtil.get_distribution(fs.weights, 'nucleotide',
                                                list('ACGT'))
    # get the nucleotide alignment
    try:
        alignment = Fasta.Alignment(StringIO(fs.alignment))
        alignment.force_nucleotide()
    except Fasta.AlignmentError as e:
        raise HandlingError(e)
    # get the rate matrix defined by the nucleotide distribution and kappa
    row_major_rate_matrix = RateMatrix.get_unscaled_hky85_rate_matrix(
        distribution, fs.kappa).get_row_major_rate_matrix()
    rate_matrix = RateMatrix.FastRateMatrix(row_major_rate_matrix,
                                            list('ACGT'))
    rate_matrix.normalize()
    # get the mle rates
    mle_rates = get_mle_rates(tree, alignment, rate_matrix)
    # return the response
    return get_stockholm_string(tree, alignment, mle_rates) + '\n'
コード例 #3
0
def get_response_content(fs):
    # read the matrix from the form data
    R = fs.matrix
    matrix_size = len(R)
    # enforce constraints on the initial and final states
    if fs.initial >= matrix_size:
        msg = 'the initial state must be less than the size of the matrix'
        raise HandlingError(msg)
    if fs.final >= matrix_size:
        msg = 'the final state must be less than the size of the matrix'
        raise HandlingError(msg)
    # convert the row major rate matrix to a rate matrix object
    arbitrary_states = list(str(x) for x in range(matrix_size))
    rate_matrix_object = RateMatrix.FastRateMatrix(
            R.tolist(), arbitrary_states)
    # get the expected time spent in each state
    expected_wait_times = rate_matrix_object.get_expected_times(
            fs.initial, fs.final, fs.time)
    # create the response text
    out = StringIO()
    for state_index, expected_wait_time in enumerate(expected_wait_times):
        print >> out, state_index, ':', expected_wait_time / fs.time
    # return the response
    return out.getvalue()