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.data;
23  
24  import java.util.HashMap;
25  import java.util.Iterator;
26  import java.util.Map;
27  
28  import fr.ens.transcriptome.nividic.om.BioAssay;
29  import fr.ens.transcriptome.nividic.platform.data.Data;
30  import fr.ens.transcriptome.nividic.platform.data.DataDefaults;
31  import fr.ens.transcriptome.nividic.platform.workflow.Container;
32  import fr.ens.transcriptome.nividic.platform.workflow.ContainerFilter;
33  
34  /***
35   * This class defines some useful method for quality tests
36   * @author Laurent Jourdren
37   */
38  public final class DoelanDataUtils {
39  
40    /***
41     * This methods return the first BioAssay found in a Container
42     * @param container Container of the objects
43     * @return the first bioassay found in a Container
44     */
45    public static BioAssay getBioAssay(final Container container) {
46  
47      final Container bioassays = container.filterFormat(DataDefaults.OM_FORMAT)
48          .filterType(DataDefaults.BIOASSAY_TYPE);
49  
50      Iterator it = bioassays.iterator();
51  
52      if (it.hasNext()) {
53        Data rd = (Data) it.next();
54        return (BioAssay) rd.getData();
55      }
56  
57      return null;
58    }
59  
60    /***
61     * This methods return all the BioAssay found in a Container
62     * @param container Container of the objects
63     * @return the bioassay objects found in a Container
64     */
65    public static BioAssay[] getBioAssays(final Container container) {
66  
67      final Container bioassays = container.filterFormat(DataDefaults.OM_FORMAT)
68          .filterType(DataDefaults.BIOASSAY_TYPE);
69  
70      BioAssay[] result = new BioAssay[bioassays.size()];
71  
72      Iterator it = bioassays.iterator();
73      int i = 0;
74  
75      while (it.hasNext()) {
76        Data rd = (Data) it.next();
77        result[i++] = (BioAssay) rd.getData();
78      }
79  
80      return result;
81    }
82  
83    /***
84     * This methods return the first array list found in a Container
85     * @param container Container of the objects
86     * @return the first array lits found in a Container
87     */
88    public static BioAssay getArrayList(final Container container) {
89  
90      final Container arraylists = container.filterFormat(DataDefaults.OM_FORMAT)
91          .filterType(DataDefaults.ARRAYLIST_TYPE);
92  
93      Iterator it = arraylists.iterator();
94  
95      if (it.hasNext()) {
96        Data rd = (Data) it.next();
97        return (BioAssay) rd.getData();
98      }
99  
100     return null;
101   }
102 
103   /***
104    * This methods return all the BioAssay found in a Container
105    * @param container Container of the objects
106    * @return the bioassay objects found in a Container
107    */
108   public static BioAssay[] getArrayLists(final Container container) {
109 
110     final Container arraylists = container.filterFormat(DataDefaults.OM_FORMAT)
111         .filterType(DataDefaults.ARRAYLIST_TYPE);
112 
113     BioAssay[] result = new BioAssay[arraylists.size()];
114 
115     Iterator it = arraylists.iterator();
116     int i = 0;
117 
118     while (it.hasNext()) {
119       Data rd = (Data) it.next();
120       result[i++] = (BioAssay) rd.getData();
121     }
122 
123     return result;
124   }
125 
126   /***
127    * This methods return all the unit test results found in a Container
128    * @param container Container of the objects
129    * @return the unit test results objects found in a Container
130    */
131   public static QualityUnitTestResult[] getQualityUnitTestResults(
132       final Container container) {
133 
134     final Container results = container.filterFormat(DataDefaults.OM_FORMAT)
135         .filterType(DoelanDataDefaults.UNIT_TEST_RESULT_TYPE);
136 
137     QualityUnitTestResult[] result = new QualityUnitTestResult[results.size()];
138 
139     Iterator it = results.iterator();
140     int i = 0;
141 
142     while (it.hasNext()) {
143       Data rd = (Data) it.next();
144       result[i++] = (QualityUnitTestResult) rd.getData();
145     }
146 
147     return result;
148   }
149 
150   /***
151    * This methods return all the global test results found in a Container
152    * @param container Container of the objects
153    * @return the global test results objects found in a Container
154    */
155   public static QualityGlobalTestResult[] getQualityGlobalTestResults(
156       final Container container) {
157 
158     final Container results = container.filterFormat(DataDefaults.OM_FORMAT)
159         .filterType(DoelanDataDefaults.GLOBAL_TEST_RESULT_TYPE);
160 
161     QualityGlobalTestResult[] result = new QualityGlobalTestResult[results
162         .size()];
163 
164     Iterator it = results.iterator();
165     int i = 0;
166 
167     while (it.hasNext()) {
168       Data rd = (Data) it.next();
169       result[i++] = (QualityGlobalTestResult) rd.getData();
170     }
171 
172     return result;
173   }
174 
175   /***
176    * This methods return all the test results found in a Container
177    * @param container Container of the objects
178    * @return the global results objects found in a Container
179    */
180   public static QualityTestResult[] getQualityTestResults(
181       final Container container) {
182 
183     final Container results = container.filterFormat(DataDefaults.OM_FORMAT)
184         .filter(new ContainerFilter() {
185 
186           public boolean accept(final Data rd) {
187 
188             return rd.getType()
189                 .equals(DoelanDataDefaults.UNIT_TEST_RESULT_TYPE)
190                 || rd.getType().equals(
191                     DoelanDataDefaults.GLOBAL_TEST_RESULT_TYPE);
192           }
193         });
194 
195     QualityTestResult[] result = new QualityTestResult[results.size()];
196 
197     Iterator it = results.iterator();
198     int i = 0;
199 
200     while (it.hasNext()) {
201       Data rd = (Data) it.next();
202       result[i++] = (QualityTestResult) rd.getData();
203     }
204 
205     return result;
206   }
207 
208   /***
209    * This methods return all the test results found in a Container
210    * @param container Container of the objects
211    * @return the global results objects found in a Container
212    */
213   public static QualityTestResult[] getOrderedQualityTestResults(
214       final Container container) {
215 
216     TestSuiteResult tsr = getTestSuiteResult(container);
217     if (tsr == null)
218       return null;
219     String[] order = tsr.getTestIdsOrder();
220 
221     if (order == null)
222       return null;
223 
224     final Container results = container.filterFormat(DataDefaults.OM_FORMAT)
225         .filter(new ContainerFilter() {
226 
227           public boolean accept(final Data rd) {
228 
229             return rd.getType()
230                 .equals(DoelanDataDefaults.UNIT_TEST_RESULT_TYPE)
231                 || rd.getType().equals(
232                     DoelanDataDefaults.GLOBAL_TEST_RESULT_TYPE);
233           }
234         });
235 
236     QualityTestResult[] result = new QualityTestResult[order.length];
237 
238     Map map = new HashMap();
239     Iterator it = results.iterator();
240 
241     while (it.hasNext()) {
242       Data rd = (Data) it.next();
243 
244       QualityTestResult r = (QualityTestResult) rd.getData();
245       map.put(r.getTestId(), r);
246     }
247 
248     for (int j = 0; j < result.length; j++)
249       result[j] = (QualityTestResult) map.get(order[j]);
250 
251     return result;
252   }
253 
254   /***
255    * This methods return the first test suite result found in a Container
256    * @param container Container of the objects
257    * @return the first test suite result found in a Container
258    */
259   public static TestSuiteResult getTestSuiteResult(final Container container) {
260 
261     final Container arraylists = container.filterFormat(DataDefaults.OM_FORMAT)
262         .filterType(DoelanDataDefaults.TESTSUITE_RESULT_TYPE);
263 
264     Iterator it = arraylists.iterator();
265 
266     if (it.hasNext()) {
267       Data rd = (Data) it.next();
268       return (TestSuiteResult) rd.getData();
269     }
270 
271     return null;
272   }
273 
274   //
275   // Constructor
276   //
277 
278   /***
279    * Private constructor.
280    */
281   private DoelanDataUtils() {
282   }
283 
284 }