本文整理汇总了Python中ete3.Tree.prune方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.prune方法的具体用法?Python Tree.prune怎么用?Python Tree.prune使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ete3.Tree
的用法示例。
在下文中一共展示了Tree.prune方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _compare
# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import prune [as 别名]
def _compare(self, newick, nodes):
nodes = [str(node) for node in nodes]
t1 = Tree(newick, format=1)
t1.prune(nodes, preserve_branch_length=True)
t2 = Tree(newick, format=1)
prune(t2, nodes, const_depth=False, keep_root=True)
self.assertEqual(t1.write(format=1), t2.write(format=1))
示例2: pruning
# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import prune [as 别名]
def pruning(inputtree, inputfasta, tree_outfilename):
#This function remove sequences from a FASTA from a larger tree
#Full initial tree - to be pruned
k = open(inputtree, "r").read()
#ete3 Tree format
f = Tree(inputtree)
#List of IDs to be picked from the full FASTA
IDlist=[]
fasta = open(inputfasta, "rU")
record_dict = SeqIO.to_dict(SeqIO.parse(fasta, "fasta"))
for recordID in record_dict.keys():
print recordID
IDlist.append(recordID)
print IDlist
tree_outfile=open(tree_outfilename, "w")
print "pruning...", inputfasta
f.prune(IDlist, preserve_branch_length=True)
f.write(format=0, outfile=tree_outfilename)
print "pruned", inputfasta
示例3: Tree
# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import prune [as 别名]
from ete3 import Tree
import argparse
pruneArgs=argparse.ArgumentParser()
pruneArgs.add_argument("-t","--tree", type=str)
pruneArgs.add_argument("-s","--species",nargs='+')
pruneArgs.add_argument("-o","--outFile", type=str)
args = pruneArgs.parse_args()
from ete3 import Tree
t = Tree(args.tree)
t.prune(args.species, preserve_branch_length=True)
t.write(outfile=args.outFile)
示例4:
# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import prune [as 别名]
for fasta in rec_dict[strain]:
concat_dict[strain]=concat_dict[strain]+str(fasta.seq)
#write out concatenated fasta
handle=open("all_concat.fasta", "w")
for rec in concat_dict:
handle.write(">"+rec+"\n"+concat_dict[rec]+"\n")
handle.close()
#SeqIO.write(list(SeqIO.parse(open("all_concat.fasta"), "fasta")), "all_concat.phy", "phylip")
#now write out tree
for node in tree_old.traverse():
if node.is_leaf():
temp=node.name.replace('p','plate')
node.name=temp
tree_old.prune(strains, preserve_branch_length=T)
write.tree(tree_old, "all_concat.newick", formatrue=1)
for leaf in collapsed.get_leaves():
temp=leaf.name.replace('p', 'plate').split("_")[0]
leaf.name=temp
collapsed.write(outfile="concat_107.newick", format=1)
test=subprocess(Popen(["/ebio/abt6_projects9/Pseudomonas_diversity/Programs/bin/ClonalFrameML", "/ebio/abt6_projects9/Pseudomonas_diversity/data/post_assembly_analysis/pan_genome/data/vis/clonalframe/concat_107.newick", "/ebio/abt6_projects9/Pseudomonas_diversity/data/post_assembly_analysis/pan_genome/data/vis/clonalframe/all_concat.fasta"]), stdout=subprocess.PIPE))
output = test.communicate()[0]
示例5: Counter
# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import prune [as 别名]
prune_count = Counter(children) #counter than contains the number of children that each terminal node has]
# print(parents)
# print(prune_list)
# print(prune_count)
# for key in prune_count.keys():
# # node_weight = ln(prune_count[key])
# # node_weight = ln(n_children)
# # print(node_weight,n_children)
# # node = lookup[key]
# node.add_features(weight=random.randint(50))
for n in t.traverse():
n.add_face(TextFace(n.name, fsize = 16), column=0, position="branch-bottom")
# n.add_features(weight=random.randint(0,20))
t.prune(prune_list)
# Create an empty TreeStyle
ts = TreeStyle()
# Set our custom layout function
ts.layout_fn = layout
# Draw a tree
# ts.mode = "c" # this makes it circular
# False need to add node names manually
ts.show_leaf_name = False
ts.scale = 120
# Show branch data
ts.show_branch_length = False
ts.show_branch_support = True
示例6:
# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import prune [as 别名]
# | | /-F
# /--------| \--------|
# | | \-I
# | |
# | \-E
#---------|
# | /-L
# | /--------|
# | | | /-N
# | | \--------|
# \--------| \-Q
# |
# | /-P
# \--------|
# \-S
# Prune the tree in order to keep only some leaf nodes.
t.prune(["H","F","E","Q", "P"])
print "Pruned tree"
print t
#
# /-F
# /--------|
# /--------| \-H
# | |
#---------| \-E
# |
# | /-Q
# \--------|
# \-P
# Let's re-create the same tree again
示例7: __init__
# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import prune [as 别名]
#.........这里部分代码省略.........
def Brutal(self, reroot = False):
if reroot:
self.re_rooting()
first_node_list = []
first_node_list.append(self.tree)
first_childs = self.tree.get_children()
for child in first_childs:
first_node_list.append(child)
num_s = self.comp_num_comb()
if num_s > self.max_num_search:
print("Too many search iterations: " + repr(num_s) + ", using H0 instead!!!")
self.H0(reroot = False)
else:
first_setting = species_setting(spe_nodes = first_node_list, root = self.tree, sp_rate = self.fix_spe, fix_sp_rate = self.fix_spe_rate, minbr = self.min_brl)
self.next(first_setting)
def search(self, strategy = "H1", reroot = False):
if strategy == "H1":
self.H1(reroot)
elif strategy == "H2":
self.H2(reroot)
elif strategy == "H3":
self.H3(reroot)
elif strategy == "Brutal":
self.Brutal(reroot)
else:
self.H0(reroot)
def count_species(self, print_log = True, pv = 0.001):
lhr = lh_ratio_test(self.null_logl, self.max_logl, 1)
pvalue = lhr.get_p_value()
if print_log:
print("Speciation rate: " + "{0:.3f}".format(self.max_setting.rate2))
print("Coalesecnt rate: " + "{0:.3f}".format(self.max_setting.rate1))
print("Null logl: " + "{0:.3f}".format(self.null_logl))
print("MAX logl: " + "{0:.3f}".format(self.max_logl))
print("P-value: " + "{0:.3f}".format(pvalue))
spefit, speaw = self.max_setting.e2.ks_statistic()
coafit, coaaw = self.max_setting.e1.ks_statistic()
print("Kolmogorov-Smirnov test for model fitting:")
print("Speciation: " + "Dtest = {0:.3f}".format(spefit) + " " + speaw)
print("Coalescent: " + "Dtest = {0:.3f}".format(coafit) + " " + coaaw)
if pvalue < pv:
num_sp, self.species_list = self.max_setting.count_species()
return num_sp
else:
self.species_list = []
self.species_list.append(self.tree.get_leaf_names())
return 1
def whitening_search(self, strategy = "H1", reroot = False, pv = 0.001):
self.search(strategy, reroot, pv)
num_sp, self.species_list = self.max_setting.count_species()
spekeep = self.max_setting.whiten_species()
self.tree.prune(spekeep)
self.max_logl = float("-inf")
self.max_setting = None
self.null_logl = 0.0
self.null_model()
self.species_list = None
self.counter = 0
self.setting_set = set([])
self.search(strategy, reroot, pv)
def print_species(self):
cnt = 1
for sp in self.species_list:
print("Species " + repr(cnt) + ":")
for leaf in sp:
print(" " + leaf)
cnt = cnt + 1
def output_species(self, taxa_order = []):
"""taxa_order is a list of taxa names, the paritions will be output as the same order"""
if len(taxa_order) == 0:
taxa_order = self.tree.get_leaf_names()
num_taxa = 0
for sp in self.species_list:
for leaf in sp:
num_taxa = num_taxa + 1
if not len(taxa_order) == num_taxa:
print("error error, taxa_order != num_taxa!")
return None, None
else:
partion = [-1] * num_taxa
cnt = 1
for sp in self.species_list:
for leaf in sp:
idx = taxa_order.index(leaf)
partion[idx] = cnt
cnt = cnt + 1
return taxa_order, partion