1 package com.github.celldynamics.quimp.plugin.protanalysis;
2
3 import java.awt.event.ActionEvent;
4 import java.lang.reflect.Field;
5 import java.util.ArrayList;
6
7 import com.github.celldynamics.quimp.CellStats;
8 import com.github.celldynamics.quimp.FrameStatistics;
9 import com.github.celldynamics.quimp.QParamsQconf;
10 import com.github.celldynamics.quimp.filesystem.QconfLoader;
11 import com.github.celldynamics.quimp.filesystem.StatsCollection;
12
13 import ij.gui.Plot;
14
15
16
17
18
19
20
21 @SuppressWarnings("serial")
22 public class ActionPlot2d extends ProtAnalysisAbstractAction {
23
24
25
26
27
28
29
30
31 public ActionPlot2d(String name, String desc, ProtAnalysisUi ui) {
32 super(name, desc, ui);
33 }
34
35
36
37
38
39
40
41
42 @Override
43 public void actionPerformed(ActionEvent e) {
44 QconfLoader qconfLoader = ui.getModel().getQconfLoader();
45 plot(qconfLoader);
46 }
47
48 void plot(QconfLoader qconfLoader) {
49 int h = options.selActiveCellPlot.getValue();
50 StatsCollection stats =
51 ((QParamsQconf) qconfLoader.getQp()).getLoadedDataContainer().getStats();
52
53 try {
54
55 if (options.chbXcentrPlot.booleanValue()) {
56 plotCentroidParamVsFrame("centroid-x", stats.getStatCollection().get(h), "X");
57 }
58 if (options.chbYcentrPlot.booleanValue()) {
59 plotCentroidParamVsFrame("centroid-y", stats.getStatCollection().get(h), "Y");
60 }
61 if (options.chbPersistencePlot.booleanValue()) {
62 plotGeomParamVsFrame("persistance", stats.getStatCollection().get(h));
63 }
64
65 if (options.chbDisplPlot.booleanValue()) {
66 plotGeomParamVsFrame("displacement", stats.getStatCollection().get(h));
67 }
68 if (options.chbDistPlot.booleanValue()) {
69 plotGeomParamVsFrame("dist", stats.getStatCollection().get(h));
70 }
71 if (options.chbSpeedPlot.booleanValue()) {
72 plotGeomParamVsFrame("speed", stats.getStatCollection().get(h));
73 }
74 if (options.chbPerimPlot.booleanValue()) {
75 plotGeomParamVsFrame("perimiter", stats.getStatCollection().get(h));
76 }
77 if (options.chbElongPlot.booleanValue()) {
78 plotGeomParamVsFrame("elongation", stats.getStatCollection().get(h));
79 }
80 if (options.chbCircPlot.booleanValue()) {
81 plotGeomParamVsFrame("circularity", stats.getStatCollection().get(h));
82 }
83 if (options.chbAreaPlot.booleanValue()) {
84 plotGeomParamVsFrame("area", stats.getStatCollection().get(h));
85 }
86
87
88 if (options.chbTotFluPlot.booleanValue()) {
89 plotFluoParamVsFrame("totalFluor", stats.getStatCollection().get(h),
90 options.selActiveChannel.intValue());
91 }
92 if (options.chbMeanFluPlot.booleanValue()) {
93 plotFluoParamVsFrame("meanFluor", stats.getStatCollection().get(h),
94 options.selActiveChannel.intValue());
95 }
96 if (options.chbCortexWidthPlot.booleanValue()) {
97 plotFluoParamVsFrame("cortexWidth", stats.getStatCollection().get(h),
98 options.selActiveChannel.intValue());
99 }
100 if (options.chbCytoAreaPlot.booleanValue()) {
101 plotFluoParamVsFrame("innerArea", stats.getStatCollection().get(h),
102 options.selActiveChannel.intValue());
103 }
104 if (options.chbTotalCytoPlot.booleanValue()) {
105 plotFluoParamVsFrame("totalInnerFluor", stats.getStatCollection().get(h),
106 options.selActiveChannel.intValue());
107 }
108 if (options.chbMeanCytoPlot.booleanValue()) {
109 plotFluoParamVsFrame("meanInnerFluor", stats.getStatCollection().get(h),
110 options.selActiveChannel.intValue());
111 }
112 if (options.chbCortexAreaPlot.booleanValue()) {
113 plotFluoParamVsFrame("cortexArea", stats.getStatCollection().get(h),
114 options.selActiveChannel.intValue());
115 }
116 if (options.chbTotalCtf2Plot.booleanValue()) {
117 plotFluoParamVsFrame("totalCorFluo", stats.getStatCollection().get(h),
118 options.selActiveChannel.intValue());
119 }
120 if (options.chbManCtfPlot.booleanValue()) {
121 plotFluoParamVsFrame("meanCorFluo", stats.getStatCollection().get(h),
122 options.selActiveChannel.intValue());
123 }
124
125 } catch (NoSuchFieldException | SecurityException | IllegalArgumentException
126 | IllegalAccessException e) {
127 throw new RuntimeException("Illegal field name.");
128 }
129
130 }
131
132
133
134
135
136
137
138
139
140
141
142 public void plotGeomParamVsFrame(String name, CellStats stats) throws NoSuchFieldException,
143 SecurityException, IllegalArgumentException, IllegalAccessException {
144 Plot plot = new Plot(name, "time", name);
145 ArrayList<Double> ar = new ArrayList<>();
146 ArrayList<Double> f = new ArrayList<>();
147 for (FrameStatistics fs : stats.getFramestat()) {
148 Field field = fs.getClass().getDeclaredField(name);
149 ar.add((double) field.getDouble(fs));
150 f.add((double) fs.frame);
151 }
152 plot.addPoints(f, ar, Plot.CONNECTED_CIRCLES);
153 plot.show();
154 }
155
156
157
158
159
160
161
162
163
164
165
166
167 public void plotFluoParamVsFrame(String name, CellStats stats, int ch)
168 throws NoSuchFieldException, SecurityException, IllegalArgumentException,
169 IllegalAccessException {
170 Plot plot = new Plot(name, "time", name);
171 ArrayList<Double> ar = new ArrayList<>();
172 ArrayList<Double> f = new ArrayList<>();
173 for (FrameStatistics fs : stats.getFramestat()) {
174 Field field = fs.channels[ch].getClass().getDeclaredField(name);
175 ar.add((double) field.getDouble(fs.channels[ch]));
176 f.add((double) fs.frame);
177 }
178 plot.addPoints(f, ar, Plot.CONNECTED_CIRCLES);
179 plot.show();
180 }
181
182
183
184
185
186
187
188
189
190
191
192 public void plotCentroidParamVsFrame(String name, CellStats stats, String type) {
193 Plot plot = new Plot(name, "time", name);
194 ArrayList<Double> ar = new ArrayList<>();
195 ArrayList<Double> f = new ArrayList<>();
196 switch (type) {
197 case "X":
198 for (FrameStatistics fs : stats.getFramestat()) {
199 ar.add(fs.centroid.getX());
200 f.add((double) fs.frame);
201 }
202 break;
203 case "Y":
204 for (FrameStatistics fs : stats.getFramestat()) {
205 ar.add(fs.centroid.getY());
206 f.add((double) fs.frame);
207 }
208 break;
209 default:
210 throw new IllegalArgumentException("Wrong type.");
211 }
212
213 plot.addPoints(f, ar, Plot.CONNECTED_CIRCLES);
214 plot.show();
215
216 }
217
218 }