def dnadist(seqs, output=None, verbose=True, force=False, args=None): if args == None: args = "y" validate_seqs(seqs) cwd = create_temp_dir() util.tic("dnadist on %d of length %d" % (len(seqs), len(seqs.values()[0]))) # create input labels = write_phylip_align(file("infile", "w"), seqs) # run phylip exec_phylip("dnadist", args, verbose) util.toc() # parse output if output != None: os.rename("outfile", "../" + output) cleanup_temp_dir(cwd) return labels else: name, mat = read_dist_matrix("outfile") cleanup_temp_dir(cwd) return labels, mat
def boot_neighbor(seqs, iters=100, seed=None, output=None, verbose=True, force=False): if seed == None: seed = random.randInt(0, 1000) * 2 + 1 validate_seqs(seqs) cwd = create_temp_dir() util.tic("boot_neighbor on %d of length %d" % (len(seqs), len(seqs.values()[0]))) # create input labels = write_phylip_align(file("infile", "w"), seqs) exec_phylip("seqboot", "r\n%d\ny\n%d" % (iters, seed), verbose) os.rename("outfile", "infile") exec_phylip("protdist", "m\nd\n%d\ny" % iters, verbose) os.rename("outfile", "infile") exec_phylip("neighbor", "m\n%d\n%d\ny" % (iters, seed), verbose) util.toc() # read tree samples if output != None: os.rename("outtree", "../" + output) cleanup_temp_dir(cwd) return labels else: trees = [] infile = file("outtree") for i in xrange(iters): tree = treelib.Tree() tree.read_newick(infile) rename_tree_with_name(tree, labels) trees.append(tree) infile.close() cleanup_temp_dir(cwd) return trees
def boot_proml(seqs, iters=100, seed=1, jumble=5, output=None, verbose=True, force=False): validate_seqs(seqs) cwd = create_temp_dir() util.tic("bootProml on %d of length %d" % (len(seqs), len(seqs.values()[0]))) # create input labels = write_phylip_align(file("infile", "w"), seqs) exec_phylip("seqboot", "y\n%d" % seed, verbose) os.rename("outfile", "infile") exec_phylip("proml", "m\nD\n%d\n%d\n%d\ny" % (iters, seed, jumble), verbose) util.toc() # read tree samples if output != None: os.rename("outtree", "../" + output) cleanup_temp_dir(cwd) return labels else: trees = [] infile = file("outtree") for i in xrange(iters): tree = treelib.Tree() tree.read_newick(infile) rename_tree_with_names(tree, labels) trees.append(tree) infile.close() cleanup_temp_dir(cwd) return trees
def proml_treelk(aln, tree, verbose=True, force=False, args="u\ny"): validate_seqs(aln) cwd = create_temp_dir() util.tic("proml on %d of length %d" % (len(aln), len(aln.values()[0]))) # create input labels = write_phylip_align(file("infile", "w"), aln) write_in_tree("intree", tree, labels) # run phylip exec_phylip("proml", args, verbose) # parse logl logl = read_logl("outfile") # parse tree tree = read_out_tree("outtree", labels) cleanup_temp_dir(cwd) util.toc() return logl, tree
def align2tree( prog, seqs, verbose=True, force=False, args=None, usertree=None, saveOutput="", bootiter=1, seed=1, jumble=1, ): validate_seqs(seqs) cwd = create_temp_dir() util.tic("%s on %d of length %d" % (prog, len(seqs), len(seqs.values()[0]))) # create input labels = write_phylip_align(file("infile", "w"), seqs) util.write_list(file("labels", "w"), labels) # initialize default arguments if args == None: args = "y" # create user tree if given if usertree != None: write_in_tree("intree", usertree, labels) args = "u\n" + args # add user tree option # bootstrap alignment if needed if bootiter > 1: exec_phylip("seqboot", "r\n%d\ny\n%d" % (bootiter, seed), verbose) os.rename("outfile", "infile") # add bootstrap arguments args = "m\nD\n%d\n%d\n%d\n%s" % (bootiter, seed, jumble, args) # run phylip exec_phylip(prog, args, verbose) # check for PHYLIP GIVE UP if is_phylip_give_up("outfile"): tree = treelib.Tree() tree.make_root() # make star tree for key in seqs: tree.add_child(tree.root, treelib.TreeNode(key)) else: # parse tree if bootiter == 1: tree = read_out_tree("outtree", labels, bootiter) # parse likelihood if prog in ["dnaml", "proml"]: tree.data["logl"] = read_logl("outfile") else: trees = read_out_tree("outtree", labels, bootiter) if saveOutput != "": save_temp_dir(cwd, saveOutput) else: cleanup_temp_dir(cwd) util.toc() if bootiter == 1: return tree else: return trees