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


Python Tree.value方法代码示例

本文整理汇总了Python中tree.Tree.value方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.value方法的具体用法?Python Tree.value怎么用?Python Tree.value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tree.Tree的用法示例。


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

示例1: NJ_Algorithm

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import value [as 别名]
def NJ_Algorithm():
    """
    Neighbor-Joining algorithm to join species and create phylogenetic tree
    """
    phylo_tree = None
    tree_dict = dict()

    # Loop through species until down to one pair
    for k in range(len(species)-1):
        # Get average distance for every node
        node_avg = ComputeNodeAvgDist()
        
        # Find lowest pair of species to join from average distance species list
        min_val, min_a, min_b = FindLowestPair(node_avg)
        
        if species[min_a] in tree_dict:
            # If the first joined species is already in the tree dictionary, retrieve it
            child1 = tree_dict[species[min_a]]
        else:
            # Else create new species tree
            child1 = Tree(species[min_a])
        # v_i = D_ij/2 + (u_i - u_j)/2
        child1.value = min_val/2.0 + (node_avg[min_a] - node_avg[min_b])/2.0
        
        if species[min_b] in tree_dict:
            # If the second joined species is already in the tree dictionary, retrieve it
            child2 = tree_dict[species[min_b]]
        else:
            # Else create new species tree
            child2 = Tree(species[min_b])
        # v_j = D_ij/2 + (u_j - u_i)/2
        child2.value = min_val/2.0 + (node_avg[min_b] - node_avg[min_a])/2.0
        
        # Create new tree with both A and B species joined 
        key = "(" + species[min_a] + "),(" + species[min_b] + ")"
        phylo_tree = Tree(key)
        phylo_tree.value = min_val/2.0

        # Put lower value to left of tree
        if child1.value <= child2.value:
            phylo_tree.AddLeftChild(child1, child1.value)
            phylo_tree.AddRightChild(child2, child2.value)
        else:
            phylo_tree.AddLeftChild(child2, child2.value)
            phylo_tree.AddRightChild(child1, child1.value)
        
        #phylo_tree.printNodeInfo()
        tree_dict[key] = phylo_tree
   
        # Create joined values to put back into 2d matrix 
        joinedDist = CreateJoinedDistances(min_a, min_b, min_val)
 
        # Remove A and B individually and insert AB joined
        CombineSpecies(joinedDist, min_a, min_b)

    return phylo_tree
开发者ID:jwei7er,项目名称:bioinformatics,代码行数:58,代码来源:nj.py

示例2: UPGMA_Algorithm

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import value [as 别名]
def UPGMA_Algorithm():
    """
    UPGMA algorithm to join species and create phylogenetic tree
    """
    phylo_tree = None
    tree_dict = dict()

    # Loop through species until down to one pair
    for k in range(len(species)-1):
        min_val, min_i, min_j = FindLowestPair()
    
        if species[min_i] in tree_dict:
            # If the first joined species is already in the tree dictionary, retrieve it
            child1 = tree_dict[species[min_i]]
        else:
            # Else create new species tree
            child1 = Tree(species[min_i])
            child1.value = min_val/2.0
    
        if species[min_j] in tree_dict:
            # If the second joined species is already in the tree dictionary, retrieve it
            child2 = tree_dict[species[min_j]]
        else:
            # Else create new species tree
            child2 = Tree(species[min_j])
            child2.value = min_val/2.0
     
        # Create new tree with both A and B species joined 
        key = "(" + species[min_i] + "),(" + species[min_j] + ")"
        phylo_tree = Tree(key)
        phylo_tree.value = min_val/2.0

        # Put lower value to left of tree
        if child1.value <= child2.value:
            phylo_tree.AddLeftChild(  child1, (phylo_tree.value - child1.value) )
            phylo_tree.AddRightChild( child2, (phylo_tree.value - child2.value) )
        else:
            phylo_tree.AddLeftChild(  child2, (phylo_tree.value - child2.value) )
            phylo_tree.AddRightChild( child1, (phylo_tree.value - child1.value) )
        
        #phylo_tree.printNodeInfo()
        tree_dict[key] = phylo_tree
     
        # Create joined values to put back into 2d matrix 
        joined_values = CreateJoinedDistances(min_i, min_j)
        
        # Remove A and B individually and insert AB joined
        CombineSpecies(joined_values, min_i, min_j)

    return phylo_tree
开发者ID:jwei7er,项目名称:bioinformatics,代码行数:52,代码来源:upgma.py

示例3: testProperty

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import value [as 别名]
    def testProperty(self):

        x = Tree(value=None)
        self.assertTrue(x.value == None)

        x.value = 5
        self.assertTrue(x.value == 5)
开发者ID:rcludwick,项目名称:TreePy,代码行数:9,代码来源:test.py

示例4: testEquals

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import value [as 别名]
    def testEquals(self):

        t1 = Tree(value="Root Node", children=TreeTest.tree_layout)
        t2 = Tree(value="Root Node", children=TreeTest.tree_layout)

        self.assertTrue(t1 == t2)

        t1.value = "x"
        t2.value = "Y"
        self.assertFalse(t1 == t2)

        t1.value = 15
        t2.value = 15
        self.assertTrue(t1 == t2)
        t1 = Tree(value="Root Node", children=TreeTest.tree_layout)
        t2 = Tree(value="Root Node", children=TreeTest.tree_layout_2)
        self.assertFalse(t1 == t2)

        t3_1 = Tree(value=None, children=TreeTest.tree_layout_3)
        t3_2 = Tree(value=None, children=TreeTest.tree_layout_3)
        self.assertTrue(t3_1 == t3_2)
开发者ID:rcludwick,项目名称:TreePy,代码行数:23,代码来源:test.py


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