3626 |
03 Aug 07 |
nicklas |
1 |
/* |
3626 |
03 Aug 07 |
nicklas |
$Id$ |
3626 |
03 Aug 07 |
nicklas |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2007 Nicklas Nordborg |
3626 |
03 Aug 07 |
nicklas |
5 |
|
3626 |
03 Aug 07 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
3626 |
03 Aug 07 |
nicklas |
Available at http://base.thep.lu.se/ |
3626 |
03 Aug 07 |
nicklas |
8 |
|
3626 |
03 Aug 07 |
nicklas |
BASE is free software; you can redistribute it and/or |
3626 |
03 Aug 07 |
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 |
3626 |
03 Aug 07 |
nicklas |
of the License, or (at your option) any later version. |
3626 |
03 Aug 07 |
nicklas |
13 |
|
3626 |
03 Aug 07 |
nicklas |
BASE is distributed in the hope that it will be useful, |
3626 |
03 Aug 07 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
3626 |
03 Aug 07 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3626 |
03 Aug 07 |
nicklas |
GNU General Public License for more details. |
3626 |
03 Aug 07 |
nicklas |
18 |
|
3626 |
03 Aug 07 |
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/>. |
3626 |
03 Aug 07 |
nicklas |
21 |
*/ |
5692 |
11 Aug 11 |
nicklas |
22 |
import java.util.ArrayList; |
3626 |
03 Aug 07 |
nicklas |
23 |
import java.util.List; |
3626 |
03 Aug 07 |
nicklas |
24 |
|
3626 |
03 Aug 07 |
nicklas |
25 |
import net.sf.basedb.core.*; |
3626 |
03 Aug 07 |
nicklas |
26 |
import net.sf.basedb.core.plugin.*; |
3626 |
03 Aug 07 |
nicklas |
27 |
|
3626 |
03 Aug 07 |
nicklas |
28 |
public class TestIlluminaImporter |
3626 |
03 Aug 07 |
nicklas |
29 |
{ |
3626 |
03 Aug 07 |
nicklas |
30 |
static boolean ok = true; |
3626 |
03 Aug 07 |
nicklas |
31 |
|
3626 |
03 Aug 07 |
nicklas |
32 |
public static void main(String[] args) |
3626 |
03 Aug 07 |
nicklas |
33 |
{ |
3626 |
03 Aug 07 |
nicklas |
34 |
TestUtil.checkArgs(args); |
3626 |
03 Aug 07 |
nicklas |
35 |
TestUtil.begin(); |
3626 |
03 Aug 07 |
nicklas |
36 |
test_all(); |
3626 |
03 Aug 07 |
nicklas |
37 |
TestUtil.stop(); |
3626 |
03 Aug 07 |
nicklas |
38 |
} |
3626 |
03 Aug 07 |
nicklas |
39 |
|
3626 |
03 Aug 07 |
nicklas |
40 |
static boolean test_all() |
3626 |
03 Aug 07 |
nicklas |
41 |
{ |
3626 |
03 Aug 07 |
nicklas |
42 |
write("++Testing Illumina rawdata import"); |
3626 |
03 Aug 07 |
nicklas |
// Test import rawdata without lims connection |
3626 |
03 Aug 07 |
nicklas |
44 |
TestReporter.test_import_from_file("data/test.illumina.reporters.txt", "Search_key,Target,ProbeId.*", ",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))", 1, 1); |
3719 |
12 Sep 07 |
nicklas |
45 |
int fileId = TestFile.test_create("data/test.illumina.rawdata.txt", false, false); |
5694 |
12 Aug 11 |
nicklas |
46 |
int hyb1Id = TestPhysicalBioAssay.test_create(0, "Hyb #1677718123", 0, 12); |
6100 |
04 Sep 12 |
nicklas |
47 |
int scan1Id = TestDerivedBioAssay.test_create_root("1677718123", hyb1Id, SystemItems.getId(DerivedBioAssay.SCAN), 0, 0, 0, 0); |
5694 |
12 Aug 11 |
nicklas |
48 |
int hyb2Id = TestPhysicalBioAssay.test_create(0, "Hyb #1677718142", 0, 12); |
6100 |
04 Sep 12 |
nicklas |
49 |
int scan2Id = TestDerivedBioAssay.test_create_root("1677718142", hyb2Id, SystemItems.getId(DerivedBioAssay.SCAN), 0, 0, 0, 0); |
5630 |
13 May 11 |
nicklas |
50 |
int protocolId = TestProtocol.test_create(SystemItems.getId(Protocol.FEATURE_EXTRACTION), null, false); |
5630 |
13 May 11 |
nicklas |
51 |
int softwareId = TestSoftware.test_create(SystemItems.getId(Software.FEATURE_EXTRACTION), null, false); |
3626 |
03 Aug 07 |
nicklas |
52 |
int experimentId = TestExperiment.test_create("illumina", false); |
3626 |
03 Aug 07 |
nicklas |
53 |
|
5694 |
12 Aug 11 |
nicklas |
// Extracts |
5694 |
12 Aug 11 |
nicklas |
55 |
int cy3 = TestTag.test_load("cy3"); |
5694 |
12 Aug 11 |
nicklas |
56 |
int labeledExtract = SystemItems.getId(Extract.LABELED); |
5694 |
12 Aug 11 |
nicklas |
57 |
int[] extractIds = new int[12]; |
5694 |
12 Aug 11 |
nicklas |
58 |
for (int i = 0; i < 12; ++i) |
5694 |
12 Aug 11 |
nicklas |
59 |
{ |
5694 |
12 Aug 11 |
nicklas |
60 |
extractIds[i] = TestExtract.test_create(0, "#" + (i+1), labeledExtract, cy3, false); |
5694 |
12 Aug 11 |
nicklas |
61 |
TestPhysicalBioAssay.test_add_extract(hyb1Id, extractIds[i], i+1, null); |
5694 |
12 Aug 11 |
nicklas |
62 |
} |
5694 |
12 Aug 11 |
nicklas |
63 |
|
3626 |
03 Aug 07 |
nicklas |
// Create plugin configuration and job |
3626 |
03 Aug 07 |
nicklas |
65 |
int pluginDefinitionId = TestPluginDefinition.test_get("net.sf.basedb.plugins.IlluminaRawDataImporter"); |
5692 |
11 Aug 11 |
nicklas |
66 |
int jobId = test_create_job(pluginDefinitionId, fileId, protocolId, softwareId, experimentId, scan1Id, scan2Id); |
3626 |
03 Aug 07 |
nicklas |
67 |
|
3626 |
03 Aug 07 |
nicklas |
// Execute job |
5319 |
20 Apr 10 |
nicklas |
69 |
ok = ok && TestJob.test_execute(jobId, false); |
3626 |
03 Aug 07 |
nicklas |
70 |
|
3626 |
03 Aug 07 |
nicklas |
// Print result |
3626 |
03 Aug 07 |
nicklas |
72 |
int[] rawBioAssays = test_getRawBioAssays(experimentId); |
3626 |
03 Aug 07 |
nicklas |
73 |
if (rawBioAssays.length > 0) |
3626 |
03 Aug 07 |
nicklas |
74 |
{ |
3626 |
03 Aug 07 |
nicklas |
75 |
ok &= TestRawBioAssay.test_list_raw_data(rawBioAssays[0], 10, 5, 97, true); |
3626 |
03 Aug 07 |
nicklas |
76 |
} |
3626 |
03 Aug 07 |
nicklas |
77 |
|
3626 |
03 Aug 07 |
nicklas |
// Clean up test |
3626 |
03 Aug 07 |
nicklas |
79 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
3626 |
03 Aug 07 |
nicklas |
80 |
TestExperiment.test_delete(experimentId); |
3626 |
03 Aug 07 |
nicklas |
81 |
for (int rawId : rawBioAssays) |
3626 |
03 Aug 07 |
nicklas |
82 |
{ |
3626 |
03 Aug 07 |
nicklas |
83 |
TestRawBioAssay.test_delete(rawId); |
3626 |
03 Aug 07 |
nicklas |
84 |
} |
4256 |
29 Apr 08 |
nicklas |
85 |
TestJob.test_delete(jobId); |
3626 |
03 Aug 07 |
nicklas |
86 |
|
5692 |
11 Aug 11 |
nicklas |
87 |
TestDerivedBioAssay.test_delete(scan1Id); |
5692 |
11 Aug 11 |
nicklas |
88 |
TestDerivedBioAssay.test_delete(scan2Id); |
5694 |
12 Aug 11 |
nicklas |
89 |
|
3626 |
03 Aug 07 |
nicklas |
90 |
TestSoftware.test_delete(softwareId); |
3626 |
03 Aug 07 |
nicklas |
91 |
TestProtocol.test_delete(protocolId); |
5692 |
11 Aug 11 |
nicklas |
92 |
TestPhysicalBioAssay.test_delete(hyb1Id); |
5692 |
11 Aug 11 |
nicklas |
93 |
TestPhysicalBioAssay.test_delete(hyb2Id); |
3626 |
03 Aug 07 |
nicklas |
94 |
TestFile.test_delete(fileId); |
3626 |
03 Aug 07 |
nicklas |
95 |
TestReporter.test_delete(); |
5694 |
12 Aug 11 |
nicklas |
96 |
for (int i = 0; i < extractIds.length; ++i) |
5694 |
12 Aug 11 |
nicklas |
97 |
{ |
5694 |
12 Aug 11 |
nicklas |
98 |
TestExtract.test_delete(extractIds[i]); |
5694 |
12 Aug 11 |
nicklas |
99 |
} |
3626 |
03 Aug 07 |
nicklas |
100 |
|
3626 |
03 Aug 07 |
nicklas |
101 |
write("++Testing Illumina rawdata import "+(ok ? "OK" : "Failed")+"\n"); |
3626 |
03 Aug 07 |
nicklas |
102 |
return ok; |
3626 |
03 Aug 07 |
nicklas |
103 |
} |
3626 |
03 Aug 07 |
nicklas |
104 |
|
5692 |
11 Aug 11 |
nicklas |
105 |
static int test_create_job(int pluginId, int fileId, int protocolId, int softwareId, int experimentId, int... scanIds) |
3626 |
03 Aug 07 |
nicklas |
106 |
{ |
3626 |
03 Aug 07 |
nicklas |
107 |
if (pluginId == 0 || fileId == 0 || experimentId == 0 && !TestUtil.hasPermission(Permission.CREATE, Item.JOB)) return 0; |
3626 |
03 Aug 07 |
nicklas |
108 |
int id = 0; |
3626 |
03 Aug 07 |
nicklas |
109 |
DbControl dc = null; |
3626 |
03 Aug 07 |
nicklas |
110 |
try |
3626 |
03 Aug 07 |
nicklas |
111 |
{ |
3626 |
03 Aug 07 |
nicklas |
112 |
dc = TestUtil.getDbControl(); |
3626 |
03 Aug 07 |
nicklas |
113 |
File file = File.getById(dc, fileId); |
3626 |
03 Aug 07 |
nicklas |
114 |
|
3626 |
03 Aug 07 |
nicklas |
115 |
PluginDefinition plugin = PluginDefinition.getById(dc, pluginId); |
4254 |
28 Apr 08 |
nicklas |
116 |
Experiment experiment = (experimentId > 0) ? Experiment.getById(dc, experimentId) : null; |
4254 |
28 Apr 08 |
nicklas |
117 |
Job j = Job.getNew(dc, plugin, null, experiment); |
3626 |
03 Aug 07 |
nicklas |
118 |
j.setName("Import Illumina data from file " + file.getName()); |
3626 |
03 Aug 07 |
nicklas |
119 |
|
3626 |
03 Aug 07 |
nicklas |
120 |
GuiContext context = new GuiContext(Item.EXPERIMENT, GuiContext.Type.LIST); |
3626 |
03 Aug 07 |
nicklas |
121 |
PluginConfigurationRequest request = j.configure(context); |
3626 |
03 Aug 07 |
nicklas |
122 |
write_request_information(request.getRequestInformation()); |
3626 |
03 Aug 07 |
nicklas |
123 |
request.setParameterValue("file", file); |
3626 |
03 Aug 07 |
nicklas |
124 |
if (experimentId != 0) |
3626 |
03 Aug 07 |
nicklas |
125 |
{ |
3626 |
03 Aug 07 |
nicklas |
126 |
request.setParameterValue("experiment", Experiment.getById(dc, experimentId)); |
3626 |
03 Aug 07 |
nicklas |
127 |
} |
5692 |
11 Aug 11 |
nicklas |
128 |
if (scanIds != null && scanIds.length > 0) |
3626 |
03 Aug 07 |
nicklas |
129 |
{ |
5692 |
11 Aug 11 |
nicklas |
130 |
List<DerivedBioAssay> bioAssays = new ArrayList<DerivedBioAssay>(scanIds.length); |
5692 |
11 Aug 11 |
nicklas |
131 |
for (int scanId : scanIds) |
5692 |
11 Aug 11 |
nicklas |
132 |
{ |
5692 |
11 Aug 11 |
nicklas |
133 |
bioAssays.add(DerivedBioAssay.getById(dc, scanId)); |
5692 |
11 Aug 11 |
nicklas |
134 |
} |
5692 |
11 Aug 11 |
nicklas |
135 |
request.setParameterValues("bioAssays", bioAssays); |
3626 |
03 Aug 07 |
nicklas |
136 |
} |
3626 |
03 Aug 07 |
nicklas |
137 |
if (protocolId != 0) |
3626 |
03 Aug 07 |
nicklas |
138 |
{ |
3626 |
03 Aug 07 |
nicklas |
139 |
request.setParameterValue("protocol", Protocol.getById(dc, protocolId)); |
3626 |
03 Aug 07 |
nicklas |
140 |
} |
3626 |
03 Aug 07 |
nicklas |
141 |
if (softwareId != 0) |
3626 |
03 Aug 07 |
nicklas |
142 |
{ |
3626 |
03 Aug 07 |
nicklas |
143 |
request.setParameterValue("software", Software.getById(dc, softwareId)); |
3626 |
03 Aug 07 |
nicklas |
144 |
} |
3626 |
03 Aug 07 |
nicklas |
145 |
request.setParameterValue("decimalSeparator", "dot"); |
3626 |
03 Aug 07 |
nicklas |
146 |
request.setParameterValue("defaultError", "fail"); |
3626 |
03 Aug 07 |
nicklas |
147 |
request.setParameterValue("missingReporterError", "null"); |
3626 |
03 Aug 07 |
nicklas |
148 |
request.setParameterValue("invalidColumnsError", "ignore"); |
3626 |
03 Aug 07 |
nicklas |
149 |
request.setParameterValue("numberFormatError", "null"); |
4247 |
24 Apr 08 |
nicklas |
150 |
request.setParameterValue("featureMismatchError", "smart"); |
3626 |
03 Aug 07 |
nicklas |
151 |
|
3626 |
03 Aug 07 |
nicklas |
152 |
PluginResponse response = request.invoke(); |
3626 |
03 Aug 07 |
nicklas |
153 |
if (response.getStatus() == Response.Status.DONE) |
3626 |
03 Aug 07 |
nicklas |
154 |
{ |
3626 |
03 Aug 07 |
nicklas |
155 |
dc.saveItem(j); |
3626 |
03 Aug 07 |
nicklas |
156 |
response.saveParameters(dc); |
3626 |
03 Aug 07 |
nicklas |
157 |
dc.commit(); |
3626 |
03 Aug 07 |
nicklas |
158 |
} |
3626 |
03 Aug 07 |
nicklas |
159 |
else |
3626 |
03 Aug 07 |
nicklas |
160 |
{ |
3626 |
03 Aug 07 |
nicklas |
161 |
throw new BaseException(response.getMessage(), response.getErrorList().get(0)); |
3626 |
03 Aug 07 |
nicklas |
162 |
} |
3626 |
03 Aug 07 |
nicklas |
163 |
id = j.getId(); |
3626 |
03 Aug 07 |
nicklas |
164 |
write("--Create job for Illumina import OK"); |
3626 |
03 Aug 07 |
nicklas |
165 |
} |
3626 |
03 Aug 07 |
nicklas |
166 |
catch (Throwable ex) |
3626 |
03 Aug 07 |
nicklas |
167 |
{ |
3626 |
03 Aug 07 |
nicklas |
168 |
write("--Create job for Illumina import FAILED"); |
3626 |
03 Aug 07 |
nicklas |
169 |
ex.printStackTrace(); |
3626 |
03 Aug 07 |
nicklas |
170 |
ok = false; |
3626 |
03 Aug 07 |
nicklas |
171 |
} |
3626 |
03 Aug 07 |
nicklas |
172 |
finally |
3626 |
03 Aug 07 |
nicklas |
173 |
{ |
3626 |
03 Aug 07 |
nicklas |
174 |
if (dc != null) dc.close(); |
3626 |
03 Aug 07 |
nicklas |
175 |
} |
3626 |
03 Aug 07 |
nicklas |
176 |
return id; |
3626 |
03 Aug 07 |
nicklas |
177 |
} |
3626 |
03 Aug 07 |
nicklas |
178 |
|
3626 |
03 Aug 07 |
nicklas |
179 |
static void write(String message) |
3626 |
03 Aug 07 |
nicklas |
180 |
{ |
3626 |
03 Aug 07 |
nicklas |
181 |
System.out.println(message); |
3626 |
03 Aug 07 |
nicklas |
182 |
} |
3626 |
03 Aug 07 |
nicklas |
183 |
|
3626 |
03 Aug 07 |
nicklas |
184 |
static void write_request_information(RequestInformation ri) |
3626 |
03 Aug 07 |
nicklas |
185 |
{ |
3626 |
03 Aug 07 |
nicklas |
186 |
if (TestUtil.getSilent()) return; |
3626 |
03 Aug 07 |
nicklas |
187 |
|
3626 |
03 Aug 07 |
nicklas |
188 |
write("Request information for command: "+ri.getCommand()); |
3626 |
03 Aug 07 |
nicklas |
189 |
write("\tTitle:\t"+ri.getTitle()); |
3626 |
03 Aug 07 |
nicklas |
190 |
write("\tDescription:\t"+ri.getDescription()); |
3626 |
03 Aug 07 |
nicklas |
191 |
for (PluginParameter<?> pp : ri.getParameters()) |
3626 |
03 Aug 07 |
nicklas |
192 |
{ |
6875 |
20 Apr 15 |
nicklas |
193 |
ParameterType<?> pt = pp.getParameterType(); |
3626 |
03 Aug 07 |
nicklas |
194 |
System.out.println("\tParameter:\t"+pp.getName() + "\t" + pp.getLabel() + "\t" + pt ); |
3626 |
03 Aug 07 |
nicklas |
195 |
} |
3626 |
03 Aug 07 |
nicklas |
196 |
} |
3626 |
03 Aug 07 |
nicklas |
197 |
|
3626 |
03 Aug 07 |
nicklas |
198 |
static int[] test_getRawBioAssays(int experimentId) |
3626 |
03 Aug 07 |
nicklas |
199 |
{ |
3626 |
03 Aug 07 |
nicklas |
200 |
int[] rawId = new int[0]; |
3626 |
03 Aug 07 |
nicklas |
201 |
if (experimentId == 0) return rawId; |
3626 |
03 Aug 07 |
nicklas |
202 |
DbControl dc = null; |
3626 |
03 Aug 07 |
nicklas |
203 |
try |
3626 |
03 Aug 07 |
nicklas |
204 |
{ |
3626 |
03 Aug 07 |
nicklas |
205 |
dc = TestUtil.getDbControl(); |
3626 |
03 Aug 07 |
nicklas |
206 |
Experiment experiment = Experiment.getById(dc, experimentId); |
3626 |
03 Aug 07 |
nicklas |
207 |
List<RawBioAssay> rawBioAssays = experiment.getRawBioAssays().list(dc); |
3626 |
03 Aug 07 |
nicklas |
208 |
rawId = new int[rawBioAssays.size()]; |
3626 |
03 Aug 07 |
nicklas |
209 |
|
3626 |
03 Aug 07 |
nicklas |
210 |
for (int i = 0; i < rawId.length; ++i) |
3626 |
03 Aug 07 |
nicklas |
211 |
{ |
3626 |
03 Aug 07 |
nicklas |
212 |
rawId[i] = rawBioAssays.get(i).getId(); |
3626 |
03 Aug 07 |
nicklas |
213 |
} |
3626 |
03 Aug 07 |
nicklas |
214 |
write("--Get imported Illumina raw bioassays OK"); |
3626 |
03 Aug 07 |
nicklas |
215 |
} |
3626 |
03 Aug 07 |
nicklas |
216 |
catch (Throwable ex) |
3626 |
03 Aug 07 |
nicklas |
217 |
{ |
3626 |
03 Aug 07 |
nicklas |
218 |
write("--Get imported of Illumina raw bioassays FAILED"); |
3626 |
03 Aug 07 |
nicklas |
219 |
ex.printStackTrace(); |
3626 |
03 Aug 07 |
nicklas |
220 |
ok = false; |
3626 |
03 Aug 07 |
nicklas |
221 |
} |
3626 |
03 Aug 07 |
nicklas |
222 |
finally |
3626 |
03 Aug 07 |
nicklas |
223 |
{ |
3626 |
03 Aug 07 |
nicklas |
224 |
if (dc != null) dc.close(); |
3626 |
03 Aug 07 |
nicklas |
225 |
} |
3626 |
03 Aug 07 |
nicklas |
226 |
return rawId; |
3626 |
03 Aug 07 |
nicklas |
227 |
} |
3626 |
03 Aug 07 |
nicklas |
228 |
|
3626 |
03 Aug 07 |
nicklas |
229 |
} |
3626 |
03 Aug 07 |
nicklas |
230 |
|