5228 |
03 Feb 10 |
nicklas |
1 |
/* |
5228 |
03 Feb 10 |
nicklas |
$Id$ |
5228 |
03 Feb 10 |
nicklas |
3 |
|
5228 |
03 Feb 10 |
nicklas |
Copyright (C) 2010 Nicklas Nordborg |
5228 |
03 Feb 10 |
nicklas |
5 |
|
5228 |
03 Feb 10 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5228 |
03 Feb 10 |
nicklas |
Available at http://base.thep.lu.se/ |
5228 |
03 Feb 10 |
nicklas |
8 |
|
5228 |
03 Feb 10 |
nicklas |
BASE is free software; you can redistribute it and/or modify it |
5228 |
03 Feb 10 |
nicklas |
under the terms of the GNU General Public License as published by |
5228 |
03 Feb 10 |
nicklas |
the Free Software Foundation; either version 3 of the License, or |
5228 |
03 Feb 10 |
nicklas |
(at your option) any later version. |
5228 |
03 Feb 10 |
nicklas |
13 |
|
5228 |
03 Feb 10 |
nicklas |
BASE is distributed in the hope that it will be useful, but |
5228 |
03 Feb 10 |
nicklas |
WITHOUT ANY WARRANTY; without even the implied warranty of |
5228 |
03 Feb 10 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
5228 |
03 Feb 10 |
nicklas |
General Public License for more details. |
5228 |
03 Feb 10 |
nicklas |
18 |
|
5228 |
03 Feb 10 |
nicklas |
You should have received a copy of the GNU General Public License |
5228 |
03 Feb 10 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5228 |
03 Feb 10 |
nicklas |
21 |
*/ |
5228 |
03 Feb 10 |
nicklas |
22 |
|
5228 |
03 Feb 10 |
nicklas |
23 |
import java.util.List; |
5228 |
03 Feb 10 |
nicklas |
24 |
|
5228 |
03 Feb 10 |
nicklas |
25 |
import net.sf.basedb.core.BaseException; |
5228 |
03 Feb 10 |
nicklas |
26 |
import net.sf.basedb.core.DbControl; |
5228 |
03 Feb 10 |
nicklas |
27 |
import net.sf.basedb.core.Experiment; |
5228 |
03 Feb 10 |
nicklas |
28 |
import net.sf.basedb.core.Formula; |
5228 |
03 Feb 10 |
nicklas |
29 |
import net.sf.basedb.core.Item; |
5228 |
03 Feb 10 |
nicklas |
30 |
import net.sf.basedb.core.Job; |
5228 |
03 Feb 10 |
nicklas |
31 |
import net.sf.basedb.core.PluginConfigurationRequest; |
5228 |
03 Feb 10 |
nicklas |
32 |
import net.sf.basedb.core.PluginDefinition; |
5228 |
03 Feb 10 |
nicklas |
33 |
import net.sf.basedb.core.PluginResponse; |
5228 |
03 Feb 10 |
nicklas |
34 |
import net.sf.basedb.core.RawBioAssay; |
5228 |
03 Feb 10 |
nicklas |
35 |
import net.sf.basedb.core.plugin.Response; |
5228 |
03 Feb 10 |
nicklas |
36 |
import net.sf.basedb.plugins.IntensityCalculatorPlugin; |
5228 |
03 Feb 10 |
nicklas |
37 |
|
5228 |
03 Feb 10 |
nicklas |
38 |
public class TestIntensityCalculatorPlugin |
5228 |
03 Feb 10 |
nicklas |
39 |
{ |
5228 |
03 Feb 10 |
nicklas |
40 |
static boolean ok = true; |
5228 |
03 Feb 10 |
nicklas |
41 |
public static void main(String[] args) |
5228 |
03 Feb 10 |
nicklas |
42 |
{ |
5228 |
03 Feb 10 |
nicklas |
43 |
TestUtil.checkArgs(args); |
5228 |
03 Feb 10 |
nicklas |
44 |
TestUtil.begin(); |
5228 |
03 Feb 10 |
nicklas |
45 |
ok = test_all(); |
5228 |
03 Feb 10 |
nicklas |
46 |
TestUtil.stop(); |
5228 |
03 Feb 10 |
nicklas |
47 |
} |
5228 |
03 Feb 10 |
nicklas |
48 |
|
5228 |
03 Feb 10 |
nicklas |
49 |
static boolean test_all() |
5228 |
03 Feb 10 |
nicklas |
50 |
{ |
5228 |
03 Feb 10 |
nicklas |
51 |
boolean wasSetup = TestAnalyzeUtil.setupExperiment(); |
5228 |
03 Feb 10 |
nicklas |
52 |
write("++Testing intensity calculator plug-in"); |
5228 |
03 Feb 10 |
nicklas |
53 |
try |
5228 |
03 Feb 10 |
nicklas |
54 |
{ |
5228 |
03 Feb 10 |
nicklas |
55 |
int experimentId = TestAnalyzeUtil.getItemId("experiment.genepix"); |
5228 |
03 Feb 10 |
nicklas |
56 |
int formulaId = TestAnalyzeUtil.getItemId("formula.intensity.genepix.mean"); |
5228 |
03 Feb 10 |
nicklas |
57 |
if (experimentId == 0 || formulaId == 0) |
5228 |
03 Feb 10 |
nicklas |
58 |
{ |
5228 |
03 Feb 10 |
nicklas |
59 |
ok = false; |
5228 |
03 Feb 10 |
nicklas |
60 |
write("Test experiment was not setup correctly."); |
5228 |
03 Feb 10 |
nicklas |
61 |
return ok; |
5228 |
03 Feb 10 |
nicklas |
62 |
} |
5228 |
03 Feb 10 |
nicklas |
63 |
|
5228 |
03 Feb 10 |
nicklas |
64 |
int jobId = test_create_job(experimentId, formulaId, "Intensity calculator plugin"); |
5319 |
20 Apr 10 |
nicklas |
65 |
ok &= TestJob.test_execute(jobId, false); |
5228 |
03 Feb 10 |
nicklas |
66 |
int rootBasId = TestAnalyzeUtil.getBioAssaySetIdByName(experimentId, "Intensity calculator plugin"); |
5228 |
03 Feb 10 |
nicklas |
67 |
TestAnalyzeUtil.setItemId("bioassayset.root.intensity-calculator-plugin", rootBasId); |
5228 |
03 Feb 10 |
nicklas |
68 |
} |
5228 |
03 Feb 10 |
nicklas |
69 |
finally |
5228 |
03 Feb 10 |
nicklas |
70 |
{ |
5228 |
03 Feb 10 |
nicklas |
71 |
if (wasSetup) TestAnalyzeUtil.cleanupExperiment(); |
5228 |
03 Feb 10 |
nicklas |
72 |
write("++Testing intensity calculator plug-in "+(ok ? "OK" : "Failed")+"\n"); |
5228 |
03 Feb 10 |
nicklas |
73 |
} |
5228 |
03 Feb 10 |
nicklas |
74 |
return ok; |
5228 |
03 Feb 10 |
nicklas |
75 |
} |
5228 |
03 Feb 10 |
nicklas |
76 |
|
5228 |
03 Feb 10 |
nicklas |
77 |
static int test_create_job(int experimentId, int formulaId, String rootName) |
5228 |
03 Feb 10 |
nicklas |
78 |
{ |
5228 |
03 Feb 10 |
nicklas |
79 |
if (experimentId == 0 || formulaId == 0) return 0; |
5228 |
03 Feb 10 |
nicklas |
80 |
DbControl dc = null; |
5228 |
03 Feb 10 |
nicklas |
81 |
int id = 0; |
5228 |
03 Feb 10 |
nicklas |
82 |
try |
5228 |
03 Feb 10 |
nicklas |
83 |
{ |
5228 |
03 Feb 10 |
nicklas |
84 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
85 |
PluginDefinition plugin = PluginDefinition.getByClassName(dc, IntensityCalculatorPlugin.class.getName()); |
5228 |
03 Feb 10 |
nicklas |
86 |
Experiment experiment = Experiment.getById(dc, experimentId); |
5228 |
03 Feb 10 |
nicklas |
87 |
Formula formula = Formula.getById(dc, formulaId); |
5228 |
03 Feb 10 |
nicklas |
88 |
List<RawBioAssay> rawBioAssays = experiment.getRawBioAssays().list(dc); |
5228 |
03 Feb 10 |
nicklas |
89 |
dc.getSessionControl().getCurrentContext(Item.EXPERIMENT).setId(experimentId); |
5228 |
03 Feb 10 |
nicklas |
90 |
Job job = Job.getNew(dc, plugin, null, experiment); |
5228 |
03 Feb 10 |
nicklas |
91 |
job.setName("Calculating root intensities using "); |
5228 |
03 Feb 10 |
nicklas |
92 |
|
5228 |
03 Feb 10 |
nicklas |
93 |
PluginConfigurationRequest request = job.configure(null); |
5228 |
03 Feb 10 |
nicklas |
94 |
request.setParameterValue("experiment", experiment); |
5228 |
03 Feb 10 |
nicklas |
95 |
request.setParameterValue("name", rootName); |
5228 |
03 Feb 10 |
nicklas |
96 |
request.setParameterValue("formula", formula); |
5228 |
03 Feb 10 |
nicklas |
97 |
request.setParameterValues("rawBioAssays", rawBioAssays); |
5228 |
03 Feb 10 |
nicklas |
98 |
|
5228 |
03 Feb 10 |
nicklas |
99 |
TestJob.write_request_information(request.getRequestInformation()); |
5228 |
03 Feb 10 |
nicklas |
100 |
|
5228 |
03 Feb 10 |
nicklas |
101 |
PluginResponse response = request.invoke(); |
5228 |
03 Feb 10 |
nicklas |
102 |
if (response.getStatus() == Response.Status.DONE) |
5228 |
03 Feb 10 |
nicklas |
103 |
{ |
5228 |
03 Feb 10 |
nicklas |
104 |
response.saveParameters(dc); |
5228 |
03 Feb 10 |
nicklas |
105 |
dc.saveItem(job); |
5228 |
03 Feb 10 |
nicklas |
106 |
dc.commit(); |
5228 |
03 Feb 10 |
nicklas |
107 |
} |
5228 |
03 Feb 10 |
nicklas |
108 |
else |
5228 |
03 Feb 10 |
nicklas |
109 |
{ |
5228 |
03 Feb 10 |
nicklas |
110 |
throw new BaseException(response.getMessage(), response.getErrorList().get(0)); |
5228 |
03 Feb 10 |
nicklas |
111 |
} |
5228 |
03 Feb 10 |
nicklas |
112 |
id = job.getId(); |
5228 |
03 Feb 10 |
nicklas |
113 |
|
5228 |
03 Feb 10 |
nicklas |
114 |
|
5228 |
03 Feb 10 |
nicklas |
115 |
write("--Create job for root intensity calculation OK"); |
5228 |
03 Feb 10 |
nicklas |
116 |
|
5228 |
03 Feb 10 |
nicklas |
117 |
} |
5228 |
03 Feb 10 |
nicklas |
118 |
catch (Throwable ex) |
5228 |
03 Feb 10 |
nicklas |
119 |
{ |
5228 |
03 Feb 10 |
nicklas |
120 |
write("--Create job for root intensity calculation FAILED"); |
5228 |
03 Feb 10 |
nicklas |
121 |
ex.printStackTrace(); |
5228 |
03 Feb 10 |
nicklas |
122 |
ok = false; |
5228 |
03 Feb 10 |
nicklas |
123 |
} |
5228 |
03 Feb 10 |
nicklas |
124 |
finally |
5228 |
03 Feb 10 |
nicklas |
125 |
{ |
5228 |
03 Feb 10 |
nicklas |
126 |
if (dc != null) dc.close(); |
5228 |
03 Feb 10 |
nicklas |
127 |
} |
5228 |
03 Feb 10 |
nicklas |
128 |
return id; |
5228 |
03 Feb 10 |
nicklas |
129 |
} |
5228 |
03 Feb 10 |
nicklas |
130 |
|
5228 |
03 Feb 10 |
nicklas |
131 |
|
5228 |
03 Feb 10 |
nicklas |
132 |
static void write(String message) |
5228 |
03 Feb 10 |
nicklas |
133 |
{ |
5228 |
03 Feb 10 |
nicklas |
134 |
System.out.println(message); |
5228 |
03 Feb 10 |
nicklas |
135 |
} |
5228 |
03 Feb 10 |
nicklas |
136 |
} |