1121 |
24 Aug 05 |
nicklas |
1 |
/* |
1121 |
24 Aug 05 |
nicklas |
$Id$ |
1121 |
24 Aug 05 |
nicklas |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Johan Enell, Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Johan Enell, Jari Häkkinen, Nicklas Nordborg |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2007 Nicklas Nordborg |
1121 |
24 Aug 05 |
nicklas |
7 |
|
2304 |
22 May 06 |
jari |
This file is part of BASE - BioArray Software Environment. |
2304 |
22 May 06 |
jari |
Available at http://base.thep.lu.se/ |
1121 |
24 Aug 05 |
nicklas |
10 |
|
1121 |
24 Aug 05 |
nicklas |
BASE is free software; you can redistribute it and/or |
1121 |
24 Aug 05 |
nicklas |
modify it under the terms of the GNU General Public License |
4480 |
05 Sep 08 |
jari |
as published by the Free Software Foundation; either version 3 |
1121 |
24 Aug 05 |
nicklas |
of the License, or (at your option) any later version. |
1121 |
24 Aug 05 |
nicklas |
15 |
|
1121 |
24 Aug 05 |
nicklas |
BASE is distributed in the hope that it will be useful, |
1121 |
24 Aug 05 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1121 |
24 Aug 05 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1121 |
24 Aug 05 |
nicklas |
GNU General Public License for more details. |
1121 |
24 Aug 05 |
nicklas |
20 |
|
1121 |
24 Aug 05 |
nicklas |
You should have received a copy of the GNU General Public License |
4514 |
11 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
1121 |
24 Aug 05 |
nicklas |
23 |
*/ |
1121 |
24 Aug 05 |
nicklas |
24 |
import net.sf.basedb.core.*; |
1124 |
24 Aug 05 |
nicklas |
25 |
import net.sf.basedb.core.data.RawData; |
7151 |
04 May 16 |
nicklas |
26 |
import net.sf.basedb.core.query.Dynamic; |
5026 |
28 Jul 09 |
nicklas |
27 |
import net.sf.basedb.core.query.Hql; |
7151 |
04 May 16 |
nicklas |
28 |
import net.sf.basedb.core.query.JoinType; |
7151 |
04 May 16 |
nicklas |
29 |
import net.sf.basedb.core.query.Orders; |
7151 |
04 May 16 |
nicklas |
30 |
import net.sf.basedb.core.query.SqlResult; |
5026 |
28 Jul 09 |
nicklas |
31 |
import net.sf.basedb.util.ConsoleProgressReporter; |
1139 |
26 Aug 05 |
nicklas |
32 |
import net.sf.basedb.util.FileUtil; |
2203 |
28 Apr 06 |
nicklas |
33 |
import net.sf.basedb.util.parser.FlatFileParser; |
2203 |
28 Apr 06 |
nicklas |
34 |
|
7151 |
04 May 16 |
nicklas |
35 |
import java.sql.SQLException; |
4426 |
29 Aug 08 |
nicklas |
36 |
import java.util.ArrayList; |
7151 |
04 May 16 |
nicklas |
37 |
import java.util.Arrays; |
1121 |
24 Aug 05 |
nicklas |
38 |
import java.util.Date; |
1121 |
24 Aug 05 |
nicklas |
39 |
import java.util.List; |
1134 |
25 Aug 05 |
nicklas |
40 |
import java.util.Map; |
5340 |
10 May 10 |
nicklas |
41 |
import java.util.Set; |
1139 |
26 Aug 05 |
nicklas |
42 |
import java.util.regex.Pattern; |
1121 |
24 Aug 05 |
nicklas |
43 |
|
1121 |
24 Aug 05 |
nicklas |
44 |
public class TestRawBioAssay |
1121 |
24 Aug 05 |
nicklas |
45 |
{ |
1121 |
24 Aug 05 |
nicklas |
46 |
|
1121 |
24 Aug 05 |
nicklas |
47 |
static boolean ok = true; |
1121 |
24 Aug 05 |
nicklas |
48 |
public static void main(String[] args) |
1121 |
24 Aug 05 |
nicklas |
49 |
{ |
1121 |
24 Aug 05 |
nicklas |
50 |
TestUtil.checkArgs(args); |
1121 |
24 Aug 05 |
nicklas |
51 |
TestUtil.begin(); |
1121 |
24 Aug 05 |
nicklas |
52 |
ok = test_all(); |
1121 |
24 Aug 05 |
nicklas |
53 |
TestUtil.stop(); |
1121 |
24 Aug 05 |
nicklas |
54 |
} |
1121 |
24 Aug 05 |
nicklas |
55 |
|
1121 |
24 Aug 05 |
nicklas |
56 |
static boolean test_all() |
1121 |
24 Aug 05 |
nicklas |
57 |
{ |
1121 |
24 Aug 05 |
nicklas |
58 |
write("++Testing raw bioassays"); |
1121 |
24 Aug 05 |
nicklas |
59 |
write_header(); |
1121 |
24 Aug 05 |
nicklas |
60 |
|
5653 |
13 Jun 11 |
nicklas |
61 |
int hybridizationId = TestPhysicalBioAssay.test_create(0, "Test hyb", 0, 1); |
5685 |
04 Aug 11 |
nicklas |
62 |
int bioAssaySetId = TestDerivedBioAssay.test_create_root("Scan", hybridizationId, |
6100 |
04 Sep 12 |
nicklas |
63 |
SystemItems.getId(DerivedBioAssay.SCAN), 0, 0, 0, 0); |
3820 |
12 Oct 07 |
nicklas |
64 |
int arrayDesignId = TestArrayDesign.test_create(Platform.GENERIC, false); |
5026 |
28 Jul 09 |
nicklas |
65 |
int arrayDesignId2 = TestArrayDesign.test_create(Platform.GENERIC, false); |
5026 |
28 Jul 09 |
nicklas |
66 |
|
2959 |
27 Nov 06 |
nicklas |
67 |
TestReporter.test_import_from_file("data/test.rawdata.import.txt", |
3626 |
03 Aug 07 |
nicklas |
68 |
"\"Block\"\\t\"Column\"\\t\"Row\"\\t\"Name\"\\t\"ID\".*", "\\t", 4, 3); |
2959 |
27 Nov 06 |
nicklas |
69 |
TestArrayDesign.test_import_from_file(arrayDesignId, "data/test.rawdata.import.txt", |
4246 |
24 Apr 08 |
nicklas |
70 |
"\"Block\"\\t\"Column\"\\t\"Row\"\\t\"Name\"\\t\"ID\".*", null, 0, 2, 1, 4); |
5026 |
28 Jul 09 |
nicklas |
71 |
TestArrayDesign.test_import_from_file(arrayDesignId2, "data/test.rawdata.import.txt", |
5026 |
28 Jul 09 |
nicklas |
72 |
"\"Block\"\\t\"Column\"\\t\"Row\"\\t\"Name\"\\t\"ID\".*", null, 0, 2, 1, 4); |
5026 |
28 Jul 09 |
nicklas |
73 |
|
5630 |
13 May 11 |
nicklas |
74 |
int softwareId = TestSoftware.test_create(SystemItems.getId(Software.FEATURE_EXTRACTION), null, false); |
5630 |
13 May 11 |
nicklas |
75 |
int protocolId = TestProtocol.test_create(SystemItems.getId(Protocol.FEATURE_EXTRACTION), null, false); |
1121 |
24 Aug 05 |
nicklas |
76 |
|
1121 |
24 Aug 05 |
nicklas |
// Standard tests: create, load, list |
5748 |
19 Sep 11 |
nicklas |
78 |
int id = test_create(Platform.GENERIC, "genepix", null, bioAssaySetId, 0, softwareId, protocolId, arrayDesignId, true); |
5748 |
19 Sep 11 |
nicklas |
79 |
int id2 = test_create(Platform.GENERIC, "genepix", null, 0, 0, 0, 0, 0, false); |
5748 |
19 Sep 11 |
nicklas |
80 |
int id3 = test_create(Platform.AFFYMETRIX, null, null, 0, 0, 0, 0, 0, false); |
1121 |
24 Aug 05 |
nicklas |
81 |
|
1121 |
24 Aug 05 |
nicklas |
82 |
test_load(id); |
1124 |
24 Aug 05 |
nicklas |
83 |
|
3820 |
12 Oct 07 |
nicklas |
// Test adding raw data -- stored in database |
1942 |
08 Feb 06 |
nicklas |
85 |
test_add_rawdata(id2, 10); |
2959 |
27 Nov 06 |
nicklas |
86 |
test_import_from_file(id, "data/test.rawdata.import.txt"); |
1942 |
08 Feb 06 |
nicklas |
87 |
test_load(id); |
1134 |
25 Aug 05 |
nicklas |
88 |
test_list(-1); |
1143 |
29 Aug 05 |
nicklas |
89 |
write_raw_data_header(); |
3471 |
11 Jun 07 |
nicklas |
90 |
test_list_raw_data(id, 10, 5, 0, true); |
7151 |
04 May 16 |
nicklas |
91 |
write_dynamic_raw_data_header(); |
7151 |
04 May 16 |
nicklas |
92 |
test_list_dynamic_raw_data(id, id2, 10, 5, 0); |
1529 |
27 Oct 05 |
nicklas |
93 |
|
5026 |
28 Jul 09 |
nicklas |
// Test switch array design |
5026 |
28 Jul 09 |
nicklas |
95 |
test_change_arraydesign(id, arrayDesignId2); |
5026 |
28 Jul 09 |
nicklas |
96 |
|
3820 |
12 Oct 07 |
nicklas |
// Test adding raw data -- stored in files |
3820 |
12 Oct 07 |
nicklas |
98 |
int celId = TestFile.test_create("data/test.affymetrix.cel", false, false); |
5652 |
10 Jun 11 |
nicklas |
99 |
TestDataFileType.test_set_file(Item.RAWBIOASSAY, id3, "affymetrix.cel", celId); |
5652 |
10 Jun 11 |
nicklas |
100 |
TestDataFileType.test_list_files(Item.RAWBIOASSAY, id3, 1); |
5652 |
10 Jun 11 |
nicklas |
101 |
TestDataFileType.test_list_file_types(Item.RAWBIOASSAY, id3, 1); |
5652 |
10 Jun 11 |
nicklas |
102 |
ok &= TestDataFileType.ok; |
3820 |
12 Oct 07 |
nicklas |
103 |
|
1529 |
27 Oct 05 |
nicklas |
104 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
1942 |
08 Feb 06 |
nicklas |
105 |
test_delete_raw_data(id); |
1121 |
24 Aug 05 |
nicklas |
106 |
|
1121 |
24 Aug 05 |
nicklas |
// Standard test: Delete |
1121 |
24 Aug 05 |
nicklas |
108 |
test_delete(id); |
1121 |
24 Aug 05 |
nicklas |
109 |
test_delete(id2); |
3820 |
12 Oct 07 |
nicklas |
110 |
test_delete(id3); |
1139 |
26 Aug 05 |
nicklas |
111 |
|
3820 |
12 Oct 07 |
nicklas |
112 |
TestFile.test_delete(celId); |
5685 |
04 Aug 11 |
nicklas |
113 |
TestDerivedBioAssay.test_delete(bioAssaySetId); |
5642 |
26 May 11 |
nicklas |
114 |
TestPhysicalBioAssay.test_delete(hybridizationId); |
1121 |
24 Aug 05 |
nicklas |
115 |
TestArrayDesign.test_delete(arrayDesignId); |
5026 |
28 Jul 09 |
nicklas |
116 |
TestArrayDesign.test_delete(arrayDesignId2); |
1121 |
24 Aug 05 |
nicklas |
117 |
TestSoftware.test_delete(softwareId); |
1121 |
24 Aug 05 |
nicklas |
118 |
TestProtocol.test_delete(protocolId); |
1942 |
08 Feb 06 |
nicklas |
119 |
TestReporter.test_delete(); |
1121 |
24 Aug 05 |
nicklas |
120 |
write("++Testing raw bioassays "+(ok ? "OK" : "Failed")+"\n"); |
1121 |
24 Aug 05 |
nicklas |
121 |
return ok; |
1121 |
24 Aug 05 |
nicklas |
122 |
} |
1121 |
24 Aug 05 |
nicklas |
123 |
|
5748 |
19 Sep 11 |
nicklas |
124 |
static int test_create(String platformId, String rawDataType, String name, int bioAssayId, int extractId, |
5748 |
19 Sep 11 |
nicklas |
125 |
int softwareId, int protocolId, int arrayDesignId, boolean setAll) |
1121 |
24 Aug 05 |
nicklas |
126 |
{ |
1121 |
24 Aug 05 |
nicklas |
127 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.RAWBIOASSAY)) return 0; |
1121 |
24 Aug 05 |
nicklas |
128 |
int id = 0; |
1121 |
24 Aug 05 |
nicklas |
129 |
DbControl dc = null; |
1121 |
24 Aug 05 |
nicklas |
130 |
try |
1121 |
24 Aug 05 |
nicklas |
131 |
{ |
1121 |
24 Aug 05 |
nicklas |
132 |
dc = TestUtil.getDbControl(); |
3820 |
12 Oct 07 |
nicklas |
133 |
Platform platform = Platform.getByExternalId(dc, platformId); |
3820 |
12 Oct 07 |
nicklas |
134 |
RawBioAssay rba = RawBioAssay.getNew(dc, platform, RawDataTypes.getRawDataType(rawDataType)); |
1121 |
24 Aug 05 |
nicklas |
135 |
if (setAll) |
1121 |
24 Aug 05 |
nicklas |
136 |
{ |
1121 |
24 Aug 05 |
nicklas |
137 |
rba.setName("Test raw bioassay"); |
1121 |
24 Aug 05 |
nicklas |
138 |
rba.setDescription("Added at "+new Date()); |
1121 |
24 Aug 05 |
nicklas |
139 |
} |
4740 |
05 Feb 09 |
nicklas |
140 |
if (name != null) rba.setName(name); |
1121 |
24 Aug 05 |
nicklas |
141 |
if (softwareId != 0) |
1121 |
24 Aug 05 |
nicklas |
142 |
{ |
1121 |
24 Aug 05 |
nicklas |
143 |
rba.setSoftware(Software.getById(dc, softwareId)); |
1121 |
24 Aug 05 |
nicklas |
144 |
} |
1121 |
24 Aug 05 |
nicklas |
145 |
if (protocolId != 0) |
1121 |
24 Aug 05 |
nicklas |
146 |
{ |
1121 |
24 Aug 05 |
nicklas |
147 |
rba.setProtocol(Protocol.getById(dc, protocolId)); |
1121 |
24 Aug 05 |
nicklas |
148 |
} |
5652 |
10 Jun 11 |
nicklas |
149 |
if (bioAssayId != 0) |
1523 |
25 Oct 05 |
enell |
150 |
{ |
5657 |
16 Jun 11 |
nicklas |
151 |
rba.setParentBioAssay(DerivedBioAssay.getById(dc, bioAssayId)); |
1523 |
25 Oct 05 |
enell |
152 |
} |
5748 |
19 Sep 11 |
nicklas |
153 |
if (extractId != 0) |
5748 |
19 Sep 11 |
nicklas |
154 |
{ |
5748 |
19 Sep 11 |
nicklas |
155 |
rba.setParentExtract(Extract.getById(dc, extractId)); |
5748 |
19 Sep 11 |
nicklas |
156 |
} |
1523 |
25 Oct 05 |
enell |
157 |
if (arrayDesignId != 0) |
1523 |
25 Oct 05 |
enell |
158 |
{ |
1523 |
25 Oct 05 |
enell |
159 |
rba.setArrayDesign(ArrayDesign.getById(dc, arrayDesignId)); |
1523 |
25 Oct 05 |
enell |
160 |
} |
1121 |
24 Aug 05 |
nicklas |
161 |
dc.saveItem(rba); |
1121 |
24 Aug 05 |
nicklas |
162 |
dc.commit(); |
1121 |
24 Aug 05 |
nicklas |
163 |
id = rba.getId(); |
1121 |
24 Aug 05 |
nicklas |
164 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
165 |
dc.reattachItem(rba, false); |
1121 |
24 Aug 05 |
nicklas |
166 |
write_item(0, rba); |
1121 |
24 Aug 05 |
nicklas |
167 |
write("--Create raw bioassay OK"); |
1121 |
24 Aug 05 |
nicklas |
168 |
} |
1121 |
24 Aug 05 |
nicklas |
169 |
catch (Throwable ex) |
1121 |
24 Aug 05 |
nicklas |
170 |
{ |
1121 |
24 Aug 05 |
nicklas |
171 |
write("--Create raw bioassay FAILED"); |
1121 |
24 Aug 05 |
nicklas |
172 |
ex.printStackTrace(); |
1121 |
24 Aug 05 |
nicklas |
173 |
ok = false; |
1121 |
24 Aug 05 |
nicklas |
174 |
} |
1121 |
24 Aug 05 |
nicklas |
175 |
finally |
1121 |
24 Aug 05 |
nicklas |
176 |
{ |
1121 |
24 Aug 05 |
nicklas |
177 |
if (dc != null) dc.close(); |
1121 |
24 Aug 05 |
nicklas |
178 |
} |
1121 |
24 Aug 05 |
nicklas |
179 |
return id; |
1121 |
24 Aug 05 |
nicklas |
180 |
} |
1121 |
24 Aug 05 |
nicklas |
181 |
|
1121 |
24 Aug 05 |
nicklas |
182 |
static void test_load(int id) |
1121 |
24 Aug 05 |
nicklas |
183 |
{ |
1121 |
24 Aug 05 |
nicklas |
184 |
if (id == 0) return; |
1121 |
24 Aug 05 |
nicklas |
185 |
DbControl dc = null; |
1121 |
24 Aug 05 |
nicklas |
186 |
try |
1121 |
24 Aug 05 |
nicklas |
187 |
{ |
1121 |
24 Aug 05 |
nicklas |
188 |
dc = TestUtil.getDbControl(); |
1121 |
24 Aug 05 |
nicklas |
189 |
RawBioAssay rba = RawBioAssay.getById(dc, id); |
1121 |
24 Aug 05 |
nicklas |
190 |
write_item(0, rba); |
1368 |
21 Sep 05 |
nicklas |
191 |
if (!TestUtil.getSilent()) |
1368 |
21 Sep 05 |
nicklas |
192 |
{ |
1368 |
21 Sep 05 |
nicklas |
193 |
write("Headers:"); |
1368 |
21 Sep 05 |
nicklas |
194 |
for (String header : rba.getHeaderNames()) |
1368 |
21 Sep 05 |
nicklas |
195 |
{ |
1368 |
21 Sep 05 |
nicklas |
196 |
write("\t"+header+"="+rba.getHeader(header)); |
1368 |
21 Sep 05 |
nicklas |
197 |
} |
1368 |
21 Sep 05 |
nicklas |
198 |
} |
1121 |
24 Aug 05 |
nicklas |
199 |
write("--Load raw bioassay OK"); |
1121 |
24 Aug 05 |
nicklas |
200 |
} |
1121 |
24 Aug 05 |
nicklas |
201 |
catch (Throwable ex) |
1121 |
24 Aug 05 |
nicklas |
202 |
{ |
1121 |
24 Aug 05 |
nicklas |
203 |
write("--Load raw bioassay FAILED"); |
1121 |
24 Aug 05 |
nicklas |
204 |
ex.printStackTrace(); |
1121 |
24 Aug 05 |
nicklas |
205 |
ok = false; |
1121 |
24 Aug 05 |
nicklas |
206 |
} |
1121 |
24 Aug 05 |
nicklas |
207 |
finally |
1121 |
24 Aug 05 |
nicklas |
208 |
{ |
1121 |
24 Aug 05 |
nicklas |
209 |
if (dc != null) dc.close(); |
1121 |
24 Aug 05 |
nicklas |
210 |
} |
1121 |
24 Aug 05 |
nicklas |
211 |
} |
1121 |
24 Aug 05 |
nicklas |
212 |
|
5696 |
12 Aug 11 |
nicklas |
213 |
static boolean test_list(int expectedResults) |
1121 |
24 Aug 05 |
nicklas |
214 |
{ |
1121 |
24 Aug 05 |
nicklas |
215 |
DbControl dc = null; |
1121 |
24 Aug 05 |
nicklas |
216 |
try |
1121 |
24 Aug 05 |
nicklas |
217 |
{ |
1121 |
24 Aug 05 |
nicklas |
218 |
dc = TestUtil.getDbControl(); |
1418 |
07 Oct 05 |
nicklas |
219 |
ItemResultList<RawBioAssay> l = RawBioAssay.getQuery().list(dc); |
1121 |
24 Aug 05 |
nicklas |
220 |
for (int i = 0; i<l.size(); i++) |
1121 |
24 Aug 05 |
nicklas |
221 |
{ |
1121 |
24 Aug 05 |
nicklas |
222 |
write_item(i, l.get(i)); |
1121 |
24 Aug 05 |
nicklas |
223 |
} |
1121 |
24 Aug 05 |
nicklas |
224 |
if (expectedResults >= 0 && expectedResults != l.size()) |
1121 |
24 Aug 05 |
nicklas |
225 |
{ |
1121 |
24 Aug 05 |
nicklas |
226 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
1121 |
24 Aug 05 |
nicklas |
227 |
} |
1121 |
24 Aug 05 |
nicklas |
228 |
write("--List raw bioassays OK ("+l.size()+")"); |
1121 |
24 Aug 05 |
nicklas |
229 |
} |
1121 |
24 Aug 05 |
nicklas |
230 |
catch (Throwable ex) |
1121 |
24 Aug 05 |
nicklas |
231 |
{ |
1121 |
24 Aug 05 |
nicklas |
232 |
write("--List raw bioassays FAILED"); |
1121 |
24 Aug 05 |
nicklas |
233 |
ex.printStackTrace(); |
1121 |
24 Aug 05 |
nicklas |
234 |
ok = false; |
5696 |
12 Aug 11 |
nicklas |
235 |
return false; |
1121 |
24 Aug 05 |
nicklas |
236 |
} |
1121 |
24 Aug 05 |
nicklas |
237 |
finally |
1121 |
24 Aug 05 |
nicklas |
238 |
{ |
1121 |
24 Aug 05 |
nicklas |
239 |
if (dc != null) dc.close(); |
1121 |
24 Aug 05 |
nicklas |
240 |
} |
5696 |
12 Aug 11 |
nicklas |
241 |
return true; |
1121 |
24 Aug 05 |
nicklas |
242 |
} |
1121 |
24 Aug 05 |
nicklas |
243 |
|
1121 |
24 Aug 05 |
nicklas |
244 |
static void test_delete(int id) |
1121 |
24 Aug 05 |
nicklas |
245 |
{ |
1121 |
24 Aug 05 |
nicklas |
246 |
if (id == 0) return; |
1121 |
24 Aug 05 |
nicklas |
247 |
DbControl dc = null; |
1121 |
24 Aug 05 |
nicklas |
248 |
try |
1121 |
24 Aug 05 |
nicklas |
249 |
{ |
1121 |
24 Aug 05 |
nicklas |
250 |
dc = TestUtil.getDbControl(); |
1121 |
24 Aug 05 |
nicklas |
251 |
RawBioAssay rba = RawBioAssay.getById(dc, id); |
1121 |
24 Aug 05 |
nicklas |
252 |
dc.deleteItem(rba); |
5340 |
10 May 10 |
nicklas |
253 |
Set<ItemProxy> using = rba.getUsingItems(); |
5340 |
10 May 10 |
nicklas |
254 |
if (using.size() > 0) |
5340 |
10 May 10 |
nicklas |
255 |
{ |
5340 |
10 May 10 |
nicklas |
256 |
throw new BaseException(rba + " is used by " + using); |
5340 |
10 May 10 |
nicklas |
257 |
} |
1121 |
24 Aug 05 |
nicklas |
258 |
dc.commit(); |
1121 |
24 Aug 05 |
nicklas |
259 |
write("--Delete raw bioassay OK"); |
1121 |
24 Aug 05 |
nicklas |
260 |
} |
1121 |
24 Aug 05 |
nicklas |
261 |
catch (Throwable ex) |
1121 |
24 Aug 05 |
nicklas |
262 |
{ |
1121 |
24 Aug 05 |
nicklas |
263 |
write("--Delete raw bioassay FAILED"); |
1121 |
24 Aug 05 |
nicklas |
264 |
ex.printStackTrace(); |
1121 |
24 Aug 05 |
nicklas |
265 |
ok = false; |
1121 |
24 Aug 05 |
nicklas |
266 |
} |
1121 |
24 Aug 05 |
nicklas |
267 |
finally |
1121 |
24 Aug 05 |
nicklas |
268 |
{ |
1121 |
24 Aug 05 |
nicklas |
269 |
if (dc != null) dc.close(); |
1121 |
24 Aug 05 |
nicklas |
270 |
} |
1121 |
24 Aug 05 |
nicklas |
271 |
} |
1121 |
24 Aug 05 |
nicklas |
272 |
|
4426 |
29 Aug 08 |
nicklas |
273 |
static void test_delete_all() |
4426 |
29 Aug 08 |
nicklas |
274 |
{ |
4426 |
29 Aug 08 |
nicklas |
275 |
DbControl dc = null; |
4426 |
29 Aug 08 |
nicklas |
276 |
try |
4426 |
29 Aug 08 |
nicklas |
277 |
{ |
4426 |
29 Aug 08 |
nicklas |
278 |
dc = TestUtil.getDbControl(); |
4426 |
29 Aug 08 |
nicklas |
279 |
List<RawBioAssay> l = new ArrayList<RawBioAssay>(RawBioAssay.getQuery().list(dc)); |
4426 |
29 Aug 08 |
nicklas |
280 |
dc.commit(); |
5688 |
10 Aug 11 |
nicklas |
281 |
int numDeleted = Trashcan.delete(dc.getSessionControl(), l, true, null); |
5688 |
10 Aug 11 |
nicklas |
282 |
if (numDeleted != l.size()) throw new BaseException("Could not delete all items: " + numDeleted + " of " + l.size()); |
4426 |
29 Aug 08 |
nicklas |
283 |
write("--Delete all raw bioassays OK ("+l.size()+")"); |
4426 |
29 Aug 08 |
nicklas |
284 |
} |
4426 |
29 Aug 08 |
nicklas |
285 |
catch (Throwable ex) |
4426 |
29 Aug 08 |
nicklas |
286 |
{ |
4426 |
29 Aug 08 |
nicklas |
287 |
write("--Delete all raw bioassays FAILED"); |
4426 |
29 Aug 08 |
nicklas |
288 |
ex.printStackTrace(); |
4426 |
29 Aug 08 |
nicklas |
289 |
ok = false; |
4426 |
29 Aug 08 |
nicklas |
290 |
} |
4426 |
29 Aug 08 |
nicklas |
291 |
finally |
4426 |
29 Aug 08 |
nicklas |
292 |
{ |
4426 |
29 Aug 08 |
nicklas |
293 |
if (dc != null) dc.close(); |
4426 |
29 Aug 08 |
nicklas |
294 |
} |
4426 |
29 Aug 08 |
nicklas |
295 |
} |
4426 |
29 Aug 08 |
nicklas |
296 |
|
1121 |
24 Aug 05 |
nicklas |
297 |
static void write_header() |
1121 |
24 Aug 05 |
nicklas |
298 |
{ |
1121 |
24 Aug 05 |
nicklas |
299 |
if (!TestUtil.getSilent()) |
1121 |
24 Aug 05 |
nicklas |
300 |
{ |
3820 |
12 Oct 07 |
nicklas |
301 |
write(" \tID \tName \tDescription\tData type\tDb spots\tFile spots\tBytes\tArray Design\tSoftware\tProtocol"); |
3820 |
12 Oct 07 |
nicklas |
302 |
write("-- \t-- \t--------- \t-----------\t---------\t--------\t-----------\t-----\t------------\t--------\t--------"); |
1121 |
24 Aug 05 |
nicklas |
303 |
} |
1121 |
24 Aug 05 |
nicklas |
304 |
} |
1134 |
25 Aug 05 |
nicklas |
305 |
static void write_raw_data_header() |
1134 |
25 Aug 05 |
nicklas |
306 |
{ |
1134 |
25 Aug 05 |
nicklas |
307 |
if (!TestUtil.getSilent()) |
1134 |
25 Aug 05 |
nicklas |
308 |
{ |
1142 |
29 Aug 05 |
nicklas |
309 |
write(" \tID \tBlock\tRow\tColumn\tGrid X\tGrid Y\tX \tY \tPosition\tReporter\tFeature\tExtra"); |
1142 |
29 Aug 05 |
nicklas |
310 |
write("-- \t-- \t-----\t---\t------\t------\t------\t-----\t-----\t--------\t--------\t-------\t-----"); |
1134 |
25 Aug 05 |
nicklas |
311 |
} |
1134 |
25 Aug 05 |
nicklas |
312 |
} |
7151 |
04 May 16 |
nicklas |
313 |
static void write_dynamic_raw_data_header() |
7151 |
04 May 16 |
nicklas |
314 |
{ |
7151 |
04 May 16 |
nicklas |
315 |
if (!TestUtil.getSilent()) |
7151 |
04 May 16 |
nicklas |
316 |
{ |
7151 |
04 May 16 |
nicklas |
317 |
write(" \tID \tX \tY \tReporter\tRaw bioassay"); |
7151 |
04 May 16 |
nicklas |
318 |
write("-- \t-- \t-----\t-----\t--------\t-------------"); |
7151 |
04 May 16 |
nicklas |
319 |
} |
7151 |
04 May 16 |
nicklas |
320 |
} |
1121 |
24 Aug 05 |
nicklas |
321 |
static void write_item(int i, RawBioAssay rba) |
1121 |
24 Aug 05 |
nicklas |
322 |
throws BaseException |
1121 |
24 Aug 05 |
nicklas |
323 |
{ |
1121 |
24 Aug 05 |
nicklas |
324 |
if (!TestUtil.getSilent()) |
1121 |
24 Aug 05 |
nicklas |
325 |
{ |
1121 |
24 Aug 05 |
nicklas |
326 |
System.out.println(i+":\t"+rba.getId()+"\t"+rba.getName()+"\t"+rba.getDescription()+ |
3820 |
12 Oct 07 |
nicklas |
327 |
"\t"+rba.getRawDataType().getName()+"\t"+rba.getNumDbSpots()+"\t"+rba.getNumFileSpots() + |
3820 |
12 Oct 07 |
nicklas |
328 |
"\t"+rba.getBytes()+"\t"+rba.getArrayDesign()+ |
1121 |
24 Aug 05 |
nicklas |
329 |
"\t"+rba.getSoftware()+"\t"+rba.getProtocol()); |
1121 |
24 Aug 05 |
nicklas |
330 |
} |
1121 |
24 Aug 05 |
nicklas |
331 |
} |
1134 |
25 Aug 05 |
nicklas |
332 |
|
3471 |
11 Jun 07 |
nicklas |
333 |
static void write_item(int i, RawData rd, boolean writeExtended) |
1142 |
29 Aug 05 |
nicklas |
334 |
throws BaseException |
1134 |
25 Aug 05 |
nicklas |
335 |
{ |
1134 |
25 Aug 05 |
nicklas |
336 |
if (!TestUtil.getSilent()) |
1134 |
25 Aug 05 |
nicklas |
337 |
{ |
1134 |
25 Aug 05 |
nicklas |
338 |
System.out.println(i+":\t"+rd.getId()+"\t"+rd.getBlock()+"\t"+rd.getRow()+ |
1134 |
25 Aug 05 |
nicklas |
339 |
"\t"+rd.getColumn()+"\t"+rd.getMetaGridX()+"\t"+rd.getMetaGridY()+ |
1142 |
29 Aug 05 |
nicklas |
340 |
"\t"+rd.getX()+"\t"+rd.getY()+"\t"+rd.getPosition()+ |
3471 |
11 Jun 07 |
nicklas |
341 |
"\t"+rd.getReporter()+"\t"+rd.getFeature()+(writeExtended ? "\t"+rd.getAllExtended() : "")); |
1134 |
25 Aug 05 |
nicklas |
342 |
} |
1134 |
25 Aug 05 |
nicklas |
343 |
} |
1134 |
25 Aug 05 |
nicklas |
344 |
|
7151 |
04 May 16 |
nicklas |
345 |
static void write_item(int i, SqlResult result, int columns) |
7151 |
04 May 16 |
nicklas |
346 |
throws BaseException, SQLException |
7151 |
04 May 16 |
nicklas |
347 |
{ |
7151 |
04 May 16 |
nicklas |
348 |
if (!TestUtil.getSilent()) |
7151 |
04 May 16 |
nicklas |
349 |
{ |
7151 |
04 May 16 |
nicklas |
350 |
StringBuilder sb = new StringBuilder(); |
7151 |
04 May 16 |
nicklas |
351 |
sb.append(i); |
7151 |
04 May 16 |
nicklas |
352 |
for (int col = 1; col <= columns; col++) |
7151 |
04 May 16 |
nicklas |
353 |
{ |
7151 |
04 May 16 |
nicklas |
354 |
sb.append("\t").append(result.getString(col)); |
7151 |
04 May 16 |
nicklas |
355 |
} |
7151 |
04 May 16 |
nicklas |
356 |
System.out.println(sb.toString()); |
7151 |
04 May 16 |
nicklas |
357 |
} |
7151 |
04 May 16 |
nicklas |
358 |
} |
7151 |
04 May 16 |
nicklas |
359 |
|
3820 |
12 Oct 07 |
nicklas |
360 |
static void write_item(int i, DataFileType type) |
3820 |
12 Oct 07 |
nicklas |
361 |
throws BaseException |
3820 |
12 Oct 07 |
nicklas |
362 |
{ |
3820 |
12 Oct 07 |
nicklas |
363 |
if (!TestUtil.getSilent()) |
3820 |
12 Oct 07 |
nicklas |
364 |
{ |
3820 |
12 Oct 07 |
nicklas |
365 |
System.out.println(i+":\t"+type.getId()+"\t"+type.getName()+"\t"+ |
3820 |
12 Oct 07 |
nicklas |
366 |
type.getDescription()); |
3820 |
12 Oct 07 |
nicklas |
367 |
} |
3820 |
12 Oct 07 |
nicklas |
368 |
} |
3820 |
12 Oct 07 |
nicklas |
369 |
|
3820 |
12 Oct 07 |
nicklas |
370 |
|
1121 |
24 Aug 05 |
nicklas |
371 |
static void write(String message) |
1121 |
24 Aug 05 |
nicklas |
372 |
{ |
1121 |
24 Aug 05 |
nicklas |
373 |
System.out.println(message); |
1121 |
24 Aug 05 |
nicklas |
374 |
} |
1121 |
24 Aug 05 |
nicklas |
375 |
|
1124 |
24 Aug 05 |
nicklas |
376 |
static void test_add_rawdata(int rawBioAssayId, int numSpots) |
1124 |
24 Aug 05 |
nicklas |
377 |
{ |
1124 |
24 Aug 05 |
nicklas |
378 |
if (rawBioAssayId == 0) return; |
1124 |
24 Aug 05 |
nicklas |
379 |
DbControl dc = null; |
1124 |
24 Aug 05 |
nicklas |
380 |
long time; |
1124 |
24 Aug 05 |
nicklas |
381 |
try |
1124 |
24 Aug 05 |
nicklas |
382 |
{ |
1124 |
24 Aug 05 |
nicklas |
383 |
write("--Start adding raw data ("+numSpots+" spots)"); |
1124 |
24 Aug 05 |
nicklas |
384 |
dc = TestUtil.getDbControl(); |
1124 |
24 Aug 05 |
nicklas |
385 |
RawBioAssay rba = RawBioAssay.getById(dc, rawBioAssayId); |
1134 |
25 Aug 05 |
nicklas |
386 |
RawDataType rdt = rba.getRawDataType(); |
1134 |
25 Aug 05 |
nicklas |
387 |
List<RawDataProperty> extraProperties = rdt.getProperties(); |
4256 |
29 Apr 08 |
nicklas |
388 |
RawDataBatcher rdb = rba.getRawDataBatcher(null, null); |
1124 |
24 Aug 05 |
nicklas |
389 |
int block = 1; |
1124 |
24 Aug 05 |
nicklas |
390 |
int row = 1; |
1124 |
24 Aug 05 |
nicklas |
391 |
int column = 1; |
1124 |
24 Aug 05 |
nicklas |
392 |
time = System.currentTimeMillis(); |
1124 |
24 Aug 05 |
nicklas |
393 |
for (int i = 0; i < numSpots; i++) |
1124 |
24 Aug 05 |
nicklas |
394 |
{ |
1134 |
25 Aug 05 |
nicklas |
395 |
RawData rd = rdb.newRawData(); |
1134 |
25 Aug 05 |
nicklas |
396 |
rd.setBlock(block); |
1134 |
25 Aug 05 |
nicklas |
397 |
rd.setRow(row); |
1134 |
25 Aug 05 |
nicklas |
398 |
rd.setColumn(column); |
1134 |
25 Aug 05 |
nicklas |
399 |
rd.setX((float)Math.random() * 50000); |
1134 |
25 Aug 05 |
nicklas |
400 |
rd.setY((float)Math.random() * 50000); |
1134 |
25 Aug 05 |
nicklas |
401 |
|
1134 |
25 Aug 05 |
nicklas |
402 |
Map<String, Object> extra = rd.getAllExtended(); |
1134 |
25 Aug 05 |
nicklas |
403 |
for (RawDataProperty p : extraProperties) |
1134 |
25 Aug 05 |
nicklas |
404 |
{ |
1134 |
25 Aug 05 |
nicklas |
405 |
Type t = p.getType(); |
1134 |
25 Aug 05 |
nicklas |
406 |
Object value = null; |
1134 |
25 Aug 05 |
nicklas |
407 |
if (t == Type.INT) |
1134 |
25 Aug 05 |
nicklas |
408 |
{ |
1134 |
25 Aug 05 |
nicklas |
409 |
value = (int)(Math.random() * 50000); |
1134 |
25 Aug 05 |
nicklas |
410 |
} |
1134 |
25 Aug 05 |
nicklas |
411 |
else if (t == Type.FLOAT) |
1134 |
25 Aug 05 |
nicklas |
412 |
{ |
1134 |
25 Aug 05 |
nicklas |
413 |
value = (float)Math.random() * 50000; |
1134 |
25 Aug 05 |
nicklas |
414 |
} |
1134 |
25 Aug 05 |
nicklas |
415 |
else if (t == Type.STRING) |
1134 |
25 Aug 05 |
nicklas |
416 |
{ |
1134 |
25 Aug 05 |
nicklas |
417 |
value = "ABCDEF"; |
1134 |
25 Aug 05 |
nicklas |
418 |
} |
1134 |
25 Aug 05 |
nicklas |
419 |
extra.put(p.getName(), value); |
1134 |
25 Aug 05 |
nicklas |
420 |
} |
1134 |
25 Aug 05 |
nicklas |
421 |
rdb.insert(rd); |
1124 |
24 Aug 05 |
nicklas |
422 |
row++; |
1124 |
24 Aug 05 |
nicklas |
423 |
if (row == 11) |
1124 |
24 Aug 05 |
nicklas |
424 |
{ |
1124 |
24 Aug 05 |
nicklas |
425 |
row = 1; |
1124 |
24 Aug 05 |
nicklas |
426 |
column++; |
1124 |
24 Aug 05 |
nicklas |
427 |
if (column == 11) |
1124 |
24 Aug 05 |
nicklas |
428 |
{ |
1124 |
24 Aug 05 |
nicklas |
429 |
column = 1; |
1124 |
24 Aug 05 |
nicklas |
430 |
block++; |
1124 |
24 Aug 05 |
nicklas |
431 |
} |
1124 |
24 Aug 05 |
nicklas |
432 |
} |
1124 |
24 Aug 05 |
nicklas |
433 |
} |
1124 |
24 Aug 05 |
nicklas |
434 |
dc.commit(); |
1124 |
24 Aug 05 |
nicklas |
435 |
time = System.currentTimeMillis()-time; |
1124 |
24 Aug 05 |
nicklas |
436 |
write("--Add raw data OK ("+time+" ms)"); |
1124 |
24 Aug 05 |
nicklas |
437 |
} |
1124 |
24 Aug 05 |
nicklas |
438 |
catch (Throwable ex) |
1124 |
24 Aug 05 |
nicklas |
439 |
{ |
1124 |
24 Aug 05 |
nicklas |
440 |
write("--Add raw data FAILED"); |
1124 |
24 Aug 05 |
nicklas |
441 |
ex.printStackTrace(); |
1124 |
24 Aug 05 |
nicklas |
442 |
ok = false; |
1124 |
24 Aug 05 |
nicklas |
443 |
} |
1124 |
24 Aug 05 |
nicklas |
444 |
finally |
1124 |
24 Aug 05 |
nicklas |
445 |
{ |
1124 |
24 Aug 05 |
nicklas |
446 |
if (dc != null) dc.close(); |
1124 |
24 Aug 05 |
nicklas |
447 |
} |
1124 |
24 Aug 05 |
nicklas |
448 |
} |
1134 |
25 Aug 05 |
nicklas |
449 |
|
3471 |
11 Jun 07 |
nicklas |
450 |
static boolean test_list_raw_data(int rawBioAssayId, int limit, int offset, long expectedTotal, boolean writeExtended) |
1134 |
25 Aug 05 |
nicklas |
451 |
{ |
3471 |
11 Jun 07 |
nicklas |
452 |
if (rawBioAssayId == 0) return ok; |
1134 |
25 Aug 05 |
nicklas |
453 |
DbControl dc = null; |
1134 |
25 Aug 05 |
nicklas |
454 |
try |
1134 |
25 Aug 05 |
nicklas |
455 |
{ |
1134 |
25 Aug 05 |
nicklas |
456 |
dc = TestUtil.getDbControl(); |
1134 |
25 Aug 05 |
nicklas |
457 |
RawBioAssay rba = RawBioAssay.getById(dc, rawBioAssayId); |
1545 |
31 Oct 05 |
nicklas |
458 |
DataQuery<RawData> query = rba.getRawData(); |
5026 |
28 Jul 09 |
nicklas |
459 |
query.join(Hql.leftJoin(null, "feature", "ft", null, true)); |
5026 |
28 Jul 09 |
nicklas |
460 |
query.join(Hql.leftJoin(null, "reporter", "rep", null, true)); |
1545 |
31 Oct 05 |
nicklas |
461 |
query.setMaxResults(limit); |
1545 |
31 Oct 05 |
nicklas |
462 |
query.setFirstResult(offset); |
1545 |
31 Oct 05 |
nicklas |
463 |
query.setReturnTotalCount(true); |
1545 |
31 Oct 05 |
nicklas |
464 |
|
1545 |
31 Oct 05 |
nicklas |
465 |
DataResultIterator<RawData> it = query.iterate(dc); |
1418 |
07 Oct 05 |
nicklas |
466 |
int counter = 0; |
1418 |
07 Oct 05 |
nicklas |
467 |
while (it.hasNext()) |
1142 |
29 Aug 05 |
nicklas |
468 |
{ |
1418 |
07 Oct 05 |
nicklas |
469 |
RawData rd = it.next(); |
1418 |
07 Oct 05 |
nicklas |
470 |
if (counter == 0) |
1418 |
07 Oct 05 |
nicklas |
471 |
{ |
1418 |
07 Oct 05 |
nicklas |
472 |
write_item(0, RawDataUtil.getRawBioAssay(dc, rd)); |
1418 |
07 Oct 05 |
nicklas |
473 |
} |
3471 |
11 Jun 07 |
nicklas |
474 |
write_item(counter, rd, writeExtended); |
1418 |
07 Oct 05 |
nicklas |
475 |
counter++; |
1142 |
29 Aug 05 |
nicklas |
476 |
} |
3468 |
08 Jun 07 |
nicklas |
477 |
long totalCount = it.getTotalCount(); |
3468 |
08 Jun 07 |
nicklas |
478 |
if (expectedTotal > 0 && expectedTotal != totalCount) |
3468 |
08 Jun 07 |
nicklas |
479 |
{ |
3468 |
08 Jun 07 |
nicklas |
480 |
throw new Exception("Unexpected number of raw data: " + totalCount +"; expected " +expectedTotal); |
3468 |
08 Jun 07 |
nicklas |
481 |
} |
3468 |
08 Jun 07 |
nicklas |
482 |
write("--List raw data OK (listed = "+counter+"; total = "+totalCount+")"); |
1134 |
25 Aug 05 |
nicklas |
483 |
} |
1134 |
25 Aug 05 |
nicklas |
484 |
catch (Throwable ex) |
1134 |
25 Aug 05 |
nicklas |
485 |
{ |
1134 |
25 Aug 05 |
nicklas |
486 |
write("--List raw data FAILED"); |
1134 |
25 Aug 05 |
nicklas |
487 |
ex.printStackTrace(); |
1134 |
25 Aug 05 |
nicklas |
488 |
ok = false; |
3471 |
11 Jun 07 |
nicklas |
489 |
return false; |
1134 |
25 Aug 05 |
nicklas |
490 |
} |
1134 |
25 Aug 05 |
nicklas |
491 |
finally |
1134 |
25 Aug 05 |
nicklas |
492 |
{ |
1134 |
25 Aug 05 |
nicklas |
493 |
if (dc != null) dc.close(); |
1134 |
25 Aug 05 |
nicklas |
494 |
} |
3471 |
11 Jun 07 |
nicklas |
495 |
return true; |
1134 |
25 Aug 05 |
nicklas |
496 |
} |
1139 |
26 Aug 05 |
nicklas |
497 |
|
7151 |
04 May 16 |
nicklas |
498 |
static boolean test_list_dynamic_raw_data(int raw1, int raw2, int limit, int offset, long expectedTotal) |
7151 |
04 May 16 |
nicklas |
499 |
{ |
7151 |
04 May 16 |
nicklas |
500 |
if (raw1 == 0 && raw2 == 0) return ok; |
7151 |
04 May 16 |
nicklas |
501 |
DbControl dc = null; |
7151 |
04 May 16 |
nicklas |
502 |
try |
7151 |
04 May 16 |
nicklas |
503 |
{ |
7151 |
04 May 16 |
nicklas |
504 |
dc = TestUtil.getDbControl(); |
7151 |
04 May 16 |
nicklas |
505 |
RawBioAssay rba1 = RawBioAssay.getById(dc, raw1); |
7151 |
04 May 16 |
nicklas |
506 |
RawBioAssay rba2 = RawBioAssay.getById(dc, raw2); |
7151 |
04 May 16 |
nicklas |
507 |
|
7151 |
04 May 16 |
nicklas |
508 |
DynamicRawDataQuery query = DynamicRawDataQuery.getQuery(Arrays.asList(rba1, rba2)); |
7151 |
04 May 16 |
nicklas |
509 |
query.setAutoJoinType(JoinType.INNER); |
7151 |
04 May 16 |
nicklas |
510 |
query.select(Dynamic.selectRawData("id")); |
7151 |
04 May 16 |
nicklas |
511 |
query.select(Dynamic.selectRawData("x")); |
7151 |
04 May 16 |
nicklas |
512 |
query.select(Dynamic.selectRawData("y")); |
7151 |
04 May 16 |
nicklas |
513 |
query.select(Dynamic.selectReporter("externalId")); |
7151 |
04 May 16 |
nicklas |
514 |
query.select(Dynamic.selectRawBioAssay("name")); |
7151 |
04 May 16 |
nicklas |
515 |
|
7151 |
04 May 16 |
nicklas |
516 |
query.order(Orders.asc(Dynamic.reporter("externalId"))); |
7151 |
04 May 16 |
nicklas |
517 |
|
7151 |
04 May 16 |
nicklas |
518 |
query.setMaxResults(limit); |
7151 |
04 May 16 |
nicklas |
519 |
query.setFirstResult(offset); |
7151 |
04 May 16 |
nicklas |
520 |
query.setReturnTotalCount(true); |
7151 |
04 May 16 |
nicklas |
521 |
|
7151 |
04 May 16 |
nicklas |
522 |
DynamicResultIterator it = query.iterate(dc); |
7151 |
04 May 16 |
nicklas |
523 |
int counter = 0; |
7151 |
04 May 16 |
nicklas |
524 |
while (it.hasNext()) |
7151 |
04 May 16 |
nicklas |
525 |
{ |
7151 |
04 May 16 |
nicklas |
526 |
SqlResult result = it.next(); |
7151 |
04 May 16 |
nicklas |
527 |
write_item(counter, result, 5); |
7151 |
04 May 16 |
nicklas |
528 |
counter++; |
7151 |
04 May 16 |
nicklas |
529 |
} |
7151 |
04 May 16 |
nicklas |
530 |
long totalCount = it.getTotalCount(); |
7151 |
04 May 16 |
nicklas |
531 |
if (expectedTotal > 0 && expectedTotal != totalCount) |
7151 |
04 May 16 |
nicklas |
532 |
{ |
7151 |
04 May 16 |
nicklas |
533 |
throw new Exception("Unexpected number of raw data: " + totalCount +"; expected " +expectedTotal); |
7151 |
04 May 16 |
nicklas |
534 |
} |
7151 |
04 May 16 |
nicklas |
535 |
write("--List dynamic raw data OK (listed = "+counter+"; total = "+totalCount+")"); |
7151 |
04 May 16 |
nicklas |
536 |
} |
7151 |
04 May 16 |
nicklas |
537 |
catch (Throwable ex) |
7151 |
04 May 16 |
nicklas |
538 |
{ |
7151 |
04 May 16 |
nicklas |
539 |
write("--List dynamic raw data FAILED"); |
7151 |
04 May 16 |
nicklas |
540 |
ex.printStackTrace(); |
7151 |
04 May 16 |
nicklas |
541 |
ok = false; |
7151 |
04 May 16 |
nicklas |
542 |
return false; |
7151 |
04 May 16 |
nicklas |
543 |
} |
7151 |
04 May 16 |
nicklas |
544 |
finally |
7151 |
04 May 16 |
nicklas |
545 |
{ |
7151 |
04 May 16 |
nicklas |
546 |
if (dc != null) dc.close(); |
7151 |
04 May 16 |
nicklas |
547 |
} |
7151 |
04 May 16 |
nicklas |
548 |
return true; |
7151 |
04 May 16 |
nicklas |
549 |
} |
7151 |
04 May 16 |
nicklas |
550 |
|
7151 |
04 May 16 |
nicklas |
551 |
|
1142 |
29 Aug 05 |
nicklas |
552 |
static void test_delete_raw_data(int rawBioAssayId) |
1142 |
29 Aug 05 |
nicklas |
553 |
{ |
1142 |
29 Aug 05 |
nicklas |
554 |
if (rawBioAssayId == 0) return; |
1142 |
29 Aug 05 |
nicklas |
555 |
DbControl dc = null; |
1142 |
29 Aug 05 |
nicklas |
556 |
try |
1142 |
29 Aug 05 |
nicklas |
557 |
{ |
1142 |
29 Aug 05 |
nicklas |
558 |
dc = TestUtil.getDbControl(); |
1142 |
29 Aug 05 |
nicklas |
559 |
RawBioAssay rba = RawBioAssay.getById(dc, rawBioAssayId); |
1142 |
29 Aug 05 |
nicklas |
560 |
rba.deleteRawData(); |
1142 |
29 Aug 05 |
nicklas |
561 |
write("--Delete raw data OK"); |
1142 |
29 Aug 05 |
nicklas |
562 |
} |
1142 |
29 Aug 05 |
nicklas |
563 |
catch (Throwable ex) |
1142 |
29 Aug 05 |
nicklas |
564 |
{ |
1142 |
29 Aug 05 |
nicklas |
565 |
write("--Delete raw data FAILED"); |
1142 |
29 Aug 05 |
nicklas |
566 |
ex.printStackTrace(); |
1142 |
29 Aug 05 |
nicklas |
567 |
ok = false; |
1142 |
29 Aug 05 |
nicklas |
568 |
} |
1142 |
29 Aug 05 |
nicklas |
569 |
finally |
1142 |
29 Aug 05 |
nicklas |
570 |
{ |
1142 |
29 Aug 05 |
nicklas |
571 |
if (dc != null) dc.close(); |
1142 |
29 Aug 05 |
nicklas |
572 |
} |
1142 |
29 Aug 05 |
nicklas |
573 |
} |
1142 |
29 Aug 05 |
nicklas |
574 |
|
1139 |
26 Aug 05 |
nicklas |
575 |
static void test_import_from_file(int rawBioAssayId, String filename) |
1139 |
26 Aug 05 |
nicklas |
576 |
{ |
1139 |
26 Aug 05 |
nicklas |
577 |
if (rawBioAssayId == 0) return; |
1139 |
26 Aug 05 |
nicklas |
578 |
write("--Start import raw data from file (" + filename + ")"); |
1139 |
26 Aug 05 |
nicklas |
579 |
DbControl dc = null; |
1139 |
26 Aug 05 |
nicklas |
580 |
long time; |
1139 |
26 Aug 05 |
nicklas |
581 |
int i = 0; |
1139 |
26 Aug 05 |
nicklas |
582 |
try |
1139 |
26 Aug 05 |
nicklas |
583 |
{ |
1139 |
26 Aug 05 |
nicklas |
584 |
dc = TestUtil.getDbControl(); |
1139 |
26 Aug 05 |
nicklas |
585 |
RawBioAssay rba = RawBioAssay.getById(dc, rawBioAssayId); |
4256 |
29 Apr 08 |
nicklas |
586 |
RawDataBatcher rawDataBatcher = rba.getRawDataBatcher(null, null); |
1139 |
26 Aug 05 |
nicklas |
587 |
ReporterBatcher reporterBatcher = ReporterBatcher.getNew(dc); |
1139 |
26 Aug 05 |
nicklas |
588 |
|
1139 |
26 Aug 05 |
nicklas |
589 |
FlatFileParser parser = new FlatFileParser(); |
1368 |
21 Sep 05 |
nicklas |
590 |
parser.setHeaderRegexp(Pattern.compile("\"(.*)=(.*)\"")); |
1139 |
26 Aug 05 |
nicklas |
591 |
parser.setDataHeaderRegexp(Pattern.compile("\"Block\"\\t\"Column\"\\t\"Row\"\\t\"Name\"\\t\"ID\".*")); |
2203 |
28 Apr 06 |
nicklas |
592 |
parser.setDataSplitterRegexp(Pattern.compile("\\t")); |
2992 |
01 Dec 06 |
enell |
593 |
parser.setInputStream(FileUtil.getInputStream(new java.io.File(filename)), "ISO-8859-1"); |
1139 |
26 Aug 05 |
nicklas |
594 |
parser.parseHeaders(); |
1139 |
26 Aug 05 |
nicklas |
595 |
|
1368 |
21 Sep 05 |
nicklas |
596 |
for (String header : parser.getHeaderNames()) |
1368 |
21 Sep 05 |
nicklas |
597 |
{ |
1594 |
14 Nov 05 |
nicklas |
598 |
String value = parser.getHeader(header); |
1594 |
14 Nov 05 |
nicklas |
599 |
if (header != null && value != null) rba.setHeader(header, value); |
1368 |
21 Sep 05 |
nicklas |
600 |
} |
1368 |
21 Sep 05 |
nicklas |
601 |
|
1139 |
26 Aug 05 |
nicklas |
602 |
time = System.currentTimeMillis(); |
1139 |
26 Aug 05 |
nicklas |
603 |
while (parser.hasMoreData()) |
1139 |
26 Aug 05 |
nicklas |
604 |
{ |
1139 |
26 Aug 05 |
nicklas |
605 |
FlatFileParser.Data parsedData = parser.nextData(); |
1139 |
26 Aug 05 |
nicklas |
606 |
RawData rawData = rawDataBatcher.newRawData(); |
7665 |
20 Mar 19 |
nicklas |
607 |
rawData.setBlock(parsedData.getInt(0)); |
7665 |
20 Mar 19 |
nicklas |
608 |
rawData.setRow(parsedData.getInt(2)); |
7665 |
20 Mar 19 |
nicklas |
609 |
rawData.setColumn(parsedData.getInt(1)); |
7665 |
20 Mar 19 |
nicklas |
610 |
rawData.setX(parsedData.getFloat(5)); |
7665 |
20 Mar 19 |
nicklas |
611 |
rawData.setY(parsedData.getFloat(6)); |
7665 |
20 Mar 19 |
nicklas |
612 |
String reporterId = parsedData.getString(4); |
1594 |
14 Nov 05 |
nicklas |
613 |
rawData.setReporter(reporterId == null ? null : reporterBatcher.getByExternalId(reporterId)); |
1139 |
26 Aug 05 |
nicklas |
614 |
|
1139 |
26 Aug 05 |
nicklas |
615 |
Map<String, Object> extraData = rawData.getAllExtended(); |
7665 |
20 Mar 19 |
nicklas |
616 |
extraData.put("diameter", parsedData.getFloat(7)); |
7665 |
20 Mar 19 |
nicklas |
617 |
extraData.put("ch1FgMedian", parsedData.getFloat(8)); |
7665 |
20 Mar 19 |
nicklas |
618 |
extraData.put("ch1FgMean", parsedData.getFloat(9)); |
7665 |
20 Mar 19 |
nicklas |
619 |
extraData.put("ch1FgSd", parsedData.getFloat(10)); |
7665 |
20 Mar 19 |
nicklas |
620 |
extraData.put("ch1BgMedian", parsedData.getFloat(11)); |
7665 |
20 Mar 19 |
nicklas |
621 |
extraData.put("ch1BgMean", parsedData.getFloat(12)); |
7665 |
20 Mar 19 |
nicklas |
622 |
extraData.put("ch1BgSd", parsedData.getFloat(13)); |
7665 |
20 Mar 19 |
nicklas |
623 |
extraData.put("ch1PercSd1", parsedData.getInt(14)); |
7665 |
20 Mar 19 |
nicklas |
624 |
extraData.put("ch1PercSd2", parsedData.getInt(15)); |
7665 |
20 Mar 19 |
nicklas |
625 |
extraData.put("ch1PercSat", parsedData.getInt(16)); |
7665 |
20 Mar 19 |
nicklas |
626 |
extraData.put("ch2FgMedian", parsedData.getFloat(17)); |
7665 |
20 Mar 19 |
nicklas |
627 |
extraData.put("ch2FgMean", parsedData.getFloat(18)); |
7665 |
20 Mar 19 |
nicklas |
628 |
extraData.put("ch2FgSd", parsedData.getFloat(19)); |
7665 |
20 Mar 19 |
nicklas |
629 |
extraData.put("ch2BgMedian", parsedData.getFloat(20)); |
7665 |
20 Mar 19 |
nicklas |
630 |
extraData.put("ch2BgMean", parsedData.getFloat(21)); |
7665 |
20 Mar 19 |
nicklas |
631 |
extraData.put("ch2BgSd", parsedData.getFloat(22)); |
7665 |
20 Mar 19 |
nicklas |
632 |
extraData.put("ch2PercSd1", parsedData.getInt(23)); |
7665 |
20 Mar 19 |
nicklas |
633 |
extraData.put("ch2PercSd2", parsedData.getInt(24)); |
7665 |
20 Mar 19 |
nicklas |
634 |
extraData.put("ch2PercSat", parsedData.getInt(25)); |
1139 |
26 Aug 05 |
nicklas |
635 |
|
4097 |
23 Jan 08 |
nicklas |
636 |
try |
4097 |
23 Jan 08 |
nicklas |
637 |
{ |
4097 |
23 Jan 08 |
nicklas |
638 |
rawDataBatcher.insert(rawData); |
4097 |
23 Jan 08 |
nicklas |
639 |
i++; |
4097 |
23 Jan 08 |
nicklas |
640 |
} |
4097 |
23 Jan 08 |
nicklas |
641 |
catch (ItemAlreadyExistsException ex) |
4097 |
23 Jan 08 |
nicklas |
642 |
{ |
4097 |
23 Jan 08 |
nicklas |
// Ignore duplicate features |
4097 |
23 Jan 08 |
nicklas |
644 |
} |
1139 |
26 Aug 05 |
nicklas |
645 |
} |
1139 |
26 Aug 05 |
nicklas |
646 |
dc.commit(); |
1139 |
26 Aug 05 |
nicklas |
647 |
time = System.currentTimeMillis()-time; |
1139 |
26 Aug 05 |
nicklas |
648 |
|
1139 |
26 Aug 05 |
nicklas |
649 |
write("--Import raw data from file OK ("+i+", time="+time+" ms)"); |
1139 |
26 Aug 05 |
nicklas |
650 |
} |
1139 |
26 Aug 05 |
nicklas |
651 |
catch (Throwable ex) |
1139 |
26 Aug 05 |
nicklas |
652 |
{ |
1139 |
26 Aug 05 |
nicklas |
653 |
write("--Import raw data from file FAILED ("+i+")"); |
1139 |
26 Aug 05 |
nicklas |
654 |
ex.printStackTrace(); |
1139 |
26 Aug 05 |
nicklas |
655 |
ok = false; |
1139 |
26 Aug 05 |
nicklas |
656 |
} |
1139 |
26 Aug 05 |
nicklas |
657 |
finally |
1139 |
26 Aug 05 |
nicklas |
658 |
{ |
1139 |
26 Aug 05 |
nicklas |
659 |
if (dc != null) dc.close(); |
1139 |
26 Aug 05 |
nicklas |
660 |
} |
1139 |
26 Aug 05 |
nicklas |
661 |
} |
3820 |
12 Oct 07 |
nicklas |
662 |
|
5026 |
28 Jul 09 |
nicklas |
663 |
static void test_change_arraydesign(int id, int arrayDesignId) |
5026 |
28 Jul 09 |
nicklas |
664 |
{ |
5026 |
28 Jul 09 |
nicklas |
665 |
if (id == 0 || arrayDesignId == 0) return; |
5026 |
28 Jul 09 |
nicklas |
666 |
DbControl dc = null; |
5026 |
28 Jul 09 |
nicklas |
667 |
try |
5026 |
28 Jul 09 |
nicklas |
668 |
{ |
5026 |
28 Jul 09 |
nicklas |
669 |
dc = TestUtil.getDbControl(); |
5026 |
28 Jul 09 |
nicklas |
670 |
RawBioAssay rba = RawBioAssay.getById(dc, id); |
5026 |
28 Jul 09 |
nicklas |
671 |
ArrayDesign ad = ArrayDesign.getById(dc, arrayDesignId); |
5026 |
28 Jul 09 |
nicklas |
672 |
ProgressReporter progress = TestUtil.getSilent() ? |
5026 |
28 Jul 09 |
nicklas |
673 |
null : new ConsoleProgressReporter(); |
5026 |
28 Jul 09 |
nicklas |
674 |
rba.updateArrayDesign(ad, null, progress); |
5026 |
28 Jul 09 |
nicklas |
675 |
dc.commit(); |
5026 |
28 Jul 09 |
nicklas |
676 |
write("--Change array design OK"); |
5026 |
28 Jul 09 |
nicklas |
677 |
} |
5026 |
28 Jul 09 |
nicklas |
678 |
catch (Throwable ex) |
5026 |
28 Jul 09 |
nicklas |
679 |
{ |
5026 |
28 Jul 09 |
nicklas |
680 |
write("--Change array design FAILED"); |
5026 |
28 Jul 09 |
nicklas |
681 |
ex.printStackTrace(); |
5026 |
28 Jul 09 |
nicklas |
682 |
ok = false; |
5026 |
28 Jul 09 |
nicklas |
683 |
} |
5026 |
28 Jul 09 |
nicklas |
684 |
finally |
5026 |
28 Jul 09 |
nicklas |
685 |
{ |
5026 |
28 Jul 09 |
nicklas |
686 |
if (dc != null) dc.close(); |
5026 |
28 Jul 09 |
nicklas |
687 |
} |
5026 |
28 Jul 09 |
nicklas |
688 |
} |
5026 |
28 Jul 09 |
nicklas |
689 |
|
1121 |
24 Aug 05 |
nicklas |
690 |
} |