1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package fr.ens.transcriptome.doelan.tests;
23
24 import org.apache.commons.collections.primitives.ArrayDoubleList;
25
26 import fr.ens.transcriptome.doelan.Defaults;
27 import fr.ens.transcriptome.doelan.DoelanChart;
28 import fr.ens.transcriptome.doelan.DoelanRegistery;
29 import fr.ens.transcriptome.doelan.algorithms.QualityUnitTest;
30 import fr.ens.transcriptome.doelan.data.QualityUnitTestResult;
31 import fr.ens.transcriptome.doelan.data.QualityUnitTestResult.SummaryResult;
32 import fr.ens.transcriptome.nividic.om.BioAssay;
33 import fr.ens.transcriptome.nividic.om.SpotIterator;
34 import fr.ens.transcriptome.nividic.platform.PlatformException;
35 import fr.ens.transcriptome.nividic.platform.module.AboutModule;
36 import fr.ens.transcriptome.nividic.platform.module.Module;
37 import fr.ens.transcriptome.nividic.platform.module.ModuleDescription;
38 import fr.ens.transcriptome.nividic.util.SystemUtils;
39 import fr.ens.transcriptome.nividic.util.parameter.FixedParameters;
40 import fr.ens.transcriptome.nividic.util.parameter.Parameter;
41 import fr.ens.transcriptome.nividic.util.parameter.ParameterBuilder;
42 import fr.ens.transcriptome.nividic.util.parameter.ParameterException;
43 import fr.ens.transcriptome.nividic.util.parameter.Parameters;
44
45 /***
46 * This class defines a quality test based on the minimal spot diameter.
47 * @author Laurent Jourdren
48 */
49 public class MinDiameterFeatureTest extends QualityUnitTest implements Module {
50
51 private static final int DEFAULT_BINS = 16;
52 private static AboutModule aboutModule;
53
54 /***
55 * Get the description of the module.
56 * @return The description of the module
57 */
58 public AboutModule aboutModule() {
59
60 if (aboutModule == null) {
61
62 ModuleDescription md = null;
63 try {
64 md = new ModuleDescription("MinDiameterFeatureTest",
65 "Test minimal diameter of features");
66 md.setWebsite(DoelanRegistery.getAppURL());
67 md.setHTMLDocumentation(SystemUtils.readTextRessource("/files/test-"
68 + SystemUtils.getClassShortName(this.getClass()) + ".html"));
69 md.setStability(AboutModule.STATE_STABLE);
70 md.setVersion(Defaults.DEFAULT_TEST_VERSION);
71 } catch (PlatformException e) {
72 getLogger().error("Unable to create the module description");
73 }
74
75 aboutModule = md;
76 }
77
78 return aboutModule;
79 }
80
81 /***
82 * Set the parameters of the element.
83 * @return The defaults parameters to set.
84 */
85 protected Parameters defineParameters() {
86
87 try {
88
89 final Parameter threshold = new ParameterBuilder().withName("threshold")
90 .withLongName("Maximal threshold of bad spots").withType(
91 Parameter.DATATYPE_DOUBLE).withDescription(
92 "Threshold for the test").withGreaterThanValue(0)
93 .withLowerThanValue(1).withDefaultValue("10").withUnit("%")
94 .getParameter();
95
96 final Parameter min = new ParameterBuilder().withName("min")
97 .withLongName("Minimal diameter value").withType(
98 Parameter.DATATYPE_INTEGER).withDescription(
99 "Minimal value of the diameter for a spot (included)")
100 .withGreaterThanValue(0).withDefaultValue("80").withUnit("µm")
101 .getParameter();
102
103 final Parameter filterFlags = new ParameterBuilder().withType(
104 Parameter.DATATYPE_YESNO).withName("filterFlags").withLongName(
105 "Remove bad spots from output array list").withDescription(
106 "Remove invalid spots in output arraylist file.").withDefaultValue(
107 "yes").getParameter();
108
109 final FixedParameters params = new FixedParameters();
110 params.addParameter(min);
111 params.addParameter(threshold);
112 params.addParameter(filterFlags);
113
114 return params;
115
116 } catch (ParameterException e) {
117 getLogger().error("Error while creating parameters: " + e);
118 }
119
120 return null;
121 }
122
123 /***
124 * Test the quality of the bioassay.
125 * @param bioassay BioAssay to test
126 * @param arrayList The array list
127 * @param parameters parameters of the test
128 * @return A QualityObjectResultTest Object
129 * @throws PlatformException if an error occurs while executing the test.
130 */
131 public QualityUnitTestResult test(final BioAssay bioassay,
132 final BioAssay arrayList, final Parameters parameters)
133 throws PlatformException {
134
135 QualityUnitTestResult result = null;
136
137 try {
138 final int min = parameters.getParameter("min").getIntValue();
139
140 final double threshold = parameters.getParameter("threshold")
141 .getDoubleValue();
142
143 final boolean filterFlags = parameters.getParameter("filterFlags")
144 .getBooleanValue();
145
146 final boolean[] results = new boolean[bioassay.size()];
147 final int[] dia = bioassay.getDataFieldInt("Dia.");
148
149 if (dia == null)
150 throw new PlatformException("Diameter field doesn't exits");
151
152 int countBadDiameter = 0;
153 int countRealSpot = 0;
154 ArrayDoubleList adl = new ArrayDoubleList();
155
156 SpotIterator si = bioassay.iterator();
157 int i = 0;
158
159 while (si.hasNext()) {
160 si.next();
161 if (si.isEmpty() || si.isFlagAbscent()) {
162 i++;
163 continue;
164 }
165
166 adl.add(dia[i]);
167 if (dia[i] >= min)
168 results[i] = true;
169 else {
170 results[i] = false;
171 countBadDiameter++;
172 }
173
174 countRealSpot++;
175 i++;
176 }
177
178 final double ratio = ((double) countBadDiameter)
179 / ((double) countRealSpot) * 100;
180
181 result = new QualityUnitTestResult(bioassay, this);
182
183 long maxThreshold = (long) (countRealSpot * threshold / 100.0);
184
185 result.setMessage("Bad diameter features: " + countBadDiameter + "/"
186 + countRealSpot + " features (threshold: " + maxThreshold
187 + " features)");
188
189 DoelanChart gu = new DoelanChart();
190 gu.setData(adl.toArray());
191 gu.setTitle("Diameter distribution");
192 gu.setXAxisLegend("Spot diameter (pixels)");
193 gu.setYAxisLegend("#Spots");
194 gu.setHistCaption("Spots");
195 gu.setThreshold(min);
196 gu.setWidth(DoelanRegistery.getDoelanChartWidth());
197 gu.setHeight(DoelanRegistery.getDoelanChartHeigth());
198 gu.setBins(DEFAULT_BINS);
199
200 result.setImage(gu.getImage());
201 result.setGlobalResultType(true);
202 result.setNewFlags(results);
203 result.setFilterFlags(filterFlags);
204 SummaryResult rac = result.getResultAllChannels();
205 rac.setPercent(true);
206 rac.setThresholdEqualityType("<=");
207 rac.setUnit("%");
208 rac.setThreshold(threshold);
209 rac.setValue(ratio);
210 rac.setPass(ratio <= threshold);
211
212 } catch (ParameterException e) {
213 throw new PlatformException("Error while creating parameters ("
214 + this.getClass().getName() + "): " + e.getMessage());
215 }
216
217 return result;
218 }
219
220
221
222
223
224 /***
225 * Public constructor.
226 * @throws PlatformException If the name or the version of the element is
227 * <b>null </b>.
228 */
229 public MinDiameterFeatureTest() throws PlatformException {
230
231 }
232
233 }