Beispiel #1
0
# use home-made code to prune the tree instead

treeName, treeExt = splitext(outtrees)
fName, ext = splitext(outtrees)
for i, RS in enumerate(removing_sets):
    trees_shrinked = deepcopy(trees)
    outfile = outdir + "/" + fName + "_RS_" + quantiles[i]
    with open(outfile, 'w') as f:
        for item in RS:
            for s in item:
                f.write(s + "\t")
            f.write("\n")
    for t, tree in enumerate(trees_shrinked):
        #filt = lambda node: False if (node.taxon is not None and node.taxon.label in RS[t]) else True
        #tree.filter_leaf_nodes(filt,update_bipartitions=True)
        prune_tree(tree, RS[t])
    trees_shrinked.write_to_path(
        outdir + "/" + treeName + "_" + quantiles[i] + treeExt, 'newick')

if not args["tempdir"]:
    call(["rm", "-r", tempdir])
'''
# prune trees according to the removing sets. 
# calling nw_prune here as a (terrible) temporary sollution, because Dendropy's filter_leaf_nodes() seems to have problems

fName,ext = splitext(outtrees)
for i,RS in enumerate(removing_sets):
    outfile = outdir + "/" + fName + "_RS_" + quantiles[i]
    with open(outfile,'w') as f:
        for item in RS:
            for s in item:
Beispiel #2
0
parser.add_argument("-l", "--listing", required=True, help="Removing set")
parser.add_argument(
    "-v",
    "--reverse",
    required=False,
    action='store_true',
    help="Do the reverse pruning: retain the listed taxa. Default: NO")

args = vars(parser.parse_args())

RS = args["listing"].split() if not args["reverse"] else None

with open(args["input"], 'r') as fin:
    treein = fin.readlines()

treeout = []

for t in treein:
    tree = Tree.get(data=t, schema="newick", preserve_underscores=True)
    if not RS:
        RS = [
            x.taxon.label for x in tree.leaf_node_iter()
            if x.taxon.label not in args["listing"].split()
        ]
    prune_tree(tree, RS)
    treeout.append(tree.as_string("newick", unquoted_underscores=True))

with open(args["output"], 'w') as fout:
    for t in treeout:
        fout.write(t)
Beispiel #3
0
    print("The tree is not large enough for this sampling size!")
else:
    if outfile:
        fout_info = open(outfile, 'w')
    else:
        fout_info = stdout

    fout_info.write("Sampled from " + abspath(treefile) + "\n")
    fout_info.write("Sampled " + str(n_reps) + " replicate(s) of " +
                    str(n_ingroups) + " ingroup(s) and " + str(n_outgroups) +
                    " outgroup(s)\n")
    with open(outtreeFile, 'w') as fout_tree:
        for i, (t, igs, ogs) in enumerate(samples):
            fout_info.write("Rep " + str(i + 1) + ":\n")
            fout_info.write("Ingroups: ")
            for i in igs:
                fout_info.write(i + " ")
            fout_info.write("\nOutgroups: ")
            for o in ogs:
                fout_info.write(o + " ")
            fout_info.write("\n")
            fout_tree.write(t.as_string('newick'))

    fout_info.close()

    if outtree_noOG:
        with open(outtree_noOG, 'w') as f:
            for t, igs, ogs in samples:
                prune_tree(t, ogs)
                f.write(t.as_string('newick'))