Ejemplo n.º 1
0
def ultimate_power():
    """
    Data from http://indexed.blogspot.com/2007/08/real-ultimate-power.html
    """
    chart = VennChart(settings.width, settings.height)
    chart.add_data([100, 100, 100, 20, 20, 20, 10])
    chart.set_title('Ninjas or God')
    chart.set_legend(['unseen agents', 'super powerful', 'secret plans'])
    chart.download('venn-ultimate-power.png')
Ejemplo n.º 2
0
def ultimate_power():
    """
    Data from http://indexed.blogspot.com/2007/08/real-ultimate-power.html
    """
    chart = VennChart(settings.width, settings.height)
    chart.add_data([100, 100, 100, 20, 20, 20, 10])
    chart.set_title('Ninjas or God')
    chart.set_legend(['unseen agents', 'super powerful', 'secret plans'])
    chart.download('venn-ultimate-power.png')
def drawThreeVenn(set1,set2,set3,set1set2Intersect,set1set3Intersect,set2set3Intersect,allIntersect,width,height,outfile,title=None,legend=None,indicateNumberInLegend=False,colors=None,htmlReport=None):
	chart=VennChart(width,height)
	chart.add_data([set1,set2,set3,set1set2Intersect,set1set3Intersect,set2set3Intersect,allIntersect])
	if title:
		chart.set_title(title)
	if legend:
		legendOut=legend[:]
		
		if indicateNumberInLegend:
			legendOut[0]=legend[0]+" ("+str(set1)+")"
			legendOut[1]=legend[1]+" ("+str(set2)+")"
			legendOut[2]=legend[2]+" ("+str(set3)+")"
			
		chart.set_legend(legendOut)
		
	if colors:
		for i in range(0,len(colors)):
			if type(colors[i]) is not StringType:
				#probably a int tuple (4 or 3)
				#print >> stderr,colors[i],"is not string"
				if  type(colors[i]) is ListType or  type(colors[i]) is TupleType:
					#print >> stderr,"is list or tuple"
					hexCode=""
					for color_component in colors[i]:
						hexCode+=twodigithex(color_component)
					colors[i]=hexCode
		
		#print >> stderr,colors
		chart.set_colours(colors)
	
	chart.download(outfile)

	if htmlReport:
		fout = open(htmlReport,"w")
		set1only=set1-set1set2Intersect-set1set3Intersect+allIntersect
		set2only=set2-set1set2Intersect-set2set3Intersect+allIntersect
		set3only=set3-set1set3Intersect-set2set3Intersect+allIntersect
		
		if not title:
			title=""
		if not legend:
			legend=["set1","set2","set3"]
		
		print >> fout, '<html><head><title>%s</title></head><body><h1>%s</h1><table width=%d><tr><td colspan=2><img src="%s"></td></tr><tr bgcolor="#AAAAAA"><td>%s</td><td>%d</td></tr><tr><td>%s</td><td>%d</td></tr> <tr bgcolor="#AAAAAA">  <td>%s</td><td>%d</td></tr> <tr>  <td>%s only</td><td>%d</td></tr>  <tr bgcolor="#AAAAAA"> <td>%s only</td><td>%d</td> </tr>  <tr><td>%s only</td><td>%d</td> </tr> <tr bgcolor="#AAAAAA"> <td>%s &#x2229; %s</td><td>%d</td></tr> <tr> <td>%s &#x2229; %s</td><td>%d</td></tr> <tr bgcolor="#AAAAAA"> <td>%s &#x2229; %s</td><td>%d</td></tr> <tr> <td>%s &#x2229; %s &#x2229; %s </td><td>%d</td></tr> </body></html>' %(title,title,width,basename(outfile),legend[0],set1,legend[1],set2,legend[2],set3,legend[0],set1only,legend[1],set2only,legend[2],set3only,legend[0],legend[1],set1set2Intersect,legend[0],legend[2],set1set3Intersect,legend[1],legend[2],set2set3Intersect,legend[0],legend[1],legend[2],allIntersect)
		fout.close()
