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 defines an algorithm to count the maximal bad spots in a test
44 * suite.
45 * @author Laurent Jourdren
46 */
47 public class GlobalMaxBadFeaturesTest extends QualityGlobalTest implements
48 Module {
49
50 private static AboutModule aboutModule;
51
52 /***
53 * Get the description of the module.
54 * @return The description of the module
55 */
56 public AboutModule aboutModule() {
57
58 if (aboutModule == null) {
59
60 ModuleDescription md = null;
61 try {
62 md = new ModuleDescription("GlobalMaxBadFeaturesTest",
63 "Count the maximal bad spots in a test suite");
64 md.setWebsite(DoelanRegistery.getAppURL());
65 md.setHTMLDocumentation(SystemUtils.readTextRessource("/files/test-"
66 + SystemUtils.getClassShortName(this.getClass()) + ".html"));
67 md.setStability(AboutModule.STATE_STABLE);
68 md.setVersion(Defaults.DEFAULT_TEST_VERSION);
69 } catch (PlatformException e) {
70 getLogger().error("Unable to create the module description");
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].getNewFlags() != null)
126 countArrays++;
127 }
128
129 boolean[][] badspots = new boolean[countArrays][];
130 countArrays = 0;
131
132 for (int i = 0; i < unitResults.length; i++) {
133 boolean[] nf = unitResults[i].getNewFlags();
134 if (nf != null)
135 badspots[countArrays++] = nf;
136 }
137
138 int countRealSpot = 0;
139 int countBad = 0;
140
141 SpotIterator si = bioassay.iterator();
142 int i = 0;
143
144 while (si.hasNext()) {
145 si.next();
146 if (si.isEmpty() || si.isFlagAbscent()) {
147 i++;
148 continue;
149 }
150
151 boolean result = true;
152 for (int j = 0; j < badspots.length; j++)
153 result = result && badspots[j][i];
154
155 if (!result)
156 countBad++;
157 countRealSpot++;
158 i++;
159 }
160
161 final double ratio = ((double) countBad) / ((double) countRealSpot) * 100;
162 long maxThreshold = (long) (countRealSpot * threshold / 100.0);
163
164 final String message = "Bad diameter features: " + countBad + "/"
165 + countRealSpot + " features (threshold: " + maxThreshold
166 + " features)";
167
168 QualityGlobalTestResult testResult = new QualityGlobalTestResult(
169 bioassay, this);
170
171 testResult.setPercent(true);
172 testResult.setThresholdEqualityType("<=");
173 testResult.setUnit("%");
174 testResult.setThreshold(threshold);
175 testResult.setValue(ratio);
176 testResult.setResult(ratio <= threshold);
177 testResult.setMessage(message);
178
179 return testResult;
180
181 } catch (ParameterException e) {
182
183 getLogger().error(
184 "Error while creating parameters (" + this.getClass().getName()
185 + "): " + e.getMessage());
186 }
187
188 return null;
189 }
190
191
192
193
194
195 /***
196 * Public constructor.
197 * @throws PlatformException If the name or the version of the element is
198 * <b>null </b>.
199 */
200 public GlobalMaxBadFeaturesTest() throws PlatformException {
201
202 }
203
204 }