739 |
09 Jun 05 |
nicklas |
1 |
/* |
739 |
09 Jun 05 |
nicklas |
$Id$ |
739 |
09 Jun 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 |
739 |
09 Jun 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/ |
739 |
09 Jun 05 |
nicklas |
10 |
|
739 |
09 Jun 05 |
nicklas |
BASE is free software; you can redistribute it and/or |
739 |
09 Jun 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 |
739 |
09 Jun 05 |
nicklas |
of the License, or (at your option) any later version. |
739 |
09 Jun 05 |
nicklas |
15 |
|
739 |
09 Jun 05 |
nicklas |
BASE is distributed in the hope that it will be useful, |
739 |
09 Jun 05 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
739 |
09 Jun 05 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
739 |
09 Jun 05 |
nicklas |
GNU General Public License for more details. |
739 |
09 Jun 05 |
nicklas |
20 |
|
739 |
09 Jun 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/>. |
739 |
09 Jun 05 |
nicklas |
23 |
*/ |
1401 |
04 Oct 05 |
enell |
24 |
import net.sf.basedb.core.ArrayDesign; |
1401 |
04 Oct 05 |
enell |
25 |
import net.sf.basedb.core.ArrayDesignBlock; |
1401 |
04 Oct 05 |
enell |
26 |
import net.sf.basedb.core.BaseException; |
1401 |
04 Oct 05 |
enell |
27 |
import net.sf.basedb.core.BlockInfo; |
5026 |
28 Jul 09 |
nicklas |
28 |
import net.sf.basedb.core.DataQuery; |
1401 |
04 Oct 05 |
enell |
29 |
import net.sf.basedb.core.DbControl; |
1401 |
04 Oct 05 |
enell |
30 |
import net.sf.basedb.core.Feature; |
1401 |
04 Oct 05 |
enell |
31 |
import net.sf.basedb.core.FeatureBatcher; |
4093 |
18 Jan 08 |
enell |
32 |
import net.sf.basedb.core.FeatureIdentificationMethod; |
3820 |
12 Oct 07 |
nicklas |
33 |
import net.sf.basedb.core.File; |
3820 |
12 Oct 07 |
nicklas |
34 |
import net.sf.basedb.core.FileSetMember; |
3820 |
12 Oct 07 |
nicklas |
35 |
import net.sf.basedb.core.DataFileType; |
1401 |
04 Oct 05 |
enell |
36 |
import net.sf.basedb.core.Item; |
4097 |
23 Jan 08 |
nicklas |
37 |
import net.sf.basedb.core.ItemAlreadyExistsException; |
5764 |
27 Sep 11 |
nicklas |
38 |
import net.sf.basedb.core.ItemNotFoundException; |
5340 |
10 May 10 |
nicklas |
39 |
import net.sf.basedb.core.ItemProxy; |
1401 |
04 Oct 05 |
enell |
40 |
import net.sf.basedb.core.Permission; |
1418 |
07 Oct 05 |
nicklas |
41 |
import net.sf.basedb.core.ItemQuery; |
1418 |
07 Oct 05 |
nicklas |
42 |
import net.sf.basedb.core.DataResultIterator; |
1719 |
15 Dec 05 |
enell |
43 |
import net.sf.basedb.core.Plate; |
3820 |
12 Oct 07 |
nicklas |
44 |
import net.sf.basedb.core.Platform; |
5764 |
27 Sep 11 |
nicklas |
45 |
import net.sf.basedb.core.PlatformVariant; |
1534 |
27 Oct 05 |
enell |
46 |
import net.sf.basedb.core.Reporter; |
1401 |
04 Oct 05 |
enell |
47 |
import net.sf.basedb.core.ReporterBatcher; |
1418 |
07 Oct 05 |
nicklas |
48 |
import net.sf.basedb.core.ItemResultList; |
4434 |
02 Sep 08 |
nicklas |
49 |
import net.sf.basedb.core.Trashcan; |
1719 |
15 Dec 05 |
enell |
50 |
import net.sf.basedb.core.Well; |
1143 |
29 Aug 05 |
nicklas |
51 |
import net.sf.basedb.core.data.FeatureData; |
1143 |
29 Aug 05 |
nicklas |
52 |
import net.sf.basedb.core.data.ReporterData; |
5026 |
28 Jul 09 |
nicklas |
53 |
import net.sf.basedb.core.query.Hql; |
1143 |
29 Aug 05 |
nicklas |
54 |
import net.sf.basedb.util.FileUtil; |
2203 |
28 Apr 06 |
nicklas |
55 |
import net.sf.basedb.util.parser.FlatFileParser; |
739 |
09 Jun 05 |
nicklas |
56 |
|
1534 |
27 Oct 05 |
enell |
57 |
import java.util.ArrayList; |
739 |
09 Jun 05 |
nicklas |
58 |
import java.util.Date; |
4434 |
02 Sep 08 |
nicklas |
59 |
import java.util.List; |
5340 |
10 May 10 |
nicklas |
60 |
import java.util.Set; |
1143 |
29 Aug 05 |
nicklas |
61 |
import java.util.regex.Pattern; |
739 |
09 Jun 05 |
nicklas |
62 |
|
739 |
09 Jun 05 |
nicklas |
63 |
public class TestArrayDesign |
739 |
09 Jun 05 |
nicklas |
64 |
{ |
739 |
09 Jun 05 |
nicklas |
65 |
|
739 |
09 Jun 05 |
nicklas |
66 |
static boolean ok = true; |
739 |
09 Jun 05 |
nicklas |
67 |
public static void main(String[] args) |
739 |
09 Jun 05 |
nicklas |
68 |
{ |
739 |
09 Jun 05 |
nicklas |
69 |
TestUtil.checkArgs(args); |
739 |
09 Jun 05 |
nicklas |
70 |
TestUtil.begin(); |
739 |
09 Jun 05 |
nicklas |
71 |
ok = test_all(); |
739 |
09 Jun 05 |
nicklas |
72 |
TestUtil.stop(); |
739 |
09 Jun 05 |
nicklas |
73 |
} |
739 |
09 Jun 05 |
nicklas |
74 |
|
739 |
09 Jun 05 |
nicklas |
75 |
static boolean test_all() |
739 |
09 Jun 05 |
nicklas |
76 |
{ |
739 |
09 Jun 05 |
nicklas |
77 |
write("++Testing array design"); |
739 |
09 Jun 05 |
nicklas |
78 |
write_header(); |
739 |
09 Jun 05 |
nicklas |
// Standard tests: create, load, list |
3820 |
12 Oct 07 |
nicklas |
80 |
int id = test_create(Platform.GENERIC, true); |
3820 |
12 Oct 07 |
nicklas |
81 |
int id2 = test_create(Platform.GENERIC, false); |
3820 |
12 Oct 07 |
nicklas |
82 |
int id3 = test_create(Platform.AFFYMETRIX, true); |
3820 |
12 Oct 07 |
nicklas |
83 |
int id4 = test_create(Platform.AFFYMETRIX, false); |
4093 |
18 Jan 08 |
enell |
84 |
int id6 = test_create(Platform.GENERIC, false); |
739 |
09 Jun 05 |
nicklas |
85 |
test_load(id); |
739 |
09 Jun 05 |
nicklas |
86 |
test_list(-1); |
739 |
09 Jun 05 |
nicklas |
87 |
|
2959 |
27 Nov 06 |
nicklas |
88 |
TestReporter.test_import_from_file("data/test.reportermap.import.txt", |
3626 |
03 Aug 07 |
nicklas |
89 |
"\"Block\"\\t\"Column\"\\t\"Row\"\\t\"ID\"\\t\"Name\".*", "\\t", 3, 4); |
2959 |
27 Nov 06 |
nicklas |
90 |
test_import_from_file(id2, "data/test.reportermap.import.txt", |
4246 |
24 Apr 08 |
nicklas |
91 |
"\"Block\"\\t\"Column\"\\t\"Row\"\\t\"ID\"\\t\"Name\".*", null, 0, 2, 1, 3); |
4093 |
18 Jan 08 |
enell |
92 |
test_add_features(id, FeatureIdentificationMethod.COORDINATES, 10); |
4093 |
18 Jan 08 |
enell |
93 |
test_add_features(id6, FeatureIdentificationMethod.FEATURE_ID, 10); |
1143 |
29 Aug 05 |
nicklas |
94 |
|
1143 |
29 Aug 05 |
nicklas |
95 |
write_feature_header(); |
1143 |
29 Aug 05 |
nicklas |
96 |
test_list_features(id, -1); |
1143 |
29 Aug 05 |
nicklas |
97 |
test_list_features(id3, -1); |
1719 |
15 Dec 05 |
enell |
98 |
|
1719 |
15 Dec 05 |
enell |
// Create arraydesign with wells |
2959 |
27 Nov 06 |
nicklas |
100 |
TestReporter.test_import_from_file("data/test.plate96.import.txt", |
3626 |
03 Aug 07 |
nicklas |
101 |
"Plate\\tRow\\tColumn\\tCluster ID\\tClone ID\\tGene Symbol\\tBarcode", "\\t", 4, 5); |
1719 |
15 Dec 05 |
enell |
102 |
int plateGeometry = TestPlateGeometry.test_create(8, 12, false); |
1719 |
15 Dec 05 |
enell |
103 |
int plateType = TestPlateType.test_create(plateGeometry, false); |
2959 |
27 Nov 06 |
nicklas |
104 |
int[] plateIds = TestPlate.test_import_from_file("data/test.plate96.import.txt", |
2959 |
27 Nov 06 |
nicklas |
105 |
"Plate\\tRow\\tColumn\\tCluster ID\\tClone ID\\tGene Symbol\\tBarcode", plateType, 0, 1, 2, 4); |
3820 |
12 Oct 07 |
nicklas |
106 |
int id5 = test_create(Platform.GENERIC, false); |
1719 |
15 Dec 05 |
enell |
107 |
test_add_plates(id5, plateIds); |
1719 |
15 Dec 05 |
enell |
108 |
|
1719 |
15 Dec 05 |
enell |
109 |
write_plate_header(); |
1719 |
15 Dec 05 |
enell |
110 |
test_list_plates(id5, plateIds.length); |
1719 |
15 Dec 05 |
enell |
111 |
|
1719 |
15 Dec 05 |
enell |
112 |
test_add_features_from_wells(id5, plateIds, 10); |
1719 |
15 Dec 05 |
enell |
113 |
|
3820 |
12 Oct 07 |
nicklas |
// Array designs with data in files |
3820 |
12 Oct 07 |
nicklas |
115 |
int cdfId = TestFile.test_create("data/test.affymetrix.cdf", false, false); |
3820 |
12 Oct 07 |
nicklas |
116 |
test_set_file(id3, DataFileType.AFFYMETRIX_CDF, cdfId); |
3820 |
12 Oct 07 |
nicklas |
117 |
test_list_files(id3, 1); |
3820 |
12 Oct 07 |
nicklas |
118 |
|
1529 |
27 Oct 05 |
nicklas |
119 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
739 |
09 Jun 05 |
nicklas |
// Standard test: Delete |
739 |
09 Jun 05 |
nicklas |
121 |
test_delete(id); |
739 |
09 Jun 05 |
nicklas |
122 |
test_delete(id2); |
974 |
20 Jul 05 |
enell |
123 |
test_delete(id3); |
974 |
20 Jul 05 |
enell |
124 |
test_delete(id4); |
1719 |
15 Dec 05 |
enell |
125 |
test_delete(id5); |
4093 |
18 Jan 08 |
enell |
126 |
test_delete(id6); |
1143 |
29 Aug 05 |
nicklas |
127 |
|
1719 |
15 Dec 05 |
enell |
128 |
TestPlate.test_delete_all(); |
1719 |
15 Dec 05 |
enell |
129 |
TestPlateType.test_delete(plateType); |
1719 |
15 Dec 05 |
enell |
130 |
TestPlateGeometry.test_delete(plateGeometry); |
3820 |
12 Oct 07 |
nicklas |
131 |
TestFile.test_delete(cdfId); |
1143 |
29 Aug 05 |
nicklas |
132 |
TestReporter.test_delete(); |
1143 |
29 Aug 05 |
nicklas |
133 |
|
739 |
09 Jun 05 |
nicklas |
134 |
write("++Testing array design "+(ok ? "OK" : "Failed")+"\n"); |
739 |
09 Jun 05 |
nicklas |
135 |
return ok; |
739 |
09 Jun 05 |
nicklas |
136 |
} |
739 |
09 Jun 05 |
nicklas |
137 |
|
3820 |
12 Oct 07 |
nicklas |
138 |
static int test_create(String platformId, boolean setAll) |
739 |
09 Jun 05 |
nicklas |
139 |
{ |
739 |
09 Jun 05 |
nicklas |
140 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.ARRAYDESIGN)) return 0; |
739 |
09 Jun 05 |
nicklas |
141 |
int id = 0; |
739 |
09 Jun 05 |
nicklas |
142 |
DbControl dc = null; |
739 |
09 Jun 05 |
nicklas |
143 |
try |
739 |
09 Jun 05 |
nicklas |
144 |
{ |
739 |
09 Jun 05 |
nicklas |
145 |
dc = TestUtil.getDbControl(); |
5764 |
27 Sep 11 |
nicklas |
146 |
ArrayDesign ad = null; |
5764 |
27 Sep 11 |
nicklas |
147 |
try |
5764 |
27 Sep 11 |
nicklas |
148 |
{ |
5764 |
27 Sep 11 |
nicklas |
149 |
Platform platform = Platform.getByExternalId(dc, platformId); |
5764 |
27 Sep 11 |
nicklas |
150 |
ad = ArrayDesign.getNew(dc, platform); |
5764 |
27 Sep 11 |
nicklas |
151 |
} |
5764 |
27 Sep 11 |
nicklas |
152 |
catch (ItemNotFoundException ex) |
5764 |
27 Sep 11 |
nicklas |
153 |
{ |
5764 |
27 Sep 11 |
nicklas |
154 |
PlatformVariant variant = PlatformVariant.getByExternalId(dc, platformId); |
5764 |
27 Sep 11 |
nicklas |
155 |
ad = ArrayDesign.getNew(dc, variant); |
5764 |
27 Sep 11 |
nicklas |
156 |
} |
739 |
09 Jun 05 |
nicklas |
157 |
if (setAll) |
739 |
09 Jun 05 |
nicklas |
158 |
{ |
744 |
10 Jun 05 |
nicklas |
159 |
ad.setName("Test array design"); |
739 |
09 Jun 05 |
nicklas |
160 |
ad.setDescription("Added at "+new Date()); |
739 |
09 Jun 05 |
nicklas |
161 |
} |
739 |
09 Jun 05 |
nicklas |
162 |
dc.saveItem(ad); |
739 |
09 Jun 05 |
nicklas |
163 |
dc.commit(); |
739 |
09 Jun 05 |
nicklas |
164 |
id = ad.getId(); |
3820 |
12 Oct 07 |
nicklas |
165 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
166 |
dc.reattachItem(ad, false); |
739 |
09 Jun 05 |
nicklas |
167 |
write_item(0, ad); |
739 |
09 Jun 05 |
nicklas |
168 |
write("--Create array design OK"); |
739 |
09 Jun 05 |
nicklas |
169 |
} |
739 |
09 Jun 05 |
nicklas |
170 |
catch (Throwable ex) |
739 |
09 Jun 05 |
nicklas |
171 |
{ |
739 |
09 Jun 05 |
nicklas |
172 |
write("--Create array design FAILED"); |
739 |
09 Jun 05 |
nicklas |
173 |
ex.printStackTrace(); |
739 |
09 Jun 05 |
nicklas |
174 |
ok = false; |
739 |
09 Jun 05 |
nicklas |
175 |
} |
739 |
09 Jun 05 |
nicklas |
176 |
finally |
739 |
09 Jun 05 |
nicklas |
177 |
{ |
739 |
09 Jun 05 |
nicklas |
178 |
if (dc != null) dc.close(); |
739 |
09 Jun 05 |
nicklas |
179 |
} |
739 |
09 Jun 05 |
nicklas |
180 |
return id; |
739 |
09 Jun 05 |
nicklas |
181 |
} |
739 |
09 Jun 05 |
nicklas |
182 |
|
739 |
09 Jun 05 |
nicklas |
183 |
static void test_load(int id) |
739 |
09 Jun 05 |
nicklas |
184 |
{ |
739 |
09 Jun 05 |
nicklas |
185 |
if (id == 0) return; |
739 |
09 Jun 05 |
nicklas |
186 |
DbControl dc = null; |
739 |
09 Jun 05 |
nicklas |
187 |
try |
739 |
09 Jun 05 |
nicklas |
188 |
{ |
739 |
09 Jun 05 |
nicklas |
189 |
dc = TestUtil.getDbControl(); |
739 |
09 Jun 05 |
nicklas |
190 |
ArrayDesign ad = ArrayDesign.getById(dc, id); |
739 |
09 Jun 05 |
nicklas |
191 |
write_item(0, ad); |
739 |
09 Jun 05 |
nicklas |
192 |
write("--Load array design OK"); |
739 |
09 Jun 05 |
nicklas |
193 |
} |
739 |
09 Jun 05 |
nicklas |
194 |
catch (Throwable ex) |
739 |
09 Jun 05 |
nicklas |
195 |
{ |
739 |
09 Jun 05 |
nicklas |
196 |
write("--Load array design FAILED"); |
739 |
09 Jun 05 |
nicklas |
197 |
ex.printStackTrace(); |
739 |
09 Jun 05 |
nicklas |
198 |
ok = false; |
739 |
09 Jun 05 |
nicklas |
199 |
} |
739 |
09 Jun 05 |
nicklas |
200 |
finally |
739 |
09 Jun 05 |
nicklas |
201 |
{ |
739 |
09 Jun 05 |
nicklas |
202 |
if (dc != null) dc.close(); |
739 |
09 Jun 05 |
nicklas |
203 |
} |
739 |
09 Jun 05 |
nicklas |
204 |
} |
739 |
09 Jun 05 |
nicklas |
205 |
|
739 |
09 Jun 05 |
nicklas |
206 |
|
5696 |
12 Aug 11 |
nicklas |
207 |
static boolean test_list(int expectedResults) |
739 |
09 Jun 05 |
nicklas |
208 |
{ |
739 |
09 Jun 05 |
nicklas |
209 |
DbControl dc = null; |
739 |
09 Jun 05 |
nicklas |
210 |
try |
739 |
09 Jun 05 |
nicklas |
211 |
{ |
739 |
09 Jun 05 |
nicklas |
212 |
dc = TestUtil.getDbControl(); |
1418 |
07 Oct 05 |
nicklas |
213 |
ItemQuery<ArrayDesign> q = ArrayDesign.getQuery(); |
1418 |
07 Oct 05 |
nicklas |
214 |
ItemResultList<ArrayDesign> l = q.list(dc); |
739 |
09 Jun 05 |
nicklas |
215 |
for (int i = 0; i<l.size(); i++) |
739 |
09 Jun 05 |
nicklas |
216 |
{ |
739 |
09 Jun 05 |
nicklas |
217 |
write_item(i, l.get(i)); |
739 |
09 Jun 05 |
nicklas |
218 |
} |
739 |
09 Jun 05 |
nicklas |
219 |
if (expectedResults >= 0 && expectedResults != l.size()) |
739 |
09 Jun 05 |
nicklas |
220 |
{ |
739 |
09 Jun 05 |
nicklas |
221 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
739 |
09 Jun 05 |
nicklas |
222 |
} |
739 |
09 Jun 05 |
nicklas |
223 |
write("--List array designs OK ("+l.size()+")"); |
739 |
09 Jun 05 |
nicklas |
224 |
} |
739 |
09 Jun 05 |
nicklas |
225 |
catch (Throwable ex) |
739 |
09 Jun 05 |
nicklas |
226 |
{ |
739 |
09 Jun 05 |
nicklas |
227 |
write("--List array designs FAILED"); |
739 |
09 Jun 05 |
nicklas |
228 |
ex.printStackTrace(); |
739 |
09 Jun 05 |
nicklas |
229 |
ok = false; |
5696 |
12 Aug 11 |
nicklas |
230 |
return false; |
739 |
09 Jun 05 |
nicklas |
231 |
} |
739 |
09 Jun 05 |
nicklas |
232 |
finally |
739 |
09 Jun 05 |
nicklas |
233 |
{ |
739 |
09 Jun 05 |
nicklas |
234 |
if (dc != null) dc.close(); |
739 |
09 Jun 05 |
nicklas |
235 |
} |
5696 |
12 Aug 11 |
nicklas |
236 |
return true; |
739 |
09 Jun 05 |
nicklas |
237 |
} |
739 |
09 Jun 05 |
nicklas |
238 |
|
739 |
09 Jun 05 |
nicklas |
239 |
|
739 |
09 Jun 05 |
nicklas |
240 |
static void test_delete(int id) |
739 |
09 Jun 05 |
nicklas |
241 |
{ |
739 |
09 Jun 05 |
nicklas |
242 |
if (id == 0) return; |
739 |
09 Jun 05 |
nicklas |
243 |
DbControl dc = null; |
739 |
09 Jun 05 |
nicklas |
244 |
try |
739 |
09 Jun 05 |
nicklas |
245 |
{ |
739 |
09 Jun 05 |
nicklas |
246 |
dc = TestUtil.getDbControl(); |
739 |
09 Jun 05 |
nicklas |
247 |
ArrayDesign ad = ArrayDesign.getById(dc, id); |
739 |
09 Jun 05 |
nicklas |
248 |
dc.deleteItem(ad); |
5340 |
10 May 10 |
nicklas |
249 |
Set<ItemProxy> using = ad.getUsingItems(); |
5340 |
10 May 10 |
nicklas |
250 |
if (using.size() > 0) |
5340 |
10 May 10 |
nicklas |
251 |
{ |
5340 |
10 May 10 |
nicklas |
252 |
throw new BaseException(ad + " is used by " + using); |
5340 |
10 May 10 |
nicklas |
253 |
} |
739 |
09 Jun 05 |
nicklas |
254 |
dc.commit(); |
739 |
09 Jun 05 |
nicklas |
255 |
write("--Delete array design OK"); |
739 |
09 Jun 05 |
nicklas |
256 |
} |
739 |
09 Jun 05 |
nicklas |
257 |
catch (Throwable ex) |
739 |
09 Jun 05 |
nicklas |
258 |
{ |
739 |
09 Jun 05 |
nicklas |
259 |
write("--Delete array design FAILED"); |
739 |
09 Jun 05 |
nicklas |
260 |
ex.printStackTrace(); |
739 |
09 Jun 05 |
nicklas |
261 |
ok = false; |
739 |
09 Jun 05 |
nicklas |
262 |
} |
739 |
09 Jun 05 |
nicklas |
263 |
finally |
739 |
09 Jun 05 |
nicklas |
264 |
{ |
739 |
09 Jun 05 |
nicklas |
265 |
if (dc != null) dc.close(); |
739 |
09 Jun 05 |
nicklas |
266 |
} |
739 |
09 Jun 05 |
nicklas |
267 |
} |
739 |
09 Jun 05 |
nicklas |
268 |
|
4434 |
02 Sep 08 |
nicklas |
269 |
static void test_delete_all() |
4434 |
02 Sep 08 |
nicklas |
270 |
{ |
4434 |
02 Sep 08 |
nicklas |
271 |
DbControl dc = null; |
4434 |
02 Sep 08 |
nicklas |
272 |
try |
4434 |
02 Sep 08 |
nicklas |
273 |
{ |
4434 |
02 Sep 08 |
nicklas |
274 |
dc = TestUtil.getDbControl(); |
4434 |
02 Sep 08 |
nicklas |
275 |
List<ArrayDesign> l = new ArrayList<ArrayDesign>(ArrayDesign.getQuery().list(dc)); |
5688 |
10 Aug 11 |
nicklas |
276 |
int numDeleted = Trashcan.delete(dc.getSessionControl(), l, true, null); |
5688 |
10 Aug 11 |
nicklas |
277 |
if (numDeleted != l.size()) throw new BaseException("Could not delete all items: " + numDeleted + " of " + l.size()); |
4434 |
02 Sep 08 |
nicklas |
278 |
dc.commit(); |
4434 |
02 Sep 08 |
nicklas |
279 |
write("--Delete all array designs OK ("+l.size()+")"); |
4434 |
02 Sep 08 |
nicklas |
280 |
} |
4434 |
02 Sep 08 |
nicklas |
281 |
catch (Throwable ex) |
4434 |
02 Sep 08 |
nicklas |
282 |
{ |
4434 |
02 Sep 08 |
nicklas |
283 |
write("--Delete all array designs FAILED"); |
4434 |
02 Sep 08 |
nicklas |
284 |
ex.printStackTrace(); |
4434 |
02 Sep 08 |
nicklas |
285 |
ok = false; |
4434 |
02 Sep 08 |
nicklas |
286 |
} |
4434 |
02 Sep 08 |
nicklas |
287 |
finally |
4434 |
02 Sep 08 |
nicklas |
288 |
{ |
4434 |
02 Sep 08 |
nicklas |
289 |
if (dc != null) dc.close(); |
4434 |
02 Sep 08 |
nicklas |
290 |
} |
4434 |
02 Sep 08 |
nicklas |
291 |
} |
4434 |
02 Sep 08 |
nicklas |
292 |
|
4434 |
02 Sep 08 |
nicklas |
293 |
|
739 |
09 Jun 05 |
nicklas |
294 |
static void write_header() |
739 |
09 Jun 05 |
nicklas |
295 |
{ |
739 |
09 Jun 05 |
nicklas |
296 |
if (!TestUtil.getSilent()) |
739 |
09 Jun 05 |
nicklas |
297 |
{ |
974 |
20 Jul 05 |
enell |
298 |
write(" \tID \tName \tDescription\tAnnotated\tAffyChipDesign"); |
974 |
20 Jul 05 |
enell |
299 |
write("-- \t-- \t--------- \t-----------\t---------\t--------------"); |
739 |
09 Jun 05 |
nicklas |
300 |
} |
739 |
09 Jun 05 |
nicklas |
301 |
} |
1719 |
15 Dec 05 |
enell |
302 |
|
1143 |
29 Aug 05 |
nicklas |
303 |
static void write_feature_header() |
1143 |
29 Aug 05 |
nicklas |
304 |
{ |
1143 |
29 Aug 05 |
nicklas |
305 |
if (!TestUtil.getSilent()) |
1143 |
29 Aug 05 |
nicklas |
306 |
{ |
1143 |
29 Aug 05 |
nicklas |
307 |
write(" \tID \tBlock\tRow\tColumn\tPosition\tReporter\tWell"); |
1143 |
29 Aug 05 |
nicklas |
308 |
write("-- \t-- \t-----\t---\t------\t--------\t--------\t----"); |
1143 |
29 Aug 05 |
nicklas |
309 |
} |
1143 |
29 Aug 05 |
nicklas |
310 |
} |
1143 |
29 Aug 05 |
nicklas |
311 |
|
1719 |
15 Dec 05 |
enell |
312 |
static void write_plate_header() |
1719 |
15 Dec 05 |
enell |
313 |
{ |
1719 |
15 Dec 05 |
enell |
314 |
if (!TestUtil.getSilent()) |
1719 |
15 Dec 05 |
enell |
315 |
{ |
1719 |
15 Dec 05 |
enell |
316 |
write(" \tID \tPlate \tPosition"); |
1719 |
15 Dec 05 |
enell |
317 |
write("-- \t-- \t---------\t-----"); |
1719 |
15 Dec 05 |
enell |
318 |
} |
1719 |
15 Dec 05 |
enell |
319 |
} |
1719 |
15 Dec 05 |
enell |
320 |
|
739 |
09 Jun 05 |
nicklas |
321 |
static void write_item(int i, ArrayDesign ad) |
739 |
09 Jun 05 |
nicklas |
322 |
throws BaseException |
739 |
09 Jun 05 |
nicklas |
323 |
{ |
1719 |
15 Dec 05 |
enell |
324 |
if (!TestUtil.getSilent()) |
1719 |
15 Dec 05 |
enell |
325 |
{ |
3820 |
12 Oct 07 |
nicklas |
326 |
write(i+":\t"+ad.getId()+"\t"+ad.getName()+"\t"+ad.getDescription()+"\t"+ad.isAnnotated()+"\t"+ad.getPlatform()); |
1719 |
15 Dec 05 |
enell |
327 |
} |
739 |
09 Jun 05 |
nicklas |
328 |
} |
1719 |
15 Dec 05 |
enell |
329 |
|
2314 |
23 May 06 |
nicklas |
330 |
static void write_item(int i, FeatureData f, DbControl dc) |
1143 |
29 Aug 05 |
nicklas |
331 |
throws BaseException |
1143 |
29 Aug 05 |
nicklas |
332 |
{ |
1143 |
29 Aug 05 |
nicklas |
333 |
if (!TestUtil.getSilent()) |
1143 |
29 Aug 05 |
nicklas |
334 |
{ |
1719 |
15 Dec 05 |
enell |
335 |
write(i+":\t"+f.getId()+"\t"+Feature.getArrayDesignBlock(dc, f)+"\t"+f.getRow()+"\t"+f.getColumn()+"\t"+f.getPosition()+"\t"+f.getReporter()+"\t"+Feature.getWell(dc, f)); |
1143 |
29 Aug 05 |
nicklas |
336 |
} |
1143 |
29 Aug 05 |
nicklas |
337 |
} |
1719 |
15 Dec 05 |
enell |
338 |
|
1719 |
15 Dec 05 |
enell |
339 |
static void write_item(int i, Plate p, int index) |
1719 |
15 Dec 05 |
enell |
340 |
throws BaseException |
1719 |
15 Dec 05 |
enell |
341 |
{ |
1719 |
15 Dec 05 |
enell |
342 |
if (!TestUtil.getSilent()) |
1719 |
15 Dec 05 |
enell |
343 |
{ |
1719 |
15 Dec 05 |
enell |
344 |
write(i + ":\t" + p.getId() + "\t" + p.getName() + "\t"+index); |
1719 |
15 Dec 05 |
enell |
345 |
} |
1719 |
15 Dec 05 |
enell |
346 |
} |
1143 |
29 Aug 05 |
nicklas |
347 |
|
3820 |
12 Oct 07 |
nicklas |
348 |
static void write_item(int i, FileSetMember member) |
3820 |
12 Oct 07 |
nicklas |
349 |
throws BaseException |
3820 |
12 Oct 07 |
nicklas |
350 |
{ |
3820 |
12 Oct 07 |
nicklas |
351 |
if (!TestUtil.getSilent()) |
3820 |
12 Oct 07 |
nicklas |
352 |
{ |
3820 |
12 Oct 07 |
nicklas |
353 |
System.out.println(i+":\t"+member.getId()+"\t"+member.getFile().getName()+"\t"+ |
3820 |
12 Oct 07 |
nicklas |
354 |
member.getDataFileType().getName()); |
3820 |
12 Oct 07 |
nicklas |
355 |
} |
3820 |
12 Oct 07 |
nicklas |
356 |
} |
3820 |
12 Oct 07 |
nicklas |
357 |
|
739 |
09 Jun 05 |
nicklas |
358 |
static void write(String message) |
739 |
09 Jun 05 |
nicklas |
359 |
{ |
739 |
09 Jun 05 |
nicklas |
360 |
System.out.println(message); |
739 |
09 Jun 05 |
nicklas |
361 |
} |
739 |
09 Jun 05 |
nicklas |
362 |
|
4093 |
18 Jan 08 |
enell |
363 |
static void test_add_features(int arrayDesignId, FeatureIdentificationMethod fiMethod, int numFeatures) |
1143 |
29 Aug 05 |
nicklas |
364 |
{ |
1143 |
29 Aug 05 |
nicklas |
365 |
if (arrayDesignId == 0) return; |
1143 |
29 Aug 05 |
nicklas |
366 |
DbControl dc = null; |
1143 |
29 Aug 05 |
nicklas |
367 |
long time; |
1143 |
29 Aug 05 |
nicklas |
368 |
try |
1143 |
29 Aug 05 |
nicklas |
369 |
{ |
1143 |
29 Aug 05 |
nicklas |
370 |
write("--Start adding features ("+numFeatures+" features)"); |
1143 |
29 Aug 05 |
nicklas |
371 |
dc = TestUtil.getDbControl(); |
1143 |
29 Aug 05 |
nicklas |
372 |
ArrayDesign ad = ArrayDesign.getById(dc, arrayDesignId); |
1438 |
11 Oct 05 |
nicklas |
373 |
|
1534 |
27 Oct 05 |
enell |
374 |
ArrayList<Integer> reporterIds = new ArrayList<Integer>(); |
1534 |
27 Oct 05 |
enell |
375 |
DataResultIterator<ReporterData> it = Reporter.getQuery().iterate(dc); |
1534 |
27 Oct 05 |
enell |
376 |
while(it.hasNext()) |
1534 |
27 Oct 05 |
enell |
377 |
{ |
1534 |
27 Oct 05 |
enell |
378 |
ReporterData reporter = it.next(); |
1534 |
27 Oct 05 |
enell |
379 |
reporterIds.add(reporter.getId()); |
1534 |
27 Oct 05 |
enell |
380 |
} |
1534 |
27 Oct 05 |
enell |
381 |
|
4257 |
29 Apr 08 |
nicklas |
382 |
FeatureBatcher batcher = ad.getFeatureBatcher(fiMethod, null); |
1143 |
29 Aug 05 |
nicklas |
383 |
int block = 1; |
1143 |
29 Aug 05 |
nicklas |
384 |
int row = 1; |
1143 |
29 Aug 05 |
nicklas |
385 |
int column = 1; |
4093 |
18 Jan 08 |
enell |
386 |
int position = 1; |
1401 |
04 Oct 05 |
enell |
387 |
ArrayDesignBlock adBlock = ad.addArrayDesignBlock(new BlockInfo(block, (int)Math.ceil(block/4F), ((block-1)%4)+1)); |
1143 |
29 Aug 05 |
nicklas |
388 |
time = System.currentTimeMillis(); |
1143 |
29 Aug 05 |
nicklas |
389 |
for (int i = 0; i < numFeatures; i++) |
1143 |
29 Aug 05 |
nicklas |
390 |
{ |
1534 |
27 Oct 05 |
enell |
391 |
ReporterData reporter = null; |
1534 |
27 Oct 05 |
enell |
392 |
if(reporterIds.size() > 0) |
1534 |
27 Oct 05 |
enell |
393 |
{ |
1534 |
27 Oct 05 |
enell |
394 |
reporter = Reporter.getById(dc, reporterIds.get((int) Math.floor(reporterIds.size() * Math.random()))); |
1534 |
27 Oct 05 |
enell |
395 |
} |
2314 |
23 May 06 |
nicklas |
396 |
FeatureData data = batcher.newFeature(adBlock, reporter); |
1143 |
29 Aug 05 |
nicklas |
397 |
data.setRow(row); |
1143 |
29 Aug 05 |
nicklas |
398 |
data.setColumn(column); |
4093 |
18 Jan 08 |
enell |
399 |
data.setPosition(position); |
4093 |
18 Jan 08 |
enell |
400 |
data.setExternalId(reporter.getExternalId() + "." + position); |
739 |
09 Jun 05 |
nicklas |
401 |
|
1143 |
29 Aug 05 |
nicklas |
402 |
batcher.insert(data); |
1143 |
29 Aug 05 |
nicklas |
403 |
row++; |
4093 |
18 Jan 08 |
enell |
404 |
position++; |
1143 |
29 Aug 05 |
nicklas |
405 |
if (row == 11) |
1143 |
29 Aug 05 |
nicklas |
406 |
{ |
1143 |
29 Aug 05 |
nicklas |
407 |
row = 1; |
1143 |
29 Aug 05 |
nicklas |
408 |
column++; |
1143 |
29 Aug 05 |
nicklas |
409 |
if (column == 11) |
1143 |
29 Aug 05 |
nicklas |
410 |
{ |
1143 |
29 Aug 05 |
nicklas |
411 |
column = 1; |
1143 |
29 Aug 05 |
nicklas |
412 |
block++; |
1401 |
04 Oct 05 |
enell |
413 |
adBlock = ad.addArrayDesignBlock(new BlockInfo(block, (int)Math.ceil(block/4F), ((block-1)%4)+1)); |
1143 |
29 Aug 05 |
nicklas |
414 |
} |
1143 |
29 Aug 05 |
nicklas |
415 |
} |
1143 |
29 Aug 05 |
nicklas |
416 |
} |
1143 |
29 Aug 05 |
nicklas |
417 |
dc.commit(); |
1143 |
29 Aug 05 |
nicklas |
418 |
time = System.currentTimeMillis()-time; |
1143 |
29 Aug 05 |
nicklas |
419 |
write("--Add features OK ("+time+" ms)"); |
1143 |
29 Aug 05 |
nicklas |
420 |
} |
1143 |
29 Aug 05 |
nicklas |
421 |
catch (Throwable ex) |
1143 |
29 Aug 05 |
nicklas |
422 |
{ |
1143 |
29 Aug 05 |
nicklas |
423 |
write("--Add features FAILED"); |
1143 |
29 Aug 05 |
nicklas |
424 |
ex.printStackTrace(); |
1143 |
29 Aug 05 |
nicklas |
425 |
ok = false; |
1143 |
29 Aug 05 |
nicklas |
426 |
} |
1143 |
29 Aug 05 |
nicklas |
427 |
finally |
1143 |
29 Aug 05 |
nicklas |
428 |
{ |
1143 |
29 Aug 05 |
nicklas |
429 |
if (dc != null) dc.close(); |
1143 |
29 Aug 05 |
nicklas |
430 |
} |
1143 |
29 Aug 05 |
nicklas |
431 |
} |
1143 |
29 Aug 05 |
nicklas |
432 |
|
1719 |
15 Dec 05 |
enell |
433 |
private static void test_add_features_from_wells(int arrayDesignId, int[] plateIds, int numFeatures) |
1719 |
15 Dec 05 |
enell |
434 |
{ |
1719 |
15 Dec 05 |
enell |
435 |
if (arrayDesignId == 0) return; |
1719 |
15 Dec 05 |
enell |
436 |
DbControl dc = null; |
1719 |
15 Dec 05 |
enell |
437 |
long time; |
1719 |
15 Dec 05 |
enell |
438 |
try |
1719 |
15 Dec 05 |
enell |
439 |
{ |
1719 |
15 Dec 05 |
enell |
440 |
write("--Start adding features from wells ("+numFeatures+" features)"); |
1719 |
15 Dec 05 |
enell |
441 |
dc = TestUtil.getDbControl(); |
1719 |
15 Dec 05 |
enell |
442 |
ArrayDesign ad = ArrayDesign.getById(dc, arrayDesignId); |
3820 |
12 Oct 07 |
nicklas |
443 |
if (Platform.AFFYMETRIX.equals(ad.getPlatform().getExternalId())) |
1719 |
15 Dec 05 |
enell |
444 |
{ |
1719 |
15 Dec 05 |
enell |
445 |
throw new BaseException("Cannot add features from wells on an affy arraydesign"); |
1719 |
15 Dec 05 |
enell |
446 |
} |
1719 |
15 Dec 05 |
enell |
447 |
ArrayList<Well> wells = new ArrayList<Well>(); |
1719 |
15 Dec 05 |
enell |
448 |
for (int plateId : plateIds) |
1719 |
15 Dec 05 |
enell |
449 |
{ |
1719 |
15 Dec 05 |
enell |
450 |
Plate plate = Plate.getById(dc, plateId); |
1719 |
15 Dec 05 |
enell |
451 |
wells.addAll(plate.getWells().list(dc)); |
1719 |
15 Dec 05 |
enell |
452 |
} |
4257 |
29 Apr 08 |
nicklas |
453 |
FeatureBatcher batcher = ad.getFeatureBatcher(FeatureIdentificationMethod.COORDINATES, null); |
1719 |
15 Dec 05 |
enell |
454 |
int block = 1; |
1719 |
15 Dec 05 |
enell |
455 |
int row = 1; |
1719 |
15 Dec 05 |
enell |
456 |
int column = 1; |
1719 |
15 Dec 05 |
enell |
457 |
ArrayDesignBlock adBlock = ad.addArrayDesignBlock(new BlockInfo(block, (int)Math.ceil(block/4F), ((block-1)%4)+1)); |
1719 |
15 Dec 05 |
enell |
458 |
time = System.currentTimeMillis(); |
1719 |
15 Dec 05 |
enell |
459 |
for (int i = 0; i < numFeatures; i++) |
1719 |
15 Dec 05 |
enell |
460 |
{ |
1719 |
15 Dec 05 |
enell |
461 |
Well well = null; |
1719 |
15 Dec 05 |
enell |
462 |
if (!wells.isEmpty()) |
1719 |
15 Dec 05 |
enell |
463 |
{ |
1719 |
15 Dec 05 |
enell |
464 |
well = wells.get((int) Math.floor(wells.size() * Math.random())); |
1719 |
15 Dec 05 |
enell |
465 |
} |
6870 |
16 Apr 15 |
nicklas |
466 |
FeatureData data = batcher.newFeature(adBlock, well); |
1719 |
15 Dec 05 |
enell |
467 |
data.setRow(row); |
1719 |
15 Dec 05 |
enell |
468 |
data.setColumn(column); |
1719 |
15 Dec 05 |
enell |
469 |
|
1719 |
15 Dec 05 |
enell |
470 |
batcher.insert(data); |
1719 |
15 Dec 05 |
enell |
471 |
row++; |
1719 |
15 Dec 05 |
enell |
472 |
if (row == 3) |
1719 |
15 Dec 05 |
enell |
473 |
{ |
1719 |
15 Dec 05 |
enell |
474 |
row = 1; |
1719 |
15 Dec 05 |
enell |
475 |
column++; |
1719 |
15 Dec 05 |
enell |
476 |
if (column == 3) |
1719 |
15 Dec 05 |
enell |
477 |
{ |
1719 |
15 Dec 05 |
enell |
478 |
column = 1; |
1719 |
15 Dec 05 |
enell |
479 |
block++; |
1719 |
15 Dec 05 |
enell |
480 |
adBlock = ad.addArrayDesignBlock(new BlockInfo(block, (int)Math.ceil(block/4F), ((block-1)%4)+1)); |
1719 |
15 Dec 05 |
enell |
481 |
} |
1719 |
15 Dec 05 |
enell |
482 |
} |
1719 |
15 Dec 05 |
enell |
483 |
} |
1719 |
15 Dec 05 |
enell |
484 |
dc.commit(); |
1719 |
15 Dec 05 |
enell |
485 |
time = System.currentTimeMillis()-time; |
1719 |
15 Dec 05 |
enell |
486 |
write("--Add features from wells OK ("+time+" ms)"); |
1719 |
15 Dec 05 |
enell |
487 |
} |
1719 |
15 Dec 05 |
enell |
488 |
catch (Throwable ex) |
1719 |
15 Dec 05 |
enell |
489 |
{ |
1719 |
15 Dec 05 |
enell |
490 |
write("--Add features from wells FAILED"); |
1719 |
15 Dec 05 |
enell |
491 |
ex.printStackTrace(); |
1719 |
15 Dec 05 |
enell |
492 |
ok = false; |
1719 |
15 Dec 05 |
enell |
493 |
} |
1719 |
15 Dec 05 |
enell |
494 |
finally |
1719 |
15 Dec 05 |
enell |
495 |
{ |
1719 |
15 Dec 05 |
enell |
496 |
if (dc != null) dc.close(); |
1719 |
15 Dec 05 |
enell |
497 |
} |
1719 |
15 Dec 05 |
enell |
498 |
} |
1719 |
15 Dec 05 |
enell |
499 |
|
1719 |
15 Dec 05 |
enell |
500 |
static void test_add_plates(int arrayDesignId, int[] plateIds) |
1719 |
15 Dec 05 |
enell |
501 |
{ |
1793 |
19 Jan 06 |
enell |
502 |
if (!TestUtil.hasPermission(Permission.WRITE, Item.ARRAYDESIGN) || arrayDesignId == 0 || plateIds == null) return ; |
1719 |
15 Dec 05 |
enell |
503 |
DbControl dc = null; |
1719 |
15 Dec 05 |
enell |
504 |
try |
1719 |
15 Dec 05 |
enell |
505 |
{ |
1719 |
15 Dec 05 |
enell |
506 |
dc = TestUtil.getDbControl(); |
1719 |
15 Dec 05 |
enell |
507 |
ArrayDesign ad = ArrayDesign.getById(dc, arrayDesignId); |
1719 |
15 Dec 05 |
enell |
508 |
for (int plateId : plateIds) |
1719 |
15 Dec 05 |
enell |
509 |
{ |
1719 |
15 Dec 05 |
enell |
510 |
Plate p = Plate.getById(dc, plateId); |
1719 |
15 Dec 05 |
enell |
511 |
ad.addPlate(p); |
1719 |
15 Dec 05 |
enell |
512 |
} |
1719 |
15 Dec 05 |
enell |
513 |
dc.commit(); |
1719 |
15 Dec 05 |
enell |
514 |
write("--Add plates to array design OK"); |
1719 |
15 Dec 05 |
enell |
515 |
} |
1719 |
15 Dec 05 |
enell |
516 |
catch (Throwable ex) |
1719 |
15 Dec 05 |
enell |
517 |
{ |
1719 |
15 Dec 05 |
enell |
518 |
write("--Add plates to array design FAILED"); |
1719 |
15 Dec 05 |
enell |
519 |
ex.printStackTrace(); |
1719 |
15 Dec 05 |
enell |
520 |
ok = false; |
1719 |
15 Dec 05 |
enell |
521 |
} |
1719 |
15 Dec 05 |
enell |
522 |
finally |
1719 |
15 Dec 05 |
enell |
523 |
{ |
1719 |
15 Dec 05 |
enell |
524 |
if (dc != null) dc.close(); |
1719 |
15 Dec 05 |
enell |
525 |
} |
1719 |
15 Dec 05 |
enell |
526 |
} |
1719 |
15 Dec 05 |
enell |
527 |
|
1143 |
29 Aug 05 |
nicklas |
528 |
static void test_list_features(int arrayDesignId, int expectedResults) |
1143 |
29 Aug 05 |
nicklas |
529 |
{ |
1143 |
29 Aug 05 |
nicklas |
530 |
if (arrayDesignId == 0) return; |
1143 |
29 Aug 05 |
nicklas |
531 |
DbControl dc = null; |
1143 |
29 Aug 05 |
nicklas |
532 |
try |
1143 |
29 Aug 05 |
nicklas |
533 |
{ |
1143 |
29 Aug 05 |
nicklas |
534 |
dc = TestUtil.getDbControl(); |
1143 |
29 Aug 05 |
nicklas |
535 |
ArrayDesign ad = ArrayDesign.getById(dc, arrayDesignId); |
1438 |
11 Oct 05 |
nicklas |
536 |
|
5026 |
28 Jul 09 |
nicklas |
537 |
DataQuery<FeatureData> query = ad.getFeatures(); |
5026 |
28 Jul 09 |
nicklas |
538 |
query.join(Hql.innerJoin(null, "arrayDesignBlock", "blk", null, true)); |
5026 |
28 Jul 09 |
nicklas |
539 |
query.join(Hql.leftJoin(null, "reporter", "rpt", null, true)); |
5026 |
28 Jul 09 |
nicklas |
540 |
DataResultIterator<FeatureData> it = query.iterate(dc); |
1418 |
07 Oct 05 |
nicklas |
541 |
int counter = 0; |
1418 |
07 Oct 05 |
nicklas |
542 |
while (it.hasNext()) |
1143 |
29 Aug 05 |
nicklas |
543 |
{ |
1418 |
07 Oct 05 |
nicklas |
544 |
write_item(counter, it.next(), dc); |
1418 |
07 Oct 05 |
nicklas |
545 |
++counter; |
1143 |
29 Aug 05 |
nicklas |
546 |
} |
1418 |
07 Oct 05 |
nicklas |
547 |
if (expectedResults >= 0 && expectedResults != counter) |
1143 |
29 Aug 05 |
nicklas |
548 |
{ |
1418 |
07 Oct 05 |
nicklas |
549 |
throw new BaseException("Expected "+expectedResults+" results, not "+counter); |
1143 |
29 Aug 05 |
nicklas |
550 |
} |
1418 |
07 Oct 05 |
nicklas |
551 |
write("--List features OK ("+counter+")"); |
1143 |
29 Aug 05 |
nicklas |
552 |
} |
1143 |
29 Aug 05 |
nicklas |
553 |
catch (Throwable ex) |
1143 |
29 Aug 05 |
nicklas |
554 |
{ |
1143 |
29 Aug 05 |
nicklas |
555 |
write("--List features FAILED"); |
1143 |
29 Aug 05 |
nicklas |
556 |
ex.printStackTrace(); |
1143 |
29 Aug 05 |
nicklas |
557 |
ok = false; |
1143 |
29 Aug 05 |
nicklas |
558 |
} |
1143 |
29 Aug 05 |
nicklas |
559 |
finally |
1143 |
29 Aug 05 |
nicklas |
560 |
{ |
1143 |
29 Aug 05 |
nicklas |
561 |
if (dc != null) dc.close(); |
1143 |
29 Aug 05 |
nicklas |
562 |
} |
1143 |
29 Aug 05 |
nicklas |
563 |
} |
1143 |
29 Aug 05 |
nicklas |
564 |
|
1719 |
15 Dec 05 |
enell |
565 |
static void test_list_plates(int arrayDesignId, int expectedResults) |
1719 |
15 Dec 05 |
enell |
566 |
{ |
1719 |
15 Dec 05 |
enell |
567 |
if (arrayDesignId == 0) return; |
1719 |
15 Dec 05 |
enell |
568 |
DbControl dc = null; |
1719 |
15 Dec 05 |
enell |
569 |
try |
1719 |
15 Dec 05 |
enell |
570 |
{ |
1719 |
15 Dec 05 |
enell |
571 |
dc = TestUtil.getDbControl(); |
1719 |
15 Dec 05 |
enell |
572 |
ArrayDesign ad = ArrayDesign.getById(dc, arrayDesignId); |
1719 |
15 Dec 05 |
enell |
573 |
|
1719 |
15 Dec 05 |
enell |
574 |
ItemQuery<Plate> plates = ad.getPlates(); |
1719 |
15 Dec 05 |
enell |
575 |
int counter = 0; |
1719 |
15 Dec 05 |
enell |
576 |
for (Plate p : plates.list(dc)) |
1719 |
15 Dec 05 |
enell |
577 |
{ |
1721 |
15 Dec 05 |
enell |
578 |
write_item(counter, p, ad.getPlatePosition(p)); |
1719 |
15 Dec 05 |
enell |
579 |
counter++; |
1719 |
15 Dec 05 |
enell |
580 |
} |
1719 |
15 Dec 05 |
enell |
581 |
if (expectedResults >= 0 && expectedResults != counter) |
1719 |
15 Dec 05 |
enell |
582 |
{ |
1719 |
15 Dec 05 |
enell |
583 |
throw new BaseException("Expected "+expectedResults+" results, not "+counter); |
1719 |
15 Dec 05 |
enell |
584 |
} |
1719 |
15 Dec 05 |
enell |
585 |
write("--List plates OK ("+counter+")"); |
1719 |
15 Dec 05 |
enell |
586 |
} |
1719 |
15 Dec 05 |
enell |
587 |
catch (Throwable ex) |
1719 |
15 Dec 05 |
enell |
588 |
{ |
1719 |
15 Dec 05 |
enell |
589 |
write("--List plates FAILED"); |
1719 |
15 Dec 05 |
enell |
590 |
ex.printStackTrace(); |
1719 |
15 Dec 05 |
enell |
591 |
ok = false; |
1719 |
15 Dec 05 |
enell |
592 |
} |
1719 |
15 Dec 05 |
enell |
593 |
finally |
1719 |
15 Dec 05 |
enell |
594 |
{ |
1719 |
15 Dec 05 |
enell |
595 |
if (dc != null) dc.close(); |
1719 |
15 Dec 05 |
enell |
596 |
} |
1719 |
15 Dec 05 |
enell |
597 |
} |
1719 |
15 Dec 05 |
enell |
598 |
|
4246 |
24 Apr 08 |
nicklas |
599 |
static void test_import_from_file(int arrayDesignId, String filename, String headerRegexp, |
4246 |
24 Apr 08 |
nicklas |
600 |
String ignoreRegexp, int blockCol, int rowCol, int colCol, int reporterCol) |
1143 |
29 Aug 05 |
nicklas |
601 |
{ |
1143 |
29 Aug 05 |
nicklas |
602 |
if (arrayDesignId == 0) return; |
1143 |
29 Aug 05 |
nicklas |
603 |
write("--Start import features from file (" + filename + ")"); |
1143 |
29 Aug 05 |
nicklas |
604 |
DbControl dc = null; |
1143 |
29 Aug 05 |
nicklas |
605 |
long time; |
1143 |
29 Aug 05 |
nicklas |
606 |
int i = 0; |
1143 |
29 Aug 05 |
nicklas |
607 |
try |
1143 |
29 Aug 05 |
nicklas |
608 |
{ |
1143 |
29 Aug 05 |
nicklas |
609 |
dc = TestUtil.getDbControl(); |
1143 |
29 Aug 05 |
nicklas |
610 |
ArrayDesign ad = ArrayDesign.getById(dc, arrayDesignId); |
4257 |
29 Apr 08 |
nicklas |
611 |
FeatureBatcher featureBatcher = ad.getFeatureBatcher(FeatureIdentificationMethod.COORDINATES, null); |
1143 |
29 Aug 05 |
nicklas |
612 |
ReporterBatcher reporterBatcher = ReporterBatcher.getNew(dc); |
1143 |
29 Aug 05 |
nicklas |
613 |
|
1143 |
29 Aug 05 |
nicklas |
614 |
FlatFileParser parser = new FlatFileParser(); |
1479 |
19 Oct 05 |
nicklas |
615 |
parser.setDataHeaderRegexp(Pattern.compile(headerRegexp)); |
2203 |
28 Apr 06 |
nicklas |
616 |
parser.setDataSplitterRegexp(Pattern.compile("\\t")); |
4246 |
24 Apr 08 |
nicklas |
617 |
if (ignoreRegexp != null) |
4246 |
24 Apr 08 |
nicklas |
618 |
{ |
4246 |
24 Apr 08 |
nicklas |
619 |
parser.setIgnoreRegexp(Pattern.compile(ignoreRegexp)); |
4246 |
24 Apr 08 |
nicklas |
620 |
} |
2992 |
01 Dec 06 |
enell |
621 |
parser.setInputStream(FileUtil.getInputStream(new java.io.File(filename)), "ISO-8859-1"); |
1143 |
29 Aug 05 |
nicklas |
622 |
parser.parseHeaders(); |
1143 |
29 Aug 05 |
nicklas |
623 |
|
1143 |
29 Aug 05 |
nicklas |
624 |
ArrayDesignBlock adBlock = null; |
1143 |
29 Aug 05 |
nicklas |
625 |
|
1143 |
29 Aug 05 |
nicklas |
626 |
time = System.currentTimeMillis(); |
1143 |
29 Aug 05 |
nicklas |
627 |
while (parser.hasMoreData()) |
1143 |
29 Aug 05 |
nicklas |
628 |
{ |
1143 |
29 Aug 05 |
nicklas |
629 |
FlatFileParser.Data parsedData = parser.nextData(); |
7665 |
20 Mar 19 |
nicklas |
630 |
String reporterId = parsedData.getString(reporterCol); |
1594 |
14 Nov 05 |
nicklas |
631 |
ReporterData reporter = reporterId == null ? null : reporterBatcher.getByExternalId(reporterId); |
7665 |
20 Mar 19 |
nicklas |
632 |
int block = parsedData.getInt(blockCol); |
1143 |
29 Aug 05 |
nicklas |
633 |
if (adBlock == null || adBlock.getBlockNumber() != block) |
1143 |
29 Aug 05 |
nicklas |
634 |
{ |
2459 |
30 Jun 06 |
nicklas |
635 |
adBlock = ad.addArrayDesignBlock(new BlockInfo(block, 0, 0)); |
1143 |
29 Aug 05 |
nicklas |
636 |
} |
1143 |
29 Aug 05 |
nicklas |
637 |
FeatureData featureData = featureBatcher.newFeature(adBlock, reporter); |
7665 |
20 Mar 19 |
nicklas |
638 |
featureData.setRow(parsedData.getInt(rowCol)); |
7665 |
20 Mar 19 |
nicklas |
639 |
featureData.setColumn(parsedData.getInt(colCol)); |
1143 |
29 Aug 05 |
nicklas |
640 |
|
4097 |
23 Jan 08 |
nicklas |
641 |
try |
4097 |
23 Jan 08 |
nicklas |
642 |
{ |
4097 |
23 Jan 08 |
nicklas |
643 |
featureBatcher.insert(featureData); |
4097 |
23 Jan 08 |
nicklas |
644 |
i++; |
4097 |
23 Jan 08 |
nicklas |
645 |
} |
4097 |
23 Jan 08 |
nicklas |
646 |
catch (ItemAlreadyExistsException ex) |
4097 |
23 Jan 08 |
nicklas |
647 |
{ |
4097 |
23 Jan 08 |
nicklas |
// Ignore duplicate features |
4097 |
23 Jan 08 |
nicklas |
649 |
} |
1143 |
29 Aug 05 |
nicklas |
650 |
} |
1143 |
29 Aug 05 |
nicklas |
651 |
dc.commit(); |
1143 |
29 Aug 05 |
nicklas |
652 |
time = System.currentTimeMillis()-time; |
1143 |
29 Aug 05 |
nicklas |
653 |
|
1143 |
29 Aug 05 |
nicklas |
654 |
write("--Import features from file OK ("+i+", time="+time+" ms)"); |
1143 |
29 Aug 05 |
nicklas |
655 |
} |
1143 |
29 Aug 05 |
nicklas |
656 |
catch (Throwable ex) |
1143 |
29 Aug 05 |
nicklas |
657 |
{ |
1143 |
29 Aug 05 |
nicklas |
658 |
write("--Import features from file FAILED ("+i+")"); |
1143 |
29 Aug 05 |
nicklas |
659 |
ex.printStackTrace(); |
1143 |
29 Aug 05 |
nicklas |
660 |
ok = false; |
1143 |
29 Aug 05 |
nicklas |
661 |
} |
1143 |
29 Aug 05 |
nicklas |
662 |
finally |
1143 |
29 Aug 05 |
nicklas |
663 |
{ |
1143 |
29 Aug 05 |
nicklas |
664 |
if (dc != null) dc.close(); |
1143 |
29 Aug 05 |
nicklas |
665 |
} |
1143 |
29 Aug 05 |
nicklas |
666 |
} |
1143 |
29 Aug 05 |
nicklas |
667 |
|
3820 |
12 Oct 07 |
nicklas |
668 |
static void test_set_file(int arrayDesignId, String fileType, int fileId) |
3820 |
12 Oct 07 |
nicklas |
669 |
{ |
3820 |
12 Oct 07 |
nicklas |
670 |
if (arrayDesignId == 0 || fileId == 0) return; |
3820 |
12 Oct 07 |
nicklas |
671 |
DbControl dc = null; |
3820 |
12 Oct 07 |
nicklas |
672 |
try |
3820 |
12 Oct 07 |
nicklas |
673 |
{ |
3820 |
12 Oct 07 |
nicklas |
674 |
dc = TestUtil.getDbControl(); |
3820 |
12 Oct 07 |
nicklas |
675 |
ArrayDesign ad = ArrayDesign.getById(dc, arrayDesignId); |
3820 |
12 Oct 07 |
nicklas |
676 |
DataFileType type = DataFileType.getByExternalId(dc, fileType); |
3820 |
12 Oct 07 |
nicklas |
677 |
File file = File.getById(dc, fileId); |
3820 |
12 Oct 07 |
nicklas |
678 |
ad.getFileSet().setMember(file, type); |
5623 |
06 May 11 |
nicklas |
679 |
ad.getFileSet().validate(dc); |
3820 |
12 Oct 07 |
nicklas |
680 |
dc.commit(); |
3820 |
12 Oct 07 |
nicklas |
681 |
write("--Set file OK ("+fileType+")"); |
3820 |
12 Oct 07 |
nicklas |
682 |
} |
3820 |
12 Oct 07 |
nicklas |
683 |
catch (Throwable ex) |
3820 |
12 Oct 07 |
nicklas |
684 |
{ |
3820 |
12 Oct 07 |
nicklas |
685 |
write("--Set file FAILED ("+fileType+")"); |
3820 |
12 Oct 07 |
nicklas |
686 |
ex.printStackTrace(); |
3820 |
12 Oct 07 |
nicklas |
687 |
ok = false; |
3820 |
12 Oct 07 |
nicklas |
688 |
} |
3820 |
12 Oct 07 |
nicklas |
689 |
finally |
3820 |
12 Oct 07 |
nicklas |
690 |
{ |
3820 |
12 Oct 07 |
nicklas |
691 |
if (dc != null) dc.close(); |
3820 |
12 Oct 07 |
nicklas |
692 |
} |
3820 |
12 Oct 07 |
nicklas |
693 |
} |
3820 |
12 Oct 07 |
nicklas |
694 |
|
3820 |
12 Oct 07 |
nicklas |
695 |
static void test_list_files(int arrayDesignId, int expectedResults) |
3820 |
12 Oct 07 |
nicklas |
696 |
{ |
3820 |
12 Oct 07 |
nicklas |
697 |
if (arrayDesignId == 0) return; |
3820 |
12 Oct 07 |
nicklas |
698 |
DbControl dc = null; |
3820 |
12 Oct 07 |
nicklas |
699 |
try |
3820 |
12 Oct 07 |
nicklas |
700 |
{ |
3820 |
12 Oct 07 |
nicklas |
701 |
dc = TestUtil.getDbControl(); |
3820 |
12 Oct 07 |
nicklas |
702 |
ArrayDesign ad = ArrayDesign.getById(dc, arrayDesignId); |
3820 |
12 Oct 07 |
nicklas |
703 |
ItemResultList<FileSetMember> l = ad.getFileSet().getMembers().list(dc); |
3820 |
12 Oct 07 |
nicklas |
704 |
for (int i = 0; i<l.size(); i++) |
3820 |
12 Oct 07 |
nicklas |
705 |
{ |
3820 |
12 Oct 07 |
nicklas |
706 |
write_item(i, l.get(i)); |
3820 |
12 Oct 07 |
nicklas |
707 |
} |
3820 |
12 Oct 07 |
nicklas |
708 |
if (expectedResults >= 0 && expectedResults != l.size()) |
3820 |
12 Oct 07 |
nicklas |
709 |
{ |
3820 |
12 Oct 07 |
nicklas |
710 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
3820 |
12 Oct 07 |
nicklas |
711 |
} |
3820 |
12 Oct 07 |
nicklas |
712 |
write("--List files OK ("+l.size()+")"); |
3820 |
12 Oct 07 |
nicklas |
713 |
} |
3820 |
12 Oct 07 |
nicklas |
714 |
catch (Throwable ex) |
3820 |
12 Oct 07 |
nicklas |
715 |
{ |
3820 |
12 Oct 07 |
nicklas |
716 |
write("--List files FAILED"); |
3820 |
12 Oct 07 |
nicklas |
717 |
ex.printStackTrace(); |
3820 |
12 Oct 07 |
nicklas |
718 |
ok = false; |
3820 |
12 Oct 07 |
nicklas |
719 |
} |
3820 |
12 Oct 07 |
nicklas |
720 |
finally |
3820 |
12 Oct 07 |
nicklas |
721 |
{ |
3820 |
12 Oct 07 |
nicklas |
722 |
if (dc != null) dc.close(); |
3820 |
12 Oct 07 |
nicklas |
723 |
} |
3820 |
12 Oct 07 |
nicklas |
724 |
} |
739 |
09 Jun 05 |
nicklas |
725 |
} |
739 |
09 Jun 05 |
nicklas |
726 |
|