def drawTwoVenn(set1,set2,intersect,width,height,outfile,fisherU=None,title=None,legend=None,indicateNumberInLegend=False,colors=None,htmlReport=None):
	chart=VennChart(width,height)
	chart.add_data([set1,set2,0,intersect])
	if title:
		chart.set_title(title)
	if legend:
	
	
		legendOut=legend[:]
			
		if indicateNumberInLegend:
			
			legendOut[0]=legend[0]+" ("+str(set1)+")"
			legendOut[1]=legend[1]+" ("+str(set2)+")"
		chart.set_legend(legendOut)
	if colors:
		for i in range(0,len(colors)):
			if type(colors[i]) is not StringType:
				#probably a int tuple (4 or 3)
				#print >> stderr,colors[i],"is not string"
				if  type(colors[i]) is ListType or  type(colors[i]) is TupleType:
					#print >> stderr,"is list or tuple"
					hexCode=""
					for color_component in colors[i]:
						hexCode+=twodigithex(color_component)
					colors[i]=hexCode
		
		#print >> stderr,colors
		chart.set_colours(colors)
	
	
	chart.download(outfile)
	
	if fisherU:
		#build a contingency table 2x2
		
		box1=intersect
		box2=set2-intersect
		box3=set2
		box6=fisherU-set2
		box7=set1
		box8=fisherU-set1
		box9=fisherU
		box4=set1-intersect
		box5=fisherU-set1-set2+intersect
		
		fisher_pvalues=fisher.pvalue(box1,box2,box4,box5)
		
		expectedIntersect=round(float(set1)*set2/fisherU)
		
	
	
	if htmlReport:
		if not title:
			title=""
		if not legend:
			legend=["set1","set2"]
			
		fout = open(htmlReport,"w")
		print >> fout, '<html><head><title>%s</title></head><body><h1>%s</h1><table width=%d><tr><td colspan=2><img src="%s"></td></tr><tr bgcolor="#AAAAAA"><td>%s</td><td>%d</td></tr><tr><td>%s</td><td>%d</td></tr> <tr bgcolor="#AAAAAA">  <td>%s only</td><td>%d</td></tr> <tr><td>%s only</td><td>%d</td></tr> <tr bgcolor="#AAAAAA"> <td>%s &#x2229; %s</td><td>%d</td></tr>   ' %(title,title,width,basename(outfile),legend[0],set1,legend[1],set2,legend[0],set1-intersect,legend[1],set2-intersect,legend[0],legend[1],intersect)
		
		
		if fisherU:
			print >> fout, '<tr><td>Universe</td><td>%d</td></tr> <tr bgcolor="#AAAAAA"> <td>E[%s &#x2229; %s]</td><td>%d</td></tr> <tr><td>dnrichment p-value</td><td>%g</td></tr> <tr bgcolor="#AAAAAA"> <td>depletion p-value</td><td>%g</td></tr>' %(fisherU,legend[0],legend[1],expectedIntersect,fisher_pvalues.right_tail,fisher_pvalues.left_tail)
		
		print >> fout, '</body></html>'
		fout.close()
def drawTwoVenn(set1,
                set2,
                intersect,
                width,
                height,
                outfile,
                fisherU=None,
                title=None,
                legend=None,
                indicateNumberInLegend=False,
                colors=None,
                htmlReport=None):
    chart = VennChart(width, height)
    chart.add_data([set1, set2, 0, intersect])
    if title:
        chart.set_title(title)
    if legend:

        legendOut = legend[:]

        if indicateNumberInLegend:

            legendOut[0] = legend[0] + " (" + str(set1) + ")"
            legendOut[1] = legend[1] + " (" + str(set2) + ")"
        chart.set_legend(legendOut)
    if colors:
        for i in range(0, len(colors)):
            if type(colors[i]) is not StringType:
                #probably a int tuple (4 or 3)
                #print >> stderr,colors[i],"is not string"
                if type(colors[i]) is ListType or type(colors[i]) is TupleType:
                    #print >> stderr,"is list or tuple"
                    hexCode = ""
                    for color_component in colors[i]:
                        hexCode += twodigithex(color_component)
                    colors[i] = hexCode

        #print >> stderr,colors
        chart.set_colours(colors)

    chart.download(outfile)

    if fisherU:
        #build a contingency table 2x2

        box1 = intersect
        box2 = set2 - intersect
        box3 = set2
        box6 = fisherU - set2
        box7 = set1
        box8 = fisherU - set1
        box9 = fisherU
        box4 = set1 - intersect
        box5 = fisherU - set1 - set2 + intersect

        fisher_pvalues = fisher.pvalue(box1, box2, box4, box5)

        expectedIntersect = round(float(set1) * set2 / fisherU)

    if htmlReport:
        if not title:
            title = ""
        if not legend:
            legend = ["set1", "set2"]

        fout = open(htmlReport, "w")
        print >> fout, '<html><head><title>%s</title></head><body><h1>%s</h1><table width=%d><tr><td colspan=2><img src="%s"></td></tr><tr bgcolor="#AAAAAA"><td>%s</td><td>%d</td></tr><tr><td>%s</td><td>%d</td></tr> <tr bgcolor="#AAAAAA">  <td>%s only</td><td>%d</td></tr> <tr><td>%s only</td><td>%d</td></tr> <tr bgcolor="#AAAAAA"> <td>%s &#x2229; %s</td><td>%d</td></tr>   ' % (
            title, title, width, basename(outfile), legend[0], set1, legend[1],
            set2, legend[0], set1 - intersect, legend[1], set2 - intersect,
            legend[0], legend[1], intersect)

        if fisherU:
            print >> fout, '<tr><td>Universe</td><td>%d</td></tr> <tr bgcolor="#AAAAAA"> <td>E[%s &#x2229; %s]</td><td>%d</td></tr> <tr><td>dnrichment p-value</td><td>%g</td></tr> <tr bgcolor="#AAAAAA"> <td>depletion p-value</td><td>%g</td></tr>' % (
                fisherU, legend[0], legend[1], expectedIntersect,
                fisher_pvalues.right_tail, fisher_pvalues.left_tail)

        print >> fout, '</body></html>'
        fout.close()
