comparison mytools/venn.xml @ 9:87eb5c5ddfe9

Uploaded
author xuebing
date Fri, 09 Mar 2012 20:01:43 -0500
parents f0dc65e7f6c0
children
comparison
equal deleted inserted replaced
8:361ec1c0479d 9:87eb5c5ddfe9
1 <tool id="venn" name="Venn Diagram">
2 <description>from summary counts</description>
3 <command interpreter="python">$script_file $labels $counts $output $script</command>
4 <inputs>
5 <param name="labels" type="text" value="A,B" size="50" label="Set Labels"/>
6 <param name="counts" type="text" value="30,10,20" size="80" label="Counts in each region" help="region order: two sets: A, B, AB; three sets: A,B,C,AB,BC,AC,ABC"/>
7 </inputs>
8 <configfiles>
9 <configfile name="script_file">
10 import os
11 labels = '${labels}'.replace(' ','_').split(',')
12 counts = '${counts}'.replace(' ','').split(',')
13 counts = map(int,counts)
14 rscript = open('${script}','w')
15 rscript.write("options(warn=-1)\n")
16 rscript.write("pdf('"+"${output}"+"')\n")
17 rscript.write("library(grid)\n")
18 rscript.write("library(VennDiagram)\n")
19 if len(labels)==2:
20 for i in range(2):
21 counts[i+1] = counts[i+1]+counts[i]
22 rscript.write("venn =venn.diagram(\n\tx=list(\n\t\t"+labels[0]+"=c(1:"+str(counts[0])+","+str(counts[1]+1)+":"+str(counts[2])+"),\n\t\t"+labels[1]+"="+str(counts[0]+1)+":"+str(counts[2])+"),\n\tfilename=NULL,\n\tfill=c('red','blue'),\n\tcol='transparent',\n\talpha=0.5,\n\tlabel.col='black',\n\tcex=2,\n\tlwd=0,\n\tfontfamily='serif',\n\tfontface='bold',\n\tcat.col = c('red', 'blue'),\n\tcat.cex=2,\n\tcat.fontfamily='serif',\n\tcat.fontface='bold')\n")
23 else:
24 for i in range(6):
25 counts[i+1] = counts[i+1]+counts[i]
26 rscript.write("venn =venn.diagram(\n\tx=list(\n\t\t"+labels[0]+"=c(1:"+str(counts[0])+","+str(counts[2]+1)+":"+str(counts[3])+","+str(counts[4]+1)+":"+str(counts[6])+"),\n\t\t"+labels[1]+"=c("+str(counts[0]+1)+":"+str(counts[1])+","+str(counts[2]+1)+":"+str(counts[4])+","+str(counts[5]+1)+":"+str(counts[6])+"),\n\t\t"+labels[2]+"=c("+str(counts[1]+1)+":"+str(counts[2])+","+str(counts[3]+1)+":"+str(counts[6])+")),\n\tfilename=NULL,\n\tfill=c('red','blue','green'),\n\tcol='transparent',\n\talpha=0.5,\n\tlabel.col='black',\n\tcex=2,\n\tlwd=0,\n\tfontfamily='serif',\n\tfontface='bold',\n\tcat.col = c('red', 'blue','green'),\n\tcat.cex=2,\n\tcat.fontfamily='serif',\n\tcat.fontface='bold')\n")
27 rscript.write("grid.draw(venn)\n")
28 rscript.write("dev.off()\n")
29 rscript.close()
30 os.system("cat "+"${script}"+" | R --vanilla --slave")
31 </configfile>
32 </configfiles>
33
34 <outputs>
35 <data format="txt" name="script" label="${tool.name} on ${on_string}: (script)" />
36 <data format="pdf" name="output" label="${tool.name} on ${on_string}: (plot)" />
37
38 </outputs>
39
40 <help>
41 .. class:: infomark
42
43 This is a wrapper for R package VennDiagram. It allows you to plot two-set or three-set venn diagrams based on counts. The R script used to generate the plot is also in the output.
44
45 Input: labels for sets and counts for each region in the diagram.
46
47 A: A-only
48
49 B: B-only
50
51 C: C-only
52
53 AB: in A and B but not C
54
55 BC: in B and C but not A
56
57 AC: in A and C but not B
58
59 ABC: in A, B, and C
60
61 -----
62
63 **Example**
64
65 Labels: X,Y
66
67 Counts: 30,10,20
68
69
70 .. image:: ./static/images/venn2.png
71
72
73 Labels: A,B,C
74
75 Counts: 10,20,30,40,50,60,70
76
77
78 .. image:: ./static/images/venn3.png
79
80
81 </help>
82 </tool>