当前位置: 首页>>代码示例>>Python>>正文


Python NewickIO类代码示例

本文整理汇总了Python中NewickIO的典型用法代码示例。如果您正苦于以下问题:Python NewickIO类的具体用法?Python NewickIO怎么用?Python NewickIO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NewickIO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_response_content

def get_response_content(fs):
    # get the set of names
    selection = Util.get_stripped_lines(StringIO(fs.names))
    # get the tree
    tree = NewickIO.parse(fs.tree, FelTree.NewickTree)
    # assert that the name selection is compatible with the tree
    selected_name_set = set(selection)
    possible_name_set = set(node.get_name() for node in tree.gen_tips())
    extra_names = selected_name_set - possible_name_set
    if extra_names:
        msg_a = "the following selected names "
        msg_b = "are not valid tips: %s" % str(tuple(extra_names))
        raise HandlingError(msg_a + msg_b)
    # get the pruned tree
    simple_tree = NewickIO.parse(fs.tree, Newick.NewickTree)
    pruned_tree = get_pruned_tree(simple_tree, selected_name_set)
    # begin writing the result
    out = StringIO()
    trees = (tree, pruned_tree)
    tree_names = ("the original tree", "the pruned tree")
    for tree, tree_name in zip(trees, tree_names):
        print >> out, "calculating splits of %s:" % tree_name
        print >> out, process_tree(tree, tree_name, fs.show_newick, fs.show_art)
    # return the response
    return out.getvalue()
开发者ID:argriffing,项目名称:xgcode,代码行数:25,代码来源:20090128a.py

示例2: get_response_content

def get_response_content(fs):
    # read the tree
    tree = NewickIO.parse(fs.tree, Newick.NewickTree) 
    # begin the response
    out = StringIO()
    # remove the branch length associated with the root
    if tree.get_root().blen is not None:
        print >> out, 'the root originally had a branch length of', tree.get_root().blen
        tree.get_root().blen = None
    else:
        print >> out, 'the root did not originally have a branch length'
    # force a trifurcation at the root
    if tree.get_root().get_child_count() < 3:
        print >> out, 'the original root had', tree.get_root().get_child_count(), 'children'
        max_children, best_child = max((child.get_child_count(), child) for child in tree.get_root().gen_children())
        old_root = tree.get_root()
        tree.reroot(best_child)
        tree.remove_node(old_root)
        print >> out, 'the new root has', tree.get_root().get_child_count(), 'children'
    else:
        print >> out, 'the root has', tree.get_root().get_child_count(), 'children'
    # remove names of internal nodes
    nremoved_names = 0
    for node in tree.preorder():
        if node.has_children() and node.name is not None:
            node.name = None
            nremoved_names += 1
    print >> out, 'removed', nremoved_names, 'internal node names'
    # draw the new formatted newick string after a break
    print >> out
    formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 120) 
    print >> out, formatted_tree_string
    # return the response
    return out.getvalue()
开发者ID:argriffing,项目名称:xgcode,代码行数:34,代码来源:20090803a.py

示例3: get_response_content

def get_response_content(fs):
    # read the query tree
    query_tree = NewickIO.parse(fs.query, FelTree.NewickTree)
    # read the reference tree
    reference_tree = NewickIO.parse(fs.reference, FelTree.NewickTree)
    # calculate the loss using the requested loss function
    if fs.uniform:
        loss_numerator = TreeComparison.get_split_distance(
                query_tree, reference_tree)
    elif fs.weighted:
        loss_numerator = TreeComparison.get_weighted_split_distance(
                query_tree, reference_tree)
    # do the normalization if requested
    if fs.normalize:
        if fs.uniform:
            loss_denominator = float(
                    TreeComparison.get_nontrivial_split_count(reference_tree))
        elif fs.weighted:
            loss_denominator = float(
                    TreeComparison.get_weighted_split_count(reference_tree))
    else:
        loss_denominator = 1
    # return the response
    if loss_denominator:
        return str(loss_numerator / loss_denominator) + '\n'
    else:
        return 'normalization failed\n'
开发者ID:argriffing,项目名称:xgcode,代码行数:27,代码来源:20080910a.py

示例4: get_form

