875 |
05 Dec 08 |
jari |
1 |
/* |
875 |
05 Dec 08 |
jari |
* $Id$ |
875 |
05 Dec 08 |
jari |
3 |
* |
875 |
05 Dec 08 |
jari |
* Copyright (C) 2005 Johan Enell |
875 |
05 Dec 08 |
jari |
* Copyright (C) 2008 Jari Häkkinen |
875 |
05 Dec 08 |
jari |
6 |
|
875 |
05 Dec 08 |
jari |
* This file is part of the se.lu.onk.Center plug-in for |
875 |
05 Dec 08 |
jari |
* BASE. Available at http://baseplugins.thep.lu.se/ and BASE web site |
875 |
05 Dec 08 |
jari |
* is http://base.thep.lu.se |
875 |
05 Dec 08 |
jari |
10 |
|
875 |
05 Dec 08 |
jari |
* This is free software; you can redistribute it and/or modify it |
875 |
05 Dec 08 |
jari |
* under the terms of the GNU General Public License as published by |
875 |
05 Dec 08 |
jari |
* the Free Software Foundation; either version 3 of the License, or |
875 |
05 Dec 08 |
jari |
* (at your option) any later version. |
875 |
05 Dec 08 |
jari |
15 |
|
875 |
05 Dec 08 |
jari |
* The software is distributed in the hope that it will be useful, but |
875 |
05 Dec 08 |
jari |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
875 |
05 Dec 08 |
jari |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
875 |
05 Dec 08 |
jari |
* General Public License for more details. |
875 |
05 Dec 08 |
jari |
20 |
|
875 |
05 Dec 08 |
jari |
* You should have received a copy of the GNU General Public License |
875 |
05 Dec 08 |
jari |
* along with this software. If not, see <http://www.gnu.org/licenses/>. |
875 |
05 Dec 08 |
jari |
23 |
*/ |
875 |
05 Dec 08 |
jari |
24 |
|
149 |
10 Aug 06 |
enell |
25 |
package center; |
149 |
10 Aug 06 |
enell |
26 |
|
149 |
10 Aug 06 |
enell |
27 |
import basefile.BASEFileReader; |
149 |
10 Aug 06 |
enell |
28 |
import basefile.BASEFileSection; |
149 |
10 Aug 06 |
enell |
29 |
|
149 |
10 Aug 06 |
enell |
30 |
import java.io.File; |
149 |
10 Aug 06 |
enell |
31 |
import java.io.FileOutputStream; |
149 |
10 Aug 06 |
enell |
32 |
import java.io.IOException; |
149 |
10 Aug 06 |
enell |
33 |
import java.io.PrintStream; |
149 |
10 Aug 06 |
enell |
34 |
import java.util.ArrayList; |
149 |
10 Aug 06 |
enell |
35 |
import java.util.Arrays; |
2012 |
01 Aug 13 |
olle |
36 |
import java.util.Collections; |
149 |
10 Aug 06 |
enell |
37 |
import java.util.HashMap; |
149 |
10 Aug 06 |
enell |
38 |
import java.util.List; |
149 |
10 Aug 06 |
enell |
39 |
import java.util.Map; |
149 |
10 Aug 06 |
enell |
40 |
|
149 |
10 Aug 06 |
enell |
41 |
class Center |
149 |
10 Aug 06 |
enell |
42 |
{ |
149 |
10 Aug 06 |
enell |
43 |
private int posCol = -1; |
149 |
10 Aug 06 |
enell |
44 |
|
149 |
10 Aug 06 |
enell |
45 |
private int repCol = -1; |
149 |
10 Aug 06 |
enell |
46 |
|
149 |
10 Aug 06 |
enell |
47 |
private int dataCol = -1; |
149 |
10 Aug 06 |
enell |
48 |
|
149 |
10 Aug 06 |
enell |
49 |
private int mCol = -1; |
149 |
10 Aug 06 |
enell |
50 |
|
149 |
10 Aug 06 |
enell |
51 |
private int aCol = -1; |
149 |
10 Aug 06 |
enell |
52 |
|
149 |
10 Aug 06 |
enell |
53 |
private int nbrOfCol = -1; |
149 |
10 Aug 06 |
enell |
54 |
|
149 |
10 Aug 06 |
enell |
55 |
private int nbrOfAssays = -1; |
149 |
10 Aug 06 |
enell |
56 |
|
149 |
10 Aug 06 |
enell |
57 |
private int nbrOfFields = -1; |
149 |
10 Aug 06 |
enell |
58 |
|
149 |
10 Aug 06 |
enell |
59 |
private CenterOn param_mm; |
149 |
10 Aug 06 |
enell |
60 |
|
149 |
10 Aug 06 |
enell |
61 |
private GeneAssay param_centerGeneAssay; |
149 |
10 Aug 06 |
enell |
62 |
|
2026 |
25 Sep 13 |
olle |
63 |
private CenteringGroups param_centeringGroups; |
2026 |
25 Sep 13 |
olle |
64 |
|
2026 |
25 Sep 13 |
olle |
65 |
private String param_centerGroupsAssayNames = ""; |
2026 |
25 Sep 13 |
olle |
66 |
|
149 |
10 Aug 06 |
enell |
67 |
private int param_centerCycles = -1; |
149 |
10 Aug 06 |
enell |
68 |
|
2026 |
25 Sep 13 |
olle |
69 |
private List<String> singleCenterGroupAssayNameList = null; |
2026 |
25 Sep 13 |
olle |
70 |
|
2026 |
25 Sep 13 |
olle |
71 |
private List<Integer> singleCenterGroupAssayIndexList = null; |
2026 |
25 Sep 13 |
olle |
72 |
|
2026 |
25 Sep 13 |
olle |
73 |
private HashMap<Integer,List<String>> centerGroupsAssayNameHashMap = null; |
2026 |
25 Sep 13 |
olle |
74 |
|
2026 |
25 Sep 13 |
olle |
75 |
private HashMap<Integer,List<Integer>> centerGroupsAssayIndexHashMap = null; |
2026 |
25 Sep 13 |
olle |
76 |
|
2026 |
25 Sep 13 |
olle |
77 |
private boolean param_createDebugFiles = false; |
2026 |
25 Sep 13 |
olle |
78 |
|
149 |
10 Aug 06 |
enell |
79 |
private ArrayList<AssayRow> data = new ArrayList<AssayRow>(); |
2026 |
25 Sep 13 |
olle |
80 |
|
2026 |
25 Sep 13 |
olle |
81 |
private boolean debug = false; |
149 |
10 Aug 06 |
enell |
82 |
|
149 |
10 Aug 06 |
enell |
83 |
public static void main(String[] args) |
149 |
10 Aug 06 |
enell |
84 |
{ |
149 |
10 Aug 06 |
enell |
85 |
try |
149 |
10 Aug 06 |
enell |
86 |
{ |
149 |
10 Aug 06 |
enell |
87 |
BASEFileReader bfr = null; |
149 |
10 Aug 06 |
enell |
88 |
if (args.length == 1) |
149 |
10 Aug 06 |
enell |
89 |
{ |
149 |
10 Aug 06 |
enell |
90 |
bfr = new BASEFileReader(new File(args[0])); |
149 |
10 Aug 06 |
enell |
91 |
} |
149 |
10 Aug 06 |
enell |
92 |
else if (args.length == 0) |
149 |
10 Aug 06 |
enell |
93 |
{ |
149 |
10 Aug 06 |
enell |
94 |
bfr = new BASEFileReader(new File("stdin.txt")); |
149 |
10 Aug 06 |
enell |
95 |
} |
149 |
10 Aug 06 |
enell |
96 |
else |
149 |
10 Aug 06 |
enell |
97 |
{ |
149 |
10 Aug 06 |
enell |
98 |
System.err.println("center: invalid input given"); |
149 |
10 Aug 06 |
enell |
99 |
System.exit(-1); |
149 |
10 Aug 06 |
enell |
100 |
} |
149 |
10 Aug 06 |
enell |
101 |
System.setOut(new PrintStream(new FileOutputStream("stdout.txt"))); |
149 |
10 Aug 06 |
enell |
102 |
System.out.println("BASEfile"); |
149 |
10 Aug 06 |
enell |
103 |
|
149 |
10 Aug 06 |
enell |
104 |
Center center = new Center(); |
149 |
10 Aug 06 |
enell |
105 |
BASEFileSection section = bfr.readSection(true); |
149 |
10 Aug 06 |
enell |
106 |
while (section != null) |
149 |
10 Aug 06 |
enell |
107 |
{ |
149 |
10 Aug 06 |
enell |
108 |
if (section.isType("center settings")) |
149 |
10 Aug 06 |
enell |
109 |
{ |
149 |
10 Aug 06 |
enell |
110 |
center.extractSettings(section); |
149 |
10 Aug 06 |
enell |
111 |
} |
149 |
10 Aug 06 |
enell |
112 |
else if (section.isType("assays")) |
149 |
10 Aug 06 |
enell |
113 |
{ |
149 |
10 Aug 06 |
enell |
114 |
center.extractAssays(section, bfr); |
149 |
10 Aug 06 |
enell |
115 |
} |
149 |
10 Aug 06 |
enell |
116 |
else if (section.isType("spots")) |
149 |
10 Aug 06 |
enell |
117 |
{ |
149 |
10 Aug 06 |
enell |
118 |
center.extractSpots(section, bfr); |
149 |
10 Aug 06 |
enell |
119 |
} |
149 |
10 Aug 06 |
enell |
120 |
section = bfr.readSection(); |
149 |
10 Aug 06 |
enell |
121 |
} |
149 |
10 Aug 06 |
enell |
122 |
center.center(); |
149 |
10 Aug 06 |
enell |
123 |
|
149 |
10 Aug 06 |
enell |
124 |
} |
149 |
10 Aug 06 |
enell |
125 |
catch (OutOfMemoryError oome) |
149 |
10 Aug 06 |
enell |
126 |
{ |
149 |
10 Aug 06 |
enell |
127 |
System.err.println("No more memory in the java virtual machine. Try to start the application with 'java -Xmx256m Center' or 'java -Xmx512m Center'. If you need even more memory, duplicate the digit"); |
149 |
10 Aug 06 |
enell |
128 |
System.exit(-1); |
149 |
10 Aug 06 |
enell |
129 |
} |
149 |
10 Aug 06 |
enell |
130 |
catch (Exception e) |
149 |
10 Aug 06 |
enell |
131 |
{ |
149 |
10 Aug 06 |
enell |
132 |
e.printStackTrace(); |
149 |
10 Aug 06 |
enell |
133 |
System.exit(-1); |
149 |
10 Aug 06 |
enell |
134 |
} |
149 |
10 Aug 06 |
enell |
135 |
} |
2026 |
25 Sep 13 |
olle |
136 |
|
2026 |
25 Sep 13 |
olle |
137 |
public Center() |
2026 |
25 Sep 13 |
olle |
138 |
{ |
2026 |
25 Sep 13 |
olle |
139 |
} |
2026 |
25 Sep 13 |
olle |
140 |
|
149 |
10 Aug 06 |
enell |
141 |
public void extractSettings(BASEFileSection section) |
149 |
10 Aug 06 |
enell |
142 |
{ |
149 |
10 Aug 06 |
enell |
143 |
try |
149 |
10 Aug 06 |
enell |
144 |
{ |
149 |
10 Aug 06 |
enell |
145 |
param_mm = CenterOn.fromValue(section.findIntOpt("mm")); |
149 |
10 Aug 06 |
enell |
146 |
param_centerGeneAssay = GeneAssay.fromValue(section.findIntOpt("centerGeneAssay")); |
2026 |
25 Sep 13 |
olle |
147 |
param_centeringGroups = CenteringGroups.fromValue(section.findIntOpt("centerAssayGroups")); |
2026 |
25 Sep 13 |
olle |
148 |
param_centerGroupsAssayNames = section.findStringOpt("centerGroupsAssayNames"); |
149 |
10 Aug 06 |
enell |
149 |
param_centerCycles = section.findIntOpt("centerCycles"); |
2026 |
25 Sep 13 |
olle |
150 |
param_createDebugFiles = section.findBooleanOpt("createDebugFiles"); |
2026 |
25 Sep 13 |
olle |
151 |
if (param_createDebugFiles) |
2026 |
25 Sep 13 |
olle |
152 |
{ |
2026 |
25 Sep 13 |
olle |
153 |
debug = true; |
2026 |
25 Sep 13 |
olle |
154 |
File dataDir = new File("data"); |
2026 |
25 Sep 13 |
olle |
155 |
dataDir.mkdir(); |
2026 |
25 Sep 13 |
olle |
156 |
} |
2026 |
25 Sep 13 |
olle |
157 |
PrintStream debugOut = null; |
2026 |
25 Sep 13 |
olle |
158 |
if (debug) |
2026 |
25 Sep 13 |
olle |
159 |
{ |
2026 |
25 Sep 13 |
olle |
160 |
debugOut = new PrintStream(new File("data", "debugExtractSettings.txt")); |
2026 |
25 Sep 13 |
olle |
161 |
debugOut.println("Center::extractSettings(): param_centerGeneAssay = " + param_centerGeneAssay); |
2026 |
25 Sep 13 |
olle |
162 |
debugOut.println("Center::extractSettings(): param_centeringGroups = " + param_centeringGroups); |
2026 |
25 Sep 13 |
olle |
163 |
debugOut.println("Center::extractSettings(): param_centerGroupsAssayNames = \"" + param_centerGroupsAssayNames + "\""); |
2026 |
25 Sep 13 |
olle |
164 |
debugOut.println("Center::extractSettings(): param_centerCycles = " + param_centerCycles); |
2026 |
25 Sep 13 |
olle |
165 |
debugOut.println("Center::extractSettings(): param_mm = " + param_mm); |
2026 |
25 Sep 13 |
olle |
166 |
debugOut.println("Center::extractSettings(): param_createDebugFiles = " + param_createDebugFiles); |
2026 |
25 Sep 13 |
olle |
167 |
} |
2026 |
25 Sep 13 |
olle |
168 |
if (param_centeringGroups == CenteringGroups.ASSAYGROUPSINGLE) |
2026 |
25 Sep 13 |
olle |
169 |
{ |
2026 |
25 Sep 13 |
olle |
170 |
singleCenterGroupAssayNameList = new ArrayList<String>(); |
2026 |
25 Sep 13 |
olle |
171 |
for (String s : param_centerGroupsAssayNames.trim().split(",")) |
2026 |
25 Sep 13 |
olle |
172 |
{ |
2026 |
25 Sep 13 |
olle |
173 |
s.trim(); |
2026 |
25 Sep 13 |
olle |
174 |
singleCenterGroupAssayNameList.add(s); |
2026 |
25 Sep 13 |
olle |
175 |
if (debug) |
2026 |
25 Sep 13 |
olle |
176 |
{ |
2026 |
25 Sep 13 |
olle |
177 |
debugOut.println("Center::extractSettings(): s = \"" + s + "\""); |
2026 |
25 Sep 13 |
olle |
178 |
} |
2026 |
25 Sep 13 |
olle |
179 |
} |
2026 |
25 Sep 13 |
olle |
180 |
} |
2026 |
25 Sep 13 |
olle |
181 |
if (param_centeringGroups == CenteringGroups.ASSAYGROUPS) |
2026 |
25 Sep 13 |
olle |
182 |
{ |
2026 |
25 Sep 13 |
olle |
183 |
centerGroupsAssayNameHashMap = new HashMap<Integer,List<String>>(); |
2026 |
25 Sep 13 |
olle |
184 |
int groupIndex = 0; |
2026 |
25 Sep 13 |
olle |
185 |
for (String assayNames : param_centerGroupsAssayNames.trim().split("\\|")) |
2026 |
25 Sep 13 |
olle |
186 |
{ |
2026 |
25 Sep 13 |
olle |
187 |
List<String> groupAssayNameList = new ArrayList<String>(); |
2026 |
25 Sep 13 |
olle |
188 |
if (debug) |
2026 |
25 Sep 13 |
olle |
189 |
{ |
2026 |
25 Sep 13 |
olle |
190 |
debugOut.println("Center::extractSettings(): assayNames = \"" + assayNames + "\""); |
2026 |
25 Sep 13 |
olle |
191 |
} |
2026 |
25 Sep 13 |
olle |
192 |
for (String s : assayNames.trim().split(",")) |
2026 |
25 Sep 13 |
olle |
193 |
{ |
2026 |
25 Sep 13 |
olle |
194 |
s.trim(); |
2026 |
25 Sep 13 |
olle |
195 |
groupAssayNameList.add(s); |
2026 |
25 Sep 13 |
olle |
196 |
if (debug) |
2026 |
25 Sep 13 |
olle |
197 |
{ |
2026 |
25 Sep 13 |
olle |
198 |
debugOut.println("Center::extractSettings(): s = \"" + s + "\""); |
2026 |
25 Sep 13 |
olle |
199 |
} |
2026 |
25 Sep 13 |
olle |
200 |
} |
2026 |
25 Sep 13 |
olle |
201 |
centerGroupsAssayNameHashMap.put(groupIndex, groupAssayNameList); |
2026 |
25 Sep 13 |
olle |
202 |
groupIndex++; |
2026 |
25 Sep 13 |
olle |
203 |
} |
2026 |
25 Sep 13 |
olle |
204 |
} |
2026 |
25 Sep 13 |
olle |
205 |
if (debug) |
2026 |
25 Sep 13 |
olle |
206 |
{ |
2026 |
25 Sep 13 |
olle |
207 |
debugOut.println("Center::extractSettings(): singleCenterGroupAssayNameList = " + singleCenterGroupAssayNameList); |
2026 |
25 Sep 13 |
olle |
208 |
debugOut.println("Center::extractSettings(): centerGroupsAssayNameHashMap = " + centerGroupsAssayNameHashMap); |
2026 |
25 Sep 13 |
olle |
209 |
debugOut.close(); |
2026 |
25 Sep 13 |
olle |
210 |
} |
149 |
10 Aug 06 |
enell |
211 |
} |
149 |
10 Aug 06 |
enell |
212 |
catch (NumberFormatException e) |
149 |
10 Aug 06 |
enell |
213 |
{ |
149 |
10 Aug 06 |
enell |
214 |
e.printStackTrace(); |
149 |
10 Aug 06 |
enell |
215 |
} |
2026 |
25 Sep 13 |
olle |
216 |
catch (Exception e1) |
2026 |
25 Sep 13 |
olle |
217 |
{ |
2026 |
25 Sep 13 |
olle |
218 |
e1.printStackTrace(); |
2026 |
25 Sep 13 |
olle |
219 |
} |
149 |
10 Aug 06 |
enell |
220 |
if (param_centerCycles < 0) |
149 |
10 Aug 06 |
enell |
221 |
{ |
149 |
10 Aug 06 |
enell |
222 |
System.err.println("Negative number of center cycles."); |
149 |
10 Aug 06 |
enell |
223 |
} |
149 |
10 Aug 06 |
enell |
224 |
if (param_centerCycles > 20) |
149 |
10 Aug 06 |
enell |
225 |
{ |
149 |
10 Aug 06 |
enell |
226 |
param_centerCycles = 20; |
2012 |
01 Aug 13 |
olle |
227 |
System.err.println("Too many center cycles. It has been adjusted to 20."); |
149 |
10 Aug 06 |
enell |
228 |
} |
149 |
10 Aug 06 |
enell |
229 |
|
149 |
10 Aug 06 |
enell |
230 |
if ((param_centerGeneAssay == GeneAssay.ASSAYS || param_centerGeneAssay == GeneAssay.GENES) && param_centerCycles > 1) |
149 |
10 Aug 06 |
enell |
231 |
{ |
149 |
10 Aug 06 |
enell |
232 |
param_centerCycles = 1; |
149 |
10 Aug 06 |
enell |
233 |
System.err.println("If you choose to center on genes or assays there is no reason to do more then one cycle. The parameter has been adjusted to 1."); |
149 |
10 Aug 06 |
enell |
234 |
} |
149 |
10 Aug 06 |
enell |
235 |
} |
149 |
10 Aug 06 |
enell |
236 |
|
149 |
10 Aug 06 |
enell |
237 |
public void extractAssays(BASEFileSection section, BASEFileReader reader) |
149 |
10 Aug 06 |
enell |
238 |
{ |
149 |
10 Aug 06 |
enell |
239 |
try |
149 |
10 Aug 06 |
enell |
240 |
{ |
149 |
10 Aug 06 |
enell |
241 |
String columns = section.findStringOpt("columns"); |
149 |
10 Aug 06 |
enell |
242 |
String count = section.findStringOpt("count"); |
149 |
10 Aug 06 |
enell |
243 |
String annotationColumns = section.findStringOpt("annotationColumns"); |
2026 |
25 Sep 13 |
olle |
244 |
int nameCol = section.findFieldList("columns").indexOf("name"); |
2026 |
25 Sep 13 |
olle |
245 |
int idCol = section.findFieldList("columns").indexOf("id"); |
2026 |
25 Sep 13 |
olle |
246 |
// |
2026 |
25 Sep 13 |
olle |
247 |
PrintStream debugOut = null; |
2026 |
25 Sep 13 |
olle |
248 |
if (debug) |
2026 |
25 Sep 13 |
olle |
249 |
{ |
2026 |
25 Sep 13 |
olle |
250 |
debugOut = new PrintStream(new File("data", "debugExtractAssays.txt")); |
2026 |
25 Sep 13 |
olle |
251 |
debugOut.println("Center::extractAssays(): param_centerGeneAssay = " + param_centerGeneAssay); |
2026 |
25 Sep 13 |
olle |
252 |
debugOut.println("Center::extractAssays(): param_centeringGroups = " + param_centeringGroups); |
2026 |
25 Sep 13 |
olle |
253 |
debugOut.println("Center::extractAssays(): param_centerGroupsAssayNames = \"" + param_centerGroupsAssayNames + "\""); |
2026 |
25 Sep 13 |
olle |
254 |
debugOut.println("Center::extractAssays(): param_centerCycles = " + param_centerCycles); |
2026 |
25 Sep 13 |
olle |
255 |
debugOut.println("Center::extractAssays(): param_mm = " + param_mm); |
2026 |
25 Sep 13 |
olle |
256 |
debugOut.println("Center::extractAssays(): singleCenterGroupAssayNameList = " + singleCenterGroupAssayNameList); |
2026 |
25 Sep 13 |
olle |
257 |
debugOut.println("Center::extractAssays(): singleCenterGroupAssayIndexList = " + singleCenterGroupAssayIndexList); |
2026 |
25 Sep 13 |
olle |
258 |
debugOut.println("Center::extractAssays(): param_centerGroupsAssayNames = \"" + param_centerGroupsAssayNames + "\""); |
2026 |
25 Sep 13 |
olle |
259 |
debugOut.println("Center::extractAssays(): centerGroupsAssayNameHashMap = " + centerGroupsAssayNameHashMap); |
2026 |
25 Sep 13 |
olle |
260 |
debugOut.println("Center::extractAssays(): centerGroupsAssayIndexHashMap = " + centerGroupsAssayIndexHashMap); |
2026 |
25 Sep 13 |
olle |
261 |
debugOut.println("Center::extractAssays(): section.findFieldList(\"columns\") = " + section.findFieldList("columns")); |
2026 |
25 Sep 13 |
olle |
262 |
debugOut.println("Center::extractAssays(): nameCol = " + nameCol); |
2026 |
25 Sep 13 |
olle |
263 |
debugOut.println("Center::extractAssays(): idCol = " + idCol); |
2026 |
25 Sep 13 |
olle |
264 |
debugOut.println("Center::extractAssays(): columns = " + columns); |
2026 |
25 Sep 13 |
olle |
265 |
debugOut.println("Center::extractAssays(): count = " + count); |
2026 |
25 Sep 13 |
olle |
266 |
debugOut.println("Center::extractAssays(): annotationColumns = " + annotationColumns); |
2026 |
25 Sep 13 |
olle |
267 |
} |
149 |
10 Aug 06 |
enell |
268 |
if (columns == null || count == null || annotationColumns == null) |
149 |
10 Aug 06 |
enell |
269 |
{ |
149 |
10 Aug 06 |
enell |
270 |
System.err.println("center: Missing header columns/count/annotationColumns in section assays"); |
149 |
10 Aug 06 |
enell |
271 |
System.exit(-1); |
149 |
10 Aug 06 |
enell |
272 |
} |
149 |
10 Aug 06 |
enell |
273 |
System.out.println(section); |
2026 |
25 Sep 13 |
olle |
274 |
// |
2026 |
25 Sep 13 |
olle |
275 |
if (param_centeringGroups == CenteringGroups.ASSAYGROUPSINGLE) |
2026 |
25 Sep 13 |
olle |
276 |
{ |
2026 |
25 Sep 13 |
olle |
277 |
singleCenterGroupAssayIndexList = new ArrayList<Integer>(); |
2026 |
25 Sep 13 |
olle |
278 |
} |
2026 |
25 Sep 13 |
olle |
279 |
if (param_centeringGroups == CenteringGroups.ASSAYGROUPS) |
2026 |
25 Sep 13 |
olle |
280 |
{ |
2026 |
25 Sep 13 |
olle |
281 |
centerGroupsAssayIndexHashMap = new HashMap<Integer,List<Integer>>(); |
2026 |
25 Sep 13 |
olle |
282 |
} |
149 |
10 Aug 06 |
enell |
283 |
String[] vals; |
2026 |
25 Sep 13 |
olle |
284 |
int index = 0; |
149 |
10 Aug 06 |
enell |
285 |
while ((vals = reader.readDataRow()) != null) |
149 |
10 Aug 06 |
enell |
286 |
{ |
2026 |
25 Sep 13 |
olle |
287 |
if (debug) |
2026 |
25 Sep 13 |
olle |
288 |
{ |
2026 |
25 Sep 13 |
olle |
289 |
debugOut.println("Center::extractAssays(): Data row: " + (index + 1) + " vals[idCol]: " + vals[idCol] + " vals[nameCol]: " + vals[nameCol]); |
2026 |
25 Sep 13 |
olle |
290 |
} |
2026 |
25 Sep 13 |
olle |
291 |
if (param_centeringGroups == CenteringGroups.ASSAYGROUPSINGLE) |
2026 |
25 Sep 13 |
olle |
292 |
{ |
2026 |
25 Sep 13 |
olle |
293 |
String assayName = vals[nameCol]; |
2026 |
25 Sep 13 |
olle |
294 |
if (singleCenterGroupAssayNameList.contains(assayName)) |
2026 |
25 Sep 13 |
olle |
295 |
{ |
2026 |
25 Sep 13 |
olle |
// Add index value for assay |
2026 |
25 Sep 13 |
olle |
297 |
singleCenterGroupAssayIndexList.add(index); |
2026 |
25 Sep 13 |
olle |
298 |
if (debug) |
2026 |
25 Sep 13 |
olle |
299 |
{ |
2026 |
25 Sep 13 |
olle |
300 |
debugOut.println("Center::extractAssays(): Assay \"" + assayName + "\" with index " + index + " included: yes"); |
2026 |
25 Sep 13 |
olle |
301 |
} } |
2026 |
25 Sep 13 |
olle |
302 |
else |
2026 |
25 Sep 13 |
olle |
303 |
{ |
2026 |
25 Sep 13 |
olle |
304 |
if (debug) |
2026 |
25 Sep 13 |
olle |
305 |
{ |
2026 |
25 Sep 13 |
olle |
306 |
debugOut.println("Center::extractAssays(): Assay \"" + assayName + "\" with index " + index + " included: no"); |
2026 |
25 Sep 13 |
olle |
307 |
} |
2026 |
25 Sep 13 |
olle |
308 |
} |
2026 |
25 Sep 13 |
olle |
309 |
} |
2026 |
25 Sep 13 |
olle |
310 |
if (param_centeringGroups == CenteringGroups.ASSAYGROUPS) |
2026 |
25 Sep 13 |
olle |
311 |
{ |
2026 |
25 Sep 13 |
olle |
312 |
String assayName = vals[nameCol]; |
2026 |
25 Sep 13 |
olle |
313 |
for (int i=0; i < centerGroupsAssayNameHashMap.size(); i++) |
2026 |
25 Sep 13 |
olle |
314 |
{ |
2026 |
25 Sep 13 |
olle |
315 |
List<String> assayNameList = (List<String>) centerGroupsAssayNameHashMap.get(i); |
2026 |
25 Sep 13 |
olle |
316 |
if (assayNameList != null && assayNameList.contains(assayName)) |
2026 |
25 Sep 13 |
olle |
317 |
{ |
2026 |
25 Sep 13 |
olle |
// Add index value for assay |
2026 |
25 Sep 13 |
olle |
319 |
if (centerGroupsAssayIndexHashMap.get(i) == null) |
2026 |
25 Sep 13 |
olle |
320 |
{ |
2026 |
25 Sep 13 |
olle |
321 |
List<Integer> assayIndexList = new ArrayList<Integer>(); |
2026 |
25 Sep 13 |
olle |
322 |
centerGroupsAssayIndexHashMap.put(i, assayIndexList); |
2026 |
25 Sep 13 |
olle |
323 |
} |
2026 |
25 Sep 13 |
olle |
324 |
centerGroupsAssayIndexHashMap.get(i).add(index); |
2026 |
25 Sep 13 |
olle |
325 |
} |
2026 |
25 Sep 13 |
olle |
326 |
} |
2026 |
25 Sep 13 |
olle |
327 |
} |
2026 |
25 Sep 13 |
olle |
328 |
index++; |
149 |
10 Aug 06 |
enell |
329 |
for (int i = 0; i < vals.length; i++) |
149 |
10 Aug 06 |
enell |
330 |
{ |
149 |
10 Aug 06 |
enell |
331 |
System.out.print(vals[i]); |
149 |
10 Aug 06 |
enell |
332 |
if (i < vals.length - 1) |
149 |
10 Aug 06 |
enell |
333 |
{ |
149 |
10 Aug 06 |
enell |
334 |
System.out.print("\t"); |
149 |
10 Aug 06 |
enell |
335 |
} |
149 |
10 Aug 06 |
enell |
336 |
} |
149 |
10 Aug 06 |
enell |
337 |
System.out.println(); |
149 |
10 Aug 06 |
enell |
338 |
} |
149 |
10 Aug 06 |
enell |
339 |
System.out.println(); |
2026 |
25 Sep 13 |
olle |
340 |
if (debug) |
2026 |
25 Sep 13 |
olle |
341 |
{ |
2026 |
25 Sep 13 |
olle |
342 |
debugOut.println("Center::extractAssays(): singleCenterGroupAssayIndexList = " + singleCenterGroupAssayIndexList); |
2026 |
25 Sep 13 |
olle |
343 |
debugOut.close(); |
2026 |
25 Sep 13 |
olle |
344 |
} |
149 |
10 Aug 06 |
enell |
345 |
} |
149 |
10 Aug 06 |
enell |
346 |
catch (IOException e) |
149 |
10 Aug 06 |
enell |
347 |
{ |
149 |
10 Aug 06 |
enell |
348 |
e.printStackTrace(); |
149 |
10 Aug 06 |
enell |
349 |
} |
149 |
10 Aug 06 |
enell |
350 |
} |
149 |
10 Aug 06 |
enell |
351 |
|
149 |
10 Aug 06 |
enell |
352 |
public void extractSpots(BASEFileSection section, BASEFileReader reader) |
149 |
10 Aug 06 |
enell |
353 |
{ |
149 |
10 Aug 06 |
enell |
354 |
List<String> columns = section.findFieldList("columns"); |
149 |
10 Aug 06 |
enell |
355 |
List<String> assayFields = section.findFieldList("assayFields"); |
149 |
10 Aug 06 |
enell |
356 |
List<String> assays = section.findFieldList("assays"); |
149 |
10 Aug 06 |
enell |
357 |
if (columns == null || assayFields == null || assays == null) |
149 |
10 Aug 06 |
enell |
358 |
{ |
149 |
10 Aug 06 |
enell |
359 |
System.err.println("center: Missing header columns/assayFields/assays in section spots"); |
149 |
10 Aug 06 |
enell |
360 |
System.exit(-1); |
149 |
10 Aug 06 |
enell |
361 |
} |
149 |
10 Aug 06 |
enell |
362 |
|
149 |
10 Aug 06 |
enell |
363 |
posCol = columns.indexOf("position"); |
149 |
10 Aug 06 |
enell |
364 |
repCol = columns.indexOf("reporter"); |
149 |
10 Aug 06 |
enell |
365 |
dataCol = columns.indexOf("assayData"); |
149 |
10 Aug 06 |
enell |
366 |
mCol = assayFields.indexOf("l2ratio1_2"); |
149 |
10 Aug 06 |
enell |
367 |
aCol = assayFields.indexOf("l10intgmean1_2"); |
149 |
10 Aug 06 |
enell |
368 |
if (posCol == -1 || repCol == -1 || dataCol == -1 || mCol == -1 || aCol == -1) |
149 |
10 Aug 06 |
enell |
369 |
{ |
149 |
10 Aug 06 |
enell |
370 |
System.err.println("center: Missing position/reporter/assayData columns or l2ratio1_2/l10intgmean1_2 fields in section spots"); |
149 |
10 Aug 06 |
enell |
371 |
System.exit(-1); |
149 |
10 Aug 06 |
enell |
372 |
} |
149 |
10 Aug 06 |
enell |
373 |
aCol += dataCol; |
149 |
10 Aug 06 |
enell |
374 |
mCol += dataCol; |
149 |
10 Aug 06 |
enell |
375 |
|
149 |
10 Aug 06 |
enell |
376 |
nbrOfCol = columns.size(); |
149 |
10 Aug 06 |
enell |
377 |
nbrOfAssays = assays.size(); |
149 |
10 Aug 06 |
enell |
378 |
nbrOfFields = assayFields.size(); |
149 |
10 Aug 06 |
enell |
379 |
|
2026 |
25 Sep 13 |
olle |
380 |
if (param_centeringGroups == CenteringGroups.DEFAULT) |
2026 |
25 Sep 13 |
olle |
381 |
{ |
2026 |
25 Sep 13 |
olle |
382 |
if (param_centerGeneAssay == GeneAssay.ASSAYS) |
2026 |
25 Sep 13 |
olle |
383 |
{ |
2026 |
25 Sep 13 |
olle |
// Add index value for each assay in its own group |
2026 |
25 Sep 13 |
olle |
385 |
if (centerGroupsAssayIndexHashMap == null) |
2026 |
25 Sep 13 |
olle |
386 |
{ |
2026 |
25 Sep 13 |
olle |
387 |
centerGroupsAssayIndexHashMap = new HashMap<Integer,List<Integer>>(); |
2026 |
25 Sep 13 |
olle |
388 |
} |
2026 |
25 Sep 13 |
olle |
389 |
for (int i=0; i < nbrOfAssays; i++) |
2026 |
25 Sep 13 |
olle |
390 |
{ |
2026 |
25 Sep 13 |
olle |
391 |
if (centerGroupsAssayIndexHashMap.get(i) == null) |
2026 |
25 Sep 13 |
olle |
392 |
{ |
2026 |
25 Sep 13 |
olle |
393 |
List<Integer> assayIndexList = new ArrayList<Integer>(); |
2026 |
25 Sep 13 |
olle |
394 |
centerGroupsAssayIndexHashMap.put(i, assayIndexList); |
2026 |
25 Sep 13 |
olle |
395 |
} |
2026 |
25 Sep 13 |
olle |
396 |
centerGroupsAssayIndexHashMap.get(i).add(i); |
2026 |
25 Sep 13 |
olle |
397 |
} |
2026 |
25 Sep 13 |
olle |
398 |
} |
2026 |
25 Sep 13 |
olle |
399 |
if (param_centerGeneAssay == GeneAssay.GENES) |
2026 |
25 Sep 13 |
olle |
400 |
{ |
2026 |
25 Sep 13 |
olle |
// Add index value for all assays in its one single group |
2026 |
25 Sep 13 |
olle |
402 |
if (centerGroupsAssayIndexHashMap == null) |
2026 |
25 Sep 13 |
olle |
403 |
{ |
2026 |
25 Sep 13 |
olle |
404 |
centerGroupsAssayIndexHashMap = new HashMap<Integer,List<Integer>>(); |
2026 |
25 Sep 13 |
olle |
405 |
} |
2026 |
25 Sep 13 |
olle |
406 |
for (int i=0; i < nbrOfAssays; i++) |
2026 |
25 Sep 13 |
olle |
407 |
{ |
2026 |
25 Sep 13 |
olle |
408 |
if (centerGroupsAssayIndexHashMap.get(0) == null) |
2026 |
25 Sep 13 |
olle |
409 |
{ |
2026 |
25 Sep 13 |
olle |
410 |
List<Integer> assayIndexList = new ArrayList<Integer>(); |
2026 |
25 Sep 13 |
olle |
411 |
centerGroupsAssayIndexHashMap.put(0, assayIndexList); |
2026 |
25 Sep 13 |
olle |
412 |
} |
2026 |
25 Sep 13 |
olle |
413 |
centerGroupsAssayIndexHashMap.get(0).add(i); |
2026 |
25 Sep 13 |
olle |
414 |
} |
2026 |
25 Sep 13 |
olle |
415 |
} |
2026 |
25 Sep 13 |
olle |
416 |
} |
2026 |
25 Sep 13 |
olle |
417 |
|
149 |
10 Aug 06 |
enell |
418 |
int totNbrOfCol = nbrOfCol - 1 + nbrOfAssays * nbrOfFields; |
149 |
10 Aug 06 |
enell |
419 |
try |
149 |
10 Aug 06 |
enell |
420 |
{ |
2026 |
25 Sep 13 |
olle |
421 |
PrintStream debugOut = null; |
2026 |
25 Sep 13 |
olle |
422 |
if (debug) |
2026 |
25 Sep 13 |
olle |
423 |
{ |
2026 |
25 Sep 13 |
olle |
424 |
debugOut = new PrintStream(new File("data", "debugExtractSpots.txt")); |
2026 |
25 Sep 13 |
olle |
425 |
debugOut.println("Center::extractSpots(): section.getHeaders() = " + section.getHeaders()); |
2026 |
25 Sep 13 |
olle |
426 |
debugOut.println("Center::extractSpots(): param_centerGeneAssay = " + param_centerGeneAssay); |
2026 |
25 Sep 13 |
olle |
427 |
debugOut.println("Center::extractSpots(): param_centeringGroups = " + param_centeringGroups); |
2026 |
25 Sep 13 |
olle |
428 |
debugOut.println("Center::extractSpots(): param_centerGroupsAssayNames = \"" + param_centerGroupsAssayNames + "\""); |
2026 |
25 Sep 13 |
olle |
429 |
debugOut.println("Center::extractSpots(): param_centerCycles = " + param_centerCycles); |
2026 |
25 Sep 13 |
olle |
430 |
debugOut.println("Center::extractSpots(): param_mm = " + param_mm); |
2026 |
25 Sep 13 |
olle |
431 |
debugOut.println("Center::extractSpots(): singleCenterGroupAssayNameList = " + singleCenterGroupAssayNameList); |
2026 |
25 Sep 13 |
olle |
432 |
debugOut.println("Center::extractSpots(): singleCenterGroupAssayIndexList = " + singleCenterGroupAssayIndexList); |
2026 |
25 Sep 13 |
olle |
433 |
debugOut.println("Center::extractSpots(): param_centerGroupsAssayNames = \"" + param_centerGroupsAssayNames + "\""); |
2026 |
25 Sep 13 |
olle |
434 |
debugOut.println("Center::extractSpots(): centerGroupsAssayNameHashMap = " + centerGroupsAssayNameHashMap); |
2026 |
25 Sep 13 |
olle |
435 |
debugOut.println("Center::extractSpots(): centerGroupsAssayIndexHashMap = " + centerGroupsAssayIndexHashMap); |
2026 |
25 Sep 13 |
olle |
436 |
debugOut.println("Center::extractSpots(): nbrOfCol = " + nbrOfCol); |
2026 |
25 Sep 13 |
olle |
437 |
debugOut.println("Center::extractSpots(): nbrOfAssays = " + nbrOfAssays); |
2026 |
25 Sep 13 |
olle |
438 |
debugOut.println("Center::extractSpots(): nbrOfFields = " + nbrOfFields); |
2026 |
25 Sep 13 |
olle |
439 |
debugOut.println("Center::extractSpots(): assays = " + assays); |
2026 |
25 Sep 13 |
olle |
440 |
debugOut.println("Center::extractSpots(): columns = " + columns); |
2026 |
25 Sep 13 |
olle |
441 |
debugOut.println("Center::extractSpots(): posCol = " + posCol); |
2026 |
25 Sep 13 |
olle |
442 |
debugOut.println("Center::extractSpots(): repCol = " + repCol); |
2026 |
25 Sep 13 |
olle |
443 |
debugOut.println("Center::extractSpots(): dataCol = " + dataCol); |
2026 |
25 Sep 13 |
olle |
444 |
debugOut.println("Center::extractSpots(): mCol = " + mCol); |
2026 |
25 Sep 13 |
olle |
445 |
debugOut.println("Center::extractSpots(): aCol = " + aCol); |
2026 |
25 Sep 13 |
olle |
446 |
} |
2026 |
25 Sep 13 |
olle |
447 |
int nRow = 0; |
149 |
10 Aug 06 |
enell |
448 |
String[] vals = reader.readDataRow(totNbrOfCol); |
149 |
10 Aug 06 |
enell |
449 |
while (vals != null) |
149 |
10 Aug 06 |
enell |
450 |
{ |
149 |
10 Aug 06 |
enell |
451 |
AssayRow assayRow = new AssayRow(Integer.parseInt(vals[posCol]), Integer.parseInt(vals[repCol]), nbrOfAssays); |
149 |
10 Aug 06 |
enell |
452 |
for (int i = 0; i < nbrOfAssays; i++) |
149 |
10 Aug 06 |
enell |
453 |
{ |
149 |
10 Aug 06 |
enell |
454 |
float m, a; |
149 |
10 Aug 06 |
enell |
455 |
try |
149 |
10 Aug 06 |
enell |
456 |
{ |
149 |
10 Aug 06 |
enell |
457 |
m = Float.parseFloat(vals[mCol + i * nbrOfFields]); |
149 |
10 Aug 06 |
enell |
458 |
a = Float.parseFloat(vals[aCol + i * nbrOfFields]); |
149 |
10 Aug 06 |
enell |
459 |
} |
149 |
10 Aug 06 |
enell |
460 |
catch (NumberFormatException e) |
149 |
10 Aug 06 |
enell |
461 |
{ |
149 |
10 Aug 06 |
enell |
462 |
m = Float.NaN; |
149 |
10 Aug 06 |
enell |
463 |
a = Float.NaN; |
149 |
10 Aug 06 |
enell |
464 |
} |
149 |
10 Aug 06 |
enell |
465 |
assayRow.add(i, m, a); |
149 |
10 Aug 06 |
enell |
466 |
} |
149 |
10 Aug 06 |
enell |
467 |
data.add(assayRow); |
149 |
10 Aug 06 |
enell |
468 |
vals = reader.readDataRow(totNbrOfCol); |
2026 |
25 Sep 13 |
olle |
469 |
nRow++; |
149 |
10 Aug 06 |
enell |
470 |
} |
2026 |
25 Sep 13 |
olle |
471 |
if (debug) |
2026 |
25 Sep 13 |
olle |
472 |
{ |
2026 |
25 Sep 13 |
olle |
473 |
debugOut.println("Center::extractSpots(): Number of rows = " + nRow); |
2026 |
25 Sep 13 |
olle |
474 |
debugOut.close(); |
2026 |
25 Sep 13 |
olle |
475 |
} |
149 |
10 Aug 06 |
enell |
476 |
} |
149 |
10 Aug 06 |
enell |
477 |
catch (Exception e) |
149 |
10 Aug 06 |
enell |
478 |
{ |
149 |
10 Aug 06 |
enell |
479 |
e.printStackTrace(); |
149 |
10 Aug 06 |
enell |
480 |
} |
149 |
10 Aug 06 |
enell |
481 |
|
149 |
10 Aug 06 |
enell |
482 |
System.out.println(section); |
149 |
10 Aug 06 |
enell |
483 |
} |
149 |
10 Aug 06 |
enell |
484 |
|
149 |
10 Aug 06 |
enell |
485 |
public void center() |
149 |
10 Aug 06 |
enell |
486 |
{ |
2026 |
25 Sep 13 |
olle |
487 |
try { |
2026 |
25 Sep 13 |
olle |
488 |
PrintStream debugOut = null; |
2026 |
25 Sep 13 |
olle |
489 |
if (debug) |
2026 |
25 Sep 13 |
olle |
490 |
{ |
2026 |
25 Sep 13 |
olle |
491 |
debugOut = new PrintStream(new File("data", "debugCenter.txt")); |
2026 |
25 Sep 13 |
olle |
492 |
debugOut.println("Center::center(): param_centerGeneAssay = " + param_centerGeneAssay); |
2026 |
25 Sep 13 |
olle |
493 |
debugOut.println("Center::center(): param_centeringGroups = " + param_centeringGroups); |
2026 |
25 Sep 13 |
olle |
494 |
debugOut.println("Center::center(): param_centerGroupsAssayNames = \"" + param_centerGroupsAssayNames + "\""); |
2026 |
25 Sep 13 |
olle |
495 |
debugOut.println("Center::center(): param_centerCycles = " + param_centerCycles); |
2026 |
25 Sep 13 |
olle |
496 |
debugOut.println("Center::center(): param_mm = " + param_mm); |
2026 |
25 Sep 13 |
olle |
497 |
debugOut.println("Center::center(): singleCenterGroupAssayNameList = " + singleCenterGroupAssayNameList); |
2026 |
25 Sep 13 |
olle |
498 |
debugOut.println("Center::center(): singleCenterGroupAssayIndexList = " + singleCenterGroupAssayIndexList); |
2026 |
25 Sep 13 |
olle |
499 |
debugOut.println("Center::center(): centerGroupsAssayNameHashMap = " + centerGroupsAssayNameHashMap); |
2026 |
25 Sep 13 |
olle |
500 |
debugOut.println("Center::center(): centerGroupsAssayIndexHashMap = " + centerGroupsAssayIndexHashMap); |
2026 |
25 Sep 13 |
olle |
501 |
} |
2026 |
25 Sep 13 |
olle |
502 |
// |
2026 |
25 Sep 13 |
olle |
503 |
for (int i = 0; i < param_centerCycles; i++) |
2026 |
25 Sep 13 |
olle |
504 |
{ |
2026 |
25 Sep 13 |
olle |
505 |
if (param_centerGeneAssay == GeneAssay.GENES || param_centerGeneAssay == GeneAssay.BOTH) |
2026 |
25 Sep 13 |
olle |
506 |
{ |
2026 |
25 Sep 13 |
olle |
507 |
if (centerGroupsAssayIndexHashMap == null) |
2026 |
25 Sep 13 |
olle |
508 |
{ |
2026 |
25 Sep 13 |
olle |
509 |
centerRows(data); |
2026 |
25 Sep 13 |
olle |
510 |
} |
2026 |
25 Sep 13 |
olle |
511 |
else |
2026 |
25 Sep 13 |
olle |
512 |
{ |
2026 |
25 Sep 13 |
olle |
513 |
centerRowsForGroupsSeparately(data); |
2026 |
25 Sep 13 |
olle |
514 |
} |
2026 |
25 Sep 13 |
olle |
515 |
} |
2026 |
25 Sep 13 |
olle |
516 |
if (param_centerGeneAssay == GeneAssay.ASSAYS || param_centerGeneAssay == GeneAssay.BOTH) |
2026 |
25 Sep 13 |
olle |
517 |
{ |
2026 |
25 Sep 13 |
olle |
518 |
if (centerGroupsAssayIndexHashMap == null) |
2026 |
25 Sep 13 |
olle |
519 |
{ |
2026 |
25 Sep 13 |
olle |
520 |
centerColumns(data); |
2026 |
25 Sep 13 |
olle |
521 |
} |
2026 |
25 Sep 13 |
olle |
522 |
else |
2026 |
25 Sep 13 |
olle |
523 |
{ |
2026 |
25 Sep 13 |
olle |
524 |
centerColumnsForGroupsSeparately(data); |
2026 |
25 Sep 13 |
olle |
525 |
} |
2026 |
25 Sep 13 |
olle |
526 |
} |
2026 |
25 Sep 13 |
olle |
527 |
} |
149 |
10 Aug 06 |
enell |
528 |
|
2026 |
25 Sep 13 |
olle |
529 |
for (AssayRow ar : data) |
149 |
10 Aug 06 |
enell |
530 |
{ |
2026 |
25 Sep 13 |
olle |
531 |
System.out.println(ar); |
149 |
10 Aug 06 |
enell |
532 |
} |
2026 |
25 Sep 13 |
olle |
533 |
if (debug) |
149 |
10 Aug 06 |
enell |
534 |
{ |
2026 |
25 Sep 13 |
olle |
535 |
debugOut.close(); |
149 |
10 Aug 06 |
enell |
536 |
} |
149 |
10 Aug 06 |
enell |
537 |
} |
2026 |
25 Sep 13 |
olle |
538 |
catch (Exception e) |
149 |
10 Aug 06 |
enell |
539 |
{ |
2026 |
25 Sep 13 |
olle |
540 |
e.printStackTrace(); |
149 |
10 Aug 06 |
enell |
541 |
} |
149 |
10 Aug 06 |
enell |
542 |
} |
149 |
10 Aug 06 |
enell |
543 |
|
149 |
10 Aug 06 |
enell |
544 |
|
2026 |
25 Sep 13 |
olle |
545 |
/** |
2026 |
25 Sep 13 |
olle |
* Center rows (genes) with same correction for each A-value (gene) |
2026 |
25 Sep 13 |
olle |
* in M/A-plot for all assays. |
2026 |
25 Sep 13 |
olle |
548 |
* |
2026 |
25 Sep 13 |
olle |
* @param data_arr List<AssayRow> AssayRow list data to use. |
2026 |
25 Sep 13 |
olle |
550 |
*/ |
149 |
10 Aug 06 |
enell |
551 |
private void centerRows(List<AssayRow> data_arr) |
149 |
10 Aug 06 |
enell |
552 |
{ |
2026 |
25 Sep 13 |
olle |
553 |
List<Integer> assayIndexList = singleCenterGroupAssayIndexList; |
2026 |
25 Sep 13 |
olle |
554 |
int nAssayRows = 0; |
2026 |
25 Sep 13 |
olle |
555 |
List<Float> rFitList = new ArrayList<Float>(); |
149 |
10 Aug 06 |
enell |
556 |
for (AssayRow ar : data_arr) |
149 |
10 Aug 06 |
enell |
557 |
{ |
149 |
10 Aug 06 |
enell |
558 |
if (ar.valid()) |
149 |
10 Aug 06 |
enell |
559 |
{ |
149 |
10 Aug 06 |
enell |
560 |
float r_fit; |
149 |
10 Aug 06 |
enell |
561 |
ArrayList<Float> r = new ArrayList<Float>(); |
149 |
10 Aug 06 |
enell |
562 |
for (int j = 0; j < nbrOfAssays; j++) |
149 |
10 Aug 06 |
enell |
563 |
{ |
2026 |
25 Sep 13 |
olle |
// Check if data for assay should be included when calculating center value |
2026 |
25 Sep 13 |
olle |
565 |
boolean includeAssayData = true; |
2026 |
25 Sep 13 |
olle |
566 |
if (assayIndexList != null && !assayIndexList.contains(j)) |
149 |
10 Aug 06 |
enell |
567 |
{ |
2026 |
25 Sep 13 |
olle |
568 |
includeAssayData = false; |
149 |
10 Aug 06 |
enell |
569 |
} |
2026 |
25 Sep 13 |
olle |
570 |
if (includeAssayData) |
2026 |
25 Sep 13 |
olle |
571 |
{ |
2026 |
25 Sep 13 |
olle |
572 |
if (!Float.isNaN(ar.ratio[j])) |
2026 |
25 Sep 13 |
olle |
573 |
{ |
2026 |
25 Sep 13 |
olle |
574 |
r.add(ar.ratio[j]); |
2026 |
25 Sep 13 |
olle |
575 |
} |
2026 |
25 Sep 13 |
olle |
576 |
} |
149 |
10 Aug 06 |
enell |
577 |
} |
149 |
10 Aug 06 |
enell |
578 |
if (param_mm == CenterOn.MEDIAN) |
149 |
10 Aug 06 |
enell |
579 |
{ |
149 |
10 Aug 06 |
enell |
580 |
r_fit = median(r); |
149 |
10 Aug 06 |
enell |
581 |
} |
149 |
10 Aug 06 |
enell |
582 |
else |
149 |
10 Aug 06 |
enell |
583 |
{ |
149 |
10 Aug 06 |
enell |
584 |
r_fit = mean(r); |
149 |
10 Aug 06 |
enell |
585 |
} |
2026 |
25 Sep 13 |
olle |
// Center data for all groups |
149 |
10 Aug 06 |
enell |
587 |
for (int j = 0; j < nbrOfAssays; j++) |
149 |
10 Aug 06 |
enell |
588 |
{ |
149 |
10 Aug 06 |
enell |
589 |
ar.ratio[j] -= r_fit; |
149 |
10 Aug 06 |
enell |
590 |
} |
2026 |
25 Sep 13 |
olle |
591 |
rFitList.add(r_fit); |
2026 |
25 Sep 13 |
olle |
592 |
nAssayRows++; |
149 |
10 Aug 06 |
enell |
593 |
} |
149 |
10 Aug 06 |
enell |
594 |
} |
2026 |
25 Sep 13 |
olle |
595 |
try |
2026 |
25 Sep 13 |
olle |
596 |
{ |
2026 |
25 Sep 13 |
olle |
597 |
if (debug) |
2026 |
25 Sep 13 |
olle |
598 |
{ |
2026 |
25 Sep 13 |
olle |
599 |
PrintStream debugOut = new PrintStream(new File("data", "debugCenterRows.txt")); |
2026 |
25 Sep 13 |
olle |
600 |
debugOut.println("Center::centerRows(): param_centerGeneAssay = " + param_centerGeneAssay); |
2026 |
25 Sep 13 |
olle |
601 |
debugOut.println("Center::centerRows(): param_centeringGroups = " + param_centeringGroups); |
2026 |
25 Sep 13 |
olle |
602 |
debugOut.println("Center::centerRows(): param_centerGroupsAssayNames = \"" + param_centerGroupsAssayNames + "\""); |
2026 |
25 Sep 13 |
olle |
603 |
debugOut.println("Center::centerRows(): param_centerCycles = " + param_centerCycles); |
2026 |
25 Sep 13 |
olle |
604 |
debugOut.println("Center::centerRows(): param_mm = " + param_mm); |
2026 |
25 Sep 13 |
olle |
605 |
debugOut.println("Center::centerRows(): singleCenterGroupAssayIndexList = " + singleCenterGroupAssayIndexList); |
2026 |
25 Sep 13 |
olle |
606 |
debugOut.println("Center::centerRows(): centerGroupsAssayIndexHashMap = " + centerGroupsAssayIndexHashMap); |
2026 |
25 Sep 13 |
olle |
607 |
debugOut.println("Center::centerRows(): nbrOfAssays = " + nbrOfAssays); |
2026 |
25 Sep 13 |
olle |
608 |
debugOut.println("Center::centerRows(): nAssayRows = " + nAssayRows); |
2026 |
25 Sep 13 |
olle |
609 |
debugOut.close(); |
2026 |
25 Sep 13 |
olle |
610 |
PrintStream debugOutRFitList = new PrintStream(new File("data", "debugCenterRowsRFitList.txt")); |
2026 |
25 Sep 13 |
olle |
611 |
for (int nRow = 0; nRow < nAssayRows; nRow++) |
2026 |
25 Sep 13 |
olle |
612 |
{ |
2026 |
25 Sep 13 |
olle |
613 |
Float r_fit = (Float) rFitList.get(nRow); |
2026 |
25 Sep 13 |
olle |
614 |
debugOutRFitList.println("Center::centerRows(): row = " + nRow + " r_fit = " + r_fit); |
2026 |
25 Sep 13 |
olle |
615 |
} |
2026 |
25 Sep 13 |
olle |
616 |
debugOutRFitList.close(); |
2026 |
25 Sep 13 |
olle |
617 |
} |
2026 |
25 Sep 13 |
olle |
618 |
} |
2026 |
25 Sep 13 |
olle |
619 |
catch (Exception e) |
2026 |
25 Sep 13 |
olle |
620 |
{ |
2026 |
25 Sep 13 |
olle |
621 |
e.printStackTrace(); |
2026 |
25 Sep 13 |
olle |
622 |
} |
149 |
10 Aug 06 |
enell |
623 |
} |
149 |
10 Aug 06 |
enell |
624 |
|
2026 |
25 Sep 13 |
olle |
625 |
/** |
2026 |
25 Sep 13 |
olle |
* Center rows (genes) for groups separately. |
2026 |
25 Sep 13 |
olle |
627 |
* |
2026 |
25 Sep 13 |
olle |
* @param data_arr List<AssayRow> AssayRow list data to use. |
2026 |
25 Sep 13 |
olle |
629 |
*/ |
2026 |
25 Sep 13 |
olle |
630 |
private void centerRowsForGroupsSeparately(List<AssayRow> data_arr) |
2026 |
25 Sep 13 |
olle |
631 |
{ |
2026 |
25 Sep 13 |
olle |
632 |
HashMap<Integer,List<Float>> rFitHashMap = new HashMap<Integer,List<Float>>(); |
2026 |
25 Sep 13 |
olle |
633 |
int nAssayRows = 0; |
2026 |
25 Sep 13 |
olle |
634 |
for (AssayRow ar : data_arr) |
2026 |
25 Sep 13 |
olle |
635 |
{ |
2026 |
25 Sep 13 |
olle |
636 |
if (ar.valid()) |
2026 |
25 Sep 13 |
olle |
637 |
{ |
2026 |
25 Sep 13 |
olle |
638 |
List<Float> rFitList = new ArrayList<Float>(); |
2026 |
25 Sep 13 |
olle |
639 |
for (int j = 0; j < nbrOfAssays; j++) |
2026 |
25 Sep 13 |
olle |
640 |
{ |
2026 |
25 Sep 13 |
olle |
641 |
rFitList.add(0f); |
2026 |
25 Sep 13 |
olle |
642 |
} |
2026 |
25 Sep 13 |
olle |
// Center data for groups separately |
2026 |
25 Sep 13 |
olle |
644 |
for (int i = 0; i < centerGroupsAssayIndexHashMap.size(); i++) |
2026 |
25 Sep 13 |
olle |
645 |
{ |
2026 |
25 Sep 13 |
olle |
646 |
List<Integer> assayIndexList = (List<Integer>) centerGroupsAssayIndexHashMap.get(i); |
2026 |
25 Sep 13 |
olle |
647 |
float r_fit = 0f; |
2026 |
25 Sep 13 |
olle |
648 |
ArrayList<Float> r = new ArrayList<Float>(); |
2026 |
25 Sep 13 |
olle |
649 |
for (int j = 0; j < nbrOfAssays; j++) |
2026 |
25 Sep 13 |
olle |
650 |
{ |
2026 |
25 Sep 13 |
olle |
// Check if data for assay should be included when calculating center value |
2026 |
25 Sep 13 |
olle |
652 |
boolean includeAssayData = true; |
2026 |
25 Sep 13 |
olle |
653 |
if (assayIndexList != null && !assayIndexList.contains(j)) |
2026 |
25 Sep 13 |
olle |
654 |
{ |
2026 |
25 Sep 13 |
olle |
655 |
includeAssayData = false; |
2026 |
25 Sep 13 |
olle |
656 |
} |
2026 |
25 Sep 13 |
olle |
657 |
if (includeAssayData) |
2026 |
25 Sep 13 |
olle |
658 |
{ |
2026 |
25 Sep 13 |
olle |
659 |
if (!Float.isNaN(ar.ratio[j])) |
2026 |
25 Sep 13 |
olle |
660 |
{ |
2026 |
25 Sep 13 |
olle |
661 |
r.add(ar.ratio[j]); |
2026 |
25 Sep 13 |
olle |
662 |
} |
2026 |
25 Sep 13 |
olle |
663 |
} |
2026 |
25 Sep 13 |
olle |
664 |
} |
2026 |
25 Sep 13 |
olle |
665 |
if (param_mm == CenterOn.MEDIAN) |
2026 |
25 Sep 13 |
olle |
666 |
{ |
2026 |
25 Sep 13 |
olle |
667 |
r_fit = median(r); |
2026 |
25 Sep 13 |
olle |
668 |
} |
2026 |
25 Sep 13 |
olle |
669 |
else |
2026 |
25 Sep 13 |
olle |
670 |
{ |
2026 |
25 Sep 13 |
olle |
671 |
r_fit = mean(r); |
2026 |
25 Sep 13 |
olle |
672 |
} |
2026 |
25 Sep 13 |
olle |
// Only center data for current group |
2026 |
25 Sep 13 |
olle |
674 |
for (int j = 0; j < nbrOfAssays; j++) |
2026 |
25 Sep 13 |
olle |
675 |
{ |
2026 |
25 Sep 13 |
olle |
676 |
if (assayIndexList == null || assayIndexList.contains(j)) |
2026 |
25 Sep 13 |
olle |
677 |
{ |
2026 |
25 Sep 13 |
olle |
678 |
ar.ratio[j] -= r_fit; |
2026 |
25 Sep 13 |
olle |
679 |
rFitList.set(j, r_fit); |
2026 |
25 Sep 13 |
olle |
680 |
} |
2026 |
25 Sep 13 |
olle |
681 |
} |
2026 |
25 Sep 13 |
olle |
682 |
} |
2026 |
25 Sep 13 |
olle |
683 |
rFitHashMap.put(nAssayRows, rFitList); |
2026 |
25 Sep 13 |
olle |
684 |
nAssayRows++; |
2026 |
25 Sep 13 |
olle |
685 |
} |
2026 |
25 Sep 13 |
olle |
686 |
} |
2026 |
25 Sep 13 |
olle |
687 |
try |
2026 |
25 Sep 13 |
olle |
688 |
{ |
2026 |
25 Sep 13 |
olle |
689 |
if (debug) |
2026 |
25 Sep 13 |
olle |
690 |
{ |
2026 |
25 Sep 13 |
olle |
691 |
PrintStream debugOut = new PrintStream(new File("data", "debugCenterRowsForGroupsSeparately.txt")); |
2026 |
25 Sep 13 |
olle |
692 |
debugOut.println("Center::centerRowsForGroupsSeparately(): param_centerGeneAssay = " + param_centerGeneAssay); |
2026 |
25 Sep 13 |
olle |
693 |
debugOut.println("Center::centerRowsForGroupsSeparately(): param_centeringGroups = " + param_centeringGroups); |
2026 |
25 Sep 13 |
olle |
694 |
debugOut.println("Center::centerRowsForGroupsSeparately(): param_centerGroupsAssayNames = \"" + param_centerGroupsAssayNames + "\""); |
2026 |
25 Sep 13 |
olle |
695 |
debugOut.println("Center::centerRowsForGroupsSeparately(): param_centerCycles = " + param_centerCycles); |
2026 |
25 Sep 13 |
olle |
696 |
debugOut.println("Center::centerRowsForGroupsSeparately(): param_mm = " + param_mm); |
2026 |
25 Sep 13 |
olle |
697 |
debugOut.println("Center::centerRowsForGroupsSeparately(): singleCenterGroupAssayIndexList = " + singleCenterGroupAssayIndexList); |
2026 |
25 Sep 13 |
olle |
698 |
debugOut.println("Center::centerRowsForGroupsSeparately(): centerGroupsAssayIndexHashMap = " + centerGroupsAssayIndexHashMap); |
2026 |
25 Sep 13 |
olle |
699 |
debugOut.println("Center::centerRowsForGroupsSeparately(): nbrOfAssays = " + nbrOfAssays); |
2026 |
25 Sep 13 |
olle |
700 |
debugOut.println("Center::centerRowsForGroupsSeparately(): nAssayRows = " + nAssayRows); |
2026 |
25 Sep 13 |
olle |
701 |
PrintStream debugOutRFitList = new PrintStream(new File("data", "debugCenterRowsForGroupsSeparatelyRFitList.txt")); |
2026 |
25 Sep 13 |
olle |
702 |
for (int nRow = 0; nRow < nAssayRows; nRow++) |
2026 |
25 Sep 13 |
olle |
703 |
{ |
2026 |
25 Sep 13 |
olle |
704 |
List<Float> rFitList = (List<Float>) rFitHashMap.get(nRow); |
2026 |
25 Sep 13 |
olle |
705 |
for (int nAssay = 0; nAssay < nbrOfAssays; nAssay++) |
2026 |
25 Sep 13 |
olle |
706 |
{ |
2026 |
25 Sep 13 |
olle |
// Get r_fit for gene nRow and assay nAssay |
2026 |
25 Sep 13 |
olle |
708 |
Float r_fit = (Float) rFitList.get(nAssay); |
2026 |
25 Sep 13 |
olle |
709 |
debugOutRFitList.println("Center::centerRowsForGroupsSeparately(): nRow = " + nRow + " nAssay = " + nAssay + " r_fit = " + r_fit); |
2026 |
25 Sep 13 |
olle |
710 |
} |
2026 |
25 Sep 13 |
olle |
711 |
} |
2026 |
25 Sep 13 |
olle |
712 |
debugOutRFitList.close(); |
2026 |
25 Sep 13 |
olle |
713 |
debugOut.close(); |
2026 |
25 Sep 13 |
olle |
714 |
} |
2026 |
25 Sep 13 |
olle |
715 |
} |
2026 |
25 Sep 13 |
olle |
716 |
catch (Exception e) |
2026 |
25 Sep 13 |
olle |
717 |
{ |
2026 |
25 Sep 13 |
olle |
718 |
e.printStackTrace(); |
2026 |
25 Sep 13 |
olle |
719 |
} |
2026 |
25 Sep 13 |
olle |
720 |
} |
2026 |
25 Sep 13 |
olle |
721 |
|
2026 |
25 Sep 13 |
olle |
722 |
/** |
2026 |
25 Sep 13 |
olle |
* Center columns (assays) with constant correction over A in M/A-plot. |
2026 |
25 Sep 13 |
olle |
724 |
* |
2026 |
25 Sep 13 |
olle |
* @param data_arr List<AssayRow> AssayRow list data to use. |
2026 |
25 Sep 13 |
olle |
726 |
*/ |
149 |
10 Aug 06 |
enell |
727 |
private void centerColumns(List<AssayRow> data_arr) |
149 |
10 Aug 06 |
enell |
728 |
{ |
2026 |
25 Sep 13 |
olle |
729 |
List<Integer> assayIndexList = singleCenterGroupAssayIndexList; |
2026 |
25 Sep 13 |
olle |
// Store centering values for debug output |
2026 |
25 Sep 13 |
olle |
731 |
List<Float> rFitList = new ArrayList<Float>(); |
2026 |
25 Sep 13 |
olle |
732 |
List<Integer> nAssayRowList = new ArrayList<Integer>(); |
2026 |
25 Sep 13 |
olle |
733 |
List<Float> r_single = null; |
2026 |
25 Sep 13 |
olle |
734 |
if (assayIndexList != null) |
2026 |
25 Sep 13 |
olle |
735 |
{ |
2026 |
25 Sep 13 |
olle |
// Collect data from single selected assay group |
2026 |
25 Sep 13 |
olle |
737 |
r_single = new ArrayList<Float>(); |
2026 |
25 Sep 13 |
olle |
738 |
for (int j = 0; j < nbrOfAssays; j++) |
2026 |
25 Sep 13 |
olle |
739 |
{ |
2026 |
25 Sep 13 |
olle |
740 |
if (assayIndexList.contains(j)) |
2026 |
25 Sep 13 |
olle |
741 |
{ |
2026 |
25 Sep 13 |
olle |
742 |
for (AssayRow ar : data_arr) |
2026 |
25 Sep 13 |
olle |
743 |
{ |
2026 |
25 Sep 13 |
olle |
744 |
if (!Float.isNaN(ar.ratio[j])) |
2026 |
25 Sep 13 |
olle |
745 |
{ |
2026 |
25 Sep 13 |
olle |
746 |
r_single.add(ar.ratio[j]); |
2026 |
25 Sep 13 |
olle |
747 |
} |
2026 |
25 Sep 13 |
olle |
748 |
} |
2026 |
25 Sep 13 |
olle |
749 |
} |
2026 |
25 Sep 13 |
olle |
750 |
} |
2026 |
25 Sep 13 |
olle |
751 |
} |
149 |
10 Aug 06 |
enell |
752 |
for (int j = 0; j < nbrOfAssays; j++) |
149 |
10 Aug 06 |
enell |
753 |
{ |
149 |
10 Aug 06 |
enell |
754 |
float r_fit; |
2026 |
25 Sep 13 |
olle |
755 |
List<Float> r = new ArrayList<Float>(); |
2026 |
25 Sep 13 |
olle |
756 |
if (r_single != null) |
149 |
10 Aug 06 |
enell |
757 |
{ |
2026 |
25 Sep 13 |
olle |
// Use data from single assay group for centering |
2026 |
25 Sep 13 |
olle |
759 |
r = r_single; |
2026 |
25 Sep 13 |
olle |
760 |
} |
2026 |
25 Sep 13 |
olle |
761 |
else |
2026 |
25 Sep 13 |
olle |
762 |
{ |
2026 |
25 Sep 13 |
olle |
// Use data from each assay for centering |
2026 |
25 Sep 13 |
olle |
764 |
for (AssayRow ar : data_arr) |
149 |
10 Aug 06 |
enell |
765 |
{ |
2026 |
25 Sep 13 |
olle |
766 |
if (!Float.isNaN(ar.ratio[j])) |
2026 |
25 Sep 13 |
olle |
767 |
{ |
2026 |
25 Sep 13 |
olle |
768 |
r.add(ar.ratio[j]); |
2026 |
25 Sep 13 |
olle |
769 |
} |
149 |
10 Aug 06 |
enell |
770 |
} |
149 |
10 Aug 06 |
enell |
771 |
} |
149 |
10 Aug 06 |
enell |
772 |
if (param_mm == CenterOn.MEDIAN) |
149 |
10 Aug 06 |
enell |
773 |
{ |
149 |
10 Aug 06 |
enell |
774 |
r_fit = median(r); |
149 |
10 Aug 06 |
enell |
775 |
} |
149 |
10 Aug 06 |
enell |
776 |
else |
149 |
10 Aug 06 |
enell |
777 |
{ |
149 |
10 Aug 06 |
enell |
778 |
r_fit = mean(r); |
149 |
10 Aug 06 |
enell |
779 |
} |
2026 |
25 Sep 13 |
olle |
780 |
rFitList.add(r_fit); |
2026 |
25 Sep 13 |
olle |
781 |
int nAssayRows = 0; |
149 |
10 Aug 06 |
enell |
782 |
for (AssayRow ar : data_arr) |
149 |
10 Aug 06 |
enell |
783 |
{ |
149 |
10 Aug 06 |
enell |
784 |
ar.ratio[j] -= r_fit; |
2026 |
25 Sep 13 |
olle |
785 |
nAssayRows++; |
149 |
10 Aug 06 |
enell |
786 |
} |
2026 |
25 Sep 13 |
olle |
787 |
nAssayRowList.add(nAssayRows); |
149 |
10 Aug 06 |
enell |
788 |
} |
2026 |
25 Sep 13 |
olle |
789 |
try |
2026 |
25 Sep 13 |
olle |
790 |
{ |
2026 |
25 Sep 13 |
olle |
791 |
if (debug) |
2026 |
25 Sep 13 |
olle |
792 |
{ |
2026 |
25 Sep 13 |
olle |
793 |
PrintStream debugOut = new PrintStream(new File("data", "debugCenterColumns.txt")); |
2026 |
25 Sep 13 |
olle |
794 |
debugOut.println("Center::centerColumns(): param_centerGeneAssay = " + param_centerGeneAssay); |
2026 |
25 Sep 13 |
olle |
795 |
debugOut.println("Center::centerColumns(): param_centeringGroups = " + param_centeringGroups); |
2026 |
25 Sep 13 |
olle |
796 |
debugOut.println("Center::centerColumns(): param_centerGroupsAssayNames = \"" + param_centerGroupsAssayNames + "\""); |
2026 |
25 Sep 13 |
olle |
797 |
debugOut.println("Center::centerColumns(): param_centerCycles = " + param_centerCycles); |
2026 |
25 Sep 13 |
olle |
798 |
debugOut.println("Center::centerColumns(): param_mm = " + param_mm); |
2026 |
25 Sep 13 |
olle |
799 |
debugOut.println("Center::centerColumns(): singleCenterGroupAssayIndexList = " + singleCenterGroupAssayIndexList); |
2026 |
25 Sep 13 |
olle |
800 |
debugOut.println("Center::centerColumns(): centerGroupsAssayIndexHashMap = " + centerGroupsAssayIndexHashMap); |
2026 |
25 Sep 13 |
olle |
801 |
debugOut.println("Center::centerColumns(): nbrOfAssays = " + nbrOfAssays); |
2026 |
25 Sep 13 |
olle |
802 |
for (int i = 0; i < nbrOfAssays; i++) |
2026 |
25 Sep 13 |
olle |
803 |
{ |
2026 |
25 Sep 13 |
olle |
804 |
debugOut.println("Center::centerColumns(): assay = " + i + " nAssayRows = " + (Integer) nAssayRowList.get(i) + " r_fit = " + (Float) rFitList.get(i)); |
2026 |
25 Sep 13 |
olle |
805 |
} |
2026 |
25 Sep 13 |
olle |
806 |
debugOut.close(); |
2026 |
25 Sep 13 |
olle |
807 |
} |
2026 |
25 Sep 13 |
olle |
808 |
} |
2026 |
25 Sep 13 |
olle |
809 |
catch (Exception e) |
2026 |
25 Sep 13 |
olle |
810 |
{ |
2026 |
25 Sep 13 |
olle |
811 |
e.printStackTrace(); |
2026 |
25 Sep 13 |
olle |
812 |
} |
149 |
10 Aug 06 |
enell |
813 |
} |
149 |
10 Aug 06 |
enell |
814 |
|
2026 |
25 Sep 13 |
olle |
815 |
/** |
2026 |
25 Sep 13 |
olle |
* Center columns (assays) for groups separately. |
2026 |
25 Sep 13 |
olle |
817 |
* |
2026 |
25 Sep 13 |
olle |
* @param data_arr List<AssayRow> AssayRow list data to use. |
2026 |
25 Sep 13 |
olle |
819 |
*/ |
2026 |
25 Sep 13 |
olle |
820 |
private void centerColumnsForGroupsSeparately(List<AssayRow> data_arr) |
2026 |
25 Sep 13 |
olle |
821 |
{ |
2026 |
25 Sep 13 |
olle |
// Store centering values for debug output |
2026 |
25 Sep 13 |
olle |
823 |
List<Float> rFitList = new ArrayList<Float>(); |
2026 |
25 Sep 13 |
olle |
824 |
List<Integer> nAssayRowList = new ArrayList<Integer>(); |
2026 |
25 Sep 13 |
olle |
825 |
for (int i = 0; i < centerGroupsAssayIndexHashMap.size(); i++) |
2026 |
25 Sep 13 |
olle |
826 |
{ |
2026 |
25 Sep 13 |
olle |
827 |
List<Integer> assayIndexList = (List<Integer>) centerGroupsAssayIndexHashMap.get(i); |
2026 |
25 Sep 13 |
olle |
// Step 1 - Calculate centering values for assay groups |
2026 |
25 Sep 13 |
olle |
829 |
float r_fit = 0f; |
2026 |
25 Sep 13 |
olle |
830 |
ArrayList<Float> r = new ArrayList<Float>(); |
2026 |
25 Sep 13 |
olle |
831 |
for (int j = 0; j < nbrOfAssays; j++) |
2026 |
25 Sep 13 |
olle |
832 |
{ |
2026 |
25 Sep 13 |
olle |
// Check if data for assay should be included when calculating center value |
2026 |
25 Sep 13 |
olle |
834 |
boolean includeAssayData = true; |
2026 |
25 Sep 13 |
olle |
835 |
if (assayIndexList != null && !assayIndexList.contains(j)) |
2026 |
25 Sep 13 |
olle |
836 |
{ |
2026 |
25 Sep 13 |
olle |
837 |
includeAssayData = false; |
2026 |
25 Sep 13 |
olle |
838 |
} |
2026 |
25 Sep 13 |
olle |
839 |
if (includeAssayData) |
2026 |
25 Sep 13 |
olle |
840 |
{ |
2026 |
25 Sep 13 |
olle |
841 |
for (AssayRow ar : data_arr) |
2026 |
25 Sep 13 |
olle |
842 |
{ |
2026 |
25 Sep 13 |
olle |
843 |
if (!Float.isNaN(ar.ratio[j])) |
2026 |
25 Sep 13 |
olle |
844 |
{ |
2026 |
25 Sep 13 |
olle |
845 |
r.add(ar.ratio[j]); |
2026 |
25 Sep 13 |
olle |
846 |
} |
2026 |
25 Sep 13 |
olle |
847 |
} |
2026 |
25 Sep 13 |
olle |
848 |
} |
2026 |
25 Sep 13 |
olle |
849 |
} |
2026 |
25 Sep 13 |
olle |
850 |
if (param_mm == CenterOn.MEDIAN) |
2026 |
25 Sep 13 |
olle |
851 |
{ |
2026 |
25 Sep 13 |
olle |
852 |
r_fit = median(r); |
2026 |
25 Sep 13 |
olle |
853 |
} |
2026 |
25 Sep 13 |
olle |
854 |
else |
2026 |
25 Sep 13 |
olle |
855 |
{ |
2026 |
25 Sep 13 |
olle |
856 |
r_fit = mean(r); |
2026 |
25 Sep 13 |
olle |
857 |
} |
2026 |
25 Sep 13 |
olle |
858 |
rFitList.add(r_fit); |
2026 |
25 Sep 13 |
olle |
// Only center data for current group |
2026 |
25 Sep 13 |
olle |
860 |
for (int j = 0; j < nbrOfAssays; j++) |
2026 |
25 Sep 13 |
olle |
861 |
{ |
2026 |
25 Sep 13 |
olle |
862 |
int nAssayRows = 0; |
2026 |
25 Sep 13 |
olle |
863 |
if (assayIndexList == null || assayIndexList.contains(j)) |
2026 |
25 Sep 13 |
olle |
864 |
{ |
2026 |
25 Sep 13 |
olle |
865 |
for (AssayRow ar : data_arr) |
2026 |
25 Sep 13 |
olle |
866 |
{ |
2026 |
25 Sep 13 |
olle |
867 |
if (!Float.isNaN(ar.ratio[j])) |
2026 |
25 Sep 13 |
olle |
868 |
{ |
2026 |
25 Sep 13 |
olle |
869 |
ar.ratio[j] -= r_fit; |
2026 |
25 Sep 13 |
olle |
870 |
nAssayRows++; |
2026 |
25 Sep 13 |
olle |
871 |
} |
2026 |
25 Sep 13 |
olle |
872 |
} |
2026 |
25 Sep 13 |
olle |
873 |
} |
2026 |
25 Sep 13 |
olle |
874 |
nAssayRowList.add(nAssayRows); |
2026 |
25 Sep 13 |
olle |
875 |
} |
2026 |
25 Sep 13 |
olle |
876 |
} |
2026 |
25 Sep 13 |
olle |
877 |
try |
2026 |
25 Sep 13 |
olle |
878 |
{ |
2026 |
25 Sep 13 |
olle |
879 |
if (debug) |
2026 |
25 Sep 13 |
olle |
880 |
{ |
2026 |
25 Sep 13 |
olle |
881 |
PrintStream debugOut = new PrintStream(new File("data", "debugCenterColumnsForGroupsSeparately.txt")); |
2026 |
25 Sep 13 |
olle |
882 |
debugOut.println("Center::centerColumnsForGroupsSeparately(): param_centerGeneAssay = " + param_centerGeneAssay); |
2026 |
25 Sep 13 |
olle |
883 |
debugOut.println("Center::centerColumnsForGroupsSeparately(): param_centeringGroups = " + param_centeringGroups); |
2026 |
25 Sep 13 |
olle |
884 |
debugOut.println("Center::centerColumnsForGroupsSeparately(): param_centerGroupsAssayNames = \"" + param_centerGroupsAssayNames + "\""); |
2026 |
25 Sep 13 |
olle |
885 |
debugOut.println("Center::centerColumnsForGroupsSeparately(): param_centerCycles = " + param_centerCycles); |
2026 |
25 Sep 13 |
olle |
886 |
debugOut.println("Center::centerColumnsForGroupsSeparately(): param_mm = " + param_mm); |
2026 |
25 Sep 13 |
olle |
887 |
debugOut.println("Center::centerColumnsForGroupsSeparately(): singleCenterGroupAssayIndexList = " + singleCenterGroupAssayIndexList); |
2026 |
25 Sep 13 |
olle |
888 |
debugOut.println("Center::centerColumnsForGroupsSeparately(): centerGroupsAssayIndexHashMap = " + centerGroupsAssayIndexHashMap); |
2026 |
25 Sep 13 |
olle |
889 |
debugOut.println("Center::centerColumnsForGroupsSeparately(): nbrOfAssays = " + nbrOfAssays); |
2026 |
25 Sep 13 |
olle |
890 |
for (int i = 0; i < centerGroupsAssayIndexHashMap.size(); i++) |
2026 |
25 Sep 13 |
olle |
891 |
{ |
2026 |
25 Sep 13 |
olle |
892 |
debugOut.println("Center::centerColumnsForGroupsSeparately(): assay group = " + i + " nAssayRows = " + (Integer) nAssayRowList.get(i) + " r_fit = " + (Float) rFitList.get(i)); |
2026 |
25 Sep 13 |
olle |
893 |
} |
2026 |
25 Sep 13 |
olle |
894 |
debugOut.close(); |
2026 |
25 Sep 13 |
olle |
895 |
} |
2026 |
25 Sep 13 |
olle |
896 |
} |
2026 |
25 Sep 13 |
olle |
897 |
catch (Exception e) |
2026 |
25 Sep 13 |
olle |
898 |
{ |
2026 |
25 Sep 13 |
olle |
899 |
e.printStackTrace(); |
2026 |
25 Sep 13 |
olle |
900 |
} |
2026 |
25 Sep 13 |
olle |
901 |
} |
2026 |
25 Sep 13 |
olle |
902 |
|
149 |
10 Aug 06 |
enell |
903 |
private float median(List<Float> vec) |
149 |
10 Aug 06 |
enell |
904 |
{ |
2012 |
01 Aug 13 |
olle |
905 |
/* |
2012 |
01 Aug 13 |
olle |
// Old code |
149 |
10 Aug 06 |
enell |
float[] window = |
149 |
10 Aug 06 |
enell |
{ Float.NaN, Float.NaN, Float.NaN}; |
149 |
10 Aug 06 |
enell |
window[0] = vec.get(0); |
149 |
10 Aug 06 |
enell |
int j = 0; |
149 |
10 Aug 06 |
enell |
for (Float f : vec) |
149 |
10 Aug 06 |
enell |
912 |
{ |
149 |
10 Aug 06 |
enell |
window[++j] = f; |
149 |
10 Aug 06 |
enell |
914 |
|
149 |
10 Aug 06 |
enell |
if (j == 2) |
149 |
10 Aug 06 |
enell |
916 |
{ |
149 |
10 Aug 06 |
enell |
Arrays.sort(window); |
149 |
10 Aug 06 |
enell |
window[0] = window[1]; |
149 |
10 Aug 06 |
enell |
window[1] = Float.NaN; |
149 |
10 Aug 06 |
enell |
window[2] = Float.NaN; |
149 |
10 Aug 06 |
enell |
j = 0; |
149 |
10 Aug 06 |
enell |
922 |
} |
149 |
10 Aug 06 |
enell |
923 |
} |
149 |
10 Aug 06 |
enell |
if (j == 1) |
149 |
10 Aug 06 |
enell |
925 |
{ |
149 |
10 Aug 06 |
enell |
window[0] = (window[0] + window[1]) / 2f; |
149 |
10 Aug 06 |
enell |
927 |
} |
149 |
10 Aug 06 |
enell |
return window[0]; |
2012 |
01 Aug 13 |
olle |
929 |
*/ |
2012 |
01 Aug 13 |
olle |
930 |
return calculatePercentile(vec, 0.5f); |
149 |
10 Aug 06 |
enell |
931 |
} |
149 |
10 Aug 06 |
enell |
932 |
|
2012 |
01 Aug 13 |
olle |
933 |
/** |
2012 |
01 Aug 13 |
olle |
* Calculates percentile value for list with (Float) values. |
2012 |
01 Aug 13 |
olle |
* If the percentile corresponds exactly to an integer index, |
2012 |
01 Aug 13 |
olle |
* the list value for that index is returned, otherwise a |
2012 |
01 Aug 13 |
olle |
* weighted value of the list values of the two index values |
2012 |
01 Aug 13 |
olle |
* nearest to the desired percentile. |
2012 |
01 Aug 13 |
olle |
939 |
* |
2012 |
01 Aug 13 |
olle |
* Code adapted from Python function described in |
2012 |
01 Aug 13 |
olle |
* http://stackoverflow.com/questions/2374640/how-do-i-calculate-percentiles-with-python-numpy. |
2012 |
01 Aug 13 |
olle |
942 |
* |
2012 |
01 Aug 13 |
olle |
* @param vec List<Float> List with (Float) values to calculate percentile for. |
2012 |
01 Aug 13 |
olle |
* @param fraction float Fraction corresponding to desired percentile, e.g. median ~ 0.5, 95% percentile ~ 0.95. |
2012 |
01 Aug 13 |
olle |
* @return float The percentile value. |
2012 |
01 Aug 13 |
olle |
946 |
*/ |
2012 |
01 Aug 13 |
olle |
947 |
private float calculatePercentile(List<Float> vec, float fraction) |
2012 |
01 Aug 13 |
olle |
948 |
{ |
2026 |
25 Sep 13 |
olle |
949 |
if (vec == null || vec.size() == 0) |
2026 |
25 Sep 13 |
olle |
950 |
{ |
2026 |
25 Sep 13 |
olle |
951 |
return 0f; |
2026 |
25 Sep 13 |
olle |
952 |
} |
2012 |
01 Aug 13 |
olle |
953 |
Float percentileValue = null; |
2012 |
01 Aug 13 |
olle |
// Get ascending sorted list |
2012 |
01 Aug 13 |
olle |
955 |
List<Float> ascSortedList = new ArrayList<Float>(); |
2012 |
01 Aug 13 |
olle |
956 |
for (Float val: vec) |
2012 |
01 Aug 13 |
olle |
957 |
{ |
2012 |
01 Aug 13 |
olle |
958 |
ascSortedList.add(val); |
2012 |
01 Aug 13 |
olle |
959 |
} |
2012 |
01 Aug 13 |
olle |
960 |
Collections.sort(ascSortedList); |
2012 |
01 Aug 13 |
olle |
961 |
// |
2012 |
01 Aug 13 |
olle |
962 |
int len = ascSortedList.size(); |
2012 |
01 Aug 13 |
olle |
// List index values goes from 0 to (len - 1) |
2012 |
01 Aug 13 |
olle |
964 |
float indexVal = fraction*(len - 1); |
2012 |
01 Aug 13 |
olle |
965 |
float floorVal = Double.valueOf(Math.floor(indexVal)).floatValue(); |
2012 |
01 Aug 13 |
olle |
966 |
float ceilVal = Double.valueOf(Math.ceil(indexVal)).floatValue(); |
2012 |
01 Aug 13 |
olle |
967 |
if (floorVal == ceilVal) |
2012 |
01 Aug 13 |
olle |
968 |
{ |
2012 |
01 Aug 13 |
olle |
969 |
percentileValue = ascSortedList.get((int) indexVal); |
2012 |
01 Aug 13 |
olle |
970 |
} |
2012 |
01 Aug 13 |
olle |
971 |
else |
2012 |
01 Aug 13 |
olle |
972 |
{ |
2012 |
01 Aug 13 |
olle |
// Calculate percentile value as weighted value of two list values |
2012 |
01 Aug 13 |
olle |
974 |
float d0 = ascSortedList.get((int) floorVal) * (ceilVal - indexVal); |
2012 |
01 Aug 13 |
olle |
975 |
float d1 = ascSortedList.get((int) ceilVal) * (indexVal - floorVal); |
2012 |
01 Aug 13 |
olle |
976 |
percentileValue = d0 + d1; |
2012 |
01 Aug 13 |
olle |
977 |
} |
2012 |
01 Aug 13 |
olle |
978 |
return percentileValue.floatValue(); |
2012 |
01 Aug 13 |
olle |
979 |
} |
2012 |
01 Aug 13 |
olle |
980 |
|
149 |
10 Aug 06 |
enell |
981 |
private float mean(List<Float> vec) |
149 |
10 Aug 06 |
enell |
982 |
{ |
2026 |
25 Sep 13 |
olle |
983 |
if (vec == null || vec.size() == 0) |
2026 |
25 Sep 13 |
olle |
984 |
{ |
2026 |
25 Sep 13 |
olle |
985 |
return 0f; |
2026 |
25 Sep 13 |
olle |
986 |
} |
149 |
10 Aug 06 |
enell |
987 |
float ret = 0; |
149 |
10 Aug 06 |
enell |
988 |
for (int i = 0; i < vec.size(); i++) |
149 |
10 Aug 06 |
enell |
989 |
{ |
149 |
10 Aug 06 |
enell |
990 |
ret += vec.get(i); |
149 |
10 Aug 06 |
enell |
991 |
} |
149 |
10 Aug 06 |
enell |
992 |
return ret / vec.size(); |
149 |
10 Aug 06 |
enell |
993 |
} |
149 |
10 Aug 06 |
enell |
994 |
|
149 |
10 Aug 06 |
enell |
995 |
private enum CenterOn { |
149 |
10 Aug 06 |
enell |
996 |
|
149 |
10 Aug 06 |
enell |
997 |
MEDIAN(1), MEAN(2), ASSAY(3); |
149 |
10 Aug 06 |
enell |
998 |
|
149 |
10 Aug 06 |
enell |
999 |
private int value; |
149 |
10 Aug 06 |
enell |
1000 |
|
149 |
10 Aug 06 |
enell |
1001 |
private CenterOn(int value) |
149 |
10 Aug 06 |
enell |
1002 |
{ |
149 |
10 Aug 06 |
enell |
1003 |
this.value = value; |
149 |
10 Aug 06 |
enell |
1004 |
} |
149 |
10 Aug 06 |
enell |
1005 |
|
149 |
10 Aug 06 |
enell |
1006 |
private static final Map<Integer, CenterOn> valueMapping = new HashMap<Integer, CenterOn>(); |
149 |
10 Aug 06 |
enell |
1007 |
|
149 |
10 Aug 06 |
enell |
1008 |
static |
149 |
10 Aug 06 |
enell |
1009 |
{ |
149 |
10 Aug 06 |
enell |
1010 |
for (CenterOn centeron : CenterOn.values()) |
149 |
10 Aug 06 |
enell |
1011 |
{ |
149 |
10 Aug 06 |
enell |
1012 |
valueMapping.put(centeron.getValue(), centeron); |
149 |
10 Aug 06 |
enell |
1013 |
} |
149 |
10 Aug 06 |
enell |
1014 |
} |
149 |
10 Aug 06 |
enell |
1015 |
|
149 |
10 Aug 06 |
enell |
1016 |
public static CenterOn fromValue(int value) |
149 |
10 Aug 06 |
enell |
1017 |
{ |
149 |
10 Aug 06 |
enell |
1018 |
CenterOn centeron = valueMapping.get(value); |
149 |
10 Aug 06 |
enell |
1019 |
return centeron; |
149 |
10 Aug 06 |
enell |
1020 |
} |
149 |
10 Aug 06 |
enell |
1021 |
|
149 |
10 Aug 06 |
enell |
1022 |
public int getValue() |
149 |
10 Aug 06 |
enell |
1023 |
{ |
149 |
10 Aug 06 |
enell |
1024 |
return value; |
149 |
10 Aug 06 |
enell |
1025 |
} |
149 |
10 Aug 06 |
enell |
1026 |
} |
149 |
10 Aug 06 |
enell |
1027 |
|
149 |
10 Aug 06 |
enell |
1028 |
private enum GeneAssay { |
149 |
10 Aug 06 |
enell |
1029 |
BOTH(1), ASSAYS(2), GENES(3); |
149 |
10 Aug 06 |
enell |
1030 |
|
149 |
10 Aug 06 |
enell |
1031 |
private int value; |
149 |
10 Aug 06 |
enell |
1032 |
|
149 |
10 Aug 06 |
enell |
1033 |
private GeneAssay(int value) |
149 |
10 Aug 06 |
enell |
1034 |
{ |
149 |
10 Aug 06 |
enell |
1035 |
this.value = value; |
149 |
10 Aug 06 |
enell |
1036 |
} |
149 |
10 Aug 06 |
enell |
1037 |
|
149 |
10 Aug 06 |
enell |
1038 |
private static final Map<Integer, GeneAssay> valueMapping = new HashMap<Integer, GeneAssay>(); |
149 |
10 Aug 06 |
enell |
1039 |
|
149 |
10 Aug 06 |
enell |
1040 |
static |
149 |
10 Aug 06 |
enell |
1041 |
{ |
149 |
10 Aug 06 |
enell |
1042 |
for (GeneAssay geneAssay : GeneAssay.values()) |
149 |
10 Aug 06 |
enell |
1043 |
{ |
149 |
10 Aug 06 |
enell |
1044 |
valueMapping.put(geneAssay.getValue(), geneAssay); |
149 |
10 Aug 06 |
enell |
1045 |
} |
149 |
10 Aug 06 |
enell |
1046 |
} |
149 |
10 Aug 06 |
enell |
1047 |
|
149 |
10 Aug 06 |
enell |
1048 |
public static GeneAssay fromValue(int value) |
149 |
10 Aug 06 |
enell |
1049 |
{ |
149 |
10 Aug 06 |
enell |
1050 |
GeneAssay geneAssay = valueMapping.get(value); |
149 |
10 Aug 06 |
enell |
1051 |
return geneAssay; |
149 |
10 Aug 06 |
enell |
1052 |
} |
149 |
10 Aug 06 |
enell |
1053 |
|
149 |
10 Aug 06 |
enell |
1054 |
public int getValue() |
149 |
10 Aug 06 |
enell |
1055 |
{ |
149 |
10 Aug 06 |
enell |
1056 |
return value; |
149 |
10 Aug 06 |
enell |
1057 |
} |
149 |
10 Aug 06 |
enell |
1058 |
} |
149 |
10 Aug 06 |
enell |
1059 |
|
2026 |
25 Sep 13 |
olle |
1060 |
private enum CenteringGroups { |
2026 |
25 Sep 13 |
olle |
1061 |
DEFAULT(1), ASSAYGROUPSINGLE(2), ASSAYGROUPS(3); |
2026 |
25 Sep 13 |
olle |
1062 |
|
2026 |
25 Sep 13 |
olle |
1063 |
private int value; |
2026 |
25 Sep 13 |
olle |
1064 |
|
2026 |
25 Sep 13 |
olle |
1065 |
private CenteringGroups(int value) |
2026 |
25 Sep 13 |
olle |
1066 |
{ |
2026 |
25 Sep 13 |
olle |
1067 |
this.value = value; |
2026 |
25 Sep 13 |
olle |
1068 |
} |
2026 |
25 Sep 13 |
olle |
1069 |
|
2026 |
25 Sep 13 |
olle |
1070 |
private static final Map<Integer, CenteringGroups> valueMapping = new HashMap<Integer, CenteringGroups>(); |
2026 |
25 Sep 13 |
olle |
1071 |
|
2026 |
25 Sep 13 |
olle |
1072 |
static |
2026 |
25 Sep 13 |
olle |
1073 |
{ |
2026 |
25 Sep 13 |
olle |
1074 |
for (CenteringGroups centeringGroups : CenteringGroups.values()) |
2026 |
25 Sep 13 |
olle |
1075 |
{ |
2026 |
25 Sep 13 |
olle |
1076 |
valueMapping.put(centeringGroups.getValue(), centeringGroups); |
2026 |
25 Sep 13 |
olle |
1077 |
} |
2026 |
25 Sep 13 |
olle |
1078 |
} |
2026 |
25 Sep 13 |
olle |
1079 |
|
2026 |
25 Sep 13 |
olle |
1080 |
public static CenteringGroups fromValue(int value) |
2026 |
25 Sep 13 |
olle |
1081 |
{ |
2026 |
25 Sep 13 |
olle |
1082 |
CenteringGroups centeringGroups = valueMapping.get(value); |
2026 |
25 Sep 13 |
olle |
1083 |
return centeringGroups; |
2026 |
25 Sep 13 |
olle |
1084 |
} |
2026 |
25 Sep 13 |
olle |
1085 |
|
2026 |
25 Sep 13 |
olle |
1086 |
public int getValue() |
2026 |
25 Sep 13 |
olle |
1087 |
{ |
2026 |
25 Sep 13 |
olle |
1088 |
return value; |
2026 |
25 Sep 13 |
olle |
1089 |
} |
2026 |
25 Sep 13 |
olle |
1090 |
} |
2026 |
25 Sep 13 |
olle |
1091 |
|
875 |
05 Dec 08 |
jari |
1092 |
} |