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