def get_form():
    """
    @return: the body of a form
    """
    # define the default tree string
    tree = NewickIO.parse(g_default_string, FelTree.NewickTree)
    formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60)
    # define the form objects
    form_objects = [
            Form.MultiLine('tree', 'newick tree',
                formatted_tree_string),
            Form.Integer('length', 'use sequences that are this long',
                100, low=1),
            Form.RadioGroup('assumption', 'distance matrix sampling model', [
                Form.RadioItem('infinite_alleles', 'infinite alleles', True),
                Form.RadioItem('jukes_cantor',
                    'Jukes-Cantor model (4 alleles)')]),
            Form.RadioGroup('infinity', 'infinite distance estimates', [
                Form.RadioItem('reject_infinity', 'reject these matrices'),
                Form.RadioItem('replace_infinity',
                    'replace inf with 20', True)]),
            Form.RadioGroup('zero', 'distance estimates of zero', [
                Form.RadioItem('reject_zero', 'reject these matrices'),
                Form.RadioItem('replace_zero', 'use .00001 instead of zero'),
                Form.RadioItem('remain_zero', 'use 0 unmodified', True)])]
    return form_objects
开发者ID:argriffing,项目名称:xgcode,代码行数:26,代码来源:20080912a.py

示例5: get_form

def get_form():
    """
    @return: the body of a form
    """
    # define the tree string
    tree_string = '(((a:0.05, b:0.05):0.15, c:0.2):0.8, x:1.0, (((m:0.05, n:0.05):0.15, p:0.2):0.8, y:1.0):1.0);'
    tree = NewickIO.parse(tree_string, FelTree.NewickTree)
    formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60)
    # define the object list
    form_objects = [
            Form.MultiLine('tree', 'tree',
                formatted_tree_string),
            Form.Integer('sequence_length', 'use sequences that are this long',
                100, low=1),
            Form.RadioGroup('assumption', 'distance matrix sampling model', [
                RadioItem('infinite_alleles', 'infinite alleles', True),
                RadioItem('jukes_cantor', 'Jukes-Cantor model (4 alleles)')]),
            Form.RadioGroup('infinity', 'matrices with infinite distances', [
                RadioItem('reject_infinity', 'reject these matrices', True),
                RadioItem('replace_infinity', 'use 20 instead')]),
            Form.RadioGroup('zero', 'matrices with zero distances', [
                RadioItem('reject_zero', 'reject these matrices'),
                RadioItem('replace_zero', 'use .00001 instead'),
                RadioItem('remain_zero', 'use 0 unmodified', True)]),
            Form.RadioGroup('criterion', 'tree reconstruction criterion', [
                RadioItem('sign', 'spectral sign approximation', True),
                RadioItem('nj', 'neighbor joining'),
                RadioItem('random', 'random bipartition')])]
    # return the object list
    return form_objects
开发者ID:argriffing,项目名称:xgcode,代码行数:30,代码来源:20080918a.py

示例6: get_form

def get_form():
    """
    @return: the body of a form
    """
    # define the default tree string
    tree = NewickIO.parse(g_default_string, FelTree.NewickTree)
    formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60)
    # define the form objects
    form_objects = [
            Form.MultiLine('tree',
                'newick tree with branch lengths', formatted_tree_string),
            Form.SingleLine('lhs_a',
                'the first taxon on one side of the split', 'a'),
            Form.SingleLine('lhs_b',
                'the second taxon on one side of the split', 'b'),
            Form.SingleLine('rhs_a',
                'the first taxon on the other side of the split', 'x'),
            Form.SingleLine('rhs_b',
                'the second taxon on the other side of the split', 'y'),
            Form.CheckGroup('options', 'output options', [
                Form.CheckItem('show_response',
                    'show the full Laplacian matrix'),
                Form.CheckItem('show_reduced_response',
                    'show the 2x2 submatrix'),
                Form.CheckItem('show_blen',
                    'show the branch length implied by the split')])]
    return form_objects
开发者ID:argriffing,项目名称:xgcode,代码行数:27,代码来源:20090209a.py

示例7: get_form

