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 |
|
11 |
13 Sep 07 |
nicklas |
22 |
package affymetrix.gcos.psi; |
11 |
13 Sep 07 |
nicklas |
23 |
import java.io.*; |
11 |
13 Sep 07 |
nicklas |
24 |
import java.util.*; |
11 |
13 Sep 07 |
nicklas |
25 |
|
11 |
13 Sep 07 |
nicklas |
/** This class is used to read and access data stored in a PSI file. */ |
11 |
13 Sep 07 |
nicklas |
27 |
public class PSIFileData { |
11 |
13 Sep 07 |
nicklas |
28 |
|
11 |
13 Sep 07 |
nicklas |
/** The name of the PSI file. */ |
11 |
13 Sep 07 |
nicklas |
30 |
private String fileName; |
11 |
13 Sep 07 |
nicklas |
31 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the name of the PSI file. |
11 |
13 Sep 07 |
nicklas |
* @return The file name. |
11 |
13 Sep 07 |
nicklas |
34 |
*/ |
11 |
13 Sep 07 |
nicklas |
35 |
public String getFileName() { return fileName; } |
11 |
13 Sep 07 |
nicklas |
36 |
|
11 |
13 Sep 07 |
nicklas |
/** Sets the name of the PSI file. |
11 |
13 Sep 07 |
nicklas |
* @param name The name of the file. |
11 |
13 Sep 07 |
nicklas |
39 |
*/ |
11 |
13 Sep 07 |
nicklas |
40 |
public void setFileName(String name) { fileName = name; } |
11 |
13 Sep 07 |
nicklas |
41 |
|
11 |
13 Sep 07 |
nicklas |
/** The array of probe set names. */ |
11 |
13 Sep 07 |
nicklas |
43 |
private Vector probeSets; |
11 |
13 Sep 07 |
nicklas |
44 |
|
11 |
13 Sep 07 |
nicklas |
/** The number of probe sets in the file. |
11 |
13 Sep 07 |
nicklas |
* @return The number of probe sets. |
11 |
13 Sep 07 |
nicklas |
47 |
*/ |
11 |
13 Sep 07 |
nicklas |
48 |
public int getProbeSetCount() { |
11 |
13 Sep 07 |
nicklas |
49 |
if (probeSets == null) |
11 |
13 Sep 07 |
nicklas |
50 |
return 0; |
11 |
13 Sep 07 |
nicklas |
51 |
else |
11 |
13 Sep 07 |
nicklas |
52 |
return probeSets.size(); |
11 |
13 Sep 07 |
nicklas |
53 |
} |
11 |
13 Sep 07 |
nicklas |
54 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the probe set name. |
11 |
13 Sep 07 |
nicklas |
* @param index The 0 based index to the probe set array. |
11 |
13 Sep 07 |
nicklas |
* @return The probe set name. |
11 |
13 Sep 07 |
nicklas |
58 |
*/ |
11 |
13 Sep 07 |
nicklas |
59 |
public String getProbeSetName(int index) |
11 |
13 Sep 07 |
nicklas |
60 |
{ |
11 |
13 Sep 07 |
nicklas |
61 |
ProbeSetInfo ps = (ProbeSetInfo) probeSets.elementAt(index); |
11 |
13 Sep 07 |
nicklas |
62 |
return ps.getProbeSetName(); |
11 |
13 Sep 07 |
nicklas |
63 |
} |
11 |
13 Sep 07 |
nicklas |
64 |
|
11 |
13 Sep 07 |
nicklas |
/** Gets the number of probe pairs in a set. |
11 |
13 Sep 07 |
nicklas |
* @param index The 0 based index to the probe set array. |
11 |
13 Sep 07 |
nicklas |
* @return The number of pairs. |
11 |
13 Sep 07 |
nicklas |
68 |
*/ |
11 |
13 Sep 07 |
nicklas |
69 |
public int getProbePairs(int index) |
11 |
13 Sep 07 |
nicklas |
70 |
{ |
11 |
13 Sep 07 |
nicklas |
71 |
ProbeSetInfo ps = (ProbeSetInfo) probeSets.elementAt(index); |
11 |
13 Sep 07 |
nicklas |
72 |
return ps.getNumberPairs(); |
11 |
13 Sep 07 |
nicklas |
73 |
} |
11 |
13 Sep 07 |
nicklas |
74 |
|
11 |
13 Sep 07 |
nicklas |
/** Reads the contents of the PSI file. |
11 |
13 Sep 07 |
nicklas |
* @return True if successful. |
11 |
13 Sep 07 |
nicklas |
77 |
*/ |
11 |
13 Sep 07 |
nicklas |
78 |
public boolean read() |
11 |
13 Sep 07 |
nicklas |
79 |
{ |
11 |
13 Sep 07 |
nicklas |
80 |
clear(); |
11 |
13 Sep 07 |
nicklas |
81 |
try |
11 |
13 Sep 07 |
nicklas |
82 |
{ |
11 |
13 Sep 07 |
nicklas |
83 |
FileReader f = new FileReader(fileName); |
11 |
13 Sep 07 |
nicklas |
84 |
BufferedReader b = new BufferedReader(f); |
11 |
13 Sep 07 |
nicklas |
85 |
|
11 |
13 Sep 07 |
nicklas |
// Check that the first line is what we expect. |
11 |
13 Sep 07 |
nicklas |
87 |
String line; |
11 |
13 Sep 07 |
nicklas |
88 |
line = b.readLine(); |
11 |
13 Sep 07 |
nicklas |
89 |
String header = "#Probe Sets: "; |
11 |
13 Sep 07 |
nicklas |
90 |
if (line.startsWith(header) == false) |
11 |
13 Sep 07 |
nicklas |
91 |
return false; |
11 |
13 Sep 07 |
nicklas |
92 |
|
11 |
13 Sep 07 |
nicklas |
// Get the number of probe sets |
11 |
13 Sep 07 |
nicklas |
94 |
int nsets = Integer.parseInt(line.substring(header.length()).trim()); |
11 |
13 Sep 07 |
nicklas |
95 |
probeSets = new Vector(); |
11 |
13 Sep 07 |
nicklas |
96 |
probeSets.setSize(nsets); |
11 |
13 Sep 07 |
nicklas |
97 |
|
11 |
13 Sep 07 |
nicklas |
// Get the probe set names and #pairs |
11 |
13 Sep 07 |
nicklas |
99 |
int index=0; |
11 |
13 Sep 07 |
nicklas |
100 |
while ((line = b.readLine()) != null) |
11 |
13 Sep 07 |
nicklas |
101 |
{ |
11 |
13 Sep 07 |
nicklas |
102 |
String[] s = line.split("\t", 3); |
11 |
13 Sep 07 |
nicklas |
103 |
ProbeSetInfo info = new ProbeSetInfo(); |
11 |
13 Sep 07 |
nicklas |
104 |
info.setProbeSetName(s[1]); |
11 |
13 Sep 07 |
nicklas |
105 |
info.setNumberPairs(Integer.parseInt(s[2].trim())); |
11 |
13 Sep 07 |
nicklas |
106 |
probeSets.set(index, info); |
11 |
13 Sep 07 |
nicklas |
107 |
++index; |
11 |
13 Sep 07 |
nicklas |
108 |
} |
11 |
13 Sep 07 |
nicklas |
109 |
} |
11 |
13 Sep 07 |
nicklas |
110 |
catch (Throwable t) |
11 |
13 Sep 07 |
nicklas |
111 |
{ |
11 |
13 Sep 07 |
nicklas |
112 |
clear(); |
11 |
13 Sep 07 |
nicklas |
113 |
return false; |
11 |
13 Sep 07 |
nicklas |
114 |
} |
11 |
13 Sep 07 |
nicklas |
115 |
return true; |
11 |
13 Sep 07 |
nicklas |
116 |
} |
11 |
13 Sep 07 |
nicklas |
117 |
|
11 |
13 Sep 07 |
nicklas |
/** Checks for the existance of a file. |
11 |
13 Sep 07 |
nicklas |
* @return True if exists. |
11 |
13 Sep 07 |
nicklas |
120 |
*/ |
11 |
13 Sep 07 |
nicklas |
121 |
public boolean exists() |
11 |
13 Sep 07 |
nicklas |
122 |
{ |
11 |
13 Sep 07 |
nicklas |
123 |
return new File(fileName).exists(); |
11 |
13 Sep 07 |
nicklas |
124 |
} |
11 |
13 Sep 07 |
nicklas |
125 |
|
11 |
13 Sep 07 |
nicklas |
/** Clears the members. */ |
11 |
13 Sep 07 |
nicklas |
127 |
public void clear() |
11 |
13 Sep 07 |
nicklas |
128 |
{ |
11 |
13 Sep 07 |
nicklas |
129 |
probeSets = null; |
11 |
13 Sep 07 |
nicklas |
130 |
} |
11 |
13 Sep 07 |
nicklas |
131 |
|
11 |
13 Sep 07 |
nicklas |
/** Creates a new instance of PSIFileData */ |
11 |
13 Sep 07 |
nicklas |
133 |
public PSIFileData() { |
11 |
13 Sep 07 |
nicklas |
134 |
fileName = ""; |
11 |
13 Sep 07 |
nicklas |
135 |
clear(); |
11 |
13 Sep 07 |
nicklas |
136 |
} |
11 |
13 Sep 07 |
nicklas |
137 |
|
11 |
13 Sep 07 |
nicklas |
138 |
} |