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 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 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