def get_form():
    """
    @return: the body of a form
    """
    # define the default tree string
    tree = NewickIO.parse(g_default_string, FelTree.NewickTree)
    formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60)
    # define the form objects
    form_objects = [
        Form.MultiLine("tree", "newick tree", formatted_tree_string),
        Form.RadioGroup(
            "matrix",
            "nodes used for the distance matrix",
            [
                RadioItem("standard", "tips only", True),
                RadioItem("augmented", "all nodes"),
                RadioItem("named", "all named nodes"),
            ],
        ),
        Form.CheckGroup(
            "output_options",
            "output options",
            [
                CheckItem("show_split", "exact criterion partition", True),
                CheckItem("show_value", "exact criterion value", True),
                CheckItem("show_value_minus_trace", "exact criterion value minus trace", True),
                CheckItem("show_fiedler_split", "show the spectral sign partition", True),
                CheckItem("show_fiedler_eigenvector", "show the eigenvector of interest", True),
                CheckItem("show_labels", "ordered labels", True),
                CheckItem("show_distance_matrix", "distance matrix", True),
                CheckItem("show_M_matrix", "M matrix", True),
            ],
        ),
    ]
    return form_objects
开发者ID:argriffing,项目名称:xgcode,代码行数:35,代码来源:20081001b.py

示例8: do_distance_analysis

def do_distance_analysis(X):
    # get the matrix of squared distances
    labels = list("0123")
    # reconstruct the matrix of Euclidean distances from a tree
    D_sqrt = np.array([[np.linalg.norm(y - x) for x in X] for y in X])
    sqrt_tree = NeighborJoining.make_tree(D_sqrt, labels)
    sqrt_tree_string = NewickIO.get_newick_string(sqrt_tree)
    sqrt_feltree = NewickIO.parse(sqrt_tree_string, FelTree.NewickTree)
    D_sqrt_reconstructed = np.array(sqrt_feltree.get_distance_matrix(labels))
    # reconstruct the matrix of squared Euclidean distances from a tree
    D = D_sqrt ** 2
    tree = NeighborJoining.make_tree(D, labels)
    tree_string = NewickIO.get_newick_string(tree)
    feltree = NewickIO.parse(tree_string, FelTree.NewickTree)
    D_reconstructed = np.array(feltree.get_distance_matrix(labels))
    # start writing
    out = StringIO()
    # matrix of Euclidean distances and its reconstruction from a tree
    print >> out, "matrix of Euclidean distances between tetrahedron vertices:"
    print >> out, D_sqrt
    print >> out, "neighbor joining tree constructed from D = non-squared Euclidean distances (unusual):"
    print >> out, sqrt_tree_string
    print >> out, "distance matrix implied by this tree:"
    print >> out, D_sqrt_reconstructed
    # matrix of squared Euclidean distances and its reconstruction from a tree
    print >> out, "matrix of squared distances between tetrahedron vertices:"
    print >> out, D
    print >> out, "neighbor joining tree constructed from D = squared Euclidean distances (normal):"
    print >> out, tree_string
    print >> out, "distance matrix implied by this tree:"
    print >> out, D_reconstructed
    return out.getvalue().strip()
开发者ID:argriffing,项目名称:xgcode,代码行数:32,代码来源:20091023a.py

示例9: test_get_split_distance

 def test_get_split_distance(self):
     """
     Test the function that gets the number of missing nontrivial partitions.
     """
     # define some trees
     tree_string_a = '((A:1, B:1):1, C:1, (D:1, E:1):1);'
     tree_string_b = '((A:1, B:1):1, D:1, (C:1, E:1):1);'
     tree_string_c = '((A:1, D:1):1, C:1, (B:1, E:1):1);'
     tree_string_d = '((A:1, D:1):1, (C:1, B:1, E:1):1);'
     tree_a = NewickIO.parse(tree_string_a, FelTree.NewickTree)
     tree_b = NewickIO.parse(tree_string_b, FelTree.NewickTree)
     tree_c = NewickIO.parse(tree_string_c, FelTree.NewickTree)
     tree_d = NewickIO.parse(tree_string_d, FelTree.NewickTree)
     # the distance from a tree to itself should be zero
     self.assertEqual(get_split_distance(tree_a, tree_a), 0)
     self.assertEqual(get_split_distance(tree_b, tree_b), 0)
     self.assertEqual(get_split_distance(tree_c, tree_c), 0)
     self.assertEqual(get_split_distance(tree_d, tree_d), 0)
     # some of the distances are symmetric
     self.assertEqual(get_split_distance(tree_a, tree_b), 1)
     self.assertEqual(get_split_distance(tree_b, tree_a), 1)
     self.assertEqual(get_split_distance(tree_b, tree_c), 2)
     self.assertEqual(get_split_distance(tree_c, tree_b), 2)
     self.assertEqual(get_split_distance(tree_a, tree_c), 2)
     self.assertEqual(get_split_distance(tree_c, tree_a), 2)
     # it is possible for the distance to be asymmetric if internal nodes are not order 3
     self.assertEqual(get_split_distance(tree_a, tree_d), 1)
     self.assertEqual(get_split_distance(tree_d, tree_a), 2)
