1523 |
25 Oct 05 |
enell |
1 |
/* |
1523 |
25 Oct 05 |
enell |
$Id: TestReporterFlatFileImporter.java 1376 2005-09-22 13:50:01 +0200 (Thu, 22 Sep 2005) nicklas $ |
1523 |
25 Oct 05 |
enell |
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 |
1523 |
25 Oct 05 |
enell |
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/ |
1523 |
25 Oct 05 |
enell |
10 |
|
1523 |
25 Oct 05 |
enell |
BASE is free software; you can redistribute it and/or |
1523 |
25 Oct 05 |
enell |
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 |
1523 |
25 Oct 05 |
enell |
of the License, or (at your option) any later version. |
1523 |
25 Oct 05 |
enell |
15 |
|
1523 |
25 Oct 05 |
enell |
BASE is distributed in the hope that it will be useful, |
1523 |
25 Oct 05 |
enell |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1523 |
25 Oct 05 |
enell |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1523 |
25 Oct 05 |
enell |
GNU General Public License for more details. |
1523 |
25 Oct 05 |
enell |
20 |
|
1523 |
25 Oct 05 |
enell |
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/>. |
1523 |
25 Oct 05 |
enell |
23 |
*/ |
1523 |
25 Oct 05 |
enell |
24 |
import net.sf.basedb.core.*; |
1523 |
25 Oct 05 |
enell |
25 |
import net.sf.basedb.core.plugin.*; |
1523 |
25 Oct 05 |
enell |
26 |
|
1523 |
25 Oct 05 |
enell |
27 |
public class TestRawDataFlatFileImporter |
1523 |
25 Oct 05 |
enell |
28 |
{ |
1523 |
25 Oct 05 |
enell |
29 |
static boolean ok = true; |
1523 |
25 Oct 05 |
enell |
30 |
|
1523 |
25 Oct 05 |
enell |
31 |
public static void main(String[] args) |
1523 |
25 Oct 05 |
enell |
32 |
{ |
1523 |
25 Oct 05 |
enell |
33 |
TestUtil.checkArgs(args); |
1523 |
25 Oct 05 |
enell |
34 |
TestUtil.begin(); |
1523 |
25 Oct 05 |
enell |
35 |
test_all(); |
1523 |
25 Oct 05 |
enell |
36 |
TestUtil.stop(); |
1523 |
25 Oct 05 |
enell |
37 |
} |
1523 |
25 Oct 05 |
enell |
38 |
|
1523 |
25 Oct 05 |
enell |
39 |
static boolean test_all() |
1523 |
25 Oct 05 |
enell |
40 |
{ |
1523 |
25 Oct 05 |
enell |
41 |
write("++Testing rawdata import using plugin"); |
1523 |
25 Oct 05 |
enell |
// Test import rawdata without lims connection |
3626 |
03 Aug 07 |
nicklas |
43 |
TestReporter.test_import_from_file("data/test.rawdata.import.txt", "\"Block\"\\t\"Column\"\\t\"Row\"\\t\"Name\"\\t\"ID\".*", "\\t", 4, 3); |
3719 |
12 Sep 07 |
nicklas |
44 |
int fileId = TestFile.test_create("data/test.rawdata.import.txt", false, false); |
3820 |
12 Oct 07 |
nicklas |
45 |
int arrayDesignId = TestArrayDesign.test_create(Platform.GENERIC, false); |
4246 |
24 Apr 08 |
nicklas |
46 |
TestArrayDesign.test_import_from_file(arrayDesignId, "data/test.rawdata.import.txt", |
4246 |
24 Apr 08 |
nicklas |
47 |
"\"Block\"\\t\"Column\"\\t\"Row\"\\t\"Name\"\\t\"ID\".*", ".*(EMPTY_WELL|no clone).*", 0, 2, 1, 4); |
5748 |
19 Sep 11 |
nicklas |
48 |
int rawBioAssayId = TestRawBioAssay.test_create(Platform.GENERIC, "genepix", null, 0, 0, 0, 0, arrayDesignId, true); |
1523 |
25 Oct 05 |
enell |
49 |
|
1523 |
25 Oct 05 |
enell |
// Create plugin configuration and job |
1523 |
25 Oct 05 |
enell |
51 |
int pluginDefinitionId = TestPluginDefinition.test_get("net.sf.basedb.plugins.RawDataFlatFileImporter"); |
1523 |
25 Oct 05 |
enell |
52 |
int pluginConfigurationId = test_create_configuration(pluginDefinitionId); |
1523 |
25 Oct 05 |
enell |
53 |
TestPluginConfiguration.test_load(pluginConfigurationId); |
1523 |
25 Oct 05 |
enell |
54 |
int jobId = test_create_job(pluginConfigurationId, rawBioAssayId, fileId); |
1523 |
25 Oct 05 |
enell |
55 |
|
1523 |
25 Oct 05 |
enell |
// Execute job |
5319 |
20 Apr 10 |
nicklas |
57 |
ok = ok && TestJob.test_execute(jobId, false); |
1523 |
25 Oct 05 |
enell |
58 |
|
1524 |
26 Oct 05 |
enell |
// Print result |
1524 |
26 Oct 05 |
enell |
60 |
TestRawBioAssay.write_raw_data_header(); |
3471 |
11 Jun 07 |
nicklas |
61 |
TestRawBioAssay.test_list_raw_data(rawBioAssayId, 10, 5, 0, true); |
1523 |
25 Oct 05 |
enell |
62 |
|
1524 |
26 Oct 05 |
enell |
// Clean up test |
1529 |
27 Oct 05 |
nicklas |
64 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
4256 |
29 Apr 08 |
nicklas |
65 |
TestRawBioAssay.test_delete(rawBioAssayId); |
4256 |
29 Apr 08 |
nicklas |
66 |
TestArrayDesign.test_delete(arrayDesignId); |
1523 |
25 Oct 05 |
enell |
67 |
TestJob.test_delete(jobId); |
1523 |
25 Oct 05 |
enell |
68 |
TestPluginConfiguration.test_delete(pluginConfigurationId); |
1523 |
25 Oct 05 |
enell |
69 |
TestFile.test_delete(fileId); |
1524 |
26 Oct 05 |
enell |
70 |
TestReporter.test_delete(); |
1523 |
25 Oct 05 |
enell |
71 |
|
1523 |
25 Oct 05 |
enell |
72 |
write("++Testing rawdata import using plugin "+(ok ? "OK" : "Failed")+"\n"); |
1523 |
25 Oct 05 |
enell |
73 |
return ok; |
1523 |
25 Oct 05 |
enell |
74 |
} |
1523 |
25 Oct 05 |
enell |
75 |
|
1523 |
25 Oct 05 |
enell |
76 |
static int test_create_configuration(int pluginDefinitionId) |
1523 |
25 Oct 05 |
enell |
77 |
{ |
1523 |
25 Oct 05 |
enell |
78 |
if (pluginDefinitionId == 0 || !TestUtil.hasPermission(Permission.CREATE, Item.PLUGINCONFIGURATION)) return 0; |
1523 |
25 Oct 05 |
enell |
79 |
int id = 0; |
1523 |
25 Oct 05 |
enell |
80 |
DbControl dc = null; |
1523 |
25 Oct 05 |
enell |
81 |
try |
1523 |
25 Oct 05 |
enell |
82 |
{ |
1523 |
25 Oct 05 |
enell |
83 |
dc = TestUtil.getDbControl(); |
1523 |
25 Oct 05 |
enell |
84 |
|
1523 |
25 Oct 05 |
enell |
85 |
PluginDefinition pd = PluginDefinition.getById(dc, pluginDefinitionId); |
1523 |
25 Oct 05 |
enell |
86 |
PluginConfiguration pc = pd.newPluginConfiguration(); |
1523 |
25 Oct 05 |
enell |
87 |
pc.setName(pd.getName()); |
1523 |
25 Oct 05 |
enell |
88 |
|
1523 |
25 Oct 05 |
enell |
89 |
PluginConfigurationRequest request = pc.configure(); |
1523 |
25 Oct 05 |
enell |
90 |
write_request_information(request.getRequestInformation()); |
1688 |
05 Dec 05 |
nicklas |
91 |
request.setParameterValue("rawDataType", "genepix"); |
1523 |
25 Oct 05 |
enell |
92 |
PluginResponse response = request.invoke(); |
1523 |
25 Oct 05 |
enell |
93 |
|
1523 |
25 Oct 05 |
enell |
94 |
if (response.getStatus() == Response.Status.ERROR) |
1523 |
25 Oct 05 |
enell |
95 |
{ |
1622 |
16 Nov 05 |
nicklas |
96 |
throw new BaseException(response.getMessage(), response.getErrorList().get(0)); |
1523 |
25 Oct 05 |
enell |
97 |
} |
1523 |
25 Oct 05 |
enell |
98 |
else if (response.getStatus() == Response.Status.DONE) |
1523 |
25 Oct 05 |
enell |
99 |
{ |
1523 |
25 Oct 05 |
enell |
100 |
throw new BaseException("Configuration should continue"); |
1523 |
25 Oct 05 |
enell |
101 |
} |
1523 |
25 Oct 05 |
enell |
102 |
request = response.getNextRequest(); |
1523 |
25 Oct 05 |
enell |
103 |
write_request_information(request.getRequestInformation()); |
1523 |
25 Oct 05 |
enell |
104 |
|
1536 |
27 Oct 05 |
enell |
105 |
request.setParameterValue("headerRegexp", "\"(.+)=(.*)\""); |
2203 |
28 Apr 06 |
nicklas |
106 |
request.setParameterValue("dataSplitterRegexp", "\\t"); |
1523 |
25 Oct 05 |
enell |
107 |
request.setParameterValue("dataHeaderRegexp", "\"Block\"\\t\"Column\"\\t\"Row\"\\t\"Name\"\\t\"ID\".*"); |
2203 |
28 Apr 06 |
nicklas |
108 |
request.setParameterValue("blockColumnMapping", "\\Block\\"); |
2203 |
28 Apr 06 |
nicklas |
109 |
request.setParameterValue("columnColumnMapping", "\\Column\\"); |
2203 |
28 Apr 06 |
nicklas |
110 |
request.setParameterValue("rowColumnMapping", "\\Row\\"); |
2203 |
28 Apr 06 |
nicklas |
111 |
request.setParameterValue("reporterIdColumnMapping", "\\ID\\"); |
1523 |
25 Oct 05 |
enell |
112 |
request.setParameterValue("xColumnMapping", "\\5\\"); |
1523 |
25 Oct 05 |
enell |
113 |
request.setParameterValue("yColumnMapping", "\\6\\"); |
1523 |
25 Oct 05 |
enell |
114 |
|
1523 |
25 Oct 05 |
enell |
115 |
request.setParameterValue("propertyMapping.diameter", "\\7\\"); |
1523 |
25 Oct 05 |
enell |
116 |
request.setParameterValue("propertyMapping.ch1FgMedian", "\\17\\"); |
1523 |
25 Oct 05 |
enell |
117 |
request.setParameterValue("propertyMapping.ch1FgMean", "\\18\\"); |
1523 |
25 Oct 05 |
enell |
118 |
request.setParameterValue("propertyMapping.ch1FgSd", "\\19\\"); |
1523 |
25 Oct 05 |
enell |
119 |
request.setParameterValue("propertyMapping.ch1BgMedian", "\\20\\"); |
1523 |
25 Oct 05 |
enell |
120 |
request.setParameterValue("propertyMapping.ch1BgMean", "\\21\\"); |
1523 |
25 Oct 05 |
enell |
121 |
request.setParameterValue("propertyMapping.ch1BgSd", "\\22\\"); |
1523 |
25 Oct 05 |
enell |
122 |
request.setParameterValue("propertyMapping.ch1PercSd1", "\\23\\"); |
1523 |
25 Oct 05 |
enell |
123 |
request.setParameterValue("propertyMapping.ch1PercSd2", "\\24\\"); |
1523 |
25 Oct 05 |
enell |
124 |
request.setParameterValue("propertyMapping.ch1PercSat", "\\25\\"); |
1523 |
25 Oct 05 |
enell |
125 |
|
1523 |
25 Oct 05 |
enell |
126 |
request.setParameterValue("propertyMapping.ch2FgMedian", "\\8\\"); |
1523 |
25 Oct 05 |
enell |
127 |
request.setParameterValue("propertyMapping.ch2FgMean", "\\9\\"); |
1523 |
25 Oct 05 |
enell |
128 |
request.setParameterValue("propertyMapping.ch2FgSd", "\\10\\"); |
1523 |
25 Oct 05 |
enell |
129 |
request.setParameterValue("propertyMapping.ch2BgMedian", "\\11\\"); |
1523 |
25 Oct 05 |
enell |
130 |
request.setParameterValue("propertyMapping.ch2BgMean", "\\12\\"); |
1523 |
25 Oct 05 |
enell |
131 |
request.setParameterValue("propertyMapping.ch2BgSd", "\\13\\"); |
1523 |
25 Oct 05 |
enell |
132 |
request.setParameterValue("propertyMapping.ch2PercSd1", "\\14\\"); |
1523 |
25 Oct 05 |
enell |
133 |
request.setParameterValue("propertyMapping.ch2PercSd2", "\\15\\"); |
1523 |
25 Oct 05 |
enell |
134 |
request.setParameterValue("propertyMapping.ch2PercSat", "\\16\\"); |
1523 |
25 Oct 05 |
enell |
135 |
|
1523 |
25 Oct 05 |
enell |
136 |
request.setParameterValue("propertyMapping.ratiosSd", "\\30\\"); |
1523 |
25 Oct 05 |
enell |
137 |
request.setParameterValue("propertyMapping.rgnRatio", "\\31\\"); |
1523 |
25 Oct 05 |
enell |
138 |
request.setParameterValue("propertyMapping.rgnR2", "\\32\\"); |
1523 |
25 Oct 05 |
enell |
139 |
request.setParameterValue("propertyMapping.fgPixels", "\\33\\"); |
1523 |
25 Oct 05 |
enell |
140 |
request.setParameterValue("propertyMapping.bgPixels", "\\34\\"); |
1523 |
25 Oct 05 |
enell |
141 |
request.setParameterValue("propertyMapping.flags", "\\46\\"); |
1523 |
25 Oct 05 |
enell |
142 |
|
1523 |
25 Oct 05 |
enell |
143 |
response = request.invoke(); |
1523 |
25 Oct 05 |
enell |
144 |
if (response.getStatus() == Response.Status.DONE) |
1523 |
25 Oct 05 |
enell |
145 |
{ |
1766 |
13 Jan 06 |
nicklas |
146 |
response.saveParameters(dc); |
1523 |
25 Oct 05 |
enell |
147 |
dc.saveItem(pc); |
1523 |
25 Oct 05 |
enell |
148 |
dc.commit(); |
1523 |
25 Oct 05 |
enell |
149 |
} |
1523 |
25 Oct 05 |
enell |
150 |
else |
1523 |
25 Oct 05 |
enell |
151 |
{ |
1622 |
16 Nov 05 |
nicklas |
152 |
throw new BaseException(response.getMessage(), response.getErrorList().get(0)); |
1523 |
25 Oct 05 |
enell |
153 |
} |
1523 |
25 Oct 05 |
enell |
154 |
id = pc.getId(); |
1523 |
25 Oct 05 |
enell |
155 |
write("--Create configuration for rawdata import OK"); |
1523 |
25 Oct 05 |
enell |
156 |
} |
1523 |
25 Oct 05 |
enell |
157 |
catch (Throwable ex) |
1523 |
25 Oct 05 |
enell |
158 |
{ |
1523 |
25 Oct 05 |
enell |
159 |
write("--Create configuration for rawdata import FAILED"); |
1523 |
25 Oct 05 |
enell |
160 |
ex.printStackTrace(); |
1523 |
25 Oct 05 |
enell |
161 |
ok = false; |
1523 |
25 Oct 05 |
enell |
162 |
} |
1523 |
25 Oct 05 |
enell |
163 |
finally |
1523 |
25 Oct 05 |
enell |
164 |
{ |
1523 |
25 Oct 05 |
enell |
165 |
if (dc != null) dc.close(); |
1523 |
25 Oct 05 |
enell |
166 |
} |
1523 |
25 Oct 05 |
enell |
167 |
return id; |
1523 |
25 Oct 05 |
enell |
168 |
} |
1523 |
25 Oct 05 |
enell |
169 |
|
1523 |
25 Oct 05 |
enell |
170 |
static int test_create_job(int pluginConfigurationId, int rawBioAssayId, int fileId) |
1523 |
25 Oct 05 |
enell |
171 |
{ |
1523 |
25 Oct 05 |
enell |
172 |
if (rawBioAssayId == 0 || pluginConfigurationId == 0 || fileId == 0 || !TestUtil.hasPermission(Permission.CREATE, Item.JOB)) return 0; |
1523 |
25 Oct 05 |
enell |
173 |
int id = 0; |
1523 |
25 Oct 05 |
enell |
174 |
DbControl dc = null; |
1523 |
25 Oct 05 |
enell |
175 |
try |
1523 |
25 Oct 05 |
enell |
176 |
{ |
1523 |
25 Oct 05 |
enell |
177 |
dc = TestUtil.getDbControl(); |
1523 |
25 Oct 05 |
enell |
178 |
|
1523 |
25 Oct 05 |
enell |
179 |
PluginConfiguration pc = PluginConfiguration.getById(dc, pluginConfigurationId); |
4254 |
28 Apr 08 |
nicklas |
180 |
Job j = pc.newJob(null); |
1523 |
25 Oct 05 |
enell |
181 |
j.setName(pc.getName()); |
1523 |
25 Oct 05 |
enell |
182 |
|
4594 |
21 Oct 08 |
nicklas |
183 |
PluginConfigurationRequest request = j.configure(GuiContext.item(Item.RAWBIOASSAY)); |
1523 |
25 Oct 05 |
enell |
184 |
write_request_information(request.getRequestInformation()); |
1523 |
25 Oct 05 |
enell |
185 |
request.setParameterValue("file", File.getById(dc, fileId)); |
1523 |
25 Oct 05 |
enell |
186 |
request.setParameterValue("rawBioAssay", RawBioAssay.getById(dc, rawBioAssayId)); |
3472 |
11 Jun 07 |
nicklas |
187 |
request.setParameterValue("numberFormatError", "null"); |
3472 |
11 Jun 07 |
nicklas |
188 |
request.setParameterValue("decimalSeparator", "dot"); |
4097 |
23 Jan 08 |
nicklas |
189 |
request.setParameterValue("duplicateFeatureError", "skip"); |
4246 |
24 Apr 08 |
nicklas |
190 |
request.setParameterValue("featureMismatchError", "smart"); |
1523 |
25 Oct 05 |
enell |
191 |
|
1523 |
25 Oct 05 |
enell |
192 |
PluginResponse response = request.invoke(); |
1523 |
25 Oct 05 |
enell |
193 |
if (response.getStatus() == Response.Status.DONE) |
1523 |
25 Oct 05 |
enell |
194 |
{ |
1523 |
25 Oct 05 |
enell |
195 |
dc.saveItem(j); |
1730 |
20 Dec 05 |
nicklas |
196 |
response.saveParameters(dc); |
1523 |
25 Oct 05 |
enell |
197 |
dc.commit(); |
1523 |
25 Oct 05 |
enell |
198 |
} |
1523 |
25 Oct 05 |
enell |
199 |
else |
1523 |
25 Oct 05 |
enell |
200 |
{ |
1622 |
16 Nov 05 |
nicklas |
201 |
throw new BaseException(response.getMessage(), response.getErrorList().get(0)); |
1523 |
25 Oct 05 |
enell |
202 |
} |
1523 |
25 Oct 05 |
enell |
203 |
id = j.getId(); |
1523 |
25 Oct 05 |
enell |
204 |
write("--Create job for rawdata import OK"); |
1523 |
25 Oct 05 |
enell |
205 |
} |
1523 |
25 Oct 05 |
enell |
206 |
catch (Throwable ex) |
1523 |
25 Oct 05 |
enell |
207 |
{ |
1523 |
25 Oct 05 |
enell |
208 |
write("--Create job for rawdata import FAILED"); |
1523 |
25 Oct 05 |
enell |
209 |
ex.printStackTrace(); |
1523 |
25 Oct 05 |
enell |
210 |
ok = false; |
1523 |
25 Oct 05 |
enell |
211 |
} |
1523 |
25 Oct 05 |
enell |
212 |
finally |
1523 |
25 Oct 05 |
enell |
213 |
{ |
1523 |
25 Oct 05 |
enell |
214 |
if (dc != null) dc.close(); |
1523 |
25 Oct 05 |
enell |
215 |
} |
1523 |
25 Oct 05 |
enell |
216 |
return id; |
1523 |
25 Oct 05 |
enell |
217 |
} |
1523 |
25 Oct 05 |
enell |
218 |
|
1523 |
25 Oct 05 |
enell |
219 |
static void write(String message) |
1523 |
25 Oct 05 |
enell |
220 |
{ |
1523 |
25 Oct 05 |
enell |
221 |
System.out.println(message); |
1523 |
25 Oct 05 |
enell |
222 |
} |
1523 |
25 Oct 05 |
enell |
223 |
|
1523 |
25 Oct 05 |
enell |
224 |
static void write_request_information(RequestInformation ri) |
1523 |
25 Oct 05 |
enell |
225 |
{ |
1523 |
25 Oct 05 |
enell |
226 |
if (TestUtil.getSilent()) return; |
1523 |
25 Oct 05 |
enell |
227 |
|
1523 |
25 Oct 05 |
enell |
228 |
write("Request information for command: "+ri.getCommand()); |
1523 |
25 Oct 05 |
enell |
229 |
write("\tTitle:\t"+ri.getTitle()); |
1523 |
25 Oct 05 |
enell |
230 |
write("\tDescription:\t"+ri.getDescription()); |
1523 |
25 Oct 05 |
enell |
231 |
for (PluginParameter<?> pp : ri.getParameters()) |
1523 |
25 Oct 05 |
enell |
232 |
{ |
6875 |
20 Apr 15 |
nicklas |
233 |
ParameterType<?> pt = pp.getParameterType(); |
1523 |
25 Oct 05 |
enell |
234 |
System.out.println("\tParameter:\t"+pp.getName() + "\t" + pp.getLabel() + "\t" + pt ); |
1523 |
25 Oct 05 |
enell |
235 |
} |
1523 |
25 Oct 05 |
enell |
236 |
} |
1523 |
25 Oct 05 |
enell |
237 |
} |
1523 |
25 Oct 05 |
enell |
238 |
|