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