783 |
18 Sep 08 |
jari |
1 |
/* |
783 |
18 Sep 08 |
jari |
$Id$ |
149 |
10 Aug 06 |
enell |
3 |
|
783 |
18 Sep 08 |
jari |
Copyright (C) 2006 Johan Enell |
783 |
18 Sep 08 |
jari |
Copyright (C) 2008 Jari Häkkinen |
783 |
18 Sep 08 |
jari |
6 |
|
783 |
18 Sep 08 |
jari |
This file is part of the se.lu.onk.MergeBioAssay plug-in for |
783 |
18 Sep 08 |
jari |
BASE. Available at http://baseplugins.thep.lu.se/ and BASE web |
783 |
18 Sep 08 |
jari |
site is http://base.thep.lu.se |
783 |
18 Sep 08 |
jari |
10 |
|
783 |
18 Sep 08 |
jari |
This is free software; you can redistribute it and/or modify it |
783 |
18 Sep 08 |
jari |
under the terms of the GNU General Public License as published by |
783 |
18 Sep 08 |
jari |
the Free Software Foundation; either version 3 of the License, or |
783 |
18 Sep 08 |
jari |
(at your option) any later version. |
783 |
18 Sep 08 |
jari |
15 |
|
783 |
18 Sep 08 |
jari |
The software is distributed in the hope that it will be useful, but |
783 |
18 Sep 08 |
jari |
WITHOUT ANY WARRANTY; without even the implied warranty of |
783 |
18 Sep 08 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
783 |
18 Sep 08 |
jari |
General Public License for more details. |
783 |
18 Sep 08 |
jari |
20 |
|
783 |
18 Sep 08 |
jari |
You should have received a copy of the GNU General Public License |
783 |
18 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
783 |
18 Sep 08 |
jari |
23 |
*/ |
149 |
10 Aug 06 |
enell |
24 |
package mergebioassay; |
149 |
10 Aug 06 |
enell |
25 |
|
149 |
10 Aug 06 |
enell |
26 |
import java.io.File; |
149 |
10 Aug 06 |
enell |
27 |
import java.io.FileNotFoundException; |
149 |
10 Aug 06 |
enell |
28 |
import java.io.FileOutputStream; |
149 |
10 Aug 06 |
enell |
29 |
import java.io.IOException; |
149 |
10 Aug 06 |
enell |
30 |
import java.io.PrintStream; |
149 |
10 Aug 06 |
enell |
31 |
import java.util.ArrayList; |
149 |
10 Aug 06 |
enell |
32 |
import java.util.HashMap; |
149 |
10 Aug 06 |
enell |
33 |
import java.util.Iterator; |
149 |
10 Aug 06 |
enell |
34 |
import java.util.List; |
149 |
10 Aug 06 |
enell |
35 |
|
149 |
10 Aug 06 |
enell |
36 |
import java.io.FileInputStream; |
149 |
10 Aug 06 |
enell |
37 |
|
149 |
10 Aug 06 |
enell |
38 |
import mergebioassay.mergers.ArithmeticIntensityMerger; |
149 |
10 Aug 06 |
enell |
39 |
import mergebioassay.mergers.ArithmeticRatioMerger; |
149 |
10 Aug 06 |
enell |
40 |
import mergebioassay.mergers.BadPatternException; |
149 |
10 Aug 06 |
enell |
41 |
import mergebioassay.mergers.GeometricRatioMerger; |
149 |
10 Aug 06 |
enell |
42 |
import mergebioassay.mergers.Merge_assay; |
149 |
10 Aug 06 |
enell |
43 |
import mergebioassay.mergers.Merger; |
149 |
10 Aug 06 |
enell |
44 |
import mergebioassay.mergers.RatioRatioMerger; |
149 |
10 Aug 06 |
enell |
45 |
|
149 |
10 Aug 06 |
enell |
46 |
import basefile.BASEFileException; |
149 |
10 Aug 06 |
enell |
47 |
import basefile.BASEFileReader; |
149 |
10 Aug 06 |
enell |
48 |
import basefile.BASEFileSection; |
149 |
10 Aug 06 |
enell |
49 |
import basefile.BadSectionException; |
149 |
10 Aug 06 |
enell |
50 |
|
149 |
10 Aug 06 |
enell |
51 |
/** |
149 |
10 Aug 06 |
enell |
* @author Johan Enell |
149 |
10 Aug 06 |
enell |
53 |
* |
149 |
10 Aug 06 |
enell |
* Merge bioassays is a plugin created for the database BASE and is designed |
149 |
10 Aug 06 |
enell |
* for merging bioassays. There are four merging method implemented in this |
149 |
10 Aug 06 |
enell |
* version which are using both arithmetic and geometric mean to calculte the |
149 |
10 Aug 06 |
enell |
* numbers. They will also allow the choice to calculate the mean from the |
149 |
10 Aug 06 |
enell |
* intensities or form raito. |
149 |
10 Aug 06 |
enell |
59 |
*/ |
149 |
10 Aug 06 |
enell |
60 |
public class MergeBioAssay |
149 |
10 Aug 06 |
enell |
61 |
{ |
149 |
10 Aug 06 |
enell |
62 |
private final int GEOMETRIC_RATIO = 0, ARITHMETIC_RATIO = 1, |
149 |
10 Aug 06 |
enell |
63 |
ARITHMETIC_INT = 2, RATIO_RATIO = 3; |
149 |
10 Aug 06 |
enell |
64 |
|
149 |
10 Aug 06 |
enell |
65 |
private String param_newname = ""; |
149 |
10 Aug 06 |
enell |
66 |
|
149 |
10 Aug 06 |
enell |
67 |
private String param_assayname = "%1"; |
149 |
10 Aug 06 |
enell |
68 |
|
149 |
10 Aug 06 |
enell |
69 |
private String param_group = "%1"; |
149 |
10 Aug 06 |
enell |
70 |
|
149 |
10 Aug 06 |
enell |
71 |
private String param_annType = ""; |
149 |
10 Aug 06 |
enell |
72 |
|
149 |
10 Aug 06 |
enell |
73 |
private String param_annValue = ""; |
149 |
10 Aug 06 |
enell |
74 |
|
149 |
10 Aug 06 |
enell |
75 |
private String param_ratio = ""; |
149 |
10 Aug 06 |
enell |
76 |
|
149 |
10 Aug 06 |
enell |
77 |
private int param_mergeMethod = GEOMETRIC_RATIO; |
149 |
10 Aug 06 |
enell |
78 |
|
149 |
10 Aug 06 |
enell |
79 |
private int nbrOfGroups = -1; |
149 |
10 Aug 06 |
enell |
80 |
|
149 |
10 Aug 06 |
enell |
81 |
private int sortnbr = 1; |
149 |
10 Aug 06 |
enell |
82 |
|
149 |
10 Aug 06 |
enell |
83 |
private boolean annSort = false; |
149 |
10 Aug 06 |
enell |
84 |
|
149 |
10 Aug 06 |
enell |
85 |
private String ratio = ""; |
149 |
10 Aug 06 |
enell |
86 |
|
149 |
10 Aug 06 |
enell |
87 |
private String ratioNumerator = ""; |
149 |
10 Aug 06 |
enell |
88 |
|
149 |
10 Aug 06 |
enell |
89 |
private String ratioDenominator = ""; |
149 |
10 Aug 06 |
enell |
90 |
|
149 |
10 Aug 06 |
enell |
91 |
private NoGroup noGroup = new NoGroup(); |
149 |
10 Aug 06 |
enell |
92 |
|
149 |
10 Aug 06 |
enell |
93 |
private HashMap<String, List<Merge_assay>> assayGroups = new HashMap<String, List<Merge_assay>>(); |
149 |
10 Aug 06 |
enell |
94 |
|
149 |
10 Aug 06 |
enell |
95 |
/** |
149 |
10 Aug 06 |
enell |
* SmoothMain method for the plugin. |
149 |
10 Aug 06 |
enell |
97 |
* |
149 |
10 Aug 06 |
enell |
* @param args |
149 |
10 Aug 06 |
enell |
99 |
*/ |
149 |
10 Aug 06 |
enell |
100 |
public static void main(String[] args) |
149 |
10 Aug 06 |
enell |
101 |
{ |
149 |
10 Aug 06 |
enell |
102 |
if (args.length == 1) |
149 |
10 Aug 06 |
enell |
103 |
{ |
149 |
10 Aug 06 |
enell |
104 |
try |
149 |
10 Aug 06 |
enell |
105 |
{ |
149 |
10 Aug 06 |
enell |
106 |
System.setIn(new FileInputStream("stdin.txt")); |
149 |
10 Aug 06 |
enell |
107 |
System.setOut(new PrintStream(new FileOutputStream("stdout.txt"))); |
149 |
10 Aug 06 |
enell |
108 |
} |
149 |
10 Aug 06 |
enell |
109 |
catch (FileNotFoundException fnfe) |
149 |
10 Aug 06 |
enell |
110 |
{ |
149 |
10 Aug 06 |
enell |
111 |
fnfe.printStackTrace(); |
149 |
10 Aug 06 |
enell |
112 |
} |
149 |
10 Aug 06 |
enell |
113 |
} |
149 |
10 Aug 06 |
enell |
114 |
|
149 |
10 Aug 06 |
enell |
115 |
MergeBioAssay merge = new MergeBioAssay(); |
149 |
10 Aug 06 |
enell |
116 |
try |
149 |
10 Aug 06 |
enell |
117 |
{ |
149 |
10 Aug 06 |
enell |
118 |
BASEFileReader reader = new BASEFileReader(new File("stdin.txt")); |
149 |
10 Aug 06 |
enell |
119 |
BASEFileSection section = null; |
149 |
10 Aug 06 |
enell |
120 |
|
149 |
10 Aug 06 |
enell |
121 |
section = reader.readSection(true); |
149 |
10 Aug 06 |
enell |
122 |
if (section.isType("merge_bioassays settings")) |
149 |
10 Aug 06 |
enell |
123 |
{ |
149 |
10 Aug 06 |
enell |
124 |
merge.extractSettings(section); |
149 |
10 Aug 06 |
enell |
125 |
} |
149 |
10 Aug 06 |
enell |
126 |
|
149 |
10 Aug 06 |
enell |
127 |
section = reader.readSection(); |
149 |
10 Aug 06 |
enell |
128 |
if (section.isType("assays")) |
149 |
10 Aug 06 |
enell |
129 |
{ |
149 |
10 Aug 06 |
enell |
130 |
merge.extractAssays(section, reader); |
149 |
10 Aug 06 |
enell |
131 |
} |
149 |
10 Aug 06 |
enell |
132 |
|
149 |
10 Aug 06 |
enell |
133 |
section = reader.readSection(); |
149 |
10 Aug 06 |
enell |
134 |
if (section.isType("spots")) |
149 |
10 Aug 06 |
enell |
135 |
{ |
149 |
10 Aug 06 |
enell |
136 |
merge.mergeSpots(section, reader); |
149 |
10 Aug 06 |
enell |
137 |
} |
149 |
10 Aug 06 |
enell |
138 |
|
149 |
10 Aug 06 |
enell |
139 |
if (!merge.noGroup.isEmpty()) |
149 |
10 Aug 06 |
enell |
140 |
{ |
149 |
10 Aug 06 |
enell |
141 |
System.setIn(new FileInputStream("stdin.txt")); |
149 |
10 Aug 06 |
enell |
142 |
reader = new BASEFileReader(new File("stdin.txt")); |
149 |
10 Aug 06 |
enell |
143 |
section = reader.readSection(); |
149 |
10 Aug 06 |
enell |
144 |
while (section != null) |
149 |
10 Aug 06 |
enell |
145 |
{ |
149 |
10 Aug 06 |
enell |
146 |
if (section.isType("spots")) |
149 |
10 Aug 06 |
enell |
147 |
{ |
149 |
10 Aug 06 |
enell |
148 |
merge.noGroup.printNoGroup(section, reader); |
149 |
10 Aug 06 |
enell |
149 |
break; |
149 |
10 Aug 06 |
enell |
150 |
} |
149 |
10 Aug 06 |
enell |
151 |
else |
149 |
10 Aug 06 |
enell |
152 |
section = reader.readSection(); |
149 |
10 Aug 06 |
enell |
153 |
} |
149 |
10 Aug 06 |
enell |
154 |
} |
149 |
10 Aug 06 |
enell |
155 |
|
149 |
10 Aug 06 |
enell |
156 |
System.setOut(new PrintStream(new FileOutputStream("report.htm"))); |
149 |
10 Aug 06 |
enell |
157 |
|
149 |
10 Aug 06 |
enell |
158 |
System.out.println("<html><head><title>Report from merge</title></head>\n<body>"); |
149 |
10 Aug 06 |
enell |
159 |
System.out.println("<big>Parameters</big>"); |
149 |
10 Aug 06 |
enell |
160 |
System.out.println("<table border=\"0\">"); |
149 |
10 Aug 06 |
enell |
161 |
System.out.println("<tr>\n<td>assayname\n<td>" + merge.param_assayname); |
149 |
10 Aug 06 |
enell |
162 |
System.out.println("<tr>\n<td>group\n<td>" + merge.param_group); |
149 |
10 Aug 06 |
enell |
163 |
System.out.println("<tr>\n<td>newname\n<td>" + merge.param_newname); |
149 |
10 Aug 06 |
enell |
164 |
System.out.println("<tr>\n<td>ratio\n<td>" + merge.param_ratio); |
149 |
10 Aug 06 |
enell |
165 |
System.out.println("<tr>\n<td>mergeMethod\n<td>" + merge.param_mergeMethod); |
149 |
10 Aug 06 |
enell |
166 |
System.out.println("<tr>\n<td>annType\n<td>" + merge.param_annType); |
149 |
10 Aug 06 |
enell |
167 |
System.out.println("<tr>\n<td>annValue\n<td>" + merge.param_annValue); |
149 |
10 Aug 06 |
enell |
168 |
System.out.println("</table>"); |
149 |
10 Aug 06 |
enell |
169 |
|
149 |
10 Aug 06 |
enell |
170 |
System.out.println("<br>"); |
149 |
10 Aug 06 |
enell |
171 |
System.out.println("<big>Groups</big>"); |
149 |
10 Aug 06 |
enell |
172 |
System.out.println("<table border=\"1\">"); |
149 |
10 Aug 06 |
enell |
173 |
for (String key : merge.assayGroups.keySet()) |
149 |
10 Aug 06 |
enell |
174 |
{ |
149 |
10 Aug 06 |
enell |
175 |
System.out.println("<tr>\n<td>" + merge.param_newname + key + "\n<td>"); |
149 |
10 Aug 06 |
enell |
176 |
|
149 |
10 Aug 06 |
enell |
177 |
List<Merge_assay> group = merge.assayGroups.get(key); |
149 |
10 Aug 06 |
enell |
178 |
for (int i = 0; i < group.size(); i++) |
149 |
10 Aug 06 |
enell |
179 |
{ |
149 |
10 Aug 06 |
enell |
180 |
BioAssay tmp = group.get(i); |
149 |
10 Aug 06 |
enell |
181 |
System.out.println(tmp.name + "<br>"); |
149 |
10 Aug 06 |
enell |
182 |
} |
149 |
10 Aug 06 |
enell |
183 |
} |
149 |
10 Aug 06 |
enell |
184 |
if (!merge.noGroup.isEmpty()) |
149 |
10 Aug 06 |
enell |
185 |
{ |
149 |
10 Aug 06 |
enell |
186 |
System.out.println("<tr>\n<td>noGroup<td>"); |
149 |
10 Aug 06 |
enell |
187 |
for (int i = 0; i < merge.noGroup.size(); i++) |
149 |
10 Aug 06 |
enell |
188 |
{ |
149 |
10 Aug 06 |
enell |
189 |
BioAssay tmp = merge.noGroup.get(i); |
149 |
10 Aug 06 |
enell |
190 |
System.out.print(tmp.name + "<br>"); |
149 |
10 Aug 06 |
enell |
191 |
} |
149 |
10 Aug 06 |
enell |
192 |
} |
149 |
10 Aug 06 |
enell |
193 |
System.out.println("</table>"); |
149 |
10 Aug 06 |
enell |
194 |
|
149 |
10 Aug 06 |
enell |
195 |
} |
149 |
10 Aug 06 |
enell |
196 |
catch (BASEFileException e) |
149 |
10 Aug 06 |
enell |
197 |
{ |
149 |
10 Aug 06 |
enell |
198 |
e.printStackTrace(); |
149 |
10 Aug 06 |
enell |
199 |
} |
149 |
10 Aug 06 |
enell |
200 |
catch (IOException e) |
149 |
10 Aug 06 |
enell |
201 |
{ |
149 |
10 Aug 06 |
enell |
202 |
e.printStackTrace(); |
149 |
10 Aug 06 |
enell |
203 |
} |
149 |
10 Aug 06 |
enell |
204 |
} |
149 |
10 Aug 06 |
enell |
205 |
|
149 |
10 Aug 06 |
enell |
206 |
/** |
149 |
10 Aug 06 |
enell |
* Will read the parameters from the baseFile. |
149 |
10 Aug 06 |
enell |
208 |
* |
149 |
10 Aug 06 |
enell |
* @param section - the section from where the parameters will be read |
149 |
10 Aug 06 |
enell |
* @return true if the parameters was read without any problems |
149 |
10 Aug 06 |
enell |
211 |
*/ |
149 |
10 Aug 06 |
enell |
212 |
private boolean extractSettings(BASEFileSection section) |
149 |
10 Aug 06 |
enell |
213 |
{ |
149 |
10 Aug 06 |
enell |
214 |
param_assayname = section.findStringOpt("assayname"); |
149 |
10 Aug 06 |
enell |
215 |
param_group = section.findStringOpt("group"); |
149 |
10 Aug 06 |
enell |
216 |
param_ratio = section.findStringOpt("ratio"); |
149 |
10 Aug 06 |
enell |
217 |
param_newname = section.findStringOpt("newname"); |
149 |
10 Aug 06 |
enell |
218 |
param_mergeMethod = section.findIntOpt("mergeMethod"); |
149 |
10 Aug 06 |
enell |
219 |
param_annType = section.findStringOpt("annType"); |
149 |
10 Aug 06 |
enell |
220 |
param_annValue = section.findStringOpt("annValue"); |
149 |
10 Aug 06 |
enell |
221 |
|
149 |
10 Aug 06 |
enell |
222 |
if (param_group.matches("%\\d")) |
149 |
10 Aug 06 |
enell |
223 |
{ |
149 |
10 Aug 06 |
enell |
224 |
if (!param_assayname.matches(".*" + param_group + ".*")) |
149 |
10 Aug 06 |
enell |
225 |
{ |
149 |
10 Aug 06 |
enell |
226 |
System.err.println("MergeBioAssay.extractSettings(BASEFileSection section)"); |
149 |
10 Aug 06 |
enell |
227 |
System.err.println("Bad argument <sort>: Cant find " + param_group + " in assayname"); |
149 |
10 Aug 06 |
enell |
228 |
System.exit(0); |
149 |
10 Aug 06 |
enell |
229 |
} |
149 |
10 Aug 06 |
enell |
230 |
|
149 |
10 Aug 06 |
enell |
231 |
sortnbr = param_group.charAt(1) - 48; |
149 |
10 Aug 06 |
enell |
232 |
} |
149 |
10 Aug 06 |
enell |
233 |
else |
149 |
10 Aug 06 |
enell |
234 |
{ |
149 |
10 Aug 06 |
enell |
235 |
sortnbr = 10; |
149 |
10 Aug 06 |
enell |
236 |
annSort = true; |
149 |
10 Aug 06 |
enell |
237 |
} |
149 |
10 Aug 06 |
enell |
238 |
|
149 |
10 Aug 06 |
enell |
239 |
if (param_mergeMethod == RATIO_RATIO) |
149 |
10 Aug 06 |
enell |
240 |
{ |
149 |
10 Aug 06 |
enell |
241 |
if (!param_ratio.equals("")) |
149 |
10 Aug 06 |
enell |
242 |
{ |
149 |
10 Aug 06 |
enell |
243 |
String[] tmp = split(param_ratio, param_ratio.charAt(param_ratio.length() - 1)); |
149 |
10 Aug 06 |
enell |
244 |
|
149 |
10 Aug 06 |
enell |
245 |
if (tmp.length != 3) |
149 |
10 Aug 06 |
enell |
246 |
{ |
149 |
10 Aug 06 |
enell |
247 |
System.err.println("MergeBioAssay.extractSettings(BASEFileSection section)"); |
149 |
10 Aug 06 |
enell |
248 |
System.err.println("Invalid format of argument <ratio>"); |
149 |
10 Aug 06 |
enell |
249 |
System.err.println("Must be <ratio>|<numerator>|<denominator>|"); |
149 |
10 Aug 06 |
enell |
250 |
System.exit(0); |
149 |
10 Aug 06 |
enell |
251 |
} |
149 |
10 Aug 06 |
enell |
252 |
ratio = tmp[0]; |
149 |
10 Aug 06 |
enell |
253 |
ratioNumerator = tmp[1]; |
149 |
10 Aug 06 |
enell |
254 |
ratioDenominator = tmp[2]; |
149 |
10 Aug 06 |
enell |
255 |
} |
149 |
10 Aug 06 |
enell |
256 |
else if (!param_annType.equals("") && !param_annValue.equals("")) |
149 |
10 Aug 06 |
enell |
257 |
{ |
149 |
10 Aug 06 |
enell |
258 |
String[] tmp = split(param_annValue, param_annValue.charAt(param_annValue.length() - 1)); |
149 |
10 Aug 06 |
enell |
259 |
if (tmp.length != 2) |
149 |
10 Aug 06 |
enell |
260 |
{ |
149 |
10 Aug 06 |
enell |
261 |
System.err.println("MergeBioAssay.extractSettings(BASEFileSection section)"); |
149 |
10 Aug 06 |
enell |
262 |
System.err.println("Invalid format of argument annValue"); |
149 |
10 Aug 06 |
enell |
263 |
System.err.println("Can not use delimiter " + param_annValue.charAt(param_annValue.length() - 1)); |
149 |
10 Aug 06 |
enell |
264 |
System.exit(0); |
149 |
10 Aug 06 |
enell |
265 |
} |
149 |
10 Aug 06 |
enell |
266 |
ratio = param_annType; |
149 |
10 Aug 06 |
enell |
267 |
ratioNumerator = tmp[0]; |
149 |
10 Aug 06 |
enell |
268 |
ratioDenominator = tmp[1]; |
149 |
10 Aug 06 |
enell |
269 |
} |
149 |
10 Aug 06 |
enell |
270 |
else |
149 |
10 Aug 06 |
enell |
271 |
{ |
149 |
10 Aug 06 |
enell |
272 |
System.err.println("MergeBioAssay.extractSettings(BASEFileSection section)"); |
149 |
10 Aug 06 |
enell |
273 |
System.err.println("Merge method 'ratio of ratio' chosen but ratio or annotation type is left blank"); |
149 |
10 Aug 06 |
enell |
274 |
System.exit(0); |
149 |
10 Aug 06 |
enell |
275 |
} |
149 |
10 Aug 06 |
enell |
276 |
} |
149 |
10 Aug 06 |
enell |
277 |
|
149 |
10 Aug 06 |
enell |
278 |
if (param_group.equals(ratio)) |
149 |
10 Aug 06 |
enell |
279 |
{ |
149 |
10 Aug 06 |
enell |
280 |
System.err.println("You have the same sort as ratio. This will create crazy values."); |
149 |
10 Aug 06 |
enell |
281 |
} |
149 |
10 Aug 06 |
enell |
282 |
return true; |
149 |
10 Aug 06 |
enell |
283 |
} |
149 |
10 Aug 06 |
enell |
284 |
|
149 |
10 Aug 06 |
enell |
285 |
/** |
149 |
10 Aug 06 |
enell |
* Will read the assay from the baseFile |
149 |
10 Aug 06 |
enell |
287 |
* |
149 |
10 Aug 06 |
enell |
* @param section - the section to be read. Must have type "assays" |
149 |
10 Aug 06 |
enell |
* @param reader - the reader where the section data is located |
149 |
10 Aug 06 |
enell |
* @return true if the baseFile is read without any problems |
149 |
10 Aug 06 |
enell |
291 |
*/ |
149 |
10 Aug 06 |
enell |
292 |
private boolean extractAssays(BASEFileSection section, BASEFileReader reader) |
149 |
10 Aug 06 |
enell |
293 |
{ |
149 |
10 Aug 06 |
enell |
294 |
int idCol, nameCol, sortCol, nbr = -1, ratioCol = -1; |
149 |
10 Aug 06 |
enell |
295 |
|
149 |
10 Aug 06 |
enell |
296 |
List<String> columns = section.findFieldList("columns"); |
149 |
10 Aug 06 |
enell |
297 |
if (columns == null) |
149 |
10 Aug 06 |
enell |
298 |
{ |
149 |
10 Aug 06 |
enell |
299 |
System.err.println("MergeBioAssay.extractAssays(BASEFileSection section, BASEFileReader reader)"); |
149 |
10 Aug 06 |
enell |
300 |
System.err.println("Missing header columns in section assays"); |
149 |
10 Aug 06 |
enell |
301 |
System.exit(0); |
149 |
10 Aug 06 |
enell |
302 |
} |
149 |
10 Aug 06 |
enell |
303 |
|
149 |
10 Aug 06 |
enell |
304 |
idCol = columns.indexOf("id"); |
149 |
10 Aug 06 |
enell |
305 |
nameCol = columns.indexOf("name"); |
149 |
10 Aug 06 |
enell |
306 |
if (idCol == -1 || nameCol == -1) |
149 |
10 Aug 06 |
enell |
307 |
{ |
149 |
10 Aug 06 |
enell |
308 |
System.err.println("MergeBioAssay.extractAssays(BASEFileSection section, BASEFileReader reader)"); |
149 |
10 Aug 06 |
enell |
309 |
System.err.println("Missing id/name in section assays"); |
149 |
10 Aug 06 |
enell |
310 |
System.exit(0); |
149 |
10 Aug 06 |
enell |
311 |
} |
149 |
10 Aug 06 |
enell |
312 |
|
149 |
10 Aug 06 |
enell |
313 |
sortCol = columns.indexOf(param_group); |
149 |
10 Aug 06 |
enell |
314 |
if (annSort && sortCol == -1) |
149 |
10 Aug 06 |
enell |
315 |
{ |
149 |
10 Aug 06 |
enell |
316 |
System.err.println("MergeBioAssay.extractAssays(BASEFileSection section, BASEFileReader reader)"); |
149 |
10 Aug 06 |
enell |
317 |
System.err.println("Missing " + param_group + " in section assays\n"); |
149 |
10 Aug 06 |
enell |
318 |
System.exit(0); |
149 |
10 Aug 06 |
enell |
319 |
} |
149 |
10 Aug 06 |
enell |
320 |
|
149 |
10 Aug 06 |
enell |
321 |
if (param_mergeMethod == RATIO_RATIO) |
149 |
10 Aug 06 |
enell |
322 |
{ |
149 |
10 Aug 06 |
enell |
323 |
|
149 |
10 Aug 06 |
enell |
324 |
if (ratio.matches("%\\d")) |
149 |
10 Aug 06 |
enell |
325 |
{ |
149 |
10 Aug 06 |
enell |
326 |
nbr = ratio.charAt(1) - 48; |
149 |
10 Aug 06 |
enell |
327 |
} |
149 |
10 Aug 06 |
enell |
328 |
else |
149 |
10 Aug 06 |
enell |
329 |
{ |
149 |
10 Aug 06 |
enell |
330 |
ratioCol = columns.indexOf(ratio); |
149 |
10 Aug 06 |
enell |
331 |
if (ratioCol == -1) |
149 |
10 Aug 06 |
enell |
332 |
{ |
149 |
10 Aug 06 |
enell |
333 |
System.err.println("MergeBioAssay.extractAssays(BASEFileSection section, BASEFileReader reader)"); |
149 |
10 Aug 06 |
enell |
334 |
System.err.println("Ratio error: Cant find annotation type " + ratio); |
149 |
10 Aug 06 |
enell |
335 |
System.exit(0); |
149 |
10 Aug 06 |
enell |
336 |
} |
149 |
10 Aug 06 |
enell |
337 |
} |
149 |
10 Aug 06 |
enell |
338 |
} |
149 |
10 Aug 06 |
enell |
339 |
|
149 |
10 Aug 06 |
enell |
340 |
try |
149 |
10 Aug 06 |
enell |
341 |
{ |
149 |
10 Aug 06 |
enell |
342 |
String[] vals = reader.readDataRow(columns.size()); |
149 |
10 Aug 06 |
enell |
343 |
while (vals != null) |
149 |
10 Aug 06 |
enell |
344 |
{ |
149 |
10 Aug 06 |
enell |
345 |
Merge_assay tmp = new Merge_assay(vals[idCol], vals[nameCol]); |
149 |
10 Aug 06 |
enell |
346 |
if (annSort) |
149 |
10 Aug 06 |
enell |
347 |
tmp.v[sortnbr] = vals[sortCol]; |
149 |
10 Aug 06 |
enell |
348 |
if (param_mergeMethod == RATIO_RATIO) |
149 |
10 Aug 06 |
enell |
349 |
{ |
149 |
10 Aug 06 |
enell |
350 |
if (ratioCol != -1) |
149 |
10 Aug 06 |
enell |
351 |
tmp.v[11] = vals[ratioCol]; |
149 |
10 Aug 06 |
enell |
352 |
else if (nbr != -1) |
149 |
10 Aug 06 |
enell |
353 |
{ |
149 |
10 Aug 06 |
enell |
354 |
tmp.parse_name(param_assayname); |
149 |
10 Aug 06 |
enell |
355 |
tmp.v[11] = tmp.v[nbr]; |
149 |
10 Aug 06 |
enell |
356 |
} |
149 |
10 Aug 06 |
enell |
357 |
} |
149 |
10 Aug 06 |
enell |
358 |
|
149 |
10 Aug 06 |
enell |
// sort the data into the right group. |
149 |
10 Aug 06 |
enell |
// if the assay lacks sort value (ie. sortvalue == "") |
149 |
10 Aug 06 |
enell |
// the data is placed in noGroup |
149 |
10 Aug 06 |
enell |
// && (annType.isEmpty() || annType.contains(tmp.v[sortnbr])) |
149 |
10 Aug 06 |
enell |
363 |
if (annSort || tmp.parse_name(param_assayname)) |
149 |
10 Aug 06 |
enell |
364 |
{ |
149 |
10 Aug 06 |
enell |
365 |
if (tmp.v[sortnbr] != null) |
149 |
10 Aug 06 |
enell |
366 |
{ |
149 |
10 Aug 06 |
enell |
367 |
List<Merge_assay> vec = assayGroups.get(tmp.v[sortnbr]); |
149 |
10 Aug 06 |
enell |
368 |
if (vec == null) |
149 |
10 Aug 06 |
enell |
369 |
{ |
149 |
10 Aug 06 |
enell |
370 |
vec = new ArrayList<Merge_assay>(); |
149 |
10 Aug 06 |
enell |
371 |
vec.add(tmp); |
149 |
10 Aug 06 |
enell |
372 |
assayGroups.put(tmp.v[sortnbr], vec); |
149 |
10 Aug 06 |
enell |
373 |
} |
149 |
10 Aug 06 |
enell |
374 |
else |
149 |
10 Aug 06 |
enell |
375 |
vec.add(tmp); |
149 |
10 Aug 06 |
enell |
376 |
} |
149 |
10 Aug 06 |
enell |
377 |
else |
149 |
10 Aug 06 |
enell |
378 |
{ |
149 |
10 Aug 06 |
enell |
379 |
noGroup.add(tmp); |
149 |
10 Aug 06 |
enell |
380 |
} |
149 |
10 Aug 06 |
enell |
381 |
} |
149 |
10 Aug 06 |
enell |
382 |
else |
149 |
10 Aug 06 |
enell |
383 |
{ |
149 |
10 Aug 06 |
enell |
384 |
noGroup.add(tmp); |
149 |
10 Aug 06 |
enell |
385 |
} |
149 |
10 Aug 06 |
enell |
386 |
vals = reader.readDataRow(columns.size()); |
149 |
10 Aug 06 |
enell |
387 |
} |
149 |
10 Aug 06 |
enell |
388 |
} |
149 |
10 Aug 06 |
enell |
389 |
catch (BadSectionException e) |
149 |
10 Aug 06 |
enell |
390 |
{ |
149 |
10 Aug 06 |
enell |
391 |
e.printStackTrace(); |
149 |
10 Aug 06 |
enell |
392 |
return false; |
149 |
10 Aug 06 |
enell |
393 |
} |
149 |
10 Aug 06 |
enell |
394 |
catch (BadPatternException e) |
149 |
10 Aug 06 |
enell |
395 |
{ |
149 |
10 Aug 06 |
enell |
396 |
e.printStackTrace(); |
149 |
10 Aug 06 |
enell |
397 |
System.exit(0); |
149 |
10 Aug 06 |
enell |
398 |
} |
663 |
16 Apr 08 |
jari |
399 |
catch (BASEFileException e) |
149 |
10 Aug 06 |
enell |
400 |
{ |
149 |
10 Aug 06 |
enell |
401 |
e.printStackTrace(); |
149 |
10 Aug 06 |
enell |
402 |
System.exit(0); |
149 |
10 Aug 06 |
enell |
403 |
} |
149 |
10 Aug 06 |
enell |
404 |
|
149 |
10 Aug 06 |
enell |
405 |
if (noGroup.size() > 0) |
149 |
10 Aug 06 |
enell |
406 |
{ |
149 |
10 Aug 06 |
enell |
407 |
System.err.println(noGroup.size() + " didn't match the assayname " + param_assayname); |
149 |
10 Aug 06 |
enell |
408 |
} |
149 |
10 Aug 06 |
enell |
409 |
|
149 |
10 Aug 06 |
enell |
410 |
if (param_mergeMethod == RATIO_RATIO) |
149 |
10 Aug 06 |
enell |
411 |
{ |
149 |
10 Aug 06 |
enell |
412 |
Iterator it = assayGroups.keySet().iterator(); |
149 |
10 Aug 06 |
enell |
413 |
Object key; |
149 |
10 Aug 06 |
enell |
414 |
while (it.hasNext()) |
149 |
10 Aug 06 |
enell |
// for (String key : assayGroups.keySet()) |
149 |
10 Aug 06 |
enell |
416 |
{ |
149 |
10 Aug 06 |
enell |
417 |
key = it.next(); |
149 |
10 Aug 06 |
enell |
418 |
List<Merge_assay> group = assayGroups.get(key); |
149 |
10 Aug 06 |
enell |
419 |
if (group.size() != 2) |
149 |
10 Aug 06 |
enell |
420 |
{ |
149 |
10 Aug 06 |
enell |
421 |
assayGroups.remove(key); |
149 |
10 Aug 06 |
enell |
422 |
noGroup.addAll(group); |
149 |
10 Aug 06 |
enell |
423 |
it = assayGroups.keySet().iterator(); |
149 |
10 Aug 06 |
enell |
424 |
} |
149 |
10 Aug 06 |
enell |
425 |
else |
149 |
10 Aug 06 |
enell |
426 |
{ |
149 |
10 Aug 06 |
enell |
427 |
Merge_assay assay1 = group.get(0); |
149 |
10 Aug 06 |
enell |
428 |
Merge_assay assay2 = group.get(1); |
149 |
10 Aug 06 |
enell |
429 |
|
149 |
10 Aug 06 |
enell |
430 |
if (!(assay1.v[11].equals(ratioNumerator) || assay1.v[11].equals(ratioDenominator))) |
149 |
10 Aug 06 |
enell |
431 |
{ |
149 |
10 Aug 06 |
enell |
432 |
assayGroups.remove(key); |
149 |
10 Aug 06 |
enell |
433 |
noGroup.add(assay1); |
149 |
10 Aug 06 |
enell |
434 |
it = assayGroups.keySet().iterator(); |
149 |
10 Aug 06 |
enell |
435 |
} |
149 |
10 Aug 06 |
enell |
436 |
if (!(assay2.v[11].equals(ratioNumerator) || assay2.v[11].equals(ratioDenominator))) |
149 |
10 Aug 06 |
enell |
437 |
{ |
149 |
10 Aug 06 |
enell |
438 |
assayGroups.remove(key); |
149 |
10 Aug 06 |
enell |
439 |
noGroup.add(assay2); |
149 |
10 Aug 06 |
enell |
440 |
it = assayGroups.keySet().iterator(); |
149 |
10 Aug 06 |
enell |
441 |
} |
149 |
10 Aug 06 |
enell |
442 |
} |
149 |
10 Aug 06 |
enell |
443 |
} |
149 |
10 Aug 06 |
enell |
444 |
} |
149 |
10 Aug 06 |
enell |
445 |
|
149 |
10 Aug 06 |
enell |
446 |
nbrOfGroups = assayGroups.size(); |
149 |
10 Aug 06 |
enell |
447 |
if (nbrOfGroups == 0) |
149 |
10 Aug 06 |
enell |
448 |
{ |
149 |
10 Aug 06 |
enell |
449 |
System.err.print("No groups found"); |
149 |
10 Aug 06 |
enell |
450 |
System.exit(0); |
149 |
10 Aug 06 |
enell |
451 |
} |
149 |
10 Aug 06 |
enell |
452 |
return true; |
149 |
10 Aug 06 |
enell |
453 |
} |
149 |
10 Aug 06 |
enell |
454 |
|
149 |
10 Aug 06 |
enell |
455 |
/** |
149 |
10 Aug 06 |
enell |
* Will read the spots from the baseFile |
149 |
10 Aug 06 |
enell |
457 |
* |
149 |
10 Aug 06 |
enell |
* @param section - the section to be read. Must have type "spots" |
149 |
10 Aug 06 |
enell |
* @param reader - the reader where the section data is located |
149 |
10 Aug 06 |
enell |
* @return true if the baseFile is read without any problems |
149 |
10 Aug 06 |
enell |
461 |
*/ |
149 |
10 Aug 06 |
enell |
462 |
public boolean mergeSpots(BASEFileSection section, BASEFileReader reader) |
149 |
10 Aug 06 |
enell |
463 |
{ |
149 |
10 Aug 06 |
enell |
464 |
|
149 |
10 Aug 06 |
enell |
465 |
System.out.print("BASEfile\n"); |
149 |
10 Aug 06 |
enell |
466 |
System.out.print("section\tassays\n" + "count\t" + (nbrOfGroups + noGroup.size()) + "\n"); |
149 |
10 Aug 06 |
enell |
467 |
System.out.print("columns\tid\tname\tparents\n"); |
149 |
10 Aug 06 |
enell |
468 |
System.out.print("%\n"); |
149 |
10 Aug 06 |
enell |
469 |
int assay_nbr = 1; |
149 |
10 Aug 06 |
enell |
470 |
for (String key : assayGroups.keySet()) |
149 |
10 Aug 06 |
enell |
471 |
{ |
149 |
10 Aug 06 |
enell |
472 |
System.out.print(assay_nbr++ + "\t" + param_newname); |
149 |
10 Aug 06 |
enell |
473 |
List<Merge_assay> group = assayGroups.get(key); |
149 |
10 Aug 06 |
enell |
474 |
for (int i = 0; i < group.size(); i++) |
149 |
10 Aug 06 |
enell |
475 |
{ |
149 |
10 Aug 06 |
enell |
476 |
Merge_assay tmp = group.get(i); |
149 |
10 Aug 06 |
enell |
477 |
if (i != 0) |
149 |
10 Aug 06 |
enell |
478 |
{ |
149 |
10 Aug 06 |
enell |
479 |
System.out.print("/"); |
149 |
10 Aug 06 |
enell |
480 |
} |
149 |
10 Aug 06 |
enell |
481 |
else |
149 |
10 Aug 06 |
enell |
482 |
{ |
149 |
10 Aug 06 |
enell |
483 |
System.out.print(tmp.v[sortnbr] + "\t"); |
149 |
10 Aug 06 |
enell |
484 |
} |
149 |
10 Aug 06 |
enell |
485 |
System.out.print(tmp.id); |
149 |
10 Aug 06 |
enell |
486 |
} |
149 |
10 Aug 06 |
enell |
487 |
System.out.print("\n"); |
149 |
10 Aug 06 |
enell |
488 |
} |
149 |
10 Aug 06 |
enell |
489 |
|
149 |
10 Aug 06 |
enell |
490 |
for (int i = 0; i < noGroup.size(); i++) |
149 |
10 Aug 06 |
enell |
491 |
{ |
149 |
10 Aug 06 |
enell |
492 |
BioAssay tmp = noGroup.get(i); |
149 |
10 Aug 06 |
enell |
493 |
System.out.print(tmp.id + "\t" + tmp.name + "\t" + tmp.id + "\n"); |
149 |
10 Aug 06 |
enell |
494 |
} |
149 |
10 Aug 06 |
enell |
495 |
System.out.println(); |
149 |
10 Aug 06 |
enell |
496 |
|
149 |
10 Aug 06 |
enell |
497 |
Merger m = null; |
149 |
10 Aug 06 |
enell |
498 |
switch (param_mergeMethod) |
149 |
10 Aug 06 |
enell |
499 |
{ |
149 |
10 Aug 06 |
enell |
500 |
case GEOMETRIC_RATIO: |
149 |
10 Aug 06 |
enell |
501 |
m = new GeometricRatioMerger(); |
149 |
10 Aug 06 |
enell |
502 |
break; |
149 |
10 Aug 06 |
enell |
503 |
case ARITHMETIC_RATIO: |
149 |
10 Aug 06 |
enell |
504 |
m = new ArithmeticRatioMerger(); |
149 |
10 Aug 06 |
enell |
505 |
break; |
149 |
10 Aug 06 |
enell |
506 |
case ARITHMETIC_INT: |
149 |
10 Aug 06 |
enell |
507 |
m = new ArithmeticIntensityMerger(); |
149 |
10 Aug 06 |
enell |
508 |
break; |
149 |
10 Aug 06 |
enell |
509 |
case RATIO_RATIO: |
149 |
10 Aug 06 |
enell |
510 |
m = new RatioRatioMerger(ratioNumerator, ratioDenominator); |
149 |
10 Aug 06 |
enell |
511 |
break; |
149 |
10 Aug 06 |
enell |
512 |
} |
149 |
10 Aug 06 |
enell |
513 |
m.merge(section, reader, assayGroups); |
149 |
10 Aug 06 |
enell |
514 |
return true; |
149 |
10 Aug 06 |
enell |
515 |
} |
149 |
10 Aug 06 |
enell |
516 |
|
149 |
10 Aug 06 |
enell |
517 |
/** |
149 |
10 Aug 06 |
enell |
* A private utility method to split a string around a char |
149 |
10 Aug 06 |
enell |
519 |
* |
149 |
10 Aug 06 |
enell |
* @param str - the string to split |
149 |
10 Aug 06 |
enell |
* @param token - the token to use to split |
149 |
10 Aug 06 |
enell |
* @return the strings as an <code>String[]</code> |
149 |
10 Aug 06 |
enell |
523 |
*/ |
149 |
10 Aug 06 |
enell |
524 |
private String[] split(String str, char token) |
149 |
10 Aug 06 |
enell |
525 |
{ |
149 |
10 Aug 06 |
enell |
526 |
ArrayList<String> ret = new ArrayList<String>(); |
149 |
10 Aug 06 |
enell |
527 |
int start = 0, end = 0; |
149 |
10 Aug 06 |
enell |
528 |
|
149 |
10 Aug 06 |
enell |
529 |
while (str.length() > start) |
149 |
10 Aug 06 |
enell |
530 |
{ |
149 |
10 Aug 06 |
enell |
531 |
end = str.indexOf(token, start); |
149 |
10 Aug 06 |
enell |
532 |
ret.add(str.substring(start, end)); |
149 |
10 Aug 06 |
enell |
533 |
start = end + 1; |
149 |
10 Aug 06 |
enell |
534 |
} |
149 |
10 Aug 06 |
enell |
535 |
return ret.toArray(new String[ret.size()]); |
149 |
10 Aug 06 |
enell |
536 |
} |
783 |
18 Sep 08 |
jari |
537 |
} |