2036 |
21 Feb 06 |
enell |
1 |
/* |
2205 |
28 Apr 06 |
enell |
$Id$ |
2036 |
21 Feb 06 |
enell |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2006 Johan Enell, Nicklas Nordborg |
2205 |
28 Apr 06 |
enell |
5 |
|
2205 |
28 Apr 06 |
enell |
This file is part of BASE - BioArray Software Environment. |
2205 |
28 Apr 06 |
enell |
Available at http://base.thep.lu.se/ |
2205 |
28 Apr 06 |
enell |
8 |
|
2205 |
28 Apr 06 |
enell |
BASE is free software; you can redistribute it and/or modify it |
2205 |
28 Apr 06 |
enell |
under the terms of the GNU General Public License as published by |
4480 |
05 Sep 08 |
jari |
the Free Software Foundation; either version 3 of the License, or |
2205 |
28 Apr 06 |
enell |
(at your option) any later version. |
2205 |
28 Apr 06 |
enell |
13 |
|
2205 |
28 Apr 06 |
enell |
BASE is distributed in the hope that it will be useful, but |
2205 |
28 Apr 06 |
enell |
WITHOUT ANY WARRANTY; without even the implied warranty of |
2205 |
28 Apr 06 |
enell |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2205 |
28 Apr 06 |
enell |
General Public License for more details. |
2205 |
28 Apr 06 |
enell |
18 |
|
2205 |
28 Apr 06 |
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/>. |
2205 |
28 Apr 06 |
enell |
21 |
*/ |
5228 |
03 Feb 10 |
nicklas |
22 |
import net.sf.basedb.core.BaseException; |
5228 |
03 Feb 10 |
nicklas |
23 |
import net.sf.basedb.core.BioAssaySet; |
5228 |
03 Feb 10 |
nicklas |
24 |
import net.sf.basedb.core.DbControl; |
5228 |
03 Feb 10 |
nicklas |
25 |
import net.sf.basedb.core.Experiment; |
5228 |
03 Feb 10 |
nicklas |
26 |
import net.sf.basedb.core.Item; |
5228 |
03 Feb 10 |
nicklas |
27 |
import net.sf.basedb.core.Job; |
5228 |
03 Feb 10 |
nicklas |
28 |
import net.sf.basedb.core.Permission; |
5228 |
03 Feb 10 |
nicklas |
29 |
import net.sf.basedb.core.PluginConfigurationRequest; |
5228 |
03 Feb 10 |
nicklas |
30 |
import net.sf.basedb.core.PluginDefinition; |
5228 |
03 Feb 10 |
nicklas |
31 |
import net.sf.basedb.core.PluginResponse; |
5228 |
03 Feb 10 |
nicklas |
32 |
import net.sf.basedb.core.plugin.Response; |
5228 |
03 Feb 10 |
nicklas |
33 |
import net.sf.basedb.plugins.LowessNormalization; |
2205 |
28 Apr 06 |
enell |
34 |
|
2036 |
21 Feb 06 |
enell |
35 |
public class TestLowessNormalization |
2036 |
21 Feb 06 |
enell |
36 |
{ |
2036 |
21 Feb 06 |
enell |
37 |
static boolean ok = true; |
2036 |
21 Feb 06 |
enell |
38 |
public static void main(String[] args) |
2036 |
21 Feb 06 |
enell |
39 |
{ |
2036 |
21 Feb 06 |
enell |
40 |
TestUtil.checkArgs(args); |
2036 |
21 Feb 06 |
enell |
41 |
TestUtil.begin(); |
2036 |
21 Feb 06 |
enell |
42 |
ok = test_all(); |
2036 |
21 Feb 06 |
enell |
43 |
TestUtil.stop(); |
2036 |
21 Feb 06 |
enell |
44 |
} |
2036 |
21 Feb 06 |
enell |
45 |
|
2036 |
21 Feb 06 |
enell |
46 |
static boolean test_all() |
2036 |
21 Feb 06 |
enell |
47 |
{ |
5228 |
03 Feb 10 |
nicklas |
48 |
boolean wasSetup = TestAnalyzeUtil.setupExperiment(); |
5228 |
03 Feb 10 |
nicklas |
49 |
write("++Testing Lowess normalization"); |
2036 |
21 Feb 06 |
enell |
50 |
try |
2036 |
21 Feb 06 |
enell |
51 |
{ |
5228 |
03 Feb 10 |
nicklas |
52 |
int experimentId = TestAnalyzeUtil.getItemId("experiment.genepix"); |
5228 |
03 Feb 10 |
nicklas |
53 |
int rootBasId = TestAnalyzeUtil.getItemId("bioassayset.root"); |
5228 |
03 Feb 10 |
nicklas |
54 |
if (experimentId == 0 || rootBasId == 0) |
2036 |
21 Feb 06 |
enell |
55 |
{ |
5228 |
03 Feb 10 |
nicklas |
56 |
ok = false; |
5228 |
03 Feb 10 |
nicklas |
57 |
write("Test experiment was not setup correctly."); |
5228 |
03 Feb 10 |
nicklas |
58 |
return ok; |
2036 |
21 Feb 06 |
enell |
59 |
} |
5228 |
03 Feb 10 |
nicklas |
60 |
|
5228 |
03 Feb 10 |
nicklas |
61 |
int jobId = test_create_job(experimentId, rootBasId, "Lowess normalized", 0.33F, 0.1F, 4, 1); |
5319 |
20 Apr 10 |
nicklas |
62 |
ok &= TestJob.test_execute(jobId, false); |
5228 |
03 Feb 10 |
nicklas |
63 |
int normalizedBasId = TestAnalyzeUtil.getBioAssaySetIdByName(experimentId, "Lowess normalized"); |
5228 |
03 Feb 10 |
nicklas |
64 |
TestAnalyzeUtil.setItemId("bioassayset.lowess", normalizedBasId); |
5228 |
03 Feb 10 |
nicklas |
65 |
|
2036 |
21 Feb 06 |
enell |
66 |
} |
2036 |
21 Feb 06 |
enell |
67 |
finally |
2036 |
21 Feb 06 |
enell |
68 |
{ |
5228 |
03 Feb 10 |
nicklas |
69 |
if (wasSetup) TestAnalyzeUtil.cleanupExperiment(); |
5228 |
03 Feb 10 |
nicklas |
70 |
write("++Testing Lowess normalization "+(ok ? "OK" : "Failed")+"\n"); |
2036 |
21 Feb 06 |
enell |
71 |
} |
5228 |
03 Feb 10 |
nicklas |
72 |
return ok; |
2036 |
21 Feb 06 |
enell |
73 |
} |
2036 |
21 Feb 06 |
enell |
74 |
|
5228 |
03 Feb 10 |
nicklas |
75 |
static int test_create_job(int experimentId, int bioAssaySetId, |
5228 |
03 Feb 10 |
nicklas |
76 |
String childName, float fitFraction, float delta, int iterations, int blockGroup) |
2036 |
21 Feb 06 |
enell |
77 |
{ |
5228 |
03 Feb 10 |
nicklas |
78 |
if (experimentId == 0 || bioAssaySetId == 0 || |
5228 |
03 Feb 10 |
nicklas |
79 |
!TestUtil.hasPermission(Permission.CREATE, Item.JOB)) |
5228 |
03 Feb 10 |
nicklas |
80 |
{ |
5228 |
03 Feb 10 |
nicklas |
81 |
return 0; |
5228 |
03 Feb 10 |
nicklas |
82 |
} |
2036 |
21 Feb 06 |
enell |
83 |
int id = 0; |
2036 |
21 Feb 06 |
enell |
84 |
DbControl dc = null; |
2036 |
21 Feb 06 |
enell |
85 |
try |
2036 |
21 Feb 06 |
enell |
86 |
{ |
2036 |
21 Feb 06 |
enell |
87 |
dc = TestUtil.getDbControl(); |
2036 |
21 Feb 06 |
enell |
88 |
|
2036 |
21 Feb 06 |
enell |
89 |
Experiment e = Experiment.getById(dc, experimentId); |
5228 |
03 Feb 10 |
nicklas |
90 |
BioAssaySet bioAssaySet = BioAssaySet.getById(dc, bioAssaySetId); |
2036 |
21 Feb 06 |
enell |
91 |
|
5228 |
03 Feb 10 |
nicklas |
92 |
PluginDefinition plugin = PluginDefinition.getByClassName(dc, LowessNormalization.class.getName()); |
5228 |
03 Feb 10 |
nicklas |
93 |
Job j = Job.getNew(dc, plugin, null, e); |
5228 |
03 Feb 10 |
nicklas |
94 |
j.setName("Normalizing using Lowess"); |
5228 |
03 Feb 10 |
nicklas |
95 |
dc.getSessionControl().getCurrentContext(Item.BIOASSAYSET).setId(bioAssaySetId); |
2036 |
21 Feb 06 |
enell |
96 |
PluginConfigurationRequest request = j.configure(null); |
5228 |
03 Feb 10 |
nicklas |
97 |
request.setParameterValue("source", bioAssaySet); |
5228 |
03 Feb 10 |
nicklas |
98 |
request.setParameterValue("childName", childName); |
2036 |
21 Feb 06 |
enell |
99 |
request.setParameterValue("fitFraction", fitFraction); |
2036 |
21 Feb 06 |
enell |
100 |
request.setParameterValue("delta", delta); |
2036 |
21 Feb 06 |
enell |
101 |
request.setParameterValue("iter", iterations); |
2036 |
21 Feb 06 |
enell |
102 |
|
5228 |
03 Feb 10 |
nicklas |
103 |
TestJob.write_request_information(request.getRequestInformation()); |
2036 |
21 Feb 06 |
enell |
104 |
|
2036 |
21 Feb 06 |
enell |
105 |
PluginResponse response = request.invoke(); |
2036 |
21 Feb 06 |
enell |
106 |
if (response.getStatus() == Response.Status.DONE) |
2036 |
21 Feb 06 |
enell |
107 |
{ |
2036 |
21 Feb 06 |
enell |
108 |
response.saveParameters(dc); |
2036 |
21 Feb 06 |
enell |
109 |
dc.saveItem(j); |
2036 |
21 Feb 06 |
enell |
110 |
dc.commit(); |
2036 |
21 Feb 06 |
enell |
111 |
} |
2036 |
21 Feb 06 |
enell |
112 |
else |
2036 |
21 Feb 06 |
enell |
113 |
{ |
2036 |
21 Feb 06 |
enell |
114 |
throw new BaseException(response.getMessage(), response.getErrorList().get(0)); |
2036 |
21 Feb 06 |
enell |
115 |
} |
2036 |
21 Feb 06 |
enell |
116 |
id = j.getId(); |
2036 |
21 Feb 06 |
enell |
117 |
write("--Create job for Lowess Normalization OK"); |
2036 |
21 Feb 06 |
enell |
118 |
} |
2036 |
21 Feb 06 |
enell |
119 |
catch (Throwable ex) |
2036 |
21 Feb 06 |
enell |
120 |
{ |
2036 |
21 Feb 06 |
enell |
121 |
write("--Create job for Lowess Normalization FAILED"); |
2036 |
21 Feb 06 |
enell |
122 |
ex.printStackTrace(); |
2036 |
21 Feb 06 |
enell |
123 |
ok = false; |
2036 |
21 Feb 06 |
enell |
124 |
} |
2036 |
21 Feb 06 |
enell |
125 |
finally |
2036 |
21 Feb 06 |
enell |
126 |
{ |
2036 |
21 Feb 06 |
enell |
127 |
if (dc != null) dc.close(); |
2036 |
21 Feb 06 |
enell |
128 |
} |
2036 |
21 Feb 06 |
enell |
129 |
return id; |
2036 |
21 Feb 06 |
enell |
130 |
} |
2036 |
21 Feb 06 |
enell |
131 |
|
2036 |
21 Feb 06 |
enell |
132 |
static void write(String message) |
2036 |
21 Feb 06 |
enell |
133 |
{ |
2036 |
21 Feb 06 |
enell |
134 |
System.out.println(message); |
2036 |
21 Feb 06 |
enell |
135 |
} |
2036 |
21 Feb 06 |
enell |
136 |
} |