예제 #1
0
파일: flower.py 프로젝트: a-terada/lamp
                ymax = shifty + sizey
            if(ymin > shifty - sizey):
                ymin = shifty - sizey

        # calculate the scaling factor
        scalex = (xmax - xmin) / (SHIFTX * 3)
        scaley = (ymax - ymin) / (SHIFTY * 3)

        # open the SVG file
        nameset = combiName[j]
        svgfilename = sys.argv[1] + '-flower'
        #for k in range(len(nameset)):
        #    svgfilename += ('-' + nameset[k])
        svgfilename += str(combiRank[j])
        svgfilename += '.svg'
        svgfile = svg.openFile(svgfilename)

        # for each motif in the combination
        for k in range(len(nameset)):
            
            # search for the motif and specify its ID
            nameid = -1
            for i in range(len(motifName)):
                if(motifName[i].find(nameset[k]) >= 0):
                    nameid = i
                    break

            # calculate the size and color of the ellipsoid
            sizeval = math.log(motifNgenes[nameid]) * sizecoef
            if(motifApvalue[nameid] > significance):
                colorval = -math.log(motifApvalue[nameid] / significance)
예제 #2
0
def main():

    if len(sys.argv) < 2:
        print 'Usage: # python %s resultfilename (target(csv)filename) (value(tab)filename)' % sys.argv[0]
        quit()

    # default values of sizes of petals
    EWIDTH = 120
    EHEIGHT = 50
    MINWIDTH = 120
    MINHEIGHT = 40

    # shift from the origin(=upper-left end)
    SHIFTX = 400
    SHIFTY = 400

    # coeffcient for the adjustment of petal position
    PETALPOSCOEF = 0.8

    # coefficient for the adjustment of torus size
    TORUSSIZECOEF = 1.2

    # coefficients for size calculation
    sizecoef = 0.3

    # add command line options
    parser = OptionParser()
    parser.add_option("--ewidth", "--EWIDTH", dest="EWIDTH", default="120")
    parser.add_option("--eheight", "--EHEIGHT", dest="EHEIGHT", default="50")
    parser.add_option("--minwidth", "--MINWIDTH", dest="MINWIDTH", default="120")
    parser.add_option("--minheight", "--MINHEIGHT", dest="MINHEIGHT", default="40")
    parser.add_option("--shiftx", "--SHIFTX", dest="SHIFTX", default="400")
    parser.add_option("--shifty", "--SHIFTY", dest="SHIFTY", default="400")
    parser.add_option("--petalposcoef", "--PETALPOSCOEF", dest="PETALPOSCOEF", default="0.8")
    parser.add_option("--torussizecoef", "--TORUSSIZECOEF", dest="TORUSSIZECOEF", default="1.2")
    (options, args) = parser.parse_args()
    EWIDTH = int(options.EWIDTH)
    EHEIGHT = int(options.EHEIGHT)
    MINWIDTH = int(options.MINWIDTH)
    MINHEIGHT = int(options.MINHEIGHT)
    SHIFTX = int(options.SHIFTX)
    SHIFTY = int(options.SHIFTY)
    PETALPOSCOEF = float(options.PETALPOSCOEF)
    TORUSSIZECOEF = float(options.TORUSSIZECOEF)

    # read the result file
    csvfname = ''
    tabfname = ''
    if len(sys.argv) > 3:
        cfvfname = sys.argv[2]
        tabfname = sys.argv[3]
    significance = readfile.readResult(sys.argv[1], csvfname, tabfname)
    colorvalMin = -math.log(1.0 / significance)

    # for each combination
    for j in range(len(combiName)):

        # reset the end position values
        xmin = 1.0e+30
        xmax = -1.0e+30
        ymin = 1.0e+30
        ymax = -1.0e+30

        # determine the scale of drawing
        nameset = combiName[j]
        for k in range(len(nameset)):
            
            # search for the motif and specify its ID
            nameid = -1
            for i in range(len(motifName)):
                if(motifName[i].find(nameset[k]) >= 0):
                    nameid = i
                    break

            # calculate the end position values
            sizeval = math.log(motifNgenes[nameid]) * sizecoef
            rad = k * math.pi * 2 / len(combiName[j]) - math.pi * 0.5
            sizex = EWIDTH * sizeval
            sizey = EHEIGHT * sizeval
            shiftx = (math.cos(rad) * (sizex - EHEIGHT * 2)) + SHIFTX
            shifty = (math.sin(rad) * (sizex - EHEIGHT * 2)) + SHIFTY
            if(xmax < shiftx + sizex):
                xmax = shiftx + sizex
            if(xmin > shiftx - sizex):
                xmin = shiftx - sizex
            if(ymax < shifty + sizey):
                ymax = shifty + sizey
            if(ymin > shifty - sizey):
                ymin = shifty - sizey

        # calculate the scaling factor
        scalex = (xmax - xmin) / (SHIFTX * 3)
        scaley = (ymax - ymin) / (SHIFTY * 3)

        # open the SVG file
        nameset = combiName[j]
        svgfilename = sys.argv[1] + '-flower'
        #for k in range(len(nameset)):
        #    svgfilename += ('-' + nameset[k])
        svgfilename += str(combiRank[j])
        svgfilename += '.svg'
        svgfile = svg.openFile(svgfilename)

        # for each motif in the combination
        for k in range(len(nameset)):
            
            # search for the motif and specify its ID
            nameid = -1
            for i in range(len(motifName)):
                if(motifName[i].find(nameset[k]) >= 0):
                    nameid = i
                    break

            # calculate the size and color of the ellipsoid
            sizeval = math.log(motifNgenes[nameid]) * sizecoef
            if(motifApvalue[nameid] > significance):
                colorval = -math.log(motifApvalue[nameid] / significance)
                if(colorval < colorvalMin):
                    colorval = colorvalMin
            if(motifApvalue[nameid] <= significance):
                colorval = motifApvalue[nameid] / significance

            # initialize variables before calculating the shape of the ellipsoid
            rad = k * math.pi * 2 / len(combiName[j]) - math.pi * 0.5
            sizex = EWIDTH * sizeval * scalex
            sizey = EHEIGHT * sizeval * scaley
            if(sizex < MINWIDTH):
                sizex = MINWIDTH
            if(sizey < MINHEIGHT):
                sizey = MINHEIGHT
            shiftx = (math.cos(rad) * (sizex - EHEIGHT * PETALPOSCOEF)) + SHIFTX
            shifty = (math.sin(rad) * (sizex - EHEIGHT * PETALPOSCOEF)) + SHIFTY
            annox = (math.cos(rad) * (sizex * 2  - EHEIGHT * PETALPOSCOEF)) + SHIFTX
            annoy = (math.sin(rad) * (sizex * 2  - EHEIGHT * PETALPOSCOEF)) + SHIFTY

            # draw a motif
            svg.drawMotif(sizex, sizey, shiftx, shifty, rad, colorval, svgfile)
            svg.annotateMotif(motifName[nameid], motifApvalue[nameid],
                              annox, annoy, svgfile)

        # draw the combination
        colorval = combiApvalue[j] / significance
        size = EHEIGHT * scalex * TORUSSIZECOEF
        if(size < MINHEIGHT):
            size = MINHEIGHT
        svg.drawMotif(size, size, SHIFTX, SHIFTY, 0.0, colorval, svgfile)
        svg.annotateMotif("", combiApvalue[j], SHIFTX-30, SHIFTY-5, svgfile)

        # close the SVG file
        svg.closeFile(svgfile)
예제 #3
0
파일: flower.py 프로젝트: msakai/lamp
                ymax = shifty + sizey
            if (ymin > shifty - sizey):
                ymin = shifty - sizey

        # calculate the scaling factor
        scalex = (xmax - xmin) / (SHIFTX * 3)
        scaley = (ymax - ymin) / (SHIFTY * 3)

        # open the SVG file
        nameset = combiName[j]
        svgfilename = sys.argv[1] + '-flower'
        #for k in range(len(nameset)):
        #    svgfilename += ('-' + nameset[k])
        svgfilename += str(combiRank[j])
        svgfilename += '.svg'
        svgfile = svg.openFile(svgfilename)

        # for each motif in the combination
        for k in range(len(nameset)):

            # search for the motif and specify its ID
            nameid = -1
            for i in range(len(motifName)):
                if (motifName[i].find(nameset[k]) >= 0):
                    nameid = i
                    break

            # calculate the size and color of the ellipsoid
            sizeval = math.log(motifNgenes[nameid]) * sizecoef
            if (motifApvalue[nameid] > significance):
                colorval = -math.log(motifApvalue[nameid] / significance)