-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWafflePlots.ipf
286 lines (249 loc) · 7.95 KB
/
WafflePlots.ipf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#pragma TextEncoding = "UTF-8"
#pragma rtGlobals=3 // Use modern global access method and strict wave access.
#pragma DefaultTab={3,20,4} // Set default tab width in Igor Pro 9 and later
#include "PXPUtils"
#include <ColorWaveEditor>
// Waffle Plots
// Show proportions in a waffle style plot instead of using a Venn diagram
// Intended for use to display colocalisation data - from two channels
// Limitations:
// Uses circles only (any shape is possible but requires more development)
// Shows two groups and their intersection only (hard coded to color green/yellow/red)
// Example usage:
//WaffleMaker(33,12,62,9,0)
//WaffleMaker(11,1,57,9,1)
//WaffleMaker(0,0,55,8,2)
//EqualiseWaffles() // makes all waffles the same size
//PXPUtils#MakeTheLayouts("wafflePlot",0,6, alphaSort = 1, saveIt = 0)
////////////////////////////////////////////////////////////////////////
// Menu items
////////////////////////////////////////////////////////////////////////
Menu "Macros"
"Equalise Waffles", /Q, EqualiseWaffles()
Submenu "Waffle Colors"
Submenu "Presets"
"Green-Yellow-Red", /Q, RemakeColorWave("GYR")
"Green-Cyan-Magenta", /Q, RemakeColorWave("GCM")
"Tol 1", /Q, RemakeColorWave("Tol1")
"Tol 2", /Q, RemakeColorWave("Tol2")
"Wong 1", /Q, RemakeColorWave("Wong1")
"Wong 2", /Q, RemakeColorWave("Wong2")
End
"User Selection", /Q, UserControlForRecoloring()
"Restore Last Color Scheme", /Q, RestoreLast()
End
Submenu "Waffle Symbols"
"Circles Filled", /Q, ChangeSymbols(19)
"Circles Open", /Q, ChangeSymbols(8)
"Squares Filled", /Q, ChangeSymbols(16)
"Specify...", /Q, SpecifySymbols()
"Change Size", /Q, SpecifySize()
End
End
////////////////////////////////////////////////////////////////////////
// Master functions and wrappers
////////////////////////////////////////////////////////////////////////
/// @param aa Variable number of green spots
/// @param anb Variable number of yellow spots (intersection/colocalisation)
/// @param bb Variable number of red spots
/// @param col Variable number of columns (rows are set by total number of spots)
/// @param iter Int Plot number (allows for recreating/overwriting)
Function WaffleMaker(aa,anb,bb,col,iter)
Variable aa, anb, bb, col, iter
aa = round(aa)
anb = round(anb)
bb = round(bb)
col = round(col)
iter = round(iter)
Variable total = aa + anb + bb
Variable row = ceil(total / col)
// xy coords for waffle plot
Make/O/N=(row * col,2) $("waffleXY_" + num2str(iter))
Wave/Z wXY = $("waffleXY_" + num2str(iter))
wXY[][0] = mod(p,col) //x
wXY[][1] = floor(p / col) //y
// set colors for waffle plot
Make/O/N=(row * col) $("waffleZ_" + num2str(iter)) = 0
Wave/Z wZ = $("waffleZ_" + num2str(iter))
if(aa != 0)
wZ[0,aa - 1] = 1 // bit 0 set
endif
if(anb != 0)
wZ[aa,aa + anb - 1] = 3 // bit 0 and bit 1 set
endif
if(bb != 0)
wZ[aa + anb,total - 1] = 2 // bit 1 set
endif
// assemble colorWave if not already present
WAVE/Z colorWave
if(!WaveExists(colorWave))
// make colorWave - easier to write in other orientation then transpose
Make/O/N=(3,4) colorWave = {{230,230,230},{0,166,81},{237,28,36},{255,199,32}}
colorWave *= 257 // convert to 16-bit
MatrixTranspose colorWave
endif
DisplayWaffle("wafflePlot" + "_" + num2str(iter),wXY,wZ)
End
Function DisplayWaffle(plotName,xyWave,zWave)
String plotName
Wave xyWave, zWave
WAVE/Z colorWave
WaveStats/RMD=[][0]/Q xyWave
Variable col = V_max + 1
WaveStats/RMD=[][1]/Q xyWave
Variable row = V_max + 1
KillWindow/Z $plotName
Display/N=$plotName xyWave[][1] vs xyWave[][0]
ModifyGraph/W=$plotName mode=3,marker=19
SetAxis/W=$plotName left row - 0.5,-0.5
SetAxis/W=$plotName bottom -0.5, col - 0.5
ModifyGraph/W=$plotName height={Plan,1,left,bottom}
ModifyGraph/W=$plotName msize=4
ModifyGraph/W=$plotName noLabel=2,axThick=0
ModifyGraph/W=$plotName margin=2
ModifyGraph/W=$plotName zColor($NameOfWave(xyWave))={zWave,*,*,cindexRGB,0,colorWave}
End
Function EqualiseWaffles()
// find size of biggest waffle
String wList = WaveList("waffleXY*",";","")
Variable nWaves = ItemsInList(wList)
Variable maxRow = 0, maxCol = 0, row, col
Variable i
for(i = 0; i < nWaves; i += 1)
WaveStats/RMD=[][0]/Q $StringFromList(i, wList)
maxCol = max(maxCol,V_max + 1)
WaveStats/RMD=[][1]/Q $StringFromList(i, wList)
maxRow = max(maxRow,V_max + 1)
endfor
String wName
for(i = 0; i < nWaves; i += 1)
wName = StringFromList(i, wList)
Wave w = $wName
WaveStats/RMD=[][0]/Q w
col = V_max + 1
WaveStats/RMD=[][1]/Q w
row = V_max + 1
if(col < maxCol || row < maxRow)
ResizeWaffle(w,maxRow,maxCol)
endif
endfor
End
Function ResizeWaffle(m0,row,col)
Wave m0
Variable row, col
if(DimSize(m0,0) > row * col)
Print NameOfWave(m0), "too many points"
return -1
endif
String xyWaveName = NameOfWave(m0)
Make/O/N=(row * col, 2) $xyWaveName
Wave m0 = $xyWaveName
m0[][0] = mod(p,col) //x
m0[][1] = floor(p / col) //y
String zWaveName = ReplaceString("waffleXY_",xyWaveName,"waffleZ_")
Wave zW = $zWaveName
Duplicate/O/FREE zW, tempW
Make/O/N=(row * col) $zWaveName = 0
Wave zW = $zWaveName
zW[0,DimSize(tempW,0) - 1] = tempW[p]
DisplayWaffle(ReplaceString("waffleXY_",xyWaveName,"wafflePlot_"),m0,zW)
return 0
End
////////////////////////////////////////////////////////////////////////
// Utility functions
////////////////////////////////////////////////////////////////////////
Function RemakeColorWave(colorStr)
String colorStr
SetDataFolder root:
strswitch(colorStr)
case "GYR" :
Make/O/N=(3,4) colorWave = {{230,230,230},{0,166,81},{237,28,36},{255,199,32}}
break
case "GCM" :
Make/O/N=(3,4) colorWave = {{230,230,230},{0,166,81},{193,0,102},{4,119,146}}
break
case "Tol1" :
Make/O/N=(3,4) colorWave = {{187,187,187},{34,136,51},{238,102,119},{204,187,68}}
break
case "Tol2" :
Make/O/N=(3,4) colorWave = {{187,187,187},{34,136,51},{170,51,119},{102,204,238}}
break
case "Wong1" :
//https://www.nature.com/articles/nmeth.1618
// Bluish Green, Yellow, Vermillion
Make/O/N=(3,4) colorWave = {{230,230,230},{0,158,115},{213,94,0},{240,228,66}}
break
case "Wong2" :
// Bluish green, Reddish purple, Sky blue
Make/O/N=(3,4) colorWave = {{230,230,230},{0,158,115},{204,121,167},{86,180,233}}
break
endswitch
colorWave *= 257 // convert to 16-bit
MatrixTranspose colorWave
End
Function UserControlForRecoloring()
SetDataFolder root:
WAVE/Z colorWave = root:colorWave
if(!WaveExists(colorWave))
DoAlert 0, "3-column colorwave required"
return -1
endif
Duplicate/O colorWave, colorWave_BKP
// present dialog to work on recoloring
CWE_MakeClientColorEditor(colorWave, 0, 65535, "Edit Colors","ColorWave","RecolorAllPlots")
return 0
End
Function RestoreLast()
SetDataFolder root:
WAVE/Z colorWave, colorWave_BKP
if(!WaveExists(colorWave))
DoAlert 0, "3-column colorwave required"
return -1
endif
if(!WaveExists(colorWave_BKP))
DoAlert 0, "No backup colorwave found"
return -1
endif
Duplicate/O colorWave_BKP,colorWave
return 0
End
Function ChangeSymbols(sym)
Variable sym
String WindowList = WinList("wafflePlot*", ";", "WIN:1")
Variable nWindows = ItemsInList(WindowList)
Variable i
for(i = 0; i < nWindows; i += 1)
ModifyGraph/W=$(StringFromList(i,WindowList)) marker=sym
endfor
DoWindow/F/Z allWafflePlotLayout
End
Function SpecifySymbols()
Variable symbolNum = 19
Prompt symbolNum, "Symbol Number"
DoPrompt "Enter new symbol", symbolNum
if(V_Flag)
return -1
endif
ChangeSymbols(symbolNum)
DoWindow/F/Z allWafflePlotLayout
End
Function ChangeSize(size)
Variable size
String WindowList = WinList("wafflePlot*", ";", "WIN:1")
Variable nWindows = ItemsInList(WindowList)
Variable i
for(i = 0; i < nWindows; i += 1)
ModifyGraph/W=$(StringFromList(i,WindowList)) msize=size
endfor
DoWindow/F/Z allWafflePlotLayout
End
Function SpecifySize()
Variable sizeNum = 4
Prompt sizeNum, "Size (default = 4, 0 for Auto)"
DoPrompt "Enter new size", sizeNum
if(V_Flag)
return -1
endif
ChangeSize(sizeNum)
DoWindow/F/Z allWafflePlotLayout
End