本文整理汇总了Python中cogent.parse.tree.DndParser.getSubTree方法的典型用法代码示例。如果您正苦于以下问题:Python DndParser.getSubTree方法的具体用法?Python DndParser.getSubTree怎么用?Python DndParser.getSubTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cogent.parse.tree.DndParser
的用法示例。
在下文中一共展示了DndParser.getSubTree方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_getsubtree
# 需要导入模块: from cogent.parse.tree import DndParser [as 别名]
# 或者: from cogent.parse.tree.DndParser import getSubTree [as 别名]
def test_getsubtree(self):
"""testing getting a subtree
"""
otu_names = ['NineBande', 'Mouse', 'HowlerMon', 'DogFaced']
newick = '(((Human,HowlerMon),Mouse),NineBande,DogFaced);'
newick_reduced = '((Mouse,HowlerMon),NineBande,DogFaced);'
tree = DndParser(newick, constructor = PicrustNode)
subtree = tree.getSubTree(otu_names)
new_tree = DndParser(newick_reduced, constructor = PicrustNode)
# check we get the same names
self.assertEqual(*[len(t.Children) for t in (subtree,new_tree)])
self.assertEqual(subtree.getNewick(), new_tree.getNewick())
示例2: main
# 需要导入模块: from cogent.parse.tree import DndParser [as 别名]
# 或者: from cogent.parse.tree.DndParser import getSubTree [as 别名]
def main():
option_parser, opts, args = parse_command_line_parameters(**script_info)
input_tree_fp = opts.input_tree_fp
tips_fp = opts.tips_fp
fasta_fp = opts.fasta_fp
output_tree_fp = opts.output_tree_fp
if tips_fp != None:
tips_to_keep = get_seqs_to_keep_lookup_from_seq_id_file(open(tips_fp,'U'))
elif fasta_fp != None:
tips_to_keep = get_seqs_to_keep_lookup_from_fasta_file(open(fasta_fp,'U'))
else:
option_parser.error("Must provide either -t or -f.")
tree = DndParser(open(input_tree_fp,'U'))
if opts.negate:
tips_to_keep = negate_tips_to_keep(tips_to_keep, tree)
tree_out = tree.getSubTree(tips_to_keep)
tree_out.writeToFile(output_tree_fp)
示例3: test_cospeciation
# 需要导入模块: from cogent.parse.tree import DndParser [as 别名]
# 或者: from cogent.parse.tree.DndParser import getSubTree [as 别名]
#.........这里部分代码省略.........
print "Analyzing pOTU # " + cotu_basename
cotu_table_fp = cotu_basename + '_seqs_otu_table.txt'
basename = cotu_basename + "_" + test
# Read in cOTU file
try:
cotu_file = open(cotu_table_fp, 'Ur')
except:
print "is this a real file?"
# Reconcile hosts in host DM and cOTU table
filtered_cotu_file, host_dist_filtered = reconcile_hosts_symbionts(
cotu_file, host_dist)
cotu_file.close()
# Read in reconciled cOTU table
sample_names, taxon_names, data, lineages = parse_otu_table(
filtered_cotu_file)
filtered_cotu_file.close()
# exit loop if less than three hosts or cOTUs
if len(sample_names) < 3 or len(taxon_names) < 3:
print "Less than 3 hosts or cOTUs in cOTU table!"
continue
# Import, filter, and root cOTU tree
otu_tree_fp = cotu_basename + "_seqs_rep_set.tre"
otu_tree_file = open(otu_tree_fp, 'r')
otu_tree_unrooted = DndParser(otu_tree_file, PhyloNode)
otu_tree_file.close()
otu_subtree_unrooted = otu_tree_unrooted.getSubTree(
taxon_names)
# root at midpoint
# Consider alternate step to go through and find closest DB seq
# to root?
otu_subtree = otu_subtree_unrooted.rootAtMidpoint()
# filter host tree
host_subtree = host_tree.getSubTree(sample_names)
# Load up and filter cOTU sequences
aligned_otu_seqs = LoadSeqs(
cotu_basename + '_seqs_rep_set_aligned.fasta', moltype=DNA, label_to_name=lambda x: x.split()[0])
filtered_seqs = aligned_otu_seqs.takeSeqs(taxon_names)
result = False
# Run recursive test on this pOTU:
try:
# DEBUG:
# print 'in run_test_cospeciation'
# get number of hosts and cOTUs
htips = len(host_subtree.getTipNames())
stips = len(otu_subtree.getTipNames())
if test == 'unifrac':
print 'calling unifrac test'
results_dict, acc_dict = unifrac_recursive_test(host_subtree, otu_subtree, sample_names,
taxon_names, data, permutations)
pvals = 'p_vals'
if test == 'hommola_recursive':