Exemplo n.º 1
0
import dendropy

if __name__ == '__main__':

    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option(
        "-p",
        "--prec",
        dest="prec",
        default=0.00001,
        type="float",
        help=
        "The precision of the comparison that the node depth is equal regardless of tip to node path."
    )
    (options, args) = parser.parse_args()
    if len(args) > 1:
        sys.exit(
            "At most one argument (a newick tree string with branch lengths) can be specified"
        )
    if len(args) == 1:
        newick = args[0]
    else:
        newick = sys.stdin.readline()

    prec = options.prec
    tree = dataio.trees_from_string(string=newick, format="NEWICK")[0]
    dendropy.trees.add_depth_to_nodes(tree, options.prec)

    sys.stdout.write("%f\n" % tree.seed_node.depth)
#!/usr/bin/env python

if __name__ == '__main__':
    import sys
    from dendropy import dataio
    from dendropy.treestats import pybus_harvey_gamma

    from optparse import OptionParser
    usage = """Calculates the Pybus-Harvey Gamma statistic for a tree specified as
    newick string.
"""
    (options, args) = parser.parse_args()
    if len(args) > 1:
        sys.exit(
            "At most one argument (a newick tree string with branch lengths) can be specified. Got: %s"
            % ' '.join(args))
    if len(args) == 1:
        newick = args[0]
    else:
        newick = sys.stdin.readline()

    tree = dataio.trees_from_string(string=newick, schema="NEWICK")[0]
    try:
        sys.stdout.write("%f\n" % pybus_harvey_gamma(tree))
    except ValueError as x:
        sys.exit(str(x))
if __name__ == '__main__':
    import sys
    from dendropy import dataio

    from optparse import OptionParser
    usage = """Takes a tree (which will be treated as rooted), and reports the list of taxa
    as the "outgroup" such that the largest clade in the tree is the "ingroup".
This script can be useful when you are simulating rooted trees and need to do
   a rooted inference procedure using software (such as PAUP*) that requires
   you to specify an outgroup when you want to score under a clock model.
"""
    parser = OptionParser(usage=usage)
    parser.add_option("-s", "--sep", dest="sep", default="\n",
        type="str",
        help="The string that separates taxa listed in the outgroup")
    (options, args) = parser.parse_args()
    if len(args) > 1:
        sys.exit("At most one argument (a newick tree string with branch lengths) can be specified. Got: %s" % ' '.join(args))
    if len(args) == 1:
        newick = args[0]
    else:
        newick = sys.stdin.readline()

    tree = dataio.trees_from_string(string=newick, schema="NEWICK")[0]
    outgroup_labels = rtree_outgroup_labels(tree)
    sep = options.sep
    sys.stdout.write("%s\n" % sep.join(outgroup_labels))


Exemplo n.º 4
0
            if leaves_to_include < leaves_to_gen:
                for l in tips:
                    if not (l in rleaves):
                        _LOG.debug("Deleting %s" % l.name)
                        l.prune_self()
                        _LOG.debug(sp_tree.newick(edge_lens=False))
            for n, l in enumerate(rleaves):
                l.name = "t%d" % (n+1)
            sp_tree.suppress_deg_two()
        newick_str = sp_tree.newick(edge_lens=True)

        if no_brlen_pattern.search(newick_str):
            sys.exit("No branch length")
        from dendropy import dataio
        if False:
            reread_sp_tree = dataio.trees_from_string(string=newick_str, format="NEWICK")[0]
            reread_newick = str(reread_sp_tree)
            _LOG.warn(reread_newick)
            if no_brlen_pattern.search(reread_newick):
                sys.exit("No branch length in reread string:\n%s" % reread_newick)

        write_tree(sys.stdout, newick_str, fmt_code, i)

        c = sp_tree.children[0]
        if sp_tree.children[0].count_tips() > sp_tree.children[1].count_tips():
            c = sp_tree.children[1]
        c.write_tip_names(outgroupsfile)
    outgroupsfile.close()

    if fmt_code == FORMAT_CODE.NEXUS:
        sys.stdout.write("END;\n")