Пример #1
0
def get_form():
    """
    @return: the body of a form
    """
    tree = NewickIO.parse(
            Contrasts.g_felsenstein_tree_string, FelTree.NewickTree)
    ordered_labels = ('a', 'b', 'c', 'd', 'e')
    C = Contrasts.get_contrast_matrix(tree, ordered_labels)
    # define the form objects
    form_objects = [
            Form.Matrix('contrast_matrix', 'contrast matrix',
                C, Contrasts.assert_contrast_matrix),
            Form.MultiLine('labels', 'ordered labels',
                '\n'.join(ordered_labels))]
    return form_objects
Пример #2
0
def get_form():
    """
    @return: the body of a form
    """
    tree = NewickIO.parse(Contrasts.g_felsenstein_tree_string,
                          FelTree.NewickTree)
    ordered_labels = ('a', 'b', 'c', 'd', 'e')
    C = Contrasts.get_contrast_matrix(tree, ordered_labels)
    # define the form objects
    form_objects = [
        Form.Matrix('contrast_matrix', 'contrast matrix', C,
                    Contrasts.assert_contrast_matrix),
        Form.MultiLine('labels', 'ordered labels', '\n'.join(ordered_labels))
    ]
    return form_objects
Пример #3
0
def get_response_content(fs):
    # get the tree
    tree = NewickIO.parse(fs.tree, FelTree.NewickTree)
    # read the ordered labels
    ordered_labels = Util.get_stripped_lines(fs.labels.splitlines())
    # validate the input
    observed_label_set = set(node.get_name() for node in tree.gen_tips())
    if set(ordered_labels) != observed_label_set:
        msg = 'the labels should match the labels of the leaves of the tree'
        raise HandlingError(msg)
    # get the matrix of pairwise distances among the tips
    C = Contrasts.get_contrast_matrix(tree, ordered_labels)
    # set elements with small absolute value to zero
    C[abs(C) < fs.epsilon] = 0
    # return the reponse
    if fs.plain_format:
        return MatrixUtil.m_to_string(C) + '\n'
    elif fs.matlab_format:
        return MatrixUtil.m_to_matlab_string(C) + '\n'
    elif fs.r_format:
        return MatrixUtil.m_to_R_string(C) + '\n'