def distanceTable(frq,method,outfile,met): keyDict = sorted(np.unique(("/".join(frq.keys())).split("/"))); mapDict = dict() if method == 'min': mapDict =minDistance(frq) elif method == 'prod': mapDict =prodDistance(frq,met) pr.printDistanceTableToFile(mapDict,keyDict,outfile)
def anchoredDistance(**kwargs): readFromTable=False for k,v in kwargs.iteritems(): if k == "qfile": qfile=v readFromTable = True elif k == "achs": achs = sorted(v) elif k == "gt": trees = v elif k == "outfile": outfile = v elif k == "wrkPath": out = v elif k == "taxa": taxa = v if(readFromTable): frq=tbs.readQuartetTable(qfile) D = anchoredDistanceFromFrq(frq,achs) else: [D,frq] = findAnchoredDistanceTable(achs,trees,taxa,out) keyDict = sorted(list(np.unique((" ".join(D.keys())).split(" ")))); pr.printDistanceTableToFile(D,keyDict,outfile) return frq
print >> f, anch_temp for achList in acSmall: for anch in achList: anch = sorted(list(anch)) anch_temp = "|".join(anch) print >> f, anch_temp f.close() os.close(ftmp3[0]) for e in con_tree.postorder_node_iter(): if e in to_resolve: z=listPoly.index(e) keyDict = sorted(list(np.unique((" ".join(normalizedD[z].keys())).split(" ")))) fileDistance = "distancet-"+str(e.label)+".d" ftmp3=tempfile.mkstemp(suffix='.d', prefix=fileDistance, dir=outpath, text=None) pr.printDistanceTableToFile(normalizedD[z],keyDict,ftmp3[1]) print "writing distance table to "+str(ftmp3[1]) os.close(ftmp3[0]) ftmp4=tempfile.mkstemp(suffix='.nwk', prefix=fileDistance+"_fastme_tree.nwk",dir=outpath,text=None) tstt.buildTreeFromDistanceMatrix(ftmp3[1],ftmp4[1],sumProg,sumProgOption) os.close(ftmp4[0]) if verbose: print "starting to resolve polytomy" res=atbs.resolvePolytomy(ftmp4[1],e,verbose) tstt.prune_tree_trivial_nodes(con_tree) outfile = outpath+"/distique_distance-sum.nwk" if verbose: print "writing the resulting tree as: "+outfile tstt.changeLabelsToNames(con_tree,new_labels,verbose) con_tree.write(path=outfile,schema="newick",suppress_rooting=True,suppress_internal_node_labels=True) print "The overall time to infer the species tree is: "