本文整理汇总了Python中qiime.parse.parse_newick函数的典型用法代码示例。如果您正苦于以下问题:Python parse_newick函数的具体用法?Python parse_newick怎么用?Python parse_newick使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_newick函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_setup_master_tree_alltips
def test_setup_master_tree_alltips(self):
"""tests setup_master_tree"""
master_tree = parse_newick("((a:2,b:3):2,(c:1,d:2)foo:7);")
t1 = parse_newick("((a:6,b:8.2):2,(c:1,d:2):7);") # same structure
t2 = parse_newick("((a:2,b:3,c:33):2,d:7);") # abc are siblings
support_tree_tipnames = ["a", "b", "c", "d"]
exp = "((a:2.0,b:3.0)node1:2.0,(c:1.0,d:2.0)foo:7.0)node0;"
new_master = tc.setup_master_tree(master_tree, [t1, t2])
self.assertEqual(new_master.getNewick(with_distances=True), exp)
desc_tips_root = frozenset(["a", "b", "c", "d"])
desc_tips_c0 = frozenset(["a", "b"])
desc_tips_c1 = frozenset(["c", "d"])
desc_tips_c0c0 = frozenset(["a"])
desc_tips_c0c1 = frozenset(["b"])
desc_tips_c1c0 = frozenset(["c"])
desc_tips_c1c1 = frozenset(["d"])
self.assertEqual(frozenset(new_master.getTipNames()), desc_tips_root)
self.assertEqual(frozenset(new_master.Children[0].getTipNames()), desc_tips_c0)
self.assertEqual(frozenset(new_master.Children[1].getTipNames()), desc_tips_c1)
c0 = master_tree.Children[0]
c1 = master_tree.Children[1]
self.assertEqual(frozenset(c0.Children[0].getTipNames()), desc_tips_c0c0)
self.assertEqual(frozenset(c0.Children[1].getTipNames()), desc_tips_c0c1)
self.assertEqual(frozenset(c1.Children[0].getTipNames()), desc_tips_c1c0)
self.assertEqual(frozenset(c1.Children[1].getTipNames()), desc_tips_c1c1)
示例2: test_setup_master_tree_missingtips
def test_setup_master_tree_missingtips(self):
"""tests setup_master_tree"""
master_tree = parse_newick('((a:2,b:3):2,(c:1,d:2)foo:7);')
t1 = parse_newick('((a:6,b:8.2):2,(c:1,d:2):7);') # same structure
t2 = parse_newick('((a:2,c:33):2,d:7);') # where's b?
support_tree_tipnames = ['a', 'c', 'd']
exp = "((c:1.0,d:2.0)foo:7.0,a:4.0)node0;"
new_master = tc.setup_master_tree(master_tree, [t1, t2])
self.assertEqual(new_master.getNewick(with_distances=True), exp)
desc_tips_root = frozenset(['a', 'c', 'd'])
desc_tips_c1 = frozenset(['a'])
desc_tips_c0 = frozenset(['c', 'd'])
desc_tips_c0c0 = frozenset(['c'])
desc_tips_c0c1 = frozenset(['d'])
self.assertEqual(frozenset(new_master.getTipNames()), desc_tips_root)
self.assertEqual(
frozenset(new_master.Children[0].getTipNames()),
desc_tips_c0)
self.assertEqual(
frozenset(new_master.Children[1].getTipNames()),
desc_tips_c1)
c0 = new_master.Children[0]
self.assertEqual(
frozenset(c0.Children[0].getTipNames()),
desc_tips_c0c0)
self.assertEqual(
frozenset(c0.Children[1].getTipNames()),
desc_tips_c0c1)
示例3: setUp
def setUp(self):
"""Set up some test variables"""
self.newick = "((s1:0.2,s2:0.2):0.6,s3:0.8);"
self.tree = parse_newick(self.newick, PhyloNode)
self.newick_scaled = "((s1:25,s2:25):75,s3:100);"
self.tree_scaled = parse_newick(self.newick_scaled, PhyloNode)
self.tree_scaled.scaleBranchLengths(max_length=100, ultrametric=True)
self.num_trees_considered = 10
self.trans_values = {(None, None) : ("#FFFFFF", ""),
(None, 0.5): ("#dddddd", "< 50%"),
(0.5, 0.7): ("#99CCFF", "50-70%"),
(0.7, 0.9): ("#82FF8B", "70-90%"),
(0.9, 0.999): ("#F8FE83", "90-99.9%"),
(0.999, None): ("#FF8582", "> 99.9%")}
self.jack_newick = "((s1:0.2,s2:0.2)0.8:0.6,s3:0.8)1.0;"
self.jack_tree = parse_newick(self.jack_newick, PhyloNode)
self.jack_newick_scaled = "((s1:25,s2:25)0.8:75,s3:100)1.0;"
self.jack_tree_scaled = parse_newick(self.jack_newick_scaled, PhyloNode)
self.jack_tree_scaled.scaleBranchLengths(max_length=100,
ultrametric=True)
self.support = { 'trees_considered': 10,
'support_dict': {"node0":1.0,
"node1":0.8}}
self.qiime_config = load_qiime_config()
self.tmp_dir = self.qiime_config['temp_dir'] or '/tmp/'
self.output_file = get_tmp_filename(tmp_dir = self.tmp_dir)
dict_mapping_data = {}
dict_mapping_data["s1"] = {
'Description':'s1 test description',
'NumIndividuals':'100',
'BarcodeSequence':'AAAAAAAAAACT',
'LinkerPrimerSequence':'AAAAAAAAAAAAAAAAAAAAA',
'ExampleHeader1':'Value1',
'ExampleHeader2':'Val2'}
dict_mapping_data["s2"] = {
'Description':'s2 test description',
'NumIndividuals':'200',
'BarcodeSequence':'CAAAAAAAAACT',
'LinkerPrimerSequence':'AAAAAAAAAAAAAAAAAAAAA',
'ExampleHeader1':'Value2',
'ExampleHeader2':'Val1'}
dict_mapping_data["s3"] = {
'Description':'s3 test description',
'NumIndividuals':'300',
'BarcodeSequence':'GAAAAAAAAACT',
'LinkerPrimerSequence':'AAAAAAAAAAAAAAAAAAAAA',
'ExampleHeader1':'Value2',
'ExampleHeader2':'Val3'}
self.mapping_data = [dict_mapping_data,
"Example comment string for test"]
self._paths_to_clean_up = []
示例4: setUp
def setUp(self):
"""Define some test data."""
self.qiime_config = load_qiime_config()
self.dirs_to_remove = []
self.tmp_dir = self.qiime_config['temp_dir'] or '/tmp/'
if not exists(self.tmp_dir):
makedirs(self.tmp_dir)
# if test creates the temp dir, also remove it
self.dirs_to_remove.append(self.tmp_dir)
self.otu_table1 = table_factory(data=array([[2, 0, 0, 1],
[1, 1, 1, 1],
[0, 0, 0, 0]]).T,
sample_ids=list('XYZ'),
observation_ids=list('abcd'),
constructor=DenseOTUTable)
fd, self.otu_table1_fp = mkstemp(dir=self.tmp_dir,
prefix='alpha_diversity_tests',
suffix='.biom')
close(fd)
open(self.otu_table1_fp, 'w').write(
format_biom_table(self.otu_table1))
self.otu_table2 = table_factory(data=array([[2, 0, 0, 1],
[1, 1, 1, 1],
[0, 0, 0, 0]]).T,
sample_ids=list('XYZ'),
observation_ids=['a', 'b', 'c', 'd_'],
constructor=DenseOTUTable)
fd, self.otu_table2_fp = mkstemp(dir=self.tmp_dir,
prefix='alpha_diversity_tests',
suffix='.biom')
close(fd)
open(self.otu_table2_fp, 'w').write(
format_biom_table(self.otu_table2))
self.single_sample_otu_table = table_factory(
data=array([[2, 0, 0, 1]]).T,
sample_ids=list('X'),
observation_ids=list(
'abcd'),
constructor=DenseOTUTable)
fd, self.single_sample_otu_table_fp = mkstemp(
dir=self.tmp_dir,
prefix='alpha_diversity_tests',
suffix='.biom')
close(fd)
open(self.single_sample_otu_table_fp, 'w').write(
format_biom_table(self.single_sample_otu_table))
self.tree1 = parse_newick('((a:2,b:3):2,(c:1,d:2):7);')
self.tree2 = parse_newick("((a:2,'b':3):2,(c:1,'d_':2):7);")
self.files_to_remove = [self.otu_table1_fp, self.otu_table2_fp,
self.single_sample_otu_table_fp]
示例5: test_tree_support
def test_tree_support(self):
""" tree_support should correctly modify node.bootstrap_support
"""
master_tree = parse_newick("((a:2,b:3)ab:2,(c:1,d:2)cd:7)rt;")
"""
/-------.5 /-a
---1| \-b
\------.5 /-c
\-d
"""
t2 = parse_newick("((a:2,b:3,c:33)ho:2,d:7);") # abc are siblings
tc.tree_support(master_tree, t2)
self.assertFloatEqual(master_tree.getNodeMatchingName("rt").bootstrap_support, 1.0)
示例6: load_tree_files
def load_tree_files(master_tree_file, support_dir):
"""Load trees from filepaths
checks if support filenames indicate that support are from different
distance methods. If so, warns user.
loads trees into phylonode objects
returns master_tree, [support_trees]
raises a RuntimeError if no support trees are loaded
"""
tree_file_names = os.listdir(support_dir)
# ignore invisible files like .DS_Store
tree_file_names = [
fname for fname in tree_file_names if not fname.startswith('.')
]
# try to warn user if using multiple types of trees
try:
base_names = []
for fname in tree_file_names:
base_names.append(qiime.parse.parse_rarefaction_fname(fname)[0])
except ValueError:
pass
else:
if len(set(base_names)) > 1:
warnstr = """
warning: support trees are named differently, please be sure you're not
comparing trees generated in different manners, unless you're quite sure
that's what you intend to do. types: """ + str(set(base_names)) + """
continuing anyway..."""
warn(warnstr)
master_tree = parse_newick(open(master_tree_file, 'U'), PhyloNode)
support_trees = []
for fname in tree_file_names:
try:
f = open(os.path.join(support_dir, fname), 'U')
tree = parse_newick(f, PhyloNode)
tree.filepath = fname
support_trees.append(tree)
f.close()
except IOError as err:
sys.stderr.write('error loading support tree ' + fname + '\n')
exit(1)
if len(support_trees) == 0:
raise RuntimeError(
'Error: no support trees loaded' +
', check that support tree directory has has valid trees')
return master_tree, support_trees
示例7: test_bootstrap_support
def test_bootstrap_support(self):
""" bootstrap_support should have correct bootstrap for a tree with
unlabeled internal nodes
"""
master_tree = parse_newick("((a:2,b:3):2,(c:1,d:2):7);")
"""
/-------.5 /-a
---1| \-b
\------.5 /-c
\-d
"""
t1 = parse_newick("((a:6,b:8.2):2,(c:1,d:2):7);") # same structure
t2 = parse_newick("((a:2,b:3,c:33):2,d:7);") # abc are siblings
new_master, bootstraps = tc.bootstrap_support(master_tree, [t1, t2])
self.assertFloatEqual(sorted(bootstraps.values()), sorted([1.0, 0.5, 0.5]))
示例8: main
def main():
option_parser, opts, args = parse_command_line_parameters(**script_info)
output_fp = opts.output_fp
if output_fp:
fd = open(output_fp, "w")
else:
fd = stdout
tr = parse_newick(open(opts.tree_fp), PhyloNode)
# all_nodes is list node objs
tip_dists, all_nodes = tr.tipToTipDistances()
all_ids = [node.Name for node in all_nodes]
o = open(opts.taxa_fp)
group_ids = [i.strip() for i in o.readline().split(",")]
o.close()
# check that there are at least 2 ids in the group, otherwise the math
# fails
if len(group_ids) < 2:
option_parser.error(
"Not enough taxa in the taxa file.You must have "
"at least 2 taxa specified in the taxa file or "
"the standard deviation of the distance will be "
"zero, causing both NRI and NTI to fail."
)
# check that all_ids contains every group_id
if not set(group_ids).issubset(all_ids):
raise option_parser.error(
"There are taxa in the taxa file which are "
"not found in the tree. You may have "
"specified an internal node."
)
# check that all_ids != group_ids
if len(all_ids) == len(group_ids): # must be same set if above passes
option_parser.error(
"The taxa_ids you specified contain every tip in "
"the tree. The NRI and NTI formulas will fail "
"because there is no standard deviation of mpd or "
"mntd, and thus division by zero. In addition, "
"the concept of over/under dispersion of a group "
"of taxa (what NRI/NTI measure) is done in "
"reference to the tree they are a part of. If the "
"group being tested is the entire tree, the idea "
"of over/under dispersion makes little sense."
)
# mapping from string of method name to function handle
method_lookup = {"nri": nri, "nti": nti}
methods = opts.methods
for method in methods:
if method not in method_lookup:
option_parser.error("Unknown method: %s; valid methods are: %s" % (method, ", ".join(method_lookup.keys())))
for method in methods:
print >> fd, method + ":", method_lookup[method](tip_dists, all_ids, group_ids, iters=opts.iters)
fd.close()
示例9: get_order_from_tree
def get_order_from_tree(ids, tree_text):
"""Returns the indices that would sort ids by tree tip order"""
tree = parse_newick(tree_text, PhyloNode)
ordered_ids = []
for tip in tree.iterTips():
if tip.Name in ids:
ordered_ids.append(tip.Name)
return names_to_indices(ids, ordered_ids)
示例10: test_bootstrap_support_labeled
def test_bootstrap_support_labeled(self):
""" bootstrap_support should have correct bootstrap on a tree
with labeled internal nodes
"""
master_tree = parse_newick('((a:2,b:3)ab:2,(c:1,d:2)cd:7)rt;')
"""
/-------.5 /-a
---1| \-b
\------.5 /-c
\-d
"""
t1 = parse_newick('((a:6,b:8.2)hi:2,(c:1,d:2):7);') # same structure
t2 = parse_newick('((a:2,b:3,c:33)ho:2,d:7);') # abc are siblings
new_master, bootstraps = tc.bootstrap_support(master_tree, [t1, t2])
expected = dict([('ab', .5), ('cd', .5), ('rt', 1.0)])
self.assertDictEqual(bootstraps, expected)
示例11: main
def main():
option_parser, opts, args = parse_command_line_parameters(**script_info)
tree = parse_newick(open(opts.master_tree, 'U'))
support_file = open(opts.support)
bootstraps = parse_bootstrap_support(support_file)
support_file.close()
write_pdf_bootstrap_tree(tree, opts.output_file, bootstraps)
示例12: setUp
def setUp(self):
"""Define some test data."""
self.qiime_config = load_qiime_config()
self.dirs_to_remove = []
self.tmp_dir = self.qiime_config["temp_dir"] or "/tmp/"
if not exists(self.tmp_dir):
makedirs(self.tmp_dir)
# if test creates the temp dir, also remove it
self.dirs_to_remove.append(self.tmp_dir)
self.otu_table1 = table_factory(
data=array([[2, 0, 0, 1], [1, 1, 1, 1], [0, 0, 0, 0]]).T,
sample_ids=list("XYZ"),
observation_ids=list("abcd"),
constructor=DenseOTUTable,
)
self.otu_table1_fp = get_tmp_filename(
tmp_dir=self.tmp_dir, prefix="alpha_diversity_tests", suffix=".biom", result_constructor=str
)
open(self.otu_table1_fp, "w").write(format_biom_table(self.otu_table1))
self.otu_table2 = table_factory(
data=array([[2, 0, 0, 1], [1, 1, 1, 1], [0, 0, 0, 0]]).T,
sample_ids=list("XYZ"),
observation_ids=["a", "b", "c", "d_"],
constructor=DenseOTUTable,
)
self.otu_table2_fp = get_tmp_filename(
tmp_dir=self.tmp_dir, prefix="alpha_diversity_tests", suffix=".biom", result_constructor=str
)
open(self.otu_table2_fp, "w").write(format_biom_table(self.otu_table2))
self.single_sample_otu_table = table_factory(
data=array([[2, 0, 0, 1]]).T, sample_ids=list("X"), observation_ids=list("abcd"), constructor=DenseOTUTable
)
self.single_sample_otu_table_fp = get_tmp_filename(
tmp_dir=self.tmp_dir, prefix="alpha_diversity_tests", suffix=".biom", result_constructor=str
)
open(self.single_sample_otu_table_fp, "w").write(format_biom_table(self.single_sample_otu_table))
self.tree1 = parse_newick("((a:2,b:3):2,(c:1,d:2):7);")
self.tree2 = parse_newick("((a:2,'b':3):2,(c:1,'d_':2):7);")
self.files_to_remove = [self.otu_table1_fp, self.otu_table2_fp, self.single_sample_otu_table_fp]
示例13: setUp
def setUp(self):
self.qiime_config = load_qiime_config()
self.tmp_dir = self.qiime_config['temp_dir'] or '/tmp/'
self.l19_data = np.array([
[7, 1, 0, 0, 0, 0, 0, 0, 0],
[4, 2, 0, 0, 0, 1, 0, 0, 0],
[2, 4, 0, 0, 0, 1, 0, 0, 0],
[1, 7, 0, 0, 0, 0, 0, 0, 0],
[0, 8, 0, 0, 0, 0, 0, 0, 0],
[0, 7, 1, 0, 0, 0, 0, 0, 0],
[0, 4, 2, 0, 0, 0, 2, 0, 0],
[0, 2, 4, 0, 0, 0, 1, 0, 0],
[0, 1, 7, 0, 0, 0, 0, 0, 0],
[0, 0, 8, 0, 0, 0, 0, 0, 0],
[0, 0, 7, 1, 0, 0, 0, 0, 0],
[0, 0, 4, 2, 0, 0, 0, 3, 0],
[0, 0, 2, 4, 0, 0, 0, 1, 0],
[0, 0, 1, 7, 0, 0, 0, 0, 0],
[0, 0, 0, 8, 0, 0, 0, 0, 0],
[0, 0, 0, 7, 1, 0, 0, 0, 0],
[0, 0, 0, 4, 2, 0, 0, 0, 4],
[0, 0, 0, 2, 4, 0, 0, 0, 1],
[0, 0, 0, 1, 7, 0, 0, 0, 0]
])
self.l19_sample_names = [
'sam1', 'sam2', 'sam3', 'sam4', 'sam5', 'sam6',
'sam7', 'sam8', 'sam9', 'sam_middle', 'sam11', 'sam12', 'sam13',
'sam14', 'sam15', 'sam16', 'sam17', 'sam18', 'sam19']
self.l19_taxon_names = ['tax1', 'tax2', 'tax3', 'tax4', 'endbigtaxon',
'tax6', 'tax7', 'tax8', 'tax9']
self.l19_taxon_names_w_underscore = ['ta_x1', 'tax2', 'tax3', 'tax4',
'endbigtaxon', 'tax6', 'tax7',
'tax8', 'tax9']
l19 = Table(self.l19_data.T, self.l19_taxon_names,
self.l19_sample_names)
fd, self.l19_fp = mkstemp(dir=self.tmp_dir,
prefix='test_bdiv_otu_table', suffix='.blom')
os.close(fd)
write_biom_table(l19, self.l19_fp)
l19_w_underscore = Table(self.l19_data.T,
self.l19_taxon_names_w_underscore,
self.l19_sample_names)
fd, self.l19_w_underscore_fp = mkstemp(dir=self.tmp_dir,
prefix='test_bdiv_otu_table',
suffix='.blom')
os.close(fd)
write_biom_table(l19_w_underscore, self.l19_w_underscore_fp)
self.l19_tree_str = '((((tax7:0.1,tax3:0.2):.98,tax8:.3, tax4:.3):.4,\
((tax1:0.3, tax6:.09):0.43,tax2:0.4):0.5):.2, (tax9:0.3, endbigtaxon:.08));'
self.l19_tree = parse_newick(self.l19_tree_str, PhyloNode)
self.files_to_remove = [self.l19_fp, self.l19_w_underscore_fp]
self.folders_to_remove = []
示例14: setUp
def setUp(self):
"""Define some test data."""
self.tmp_dir = get_qiime_temp_dir()
self.otu_table1 = Table(data=array([[2, 0, 0, 1],
[1, 1, 1, 1],
[0, 0, 0, 0]]).T,
sample_ids=list('XYZ'),
observation_ids=list('abcd'))
fd, self.otu_table1_fp = mkstemp(dir=self.tmp_dir,
prefix='alpha_diversity_tests',
suffix='.biom')
close(fd)
write_biom_table(self.otu_table1, self.otu_table1_fp)
self.otu_table2 = Table(data=array([[2, 0, 0, 1],
[1, 1, 1, 1],
[0, 0, 0, 0]]).T,
sample_ids=list('XYZ'),
observation_ids=['a', 'b', 'c', 'd_'])
fd, self.otu_table2_fp = mkstemp(dir=self.tmp_dir,
prefix='alpha_diversity_tests',
suffix='.biom')
close(fd)
write_biom_table(self.otu_table2, self.otu_table2_fp)
self.single_sample_otu_table = Table(
data=array([[2, 0, 0, 1]]).T,
sample_ids=list('X'),
observation_ids=list(
'abcd'))
fd, self.single_sample_otu_table_fp = mkstemp(
dir=self.tmp_dir,
prefix='alpha_diversity_tests',
suffix='.biom')
close(fd)
write_biom_table(self.single_sample_otu_table,
self.single_sample_otu_table_fp)
self.tree1 = parse_newick('((a:2,b:3):2,(c:1,d:2):7);')
self.tree2 = parse_newick("((a:2,'b':3):2,(c:1,'d_':2):7);")
self.files_to_remove = [self.otu_table1_fp, self.otu_table2_fp,
self.single_sample_otu_table_fp]
示例15: test_write_pdf_bootstrap_tree
def test_write_pdf_bootstrap_tree(self):
""" write_pdf_bootstrap_tree should throw no errors"""
tree = parse_newick("((tax7:0.1,tax3:0.2)node0:.98,tax8:.3, tax4:.3)node1:.4", PhyloNode)
bootstraps = {"node0": 0.7, "node1": 0.4}
fd, f = mkstemp(prefix="make_bootstrapped_tree_test", suffix=".pdf")
close(fd)
self._paths_to_clean_up.append(f)
write_pdf_bootstrap_tree(tree, f, bootstraps)
assert os.path.exists(f)