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.algorithms.QualityUnitTest;
25 import fr.ens.transcriptome.doelan.data.QualityUnitTestResult;
26 import fr.ens.transcriptome.doelan.data.QualityUnitTestResult.SummaryResult;
27 import fr.ens.transcriptome.nividic.om.BioAssay;
28 import fr.ens.transcriptome.nividic.om.SpotIterator;
29 import fr.ens.transcriptome.nividic.platform.PlatformException;
30 import fr.ens.transcriptome.nividic.platform.module.AboutModule;
31 import fr.ens.transcriptome.nividic.platform.module.Module;
32 import fr.ens.transcriptome.nividic.util.parameter.FixedParameters;
33 import fr.ens.transcriptome.nividic.util.parameter.Parameter;
34 import fr.ens.transcriptome.nividic.util.parameter.ParameterBuilder;
35 import fr.ens.transcriptome.nividic.util.parameter.ParameterException;
36 import fr.ens.transcriptome.nividic.util.parameter.Parameters;
37
38 /***
39 * This class defines a test for not found spot flag.
40 * @author Laurent Jourdren
41 */
42 public abstract class FeatureFlagTest extends QualityUnitTest implements Module {
43
44 /***
45 * Get the description of the module.
46 * @return The description of the module
47 */
48 public abstract AboutModule aboutModule();
49
50 /***
51 * Set the parameters of the element.
52 * @return The defaults parameters to set.
53 */
54 protected Parameters defineParameters() {
55
56 try {
57
58 final Parameter threshold = new ParameterBuilder().withName("threshold")
59 .withLongName("Maximal threshold of bad spots").withType(
60 Parameter.DATATYPE_DOUBLE).withDescription(
61 "Threshold of invalid spots to reject the test")
62 .withGreaterThanValue(0).withDefaultValue("" + getDefaultThreshold())
63 .withUnit("%").getParameter();
64
65 final Parameter filterFlags = new ParameterBuilder().withName(
66 "filterFlags").withType(Parameter.DATATYPE_YESNO).withLongName(
67 "Remove bad spots from output array list").withDescription(
68 "Remove invalid spots in output arraylist file.").withDefaultValue(
69 "yes").getParameter();
70
71 final FixedParameters params = new FixedParameters();
72 params.addParameter(threshold);
73 params.addParameter(filterFlags);
74
75 return params;
76
77 } catch (ParameterException e) {
78 getLogger().error("Error while creating parameters: " + e);
79 }
80
81 return null;
82 }
83
84 protected abstract int getFlagFilterValue();
85
86 protected abstract String getFlagFilerType();
87
88 protected abstract double getDefaultThreshold();
89
90 /***
91 * Test the quality of the bioassay.
92 * @param bioassay BioAssay to test
93 * @param arrayList The array list
94 * @param parameters parameters of the test
95 * @return A QualityObjectResultTest Object
96 * @throws PlatformException if an error occurs while executing the test.
97 */
98 public QualityUnitTestResult test(final BioAssay bioassay,
99 final BioAssay arrayList, final Parameters parameters)
100 throws PlatformException {
101
102 QualityUnitTestResult result = null;
103
104 try {
105
106 final boolean[] results = new boolean[bioassay.size()];
107
108
109 final double threshold = parameters.getParameter("threshold")
110 .getDoubleValue();
111
112 final boolean filterFlags = parameters.getParameter("filterFlags")
113 .getBooleanValue();
114
115 final int flagValue = getFlagFilterValue();
116
117 int countBad = 0;
118 int countRealSpot = 0;
119
120 SpotIterator si = bioassay.iterator();
121
122 while (si.hasNext()) {
123 si.next();
124
125 if (si.isEmpty()
126 || (si.isFlagAbscent() && flagValue != BioAssay.FLAG_ABSCENT))
127 continue;
128
129 if (si.getFlag() == flagValue)
130 countBad++;
131 else
132 results[si.getIndex()] = true;
133
134 countRealSpot++;
135 }
136
137 final double ratio = ((double) countBad) / ((double) countRealSpot) * 100;
138
139 result = new QualityUnitTestResult(bioassay, this);
140 final long max = (long) (countRealSpot * threshold / 100);
141
142 result.setMessage(getFlagFilerType() + " features: " + countBad + "/"
143 + countRealSpot + " features (threshold: " + max + " features)");
144
145 result.setGlobalResultType(true);
146 result.setFilterFlags(filterFlags);
147 result.setNewFlags(results);
148 SummaryResult rac = result.getResultAllChannels();
149 rac.setPercent(true);
150 rac.setThresholdEqualityType("<=");
151 rac.setThreshold(threshold);
152 rac.setUnit("%");
153 rac.setValue(ratio);
154 rac.setPercent(false);
155 rac.setPass(ratio <= threshold);
156
157 } catch (ParameterException e) {
158 throw new PlatformException("Error while creating parameters ("
159 + this.getClass().getName() + "): " + e.getMessage());
160 }
161
162 return result;
163 }
164
165
166
167
168
169 /***
170 * Public constructor.
171 * @throws PlatformException If the name or the version of the element is
172 * <b>null </b>.
173 */
174 public FeatureFlagTest() throws PlatformException {
175
176 }
177 }