5623 |
06 May 11 |
nicklas |
1 |
/** |
5623 |
06 May 11 |
nicklas |
$Id$ |
5623 |
06 May 11 |
nicklas |
3 |
|
5623 |
06 May 11 |
nicklas |
Copyright (C) 2011 Nicklas Nordborg |
5623 |
06 May 11 |
nicklas |
5 |
|
5623 |
06 May 11 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5623 |
06 May 11 |
nicklas |
Available at http://base.thep.lu.se/ |
5623 |
06 May 11 |
nicklas |
8 |
|
5623 |
06 May 11 |
nicklas |
BASE is free software; you can redistribute it and/or |
5623 |
06 May 11 |
nicklas |
modify it under the terms of the GNU General Public License |
5623 |
06 May 11 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5623 |
06 May 11 |
nicklas |
of the License, or (at your option) any later version. |
5623 |
06 May 11 |
nicklas |
13 |
|
5623 |
06 May 11 |
nicklas |
BASE is distributed in the hope that it will be useful, |
5623 |
06 May 11 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5623 |
06 May 11 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5623 |
06 May 11 |
nicklas |
GNU General Public License for more details. |
5623 |
06 May 11 |
nicklas |
18 |
|
5623 |
06 May 11 |
nicklas |
You should have received a copy of the GNU General Public License |
5623 |
06 May 11 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5623 |
06 May 11 |
nicklas |
21 |
*/ |
5623 |
06 May 11 |
nicklas |
22 |
package net.sf.basedb.util.affymetrix; |
5623 |
06 May 11 |
nicklas |
23 |
|
5713 |
02 Sep 11 |
nicklas |
24 |
import java.util.List; |
5713 |
02 Sep 11 |
nicklas |
25 |
|
5623 |
06 May 11 |
nicklas |
26 |
import affymetrix.fusion.cdf.FusionCDFData; |
5623 |
06 May 11 |
nicklas |
27 |
import affymetrix.fusion.cel.FusionCELData; |
5623 |
06 May 11 |
nicklas |
28 |
import net.sf.basedb.core.ArrayDesign; |
5623 |
06 May 11 |
nicklas |
29 |
import net.sf.basedb.core.DataFileType; |
5623 |
06 May 11 |
nicklas |
30 |
import net.sf.basedb.core.DbControl; |
5623 |
06 May 11 |
nicklas |
31 |
import net.sf.basedb.core.File; |
5623 |
06 May 11 |
nicklas |
32 |
import net.sf.basedb.core.FileStoreEnabled; |
5623 |
06 May 11 |
nicklas |
33 |
import net.sf.basedb.core.FileStoreUtil; |
5623 |
06 May 11 |
nicklas |
34 |
import net.sf.basedb.core.InvalidDataException; |
5623 |
06 May 11 |
nicklas |
35 |
import net.sf.basedb.core.InvalidUseOfNullException; |
5623 |
06 May 11 |
nicklas |
36 |
import net.sf.basedb.core.Platform; |
5623 |
06 May 11 |
nicklas |
37 |
import net.sf.basedb.core.RawBioAssay; |
5623 |
06 May 11 |
nicklas |
38 |
|
5623 |
06 May 11 |
nicklas |
39 |
/** |
5623 |
06 May 11 |
nicklas |
Utility class with Affymetrix-related functionality. |
5623 |
06 May 11 |
nicklas |
41 |
|
5623 |
06 May 11 |
nicklas |
@author Nicklas |
5623 |
06 May 11 |
nicklas |
@since 3.0 |
5623 |
06 May 11 |
nicklas |
@base.modified $Date$ |
5623 |
06 May 11 |
nicklas |
45 |
*/ |
5623 |
06 May 11 |
nicklas |
46 |
public final class AffymetrixUtil |
5623 |
06 May 11 |
nicklas |
47 |
{ |
5623 |
06 May 11 |
nicklas |
48 |
|
5623 |
06 May 11 |
nicklas |
49 |
/** |
5623 |
06 May 11 |
nicklas |
Check if the item is using the affymetrix platform. |
5623 |
06 May 11 |
nicklas |
@param item Item to check. Null is not allowed. |
5623 |
06 May 11 |
nicklas |
@return TRUE if platform is used, FALSE otherwise. |
5623 |
06 May 11 |
nicklas |
53 |
*/ |
5623 |
06 May 11 |
nicklas |
54 |
public static boolean isAffymetrix(FileStoreEnabled item) |
5623 |
06 May 11 |
nicklas |
55 |
{ |
5623 |
06 May 11 |
nicklas |
56 |
if (item == null) throw new InvalidUseOfNullException("item"); |
5623 |
06 May 11 |
nicklas |
57 |
Platform platform = item.getPlatform(); |
5623 |
06 May 11 |
nicklas |
58 |
if (platform == null || !Platform.AFFYMETRIX.equals(platform.getExternalId())) |
5623 |
06 May 11 |
nicklas |
59 |
{ |
5623 |
06 May 11 |
nicklas |
60 |
return false; |
5623 |
06 May 11 |
nicklas |
61 |
} |
5623 |
06 May 11 |
nicklas |
62 |
return true; |
5623 |
06 May 11 |
nicklas |
63 |
} |
5623 |
06 May 11 |
nicklas |
64 |
|
5623 |
06 May 11 |
nicklas |
65 |
/** |
5623 |
06 May 11 |
nicklas |
Check if the CEL file on the raw bioassay matches the CDF file on the |
5713 |
02 Sep 11 |
nicklas |
array design. If the array design has more than one CDF file only the |
5713 |
02 Sep 11 |
nicklas |
first one is used. If the raw bioassay has more than one CEL file, each |
5713 |
02 Sep 11 |
nicklas |
file will be validated against the CDF. |
5623 |
06 May 11 |
nicklas |
70 |
|
5623 |
06 May 11 |
nicklas |
@param rawBioAssay The raw bioassay |
5623 |
06 May 11 |
nicklas |
@param design The array design |
5623 |
06 May 11 |
nicklas |
@param required TRUE if the absense of either a CEL or a CDF file is an |
5623 |
06 May 11 |
nicklas |
error condition |
5623 |
06 May 11 |
nicklas |
@throws InvalidDataException If the raw bioassay or array design are not |
5623 |
06 May 11 |
nicklas |
Affymetrix type, or if the CEL doesn't match the CDF |
5623 |
06 May 11 |
nicklas |
@since 2.4 |
5623 |
06 May 11 |
nicklas |
78 |
*/ |
5623 |
06 May 11 |
nicklas |
79 |
public static void validateCelAndCdf(RawBioAssay rawBioAssay, ArrayDesign design, boolean required) |
5623 |
06 May 11 |
nicklas |
80 |
{ |
5623 |
06 May 11 |
nicklas |
81 |
DbControl dc = rawBioAssay.getDbControl(); |
5713 |
02 Sep 11 |
nicklas |
82 |
List<File> celFiles = FileStoreUtil.getDataFiles(dc, rawBioAssay, DataFileType.AFFYMETRIX_CEL, false); |
5623 |
06 May 11 |
nicklas |
83 |
File cdfFile = FileStoreUtil.getDataFile(dc, design, DataFileType.AFFYMETRIX_CDF, false); |
5713 |
02 Sep 11 |
nicklas |
84 |
if (cdfFile != null && celFiles != null && celFiles.size() > 0) |
5623 |
06 May 11 |
nicklas |
85 |
{ |
5623 |
06 May 11 |
nicklas |
86 |
String cdfChipType = cdfFile.getName(); |
5623 |
06 May 11 |
nicklas |
87 |
CelValidator celValidator = new CelValidator(); |
5623 |
06 May 11 |
nicklas |
88 |
CdfValidator cdfValidator = new CdfValidator(); |
5623 |
06 May 11 |
nicklas |
89 |
FusionCDFData cdf = cdfValidator.loadCdfFile(cdfFile); |
5713 |
02 Sep 11 |
nicklas |
90 |
|
5713 |
02 Sep 11 |
nicklas |
91 |
for (File celFile : celFiles) |
5713 |
02 Sep 11 |
nicklas |
92 |
{ |
5713 |
02 Sep 11 |
nicklas |
93 |
FusionCELData cel = celValidator.loadCelFile(celFile); |
5713 |
02 Sep 11 |
nicklas |
94 |
celValidator.validateCelAndCdf(cel, cdf, cdfChipType); |
5713 |
02 Sep 11 |
nicklas |
95 |
} |
5623 |
06 May 11 |
nicklas |
96 |
} |
5623 |
06 May 11 |
nicklas |
97 |
else if (required) |
5623 |
06 May 11 |
nicklas |
98 |
{ |
5713 |
02 Sep 11 |
nicklas |
99 |
if (celFiles == null || celFiles.size() == 0) |
5623 |
06 May 11 |
nicklas |
100 |
{ |
5623 |
06 May 11 |
nicklas |
101 |
throw new InvalidDataException("Raw bioassay has no CEL file: " + rawBioAssay); |
5623 |
06 May 11 |
nicklas |
102 |
} |
5623 |
06 May 11 |
nicklas |
103 |
else |
5623 |
06 May 11 |
nicklas |
104 |
{ |
5623 |
06 May 11 |
nicklas |
105 |
throw new InvalidDataException("Array design has no CDF file: " + design); |
5623 |
06 May 11 |
nicklas |
106 |
} |
5623 |
06 May 11 |
nicklas |
107 |
} |
5623 |
06 May 11 |
nicklas |
108 |
} |
5623 |
06 May 11 |
nicklas |
109 |
|
5623 |
06 May 11 |
nicklas |
110 |
} |