103 |
01 Jun 06 |
enell |
1 |
/* |
105 |
02 Jun 06 |
enell |
$Id$ |
103 |
01 Jun 06 |
enell |
3 |
|
105 |
02 Jun 06 |
enell |
Copyright (C) 2006 Johan Enell |
103 |
01 Jun 06 |
enell |
5 |
|
105 |
02 Jun 06 |
enell |
This file is part of BASE - BioArray Software Environment. |
105 |
02 Jun 06 |
enell |
Available at http://base.thep.lu.se/ |
103 |
01 Jun 06 |
enell |
8 |
|
105 |
02 Jun 06 |
enell |
BASE is free software; you can redistribute it and/or modify it |
105 |
02 Jun 06 |
enell |
under the terms of the GNU General Public License as published by |
105 |
02 Jun 06 |
enell |
the Free Software Foundation; either version 2 of the License, or |
105 |
02 Jun 06 |
enell |
(at your option) any later version. |
103 |
01 Jun 06 |
enell |
13 |
|
105 |
02 Jun 06 |
enell |
BASE is distributed in the hope that it will be useful, but |
105 |
02 Jun 06 |
enell |
WITHOUT ANY WARRANTY; without even the implied warranty of |
105 |
02 Jun 06 |
enell |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
105 |
02 Jun 06 |
enell |
General Public License for more details. |
103 |
01 Jun 06 |
enell |
18 |
|
105 |
02 Jun 06 |
enell |
You should have received a copy of the GNU General Public License |
105 |
02 Jun 06 |
enell |
along with this program; if not, write to the Free Software |
105 |
02 Jun 06 |
enell |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
105 |
02 Jun 06 |
enell |
02111-1307, USA. |
105 |
02 Jun 06 |
enell |
23 |
*/ |
103 |
01 Jun 06 |
enell |
24 |
package medianratio; |
103 |
01 Jun 06 |
enell |
25 |
|
103 |
01 Jun 06 |
enell |
26 |
import java.io.File; |
103 |
01 Jun 06 |
enell |
27 |
import java.io.IOException; |
103 |
01 Jun 06 |
enell |
28 |
import java.util.List; |
103 |
01 Jun 06 |
enell |
29 |
|
103 |
01 Jun 06 |
enell |
30 |
import basefile.BASEFileException; |
103 |
01 Jun 06 |
enell |
31 |
import basefile.BASEFileReader; |
103 |
01 Jun 06 |
enell |
32 |
import basefile.BASEFileSection; |
103 |
01 Jun 06 |
enell |
33 |
import basefile.BASEFileSpotSection; |
103 |
01 Jun 06 |
enell |
34 |
|
103 |
01 Jun 06 |
enell |
35 |
/** |
103 |
01 Jun 06 |
enell |
36 |
* |
103 |
01 Jun 06 |
enell |
* @author Johan Enell, johan.enell@onk.lu.se, Dept Oncology, Lund University, S-221 85 Lund, Sweden |
103 |
01 Jun 06 |
enell |
38 |
*/ |
103 |
01 Jun 06 |
enell |
39 |
public class MedianRatio |
103 |
01 Jun 06 |
enell |
40 |
{ |
103 |
01 Jun 06 |
enell |
41 |
|
103 |
01 Jun 06 |
enell |
42 |
/** |
103 |
01 Jun 06 |
enell |
* @param args |
103 |
01 Jun 06 |
enell |
* @throws IOException |
103 |
01 Jun 06 |
enell |
* @throws BASEFileException |
103 |
01 Jun 06 |
enell |
46 |
*/ |
105 |
02 Jun 06 |
enell |
47 |
public static void main(String[] args) |
105 |
02 Jun 06 |
enell |
48 |
throws IOException, BASEFileException |
103 |
01 Jun 06 |
enell |
49 |
{ |
105 |
02 Jun 06 |
enell |
50 |
BASEFileReader bfr = new BASEFileReader(new File("stdin.txt")); |
103 |
01 Jun 06 |
enell |
51 |
BASEFileSection bfs = bfr.readSection(true); |
103 |
01 Jun 06 |
enell |
52 |
if (!bfs.isType("settings")) |
103 |
01 Jun 06 |
enell |
53 |
{ |
103 |
01 Jun 06 |
enell |
54 |
throw new BASEFileException("Can't find section settings"); |
103 |
01 Jun 06 |
enell |
55 |
} |
103 |
01 Jun 06 |
enell |
56 |
|
105 |
02 Jun 06 |
enell |
57 |
Float median; |
105 |
02 Jun 06 |
enell |
58 |
if (bfs.findStringOpt("median").equals("none")) |
105 |
02 Jun 06 |
enell |
59 |
{ |
105 |
02 Jun 06 |
enell |
60 |
median = null; |
105 |
02 Jun 06 |
enell |
61 |
} |
105 |
02 Jun 06 |
enell |
62 |
else |
105 |
02 Jun 06 |
enell |
63 |
{ |
105 |
02 Jun 06 |
enell |
64 |
try |
105 |
02 Jun 06 |
enell |
65 |
{ |
105 |
02 Jun 06 |
enell |
66 |
median = bfs.findFloatOpt("median"); |
105 |
02 Jun 06 |
enell |
67 |
} |
105 |
02 Jun 06 |
enell |
68 |
catch (NumberFormatException e) |
105 |
02 Jun 06 |
enell |
69 |
{ |
105 |
02 Jun 06 |
enell |
70 |
throw new BASEFileException("Median must be 'none' or a number."); |
105 |
02 Jun 06 |
enell |
71 |
} |
105 |
02 Jun 06 |
enell |
72 |
} |
105 |
02 Jun 06 |
enell |
73 |
|
105 |
02 Jun 06 |
enell |
74 |
Normalizer norm = new Normalizer(bfs.findFloatOpt("low_exclude"), bfs.findFloatOpt("high_exclude"), bfs.findFloatOpt("min_I"), |
105 |
02 Jun 06 |
enell |
75 |
bfs.findIntOpt("blockGroup"), median); |
104 |
01 Jun 06 |
enell |
76 |
System.out.println("BASEFile"); |
103 |
01 Jun 06 |
enell |
77 |
BASEFileSpotSection<Reporter, Spot> bfss = bfr.readSpotSection(); |
103 |
01 Jun 06 |
enell |
78 |
while (bfss != null) |
103 |
01 Jun 06 |
enell |
79 |
{ |
103 |
01 Jun 06 |
enell |
80 |
List<String> columns = bfss.findFieldList("columns"); |
103 |
01 Jun 06 |
enell |
81 |
List<String> assayFields = bfss.findFieldList("assayFields"); |
105 |
02 Jun 06 |
enell |
82 |
|
103 |
01 Jun 06 |
enell |
83 |
int posCol = columns.indexOf("position"); |
103 |
01 Jun 06 |
enell |
84 |
int dataCol = columns.indexOf("assayData"); |
103 |
01 Jun 06 |
enell |
85 |
int repCol = columns.indexOf("reporter"); |
103 |
01 Jun 06 |
enell |
86 |
int i1Col = assayFields.indexOf("intensity1") + dataCol; |
103 |
01 Jun 06 |
enell |
87 |
int i2Col = assayFields.indexOf("intensity2") + dataCol; |
104 |
01 Jun 06 |
enell |
88 |
int blockCol = assayFields.indexOf("block") + dataCol; |
105 |
02 Jun 06 |
enell |
89 |
|
103 |
01 Jun 06 |
enell |
90 |
bfss.setDataMatrix(bfss.findIntOpt("count"), 1); |
105 |
02 Jun 06 |
enell |
91 |
|
103 |
01 Jun 06 |
enell |
92 |
String[] data = bfr.readDataRow(5); |
103 |
01 Jun 06 |
enell |
93 |
while (data != null) |
103 |
01 Jun 06 |
enell |
94 |
{ |
103 |
01 Jun 06 |
enell |
95 |
Spot s; |
103 |
01 Jun 06 |
enell |
96 |
if (blockCol == -1) |
103 |
01 Jun 06 |
enell |
97 |
{ |
103 |
01 Jun 06 |
enell |
98 |
s = new Spot(Float.parseFloat(data[i1Col]), Float.parseFloat(data[i2Col])); |
103 |
01 Jun 06 |
enell |
99 |
} |
103 |
01 Jun 06 |
enell |
100 |
else |
103 |
01 Jun 06 |
enell |
101 |
{ |
103 |
01 Jun 06 |
enell |
102 |
s = new Spot(Float.parseFloat(data[i1Col]), Float.parseFloat(data[i2Col]), Integer.parseInt(data[blockCol])); |
103 |
01 Jun 06 |
enell |
103 |
} |
103 |
01 Jun 06 |
enell |
104 |
Reporter r = new Reporter(Integer.parseInt(data[posCol]), Integer.parseInt(data[repCol])); |
103 |
01 Jun 06 |
enell |
105 |
bfss.addData(r, s); |
105 |
02 Jun 06 |
enell |
106 |
|
103 |
01 Jun 06 |
enell |
107 |
data = bfr.readDataRow(5); |
103 |
01 Jun 06 |
enell |
108 |
} |
103 |
01 Jun 06 |
enell |
109 |
norm.normalize(bfss); |
105 |
02 Jun 06 |
enell |
110 |
|
104 |
01 Jun 06 |
enell |
111 |
bfss.setHeader("assayFields", "intensity1", "intensity2"); |
104 |
01 Jun 06 |
enell |
112 |
System.out.println(bfss); |
104 |
01 Jun 06 |
enell |
113 |
for (int i = 0; i < bfss.getHeight(); i++) |
104 |
01 Jun 06 |
enell |
114 |
{ |
104 |
01 Jun 06 |
enell |
115 |
System.out.println(bfss.getReporter(i) + "\t" + bfss.getSpot(i)); |
104 |
01 Jun 06 |
enell |
116 |
} |
104 |
01 Jun 06 |
enell |
117 |
System.out.println(); |
103 |
01 Jun 06 |
enell |
118 |
bfss = bfr.readSpotSection(); |
103 |
01 Jun 06 |
enell |
119 |
} |
103 |
01 Jun 06 |
enell |
120 |
} |
103 |
01 Jun 06 |
enell |
121 |
} |