11 |
13 Sep 07 |
nicklas |
1 |
///////////////////////////////////////////////////////////////// |
11 |
13 Sep 07 |
nicklas |
2 |
// |
11 |
13 Sep 07 |
nicklas |
// Copyright (C) 2005 Affymetrix, Inc. |
11 |
13 Sep 07 |
nicklas |
4 |
// |
11 |
13 Sep 07 |
nicklas |
// This library is free software; you can redistribute it and/or modify |
11 |
13 Sep 07 |
nicklas |
// it under the terms of the GNU Lesser General Public License as published |
11 |
13 Sep 07 |
nicklas |
// by the Free Software Foundation; either version 2.1 of the License, |
11 |
13 Sep 07 |
nicklas |
// or (at your option) any later version. |
11 |
13 Sep 07 |
nicklas |
9 |
// |
11 |
13 Sep 07 |
nicklas |
// This library is distributed in the hope that it will be useful, but |
11 |
13 Sep 07 |
nicklas |
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
11 |
13 Sep 07 |
nicklas |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
11 |
13 Sep 07 |
nicklas |
// for more details. |
11 |
13 Sep 07 |
nicklas |
14 |
// |
11 |
13 Sep 07 |
nicklas |
// You should have received a copy of the GNU Lesser General Public License |
11 |
13 Sep 07 |
nicklas |
// along with this library; if not, write to the Free Software Foundation, Inc., |
11 |
13 Sep 07 |
nicklas |
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
11 |
13 Sep 07 |
nicklas |
18 |
// |
11 |
13 Sep 07 |
nicklas |
19 |
///////////////////////////////////////////////////////////////// |
11 |
13 Sep 07 |
nicklas |
20 |
|
11 |
13 Sep 07 |
nicklas |
21 |
package affymetrix.fusion.chp; |
11 |
13 Sep 07 |
nicklas |
22 |
|
11 |
13 Sep 07 |
nicklas |
23 |
import affymetrix.calvin.data.*; |
11 |
13 Sep 07 |
nicklas |
24 |
import affymetrix.calvin.utils.*; |
11 |
13 Sep 07 |
nicklas |
25 |
import affymetrix.calvin.parsers.*; |
11 |
13 Sep 07 |
nicklas |
26 |
import java.util.*; |
11 |
13 Sep 07 |
nicklas |
27 |
|
11 |
13 Sep 07 |
nicklas |
/** This class provides storage and reading capabilities for CHP files */ |
11 |
13 Sep 07 |
nicklas |
29 |
public class FusionCHPGenericData extends FusionCHPData |
11 |
13 Sep 07 |
nicklas |
30 |
{ |
11 |
13 Sep 07 |
nicklas |
31 |
|
11 |
13 Sep 07 |
nicklas |
/** Deallocates any memory used by the class object */ |
11 |
13 Sep 07 |
nicklas |
33 |
public void clear() { genericData = null; } |
11 |
13 Sep 07 |
nicklas |
34 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the generic data object. |
11 |
13 Sep 07 |
nicklas |
* @return The generic data object. |
11 |
13 Sep 07 |
nicklas |
37 |
*/ |
11 |
13 Sep 07 |
nicklas |
38 |
public GenericData getData() { return genericData; } |
11 |
13 Sep 07 |
nicklas |
39 |
|
11 |
13 Sep 07 |
nicklas |
/** Constructor */ |
11 |
13 Sep 07 |
nicklas |
41 |
private FusionCHPGenericData() { clear(); } |
11 |
13 Sep 07 |
nicklas |
42 |
|
11 |
13 Sep 07 |
nicklas |
/** The generic file data object. */ |
11 |
13 Sep 07 |
nicklas |
44 |
private GenericData genericData; |
11 |
13 Sep 07 |
nicklas |
45 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the CHP file. |
11 |
13 Sep 07 |
nicklas |
* @return True if successful. |
11 |
13 Sep 07 |
nicklas |
48 |
*/ |
11 |
13 Sep 07 |
nicklas |
49 |
protected boolean read() { |
11 |
13 Sep 07 |
nicklas |
50 |
genericData = new GenericData(); |
11 |
13 Sep 07 |
nicklas |
51 |
GenericFileReader reader = new GenericFileReader(); |
11 |
13 Sep 07 |
nicklas |
52 |
try |
11 |
13 Sep 07 |
nicklas |
53 |
{ |
11 |
13 Sep 07 |
nicklas |
54 |
reader.setFilename(filename); |
11 |
13 Sep 07 |
nicklas |
55 |
reader.open(genericData, ReadHeaderOption.ReadAllHeaders); |
11 |
13 Sep 07 |
nicklas |
56 |
return true; |
11 |
13 Sep 07 |
nicklas |
57 |
} |
11 |
13 Sep 07 |
nicklas |
58 |
catch (Throwable t) |
11 |
13 Sep 07 |
nicklas |
59 |
{ |
11 |
13 Sep 07 |
nicklas |
60 |
clear(); |
11 |
13 Sep 07 |
nicklas |
61 |
return false; |
11 |
13 Sep 07 |
nicklas |
62 |
} |
11 |
13 Sep 07 |
nicklas |
63 |
} |
11 |
13 Sep 07 |
nicklas |
64 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the header of the CHP file |
11 |
13 Sep 07 |
nicklas |
* @return True if successful |
11 |
13 Sep 07 |
nicklas |
67 |
*/ |
11 |
13 Sep 07 |
nicklas |
68 |
protected boolean readHeader() { return read(); } |
11 |
13 Sep 07 |
nicklas |
69 |
|
11 |
13 Sep 07 |
nicklas |
/** Get the id of the file (only valid for Command Console "calvin" files) |
11 |
13 Sep 07 |
nicklas |
* @return The unique file id. |
11 |
13 Sep 07 |
nicklas |
72 |
*/ |
11 |
13 Sep 07 |
nicklas |
73 |
public AffymetrixGuidType getFileId() { |
11 |
13 Sep 07 |
nicklas |
74 |
return genericData.getFileIdentifier(); |
11 |
13 Sep 07 |
nicklas |
75 |
} |
11 |
13 Sep 07 |
nicklas |
76 |
|
11 |
13 Sep 07 |
nicklas |
/** A class to register a generic CHP reader. */ |
11 |
13 Sep 07 |
nicklas |
78 |
private static class Reg extends FusionCHPDataReg |
11 |
13 Sep 07 |
nicklas |
79 |
{ |
11 |
13 Sep 07 |
nicklas |
/** Constructor - register the file type. */ |
11 |
13 Sep 07 |
nicklas |
81 |
public Reg() { |
11 |
13 Sep 07 |
nicklas |
82 |
super(); |
11 |
13 Sep 07 |
nicklas |
83 |
Vector ids = new Vector(); |
11 |
13 Sep 07 |
nicklas |
84 |
setFileTypeIds(ids); |
11 |
13 Sep 07 |
nicklas |
85 |
} |
11 |
13 Sep 07 |
nicklas |
86 |
|
11 |
13 Sep 07 |
nicklas |
/** Creates a generic CHP object. |
11 |
13 Sep 07 |
nicklas |
* @return The generic CHP object. |
11 |
13 Sep 07 |
nicklas |
89 |
*/ |
11 |
13 Sep 07 |
nicklas |
90 |
public FusionCHPData makeObject() { return new FusionCHPGenericData(); } |
11 |
13 Sep 07 |
nicklas |
91 |
}; |
11 |
13 Sep 07 |
nicklas |
92 |
|
11 |
13 Sep 07 |
nicklas |
/** The one and only registration object. This registers the class as a CHP reader. */ |
11 |
13 Sep 07 |
nicklas |
94 |
private static Reg reg = new Reg(); |
11 |
13 Sep 07 |
nicklas |
95 |
|
11 |
13 Sep 07 |
nicklas |
/** Register the reader with the system. */ |
11 |
13 Sep 07 |
nicklas |
97 |
public static void registerReader() { |
11 |
13 Sep 07 |
nicklas |
98 |
if (FusionCHPGenericData.reg == null) |
11 |
13 Sep 07 |
nicklas |
99 |
FusionCHPGenericData.reg = new Reg(); |
11 |
13 Sep 07 |
nicklas |
100 |
} |
11 |
13 Sep 07 |
nicklas |
101 |
|
11 |
13 Sep 07 |
nicklas |
/** Converts the type to the generic CHP type. |
11 |
13 Sep 07 |
nicklas |
* @param chip The pointer to the CHP data object. |
11 |
13 Sep 07 |
nicklas |
* @return The generic CHP data type or NULL if not compatible. |
11 |
13 Sep 07 |
nicklas |
105 |
*/ |
11 |
13 Sep 07 |
nicklas |
106 |
public static FusionCHPGenericData fromBase(FusionCHPData chip) { |
11 |
13 Sep 07 |
nicklas |
107 |
if (chip == null) |
11 |
13 Sep 07 |
nicklas |
108 |
return null; |
11 |
13 Sep 07 |
nicklas |
109 |
String chipName = chip.getClass().getName(); |
11 |
13 Sep 07 |
nicklas |
110 |
String genName = FusionCHPGenericData.class.getName(); |
11 |
13 Sep 07 |
nicklas |
111 |
if (chipName.compareTo(genName) == 0) |
11 |
13 Sep 07 |
nicklas |
112 |
return (FusionCHPGenericData) chip; |
11 |
13 Sep 07 |
nicklas |
113 |
return null; |
11 |
13 Sep 07 |
nicklas |
114 |
} |
11 |
13 Sep 07 |
nicklas |
115 |
|
11 |
13 Sep 07 |
nicklas |
116 |
} |