本文整理汇总了Python中dendropy.Tree.yield_from_files方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.yield_from_files方法的具体用法?Python Tree.yield_from_files怎么用?Python Tree.yield_from_files使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dendropy.Tree
的用法示例。
在下文中一共展示了Tree.yield_from_files方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from dendropy import Tree [as 别名]
# 或者: from dendropy.Tree import yield_from_files [as 别名]
def main (folder=None,seed=None):
print("Folder %s, seed %s") % (folder,seed)
r=numpy.random.RandomState(seed)
gene_trees=TreeList()
taxa = dendropy.TaxonNamespace()
treefiles=glob.glob(args.sd+"/"+folder+"/g_trees*.trees")
tree_yielder=Tree.yield_from_files(files=treefiles,schema="newick",rooting="default-rooted",preserve_underscores=True,taxon_namespace=taxa)
#Modify gene trees
#I have to modify here the trees
if args.mk=="random":
for gtree in tree_yielder:
onodes=gtree.leaf_nodes()
nodes=remove_taxa_prov(r,onodes,args.pr)
if len(nodes) < len(onodes)-3: #Tree with missing leaves
gtree.prune_taxa(nodes,update_bipartitions=False, suppress_unifurcations=True)
gene_trees.append(gtree)
else: #The whole tree is missing (the tree would have 3 leaves or less, which is not an unrooted tree)
continue
elif args.mk=="byindividual":
tagProbs=None
for gtree in tree_yielder:
onodes=gtree.leaf_nodes()
if not tagProbs:
tagProbs={}
probs=truncated_normal(r,n=len(onodes),mean=args.pr,sd=args.ist,min=args.itmin,max=args.itmax) #one prob for each leaf
for leafi in xrange(len(onodes)):
tagProbs[onodes[leafi].taxon.label]=probs[leafi]#assigment to leaf labels in the dictionary
nodes=remove_taxa_tagprobs(r,onodes,tagProbs)
if len(nodes) < len(onodes)-3: #Tree with missing leaves
gtree.prune_taxa(nodes,update_bipartitions=False, suppress_unifurcations=True)
gene_trees.append(gtree)
else: #The whole tree is missing (the tree would have 3 leaves or less, which is not an unrooted tree)
continue
else:
print("Yet unsupported option")
#Write gene trees
gene_trees.write(path=args.sd+"/"+folder+"/"+args.o,schema="newick")