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.platform.PlatformException;
34 import fr.ens.transcriptome.nividic.platform.module.AboutModule;
35 import fr.ens.transcriptome.nividic.platform.module.Module;
36 import fr.ens.transcriptome.nividic.platform.module.ModuleDescription;
37 import fr.ens.transcriptome.nividic.util.SystemUtils;
38 import fr.ens.transcriptome.nividic.util.graphics.GraphicsUtil;
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 test for Test Heterogeneity of features.
47 * @author Laurent Jourdren
48 */
49 public class HeterogeneousFeatureTest 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("HeterogeneousFeatureTest",
65 "Test Heterogeneity 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 of invalid spots to reject the chip")
93 .withGreaterThanValue(0).withDefaultValue("10").withUnit("%")
94 .getParameter();
95
96 final Parameter max = new ParameterBuilder().withName("max")
97 .withLongName("Maximal value of standard deviation").withType(
98 Parameter.DATATYPE_INTEGER).withDescription(
99 "Minimal value of the standard deviation for a spot")
100 .withGreaterThanValue(0).withLowerThanValue(100).withDefaultValue(
101 "500").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(max);
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
139 final boolean[] results = new boolean[bioassay.size()];
140 final int[] flags = bioassay.getFlags();
141 final int[] f635SD = bioassay.getDataFieldInt("F635 SD");
142 final int[] f532SD = bioassay.getDataFieldInt("F532 SD");
143
144 final double threshold = parameters.getParameter("threshold")
145 .getDoubleValue();
146 final double max = parameters.getParameter("max").getIntValue();
147
148 final boolean filterFlags = parameters.getParameter("filterFlags")
149 .getBooleanValue();
150
151 int countOut532 = 0;
152 int countOut635 = 0;
153 int countRealSpot = 0;
154
155
156 ArrayDoubleList adl532 = new ArrayDoubleList();
157 ArrayDoubleList adl635 = new ArrayDoubleList();
158
159 for (int i = 0; i < flags.length; i++) {
160 if (flags[i] == BioAssay.FLAG_ABSCENT)
161 continue;
162
163
164 adl532.add(f532SD[i]);
165 adl635.add(f635SD[i]);
166
167 boolean flag = false;
168
169 if (f532SD[i] >= max) {
170 countOut532++;
171 flag = true;
172 }
173
174 if (f635SD[i] >= max) {
175 countOut635++;
176 flag = true;
177 }
178
179 if (!flag)
180 results[i] = true;
181
182 countRealSpot++;
183 }
184
185 final double ratio532 = ((double) countOut532) / ((double) countRealSpot)
186 * 100;
187 final double ratio635 = ((double) countOut635) / ((double) countRealSpot)
188 * 100;
189
190 int realThreshold = (int) (threshold / 100 * countRealSpot);
191
192 result = new QualityUnitTestResult(bioassay, this);
193 result.setMessage("Heterogeneous features in 532: " + countOut532 + "/"
194 + countRealSpot + " features (threshold: " + realThreshold
195 + " features)<br>" + "Heterogeneous features in 635 : " + countOut635
196 + "/" + countRealSpot + " features (threshold: " + realThreshold
197 + " features)"
198
199 );
200
201 result.setNewFlags(results);
202 result.setFilterFlags(filterFlags);
203 result.setGlobalResultType(false);
204
205 SummaryResult r532 = result.getResultChannel532();
206 SummaryResult r635 = result.getResultChannel635();
207
208 r532.setPercent(true);
209 r532.setThresholdEqualityType("<=");
210 r532.setUnit("%");
211 r532.setThreshold(threshold);
212 r532.setValue(ratio532);
213 r532.setPass(ratio532 <= threshold);
214
215 r635.setPercent(true);
216 r635.setThresholdEqualityType("<=");
217 r635.setUnit("%");
218 r635.setThreshold(threshold);
219 r635.setValue(ratio635);
220 r635.setPass(ratio635 <= threshold);
221
222 DoelanChart gu532 = new DoelanChart();
223 gu532.setData(adl532.toArray());
224 gu532.setTitle("532 foreground standard deviation");
225 gu532.setXAxisLegend("Standard deviation");
226 gu532.setYAxisLegend("#Spots");
227 gu532.setHistCaption("Spots");
228 gu532.setThreshold(max);
229 gu532.setHeight(DoelanRegistery.getDoelanChartHeigth());
230 gu532.setWidth(DoelanRegistery.getDoelanChartWidth());
231 gu532.setBins(DEFAULT_BINS);
232 gu532.setYLogAxis(true);
233
234 DoelanChart gu635 = new DoelanChart();
235 gu635.setData(adl635.toArray());
236 gu635.setTitle("635 foreground standard deviation");
237 gu635.setXAxisLegend("Standard deviation");
238 gu635.setYAxisLegend("#Spots");
239 gu635.setHistCaption("Spots");
240 gu635.setThreshold(max);
241 gu635.setHeight(DoelanRegistery.getDoelanChartHeigth());
242 gu635.setWidth(DoelanRegistery.getDoelanChartWidth());
243 gu635.setBins(DEFAULT_BINS);
244 gu635.setYLogAxis(true);
245
246 result.setImage(GraphicsUtil.mergeImages(gu532.getImage(), gu635
247 .getImage()));
248
249 } catch (ParameterException e) {
250 throw new PlatformException("Error while creating parameters ("
251 + this.getClass().getName() + "): " + e.getMessage());
252 }
253
254 return result;
255 }
256
257
258
259
260
261 /***
262 * Public constructor.
263 * @throws PlatformException If the name or the version of the element is
264 * <b>null </b>.
265 */
266 public HeterogeneousFeatureTest() throws PlatformException {
267
268 }
269 }