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