View Javadoc

1   /*
2    *                Doelan development code
3    *
4    * This code may be freely distributed and modified under the
5    * terms of the GNU General Public Licence.  This should
6    * be distributed with the code. If you do not have a copy,
7    * see:
8    *
9    *      http://www.gnu.org/copyleft/gpl.txt
10   *
11   * Copyright (c) 2004-2005 ENS Microarray Platform
12   * Copyright for this code is held jointly by the individual
13   * authors.  These should be listed in @author doc comments.
14   *
15   * For more information on the Doelan project and its aims,
16   * or to join the Doelan mailing list, visit the home page
17   * at:
18   *
19   *      http://www.transcriptome.ens.fr/doelan
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.QualityUnitTest;
27  import fr.ens.transcriptome.doelan.data.QualityUnitTestResult;
28  import fr.ens.transcriptome.doelan.data.QualityUnitTestResult.SummaryResult;
29  import fr.ens.transcriptome.nividic.om.BioAssay;
30  import fr.ens.transcriptome.nividic.platform.PlatformException;
31  import fr.ens.transcriptome.nividic.platform.module.AboutModule;
32  import fr.ens.transcriptome.nividic.platform.module.Module;
33  import fr.ens.transcriptome.nividic.platform.module.ModuleDescription;
34  import fr.ens.transcriptome.nividic.util.SystemUtils;
35  import fr.ens.transcriptome.nividic.util.parameter.FixedParameters;
36  import fr.ens.transcriptome.nividic.util.parameter.Parameter;
37  import fr.ens.transcriptome.nividic.util.parameter.ParameterBuilder;
38  import fr.ens.transcriptome.nividic.util.parameter.ParameterException;
39  import fr.ens.transcriptome.nividic.util.parameter.Parameters;
40  
41  /***
42   * This class define a test for saturated pixel of features from a bioassay.
43   * @author Laurent Jourdren
44   */
45  public class SaturatedPixelsTest extends QualityUnitTest implements Module {
46  
47    private static AboutModule aboutModule;
48  
49    /***
50     * Get the description of the module.
51     * @return The description of the module
52     */
53    public AboutModule aboutModule() {
54  
55      if (aboutModule == null) {
56  
57        ModuleDescription md = null;
58        try {
59          md = new ModuleDescription("SaturatedPixelsTest",
60              "Test saturated pixels of spots");
61          md.setWebsite(DoelanRegistery.getAppURL());
62          md.setHTMLDocumentation(SystemUtils.readTextRessource("/files/test-"
63              + SystemUtils.getClassShortName(this.getClass()) + ".html"));
64          md.setStability(AboutModule.STATE_STABLE);
65          md.setVersion(Defaults.DEFAULT_TEST_VERSION);
66        } catch (PlatformException e) {
67          getLogger().error("Unable to create the module description");
68        }
69        aboutModule = md;
70      }
71  
72      return aboutModule;
73    }
74  
75    /***
76     * Set the parameters of the element.
77     * @return The defaults parameters to set.
78     */
79    protected Parameters defineParameters() {
80  
81      try {
82  
83        final Parameter threshold = new ParameterBuilder().withName("threshold")
84            .withLongName("Maximal threshold of bad spots").withType(
85                Parameter.DATATYPE_DOUBLE).withDescription(
86                "Threshold of invalid spots to reject the chip")
87            .withGreaterThanValue(0).withDefaultValue("10").withUnit("%")
88            .getParameter();
89  
90        final Parameter saturatedPixels = new ParameterBuilder().withName(
91            "saturated pixels threshold").withLongName(
92            "Threshold maximum saturated pixels").withType(
93            Parameter.DATATYPE_INTEGER).withDescription(
94            "Threshold of saturated pixels (in percent) to reject a spot")
95            .withGreaterThanValue(0).withLowerThanValue(100)
96            .withDefaultValue("1").withUnit("%").getParameter();
97  
98        final Parameter filterFlags = new ParameterBuilder().withName(
99            "filterFlags")
100           .withLongName("Remove bad spots from output array list").withType(
101               Parameter.DATATYPE_YESNO).withDescription(
102               "Remove invalid spots in output arraylist file.")
103           .withDefaultValue("yes").getParameter();
104 
105       final FixedParameters params = new FixedParameters();
106       params.addParameter(threshold);
107       params.addParameter(saturatedPixels);
108       params.addParameter(filterFlags);
109 
110       return params;
111 
112     } catch (ParameterException e) {
113       getLogger().error("Error while creating parameters: " + e);
114     }
115 
116     return null;
117   }
118 
119   /***
120    * Test the quality of the bioassay.
121    * @param bioassay BioAssay to test
122    * @param arrayList The array list
123    * @param parameters parameters of the test
124    * @return A QualityObjectResultTest Object
125    * @throws PlatformException if an error occurs while executing the test.
126    */
127   public QualityUnitTestResult test(final BioAssay bioassay,
128       final BioAssay arrayList, final Parameters parameters)
129       throws PlatformException {
130 
131     QualityUnitTestResult result = null;
132 
133     try {
134 
135       final boolean[] results = new boolean[bioassay.size()];
136       final int[] flags = bioassay.getFlags();
137       final int[] sat635 = bioassay.getDataFieldInt("F635 % Sat.");
138       final int[] sat532 = bioassay.getDataFieldInt("F532 % Sat.");
139       final boolean filterFlags = parameters.getParameter("filterFlags")
140           .getBooleanValue();
141 
142       final double threshold = parameters.getParameter("threshold")
143           .getDoubleValue();
144       final double saturatedPixels = parameters.getParameter(
145           "saturated pixels threshold").getIntValue();
146 
147       int countSat532 = 0;
148       int countSat635 = 0;
149       int countRealSpot = 0;
150       for (int i = 0; i < flags.length; i++) {
151         results[i] = true;
152         if (flags[i] == BioAssay.FLAG_ABSCENT)
153           continue;
154 
155         if (sat532[i] >= saturatedPixels) {
156           countSat532++;
157           results[i] = false;
158         }
159 
160         if (sat635[i] >= saturatedPixels) {
161           countSat635++;
162           results[i] = false;
163         }
164 
165         countRealSpot++;
166       }
167 
168       final double ratio532 = ((double) countSat532) / ((double) countRealSpot)
169           * 100;
170       final double ratio635 = ((double) countSat635) / ((double) countRealSpot)
171           * 100;
172 
173       result = new QualityUnitTestResult(bioassay, this);
174 
175       final long max = (long) (countRealSpot * threshold / 100);
176       result.setMessage("Features with invalid saturated pixels in 532 : "
177           + countSat532 + "/" + countRealSpot + " features (threshold: " + max
178           + " features)<br>"
179           + "Features with invalid saturated pixels in 635: " + countSat635
180           + "/" + countRealSpot + " features (threshold: " + max + " features)"
181 
182       );
183 
184       result.setNewFlags(results);
185       result.setFilterFlags(filterFlags);
186 
187       result.setGlobalResultType(false);
188 
189       SummaryResult r532 = result.getResultChannel532();
190       SummaryResult r635 = result.getResultChannel635();
191 
192       r532.setPercent(true);
193       r532.setThresholdEqualityType("<=");
194       r532.setUnit("%");
195       r532.setThreshold(threshold);
196       r532.setValue(ratio532);
197       r532.setPass(ratio532 <= threshold);
198 
199       r635.setPercent(true);
200       r635.setThresholdEqualityType("<=");
201       r635.setUnit("%");
202       r635.setThreshold(threshold);
203       r635.setValue(ratio635);
204       r635.setPass(ratio635 <= threshold);
205 
206     } catch (ParameterException e) {
207       throw new PlatformException("Error while creating parameters ("
208           + this.getClass().getName() + "): " + e.getMessage());
209     }
210 
211     return result;
212   }
213 
214   //
215   // Constructor
216   //
217 
218   /***
219    * Public constructor.
220    * @throws PlatformException If the name or the version of the element is
221    *           <b>null </b>.
222    */
223   public SaturatedPixelsTest() throws PlatformException {
224     // MUST BE EMPTY
225   }
226 }