Пример #1
0
def getInput(outputExtension, allowEmptyOutfile=False):
    """ outputExtension is the output file extension (e.g, pdf or csv) """
    
    # Get input file name and try to open it
    # while True:
    #     fileName = raw_input("Enter .newick input file name: ")
    #     if fileName.endswith(".newick"):
    #         try:
    #             fileHandle = open(fileName, 'r')
    #             break
    #         except IOError:
    #             print "Error reading file.  Please try again."
    #     else:
    #         print "File name must end in .newick.  Please try again."

    fileHandle = open("/Users/hmcguest/Downloads/xscape/examples/heliconius.newick", "r")
    
    hostTree, parasiteTree, phi = newickFormatReader(fileHandle)
    fileHandle.close()

    # Get output file name
    # while True:
    #     if allowEmptyOutfile:
    #         outfile = raw_input("Enter ." + outputExtension + " name for output file (or Return): ")
    #         if outfile == "": break
    #     else:
    #         outfile = raw_input("Enter ." + outputExtension + " name for output file: ")
    #     if outfile.endswith(outputExtension):
    #         break
    #     else:
    #         print "File name must end in ." + outputExtension + ".  Please try again."   
    
    # Get parameter value ranges            
    outfile = "out.pdf"
    # switchLo = floatInput("Enter switch low value: ", min_val=0.9)
    # switchHi = floatInput("Enter switch high value: ", min_val=1.2)
    # lossLo = floatInput("Enter loss low value: ", min_val=0.9)
    # lossHi = floatInput("Enter loss high value: ", min_val=1.2)
    
    switchLo = 0.9
    switchHi = 1.2
    lossLo = 0.9
    lossHi = 1.2

    return hostTree, parasiteTree, phi, switchLo, switchHi, lossLo, lossHi, outfile
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
Пример #3
0
def getInput(outputExtension, allowEmptyOutfile=False):
    """ outputExtension is the output file extension (e.g, pdf or csv) """

    # Get input file name and try to open it
    while True:
        fileName = raw_input("Enter .newick input file name: ")
        if fileName.endswith(".newick"):
            try:
                fileHandle = open(fileName, 'r')
                break
            except IOError:
                print "Error reading file.  Please try again."
        else:
            print "File name must end in .newick.  Please try again."

    hostTree, parasiteTree, phi = newickFormatReader(fileHandle)
    fileHandle.close()

    # Get output file name
    while True:
        if allowEmptyOutfile:
            outfile = raw_input("Enter ." + outputExtension +
                                " name for output file (or Return): ")
            if outfile == "": break
        else:
            outfile = raw_input("Enter ." + outputExtension +
                                " name for output file: ")
        if outfile.endswith(outputExtension):
            break
        else:
            print "File name must end in ." + outputExtension + ".  Please try again."

    # Get parameter value ranges
    switchLo = floatInput("Enter switch low value: ", min_val=0)
    switchHi = floatInput("Enter switch high value: ", min_val=switchLo)
    lossLo = floatInput("Enter loss low value: ", min_val=0)
    lossHi = floatInput("Enter loss high value: ", min_val=lossLo)

    return hostTree, parasiteTree, phi, switchLo, switchHi, lossLo, lossHi, 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
Пример #5
0
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 getInput(outputExtension, allowEmptyOutfile=False):
    """ outputExtension is the output file extension (e.g, pdf or csv) """
    
    # Get input file name and try to open it
    while True:
        fileName = raw_input("Enter .newick input file name: ")
        if fileName.endswith(".newick"):
            try:
                fileHandle = open(fileName, 'r')
                break
            except IOError:
                print "Error reading file.  Please try again."
        else:
            print "File name must end in .newick.  Please try again."
    
    hostTree, parasiteTree, phi = newickFormatReader(fileHandle)
    fileHandle.close()

    # Get output file name
    while True:
        if allowEmptyOutfile:
            outfile = raw_input("Enter ." + outputExtension + " name for output file (or Return): ")
            if outfile == "": break
        else:
            outfile = raw_input("Enter ." + outputExtension + " name for output file: ")
        if outfile.endswith(outputExtension):
            break
        else:
            print "File name must end in ." + outputExtension + ".  Please try again."   
    
    # Get parameter value ranges            
    switchLo = floatInput("Enter switch low value: ", min_val=0)
    switchHi = floatInput("Enter switch high value: ", min_val=switchLo)
    lossLo = floatInput("Enter loss low value: ", min_val=0)
    lossHi = floatInput("Enter loss high value: ", min_val=lossLo)
    
    return hostTree, parasiteTree, phi, switchLo, switchHi, lossLo, lossHi, outfile