def drawThreeVenn(set1,
                  set2,
                  set3,
                  set1set2Intersect,
                  set1set3Intersect,
                  set2set3Intersect,
                  allIntersect,
                  width,
                  height,
                  outfile,
                  title=None,
                  legend=None,
                  indicateNumberInLegend=False,
                  colors=None,
                  htmlReport=None):
    chart = VennChart(width, height)
    chart.add_data([
        set1, set2, set3, set1set2Intersect, set1set3Intersect,
        set2set3Intersect, allIntersect
    ])
    if title:
        chart.set_title(title)
    if legend:
        legendOut = legend[:]

        if indicateNumberInLegend:
            legendOut[0] = legend[0] + " (" + str(set1) + ")"
            legendOut[1] = legend[1] + " (" + str(set2) + ")"
            legendOut[2] = legend[2] + " (" + str(set3) + ")"

        chart.set_legend(legendOut)

    if colors:
        for i in range(0, len(colors)):
            if type(colors[i]) is not StringType:
                #probably a int tuple (4 or 3)
                #print >> stderr,colors[i],"is not string"
                if type(colors[i]) is ListType or type(colors[i]) is TupleType:
                    #print >> stderr,"is list or tuple"
                    hexCode = ""
                    for color_component in colors[i]:
                        hexCode += twodigithex(color_component)
                    colors[i] = hexCode

        #print >> stderr,colors
        chart.set_colours(colors)

    chart.download(outfile)

    if htmlReport:
        fout = open(htmlReport, "w")
        set1only = set1 - set1set2Intersect - set1set3Intersect + allIntersect
        set2only = set2 - set1set2Intersect - set2set3Intersect + allIntersect
        set3only = set3 - set1set3Intersect - set2set3Intersect + allIntersect

        if not title:
            title = ""
        if not legend:
            legend = ["set1", "set2", "set3"]

        print >> fout, '<html><head><title>%s</title></head><body><h1>%s</h1><table width=%d><tr><td colspan=2><img src="%s"></td></tr><tr bgcolor="#AAAAAA"><td>%s</td><td>%d</td></tr><tr><td>%s</td><td>%d</td></tr> <tr bgcolor="#AAAAAA">  <td>%s</td><td>%d</td></tr> <tr>  <td>%s only</td><td>%d</td></tr>  <tr bgcolor="#AAAAAA"> <td>%s only</td><td>%d</td> </tr>  <tr><td>%s only</td><td>%d</td> </tr> <tr bgcolor="#AAAAAA"> <td>%s &#x2229; %s</td><td>%d</td></tr> <tr> <td>%s &#x2229; %s</td><td>%d</td></tr> <tr bgcolor="#AAAAAA"> <td>%s &#x2229; %s</td><td>%d</td></tr> <tr> <td>%s &#x2229; %s &#x2229; %s </td><td>%d</td></tr> </body></html>' % (
            title, title, width, basename(outfile), legend[0], set1, legend[1],
            set2, legend[2], set3, legend[0], set1only, legend[1], set2only,
            legend[2], set3only, legend[0], legend[1], set1set2Intersect,
            legend[0], legend[2], set1set3Intersect, legend[1], legend[2],
            set2set3Intersect, legend[0], legend[1], legend[2], allIntersect)
        fout.close()