-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plotter_multifile_Cluster_20170227_to_work_with_python_dbscan.ipf
1614 lines (1161 loc) · 46.2 KB
/
Plotter_multifile_Cluster_20170227_to_work_with_python_dbscan.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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma rtGlobals=3 // Use modern global access method and strict wave access.
function multiple()
variable numberoffolders=53
make/o/n=(numberoffolders)/T filelist
filelist[0]="BirdBox2:iPSCs_pFTAA:Trip:29:"
filelist[1]="BirdBox2:iPSCs_pFTAA:Trip:0:"
filelist[2]="BirdBox2:iPSCs_pFTAA:Trip:1:"
filelist[3]="BirdBox2:iPSCs_pFTAA:Trip:2:"
filelist[4]="BirdBox2:iPSCs_pFTAA:Trip:3:"
filelist[5]="BirdBox2:iPSCs_pFTAA:Trip:4:"
filelist[6]="BirdBox2:iPSCs_pFTAA:Trip:5:"
filelist[7]="BirdBox2:iPSCs_pFTAA:Trip:6:"
filelist[8]="BirdBox2:iPSCs_pFTAA:Trip:7:"
filelist[9]="BirdBox2:iPSCs_pFTAA:Trip:8:"
filelist[10]="BirdBox2:iPSCs_pFTAA:Trip:9:"
filelist[11]="BirdBox2:iPSCs_pFTAA:Trip:10:"
filelist[12]="BirdBox2:iPSCs_pFTAA:Trip:11:"
filelist[13]="BirdBox2:iPSCs_pFTAA:Trip:12:"
filelist[14]="BirdBox2:iPSCs_pFTAA:Trip:13:"
filelist[15]="BirdBox2:iPSCs_pFTAA:Trip:14:"
filelist[16]="BirdBox2:iPSCs_pFTAA:Trip:15:"
filelist[17]="BirdBox2:iPSCs_pFTAA:Trip:16:"
filelist[18]="BirdBox2:iPSCs_pFTAA:Trip:17:"
filelist[19]="BirdBox2:iPSCs_pFTAA:Trip:18:"
filelist[20]="BirdBox2:iPSCs_pFTAA:Trip:19:"
filelist[21]="BirdBox2:iPSCs_pFTAA:Trip:20:"
filelist[22]="BirdBox2:iPSCs_pFTAA:Trip:21:"
filelist[23]="BirdBox2:iPSCs_pFTAA:Trip:23:"
filelist[24]="BirdBox2:iPSCs_pFTAA:Trip:24:"
filelist[25]="BirdBox2:iPSCs_pFTAA:Trip:25:"
filelist[26]="BirdBox2:iPSCs_pFTAA:Trip:26:"
filelist[27]="BirdBox2:iPSCs_pFTAA:Trip:27:"
filelist[28]="BirdBox2:iPSCs_pFTAA:Trip:28:"
filelist[29]="BirdBox2:iPSCs_pFTAA:Cont:29:"
filelist[30]="BirdBox2:iPSCs_pFTAA:Cont:0:"
filelist[31]="BirdBox2:iPSCs_pFTAA:Cont:2:"
filelist[32]="BirdBox2:iPSCs_pFTAA:Cont:3:"
filelist[33]="BirdBox2:iPSCs_pFTAA:Cont:5:"
filelist[34]="BirdBox2:iPSCs_pFTAA:Cont:6:"
filelist[35]="BirdBox2:iPSCs_pFTAA:Cont:7:"
filelist[36]="BirdBox2:iPSCs_pFTAA:Cont:8:"
filelist[37]="BirdBox2:iPSCs_pFTAA:Cont:9:"
filelist[38]="BirdBox2:iPSCs_pFTAA:Cont:12:"
filelist[39]="BirdBox2:iPSCs_pFTAA:Cont:13:"
filelist[40]="BirdBox2:iPSCs_pFTAA:Cont:14:"
filelist[41]="BirdBox2:iPSCs_pFTAA:Cont:15:"
filelist[42]="BirdBox2:iPSCs_pFTAA:Cont:16:"
filelist[43]="BirdBox2:iPSCs_pFTAA:Cont:19:"
filelist[44]="BirdBox2:iPSCs_pFTAA:Cont:20:"
filelist[45]="BirdBox2:iPSCs_pFTAA:Cont:21:"
filelist[46]="BirdBox2:iPSCs_pFTAA:Cont:22:"
filelist[47]="BirdBox2:iPSCs_pFTAA:Cont:23:"
filelist[48]="BirdBox2:iPSCs_pFTAA:Cont:24:"
filelist[49]="BirdBox2:iPSCs_pFTAA:Cont:25:"
filelist[50]="BirdBox2:iPSCs_pFTAA:Cont:26:"
filelist[51]="BirdBox2:iPSCs_pFTAA:Cont:27:"
filelist[52]="BirdBox2:iPSCs_pFTAA:Cont:28:"
variable f
for(f=0;f<numberoffolders;f+=1)
setdatafolder root:
string folder=num2str(f)
//PRINT FOLDER
newdatafolder/s $folder
string path=filelist[f]
loadmult(path)
imageclusterplot(path)
clusteranal()
savewithheader(path)
countpoints()
xyextract()
distances()
plotdl(path)
//Particle_analysis(path)
savedlplot(path)
setdatafolder root:
endfor
variable first=0,last=f
post_analyse(first,last)
end
//////////LOAD MULTIPLE FILES////////////
function loadmult(path)
string path
string load1=path+"Resultsthresh_mask_20_0.5.csv"
print load1
LoadWave/J/D/W/K=0/A load1
wave precision
if(dimsize(precision,0)>0)
duplicate/o precision,precision__nm_
endif
//wave xw
//duplicate/o xw,cluster
//killwaves xw
//string load2=path+"fitresults.txt"
//print load2
//LoadWave/J/D/W/K=0/A load2
end
///////////Output images//////////////
function imageclusterplot(path) // This needs a prior code that outputs all localisations as xw, yw, precision.
string path
wave xw,yw,precision__nm_,cluster
duplicate/o precision__nm_,precision // I only need the x and y-coords and precision values.
variable scale=8 // Change this for different scale.
variable size=scale*512 // This is the size of the matrix to make.
make/o/n=(size,size) Image=0,imagegauss=0 // Make matrices for data.
variable a,b,c // Some originally named variables.
/////////// THIS PART TO PLOT LOCALISATIONS ONLY /////////////////////////
for(a=0;a<(dimsize(xw,0));a+=1) // Go through all of localisations.
if(cluster[a]>-1)
variable xcoord=round(scale*(xw[a])) // Multiply by 8 to fit in matrix.
variable ycoord=round(scale*(yw[a]))
image[xcoord][ycoord]+=1 // Add 1 to the matrix- localisation only.
endif
endfor
///// THIS PART FOR 2D GAUSS- width = precision image ///////////////////
make/o/n=(11,11) tempgauss // This is where I'm going to store each Gaussian that's fitted. Need to make an odd number in size to ensure there is a central pixel.
duplicate/o precision,precisionpixel // Notekeeping- I did this just so that I could confirm that the precisions are correct when converted to pixels (from nm)
for(a=0;a<(dimsize(xw,0));a+=1)
if(cluster[a]>-1)
xcoord=round(scale*(xw[a]))
ycoord=round(scale*(yw[a]))
variable precis=precision[a]
// Need to convert precision to pixels
variable pixelsize=109 // Change pixel size here if different.
variable pixelsizeinexpanded=109/scale // This is new pixel size with different scale.
variable precispixel=precis/pixelsizeinexpanded // This is now the precision in pixels rather than nm.
precisionpixel[a]=precispixel // Store for notekeeping.
duplicate/o tempgauss,tempfit // I need to make a wave to store the fit in. Idiosynchratic nature of Igor!!
K0 = 0;K1 = 1;K2 = 5;K3 = precispixel;K4 = 5;K5 = precispixel;K6 = 0; // These are the fixed variables to fit the 2D Gaussian to - amplitude = 1, x-width,ywidth = precision (in pixels)
CurveFit/H="1111111"/q Gauss2D tempgauss /D=tempfit // Fit the curve, and output the fit to tempfit wave.
for(b=0;b<11;b+=1) // Place this in the original gaussimage.
for(c=0;c<11;c+=1)
imagegauss[xcoord-5+b][ycoord-5+c]=imagegauss[xcoord-5+b][ycoord-5+c]+tempfit[b][c] // Note that it's an add function - allows gauss to overlap.
endfor
endfor
endif
endfor
string tosave=path+"imagegausspython.txt"
Save/O/J/M="\n" imagegauss as tosave // Saves the file.
end
///////////////////////////////////////
function load_dan()
LoadWave/J/D/W/K=0/A
wave wave0,wave1,wave2
duplicate/o wave0,xw
duplicate/o wave1,yw
duplicate/o wave2,precision__nm_
end
////// Without clusters
function imageplot() // This needs a prior code that outputs all localisations as xw, yw, precision.
wave xw,yw,precision__nm_
duplicate/o precision__nm_,precision // I only need the x and y-coords and precision values.
variable scale=8 // Change this for different scale.
variable size=scale*512 // This is the size of the matrix to make.
make/o/n=(size,size) Image=0,imagegauss=0 // Make matrices for data.
variable a,b,c // Some originally named variables.
/////////// THIS PART TO PLOT LOCALISATIONS ONLY /////////////////////////
for(a=0;a<(dimsize(xw,0));a+=1) // Go through all of localisations.
variable xcoord=round(scale*(xw[a])) // Multiply by 8 to fit in matrix.
variable ycoord=round(scale*(yw[a]))
image[xcoord][ycoord]+=1 // Add 1 to the matrix- localisation only.
endfor
///// THIS PART FOR 2D GAUSS- width = precision image ///////////////////
make/o/n=(11,11) tempgauss // This is where I'm going to store each Gaussian that's fitted. Need to make an odd number in size to ensure there is a central pixel.
duplicate/o precision,precisionpixel // Notekeeping- I did this just so that I could confirm that the precisions are correct when converted to pixels (from nm)
for(a=0;a<(dimsize(xw,0));a+=1)
xcoord=round(scale*(xw[a]))
ycoord=round(scale*(yw[a]))
variable precis=precision[a]
// Need to convert precision to pixels
variable pixelsize=109 // Change pixel size here if different.
variable pixelsizeinexpanded=109/scale // This is new pixel size with different scale.
variable precispixel=precis/pixelsizeinexpanded // This is now the precision in pixels rather than nm.
precisionpixel[a]=precispixel // Store for notekeeping.
duplicate/o tempgauss,tempfit // I need to make a wave to store the fit in. Idiosynchratic nature of Igor!!
K0 = 0;K1 = 1;K2 = 5;K3 = precispixel;K4 = 5;K5 = precispixel;K6 = 0; // These are the fixed variables to fit the 2D Gaussian to - amplitude = 1, x-width,ywidth = precision (in pixels)
CurveFit/H="1111111"/q Gauss2D tempgauss /D=tempfit // Fit the curve, and output the fit to tempfit wave.
for(b=0;b<11;b+=1) // Place this in the original gaussimage.
for(c=0;c<11;c+=1)
imagegauss[xcoord-5+b][ycoord-5+c]=imagegauss[xcoord-5+b][ycoord-5+c]+tempfit[b][c] // Note that it's an add function - allows gauss to overlap.
endfor
endfor
endfor
Save/O/J/M="\n" imagegauss // Saves the file.
end
function clusteranal()
wave cluster,xw,yw,precision__nm_
duplicate/o precision__nm_,precision
variable cl,rows
wavestats cluster
variable length=v_max
make/o/n=(length) numberofpoints
make/o/n=1 temp_prec,temp_x,temp_y
for(cl=0;cl<length;cl+=1)
variable count=0
for(rows=0;rows<(dimsize(cluster,0));rows+=1)
if(cluster[rows]==(cl))
redimension/n=(count+1) temp_prec,temp_x,temp_y
temp_prec[count]=precision[rows]
temp_x[count]=xw[rows]
temp_y[count]=yw[rows]
count+=1
endif
endfor
string name1=num2str(cl)+"xw"
string name2=num2str(cl)+"yw"
string name3=num2str(cl)+"precision"
numberofpoints[cl]=count
duplicate/o temp_prec,$name3
duplicate/o temp_x,$name1
duplicate/o temp_y,$name2
endfor
Make/N=25/O numberofpoints_Hist;DelayUpdate
Histogram/B={0,25,25} numberofpoints,numberofpoints_Hist;DelayUpdate
Display numberofpoints_Hist
SetAxis bottom *,1000
ModifyGraph mode=5
print median(numberofpoints)
end
function clusterloaddan()
LoadWave/J/D/W/K=0/A
wave xw
duplicate/o xw,cluster
killwaves xw
LoadWave/J/D/W/K=0/A
wave wave0,wave1,wave2
duplicate/o wave0,xw
duplicate/o wave1,yw
duplicate/o wave2,precision__nm_
end
function plot_number(num)
variable num
string name1=num2str(num)+"xw"
string name2=num2str(num)+"yw"
string name3=num2str(num)+"precision"
duplicate/o $name3,temp_prec
duplicate/o $name1,temp_x
duplicate/o $name2,temp_y
make/o/n=(11,11) tempgauss // This is where I'm going to store each Gaussian that's fitted. Need to make an odd number in size to ensure there is a central pixel.
variable a,b,c,scale=8
make/o/n=(scale*512,scale*512) t_imagegauss=0
duplicate/o temp_prec,precisionpixel // Notekeeping- I did this just so that I could confirm that the precisions are correct when converted to pixels (from nm)
for(a=0;a<(dimsize(temp_x,0));a+=1)
variable xcoord=round(scale*(temp_x[a]))
variable ycoord=round(scale*(temp_y[a]))
variable precis=temp_prec[a]
// Need to convert precision to pixels
variable pixelsize=109 // Change pixel size here if different.
variable pixelsizeinexpanded=109/scale // This is new pixel size with different scale.
variable precispixel=precis/pixelsizeinexpanded // This is now the precision in pixels rather than nm.
precisionpixel[a]=precispixel // Store for notekeeping.
duplicate/o tempgauss,tempfit // I need to make a wave to store the fit in. Idiosynchratic nature of Igor!!
K0 = 0;K1 = 1;K2 = 5;K3 = precispixel;K4 = 5;K5 = precispixel;K6 = 0; // These are the fixed variables to fit the 2D Gaussian to - amplitude = 1, x-width,ywidth = precision (in pixels)
CurveFit/H="1111111"/q Gauss2D tempgauss /D=tempfit // Fit the curve, and output the fit to tempfit wave.
for(b=0;b<11;b+=1) // Place this in the original gaussimage.
for(c=0;c<11;c+=1)
t_imagegauss[xcoord-5+b][ycoord-5+c]=t_imagegauss[xcoord-5+b][ycoord-5+c]+tempfit[b][c] // Note that it's an add function - allows gauss to overlap.
endfor
endfor
endfor
wavestats temp_x
variable xmax=8*v_max
variable xmin=8*v_min
variable xrange=(xmax-xmin)
wavestats temp_y
variable ymax=8*v_max
variable ymin=8*v_min
variable yrange=(xmax-xmin)
if(yrange>xrange)
variable length=yrange
else
length=xrange
endif
newimage t_imagegauss
//AppendImage t_imagegauss
ModifyGraph tick=3,noLabel=2
SetAxis/R top (xmin-40),(xmin+length+40)
SetAxis/R left (ymin-40),(ymin+length+40)
ModifyImage t_imagegauss ctab= {*,*,YellowHot,0}
ModifyGraph width=283.465,height=283.465
end
function savewithheader(path)
string path
variable a,b,c
variable correct=0
//Load the files
make/o/n=1 all_Frame, all_origX, all_origY, all_origValue, all_Error, all_Noise, all_SNR,all_Background,all_Signal, all_Angle, all_XW, all_YW, all_X_SD, all_Y_SD, all_Precision__nm_
wave Source, Frame, origX, origY, origValue, Error, Noise, SNR,Background, Signal, Angle, XW, YW, X_SD,Y_SD, Precision__nm_,cluster
for(b=0;b<(dimsize(frame,0));b+=1)
if(cluster[b]>-1)
redimension/n=(c+1) all_Frame, all_origX, all_origY, all_origValue, all_Error, all_Noise, all_SNR,all_Background,all_Signal, all_Angle, all_XW, all_YW, all_X_SD, all_Y_SD, all_Precision__nm_
all_frame[c]=frame[b]+correct
all_origX[c]=origx[b]
all_origY[c]=origy[b]
all_origValue[c]=origvalue[b]
all_Error[c]=error[b]
all_Noise[c]=noise[b]
all_SNR[c]=snr[b]
all_Background[c]=background[b]
all_Signal[c]=signal[b]
all_Angle[c]=angle[b]
all_XW[c]=xw[b]
all_YW[c]=yw[b]
all_X_SD[c]=x_SD[b]
all_Y_SD[c]=Y_sd[b]
all_Precision__nm_[c]=Precision__nm_[b]
c+=1
endif
endfor
wavestats/q all_frame
correct=v_max
string tosave=path+"allfitswithheader_cluster_mask_20_0_5.txt"
//Save/J/M="\n"/O/W all_Frame, all_origX, all_origY, all_origValue, all_Error, all_Noise,all_Background,all_Signal, all_Angle, all_XW, all_YW, all_X_SD, all_Y_SD, all_Precision__nm_ as tosave
variable f1
Open f1 as tosave
fprintf f1, "#Localisation Results File\r#FileVersion Text.D0.E0.V2\r\r#Name Image (LSE)\r"
fprintf f1, "#Source <gdsc.smlm.ij.IJImageSource><singleFrame>0</singleFrame><extraFrames>0</extraFrames><path>/Volumes/BIRDBOX/20161012_DNAPAINT_Tau_Fids_2/1/01.tiff</path></gdsc.smlm.ij.IJImageSource>\r"
fprintf f1, "#Bounds x0 y0 w512 h512\r#Calibration <gdsc.smlm.results.Calibration><nmPerPixel>105.0</nmPerPixel><gain>55.5</gain><exposureTime>25.0</exposureTime><readNoise>0.0</readNoise><bias>500.0</bias><emCCD>false</emCCD></gdsc.smlm.results.Calibration>\r"
fprintf f1, "#Configuration <gdsc.smlm.engine.FitEngineConfiguration><fitConfiguration><fitCriteria>LEAST_SQUARED_ERROR</fitCriteria><delta>1.0E-4</delta><initialAngle>0.0</initialAngle><initialSD0>2.0</initialSD0><initialSD1>2.0</initialSD1><computeDeviations>"
fprintf f1, "false</computeDeviations><fitSolver>LVM</fitSolver><minIterations>0</minIterations><maxIterations>20</maxIterations><significantDigits>5</significantDigits><fitFunction>CIRCULAR</fitFunction><flags>20</flags><backgroundFitting>true</backgroundFitting>"
fprintf f1, "<notSignalFitting>false</notSignalFitting><coordinateShift>4.0</coordinateShift><signalThreshold>1665.0</signalThreshold><signalStrength>30.0</signalStrength><minPhotons>30.0</minPhotons><precisionThreshold>625.0</precisionThreshold><precisionUsingBackground>"
fprintf f1, "false</precisionUsingBackground><nmPerPixel>105.0</nmPerPixel><gain>55.5</gain><emCCD>false</emCCD><modelCamera>false</modelCamera><noise>0.0</noise><widthFactor>2.0</widthFactor><fitValidation>true</fitValidation><lambda>10.0</lambda><computeResiduals>false</computeResiduals>"
fprintf f1, "<duplicateDistance>0.5</duplicateDistance><bias>500.0</bias><readNoise>0.0</readNoise><maxFunctionEvaluations>1000</maxFunctionEvaluations><searchMethod>POWELL</searchMethod><gradientLineMinimisation>false</gradientLineMinimisation><relativeThreshold>1.0E-6</relativeThreshold>"
fprintf f1, "<absoluteThreshold>1.0E-16</absoluteThreshold></fitConfiguration><search>3.0</search><border>1.0</border><fitting>3.0</fitting><failuresLimit>10</failuresLimit><includeNeighbours>true</includeNeighbours><neighbourHeightThreshold>0.3</neighbourHeightThreshold><residualsThreshold>"
fprintf f1, "1.0</residualsThreshold><noiseMethod>QUICK_RESIDUALS_LEAST_MEAN_OF_SQUARES</noiseMethod><dataFilterType>SINGLE</dataFilterType><smooth><double>0.5</double></smooth><dataFilter><gdsc.smlm.engine.DataFilter>MEAN</gdsc.smlm.engine.DataFilter></dataFilter>"
fprintf f1, "</gdsc.smlm.engine.FitEngineConfiguration>\r"
fprintf f1, "#Frame\torigX\torigY\torigValue\tError\tNoise\tBackground\tSignal\tAngle\tX\tY\tXSD\tYSD\tPrecision"
wfprintf f1, "%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\r" all_Frame, all_origX, all_origY, all_origValue, all_Error, all_Noise,all_Background,all_Signal, all_Angle, all_XW, all_YW, all_X_SD, all_Y_SD, all_Precision__nm_
Close f1
//string tosave2="Macintosh HD:Users:Mathew:Desktop:indexlist.txt"
//variable f2
//open/A f2 as tosave2
//fprintf f2, "path[]=\"%s\"\r" path
//close f2
end
xyextract()
distances()
plotdl(path)
Particle_analysis(path)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////// (1) First code to run from multirun /////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function countpoints() // How many points per cluster?
wave origX,origY,cluster
variable a,b,c,z // Some variables for later operations
wavestats cluster // Number of clusters
variable cluster_max=V_max
make/o/n=(cluster_max) points_per_cluster // Table to store counts - looks at the highest cluster number in the table.
for(a=0;a<(cluster_max);a+=1)
c=0 // Reset the counter.
for(b=0;b<(dimsize(cluster,0));b+=1) // Go through all of cluster numbers
if(cluster[b]==(a)) // If the cluster number is equal to the number- add the +1 since we're not interested in cluster = 0.
c+=1 // Add 1 to c for each value that is equal to that cluster
endif
endfor
points_per_cluster[a]=c
endfor
wavestats points_per_cluster // Output the average and standard deviations of the counts per cluster.
variable average_points_per_cluster=V_avg
variable sdev_points_per_cluster=V_sdev
string avg=num2str(average_points_per_cluster)
string std=num2str(sdev_points_per_cluster)
// order the clusters by size
make/o/n=(cluster_max) ordered_points,ordered_cluster_number
duplicate/o points_per_cluster,temp
variable d=0
do
redimension/n=(d+1) ordered_points,ordered_cluster_number
ordered_points[d]=V_max
ordered_cluster_number[d]=V_maxloc
variable pos=v_maxloc
temp[pos]=0
wavestats/Q temp
d+=1
while (v_max>0) // as long as expression is TRUE
end
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////Extract X and Y co-ordinates //////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Needed to extract the x and y positions for each cluster.
function XYExtract() // Plot all clusters with colours corresponding to size.
wave ordered_cluster_number,cluster,origx,origY,xw,yw
duplicate/o xw,xp
duplicate/o yw,yp
variable a,b,c,d,f
wave cluster,precision__nm_
duplicate/o precision__nm_,precision
wavestats cluster
variable length=V_max
for(a=0;a<(dimsize(ordered_cluster_number,0));a+=1) // Looks for the highest value in the cluster.
make/o/n=1 tempx,tempy,tempprec // Need somewhere to store the data
c=0
variable cluster_number=ordered_cluster_number[a]+1 // It has to be +1, because the ordered cluster number starts from zero, yet the cluster address wave starts from 1 (zero is a non-cluster address).
for(b=0;b<(dimsize(cluster,0));b+=1) // Go through all of the localisations information
if(cluster[b]==cluster_number)
variable x=xp[b] // Set X and Y variables- from xp and yp which are the exact co-ordinates.
variable y=yp[b]
variable sig=precision[b] // Precision
redimension/n=(c+1) tempx,tempy,tempprec // Make wave longer for the files.
tempx[c]=Xp[b] // Store data into tempx and tempy
tempy[c]=yp[b]
tempprec[c]=sig
c+=1
endif
endfor
string xval="x"+num2str(a)
string yval="y"+num2str(a)
string precval="prex"+num2str(a)
duplicate/o tempx,$xval
duplicate/o tempy,$yval
duplicate/o tempprec,$precval
endfor
killwaves tempx,tempy,tempprec
end
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////// DL Plots ////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///THIS FOLLOWS THE CLUSTER ANALYSIS DONE IN THE PAPER///
// that it is 40 nm for now (which is ~0.3 pixels).
function distances()
wave cluster,origx,origy,xp,yp
variable a,b,c,d,e,f
make/o/n=1 alldistances
wavestats cluster // This is on the clusters- calculate how many clusters there are.
variable length=v_max
variable sig=0.3
make/o/n=(length) Reff // This is the effective resolution- this will be equal to sqrt(rnn^2+sigma^2), where rnn = mean n.n. distance, and sigma=mean prec
// Gould et al 2009.
make/o/n=(length) DLdist // The neighbour distance
// Molecular positions need to be colour coded in terms of local density, where the local density is defined as the number of molecules
// within 5* the mean nearest neighbour distanceof all molecules in that cluster.
// First step- find out the mean nearest neighbour distance for all molecules in each PSD:
for(a=0;a<length;a+=1) // Go through each of clusters
string xvar="X"+num2str(a) // These are the cluster waves that need using.
string yvar="Y"+num2str(a)
string precvar="prex"+num2str(a)
make/o/n=1 tempdist // Temporary wave in which to store the distances.
duplicate/o $xvar,tempx // Contains all of x-coords.
duplicate/o $yvar,tempy // Contains all of y-coords
duplicate/o $precvar,tempprec // Contains all of precisions
make/o/n=(dimsize(tempy,0)) tempcartdistance,tempNN
variable dd
for(b=0;b<(dimsize(tempx,0));b+=1)
variable cartdistance=10000000 // This is just a large start value- it will immediately be replaced by the first distance.
for(c=0;c<(dimsize(tempx,0));c+=1)
if(b==c) // Don't want to measure the distance between a point and itself- this would = 0
else
variable old_cartdistance=cartdistance // Set the variable of the old-cartdistance to the previous distance measured.
variable xlength=tempx[c]-tempx[b] // Calculate the distances between the points.
variable ylength=tempy[c]-tempy[b]
cartdistance=sqrt(xlength^2+ylength^2) // Pythag to calculate cartesian distance.
if(cartdistance<old_cartdistance) // If the newly calculated cartesian distance is less than the old one
// do nothing.
else
cartdistance=old_cartdistance // Else let the cartesian distance equal the old one. I.e. If the cart distance is longer, then replace it with
// the one from the previous run. By doing this we will get to the neirest neighbour distance eventually.
endif
endif
endfor
tempcartdistance[b]=cartdistance // This is the nearest neighbour distance for each point in that cluster now.
endfor
string toname2="Min"+num2str(a) // Just need to copy this to its own wave now.
duplicate/o tempcartdistance,$toname2
wavestats/q tempcartdistance // Perform statisitics on it to get the average.
variable thresh=5*v_avg // This is the threshold distance
dldist[a]=thresh // Store this distance in the dldistance wave.
variable tempcartnm=109*v_avg
wavestats/q tempprec // Get stats on the s.r. precisions.
variable median_prec=median(tempprec)
variable median_cart=109*median(tempcartdistance)
//variable reffective=sqrt(tempcartnm^2+v_avg^2) // As defined in paper- the effective resolution.
variable reffective=sqrt(median_prec^2+median_cart^2)
reff[a]=reffective // Store in the wave. Gould et al. 2009.
// We now need to calculate how many neighbours each point has within a range of the threshold distance.
for(b=0;b<(dimsize(tempx,0));b+=1) // Go through each of the points.
for(c=0;c<(dimsize(tempx,0));c+=1) // Go through each of the points again to compare with the previous.
if(b==c) // Don't compare with self.
else
xlength=tempx[c]-tempx[b] // Calculate the lengths.
ylength=tempy[c]-tempy[b]
cartdistance=sqrt(xlength^2+ylength^2) // Calculate the cartesian distance.
if(cartdistance<thresh)
dd+=1 // If within the radius, then add 1 to variable dd.
endif
endif
endfor
tempNN[b]=dd // Save into temporary file.
dd=0 // Reset variable
endfor
string toname="DL"+num2str(a)
duplicate/o tempNN,$toname // Rename as required. This cotains information about all of the nearest neighbours.
endfor
end
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////// Make pretty images /////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function plotdl(path)
string path
// Need to make an SR image that Matt likes.
variable scale = 8 // Set the scale
variable pixelwidth=109 // nm pixel
make/o/n=((512*scale),(512*scale)) DL_Image=0,L_image=0,NN_Image=0 // Make the image- the dimensions may need to be altered, depending on the size of the image (this should be 10x the dimensions of the image)
wave xw
wavestats xw
variable length=v_max
variable a,b,c
make/o/n=1 xcoords,ycoords,NumNN,PrecisionList,NNdist,Clusternumber
for(a=0;a<length;a+=1)
string xlist="x"+num2str(a) // xcoord
string ylist="y"+num2str(a) // ycoord
string dlist="dl"+num2str(a) // no of nns
string preclist="prex"+num2str(a) // precision for sr fit
string minlist="min"+num2str(a) // nearest neighbour distance
duplicate/o $xlist,tempx
duplicate/o $ylist,tempy
duplicate/o $dlist,tempd
duplicate/o $preclist,tempprec
duplicate/o $minlist,tempmin
for(b=0;b<(dimsize(tempx,0));b+=1)
redimension/n=(c+1) xcoords,ycoords,NNdist,PrecisionList,NumNN,Clusternumber
xcoords[c]=tempx[b]
ycoords[c]=tempy[b]
NumNN[c]=tempd[b]
PrecisionList[c]=tempprec[b]
NNdist[c]=tempmin[b]*109
clusternumber[c]=a+1
c+=1
endfor
endfor
string tosave=path+"All_Localisation_Information.txt"
Save/O/J/M="\n"/W Clusternumber,xcoords,ycoords,NNdist,PrecisionList,NumNN as tosave
variable aa
for(a=0;a<(dimsize(xcoords,0));a+=1) // Populate the matrix
variable xpos=round(scale*(xcoords[a])) // Get the co-ordinates
variable ypos=round(scale*(ycoords[a]))
DL_image[xpos][ypos]=DL_image[xpos][ypos]+NumNN[a] // Populate the matrix
L_image[xpos][ypos]+=1
endfor
for(a=0;a<(dimsize(dl_image,0));a+=1)
for(b=0;b<(dimsize(dl_image,1));b+=1)
if(L_image[a][b]>0)
NN_image[a][b]=DL_image[a][b]/L_image[a][b]
else
NN_image[a][b]=0
endif
endfor
endfor
wavestats/q xcoords
variable xmin=v_min
variable xmax=v_max
wavestats/q ycoords
variable ymin=v_min
variable ymax=V_max
wave dldist,reff,points_per_cluster
duplicate/o DLdist,DL_Distance
for(a=0;a<(dimsize(dldist,0));a+=1)
DL_Distance[a]=109*DL_Distance[a]
endfor
string tosave2=path+"All_Cluster_Information_all.txt"
Save/O/J/M="\n"/W points_per_cluster,Reff,DL_Distance as tosave2
string image1=path+"NN_Image_all.tif"
string image2=path+"SR_Image_all.tif"
ImageSave/O/F/T="TIFF" NN_Image as image1
ImageSave/O/F/T="TIFF" L_Image as image2
end
function kill()
variable winMask;
variable i,n;
variable all=0x1000+0x40+0x10+0x4+0x2+0x1;
string theWins;
winMask = !winMask ? all : winMask;
theWins = winList("*",";","WIN:"+num2iStr(winMask & all));
for(i=0,n=itemsInList(theWins,";") ; i<n ; i+=1)
doWindow/K $stringFromList(i,theWins,";");
endfor;
end
macro close_windows()
kill()
end
macro plot()
kill()
plotall()
clusterplotpaper()
end
function plotall()
variable clustnumber
wave NN_image
NewImage/K=0 NN_Image
ModifyImage NN_Image ctab={*,*,Rainbow,0}
ModifyImage NN_Image ctab= {*,*,Rainbow,1}
SetDrawLayer ProgFront
SetDrawEnv linefgc= (65535,65535,65535),fillpat= 0,xcoord= top,ycoord= left, save
variable c
wave xw
wavestats xw
variable maxi=v_max
for(c=0;c<(maxi);c+=1)
string xlist="x"+num2str(c)
string ylist="y"+num2str(c)
string dllist="dl"+num2str(c)
duplicate/o $xlist,tempx
duplicate/o $ylist,tempy
wavestats/q tempx
//variable xmin=round(v_min-100)*8
//variable xmax=round(v_max-100)*8
//variable xdiff=round(v_max-v_min)
variable xmin=round(v_min)*8
variable xmax=round(v_max)*8
variable xdiff=round(v_max-v_min)
wavestats/q tempy
//variable ymin=round(v_min-100)*8
//variable ymax=round(v_max-100)*8
//variable ydiff=round(v_max-v_min)
variable ymin=round(v_min)*8
variable ymax=round(v_max)*8
variable ydiff=round(v_max-v_min)
DrawRect xmin,ymin,xmax,ymax
string clu=num2str(c+1)
SetDrawEnv textrgb= (65535,65535,65535),fsize= 10;DelayUpdate
DrawText xmax,ymax,clu
//print xmin
//print xmax
endfor
end
function clusterplot()
variable clustnumber
Prompt clustnumber, "Cluster to plot: " // Set prompt for x param
DoPrompt "Cluster", clustnumber
if (V_Flag)
return -1 // User canceled
endif
string xlist="x"+num2str(clustnumber)
string ylist="y"+num2str(clustnumber)
string dllist="dl"+num2str(clustnumber)
duplicate/o $xlist,tempx
duplicate/o $ylist,tempy
duplicate/o $dllist,tempd
variable scale=8
wavestats tempx
variable xmin=round(v_min)
variable xmax=round(v_max)
variable xdiff=round(v_max-v_min)
wavestats tempy
variable ymin=round(v_min)
variable ymax=round(v_max)
variable ydiff=round(v_max-v_min)
make/o/n=(scale*(xdiff+2),scale*(ydiff+2)) clu_DLimage=0,clu_Limage=0,clu_NNimage=0
variable a
for(a=0;a<(dimsize(tempx,0));a+=1) // Populate the matrix
variable xpos=round(scale*(tempx[a]-xmin+1)) // Get the co-ordinates
variable ypos=round(scale*(tempy[a]-ymin+1))
clu_DLimage[xpos][ypos]=Clu_DLimage[xpos][ypos]+tempd[a] // Populate the matrix
clu_Limage[xpos][ypos]+=1
endfor
variable b
for(a=0;a<(dimsize(clu_dlimage,0));a+=1)
for(b=0;b<(dimsize(clu_dlimage,1));b+=1)
if(Clu_Limage[a][b]>0)
Clu_NNimage[a][b]=Clu_DLimage[a][b]/clu_Limage[a][b]
else
clu_NNimage[a][b]=0
endif
endfor
endfor
Display;AppendMatrixContour clu_NNimage
ModifyContour clu_NNimage labels=0,autoLevels={*,*,100}
ModifyGraph mode=3,marker=19,msize=1
ModifyContour clu_NNimage autoLevels={*,*,10}
ModifyContour clu_NNimage autoLevels={*,*,50}
ModifyGraph mode=3,marker=19,msize=2
ColorScale/C/N=text0/A=MC ctab={0,100,Rainbow,0}
ColorScale/C/N=text0/E
ColorScale/C/N=text0/A=MB/X=0.00/Y=0.00 vert=0
ModifyContour clu_NNimage ctabLines={*,*,Rainbow,1}
newimage clu_NNimage
ModifyImage clu_NNimage ctab={*,*,Rainbow,0}
ModifyImage clu_NNimage ctab= {*,*,Grays,0}
ImageThreshold/T=40 clu_nnimage
wave M_imagethresh
newimage M_imagethresh
ImageAnalyzeParticles /E/W/Q/M=3/A=10 stats,M_imageThresh
end
macro plotallnice()
combineall()
clusterplotpaperall()
end
function combineall()
make/o/n=1 allx,ally,alldl
variable a,b,c,d
wave xw
wavestats xw
variable tot=v_max
for(a=0;a<tot;a+=1)
string xlist="x"+num2str(a)
string ylist="y"+num2str(a)
string dllist="dl"+num2str(a)
duplicate/o $xlist,tempx
duplicate/o $ylist,tempy
duplicate/o $dllist,tempd
for(b=0;b<(dimsize(tempx,0));b+=1)
redimension/n=(c+1) allx,ally,alldl
allx[c]=tempx[b]
ally[c]=tempy[b]
alldl[c]=tempd[b]
c+=1
endfor
endfor
end
function clusterplotpaperall()
variable upper=200
Prompt Upper, "Upper value for scale: " // Set prompt for x param
DoPrompt "Upper", upper
if (V_Flag)
return -1 // User canceled
endif
wave allx,ally,alldl
duplicate/o allx,tempx
duplicate/o ally,tempy
duplicate/o alldl,tempd
display tempx vs tempy
// Need to go through and plot a different color for each different density- i.e. 1 NN - Purple 100 NN - Red
// Get colors wave:
ColorTab2Wave Rainbow // Make colour table.
wave m_colors
variable increment=upper/100
display
variable a,b,e=0
for(a=0;a<upper;a+=increment)
string xcol="xco"+num2str(a)
string ycol="yco"+num2str(a)
make/o/n=1 tempxc,tempyc
variable c=0
for(b=0;b<(dimsize(tempd,0));b+=1)
if(tempd[b]<(a+increment)&&tempd[b]>(a))
redimension/n=(c+1) tempxc,tempyc
tempxc[c]=tempx[b]
tempyc[c]=tempy[b]
c+=1
endif
endfor
duplicate/o tempxc,$xcol
duplicate/o tempyc,$ycol
appendtograph $ycol vs $xcol
variable r=m_colors[99-e][0]
variable g=m_colors[99-e][1]
variable bl=m_colors[99-e][2]
ModifyGraph rgb($ycol)=(r,g,bl)
e+=1