当前位置: 首页>>代码示例>>Python>>正文


Python LoadTree.prune方法代码示例

本文整理汇总了Python中cogent.LoadTree.prune方法的典型用法代码示例。如果您正苦于以下问题:Python LoadTree.prune方法的具体用法?Python LoadTree.prune怎么用?Python LoadTree.prune使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cogent.LoadTree的用法示例。


在下文中一共展示了LoadTree.prune方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from cogent import LoadTree [as 别名]
# 或者: from cogent.LoadTree import prune [as 别名]

#.........这里部分代码省略.........
    if verbose:
        print "Running with options:"
        print "%s:%s" %("Tree file",tree_file)
        print "%s:%s" %("Trait table",trait_table_fp)
        print "%s:%s" %("Output tree",output_tree_fp)
        print "%s:%s" %("Output trait table",output_table_fp)
        print "%s:%s" %("Add branch length to root",opts.add_branch_length_to_root)
        print "%s:%s" %("Convert to NEXUS?",opts.convert_to_nexus)
         
    # Open output files
    output_trait_table_file = open(output_table_fp,"w+")
    output_tree_file  = open(output_tree_fp,"w+")
    

    # Begin reformatting
    
    # TODO: convert parameter candidates to params
    #delimiter = "\t"
    
    
    delimiter = " "
    min_branch_length = 0.0001
    root_name = "root"
    
    if format_for_bayestraits:
        convert_to_nexus = True
        convert_to_bifurcating = True
        filter_table_by_tree_tips = True
        filter_tree_by_table_entries = True
        enforce_min_branch_length = True
        convert_trait_floats_to_ints = True

    #Load inputs
    input_tree = LoadTree(tree_file)
    
    trait_table = open(trait_table_fp,"U")
    trait_table_lines = trait_table.readlines()
    
    #if opts.verbose:
        #print "Tree prior to reformatting:"
        #print input_tree.getNewick(with_distances=True)
        #print "Tree nodes prior to reformatting:"
        #print_node_summary_table(input_tree)
    
    # Remove taxa missing in tree tips
    if filter_table_by_tree_tips: 
        trait_table_lines = filter_table_by_presence_in_tree(input_tree,trait_table_lines,delimiter=delimiter)
    
    #Convert floating point values to ints
    if convert_trait_floats_to_ints:
        trait_table_lines = convert_trait_values(\
            trait_table_lines,conversion_fn = int,delimiter=delimiter)
   
    #Write out results
    output_trait_table_file.writelines(trait_table_lines)
    trait_table.close()
    output_trait_table_file.close()
   
    # Use the reformatted trait table to filter tree
    trait_table = open(output_table_fp,"U")
    trait_table_lines = trait_table.readlines()
    

    if filter_tree_by_table_entries:
        input_tree = filter_tree_tips_by_presence_in_table(input_tree,trait_table_lines,delimiter=delimiter) 
    
    # Tree reformatting
    
    
    if convert_to_bifurcating:
        input_tree = input_tree.bifurcating() # Required by most ancSR programs
    
   
    if convert_to_bifurcating:
        input_tree = ensure_root_is_bifurcating(input_tree)
        # The below nutty-looking re-filtering step is necessary
        # When ensuring the root is bifurcating, internal nodes can get moved to the tips
        # So without additional filtering we get unannotated tip nodes
        if filter_tree_by_table_entries:
            input_tree = filter_tree_tips_by_presence_in_table(input_tree,trait_table_lines,delimiter=delimiter) 
    
    if enforce_min_branch_length:
        input_tree = set_min_branch_length(input_tree,min_length = min_branch_length)
    
    if opts.add_branch_length_to_root:
        input_tree = add_branch_length_to_root(input_tree,root_name=input_tree.Name,root_length=min_branch_length)
    
    input_tree.prune() 
    
    #if opts.verbose:
    #    print "Tree nodes after reformatting:"
    #    print_node_summary_table(input_tree)
    #    print "Convert to nexus is True?",convert_to_nexus is True
    if convert_to_nexus is True:
        lines = nexus_lines_from_tree(input_tree)
        output_tree_file.write("\n".join(map(str,lines)))
    else:
        output_tree_file.write(input_tree.getNewick(with_distances=True))
    
    output_tree_file.close()
开发者ID:cleme,项目名称:picrust,代码行数:104,代码来源:format.py


注:本文中的cogent.LoadTree.prune方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。