开发者ID:argriffing,项目名称:xgcode,代码行数:28,代码来源:TreeComparison.py

示例10: get_form

def get_form():
    """
    @return: a list of form objects
    """
    tree = NewickIO.parse(g_default_string, FelTree.NewickTree)
    formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60)
    return [Form.MultiLine('tree', 'tree', formatted_tree_string)]
开发者ID:argriffing,项目名称:xgcode,代码行数:7,代码来源:20081120a.py

示例11: get_form

def get_form():
    """
    @return: the body of a form
    """
    # define the default tree string and ordered tip labels
    tree_string = "(a:1, (b:2, d:5):1, c:4);"
    tree = NewickIO.parse(tree_string, FelTree.NewickTree)
    formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60)
    labels = list(sorted(tip.name for tip in tree.gen_tips()))
    # define the form objects
    form_objects = [
        Form.MultiLine("tree", "newick tree", formatted_tree_string),
        Form.MultiLine("inlabels", "ordered labels", "\n".join(labels)),
        Form.Float("strength", "perturbation strength", 0.1, low_inclusive=0),
        Form.CheckGroup(
            "options",
            "output options",
            [
                CheckItem("perturbed", "a perturbed distance matrix", True),
                CheckItem("distance", "the original distance matrix"),
                CheckItem("outlabels", "ordered labels"),
            ],
        ),
    ]
    return form_objects
开发者ID:argriffing,项目名称:xgcode,代码行数:25,代码来源:20080703a.py

示例12: get_form

def get_form():
    """
    @return: a list of form objects
    """
    # define the default tree string
    tree = NewickIO.parse(g_default_string, FelTree.NewickTree)
    formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60)
    # return the form objects
    form_objects = [Form.MultiLine("tree", "newick tree with branch lengths", formatted_tree_string)]
    return form_objects
开发者ID:argriffing,项目名称:xgcode,代码行数:10,代码来源:20081202a.py

示例13: test_contrast_matrix_to_tree

 def test_contrast_matrix_to_tree(self):
     original_tree = NewickIO.parse(g_felsenstein_tree_string, FelTree.NewickTree)
     ordered_names = ('a', 'b', 'c', 'd', 'e')
     C = get_contrast_matrix(original_tree, ordered_names)
     assert_contrast_matrix(C)
     reconstructed_tree = contrast_matrix_to_tree(C, ordered_names)
     newick_string = NewickIO.get_newick_string(reconstructed_tree)
     print
     print newick_string
     pass
开发者ID:argriffing,项目名称:xgcode,代码行数:10,代码来源:Contrasts.py

示例14: get_form

def get_form():
    """
    @return: the body of a form
    """
    # define the formatted tree string
    tree = NewickIO.parse(g_tree_data, Newick.NewickTree) 
    formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) 
    # return the form objects
    form_objects = [
            Form.MultiLine('tree', 'newick tree', formatted_tree_string)]
    return form_objects
开发者ID:argriffing,项目名称:xgcode,代码行数:11,代码来源:20090803a.py

示例15: get_form

def get_form():
    """
    @return: a list of form objects
    """
    # define the default tree string
    tree = NewickIO.parse(g_tree_string, FelTree.NewickTree)
    formatted_default_tree_string = NewickIO.get_narrow_newick_string(tree, 60)
    # define the list of form objects
    form_objects = [
            Form.MultiLine('tree', 'tree', formatted_default_tree_string),
            Form.ImageFormat()]
    return form_objects
开发者ID:argriffing,项目名称:xgcode,代码行数:12,代码来源:20090920a.py


注:本文中的NewickIO类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。