1470 |
14 Oct 05 |
nicklas |
1 |
/* |
1470 |
14 Oct 05 |
nicklas |
$Id$ |
1470 |
14 Oct 05 |
nicklas |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Johan Enell, Jari Häkkinen, Nicklas Nordborg, Gregory Vincic |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2007 Johan Enell, Nicklas Nordborg |
1470 |
14 Oct 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/ |
1470 |
14 Oct 05 |
nicklas |
10 |
|
1470 |
14 Oct 05 |
nicklas |
BASE is free software; you can redistribute it and/or |
1470 |
14 Oct 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 |
1470 |
14 Oct 05 |
nicklas |
of the License, or (at your option) any later version. |
1470 |
14 Oct 05 |
nicklas |
15 |
|
1470 |
14 Oct 05 |
nicklas |
BASE is distributed in the hope that it will be useful, |
1470 |
14 Oct 05 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1470 |
14 Oct 05 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1470 |
14 Oct 05 |
nicklas |
GNU General Public License for more details. |
1470 |
14 Oct 05 |
nicklas |
20 |
|
1470 |
14 Oct 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/>. |
1470 |
14 Oct 05 |
nicklas |
23 |
*/ |
1470 |
14 Oct 05 |
nicklas |
24 |
|
1575 |
07 Nov 05 |
nicklas |
25 |
|
5228 |
03 Feb 10 |
nicklas |
26 |
|
1470 |
14 Oct 05 |
nicklas |
27 |
import java.util.Date; |
5340 |
10 May 10 |
nicklas |
28 |
import java.util.Set; |
1470 |
14 Oct 05 |
nicklas |
29 |
|
5228 |
03 Feb 10 |
nicklas |
30 |
import net.sf.basedb.core.AnnotationType; |
5228 |
03 Feb 10 |
nicklas |
31 |
import net.sf.basedb.core.BaseException; |
5228 |
03 Feb 10 |
nicklas |
32 |
import net.sf.basedb.core.DbControl; |
5228 |
03 Feb 10 |
nicklas |
33 |
import net.sf.basedb.core.Experiment; |
5228 |
03 Feb 10 |
nicklas |
34 |
import net.sf.basedb.core.Item; |
5340 |
10 May 10 |
nicklas |
35 |
import net.sf.basedb.core.ItemProxy; |
5228 |
03 Feb 10 |
nicklas |
36 |
import net.sf.basedb.core.ItemResultList; |
5228 |
03 Feb 10 |
nicklas |
37 |
import net.sf.basedb.core.Permission; |
5228 |
03 Feb 10 |
nicklas |
38 |
import net.sf.basedb.core.Platform; |
5228 |
03 Feb 10 |
nicklas |
39 |
import net.sf.basedb.core.RawBioAssay; |
5228 |
03 Feb 10 |
nicklas |
40 |
import net.sf.basedb.core.RawDataTypes; |
5228 |
03 Feb 10 |
nicklas |
41 |
import net.sf.basedb.core.Type; |
1767 |
13 Jan 06 |
gregory |
42 |
|
1470 |
14 Oct 05 |
nicklas |
43 |
public class TestExperiment |
1470 |
14 Oct 05 |
nicklas |
44 |
{ |
1470 |
14 Oct 05 |
nicklas |
45 |
|
1470 |
14 Oct 05 |
nicklas |
46 |
static boolean ok = true; |
1470 |
14 Oct 05 |
nicklas |
47 |
public static void main(String[] args) |
1470 |
14 Oct 05 |
nicklas |
48 |
{ |
1470 |
14 Oct 05 |
nicklas |
49 |
TestUtil.checkArgs(args); |
1470 |
14 Oct 05 |
nicklas |
50 |
TestUtil.begin(); |
1470 |
14 Oct 05 |
nicklas |
51 |
ok = test_all(); |
1470 |
14 Oct 05 |
nicklas |
52 |
TestUtil.stop(); |
1470 |
14 Oct 05 |
nicklas |
53 |
} |
1470 |
14 Oct 05 |
nicklas |
54 |
|
1470 |
14 Oct 05 |
nicklas |
55 |
static boolean test_all() |
1470 |
14 Oct 05 |
nicklas |
56 |
{ |
1470 |
14 Oct 05 |
nicklas |
57 |
write("++Testing experiments"); |
1470 |
14 Oct 05 |
nicklas |
58 |
write_header(); |
1470 |
14 Oct 05 |
nicklas |
59 |
|
1470 |
14 Oct 05 |
nicklas |
// Standard tests: create, load, list |
1690 |
05 Dec 05 |
nicklas |
61 |
int id = test_create("genepix", true); |
1690 |
05 Dec 05 |
nicklas |
62 |
int id2 = test_create("genepix", false); |
1470 |
14 Oct 05 |
nicklas |
63 |
|
1470 |
14 Oct 05 |
nicklas |
64 |
test_load(id); |
1470 |
14 Oct 05 |
nicklas |
65 |
test_list(-1); |
1479 |
19 Oct 05 |
nicklas |
66 |
|
3973 |
16 Nov 07 |
nicklas |
// Experimental factors |
4544 |
25 Sep 08 |
nicklas |
68 |
int factorId1 = TestAnnotationType.test_create("Drug resistance", Type.STRING, 0, null, null, Item.RAWBIOASSAY, 1, new String[] { "high", "medium", "low" }, false); |
4544 |
25 Sep 08 |
nicklas |
69 |
int factorId2 = TestAnnotationType.test_create("Temperature", Type.FLOAT, 0, null, null, Item.RAWBIOASSAY, 1, null, false); |
3973 |
16 Nov 07 |
nicklas |
70 |
test_add_experimental_factors(id, factorId1, factorId2); |
3973 |
16 Nov 07 |
nicklas |
71 |
test_list_experimental_factors(id, 2); |
1791 |
18 Jan 06 |
gregory |
72 |
|
1479 |
19 Oct 05 |
nicklas |
// Import reporters |
2959 |
27 Nov 06 |
nicklas |
74 |
TestReporter.test_import_from_file("data/test.rawdata.import.txt", |
3626 |
03 Aug 07 |
nicklas |
75 |
"\"Block\"\\t\"Column\"\\t\"Row\"\\t\"Name\"\\t\"ID\".*", "\\t", 4, 3); |
1479 |
19 Oct 05 |
nicklas |
76 |
|
3820 |
12 Oct 07 |
nicklas |
77 |
int arrayDesignId = TestArrayDesign.test_create(Platform.GENERIC, false); |
2959 |
27 Nov 06 |
nicklas |
78 |
TestArrayDesign.test_import_from_file(arrayDesignId, "data/test.rawdata.import.txt", |
4246 |
24 Apr 08 |
nicklas |
79 |
"\"Block\"\\t\"Column\"\\t\"Row\"\\t\"Name\"\\t\"ID\".*", null, 0, 2, 1, 4); |
1479 |
19 Oct 05 |
nicklas |
80 |
|
5748 |
19 Sep 11 |
nicklas |
81 |
int rbaId1 = TestRawBioAssay.test_create(Platform.GENERIC, "genepix", null, 0, 0, 0, 0, arrayDesignId, false); |
5748 |
19 Sep 11 |
nicklas |
82 |
int rbaId2 = TestRawBioAssay.test_create(Platform.GENERIC, "genepix", null, 0, 0, 0, 0, arrayDesignId, false); |
2959 |
27 Nov 06 |
nicklas |
83 |
TestRawBioAssay.test_import_from_file(rbaId1, "data/test.rawdata.import.txt"); |
2959 |
27 Nov 06 |
nicklas |
84 |
TestRawBioAssay.test_import_from_file(rbaId2, "data/test.rawdata.import.txt"); |
1470 |
14 Oct 05 |
nicklas |
85 |
|
1479 |
19 Oct 05 |
nicklas |
86 |
test_add_rawbioassay(id, rbaId1); |
1479 |
19 Oct 05 |
nicklas |
87 |
test_add_rawbioassay(id, rbaId2); |
1479 |
19 Oct 05 |
nicklas |
88 |
test_list_rawbioassays(id, 2); |
1767 |
13 Jan 06 |
gregory |
89 |
|
1529 |
27 Oct 05 |
nicklas |
90 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
1529 |
27 Oct 05 |
nicklas |
91 |
|
1479 |
19 Oct 05 |
nicklas |
92 |
test_remove_rawbioassay(id, rbaId1); |
1479 |
19 Oct 05 |
nicklas |
93 |
test_remove_rawbioassay(id, rbaId2); |
1529 |
27 Oct 05 |
nicklas |
94 |
|
1499 |
20 Oct 05 |
nicklas |
// Standard test: Delete |
1499 |
20 Oct 05 |
nicklas |
96 |
test_delete(id); |
1499 |
20 Oct 05 |
nicklas |
97 |
test_delete(id2); |
1499 |
20 Oct 05 |
nicklas |
98 |
|
3973 |
16 Nov 07 |
nicklas |
99 |
TestAnnotationType.test_delete(factorId1); |
3973 |
16 Nov 07 |
nicklas |
100 |
TestAnnotationType.test_delete(factorId2); |
1479 |
19 Oct 05 |
nicklas |
101 |
TestRawBioAssay.test_delete(rbaId1); |
1479 |
19 Oct 05 |
nicklas |
102 |
TestRawBioAssay.test_delete(rbaId2); |
1479 |
19 Oct 05 |
nicklas |
103 |
TestArrayDesign.test_delete(arrayDesignId); |
1782 |
18 Jan 06 |
nicklas |
104 |
TestReporter.test_delete(); |
1470 |
14 Oct 05 |
nicklas |
105 |
write("++Testing experiments "+(ok ? "OK" : "Failed")+"\n"); |
1470 |
14 Oct 05 |
nicklas |
106 |
return ok; |
1470 |
14 Oct 05 |
nicklas |
107 |
} |
1470 |
14 Oct 05 |
nicklas |
108 |
|
1470 |
14 Oct 05 |
nicklas |
109 |
static int test_create(String rawDataType, boolean setAll) |
1470 |
14 Oct 05 |
nicklas |
110 |
{ |
1470 |
14 Oct 05 |
nicklas |
111 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.EXPERIMENT)) return 0; |
1470 |
14 Oct 05 |
nicklas |
112 |
int id = 0; |
1470 |
14 Oct 05 |
nicklas |
113 |
DbControl dc = null; |
1470 |
14 Oct 05 |
nicklas |
114 |
try |
1470 |
14 Oct 05 |
nicklas |
115 |
{ |
1470 |
14 Oct 05 |
nicklas |
116 |
dc = TestUtil.getDbControl(); |
4124 |
04 Feb 08 |
nicklas |
117 |
Experiment e = Experiment.getNew(dc, RawDataTypes.getSafeRawDataType(rawDataType)); |
1470 |
14 Oct 05 |
nicklas |
118 |
if (setAll) |
1470 |
14 Oct 05 |
nicklas |
119 |
{ |
1470 |
14 Oct 05 |
nicklas |
120 |
e.setName("Test experiment"); |
1470 |
14 Oct 05 |
nicklas |
121 |
e.setDescription("Added at "+new Date()); |
1470 |
14 Oct 05 |
nicklas |
122 |
e.setAbstract("An abstract"); |
1470 |
14 Oct 05 |
nicklas |
123 |
e.setAffiliations("The affiliations"); |
1470 |
14 Oct 05 |
nicklas |
124 |
e.setAuthors("The authors"); |
1470 |
14 Oct 05 |
nicklas |
125 |
e.setExperimentDesign("A cool design"); |
1470 |
14 Oct 05 |
nicklas |
126 |
e.setExperimentType("The type"); |
1470 |
14 Oct 05 |
nicklas |
127 |
e.setPublication("Here is the publication"); |
1470 |
14 Oct 05 |
nicklas |
128 |
e.setPublicationDate(new Date()); |
1470 |
14 Oct 05 |
nicklas |
129 |
e.setPubMedId("PUBMED-123ABC"); |
1470 |
14 Oct 05 |
nicklas |
130 |
} |
1470 |
14 Oct 05 |
nicklas |
131 |
dc.saveItem(e); |
1470 |
14 Oct 05 |
nicklas |
132 |
dc.commit(); |
1470 |
14 Oct 05 |
nicklas |
133 |
id = e.getId(); |
1470 |
14 Oct 05 |
nicklas |
134 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
135 |
dc.reattachItem(e, false); |
1470 |
14 Oct 05 |
nicklas |
136 |
write_item(0, e); |
1470 |
14 Oct 05 |
nicklas |
137 |
write("--Create experiment OK"); |
1470 |
14 Oct 05 |
nicklas |
138 |
} |
1470 |
14 Oct 05 |
nicklas |
139 |
catch (Throwable ex) |
1470 |
14 Oct 05 |
nicklas |
140 |
{ |
1470 |
14 Oct 05 |
nicklas |
141 |
write("--Create experiment FAILED"); |
1470 |
14 Oct 05 |
nicklas |
142 |
ex.printStackTrace(); |
1470 |
14 Oct 05 |
nicklas |
143 |
ok = false; |
1470 |
14 Oct 05 |
nicklas |
144 |
} |
1470 |
14 Oct 05 |
nicklas |
145 |
finally |
1470 |
14 Oct 05 |
nicklas |
146 |
{ |
1470 |
14 Oct 05 |
nicklas |
147 |
if (dc != null) dc.close(); |
1470 |
14 Oct 05 |
nicklas |
148 |
} |
1470 |
14 Oct 05 |
nicklas |
149 |
return id; |
1470 |
14 Oct 05 |
nicklas |
150 |
} |
1470 |
14 Oct 05 |
nicklas |
151 |
|
1470 |
14 Oct 05 |
nicklas |
152 |
static void test_load(int id) |
1470 |
14 Oct 05 |
nicklas |
153 |
{ |
1470 |
14 Oct 05 |
nicklas |
154 |
if (id == 0) return; |
1470 |
14 Oct 05 |
nicklas |
155 |
DbControl dc = null; |
1470 |
14 Oct 05 |
nicklas |
156 |
try |
1470 |
14 Oct 05 |
nicklas |
157 |
{ |
1470 |
14 Oct 05 |
nicklas |
158 |
dc = TestUtil.getDbControl(); |
1470 |
14 Oct 05 |
nicklas |
159 |
Experiment e = Experiment.getById(dc, id); |
1470 |
14 Oct 05 |
nicklas |
160 |
write_item(0, e); |
1470 |
14 Oct 05 |
nicklas |
161 |
write("--Load experiment OK"); |
1470 |
14 Oct 05 |
nicklas |
162 |
} |
1470 |
14 Oct 05 |
nicklas |
163 |
catch (Throwable ex) |
1470 |
14 Oct 05 |
nicklas |
164 |
{ |
1470 |
14 Oct 05 |
nicklas |
165 |
write("--Load experiment FAILED"); |
1470 |
14 Oct 05 |
nicklas |
166 |
ex.printStackTrace(); |
1470 |
14 Oct 05 |
nicklas |
167 |
ok = false; |
1470 |
14 Oct 05 |
nicklas |
168 |
} |
1470 |
14 Oct 05 |
nicklas |
169 |
finally |
1470 |
14 Oct 05 |
nicklas |
170 |
{ |
1470 |
14 Oct 05 |
nicklas |
171 |
if (dc != null) dc.close(); |
1470 |
14 Oct 05 |
nicklas |
172 |
} |
1470 |
14 Oct 05 |
nicklas |
173 |
} |
1470 |
14 Oct 05 |
nicklas |
174 |
|
1470 |
14 Oct 05 |
nicklas |
175 |
static void test_list(int expectedResults) |
1470 |
14 Oct 05 |
nicklas |
176 |
{ |
1470 |
14 Oct 05 |
nicklas |
177 |
DbControl dc = null; |
1470 |
14 Oct 05 |
nicklas |
178 |
try |
1470 |
14 Oct 05 |
nicklas |
179 |
{ |
1470 |
14 Oct 05 |
nicklas |
180 |
dc = TestUtil.getDbControl(); |
1470 |
14 Oct 05 |
nicklas |
181 |
ItemResultList<Experiment> l = Experiment.getQuery().list(dc); |
1470 |
14 Oct 05 |
nicklas |
182 |
for (int i = 0; i<l.size(); i++) |
1470 |
14 Oct 05 |
nicklas |
183 |
{ |
1470 |
14 Oct 05 |
nicklas |
184 |
write_item(i, l.get(i)); |
1470 |
14 Oct 05 |
nicklas |
185 |
} |
1470 |
14 Oct 05 |
nicklas |
186 |
if (expectedResults >= 0 && expectedResults != l.size()) |
1470 |
14 Oct 05 |
nicklas |
187 |
{ |
1470 |
14 Oct 05 |
nicklas |
188 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
1470 |
14 Oct 05 |
nicklas |
189 |
} |
1470 |
14 Oct 05 |
nicklas |
190 |
write("--List experiments OK ("+l.size()+")"); |
1470 |
14 Oct 05 |
nicklas |
191 |
} |
1470 |
14 Oct 05 |
nicklas |
192 |
catch (Throwable ex) |
1470 |
14 Oct 05 |
nicklas |
193 |
{ |
1470 |
14 Oct 05 |
nicklas |
194 |
write("--List experiments FAILED"); |
1470 |
14 Oct 05 |
nicklas |
195 |
ex.printStackTrace(); |
1470 |
14 Oct 05 |
nicklas |
196 |
ok = false; |
1470 |
14 Oct 05 |
nicklas |
197 |
} |
1470 |
14 Oct 05 |
nicklas |
198 |
finally |
1470 |
14 Oct 05 |
nicklas |
199 |
{ |
1470 |
14 Oct 05 |
nicklas |
200 |
if (dc != null) dc.close(); |
1470 |
14 Oct 05 |
nicklas |
201 |
} |
1470 |
14 Oct 05 |
nicklas |
202 |
} |
1470 |
14 Oct 05 |
nicklas |
203 |
|
1470 |
14 Oct 05 |
nicklas |
204 |
static void test_delete(int id) |
1470 |
14 Oct 05 |
nicklas |
205 |
{ |
1470 |
14 Oct 05 |
nicklas |
206 |
if (id == 0) return; |
1470 |
14 Oct 05 |
nicklas |
207 |
DbControl dc = null; |
1470 |
14 Oct 05 |
nicklas |
208 |
try |
1470 |
14 Oct 05 |
nicklas |
209 |
{ |
1470 |
14 Oct 05 |
nicklas |
210 |
dc = TestUtil.getDbControl(); |
1470 |
14 Oct 05 |
nicklas |
211 |
Experiment e = Experiment.getById(dc, id); |
1470 |
14 Oct 05 |
nicklas |
212 |
dc.deleteItem(e); |
5340 |
10 May 10 |
nicklas |
213 |
Set<ItemProxy> using = e.getUsingItems(); |
5340 |
10 May 10 |
nicklas |
214 |
if (using.size() > 0) |
5340 |
10 May 10 |
nicklas |
215 |
{ |
5340 |
10 May 10 |
nicklas |
216 |
throw new BaseException(e + " is used by " + using); |
5340 |
10 May 10 |
nicklas |
217 |
} |
1470 |
14 Oct 05 |
nicklas |
218 |
dc.commit(); |
1470 |
14 Oct 05 |
nicklas |
219 |
write("--Delete experiment OK"); |
1470 |
14 Oct 05 |
nicklas |
220 |
} |
1470 |
14 Oct 05 |
nicklas |
221 |
catch (Throwable ex) |
1470 |
14 Oct 05 |
nicklas |
222 |
{ |
1470 |
14 Oct 05 |
nicklas |
223 |
write("--Delete experiment FAILED"); |
1470 |
14 Oct 05 |
nicklas |
224 |
ex.printStackTrace(); |
1470 |
14 Oct 05 |
nicklas |
225 |
ok = false; |
1470 |
14 Oct 05 |
nicklas |
226 |
} |
1470 |
14 Oct 05 |
nicklas |
227 |
finally |
1470 |
14 Oct 05 |
nicklas |
228 |
{ |
1470 |
14 Oct 05 |
nicklas |
229 |
if (dc != null) dc.close(); |
1470 |
14 Oct 05 |
nicklas |
230 |
} |
1470 |
14 Oct 05 |
nicklas |
231 |
} |
1470 |
14 Oct 05 |
nicklas |
232 |
|
1470 |
14 Oct 05 |
nicklas |
233 |
static void write_header() |
1470 |
14 Oct 05 |
nicklas |
234 |
{ |
1470 |
14 Oct 05 |
nicklas |
235 |
if (!TestUtil.getSilent()) |
1470 |
14 Oct 05 |
nicklas |
236 |
{ |
1470 |
14 Oct 05 |
nicklas |
237 |
write(" \tID \tName \tRaw data type\tDescription\tAbstract\tAffiliations\tAuthors\tDesign\tType\tPublication\tDate\tPubMed ID"); |
1470 |
14 Oct 05 |
nicklas |
238 |
write("-- \t-- \t--------- \t-------------\t-----------\t--------\t------------\t-------\t------\t----\t-----------\t----\t---------"); |
1470 |
14 Oct 05 |
nicklas |
239 |
} |
1470 |
14 Oct 05 |
nicklas |
240 |
} |
1470 |
14 Oct 05 |
nicklas |
241 |
static void write_item(int i, Experiment e) |
1470 |
14 Oct 05 |
nicklas |
242 |
throws BaseException |
1470 |
14 Oct 05 |
nicklas |
243 |
{ |
1470 |
14 Oct 05 |
nicklas |
244 |
if (!TestUtil.getSilent()) |
1470 |
14 Oct 05 |
nicklas |
245 |
{ |
1470 |
14 Oct 05 |
nicklas |
246 |
System.out.println(i+":\t"+e.getId()+"\t"+e.getName()+"\t"+e.getRawDataType().getName()+"\t"+e.getDescription()+ |
1470 |
14 Oct 05 |
nicklas |
247 |
"\t"+e.getAbstract()+"\t"+e.getAffiliations()+"\t"+e.getAuthors()+ |
1470 |
14 Oct 05 |
nicklas |
248 |
"\t"+e.getExperimentDesign()+"\t"+e.getExperimentType()+"\t"+e.getPublication()+ |
1470 |
14 Oct 05 |
nicklas |
249 |
"\t"+e.getPublicationDate()+"\t"+e.getPubMedId()); |
1470 |
14 Oct 05 |
nicklas |
250 |
} |
1470 |
14 Oct 05 |
nicklas |
251 |
} |
1479 |
19 Oct 05 |
nicklas |
252 |
static void write_item(int i, RawBioAssay rba) |
1479 |
19 Oct 05 |
nicklas |
253 |
throws BaseException |
1479 |
19 Oct 05 |
nicklas |
254 |
{ |
1479 |
19 Oct 05 |
nicklas |
255 |
if (!TestUtil.getSilent()) |
1479 |
19 Oct 05 |
nicklas |
256 |
{ |
1479 |
19 Oct 05 |
nicklas |
257 |
System.out.println(i+":\t"+rba.getId()+"\t"+rba.getName()+"\t"+rba.getDescription()+ |
3820 |
12 Oct 07 |
nicklas |
258 |
"\t"+rba.getRawDataType().getName()+"\t"+rba.getNumDbSpots()+"\t"+rba.getBytes()+"\t"+rba.getArrayDesign()+ |
1479 |
19 Oct 05 |
nicklas |
259 |
"\t"+rba.getSoftware()+"\t"+rba.getProtocol()); |
1479 |
19 Oct 05 |
nicklas |
260 |
} |
1479 |
19 Oct 05 |
nicklas |
261 |
} |
1567 |
04 Nov 05 |
nicklas |
262 |
|
1470 |
14 Oct 05 |
nicklas |
263 |
static void write(String message) |
1470 |
14 Oct 05 |
nicklas |
264 |
{ |
1470 |
14 Oct 05 |
nicklas |
265 |
System.out.println(message); |
1470 |
14 Oct 05 |
nicklas |
266 |
} |
1470 |
14 Oct 05 |
nicklas |
267 |
|
4740 |
05 Feb 09 |
nicklas |
268 |
static void test_add_rawbioassay(int id, int... rawBioAssayId) |
1479 |
19 Oct 05 |
nicklas |
269 |
{ |
4740 |
05 Feb 09 |
nicklas |
270 |
if (id == 0) return; |
1479 |
19 Oct 05 |
nicklas |
271 |
DbControl dc = null; |
1479 |
19 Oct 05 |
nicklas |
272 |
try |
1479 |
19 Oct 05 |
nicklas |
273 |
{ |
1479 |
19 Oct 05 |
nicklas |
274 |
dc = TestUtil.getDbControl(); |
1479 |
19 Oct 05 |
nicklas |
275 |
Experiment e = Experiment.getById(dc, id); |
4740 |
05 Feb 09 |
nicklas |
276 |
for (int rbaId : rawBioAssayId) |
4740 |
05 Feb 09 |
nicklas |
277 |
{ |
4740 |
05 Feb 09 |
nicklas |
278 |
RawBioAssay rba = RawBioAssay.getById(dc, rbaId); |
4740 |
05 Feb 09 |
nicklas |
279 |
e.addRawBioAssay(rba); |
4740 |
05 Feb 09 |
nicklas |
280 |
} |
1479 |
19 Oct 05 |
nicklas |
281 |
dc.commit(); |
4740 |
05 Feb 09 |
nicklas |
282 |
write("--Add raw bioassays OK"); |
1479 |
19 Oct 05 |
nicklas |
283 |
} |
1479 |
19 Oct 05 |
nicklas |
284 |
catch (Throwable ex) |
1479 |
19 Oct 05 |
nicklas |
285 |
{ |
4740 |
05 Feb 09 |
nicklas |
286 |
write("--Add raw bioassays FAILED"); |
1479 |
19 Oct 05 |
nicklas |
287 |
ex.printStackTrace(); |
1479 |
19 Oct 05 |
nicklas |
288 |
ok = false; |
1479 |
19 Oct 05 |
nicklas |
289 |
} |
1479 |
19 Oct 05 |
nicklas |
290 |
finally |
1479 |
19 Oct 05 |
nicklas |
291 |
{ |
1479 |
19 Oct 05 |
nicklas |
292 |
if (dc != null) dc.close(); |
1479 |
19 Oct 05 |
nicklas |
293 |
} |
1479 |
19 Oct 05 |
nicklas |
294 |
} |
1479 |
19 Oct 05 |
nicklas |
295 |
|
1479 |
19 Oct 05 |
nicklas |
296 |
static void test_remove_rawbioassay(int id, int rawBioAssayId) |
1479 |
19 Oct 05 |
nicklas |
297 |
{ |
1479 |
19 Oct 05 |
nicklas |
298 |
if (id == 0 || rawBioAssayId == 0) return; |
1479 |
19 Oct 05 |
nicklas |
299 |
DbControl dc = null; |
1479 |
19 Oct 05 |
nicklas |
300 |
try |
1479 |
19 Oct 05 |
nicklas |
301 |
{ |
1479 |
19 Oct 05 |
nicklas |
302 |
dc = TestUtil.getDbControl(); |
1479 |
19 Oct 05 |
nicklas |
303 |
Experiment e = Experiment.getById(dc, id); |
1479 |
19 Oct 05 |
nicklas |
304 |
RawBioAssay rba = RawBioAssay.getById(dc, rawBioAssayId); |
1479 |
19 Oct 05 |
nicklas |
305 |
e.removeRawBioAssay(rba); |
1479 |
19 Oct 05 |
nicklas |
306 |
dc.commit(); |
1479 |
19 Oct 05 |
nicklas |
307 |
write("--Remove raw bioassay OK"); |
1479 |
19 Oct 05 |
nicklas |
308 |
} |
1479 |
19 Oct 05 |
nicklas |
309 |
catch (Throwable ex) |
1479 |
19 Oct 05 |
nicklas |
310 |
{ |
1479 |
19 Oct 05 |
nicklas |
311 |
write("--Remove raw bioassay FAILED"); |
1479 |
19 Oct 05 |
nicklas |
312 |
ex.printStackTrace(); |
1479 |
19 Oct 05 |
nicklas |
313 |
ok = false; |
1479 |
19 Oct 05 |
nicklas |
314 |
} |
1479 |
19 Oct 05 |
nicklas |
315 |
finally |
1479 |
19 Oct 05 |
nicklas |
316 |
{ |
1479 |
19 Oct 05 |
nicklas |
317 |
if (dc != null) dc.close(); |
1479 |
19 Oct 05 |
nicklas |
318 |
} |
1479 |
19 Oct 05 |
nicklas |
319 |
} |
1479 |
19 Oct 05 |
nicklas |
320 |
|
4232 |
17 Apr 08 |
nicklas |
321 |
static int[] test_list_rawbioassays(int id, int expectedResults) |
1479 |
19 Oct 05 |
nicklas |
322 |
{ |
4232 |
17 Apr 08 |
nicklas |
323 |
if (id == 0) return null; |
1479 |
19 Oct 05 |
nicklas |
324 |
DbControl dc = null; |
4232 |
17 Apr 08 |
nicklas |
325 |
int[] rawBioAssays = null; |
1479 |
19 Oct 05 |
nicklas |
326 |
try |
1479 |
19 Oct 05 |
nicklas |
327 |
{ |
1479 |
19 Oct 05 |
nicklas |
328 |
dc = TestUtil.getDbControl(); |
1479 |
19 Oct 05 |
nicklas |
329 |
Experiment e = Experiment.getById(dc, id); |
1479 |
19 Oct 05 |
nicklas |
330 |
|
1479 |
19 Oct 05 |
nicklas |
331 |
ItemResultList<RawBioAssay> l = e.getRawBioAssays().list(dc); |
4232 |
17 Apr 08 |
nicklas |
332 |
rawBioAssays = new int[l.size()]; |
1479 |
19 Oct 05 |
nicklas |
333 |
for (int i = 0; i<l.size(); i++) |
1479 |
19 Oct 05 |
nicklas |
334 |
{ |
4232 |
17 Apr 08 |
nicklas |
335 |
rawBioAssays[i] = l.get(i).getId(); |
1479 |
19 Oct 05 |
nicklas |
336 |
write_item(i, l.get(i)); |
1479 |
19 Oct 05 |
nicklas |
337 |
} |
1479 |
19 Oct 05 |
nicklas |
338 |
if (expectedResults >= 0 && expectedResults != l.size()) |
1479 |
19 Oct 05 |
nicklas |
339 |
{ |
1479 |
19 Oct 05 |
nicklas |
340 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
1479 |
19 Oct 05 |
nicklas |
341 |
} |
1479 |
19 Oct 05 |
nicklas |
342 |
write("--List raw bioassays OK ("+l.size()+")"); |
1479 |
19 Oct 05 |
nicklas |
343 |
} |
1479 |
19 Oct 05 |
nicklas |
344 |
catch (Throwable ex) |
1479 |
19 Oct 05 |
nicklas |
345 |
{ |
1479 |
19 Oct 05 |
nicklas |
346 |
write("--List raw bioassays FAILED"); |
1479 |
19 Oct 05 |
nicklas |
347 |
ex.printStackTrace(); |
1479 |
19 Oct 05 |
nicklas |
348 |
ok = false; |
1479 |
19 Oct 05 |
nicklas |
349 |
} |
1479 |
19 Oct 05 |
nicklas |
350 |
finally |
1479 |
19 Oct 05 |
nicklas |
351 |
{ |
1479 |
19 Oct 05 |
nicklas |
352 |
if (dc != null) dc.close(); |
1479 |
19 Oct 05 |
nicklas |
353 |
} |
4232 |
17 Apr 08 |
nicklas |
354 |
return rawBioAssays; |
1479 |
19 Oct 05 |
nicklas |
355 |
} |
1499 |
20 Oct 05 |
nicklas |
356 |
|
3973 |
16 Nov 07 |
nicklas |
357 |
static void test_add_experimental_factors(int id, int... annotationTypes) |
3973 |
16 Nov 07 |
nicklas |
358 |
{ |
3973 |
16 Nov 07 |
nicklas |
359 |
if (id == 0) return; |
3973 |
16 Nov 07 |
nicklas |
360 |
DbControl dc = null; |
3973 |
16 Nov 07 |
nicklas |
361 |
try |
3973 |
16 Nov 07 |
nicklas |
362 |
{ |
3973 |
16 Nov 07 |
nicklas |
363 |
dc = TestUtil.getDbControl(); |
3973 |
16 Nov 07 |
nicklas |
364 |
Experiment e = Experiment.getById(dc, id); |
3973 |
16 Nov 07 |
nicklas |
365 |
for (int atId : annotationTypes) |
3973 |
16 Nov 07 |
nicklas |
366 |
{ |
3973 |
16 Nov 07 |
nicklas |
367 |
AnnotationType at = AnnotationType.getById(dc, atId); |
3973 |
16 Nov 07 |
nicklas |
368 |
e.addExperimentalFactor(at); |
3973 |
16 Nov 07 |
nicklas |
369 |
} |
3973 |
16 Nov 07 |
nicklas |
370 |
dc.commit(); |
3973 |
16 Nov 07 |
nicklas |
371 |
write("--Add experimental factors OK"); |
3973 |
16 Nov 07 |
nicklas |
372 |
} |
3973 |
16 Nov 07 |
nicklas |
373 |
catch (Throwable ex) |
3973 |
16 Nov 07 |
nicklas |
374 |
{ |
3973 |
16 Nov 07 |
nicklas |
375 |
write("--Add experimental factors FAILED"); |
3973 |
16 Nov 07 |
nicklas |
376 |
ex.printStackTrace(); |
3973 |
16 Nov 07 |
nicklas |
377 |
ok = false; |
3973 |
16 Nov 07 |
nicklas |
378 |
} |
3973 |
16 Nov 07 |
nicklas |
379 |
finally |
3973 |
16 Nov 07 |
nicklas |
380 |
{ |
3973 |
16 Nov 07 |
nicklas |
381 |
if (dc != null) dc.close(); |
3973 |
16 Nov 07 |
nicklas |
382 |
} |
3973 |
16 Nov 07 |
nicklas |
383 |
} |
3973 |
16 Nov 07 |
nicklas |
384 |
|
3973 |
16 Nov 07 |
nicklas |
385 |
static void test_remove_experimental_factors(int id, int... annotationTypes) |
3973 |
16 Nov 07 |
nicklas |
386 |
{ |
3973 |
16 Nov 07 |
nicklas |
387 |
if (id == 0) return; |
3973 |
16 Nov 07 |
nicklas |
388 |
DbControl dc = null; |
3973 |
16 Nov 07 |
nicklas |
389 |
try |
3973 |
16 Nov 07 |
nicklas |
390 |
{ |
3973 |
16 Nov 07 |
nicklas |
391 |
dc = TestUtil.getDbControl(); |
3973 |
16 Nov 07 |
nicklas |
392 |
Experiment e = Experiment.getById(dc, id); |
3973 |
16 Nov 07 |
nicklas |
393 |
for (int atId : annotationTypes) |
3973 |
16 Nov 07 |
nicklas |
394 |
{ |
3973 |
16 Nov 07 |
nicklas |
395 |
AnnotationType at = AnnotationType.getById(dc, atId); |
3973 |
16 Nov 07 |
nicklas |
396 |
e.removeExperimentalFactor(at); |
3973 |
16 Nov 07 |
nicklas |
397 |
} |
3973 |
16 Nov 07 |
nicklas |
398 |
dc.commit(); |
3973 |
16 Nov 07 |
nicklas |
399 |
write("--Remove experimental factors OK"); |
3973 |
16 Nov 07 |
nicklas |
400 |
} |
3973 |
16 Nov 07 |
nicklas |
401 |
catch (Throwable ex) |
3973 |
16 Nov 07 |
nicklas |
402 |
{ |
3973 |
16 Nov 07 |
nicklas |
403 |
write("--Remove experimental factors FAILED"); |
3973 |
16 Nov 07 |
nicklas |
404 |
ex.printStackTrace(); |
3973 |
16 Nov 07 |
nicklas |
405 |
ok = false; |
3973 |
16 Nov 07 |
nicklas |
406 |
} |
3973 |
16 Nov 07 |
nicklas |
407 |
finally |
3973 |
16 Nov 07 |
nicklas |
408 |
{ |
3973 |
16 Nov 07 |
nicklas |
409 |
if (dc != null) dc.close(); |
3973 |
16 Nov 07 |
nicklas |
410 |
} |
3973 |
16 Nov 07 |
nicklas |
411 |
} |
3973 |
16 Nov 07 |
nicklas |
412 |
|
3973 |
16 Nov 07 |
nicklas |
413 |
static void test_list_experimental_factors(int id, int expectedResults) |
3973 |
16 Nov 07 |
nicklas |
414 |
{ |
3973 |
16 Nov 07 |
nicklas |
415 |
if (id == 0) return; |
3973 |
16 Nov 07 |
nicklas |
416 |
DbControl dc = null; |
3973 |
16 Nov 07 |
nicklas |
417 |
try |
3973 |
16 Nov 07 |
nicklas |
418 |
{ |
3973 |
16 Nov 07 |
nicklas |
419 |
dc = TestUtil.getDbControl(); |
3973 |
16 Nov 07 |
nicklas |
420 |
Experiment e = Experiment.getById(dc, id); |
3973 |
16 Nov 07 |
nicklas |
421 |
|
3973 |
16 Nov 07 |
nicklas |
422 |
ItemResultList<AnnotationType> l = e.getExperimentalFactors().list(dc); |
3973 |
16 Nov 07 |
nicklas |
423 |
for (int i = 0; i<l.size(); i++) |
3973 |
16 Nov 07 |
nicklas |
424 |
{ |
3973 |
16 Nov 07 |
nicklas |
425 |
TestAnnotationType.write_item(i, l.get(i)); |
3973 |
16 Nov 07 |
nicklas |
426 |
} |
3973 |
16 Nov 07 |
nicklas |
427 |
if (expectedResults >= 0 && expectedResults != l.size()) |
3973 |
16 Nov 07 |
nicklas |
428 |
{ |
3973 |
16 Nov 07 |
nicklas |
429 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
3973 |
16 Nov 07 |
nicklas |
430 |
} |
3973 |
16 Nov 07 |
nicklas |
431 |
write("--List experimental factors OK ("+l.size()+")"); |
3973 |
16 Nov 07 |
nicklas |
432 |
} |
3973 |
16 Nov 07 |
nicklas |
433 |
catch (Throwable ex) |
3973 |
16 Nov 07 |
nicklas |
434 |
{ |
3973 |
16 Nov 07 |
nicklas |
435 |
write("--List experimental factors FAILED"); |
3973 |
16 Nov 07 |
nicklas |
436 |
ex.printStackTrace(); |
3973 |
16 Nov 07 |
nicklas |
437 |
ok = false; |
3973 |
16 Nov 07 |
nicklas |
438 |
} |
3973 |
16 Nov 07 |
nicklas |
439 |
finally |
3973 |
16 Nov 07 |
nicklas |
440 |
{ |
3973 |
16 Nov 07 |
nicklas |
441 |
if (dc != null) dc.close(); |
3973 |
16 Nov 07 |
nicklas |
442 |
} |
3973 |
16 Nov 07 |
nicklas |
443 |
} |
1767 |
13 Jan 06 |
gregory |
444 |
|
1470 |
14 Oct 05 |
nicklas |
445 |
} |