116 |
26 Jun 06 |
enell |
1 |
/* |
116 |
26 Jun 06 |
enell |
$Id$ |
116 |
26 Jun 06 |
enell |
3 |
|
116 |
26 Jun 06 |
enell |
Copyright (C) 2006 Johan Enell |
116 |
26 Jun 06 |
enell |
5 |
|
116 |
26 Jun 06 |
enell |
This file is part of BASE - BioArray Software Environment. |
116 |
26 Jun 06 |
enell |
Available at http://base.thep.lu.se/ |
116 |
26 Jun 06 |
enell |
8 |
|
116 |
26 Jun 06 |
enell |
BASE is free software; you can redistribute it and/or modify it |
116 |
26 Jun 06 |
enell |
under the terms of the GNU General Public License as published by |
116 |
26 Jun 06 |
enell |
the Free Software Foundation; either version 2 of the License, or |
116 |
26 Jun 06 |
enell |
(at your option) any later version. |
116 |
26 Jun 06 |
enell |
13 |
|
116 |
26 Jun 06 |
enell |
BASE is distributed in the hope that it will be useful, but |
116 |
26 Jun 06 |
enell |
WITHOUT ANY WARRANTY; without even the implied warranty of |
116 |
26 Jun 06 |
enell |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
116 |
26 Jun 06 |
enell |
General Public License for more details. |
116 |
26 Jun 06 |
enell |
18 |
|
116 |
26 Jun 06 |
enell |
You should have received a copy of the GNU General Public License |
116 |
26 Jun 06 |
enell |
along with this program; if not, write to the Free Software |
116 |
26 Jun 06 |
enell |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
116 |
26 Jun 06 |
enell |
02111-1307, USA. |
116 |
26 Jun 06 |
enell |
23 |
*/ |
118 |
26 Jun 06 |
enell |
24 |
package base1null; |
116 |
26 Jun 06 |
enell |
25 |
|
251 |
10 Apr 07 |
enell |
26 |
import java.io.BufferedReader; |
116 |
26 Jun 06 |
enell |
27 |
import java.io.File; |
251 |
10 Apr 07 |
enell |
28 |
import java.io.FileReader; |
251 |
10 Apr 07 |
enell |
29 |
import java.io.IOException; |
251 |
10 Apr 07 |
enell |
30 |
import java.io.InputStreamReader; |
251 |
10 Apr 07 |
enell |
31 |
import java.io.PrintWriter; |
116 |
26 Jun 06 |
enell |
32 |
import java.util.List; |
116 |
26 Jun 06 |
enell |
33 |
|
116 |
26 Jun 06 |
enell |
34 |
import basefile.BASEFileException; |
116 |
26 Jun 06 |
enell |
35 |
import basefile.BASEFileReader; |
116 |
26 Jun 06 |
enell |
36 |
import basefile.BASEFileSection; |
116 |
26 Jun 06 |
enell |
37 |
import basefile.BASEFileSpotSection; |
116 |
26 Jun 06 |
enell |
38 |
|
116 |
26 Jun 06 |
enell |
39 |
public class Base1NullPlugin |
116 |
26 Jun 06 |
enell |
40 |
{ |
116 |
26 Jun 06 |
enell |
41 |
|
116 |
26 Jun 06 |
enell |
42 |
/** |
116 |
26 Jun 06 |
enell |
* @param args |
116 |
26 Jun 06 |
enell |
44 |
*/ |
116 |
26 Jun 06 |
enell |
45 |
public static void main(String[] args) |
116 |
26 Jun 06 |
enell |
46 |
throws Exception |
116 |
26 Jun 06 |
enell |
47 |
{ |
251 |
10 Apr 07 |
enell |
48 |
readStdin(); |
251 |
10 Apr 07 |
enell |
49 |
readFile(); |
251 |
10 Apr 07 |
enell |
50 |
|
116 |
26 Jun 06 |
enell |
51 |
BASEFileReader bfr; |
116 |
26 Jun 06 |
enell |
52 |
bfr = new BASEFileReader(new File("stdin.txt")); |
116 |
26 Jun 06 |
enell |
53 |
|
116 |
26 Jun 06 |
enell |
54 |
BASEFileSection bfs = bfr.readSection(true); |
116 |
26 Jun 06 |
enell |
55 |
if (!bfs.isType("settings")) |
116 |
26 Jun 06 |
enell |
56 |
{ |
116 |
26 Jun 06 |
enell |
57 |
throw new BASEFileException("Can't find section settings"); |
116 |
26 Jun 06 |
enell |
58 |
} |
116 |
26 Jun 06 |
enell |
59 |
|
116 |
26 Jun 06 |
enell |
60 |
System.out.println("BASEfile"); |
116 |
26 Jun 06 |
enell |
61 |
BASEFileSection bfas = bfr.readSection(false); |
116 |
26 Jun 06 |
enell |
62 |
|
116 |
26 Jun 06 |
enell |
63 |
BASEFileSpotSection<Reporter, Spot> bfss = bfr.readSpotSection(); |
251 |
10 Apr 07 |
enell |
64 |
bfss.setDataMatrix(bfss.getCount(), bfss.getAssays().size()); |
116 |
26 Jun 06 |
enell |
65 |
if (bfss != null) |
116 |
26 Jun 06 |
enell |
66 |
{ |
116 |
26 Jun 06 |
enell |
67 |
List<String> columns = bfss.findFieldList("columns"); |
116 |
26 Jun 06 |
enell |
68 |
List<String> assayFields = bfss.findFieldList("assayFields"); |
116 |
26 Jun 06 |
enell |
69 |
List<String> assays = bfss.findFieldList("assays"); |
116 |
26 Jun 06 |
enell |
70 |
|
116 |
26 Jun 06 |
enell |
71 |
bfas.setHeader("annotationColumns", ""); |
122 |
29 Jun 06 |
enell |
72 |
bfas.setHeader("columns", "id", "name", "parents"); |
116 |
26 Jun 06 |
enell |
73 |
System.out.println(bfas); |
116 |
26 Jun 06 |
enell |
74 |
System.out.println("1\tintensity\t"+assays.get(0)); |
116 |
26 Jun 06 |
enell |
75 |
System.out.println("2\tMA\t"+assays.get(0)); |
116 |
26 Jun 06 |
enell |
76 |
System.out.println(); |
116 |
26 Jun 06 |
enell |
77 |
|
116 |
26 Jun 06 |
enell |
78 |
int posCol = columns.indexOf("position"); |
116 |
26 Jun 06 |
enell |
79 |
int dataCol = columns.indexOf("assayData"); |
116 |
26 Jun 06 |
enell |
80 |
int repCol = columns.indexOf("reporter"); |
116 |
26 Jun 06 |
enell |
81 |
int int1Col = assayFields.indexOf("intensity1") + dataCol; |
116 |
26 Jun 06 |
enell |
82 |
int int2Col = assayFields.indexOf("intensity2") + dataCol; |
116 |
26 Jun 06 |
enell |
83 |
|
119 |
29 Jun 06 |
enell |
84 |
String[] data = bfr.readDataRow(); |
116 |
26 Jun 06 |
enell |
85 |
while (data != null) |
116 |
26 Jun 06 |
enell |
86 |
{ |
121 |
29 Jun 06 |
enell |
87 |
Integer reporter = data[repCol].equals("") ? null : Integer.parseInt(data[repCol]); |
121 |
29 Jun 06 |
enell |
88 |
Reporter r = new Reporter(Integer.parseInt(data[posCol]), reporter); |
116 |
26 Jun 06 |
enell |
89 |
Spot s = new Spot(Float.parseFloat(data[int1Col]), Float.parseFloat(data[int2Col])); |
116 |
26 Jun 06 |
enell |
90 |
bfss.addData(r, s); |
116 |
26 Jun 06 |
enell |
91 |
|
116 |
26 Jun 06 |
enell |
92 |
data = bfr.readDataRow(); |
116 |
26 Jun 06 |
enell |
93 |
} |
116 |
26 Jun 06 |
enell |
94 |
|
116 |
26 Jun 06 |
enell |
95 |
bfss.setHeader("assays", 1); |
116 |
26 Jun 06 |
enell |
96 |
bfss.setHeader("columns", "position", "reporter", "assayData"); |
116 |
26 Jun 06 |
enell |
97 |
bfss.setHeader("assayFields", "intensity1", "intensity2"); |
116 |
26 Jun 06 |
enell |
98 |
System.out.println(bfss); |
121 |
29 Jun 06 |
enell |
99 |
for (int i = 0; i < bfss.getSpotSize(); i++) |
116 |
26 Jun 06 |
enell |
100 |
{ |
116 |
26 Jun 06 |
enell |
101 |
System.out.println(bfss.getReporter(i) + "\t" + bfss.getSpot(i).getInt1() + "\t" + bfss.getSpot(i).getInt2()); |
116 |
26 Jun 06 |
enell |
102 |
} |
116 |
26 Jun 06 |
enell |
103 |
System.out.println(); |
116 |
26 Jun 06 |
enell |
104 |
|
116 |
26 Jun 06 |
enell |
105 |
bfss.setHeader("assays", 2); |
116 |
26 Jun 06 |
enell |
106 |
bfss.setHeader("assayFields", "l2ratio1_2", "l10intgmean1_2"); |
116 |
26 Jun 06 |
enell |
107 |
System.out.println(bfss); |
116 |
26 Jun 06 |
enell |
108 |
for (int i = 0; i < bfss.getHeight(); i++) |
116 |
26 Jun 06 |
enell |
109 |
{ |
116 |
26 Jun 06 |
enell |
110 |
System.out.println(bfss.getReporter(i) + "\t" + bfss.getSpot(i).getM() + "\t" + bfss.getSpot(i).getA()); |
116 |
26 Jun 06 |
enell |
111 |
} |
116 |
26 Jun 06 |
enell |
112 |
System.out.println(); |
116 |
26 Jun 06 |
enell |
113 |
} |
116 |
26 Jun 06 |
enell |
114 |
} |
116 |
26 Jun 06 |
enell |
115 |
|
251 |
10 Apr 07 |
enell |
116 |
private static void readFile() throws IOException |
251 |
10 Apr 07 |
enell |
117 |
{ |
251 |
10 Apr 07 |
enell |
118 |
PrintWriter out = new PrintWriter("readStdinFile.txt"); |
251 |
10 Apr 07 |
enell |
119 |
BufferedReader in = new BufferedReader(new FileReader("stdin.txt")); |
251 |
10 Apr 07 |
enell |
120 |
|
251 |
10 Apr 07 |
enell |
121 |
for (int i = 0; i < 100; i++) |
251 |
10 Apr 07 |
enell |
122 |
{ |
251 |
10 Apr 07 |
enell |
123 |
out.printf("%4d:%s%n",i, in.readLine()); |
251 |
10 Apr 07 |
enell |
124 |
} |
251 |
10 Apr 07 |
enell |
125 |
|
251 |
10 Apr 07 |
enell |
126 |
out.close(); |
251 |
10 Apr 07 |
enell |
127 |
} |
251 |
10 Apr 07 |
enell |
128 |
|
251 |
10 Apr 07 |
enell |
129 |
private static void readStdin() throws IOException |
251 |
10 Apr 07 |
enell |
130 |
{ |
251 |
10 Apr 07 |
enell |
131 |
PrintWriter out = new PrintWriter("readStdinStream.txt"); |
251 |
10 Apr 07 |
enell |
132 |
BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); |
251 |
10 Apr 07 |
enell |
133 |
|
251 |
10 Apr 07 |
enell |
134 |
for (int i = 0; i < 100; i++) |
251 |
10 Apr 07 |
enell |
135 |
{ |
251 |
10 Apr 07 |
enell |
136 |
out.printf("%4d:%s%n",i, in.readLine()); |
251 |
10 Apr 07 |
enell |
137 |
} |
251 |
10 Apr 07 |
enell |
138 |
|
251 |
10 Apr 07 |
enell |
139 |
out.close(); |
251 |
10 Apr 07 |
enell |
140 |
} |
251 |
10 Apr 07 |
enell |
141 |
|
116 |
26 Jun 06 |
enell |
142 |
} |