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


Python LoadTree.asciiArt方法代码示例

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


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

示例1: TestTree

# 需要导入模块: from cogent import LoadTree [as 别名]
# 或者: from cogent.LoadTree import asciiArt [as 别名]
class TestTree(unittest.TestCase):
    """tests for a single tree-type"""
    
    def setUp(self):
        self.name = 'small tree - '
        self.otu_names = ['NineBande', 'Mouse', 'HowlerMon', 'DogFaced']
        self.otu_names.sort()
        self.newick = '(((Human,HowlerMon),Mouse),NineBande,DogFaced);'
        self.newick_sorted = '(DogFaced,((HowlerMon,Human),Mouse),NineBande);'
        self.newick_reduced = '((HowlerMon,Mouse),NineBande,DogFaced);'
        self.tree = LoadTree(treestring = self.newick)
    
    def test_sorttree(self):
        """testing (well, exercising at least) treesort"""
        new_tree = self.tree.sorted()
        if hasattr(self, 'newick_sorted'):
            self.assertEqual(
                self.newick_sorted,
                new_tree.getNewick(with_distances=0))
    
    def test_getsubtree(self):
        """testing getting a subtree"""
        subtree = self.tree.unrooted().getSubTree(self.otu_names)
        
        new_tree = LoadTree(treestring = self.newick_reduced).unrooted()
        
        # check we get the same names
        self.assertEqual(*[len(t.Children) for t in (subtree,new_tree)])
        self.assertEqual(str(subtree), str(new_tree))
    
    def test_ascii(self):
        self.tree.asciiArt()
        # unlabeled internal node
        tr = DndParser("(B:0.2,(C:0.3,D:0.4):0.6)F;")
        tr.asciiArt(show_internal=True, compact=False)
        tr.asciiArt(show_internal=True, compact=True)
        tr.asciiArt(show_internal=False, compact=False)
开发者ID:carze,项目名称:clovr-base,代码行数:39,代码来源:test_tree2.py

示例2: __init__

# 需要导入模块: from cogent import LoadTree [as 别名]
# 或者: from cogent.LoadTree import asciiArt [as 别名]

#.........这里部分代码省略.........

    def getLongestEvoDistance(self):
        longestDistance = 0.0

        for LeafKey in self.FastMLTree.LeafKey_L:

            distance = self.getEvoDistance(LeafKey)

            if distance > longestDistance:
                longestDistance = distance

        return longestDistance

    "modifies evolutionary distance into a different format"

    def modEvoDistance(self):
        Ret = {}

        for Key in self.EvoDistance_D.keys():
            if Key == self.FastMLTree.TopKey:
                Ret[Key] = self.EvoDistance_D[Key]

            else:
                if self.EvoDistance_D[Key] == 0:
                    Ret[Key] = self.EvoDistance_D[Key]
                else:
                    Ret[Key] = self.EvoDistance_D[Key]
        return Ret

    "sets tree node coordinates (horizontal and vertical) for the SVG image"

    def setTreeCoords(self):

        Lines_L = self.CogentTree.asciiArt().split("\n")
        MaxVert = 0
        VertCoord_D = {}

        for i in range(0, len(Lines_L)):

            if re.compile("[a-zA-Z0-9_\[email protected]]+").search(Lines_L[i]):
                Leaves = re.findall("([a-zA-Z0-9_\[email protected]]+)", Lines_L[i])

                for Leaf in Leaves:

                    VertCoord_D[Leaf] = i
                    MaxVert = i

        TreeCoords_D = {
            Key: [(self.ModdedEvoDistance_D[Key] / self.LongestDistance) *
                  self.TreeFigWIDTH + self.TreeFigXOffset,
                  float(float(VertCoord_D[Key]) / float(MaxVert)) *
                  self.TreeFigHEIGHT + self.TreeFigYOffset]
            for Key in self.NodeToSeq_D.keys()
        }
        return TreeCoords_D

    "adds node names at each node vertex"

    def addNodeNamesAtNodePoints(self):
        for Key in self.FastMLTree.LeafKey_L:

            xy = self.TreeCoords_D[Key]
            xStart = str(xy[0])
            yStart = str(xy[1])
            self.FigureSVG_D["TreeAndStates"].append(
                '''\t<text x='%s' y='%s' text-anchor='left' font-size='20' font-family='Courier' style="fill: #000000;"  >%s</text>'''
开发者ID:JeremyBAdams,项目名称:Adaptation3D,代码行数:70,代码来源:exploreprediction.py


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