8 |
10 Oct 05 |
enell |
1 |
/* |
895 |
08 Dec 08 |
jari |
* $Id$ |
895 |
08 Dec 08 |
jari |
3 |
* |
895 |
08 Dec 08 |
jari |
* Copyright (C) 2004 Johan Enell |
895 |
08 Dec 08 |
jari |
* Copyright (C) 2008 Jari Häkkinen |
895 |
08 Dec 08 |
jari |
6 |
* |
895 |
08 Dec 08 |
jari |
* This file is part of the se.lu.onk.Center plug-in for |
895 |
08 Dec 08 |
jari |
* BASE. Available at http://baseplugins.thep.lu.se/ and BASE web site |
895 |
08 Dec 08 |
jari |
* is http://base.thep.lu.se |
895 |
08 Dec 08 |
jari |
10 |
* |
895 |
08 Dec 08 |
jari |
* This is free software; you can redistribute it and/or modify it |
895 |
08 Dec 08 |
jari |
* under the terms of the GNU General Public License as published by |
895 |
08 Dec 08 |
jari |
* the Free Software Foundation; either version 3 of the License, or |
895 |
08 Dec 08 |
jari |
* (at your option) any later version. |
895 |
08 Dec 08 |
jari |
15 |
* |
895 |
08 Dec 08 |
jari |
* The software is distributed in the hope that it will be useful, but |
895 |
08 Dec 08 |
jari |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
895 |
08 Dec 08 |
jari |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
895 |
08 Dec 08 |
jari |
* General Public License for more details. |
895 |
08 Dec 08 |
jari |
20 |
* |
8 |
10 Oct 05 |
enell |
* You should have received a copy of the GNU General Public License |
895 |
08 Dec 08 |
jari |
* along with this software. If not, see <http://www.gnu.org/licenses/>. |
8 |
10 Oct 05 |
enell |
23 |
*/ |
8 |
10 Oct 05 |
enell |
24 |
|
895 |
08 Dec 08 |
jari |
25 |
package virtualarray; |
895 |
08 Dec 08 |
jari |
26 |
|
15 |
14 Oct 05 |
enell |
27 |
import java.io.File; |
8 |
10 Oct 05 |
enell |
28 |
import java.io.FileNotFoundException; |
8 |
10 Oct 05 |
enell |
29 |
import java.io.IOException; |
13 |
11 Oct 05 |
enell |
30 |
import java.util.ArrayList; |
8 |
10 Oct 05 |
enell |
31 |
import java.util.List; |
8 |
10 Oct 05 |
enell |
32 |
|
8 |
10 Oct 05 |
enell |
33 |
import basefile.BASEFileException; |
8 |
10 Oct 05 |
enell |
34 |
import basefile.BASEFileReader; |
8 |
10 Oct 05 |
enell |
35 |
import basefile.BASEFileSection; |
8 |
10 Oct 05 |
enell |
36 |
import basefile.MissingOptionException; |
8 |
10 Oct 05 |
enell |
37 |
|
8 |
10 Oct 05 |
enell |
38 |
|
8 |
10 Oct 05 |
enell |
39 |
|
8 |
10 Oct 05 |
enell |
40 |
/** |
8 |
10 Oct 05 |
enell |
41 |
* |
8 |
10 Oct 05 |
enell |
* @author Johan Enell, johan.enell@onk.lu.se, Dept Oncology, Lund University, |
8 |
10 Oct 05 |
enell |
* S-221 85 Lund, Sweden |
8 |
10 Oct 05 |
enell |
44 |
*/ |
8 |
10 Oct 05 |
enell |
45 |
public class VirtualArray |
8 |
10 Oct 05 |
enell |
46 |
{ |
8 |
10 Oct 05 |
enell |
47 |
|
8 |
10 Oct 05 |
enell |
48 |
private VirtualArray(BASEFileReader bfr) throws BASEFileException, IOException |
8 |
10 Oct 05 |
enell |
49 |
{ |
8 |
10 Oct 05 |
enell |
50 |
BASEFileSection section = bfr.readSection(true); |
8 |
10 Oct 05 |
enell |
51 |
while (section != null) |
8 |
10 Oct 05 |
enell |
52 |
{ |
8 |
10 Oct 05 |
enell |
53 |
if (section.isType("settings")) |
8 |
10 Oct 05 |
enell |
54 |
{ |
8 |
10 Oct 05 |
enell |
55 |
extractSettings(section); |
8 |
10 Oct 05 |
enell |
56 |
} |
8 |
10 Oct 05 |
enell |
57 |
else if (section.isType("assays")) |
8 |
10 Oct 05 |
enell |
58 |
{ |
8 |
10 Oct 05 |
enell |
59 |
extractAssays(section, bfr); |
8 |
10 Oct 05 |
enell |
60 |
} |
8 |
10 Oct 05 |
enell |
61 |
else if (section.isType("spots")) |
8 |
10 Oct 05 |
enell |
62 |
{ |
8 |
10 Oct 05 |
enell |
63 |
extractSpots(section, bfr); |
8 |
10 Oct 05 |
enell |
64 |
} |
8 |
10 Oct 05 |
enell |
65 |
section = bfr.readSection(); |
8 |
10 Oct 05 |
enell |
66 |
} |
8 |
10 Oct 05 |
enell |
67 |
} |
8 |
10 Oct 05 |
enell |
68 |
|
8 |
10 Oct 05 |
enell |
69 |
private void extractSettings(BASEFileSection section) |
8 |
10 Oct 05 |
enell |
70 |
{} |
8 |
10 Oct 05 |
enell |
71 |
|
8 |
10 Oct 05 |
enell |
72 |
private void extractAssays(BASEFileSection section, BASEFileReader bfr) |
8 |
10 Oct 05 |
enell |
73 |
throws IOException, |
8 |
10 Oct 05 |
enell |
74 |
MissingOptionException |
8 |
10 Oct 05 |
enell |
75 |
{ |
8 |
10 Oct 05 |
enell |
76 |
System.out.println("BASEfile"); |
8 |
10 Oct 05 |
enell |
77 |
|
8 |
10 Oct 05 |
enell |
78 |
System.out.println(section); |
8 |
10 Oct 05 |
enell |
79 |
|
8 |
10 Oct 05 |
enell |
80 |
String[] row = bfr.readDataRow(); |
8 |
10 Oct 05 |
enell |
81 |
while (row != null) |
8 |
10 Oct 05 |
enell |
82 |
{ |
8 |
10 Oct 05 |
enell |
83 |
System.out.print(row[0]); |
8 |
10 Oct 05 |
enell |
84 |
for (int j = 1; j < row.length; j++) |
8 |
10 Oct 05 |
enell |
85 |
{ |
8 |
10 Oct 05 |
enell |
86 |
System.out.print("\t" + row[j]); |
8 |
10 Oct 05 |
enell |
87 |
} |
8 |
10 Oct 05 |
enell |
88 |
System.out.println(); |
8 |
10 Oct 05 |
enell |
89 |
row = bfr.readDataRow(); |
8 |
10 Oct 05 |
enell |
90 |
} |
8 |
10 Oct 05 |
enell |
91 |
System.out.println(); |
8 |
10 Oct 05 |
enell |
92 |
|
8 |
10 Oct 05 |
enell |
93 |
} |
8 |
10 Oct 05 |
enell |
94 |
|
8 |
10 Oct 05 |
enell |
95 |
private void extractSpots(BASEFileSection section, BASEFileReader bfr) |
8 |
10 Oct 05 |
enell |
96 |
throws BASEFileException, |
8 |
10 Oct 05 |
enell |
97 |
IOException |
8 |
10 Oct 05 |
enell |
98 |
{ |
8 |
10 Oct 05 |
enell |
99 |
List<String> columns = section.findFieldList("columns"); |
8 |
10 Oct 05 |
enell |
100 |
List<String> assayFields = section.findFieldList("assayFields"); |
13 |
11 Oct 05 |
enell |
101 |
List<String> setExtraFloats = new ArrayList<String>(); |
13 |
11 Oct 05 |
enell |
102 |
|
13 |
11 Oct 05 |
enell |
103 |
for (int i = 0; i < assayFields.size(); i++) |
13 |
11 Oct 05 |
enell |
104 |
{ |
13 |
11 Oct 05 |
enell |
105 |
String value = assayFields.get(i); |
13 |
11 Oct 05 |
enell |
106 |
if (value.startsWith("_xc_")) |
13 |
11 Oct 05 |
enell |
107 |
{ |
13 |
11 Oct 05 |
enell |
108 |
assayFields.set(i, value.substring(4)); |
13 |
11 Oct 05 |
enell |
109 |
setExtraFloats.add(value.substring(4)); |
13 |
11 Oct 05 |
enell |
110 |
} |
13 |
11 Oct 05 |
enell |
111 |
} |
13 |
11 Oct 05 |
enell |
112 |
section.setHeader("assayFields", assayFields.toArray()); |
13 |
11 Oct 05 |
enell |
113 |
if (setExtraFloats.size() > 0) |
13 |
11 Oct 05 |
enell |
114 |
{ |
13 |
11 Oct 05 |
enell |
115 |
section.setHeader("setExtraFloats", setExtraFloats.toArray()); |
13 |
11 Oct 05 |
enell |
116 |
} |
8 |
10 Oct 05 |
enell |
117 |
|
8 |
10 Oct 05 |
enell |
118 |
columns.add(0, "position"); |
8 |
10 Oct 05 |
enell |
119 |
section.setHeader("columns", columns.toArray()); |
8 |
10 Oct 05 |
enell |
120 |
System.out.println(section); |
8 |
10 Oct 05 |
enell |
121 |
|
8 |
10 Oct 05 |
enell |
122 |
String[] row = bfr.readDataRow(); |
8 |
10 Oct 05 |
enell |
123 |
int i = 0; |
13 |
11 Oct 05 |
enell |
124 |
while (row != null) |
8 |
10 Oct 05 |
enell |
125 |
{ |
8 |
10 Oct 05 |
enell |
126 |
System.out.print(--i); |
13 |
11 Oct 05 |
enell |
127 |
for (String val : row) |
8 |
10 Oct 05 |
enell |
128 |
{ |
8 |
10 Oct 05 |
enell |
129 |
System.out.print("\t" + val); |
8 |
10 Oct 05 |
enell |
130 |
} |
8 |
10 Oct 05 |
enell |
131 |
System.out.println(); |
8 |
10 Oct 05 |
enell |
132 |
row = bfr.readDataRow(); |
8 |
10 Oct 05 |
enell |
133 |
} |
8 |
10 Oct 05 |
enell |
134 |
|
8 |
10 Oct 05 |
enell |
135 |
} |
8 |
10 Oct 05 |
enell |
136 |
|
8 |
10 Oct 05 |
enell |
137 |
public static void main(String[] args) |
8 |
10 Oct 05 |
enell |
138 |
{ |
8 |
10 Oct 05 |
enell |
139 |
try |
8 |
10 Oct 05 |
enell |
140 |
{ |
8 |
10 Oct 05 |
enell |
141 |
BASEFileReader bfr = null; |
8 |
10 Oct 05 |
enell |
142 |
if (args.length == 1) |
8 |
10 Oct 05 |
enell |
143 |
{ |
15 |
14 Oct 05 |
enell |
144 |
bfr = new BASEFileReader(new File(args[0])); |
8 |
10 Oct 05 |
enell |
145 |
} |
8 |
10 Oct 05 |
enell |
146 |
else if (args.length == 0) |
8 |
10 Oct 05 |
enell |
147 |
{ |
15 |
14 Oct 05 |
enell |
148 |
bfr = new BASEFileReader(new File("stdin.txt")); |
8 |
10 Oct 05 |
enell |
149 |
} |
8 |
10 Oct 05 |
enell |
150 |
else |
8 |
10 Oct 05 |
enell |
151 |
{ |
8 |
10 Oct 05 |
enell |
152 |
System.err.println("VirtualArray: invalid input given"); |
8 |
10 Oct 05 |
enell |
153 |
System.exit(-1); |
8 |
10 Oct 05 |
enell |
154 |
} |
8 |
10 Oct 05 |
enell |
155 |
|
8 |
10 Oct 05 |
enell |
156 |
new VirtualArray(bfr); |
8 |
10 Oct 05 |
enell |
157 |
} |
8 |
10 Oct 05 |
enell |
158 |
catch (OutOfMemoryError e) |
8 |
10 Oct 05 |
enell |
159 |
{ |
8 |
10 Oct 05 |
enell |
160 |
System.err.println("No more memory in the java virtual machine. Try to start the application with the flag '-Xmx256m' or '-Xmx512m'. If you need even more memory choose a larger digit (max 1024)"); |
8 |
10 Oct 05 |
enell |
161 |
e.printStackTrace(); |
8 |
10 Oct 05 |
enell |
162 |
System.exit(-1); |
8 |
10 Oct 05 |
enell |
163 |
} |
8 |
10 Oct 05 |
enell |
164 |
catch (FileNotFoundException e) |
8 |
10 Oct 05 |
enell |
165 |
{ |
8 |
10 Oct 05 |
enell |
166 |
e.printStackTrace(); |
8 |
10 Oct 05 |
enell |
167 |
} |
8 |
10 Oct 05 |
enell |
168 |
catch (BASEFileException e) |
8 |
10 Oct 05 |
enell |
169 |
{ |
8 |
10 Oct 05 |
enell |
170 |
e.printStackTrace(); |
8 |
10 Oct 05 |
enell |
171 |
} |
8 |
10 Oct 05 |
enell |
172 |
catch (IOException e) |
8 |
10 Oct 05 |
enell |
173 |
{ |
8 |
10 Oct 05 |
enell |
174 |
e.printStackTrace(); |
8 |
10 Oct 05 |
enell |
175 |
} |
8 |
10 Oct 05 |
enell |
176 |
} |
8 |
10 Oct 05 |
enell |
177 |
} |