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 fr.ens.transcriptome.doelan.Defaults;
25 import fr.ens.transcriptome.doelan.DoelanRegistery;
26 import fr.ens.transcriptome.doelan.algorithms.QualityGlobalTest;
27 import fr.ens.transcriptome.doelan.data.QualityGlobalTestResult;
28 import fr.ens.transcriptome.doelan.data.QualityUnitTestResult;
29 import fr.ens.transcriptome.nividic.om.BioAssay;
30 import fr.ens.transcriptome.nividic.om.SpotIterator;
31 import fr.ens.transcriptome.nividic.platform.PlatformException;
32 import fr.ens.transcriptome.nividic.platform.module.AboutModule;
33 import fr.ens.transcriptome.nividic.platform.module.Module;
34 import fr.ens.transcriptome.nividic.platform.module.ModuleDescription;
35 import fr.ens.transcriptome.nividic.util.SystemUtils;
36 import fr.ens.transcriptome.nividic.util.parameter.FixedParameters;
37 import fr.ens.transcriptome.nividic.util.parameter.Parameter;
38 import fr.ens.transcriptome.nividic.util.parameter.ParameterBuilder;
39 import fr.ens.transcriptome.nividic.util.parameter.ParameterException;
40 import fr.ens.transcriptome.nividic.util.parameter.Parameters;
41
42 /***
43 * This class define a Global test which count the number of bad removed spot.
44 * @author Laurent Jourdren
45 */
46 public class GlobalMaxBadFeatureRemoved extends QualityGlobalTest implements
47 Module {
48
49 private static AboutModule aboutModule;
50
51 /***
52 * Get the description of the module.
53 * @return The description of the module
54 */
55 public AboutModule aboutModule() {
56
57 if (aboutModule == null) {
58
59 ModuleDescription md = null;
60 try {
61 md = new ModuleDescription("GlobalMaxBadFeaturesRemovedTest",
62 "Count the maximal bad spots removed in a test suite");
63 md.setWebsite(DoelanRegistery.getAppURL());
64 md.setHTMLDocumentation(SystemUtils.readTextRessource("/files/test-"
65 + SystemUtils.getClassShortName(this.getClass()) + ".html"));
66 md.setStability(AboutModule.STATE_STABLE);
67 md.setVersion(Defaults.DEFAULT_TEST_VERSION);
68 } catch (PlatformException e) {
69 getLogger().error("Unable to create the module description");
70 }
71
72 aboutModule = md;
73 }
74
75 return aboutModule;
76 }
77
78 /***
79 * Set the parameters of the element.
80 * @return The defaults parameters to set.
81 */
82 protected Parameters defineParameters() {
83
84 try {
85
86 final Parameter threshold = new ParameterBuilder().withName("threshold")
87 .withLongName("Maximal threshold of bad spots").withType(
88 Parameter.DATATYPE_DOUBLE).withDescription(
89 "Threshold for the test").withGreaterThanValue(0)
90 .withLowerThanValue(1).withDefaultValue("10").withUnit("%")
91 .getParameter();
92
93 final FixedParameters params = new FixedParameters();
94 params.addParameter(threshold);
95
96 return params;
97
98 } catch (ParameterException e) {
99 getLogger().error("Error while creating parameters: " + e);
100 }
101
102 return null;
103 }
104
105 /***
106 * Do the test.
107 * @param parameters Parameters of the test
108 * @param unitResults results of the units tests
109 * @throws PlatformException if an error occurs while executing the test.
110 */
111 protected QualityGlobalTestResult test(final BioAssay bioassay,
112 final BioAssay arrayList, final Parameters parameters,
113 final QualityUnitTestResult[] unitResults) throws PlatformException {
114
115 if (parameters == null || unitResults == null)
116 return null;
117
118 try {
119 final double threshold = parameters.getParameter("threshold")
120 .getDoubleValue();
121
122 int countArrays = 0;
123
124 for (int i = 0; i < unitResults.length; i++) {
125 if (unitResults[i].isFilterFlags()
126 && unitResults[i].getNewFlags() != null)
127 countArrays++;
128 }
129
130 boolean[][] badspots = new boolean[countArrays][];
131 countArrays = 0;
132
133 for (int i = 0; i < unitResults.length; i++) {
134 boolean[] nf = unitResults[i].getNewFlags();
135 if (unitResults[i].isFilterFlags() && nf != null)
136 badspots[countArrays++] = nf;
137 }
138
139 int countRealSpot = 0;
140 int countBad = 0;
141
142 SpotIterator si = bioassay.iterator();
143 int i = 0;
144
145 while (si.hasNext()) {
146 si.next();
147 if (si.isEmpty() || si.isFlagAbscent()) {
148 i++;
149 continue;
150 }
151
152 boolean result = true;
153 for (int j = 0; j < badspots.length; j++)
154 result = result && badspots[j][i];
155
156 if (!result)
157 countBad++;
158 countRealSpot++;
159 i++;
160 }
161
162 final double ratio = ((double) countBad) / ((double) countRealSpot) * 100;
163 long maxThreshold = (long) (countRealSpot * threshold / 100.0);
164
165 final String message = "Bad diameter features: " + countBad + "/"
166 + countRealSpot + " features (threshold: " + maxThreshold
167 + " features)";
168
169 QualityGlobalTestResult testResult = new QualityGlobalTestResult(
170 bioassay, this);
171
172 testResult.setPercent(true);
173 testResult.setThresholdEqualityType("<=");
174 testResult.setUnit("%");
175 testResult.setThreshold(threshold);
176 testResult.setValue(ratio);
177 testResult.setResult(ratio <= threshold);
178 testResult.setMessage(message);
179
180 return testResult;
181
182 } catch (ParameterException e) {
183
184 getLogger().error(
185 "Error while creating parameters (" + this.getClass().getName()
186 + "): " + e.getMessage());
187 }
188
189 return null;
190 }
191
192
193
194
195
196 /***
197 * Public constructor.
198 * @throws PlatformException If the name or the version of the element is
199 * <b>null </b>.
200 */
201 public GlobalMaxBadFeatureRemoved() throws PlatformException {
202
203 }
204
205 }