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.algorithms;
23  
24  import java.applet.Applet;
25  import java.io.File;
26  import java.io.FileInputStream;
27  import java.io.FileNotFoundException;
28  
29  import fr.ens.transcriptome.doelan.data.TestSuiteResult;
30  import fr.ens.transcriptome.doelan.data.TestSuiteResultData;
31  import fr.ens.transcriptome.nividic.om.BioAssay;
32  import fr.ens.transcriptome.nividic.om.BioAssayFactory;
33  import fr.ens.transcriptome.nividic.om.GenepixResults;
34  import fr.ens.transcriptome.nividic.om.io.BioAssayReader;
35  import fr.ens.transcriptome.nividic.om.io.GPRReader;
36  import fr.ens.transcriptome.nividic.om.io.NividicIOException;
37  import fr.ens.transcriptome.nividic.platform.PlatformException;
38  import fr.ens.transcriptome.nividic.platform.data.ArrayListOMData;
39  import fr.ens.transcriptome.nividic.platform.data.BioAssayOMData;
40  import fr.ens.transcriptome.nividic.platform.module.AboutModule;
41  import fr.ens.transcriptome.nividic.platform.module.Module;
42  import fr.ens.transcriptome.nividic.platform.module.ModuleDescription;
43  import fr.ens.transcriptome.nividic.platform.workflow.Algorithm;
44  import fr.ens.transcriptome.nividic.platform.workflow.Container;
45  import fr.ens.transcriptome.nividic.util.parameter.FixedParameters;
46  import fr.ens.transcriptome.nividic.util.parameter.Parameter;
47  import fr.ens.transcriptome.nividic.util.parameter.ParameterBuilder;
48  import fr.ens.transcriptome.nividic.util.parameter.ParameterException;
49  import fr.ens.transcriptome.nividic.util.parameter.Parameters;
50  
51  /***
52   * This class implements a module witch load GPR and GAL file.
53   * @author Laurent Jourdren
54   */
55  public class DoelanLoadGenepixData extends Algorithm implements Module {
56  
57    /*** the applet Object to load data from the GPR. */
58    private Applet applet;
59  
60    //
61    // Getters
62    //
63  
64    /***
65     * Get the applet.
66     * @return Returns the applet.
67     */
68    public Applet getApplet() {
69      return applet;
70    }
71  
72    //
73    // Setters
74    //
75  
76    /***
77     * Set the applet.
78     * @param applet The applet to set
79     */
80    public void setApplet(final Applet applet) {
81      this.applet = applet;
82    }
83  
84    //
85    // Others methods
86    //
87  
88    /***
89     * Get the description of the module.
90     * @return The description of the module
91     */
92    public AboutModule aboutModule() {
93  
94      ModuleDescription md = null;
95      try {
96        md = new ModuleDescription("DoelanLoadData", "Load GPR and GAL files");
97        md.setStability(AboutModule.STATE_STABLE);
98      } catch (PlatformException e) {
99        getLogger().error("Unable to create the module description");
100     }
101     return md;
102   }
103 
104   /***
105    * Set the parameters of the element.
106    * @return The defaults parameters to set.
107    */
108   protected Parameters defineParameters() {
109 
110     try {
111 
112       final Parameter chipTypeName = new ParameterBuilder().withName(
113           "chipTypeName").withDescription("Name of the chip type")
114           .getParameter();
115 
116       final Parameter testSuiteName = new ParameterBuilder().withName(
117           "testSuiteName").withDescription("Name of the test suite name")
118           .getParameter();
119 
120       final Parameter gprFile = new ParameterBuilder().withName("gprFilename")
121           .withDescription("The path to the GPR file").getParameter();
122 
123       final Parameter galFile = new ParameterBuilder().withName("galFilename")
124           .withDescription("The path to the GAL file").getParameter();
125 
126       final Parameter description = new ParameterBuilder().withName(
127           "description").withDescription("Data description").getParameter();
128 
129       final Parameter loadFromApplet = new ParameterBuilder().withName(
130           "loadFromApplet").withType(Parameter.DATATYPE_BOOLEAN)
131           .withDescription("Flag to load data from applet").getParameter();
132 
133       final FixedParameters params = new FixedParameters();
134       params.addParameter(chipTypeName);
135       params.addParameter(testSuiteName);
136       params.addParameter(gprFile);
137       params.addParameter(galFile);
138       params.addParameter(description);
139       params.addParameter(loadFromApplet);
140 
141       return params;
142 
143     } catch (ParameterException e) {
144       getLogger().error("Error while creating parameters : " + e);
145     }
146 
147     return null;
148   }
149 
150   /***
151    * This method contains all the code to manipulate the container <b>c </b> in
152    * this element.
153    * @param c The container to be manipulated
154    * @param parameters Parameters of the elements
155    * @throws PlatformException if an error occurs while executing the test.
156    */
157   protected void doIt(final Container c, final Parameters parameters)
158       throws PlatformException {
159 
160     try {
161 
162       String galFilename = null;
163       BioAssay gpr = null;
164       BioAssay gal = null;
165       String chipTypeName = parameters.getParameter("chipTypeName")
166           .getStringValue();
167       String testSuiteName = parameters.getParameter("testSuiteName")
168           .getStringValue();
169       String description = parameters.getParameter("description")
170           .getStringValue();
171 
172       if (parameters.getParameter("loadFromApplet").getBooleanValue()) {
173         if (getApplet() == null)
174           throw new PlatformException("No Applet");
175         gpr = BioAssayFactory.createBioAssay(getApplet());
176 
177         galFilename = new GenepixResults(gpr).getGALFile();
178       } else {
179         gpr = loadATFFile(parameters.getParameter("gprFilename")
180             .getStringValue());
181         galFilename = parameters.getParameter("galFilename").getStringValue();
182       }
183 
184       if (galFilename != null && new File(galFilename).exists())
185         gal = loadATFFile(galFilename);
186 
187       if (gpr != null) {
188         BioAssayOMData baro = new BioAssayOMData(gpr);
189         c.add(baro);
190       }
191       if (gal != null) {
192         ArrayListOMData alro = new ArrayListOMData(gal);
193         c.add(alro);
194       }
195 
196       TestSuiteResult testSuiteResult = new TestSuiteResult(chipTypeName,
197           testSuiteName, description);
198 
199       c.add(new TestSuiteResultData(testSuiteResult));
200 
201     } catch (ParameterException e) {
202       throw new PlatformException("Parameter error : " + e.getMessage());
203     }
204 
205   }
206 
207   /***
208    * Load a ATF file.
209    * @param filename File to load
210    * @return A BioAssay Object
211    */
212   private BioAssay loadATFFile(final String filename) {
213 
214     BioAssay b = null;
215 
216     try {
217       BioAssayReader bar = new GPRReader(new FileInputStream(filename));
218       bar.addAllFieldsToRead();
219 
220       b = bar.read();
221     } catch (FileNotFoundException e) {
222       getLogger().error("File not found : " + filename);
223     } catch (NividicIOException e) {
224       getLogger().error("Can't load ATF file : " + filename);
225     }
226 
227     return b;
228   }
229 
230   //
231   // Constructor
232   //
233 
234   /***
235    * Public constructor.
236    * @throws PlatformException If the name or the version of the element is
237    *           <b>null </b>.
238    */
239   public DoelanLoadGenepixData() throws PlatformException {
240     // MUST BE EMPTY
241   }
242 
243 }