def findCenters(newickFile, switchLo, switchHi, lossLo, lossHi): """This function takes as input a .newick file in the form <filename>.newick, and low and high values for costscape for both switches and losses. It returns a list of the centroids of each region in the costscape associated with the given .newick file.""" hostTree, parasiteTree, phi = newickFormatReader(newickFile) CVlist = reconcile.reconcile(parasiteTree, hostTree, phi, switchLo, switchHi, lossLo, lossHi) coordList = plotcosts.plotcosts(CVlist, lossLo, lossHi, switchLo, switchHi, "", False, False) polygonList = getNewCoordList(newickFile, switchLo, switchHi, lossLo, lossHi) pointList = [] for i in range(len(polygonList)): point = polygonList[i] numCommas = point.count(",") if numCommas > 1: # polygon case region = load_wkt(point) pointList.append(region.centroid.wkt) elif numCommas == 1: # line case x1 = coordList[i][0][0] y1 = coordList[i][0][1] x2 = coordList[i][1][0] y2 = coordList[i][1][1] midx = (x1 + x2) * 1.0 / 2 midy = (y1 + y2) * 1.0 / 2 pointList.append("POINT ({} {})".format(str(midx), str(midy))) else: # point case pointList.append("POINT {}".format(str(coordList[i][0]))) return pointList
def seqTrials(parasiteTree, hostTree, phi, numTrials, switchLo, switchHi, lossLo, lossHi, verbose=True): ''' Perform numTrials randomization trials sequentially. Although parTrials could be used to do this too, this function doesn't require the multiprocessing package and thus may be preferable to some users in some situation.''' parasiteTips, hostTips = getTipLists(parasiteTree, hostTree, phi) output = [] for t in range(numTrials): if verbose: print(".", end=' ') # Progress indicator! sys.stdout.flush() newPhi = randomizeTips(parasiteTips, hostTips) output.append( reconcile.reconcile(parasiteTree, hostTree, newPhi, switchLo, switchHi, lossLo, lossHi)) if verbose: print() # Newline return output
def parTrials(parasiteTree, hostTree, phi, numTrials, \ switchLo, switchHi, lossLo, lossHi, result, verbose=True): ''' Perform numTrials randomization trials in one process. ''' parasiteTips, hostTips = getTipLists(parasiteTree, hostTree, phi) output = [] for t in range(numTrials): if verbose: print(".", end=' ') # Progress indicator! sys.stdout.flush() newPhi = randomizeTips(parasiteTips, hostTips) output.append(reconcile.reconcile(parasiteTree, hostTree, newPhi, \ switchLo, switchHi, lossLo, lossHi)) result.put(output)
def getNewCoordList(newickFile, switchLo, switchHi, lossLo, lossHi): """Takes as input a newick file in the form <filename>.newick, and low and high values for costscape for both switches and losses. Returns a list of strings, where each string contains all the verteces of one region from costscape.""" hostTree, parasiteTree, phi = newickFormatReader(newickFile) CVlist = reconcile.reconcile(parasiteTree, hostTree, phi, switchLo, switchHi, lossLo, lossHi) coordList = plotcosts.plotcosts(CVlist, lossLo, lossHi, switchLo, switchHi, "", False, False) newCoordList = [] for vertexList in coordList: string = "POLYGON((" for vertex in vertexList: string = "{}{} {},".format(string, str(vertex[0]), str(vertex[1])) string = "{}))".format(string[:-1]) newCoordList.append(string) return newCoordList
def getNewCoordList(newickFile, switchLo, switchHi, lossLo, lossHi): """Takes as input a newick file in the form <filename>.newick, and low and high values for costscape for both switches and losses. Returns a list of strings, where each string contains all the verteces of one region from costscape.""" hostTree, parasiteTree, phi = newickFormatReader(newickFile) CVlist = reconcile.reconcile(parasiteTree, hostTree, phi, switchLo, \ switchHi, lossLo, lossHi) coordList = plotcosts.plotcosts(CVlist, lossLo, lossHi, switchLo, \ switchHi, "", False, False) newCoordList = [] for element in coordList: string = "POLYGON((" for i in element: string = string + str(i[0]) + ' ' + str(i[1]) + ',' string = string[:-1] + '))' newCoordList.append(string) return newCoordList
def main(): print("Sigscape %s" % xscape.PROGRAM_VERSION_TEXT) hostTree, parasiteTree, phi, switchLo, switchHi, lossLo, lossHi, \ outfile = getInput.getInput(outputExtension = "pdf", allowEmptyOutfile = True) log = getInput.boolInput("Display in log coordinates? ") if outfile == "": display = True else: display = getInput.boolInput("Display to screen? ") numTrials = getInput.intInput("Enter the number of randomization trials: ", 1) numProcs = getInput.intInput( "Enter the number of cores for parallelization: ", 1) seed = getSeed("Enter random seed (leave blank if none): ") if seed: random.seed(seed) print("Reconciling trees...") CVlist = reconcile.reconcile(parasiteTree, hostTree, phi, \ switchLo, switchHi, lossLo, lossHi) startTime = time.time() if numProcs == 1: randomTrialsCVlist = seqTrials(parasiteTree, hostTree, phi, \ numTrials, switchLo, switchHi, \ lossLo, lossHi) else: randomTrialsCVlist = parallelTrials(parasiteTree, hostTree, phi, \ numTrials, numProcs, \ switchLo, switchHi, \ lossLo, lossHi) endTime = time.time() elapsedTime = endTime - startTime print("\nElapsed time %.2f seconds" % elapsedTime) print("Plotting...") plotsig.plotsig(CVlist, randomTrialsCVlist, switchLo, switchHi, \ lossLo, lossHi, DOTS, outfile, \ log, display) if outfile != "": print("Output written in file ", outfile)
def solve(newick_data, switchLo, switchHi, lossLo, lossHi, optional): print("Costscape %s" % xscape.PROGRAM_VERSION_TEXT) hostTree, parasiteTree, phi, = newick_data if optional.outfile == "": display = True else: display = optional.display print("Reconciling trees...") startTime = time.time() CVlist = reconcile.reconcile(parasiteTree, hostTree, phi, \ switchLo, switchHi, lossLo, lossHi) endTime = time.time() elapsedTime = endTime - startTime print("Elapsed time %.2f seconds" % elapsedTime) plotcosts.plotcosts(CVlist, switchLo, switchHi, lossLo, lossHi, \ optional.outfile, \ optional.log, display) if optional.outfile != "": print("Output written to file: ", optional.outfile)
def findCenters(newickFile, switchLo, switchHi, lossLo, lossHi): """This function takes as input a .newick file in the form <filename>.newick, and low and high values for costscape for both switches and losses. It returns a list of the centroids of each region in the costscape associated with the given .newick file.""" hostTree, parasiteTree, phi = newickFormatReader(newickFile) CVlist = reconcile.reconcile(parasiteTree, hostTree, phi, switchLo, \ switchHi, lossLo, lossHi) coordList = plotcosts.plotcosts(CVlist, lossLo, lossHi, switchLo, \ switchHi, "", False, False) polygonList = getNewCoordList(newickFile, switchLo, switchHi, lossLo, \ lossHi) pointList = [] for i in range(len(polygonList)): point = polygonList[i] numCommas = 0 for j in range(len(point)): if point[j] == ",": numCommas = numCommas + 1 if numCommas > 1: #polygon case region = load_wkt(point) pointList.append((region.centroid.wkt)) elif numCommas == 1: #line case x1 = coordList[i][0][0] y1 = coordList[i][0][1] x2 = coordList[i][1][0] y2 = coordList[i][1][1] midx = (x1 + x2) * 1.0 / 2 midy = (y1 + y2) * 1.0 / 2 pointList.append("POINT (" + str(midx) + " " + str(midy) + ")") else: #point case pointList.append("POINT " + str(coordList[i][0])) return pointList
def main(): global CandidateCVlist print("Eventscape %s" % xscape.PROGRAM_VERSION_TEXT) hostTree, parasiteTree, phi, switchLo, switchHi, lossLo, lossHi, outfile = \ getInput.getInput(outputExtension = "csv") while True: merge_type = input("[U]nion or [I]ntersection? ") if merge_type == "U" or merge_type == "I": break print("Invalid input. Please try again.") CONFIG.intersection = merge_type == "I" print("Reconciling trees...") startTime = time.time() print(" Preprocessing...") preCVlist = reconcile.reconcile(parasiteTree, hostTree, phi, \ switchLo, switchHi, lossLo, lossHi) CandidateCVlist.extend(restrict(preCVlist, \ switchLo, switchHi, lossLo, lossHi)) print(" Solving...") CVlist = reconcileEvents(parasiteTree, hostTree, phi, \ switchLo, switchHi, lossLo, lossHi) endTime = time.time() elapsedTime = endTime - startTime print("Elapsed time %.2f seconds" % elapsedTime) output(outfile, CVlist, hostTree, switchLo, switchHi, lossLo, lossHi, root=parasiteTree["pTop"][1]) print("Output written to file ", outfile)