本文整理汇总了Python中cogent.parse.tree.DndParser.deepcopy方法的典型用法代码示例。如果您正苦于以下问题:Python DndParser.deepcopy方法的具体用法?Python DndParser.deepcopy怎么用?Python DndParser.deepcopy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cogent.parse.tree.DndParser
的用法示例。
在下文中一共展示了DndParser.deepcopy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestMakeTestTrees
# 需要导入模块: from cogent.parse.tree import DndParser [as 别名]
# 或者: from cogent.parse.tree.DndParser import deepcopy [as 别名]
class TestMakeTestTrees(TestCase):
"""Tests of make_test_trees.py"""
def setUp(self):
self.SimpleTree = \
DndParser("((A:0.02,B:0.01)E:0.05,(C:0.01,D:0.01)F:0.05)root;")
self.SimplePolytomyTree = \
DndParser("((A:0.02,B:0.01,B_prime:0.03)E:0.05,(C:0.01,D:0.01)F:0.05)root;")
def test_exclude_tip(self):
"""exclude_tip should yield a holdout tree"""
#Try excluding tip 'B'
test_tree = self.SimpleTree.deepcopy()
obs = exclude_tip(test_tree.getNodeMatchingName('B'),test_tree)
obs_newick = obs.getNewick(with_distances=True)
exp_newick = "((C:0.01,D:0.01)F:0.05,A:0.07)root;"
self.assertEqual(obs_newick,exp_newick)
#Make sure the holdout works with a polytomy
test_tree = self.SimplePolytomyTree.deepcopy()
obs = exclude_tip(test_tree.getNodeMatchingName('B'),test_tree)
obs_newick = obs.getNewick(with_distances=True)
exp_newick = "((A:0.02,'B_prime':0.03)E:0.05,(C:0.01,D:0.01)F:0.05)root;"
self.assertEqual(obs_newick,exp_newick)
#Make sure we raise if the tip is invalid
test_tree = self.SimpleTree.deepcopy()
self.assertRaises(ValueError,exclude_tip,\
test_tree.getNodeMatchingName('E'),test_tree)
def test_make_distance_based_exclusion_fn(self):
"""make_distance_based_exclusion_fn should return a working function"""
exclude_similar_strains =\
make_distance_based_exclusion_fn(0.03)
#Test that the function works
test_tree = self.SimpleTree.deepcopy()
#print test_tree.getNewick(with_distances=True)
tip = test_tree.getNodeMatchingName('C')
obs = exclude_similar_strains(tip,test_tree).getNewick(with_distances=True)
exp = "((A:0.02,B:0.01)E:0.05,C:0.06)root;"
self.assertEqual(obs,exp)
#Test that new function is documented
exp_doc = 'Exclude neighbors of tip within 0.030000 branch length units'
self.assertEqual(exp_doc,exclude_similar_strains.__doc__)
#Test that we raise if distance is too large
test_tree = self.SimpleTree.deepcopy()
test_fn = make_distance_based_exclusion_fn(300.0)
tip = test_tree.getNodeMatchingName('C')
self.assertRaises(ValueError,test_fn,tip,test_tree)
def make_distance_based_randomizer(self):
"""make_distance_based_randomizer should randomize tip labels iwthin d"""
tip_randomizer =\
make_distance_based_tip_label_randomizer(0.08)
#Test that the function works
test_tree = self.SimpleTree.deepcopy()
print test_tree.asciiArt()
tip = test_tree.getNodeMatchingName('C')
obs = tip_randomizer(tip,test_tree).getNewick(with_distances=True)
print "OBS:",obs.asciiArt()
# TODO: finish this test!
def test_yield_test_trees(self):
"""yield_test_trees should yield modified test trees"""
# Test with simple tree and exclude_tip
start_tree = self.SimpleTree.deepcopy()
obs = yield_test_trees(start_tree, exclude_tip)
test_trees = [tree for tree in obs]
#Test that each tree excludes the correct tip
for i,exp_tip in enumerate(start_tree.tips()):
node_names = [obs_tip.Name for obs_tip in test_trees[i].tips()]
self.assertTrue(exp_tip not in node_names)
#Test that the topology is correct
self.assertEqual(test_trees[1].getNewick(with_distances=True),\
"((C:0.01,D:0.01)F:0.05,A:0.07)root;")
示例2: TestMakeTestTrees
# 需要导入模块: from cogent.parse.tree import DndParser [as 别名]
# 或者: from cogent.parse.tree.DndParser import deepcopy [as 别名]
class TestMakeTestTrees(TestCase):
"""Tests of make_test_trees.py"""
def setUp(self):
self.SimpleTree = \
DndParser("((A:0.02,B:0.01)E:0.05,(C:0.01,D:0.01)F:0.05)root;")
self.SimplePolytomyTree = \
DndParser("((A:0.02,B:0.01,B_prime:0.03)E:0.05,(C:0.01,D:0.01)F:0.05)root;")
def test_exclude_tip(self):
"""exclude_tip should yield a holdout tree"""
#Try excluding tip 'B'
test_tree = self.SimpleTree.deepcopy()
obs = exclude_tip(test_tree.getNodeMatchingName('B'),test_tree)
obs_newick = obs.getNewick(with_distances=True)
exp_newick = "((C:0.01,D:0.01)F:0.05,A:0.07)root;"
alt_newick = "(A:0.07,(C:0.01,D:0.01)F:0.05)root;"
#exp_newick and alt_newick represent
#two ways of expressing the same tree
self.assertTrue(obs_newick in [exp_newick,alt_newick])
#Make sure the holdout works with a polytomy
test_tree = self.SimplePolytomyTree.deepcopy()
obs = exclude_tip(test_tree.getNodeMatchingName('B'),test_tree)
obs_newick = obs.getNewick(with_distances=True)
exp_newick = "((A:0.02,'B_prime':0.03)E:0.05,(C:0.01,D:0.01)F:0.05)root;"
self.assertEqual(obs_newick,exp_newick)
#Make sure we raise if the tip is invalid
test_tree = self.SimpleTree.deepcopy()
self.assertRaises(ValueError,exclude_tip,\
test_tree.getNodeMatchingName('E'),test_tree)
def test_make_distance_based_exclusion_fn(self):
"""make_distance_based_exclusion_fn should return a working function"""
exclude_similar_strains =\
make_distance_based_exclusion_fn(0.03)
#Test that new function is documented
exp_doc = 'Exclude neighbors of tip within 0.030000 branch length units'
self.assertEqual(exp_doc,exclude_similar_strains.__doc__)
#Test that the function works
test_tree = self.SimpleTree.deepcopy()
#print test_tree.getNewick(with_distances=True)
tip = test_tree.getNodeMatchingName('C')
obs = exclude_similar_strains(tip,test_tree).getNewick(with_distances=True)
exp = "(A:0.02,B:0.01)root;"
self.assertEqual(obs,exp)
#Test on a tree where a single node will remain
test_tree = \
DndParser("((A:0.02,B:0.01)E:0.05,(C:0.06,D:0.01)F:0.05)root;")
#print test_tree.getNewick(with_distances=True)
tip = test_tree.getNodeMatchingName('D')
obs = exclude_similar_strains(tip,test_tree).getNewick(with_distances=True)
exp = "((A:0.02,B:0.01)E:0.05,C:0.11)root;"
self.assertEqual(obs,exp)
#Test that we raise if distance is too large
test_tree = self.SimpleTree.deepcopy()
test_fn = make_distance_based_exclusion_fn(300.0)
tip = test_tree.getNodeMatchingName('C')
self.assertRaises(ValueError,test_fn,tip,test_tree)
def test_make_distance_based_randomizer(self):
"""make_distance_based_randomizer should randomize tip labels wthin d. NOTE: results are tested by cumulative binomial distribution, so ~1/500 test runs may fail stochasitically."""
tip_randomizer =\
make_distance_based_tip_label_randomizer(0.50)
#Test that the function works
test_replicates = 5000
results = defaultdict(int)
total = 0
for i in range(test_replicates):
test_tree = self.SimpleTree.deepcopy()
#print test_tree.asciiArt()
tip = test_tree.getNodeMatchingName('C')
obs = tip_randomizer(tip,test_tree)
obs_newick = obs.getNewick(with_distances=True)
#print obs.asciiArt()
results[obs_newick]+= 1
total += 1
n_unique_trees = len(results.keys())
#Since only the 4 tips are scrambled
#.........这里部分代码省略.........
示例3: TestMakeTestTrees
# 需要导入模块: from cogent.parse.tree import DndParser [as 别名]
# 或者: from cogent.parse.tree.DndParser import deepcopy [as 别名]
class TestMakeTestTrees(TestCase):
"""Tests of make_test_trees.py"""
def setUp(self):
self.SimpleTree = \
DndParser("((A:0.02,B:0.01)E:0.05,(C:0.01,D:0.01)F:0.05)root;")
self.SimplePolytomyTree = \
DndParser("((A:0.02,B:0.01,B_prime:0.03)E:0.05,(C:0.01,D:0.01)F:0.05)root;")
def test_exclude_tip(self):
"""exclude_tip should yield a holdout tree"""
#Try excluding tip 'B'
test_tree = self.SimpleTree.deepcopy()
obs = exclude_tip(test_tree.getNodeMatchingName('B'),test_tree)
obs_newick = obs.getNewick(with_distances=True)
exp_newick = "((C:0.01,D:0.01)F:0.05,A:0.07)root;"
self.assertEqual(obs_newick,exp_newick)
#Make sure the holdout works with a polytomy
test_tree = self.SimplePolytomyTree.deepcopy()
obs = exclude_tip(test_tree.getNodeMatchingName('B'),test_tree)
obs_newick = obs.getNewick(with_distances=True)
exp_newick = "((A:0.02,'B_prime':0.03)E:0.05,(C:0.01,D:0.01)F:0.05)root;"
self.assertEqual(obs_newick,exp_newick)
#Make sure we raise if the tip is invalid
test_tree = self.SimpleTree.deepcopy()
self.assertRaises(ValueError,exclude_tip,\
test_tree.getNodeMatchingName('E'),test_tree)
def test_make_distance_based_exclusion_fn(self):
"""make_distance_based_exclusion_fn should return a working function"""
exclude_similar_strains =\
make_distance_based_exclusion_fn(0.03)
#Test that new function is documented
exp_doc = 'Exclude neighbors of tip within 0.030000 branch length units'
self.assertEqual(exp_doc,exclude_similar_strains.__doc__)
#Test that the function works
test_tree = self.SimpleTree.deepcopy()
#print test_tree.getNewick(with_distances=True)
tip = test_tree.getNodeMatchingName('C')
obs = exclude_similar_strains(tip,test_tree).getNewick(with_distances=True)
exp = "(A:0.02,B:0.01)root;"
self.assertEqual(obs,exp)
#Test on a tree where a single node will remain
test_tree = \
DndParser("((A:0.02,B:0.01)E:0.05,(C:0.06,D:0.01)F:0.05)root;")
#print test_tree.getNewick(with_distances=True)
tip = test_tree.getNodeMatchingName('D')
obs = exclude_similar_strains(tip,test_tree).getNewick(with_distances=True)
exp = "((A:0.02,B:0.01)E:0.05,C:0.11)root;"
self.assertEqual(obs,exp)
#Test that we raise if distance is too large
test_tree = self.SimpleTree.deepcopy()
test_fn = make_distance_based_exclusion_fn(300.0)
tip = test_tree.getNodeMatchingName('C')
self.assertRaises(ValueError,test_fn,tip,test_tree)
def make_distance_based_randomizer(self):
"""make_distance_based_randomizer should randomize tip labels iwthin d"""
tip_randomizer =\
make_distance_based_tip_label_randomizer(0.08)
#Test that the function works
test_tree = self.SimpleTree.deepcopy()
print test_tree.asciiArt()
tip = test_tree.getNodeMatchingName('C')
obs = tip_randomizer(tip,test_tree).getNewick(with_distances=True)
print "OBS:",obs.asciiArt()
# TODO: finish this test!
def test_yield_test_trees(self):
"""yield_test_trees should yield modified test trees"""
start_tree = self.SimpleTree.deepcopy()
# First, test with simple tree and exclude_tip
# (not a typical use, but easy to predict
# and still important to test)
#.........这里部分代码省略.........