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.mergers; |
149 |
10 Aug 06 |
enell |
25 |
|
149 |
10 Aug 06 |
enell |
26 |
import mergebioassay.BioAssay; |
149 |
10 Aug 06 |
enell |
27 |
|
149 |
10 Aug 06 |
enell |
28 |
import java.io.IOException; |
149 |
10 Aug 06 |
enell |
29 |
import java.util.HashMap; |
149 |
10 Aug 06 |
enell |
30 |
import java.util.Iterator; |
149 |
10 Aug 06 |
enell |
31 |
import java.util.List; |
149 |
10 Aug 06 |
enell |
32 |
|
663 |
16 Apr 08 |
jari |
33 |
import basefile.BASEFileException; |
149 |
10 Aug 06 |
enell |
34 |
import basefile.BASEFileReader; |
149 |
10 Aug 06 |
enell |
35 |
import basefile.BASEFileSection; |
149 |
10 Aug 06 |
enell |
36 |
import basefile.BadSectionException; |
149 |
10 Aug 06 |
enell |
37 |
|
149 |
10 Aug 06 |
enell |
38 |
/** |
149 |
10 Aug 06 |
enell |
* @author Johan Enell |
149 |
10 Aug 06 |
enell |
40 |
* |
149 |
10 Aug 06 |
enell |
* The ArithmeticIntensityMerger implements the abstract merger class. It will |
149 |
10 Aug 06 |
enell |
* use the arithmetic mean of the intensities. |
149 |
10 Aug 06 |
enell |
43 |
*/ |
149 |
10 Aug 06 |
enell |
44 |
public class ArithmeticIntensityMerger extends Merger |
149 |
10 Aug 06 |
enell |
45 |
{ |
149 |
10 Aug 06 |
enell |
46 |
|
149 |
10 Aug 06 |
enell |
47 |
/* |
149 |
10 Aug 06 |
enell |
* (non-Javadoc) |
149 |
10 Aug 06 |
enell |
49 |
* |
149 |
10 Aug 06 |
enell |
* @see mergers.Merger#merge(baseFile.BASEFileSection, |
149 |
10 Aug 06 |
enell |
* baseFile.BASEFileReader, java.util.HashMap) |
149 |
10 Aug 06 |
enell |
52 |
*/ |
149 |
10 Aug 06 |
enell |
53 |
@Override |
149 |
10 Aug 06 |
enell |
54 |
public void merge(BASEFileSection section, BASEFileReader reader, HashMap<String, List<Merge_assay>> assayGroups) |
149 |
10 Aug 06 |
enell |
55 |
{ |
149 |
10 Aug 06 |
enell |
56 |
int intensity1Pos = -1; |
149 |
10 Aug 06 |
enell |
57 |
int intensity2Pos = -1; |
149 |
10 Aug 06 |
enell |
58 |
|
149 |
10 Aug 06 |
enell |
59 |
super.init(section, reader); |
149 |
10 Aug 06 |
enell |
60 |
|
149 |
10 Aug 06 |
enell |
61 |
intensity1Pos = assayFieldsMap.indexOf("intensity1"); |
149 |
10 Aug 06 |
enell |
62 |
if (intensity1Pos == -1) |
149 |
10 Aug 06 |
enell |
63 |
{ |
149 |
10 Aug 06 |
enell |
64 |
System.err.print("intensity1 field in assayFields row missing\n"); |
149 |
10 Aug 06 |
enell |
65 |
System.exit(0); |
149 |
10 Aug 06 |
enell |
66 |
} |
149 |
10 Aug 06 |
enell |
67 |
|
149 |
10 Aug 06 |
enell |
68 |
intensity2Pos = assayFieldsMap.indexOf("intensity2"); |
149 |
10 Aug 06 |
enell |
69 |
if (intensity2Pos == -1) |
149 |
10 Aug 06 |
enell |
70 |
{ |
149 |
10 Aug 06 |
enell |
71 |
System.err.print("intensity2 field in assayFields row missing\n"); |
149 |
10 Aug 06 |
enell |
72 |
System.exit(0); |
149 |
10 Aug 06 |
enell |
73 |
} |
149 |
10 Aug 06 |
enell |
74 |
|
149 |
10 Aug 06 |
enell |
75 |
try |
149 |
10 Aug 06 |
enell |
76 |
{ |
149 |
10 Aug 06 |
enell |
77 |
|
149 |
10 Aug 06 |
enell |
78 |
System.out.print("section\tspots\n"); |
149 |
10 Aug 06 |
enell |
79 |
System.out.print("columns\tposition\treporter\tassayData\n"); |
149 |
10 Aug 06 |
enell |
80 |
System.out.print("assayFields\tintensity1\tintensity2\tJE_nbrOfElements\n"); |
149 |
10 Aug 06 |
enell |
81 |
System.out.print("setExtraFloats\tJE_nbrOfElements\n"); |
149 |
10 Aug 06 |
enell |
82 |
System.out.print("assays"); |
149 |
10 Aug 06 |
enell |
83 |
for (int i = 0; i < assayGroups.size(); i++) |
149 |
10 Aug 06 |
enell |
84 |
System.out.print("\t" + (i + 1)); |
149 |
10 Aug 06 |
enell |
85 |
System.out.print("\n%\n"); |
149 |
10 Aug 06 |
enell |
86 |
String[] row = reader.readDataRow(nbrOfColumns); |
149 |
10 Aug 06 |
enell |
87 |
|
149 |
10 Aug 06 |
enell |
88 |
Iterator it = assayGroups.keySet().iterator(); |
149 |
10 Aug 06 |
enell |
89 |
String key; |
149 |
10 Aug 06 |
enell |
90 |
while (row != null) |
149 |
10 Aug 06 |
enell |
91 |
{ |
149 |
10 Aug 06 |
enell |
92 |
System.out.print(row[positionPos] + "\t" + row[reporterPos]); |
149 |
10 Aug 06 |
enell |
93 |
|
149 |
10 Aug 06 |
enell |
94 |
it = assayGroups.keySet().iterator(); |
149 |
10 Aug 06 |
enell |
95 |
while (it.hasNext()) |
149 |
10 Aug 06 |
enell |
96 |
{ |
149 |
10 Aug 06 |
enell |
97 |
key = (String) it.next(); |
149 |
10 Aug 06 |
enell |
98 |
List<Merge_assay> micro = assayGroups.get(key); |
149 |
10 Aug 06 |
enell |
99 |
double int1 = 0, int2 = 0; |
149 |
10 Aug 06 |
enell |
100 |
DoubleVector intVector1 = new DoubleVector(); |
149 |
10 Aug 06 |
enell |
101 |
DoubleVector intVector2 = new DoubleVector(); |
149 |
10 Aug 06 |
enell |
102 |
for (int i = 0; i < micro.size(); i++) |
149 |
10 Aug 06 |
enell |
103 |
{ |
149 |
10 Aug 06 |
enell |
104 |
BioAssay tmp = micro.get(i); |
149 |
10 Aug 06 |
enell |
105 |
int assay = assaysMap.indexOf(tmp.id); |
149 |
10 Aug 06 |
enell |
106 |
try |
149 |
10 Aug 06 |
enell |
107 |
{ |
149 |
10 Aug 06 |
enell |
108 |
int1 = Double.parseDouble(row[assayDataPos + intensity1Pos + assay * assayFieldsMap.size()]); |
149 |
10 Aug 06 |
enell |
109 |
int2 = Double.parseDouble(row[assayDataPos + intensity2Pos + assay * assayFieldsMap.size()]); |
149 |
10 Aug 06 |
enell |
110 |
|
149 |
10 Aug 06 |
enell |
111 |
intVector1.add(int1); |
149 |
10 Aug 06 |
enell |
112 |
intVector2.add(int2); |
149 |
10 Aug 06 |
enell |
113 |
} |
149 |
10 Aug 06 |
enell |
114 |
catch (NumberFormatException nfe) |
149 |
10 Aug 06 |
enell |
115 |
{ |
149 |
10 Aug 06 |
enell |
116 |
missingValues++; |
149 |
10 Aug 06 |
enell |
117 |
} |
149 |
10 Aug 06 |
enell |
118 |
} |
149 |
10 Aug 06 |
enell |
119 |
|
149 |
10 Aug 06 |
enell |
120 |
System.out.print("\t"); |
149 |
10 Aug 06 |
enell |
121 |
if (intVector1.size() > 0) |
149 |
10 Aug 06 |
enell |
122 |
{ |
149 |
10 Aug 06 |
enell |
123 |
System.out.print((float) arithmeticMean(intVector1.toArray())); |
149 |
10 Aug 06 |
enell |
124 |
System.out.print("\t"); |
149 |
10 Aug 06 |
enell |
125 |
System.out.print((float) arithmeticMean(intVector2.toArray())); |
149 |
10 Aug 06 |
enell |
126 |
} |
149 |
10 Aug 06 |
enell |
127 |
else System.out.print("\t"); |
149 |
10 Aug 06 |
enell |
128 |
if (intVector1.size() > 0) System.out.print("\t" + intVector1.size()); |
149 |
10 Aug 06 |
enell |
129 |
else System.out.print("\t"); |
149 |
10 Aug 06 |
enell |
130 |
} |
149 |
10 Aug 06 |
enell |
131 |
System.out.print("\n"); |
149 |
10 Aug 06 |
enell |
132 |
row = reader.readDataRow(nbrOfColumns); |
149 |
10 Aug 06 |
enell |
133 |
} |
149 |
10 Aug 06 |
enell |
134 |
System.out.print("\n"); |
149 |
10 Aug 06 |
enell |
135 |
} |
149 |
10 Aug 06 |
enell |
136 |
catch (BadSectionException e) |
149 |
10 Aug 06 |
enell |
137 |
{ |
149 |
10 Aug 06 |
enell |
138 |
e.printStackTrace(); |
149 |
10 Aug 06 |
enell |
139 |
} |
663 |
16 Apr 08 |
jari |
140 |
catch (BASEFileException e) |
149 |
10 Aug 06 |
enell |
141 |
{ |
149 |
10 Aug 06 |
enell |
142 |
e.printStackTrace(); |
149 |
10 Aug 06 |
enell |
143 |
System.exit(0); |
149 |
10 Aug 06 |
enell |
144 |
} |
149 |
10 Aug 06 |
enell |
145 |
} |
149 |
10 Aug 06 |
enell |
146 |
} |