5228 |
03 Feb 10 |
nicklas |
1 |
/* |
5228 |
03 Feb 10 |
nicklas |
$Id: TestExperiment.java 5060 2009-08-19 07:02:11Z nicklas $ |
5228 |
03 Feb 10 |
nicklas |
3 |
|
5228 |
03 Feb 10 |
nicklas |
Copyright (C) 2010 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 |
5228 |
03 Feb 10 |
nicklas |
modify it under the terms of the GNU General Public License |
5228 |
03 Feb 10 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5228 |
03 Feb 10 |
nicklas |
of the License, or (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, |
5228 |
03 Feb 10 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5228 |
03 Feb 10 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5228 |
03 Feb 10 |
nicklas |
GNU 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 net.sf.basedb.core.BaseException; |
5228 |
03 Feb 10 |
nicklas |
24 |
import net.sf.basedb.core.BioAssay; |
5228 |
03 Feb 10 |
nicklas |
25 |
import net.sf.basedb.core.BioAssaySet; |
5228 |
03 Feb 10 |
nicklas |
26 |
import net.sf.basedb.core.DataFileType; |
5228 |
03 Feb 10 |
nicklas |
27 |
import net.sf.basedb.core.DbControl; |
5228 |
03 Feb 10 |
nicklas |
28 |
import net.sf.basedb.core.DynamicExtraValueQuery; |
5228 |
03 Feb 10 |
nicklas |
29 |
import net.sf.basedb.core.DynamicResultIterator; |
5228 |
03 Feb 10 |
nicklas |
30 |
import net.sf.basedb.core.DynamicSpotQuery; |
5228 |
03 Feb 10 |
nicklas |
31 |
import net.sf.basedb.core.Experiment; |
5228 |
03 Feb 10 |
nicklas |
32 |
import net.sf.basedb.core.ExtraValue; |
5228 |
03 Feb 10 |
nicklas |
33 |
import net.sf.basedb.core.ExtraValueType; |
5228 |
03 Feb 10 |
nicklas |
34 |
import net.sf.basedb.core.File; |
5228 |
03 Feb 10 |
nicklas |
35 |
import net.sf.basedb.core.FileSet; |
5228 |
03 Feb 10 |
nicklas |
36 |
import net.sf.basedb.core.FileSetMember; |
5228 |
03 Feb 10 |
nicklas |
37 |
import net.sf.basedb.core.FileStoreUtil; |
5228 |
03 Feb 10 |
nicklas |
38 |
import net.sf.basedb.core.FilterBatcher; |
5228 |
03 Feb 10 |
nicklas |
39 |
import net.sf.basedb.core.Formula; |
5228 |
03 Feb 10 |
nicklas |
40 |
import net.sf.basedb.core.IntensityTransform; |
5228 |
03 Feb 10 |
nicklas |
41 |
import net.sf.basedb.core.ItemResultList; |
5630 |
13 May 11 |
nicklas |
42 |
import net.sf.basedb.core.ItemSubtype; |
5228 |
03 Feb 10 |
nicklas |
43 |
import net.sf.basedb.core.Path; |
5228 |
03 Feb 10 |
nicklas |
44 |
import net.sf.basedb.core.PositionExtraValueBatcher; |
5228 |
03 Feb 10 |
nicklas |
45 |
import net.sf.basedb.core.RawBioAssay; |
5228 |
03 Feb 10 |
nicklas |
46 |
import net.sf.basedb.core.RawDataType; |
5228 |
03 Feb 10 |
nicklas |
47 |
import net.sf.basedb.core.SpotBatcher; |
5228 |
03 Feb 10 |
nicklas |
48 |
import net.sf.basedb.core.SpotExtraValueBatcher; |
5228 |
03 Feb 10 |
nicklas |
49 |
import net.sf.basedb.core.SystemItems; |
5228 |
03 Feb 10 |
nicklas |
50 |
import net.sf.basedb.core.Transformation; |
5228 |
03 Feb 10 |
nicklas |
51 |
import net.sf.basedb.core.Type; |
5228 |
03 Feb 10 |
nicklas |
52 |
import net.sf.basedb.core.VirtualColumn; |
5228 |
03 Feb 10 |
nicklas |
53 |
import net.sf.basedb.core.query.Restrictions; |
5228 |
03 Feb 10 |
nicklas |
54 |
import net.sf.basedb.core.query.Expressions; |
5228 |
03 Feb 10 |
nicklas |
55 |
import net.sf.basedb.core.query.Expression; |
5228 |
03 Feb 10 |
nicklas |
56 |
import net.sf.basedb.core.query.Dynamic; |
5228 |
03 Feb 10 |
nicklas |
57 |
import net.sf.basedb.core.query.SqlResult; |
5228 |
03 Feb 10 |
nicklas |
58 |
import net.sf.basedb.core.query.JoinType; |
5228 |
03 Feb 10 |
nicklas |
59 |
import net.sf.basedb.core.query.Selects; |
5228 |
03 Feb 10 |
nicklas |
60 |
|
5228 |
03 Feb 10 |
nicklas |
61 |
import net.sf.basedb.util.IntensityCalculatorUtil; |
5228 |
03 Feb 10 |
nicklas |
62 |
import net.sf.basedb.util.jep.Jep; |
5228 |
03 Feb 10 |
nicklas |
63 |
import net.sf.basedb.util.jep.RawFunction; |
5228 |
03 Feb 10 |
nicklas |
64 |
import net.sf.basedb.util.ConsoleProgressReporter; |
5228 |
03 Feb 10 |
nicklas |
65 |
|
5228 |
03 Feb 10 |
nicklas |
66 |
import java.io.PrintWriter; |
5228 |
03 Feb 10 |
nicklas |
67 |
import java.util.Collections; |
5228 |
03 Feb 10 |
nicklas |
68 |
import java.util.List; |
5228 |
03 Feb 10 |
nicklas |
69 |
import java.util.ArrayList; |
5228 |
03 Feb 10 |
nicklas |
70 |
|
5228 |
03 Feb 10 |
nicklas |
71 |
|
5228 |
03 Feb 10 |
nicklas |
72 |
public class TestBasicAnalysis |
5228 |
03 Feb 10 |
nicklas |
73 |
{ |
5228 |
03 Feb 10 |
nicklas |
74 |
|
5228 |
03 Feb 10 |
nicklas |
75 |
static boolean ok = true; |
5228 |
03 Feb 10 |
nicklas |
76 |
public static void main(String[] args) |
5228 |
03 Feb 10 |
nicklas |
77 |
{ |
5228 |
03 Feb 10 |
nicklas |
78 |
TestUtil.checkArgs(args); |
5228 |
03 Feb 10 |
nicklas |
79 |
TestUtil.begin(); |
5228 |
03 Feb 10 |
nicklas |
80 |
ok = test_all(); |
5228 |
03 Feb 10 |
nicklas |
81 |
TestUtil.stop(); |
5228 |
03 Feb 10 |
nicklas |
82 |
} |
5228 |
03 Feb 10 |
nicklas |
83 |
|
5228 |
03 Feb 10 |
nicklas |
84 |
static boolean test_all() |
5228 |
03 Feb 10 |
nicklas |
85 |
{ |
5228 |
03 Feb 10 |
nicklas |
86 |
boolean wasSetup = TestAnalyzeUtil.setupExperiment(); |
5228 |
03 Feb 10 |
nicklas |
87 |
write("++Testing basic analysis"); |
5228 |
03 Feb 10 |
nicklas |
88 |
try |
5228 |
03 Feb 10 |
nicklas |
89 |
{ |
5228 |
03 Feb 10 |
nicklas |
90 |
int experimentId = TestAnalyzeUtil.getItemId("experiment.genepix"); |
5228 |
03 Feb 10 |
nicklas |
91 |
int rootBasId = TestAnalyzeUtil.getItemId("bioassayset.root"); |
5228 |
03 Feb 10 |
nicklas |
92 |
if (experimentId == 0 || rootBasId == 0) |
5228 |
03 Feb 10 |
nicklas |
93 |
{ |
5228 |
03 Feb 10 |
nicklas |
94 |
ok = false; |
5228 |
03 Feb 10 |
nicklas |
95 |
write("Test experiment was not setup correctly."); |
5228 |
03 Feb 10 |
nicklas |
96 |
return ok; |
5228 |
03 Feb 10 |
nicklas |
97 |
} |
5228 |
03 Feb 10 |
nicklas |
98 |
|
5228 |
03 Feb 10 |
nicklas |
// Create some root bioassay sets |
5228 |
03 Feb 10 |
nicklas |
100 |
int emptyRootId = test_create_empty_root_bioassayset(experimentId, "Empty root"); |
5228 |
03 Feb 10 |
nicklas |
101 |
int queryRootId = test_create_root_bioassayset_using_query(experimentId, "mean", "Query mean"); |
5228 |
03 Feb 10 |
nicklas |
102 |
TestAnalyzeUtil.setItemId("bioassayset.root.empty", emptyRootId); |
5228 |
03 Feb 10 |
nicklas |
103 |
TestAnalyzeUtil.setItemId("bioassayset.root.query", queryRootId); |
5228 |
03 Feb 10 |
nicklas |
104 |
|
5228 |
03 Feb 10 |
nicklas |
// Create a filtered bioassay set using core api |
5228 |
03 Feb 10 |
nicklas |
106 |
int filterBasId = test_filter_bioassayset(queryRootId, "Filtered; ch1 > 2*ch2", 2.0f); |
5228 |
03 Feb 10 |
nicklas |
107 |
TestAnalyzeUtil.setItemId("bioassayset.filtered", filterBasId); |
5228 |
03 Feb 10 |
nicklas |
108 |
|
5228 |
03 Feb 10 |
nicklas |
// Create a transformed bioassay set using core api |
5228 |
03 Feb 10 |
nicklas |
110 |
int transformedBasId = test_transform_bioassayset(filterBasId, "Transformed; ch1*2, ch2/2", 2.0f); |
5228 |
03 Feb 10 |
nicklas |
111 |
TestAnalyzeUtil.setItemId("bioassayset.transformed", transformedBasId); |
5228 |
03 Feb 10 |
nicklas |
112 |
|
5228 |
03 Feb 10 |
nicklas |
// Create a file-only bioassay set using core api |
5228 |
03 Feb 10 |
nicklas |
114 |
int fileBasId = test_create_file_bioassayset(rootBasId, "/spotdata-" + rootBasId + ".txt", |
5228 |
03 Feb 10 |
nicklas |
115 |
"File bioassayset"); |
5228 |
03 Feb 10 |
nicklas |
116 |
TestAnalyzeUtil.setItemId("bioassayset.file-only", fileBasId); |
5228 |
03 Feb 10 |
nicklas |
117 |
|
5228 |
03 Feb 10 |
nicklas |
// Create some extra values using core api |
5228 |
03 Feb 10 |
nicklas |
119 |
int intExtraId = TestAnalyzeUtil.getItemId("extravaluetype.int"); |
5228 |
03 Feb 10 |
nicklas |
120 |
int floatExtraId = TestAnalyzeUtil.getItemId("extravaluetype.float"); |
5228 |
03 Feb 10 |
nicklas |
121 |
int stringExtraId = TestAnalyzeUtil.getItemId("extravaluetype.string"); |
5228 |
03 Feb 10 |
nicklas |
122 |
|
5228 |
03 Feb 10 |
nicklas |
123 |
int extraSpotId = test_calculate_spotextravalues(filterBasId, "Spot extra values", |
5228 |
03 Feb 10 |
nicklas |
124 |
intExtraId, floatExtraId, stringExtraId); |
5228 |
03 Feb 10 |
nicklas |
125 |
int extraPosId = test_calculate_positionextravalues(filterBasId, "Position extra values", |
5228 |
03 Feb 10 |
nicklas |
126 |
intExtraId, floatExtraId, stringExtraId); |
5228 |
03 Feb 10 |
nicklas |
127 |
|
5228 |
03 Feb 10 |
nicklas |
128 |
test_list_bioassaysets(experimentId, 8); |
5228 |
03 Feb 10 |
nicklas |
129 |
test_list_bioassays(transformedBasId, 2); |
5228 |
03 Feb 10 |
nicklas |
130 |
|
5228 |
03 Feb 10 |
nicklas |
131 |
write_data_header(); |
5228 |
03 Feb 10 |
nicklas |
132 |
test_list_bioassayset_data(extraSpotId, 10, 2, intExtraId, floatExtraId, stringExtraId); |
5228 |
03 Feb 10 |
nicklas |
133 |
|
5228 |
03 Feb 10 |
nicklas |
134 |
write_extra_values_header(); |
5228 |
03 Feb 10 |
nicklas |
135 |
test_list_extra_values(extraSpotId, intExtraId, 10, 2); |
5228 |
03 Feb 10 |
nicklas |
136 |
|
5228 |
03 Feb 10 |
nicklas |
137 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
5230 |
04 Feb 10 |
nicklas |
138 |
TestAnalyzeUtil.test_delete_bioassayset(extraPosId); |
5228 |
03 Feb 10 |
nicklas |
139 |
test_delete_data_files(fileBasId); |
5228 |
03 Feb 10 |
nicklas |
140 |
} |
5228 |
03 Feb 10 |
nicklas |
141 |
finally |
5228 |
03 Feb 10 |
nicklas |
142 |
{ |
5228 |
03 Feb 10 |
nicklas |
143 |
if (wasSetup) TestAnalyzeUtil.cleanupExperiment(); |
5228 |
03 Feb 10 |
nicklas |
144 |
write("++Testing basic analysis "+(ok ? "OK" : "Failed")+"\n"); |
5228 |
03 Feb 10 |
nicklas |
145 |
} |
5228 |
03 Feb 10 |
nicklas |
146 |
return ok; |
5228 |
03 Feb 10 |
nicklas |
147 |
} |
5228 |
03 Feb 10 |
nicklas |
148 |
|
5228 |
03 Feb 10 |
nicklas |
149 |
|
5228 |
03 Feb 10 |
nicklas |
150 |
static void write_item(int i, RawBioAssay rba) |
5228 |
03 Feb 10 |
nicklas |
151 |
throws BaseException |
5228 |
03 Feb 10 |
nicklas |
152 |
{ |
5228 |
03 Feb 10 |
nicklas |
153 |
if (!TestUtil.getSilent()) |
5228 |
03 Feb 10 |
nicklas |
154 |
{ |
5228 |
03 Feb 10 |
nicklas |
155 |
System.out.println(i+":\t"+rba.getId()+"\t"+rba.getName()+"\t"+rba.getDescription()+ |
5228 |
03 Feb 10 |
nicklas |
156 |
"\t"+rba.getRawDataType().getName()+"\t"+rba.getNumDbSpots()+"\t"+rba.getBytes()+"\t"+rba.getArrayDesign()+ |
5228 |
03 Feb 10 |
nicklas |
157 |
"\t"+rba.getSoftware()+"\t"+rba.getProtocol()); |
5228 |
03 Feb 10 |
nicklas |
158 |
} |
5228 |
03 Feb 10 |
nicklas |
159 |
} |
5228 |
03 Feb 10 |
nicklas |
160 |
static void write_item(int i, BioAssay ba) |
5228 |
03 Feb 10 |
nicklas |
161 |
throws BaseException |
5228 |
03 Feb 10 |
nicklas |
162 |
{ |
5228 |
03 Feb 10 |
nicklas |
163 |
if (!TestUtil.getSilent()) |
5228 |
03 Feb 10 |
nicklas |
164 |
{ |
5228 |
03 Feb 10 |
nicklas |
165 |
System.out.println(i+":\t"+ba.getId()+"\t"+ba.getName()+"\t"+ba.getDescription()+ |
5228 |
03 Feb 10 |
nicklas |
166 |
"\t"+ba.getRawDataType().getName()+"\t"+ba.getNumSpots()); |
5228 |
03 Feb 10 |
nicklas |
167 |
} |
5228 |
03 Feb 10 |
nicklas |
168 |
} |
5228 |
03 Feb 10 |
nicklas |
169 |
static void write_item(int i, BioAssaySet bas) |
5228 |
03 Feb 10 |
nicklas |
170 |
throws BaseException |
5228 |
03 Feb 10 |
nicklas |
171 |
{ |
5228 |
03 Feb 10 |
nicklas |
172 |
if (!TestUtil.getSilent()) |
5228 |
03 Feb 10 |
nicklas |
173 |
{ |
5228 |
03 Feb 10 |
nicklas |
174 |
System.out.println(i+":\t"+bas.getId()+"\t"+bas.getName()+"\t"+bas.getDescription()+ |
5228 |
03 Feb 10 |
nicklas |
175 |
"\t"+bas.getTransformation()+"\t"+bas.getNumReporters()+"\t"+bas.getNumSpots() + |
5228 |
03 Feb 10 |
nicklas |
176 |
"\t" + bas.getNumFileReporters() + "\t" + bas.getNumFileSpots()); |
5228 |
03 Feb 10 |
nicklas |
177 |
} |
5228 |
03 Feb 10 |
nicklas |
178 |
} |
5228 |
03 Feb 10 |
nicklas |
179 |
static void write_item(int i, ExtraValue ev) |
5228 |
03 Feb 10 |
nicklas |
180 |
throws BaseException |
5228 |
03 Feb 10 |
nicklas |
181 |
{ |
5228 |
03 Feb 10 |
nicklas |
182 |
if (!TestUtil.getSilent()) |
5228 |
03 Feb 10 |
nicklas |
183 |
{ |
5228 |
03 Feb 10 |
nicklas |
184 |
System.out.println("\tExtra value: "+i+":\t"+ev.getId()+"\t"+ev.getValueType()+"\t"+ |
5228 |
03 Feb 10 |
nicklas |
185 |
ev.getCoordinateType()+"\t"+ev.getExtraValueType().getExternalId()+"\t"+ev.getNumValues()); |
5228 |
03 Feb 10 |
nicklas |
186 |
} |
5228 |
03 Feb 10 |
nicklas |
187 |
} |
5228 |
03 Feb 10 |
nicklas |
188 |
static void write_data_header() |
5228 |
03 Feb 10 |
nicklas |
189 |
{ |
5228 |
03 Feb 10 |
nicklas |
190 |
if (!TestUtil.getSilent()) |
5228 |
03 Feb 10 |
nicklas |
191 |
{ |
5228 |
03 Feb 10 |
nicklas |
192 |
write(" \tColumn\tPosition\tChannel 1\tChannel 2\tReporter\tX \tY \tExtra"); |
5228 |
03 Feb 10 |
nicklas |
193 |
write("-- \t------\t--------\t---------\t---------\t--------\t---\t---\t-----"); |
5228 |
03 Feb 10 |
nicklas |
194 |
} |
5228 |
03 Feb 10 |
nicklas |
195 |
} |
5228 |
03 Feb 10 |
nicklas |
196 |
static void write_extra_values_header() |
5228 |
03 Feb 10 |
nicklas |
197 |
{ |
5228 |
03 Feb 10 |
nicklas |
198 |
if (!TestUtil.getSilent()) |
5228 |
03 Feb 10 |
nicklas |
199 |
{ |
5228 |
03 Feb 10 |
nicklas |
200 |
write(" \tColumn\tPosition\tExtra"); |
5228 |
03 Feb 10 |
nicklas |
201 |
write("-- \t------\t--------\t-----"); |
5228 |
03 Feb 10 |
nicklas |
202 |
} |
5228 |
03 Feb 10 |
nicklas |
203 |
} |
5228 |
03 Feb 10 |
nicklas |
204 |
static void write_data(int i, short column, int position, float ch1, float ch2, |
5228 |
03 Feb 10 |
nicklas |
205 |
String reporter, float x, float y, List<Object> extra) |
5228 |
03 Feb 10 |
nicklas |
206 |
{ |
5228 |
03 Feb 10 |
nicklas |
207 |
if (!TestUtil.getSilent()) |
5228 |
03 Feb 10 |
nicklas |
208 |
{ |
5228 |
03 Feb 10 |
nicklas |
209 |
System.out.println(i+":\t"+column+"\t"+position+"\t"+ch1+"\t"+ch2+"\t"+reporter+ |
5228 |
03 Feb 10 |
nicklas |
210 |
"\t"+x+"\t"+y+"\t"+extra); |
5228 |
03 Feb 10 |
nicklas |
211 |
} |
5228 |
03 Feb 10 |
nicklas |
212 |
} |
5228 |
03 Feb 10 |
nicklas |
213 |
static void write_extra_value(int i, short column, int position, Object extra) |
5228 |
03 Feb 10 |
nicklas |
214 |
{ |
5228 |
03 Feb 10 |
nicklas |
215 |
if (!TestUtil.getSilent()) |
5228 |
03 Feb 10 |
nicklas |
216 |
{ |
5228 |
03 Feb 10 |
nicklas |
217 |
System.out.println(i+":\t"+column+"\t"+position+"\t"+extra); |
5228 |
03 Feb 10 |
nicklas |
218 |
} |
5228 |
03 Feb 10 |
nicklas |
219 |
} |
5228 |
03 Feb 10 |
nicklas |
220 |
|
5228 |
03 Feb 10 |
nicklas |
221 |
static void write(String message) |
5228 |
03 Feb 10 |
nicklas |
222 |
{ |
5228 |
03 Feb 10 |
nicklas |
223 |
System.out.println(message); |
5228 |
03 Feb 10 |
nicklas |
224 |
} |
5228 |
03 Feb 10 |
nicklas |
225 |
|
5228 |
03 Feb 10 |
nicklas |
226 |
|
5228 |
03 Feb 10 |
nicklas |
227 |
|
5228 |
03 Feb 10 |
nicklas |
228 |
|
5228 |
03 Feb 10 |
nicklas |
229 |
static int test_create_root_bioassayset_using_query(int experimentId, String intensityFormula, String name) |
5228 |
03 Feb 10 |
nicklas |
230 |
{ |
5228 |
03 Feb 10 |
nicklas |
231 |
if (experimentId == 0) return 0; |
5228 |
03 Feb 10 |
nicklas |
232 |
int id = 0; |
5228 |
03 Feb 10 |
nicklas |
233 |
DbControl dc = null; |
5228 |
03 Feb 10 |
nicklas |
234 |
long time; |
5228 |
03 Feb 10 |
nicklas |
235 |
try |
5228 |
03 Feb 10 |
nicklas |
236 |
{ |
5228 |
03 Feb 10 |
nicklas |
237 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
238 |
Experiment e = Experiment.getById(dc, experimentId); |
5228 |
03 Feb 10 |
nicklas |
239 |
|
5228 |
03 Feb 10 |
nicklas |
240 |
List<RawBioAssay> rbaCollection = e.getRawBioAssays().list(dc); |
5228 |
03 Feb 10 |
nicklas |
241 |
|
5228 |
03 Feb 10 |
nicklas |
242 |
RawDataType rdt = e.getRawDataType(); |
5228 |
03 Feb 10 |
nicklas |
243 |
String[] formulas = rdt.getIntensityFormula(intensityFormula).getExpressions(); |
5228 |
03 Feb 10 |
nicklas |
244 |
RawFunction raw = new RawFunction(dc, e.getRawDataType(), true); |
5228 |
03 Feb 10 |
nicklas |
245 |
Expression ch1 = Jep.formulaToExpression(formulas[0], raw); |
5228 |
03 Feb 10 |
nicklas |
246 |
Expression ch2 = Jep.formulaToExpression(formulas[1], raw); |
5228 |
03 Feb 10 |
nicklas |
247 |
|
5228 |
03 Feb 10 |
nicklas |
248 |
time = System.currentTimeMillis(); |
5228 |
03 Feb 10 |
nicklas |
249 |
BioAssaySet root = IntensityCalculatorUtil.createRootBioAssaySet( |
5228 |
03 Feb 10 |
nicklas |
250 |
dc, e, rbaCollection, null, new Expression[] { ch1, ch2 }, |
5228 |
03 Feb 10 |
nicklas |
251 |
TestUtil.getSilent() ? null : new ConsoleProgressReporter() ); |
5228 |
03 Feb 10 |
nicklas |
252 |
root.setName(name); |
5228 |
03 Feb 10 |
nicklas |
253 |
root.getTransformation().setName(name); |
5228 |
03 Feb 10 |
nicklas |
254 |
dc.commit(); |
5228 |
03 Feb 10 |
nicklas |
255 |
|
5228 |
03 Feb 10 |
nicklas |
256 |
time = System.currentTimeMillis()-time; |
5228 |
03 Feb 10 |
nicklas |
257 |
int numSpots = root.getNumSpots(); |
5228 |
03 Feb 10 |
nicklas |
258 |
id = root.getId(); |
5228 |
03 Feb 10 |
nicklas |
259 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
260 |
dc.reattachItem(root, false); |
5228 |
03 Feb 10 |
nicklas |
261 |
write_item(0, root); |
5228 |
03 Feb 10 |
nicklas |
262 |
write("--Create root bioassayset using query OK ("+numSpots+" spots inserted; "+time+" ms)"); |
5228 |
03 Feb 10 |
nicklas |
263 |
} |
5228 |
03 Feb 10 |
nicklas |
264 |
catch (Throwable ex) |
5228 |
03 Feb 10 |
nicklas |
265 |
{ |
5228 |
03 Feb 10 |
nicklas |
266 |
write("--Create root bioassayset using query FAILED"); |
5228 |
03 Feb 10 |
nicklas |
267 |
ex.printStackTrace(); |
5228 |
03 Feb 10 |
nicklas |
268 |
ok = false; |
5228 |
03 Feb 10 |
nicklas |
269 |
} |
5228 |
03 Feb 10 |
nicklas |
270 |
finally |
5228 |
03 Feb 10 |
nicklas |
271 |
{ |
5228 |
03 Feb 10 |
nicklas |
272 |
if (dc != null) dc.close(); |
5228 |
03 Feb 10 |
nicklas |
273 |
} |
5228 |
03 Feb 10 |
nicklas |
274 |
return id; |
5228 |
03 Feb 10 |
nicklas |
275 |
} |
5228 |
03 Feb 10 |
nicklas |
276 |
|
5228 |
03 Feb 10 |
nicklas |
277 |
static int test_create_empty_root_bioassayset(int experimentId, String name) |
5228 |
03 Feb 10 |
nicklas |
278 |
{ |
5228 |
03 Feb 10 |
nicklas |
279 |
if (experimentId == 0) return 0; |
5228 |
03 Feb 10 |
nicklas |
280 |
int id = 0; |
5228 |
03 Feb 10 |
nicklas |
281 |
DbControl dc = null; |
5228 |
03 Feb 10 |
nicklas |
282 |
try |
5228 |
03 Feb 10 |
nicklas |
283 |
{ |
5228 |
03 Feb 10 |
nicklas |
284 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
285 |
Experiment e = Experiment.getById(dc, experimentId); |
5228 |
03 Feb 10 |
nicklas |
286 |
|
5228 |
03 Feb 10 |
nicklas |
287 |
List<RawBioAssay> rbaCollection = e.getRawBioAssays().list(dc); |
5228 |
03 Feb 10 |
nicklas |
288 |
|
5228 |
03 Feb 10 |
nicklas |
289 |
Transformation t = e.newTransformation(null, rbaCollection); |
5228 |
03 Feb 10 |
nicklas |
290 |
t.setName(name); |
5228 |
03 Feb 10 |
nicklas |
291 |
BioAssaySet root = t.newProduct("new", "new", false); |
5228 |
03 Feb 10 |
nicklas |
292 |
root.setName(name); |
5228 |
03 Feb 10 |
nicklas |
293 |
dc.saveItem(t); |
5228 |
03 Feb 10 |
nicklas |
294 |
dc.saveItem(root); |
5228 |
03 Feb 10 |
nicklas |
295 |
|
5228 |
03 Feb 10 |
nicklas |
296 |
for (RawBioAssay rba : rbaCollection) |
5228 |
03 Feb 10 |
nicklas |
297 |
{ |
5228 |
03 Feb 10 |
nicklas |
// Create a new BioAssay for each raw bioassay |
5228 |
03 Feb 10 |
nicklas |
299 |
BioAssay ba = root.newRootBioAssay(Collections.singleton(rba)); |
5228 |
03 Feb 10 |
nicklas |
300 |
ba.setName(rba.getName()); |
5228 |
03 Feb 10 |
nicklas |
301 |
dc.saveItem(ba); |
5228 |
03 Feb 10 |
nicklas |
302 |
} |
5228 |
03 Feb 10 |
nicklas |
303 |
dc.commit(); |
5228 |
03 Feb 10 |
nicklas |
304 |
|
5228 |
03 Feb 10 |
nicklas |
305 |
int numSpots = root.getNumSpots(); |
5228 |
03 Feb 10 |
nicklas |
306 |
id = root.getId(); |
5228 |
03 Feb 10 |
nicklas |
307 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
308 |
dc.reattachItem(root, false); |
5228 |
03 Feb 10 |
nicklas |
309 |
write_item(0, root); |
5228 |
03 Feb 10 |
nicklas |
310 |
write("--Create empty root bioassayset OK ("+numSpots+" spots inserted)"); |
5228 |
03 Feb 10 |
nicklas |
311 |
} |
5228 |
03 Feb 10 |
nicklas |
312 |
catch (Throwable ex) |
5228 |
03 Feb 10 |
nicklas |
313 |
{ |
5228 |
03 Feb 10 |
nicklas |
314 |
write("--Create empty root bioassayset FAILED"); |
5228 |
03 Feb 10 |
nicklas |
315 |
ex.printStackTrace(); |
5228 |
03 Feb 10 |
nicklas |
316 |
ok = false; |
5228 |
03 Feb 10 |
nicklas |
317 |
} |
5228 |
03 Feb 10 |
nicklas |
318 |
finally |
5228 |
03 Feb 10 |
nicklas |
319 |
{ |
5228 |
03 Feb 10 |
nicklas |
320 |
if (dc != null) dc.close(); |
5228 |
03 Feb 10 |
nicklas |
321 |
} |
5228 |
03 Feb 10 |
nicklas |
322 |
return id; |
5228 |
03 Feb 10 |
nicklas |
323 |
} |
5228 |
03 Feb 10 |
nicklas |
324 |
|
5228 |
03 Feb 10 |
nicklas |
325 |
|
5228 |
03 Feb 10 |
nicklas |
326 |
static int test_create_file_bioassayset(int bioAssaySetId, String path, String name) |
5228 |
03 Feb 10 |
nicklas |
327 |
{ |
5228 |
03 Feb 10 |
nicklas |
328 |
if (bioAssaySetId == 0) return 0; |
5228 |
03 Feb 10 |
nicklas |
329 |
int id = 0; |
5228 |
03 Feb 10 |
nicklas |
330 |
DbControl dc = null; |
5228 |
03 Feb 10 |
nicklas |
331 |
try |
5228 |
03 Feb 10 |
nicklas |
332 |
{ |
5228 |
03 Feb 10 |
nicklas |
333 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
334 |
|
5228 |
03 Feb 10 |
nicklas |
335 |
BioAssaySet source = BioAssaySet.getById(dc, bioAssaySetId); |
5228 |
03 Feb 10 |
nicklas |
336 |
Transformation t = source.newTransformation(null); |
5228 |
03 Feb 10 |
nicklas |
337 |
t.setName(name); |
5228 |
03 Feb 10 |
nicklas |
338 |
dc.saveItem(t); |
5228 |
03 Feb 10 |
nicklas |
339 |
|
5228 |
03 Feb 10 |
nicklas |
340 |
BioAssaySet bas = t.newProduct(null, "new", false); |
5228 |
03 Feb 10 |
nicklas |
341 |
bas.setName(name); |
5228 |
03 Feb 10 |
nicklas |
342 |
dc.saveItem(bas); |
5228 |
03 Feb 10 |
nicklas |
343 |
|
5228 |
03 Feb 10 |
nicklas |
344 |
for (BioAssay parentBa : source.getBioAssays().list(dc)) |
5228 |
03 Feb 10 |
nicklas |
345 |
{ |
5228 |
03 Feb 10 |
nicklas |
346 |
BioAssay childBa = bas.newBioAssay(parentBa); |
5228 |
03 Feb 10 |
nicklas |
347 |
childBa.setNumFileSpots(parentBa.getNumSpots()); |
5228 |
03 Feb 10 |
nicklas |
348 |
dc.saveItem(childBa); |
5228 |
03 Feb 10 |
nicklas |
349 |
} |
5228 |
03 Feb 10 |
nicklas |
350 |
|
5228 |
03 Feb 10 |
nicklas |
351 |
File f = File.getByPath(dc, new Path(path, Path.Type.FILE), true); |
5228 |
03 Feb 10 |
nicklas |
352 |
f.setMimeType("text/plain"); |
5630 |
13 May 11 |
nicklas |
353 |
f.setItemSubtype(ItemSubtype.getById(dc, SystemItems.getId(File.SPOT_DATA))); |
5228 |
03 Feb 10 |
nicklas |
354 |
if (!f.isInDatabase()) dc.saveItem(f); |
5228 |
03 Feb 10 |
nicklas |
355 |
FileStoreUtil.setDataFile(dc, bas, DataFileType.GENERIC_SPOT_DATA, f); |
5228 |
03 Feb 10 |
nicklas |
356 |
bas.setNumFileSpots(source.getNumSpots()); |
5228 |
03 Feb 10 |
nicklas |
357 |
bas.setNumFileReporters(source.getNumReporters()); |
5228 |
03 Feb 10 |
nicklas |
358 |
|
5228 |
03 Feb 10 |
nicklas |
359 |
PrintWriter out = new PrintWriter(f.getUploadStream(false)); |
5228 |
03 Feb 10 |
nicklas |
360 |
int numChannels = bas.getRawDataType().getChannels(); |
5228 |
03 Feb 10 |
nicklas |
361 |
out.print("REPORTER\tASSAY\tPOSITION"); |
5228 |
03 Feb 10 |
nicklas |
362 |
for (int ch = 1; ch <= numChannels; ++ch) |
5228 |
03 Feb 10 |
nicklas |
363 |
{ |
5228 |
03 Feb 10 |
nicklas |
364 |
out.print("\tCH"); |
5228 |
03 Feb 10 |
nicklas |
365 |
out.print(ch); |
5228 |
03 Feb 10 |
nicklas |
366 |
} |
5228 |
03 Feb 10 |
nicklas |
367 |
out.print('\n'); |
5228 |
03 Feb 10 |
nicklas |
368 |
|
5228 |
03 Feb 10 |
nicklas |
369 |
DynamicSpotQuery query = source.getSpotData(); |
5228 |
03 Feb 10 |
nicklas |
370 |
query.select(Dynamic.selectReporter("externalId")); |
5228 |
03 Feb 10 |
nicklas |
371 |
query.select(Dynamic.select(VirtualColumn.COLUMN)); |
5228 |
03 Feb 10 |
nicklas |
372 |
query.select(Dynamic.select(VirtualColumn.POSITION)); |
5228 |
03 Feb 10 |
nicklas |
373 |
for (int ch = 1; ch <= numChannels; ++ch) |
5228 |
03 Feb 10 |
nicklas |
374 |
{ |
5228 |
03 Feb 10 |
nicklas |
375 |
query.select(Dynamic.select(VirtualColumn.channelRaw(ch))); |
5228 |
03 Feb 10 |
nicklas |
376 |
} |
5228 |
03 Feb 10 |
nicklas |
377 |
DynamicResultIterator it = query.iterate(dc); |
5228 |
03 Feb 10 |
nicklas |
378 |
|
5228 |
03 Feb 10 |
nicklas |
379 |
while (it.hasNext()) |
5228 |
03 Feb 10 |
nicklas |
380 |
{ |
5228 |
03 Feb 10 |
nicklas |
381 |
SqlResult result = it.next(); |
5228 |
03 Feb 10 |
nicklas |
382 |
out.print(result.getString(1)); // Reporter |
5228 |
03 Feb 10 |
nicklas |
383 |
out.print('\t'); |
5228 |
03 Feb 10 |
nicklas |
384 |
out.print(result.getInt(2)); // Assay |
5228 |
03 Feb 10 |
nicklas |
385 |
out.print('\t'); |
5228 |
03 Feb 10 |
nicklas |
386 |
out.print(result.getInt(3)); // Position |
5228 |
03 Feb 10 |
nicklas |
387 |
|
5228 |
03 Feb 10 |
nicklas |
388 |
for (int ch = 1; ch <= numChannels; ++ch) |
5228 |
03 Feb 10 |
nicklas |
389 |
{ |
5228 |
03 Feb 10 |
nicklas |
390 |
out.print('\t'); |
5228 |
03 Feb 10 |
nicklas |
391 |
out.print(result.getFloat(3+ch)); |
5228 |
03 Feb 10 |
nicklas |
392 |
} |
5228 |
03 Feb 10 |
nicklas |
393 |
out.print('\n'); |
5228 |
03 Feb 10 |
nicklas |
394 |
} |
5228 |
03 Feb 10 |
nicklas |
395 |
out.flush(); |
5228 |
03 Feb 10 |
nicklas |
396 |
out.close(); |
5228 |
03 Feb 10 |
nicklas |
397 |
|
5228 |
03 Feb 10 |
nicklas |
398 |
dc.commit(); |
5228 |
03 Feb 10 |
nicklas |
399 |
id = bas.getId(); |
5228 |
03 Feb 10 |
nicklas |
400 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
401 |
dc.reattachItem(bas, false); |
5228 |
03 Feb 10 |
nicklas |
402 |
write_item(0, bas); |
5228 |
03 Feb 10 |
nicklas |
403 |
write("--Create file bioassayset OK ("+bas.getNumFileSpots()+" spots inserted)"); |
5228 |
03 Feb 10 |
nicklas |
404 |
} |
5228 |
03 Feb 10 |
nicklas |
405 |
catch (Throwable ex) |
5228 |
03 Feb 10 |
nicklas |
406 |
{ |
5228 |
03 Feb 10 |
nicklas |
407 |
write("--Create file bioassayset FAILED"); |
5228 |
03 Feb 10 |
nicklas |
408 |
ex.printStackTrace(); |
5228 |
03 Feb 10 |
nicklas |
409 |
ok = false; |
5228 |
03 Feb 10 |
nicklas |
410 |
} |
5228 |
03 Feb 10 |
nicklas |
411 |
finally |
5228 |
03 Feb 10 |
nicklas |
412 |
{ |
5228 |
03 Feb 10 |
nicklas |
413 |
if (dc != null) dc.close(); |
5228 |
03 Feb 10 |
nicklas |
414 |
} |
5228 |
03 Feb 10 |
nicklas |
415 |
return id; |
5228 |
03 Feb 10 |
nicklas |
416 |
} |
5228 |
03 Feb 10 |
nicklas |
417 |
|
5228 |
03 Feb 10 |
nicklas |
418 |
|
5228 |
03 Feb 10 |
nicklas |
419 |
static int test_transform_bioassayset(int bioAssaySetId, String name, float factor) |
5228 |
03 Feb 10 |
nicklas |
420 |
{ |
5228 |
03 Feb 10 |
nicklas |
421 |
if (bioAssaySetId == 0) return 0; |
5228 |
03 Feb 10 |
nicklas |
422 |
int id = 0; |
5228 |
03 Feb 10 |
nicklas |
423 |
DbControl dc = null; |
5228 |
03 Feb 10 |
nicklas |
424 |
try |
5228 |
03 Feb 10 |
nicklas |
425 |
{ |
5228 |
03 Feb 10 |
nicklas |
426 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
427 |
BioAssaySet source = BioAssaySet.getById(dc, bioAssaySetId); |
5228 |
03 Feb 10 |
nicklas |
428 |
|
5228 |
03 Feb 10 |
nicklas |
429 |
Transformation t = source.newTransformation(null); |
5228 |
03 Feb 10 |
nicklas |
430 |
t.setName(name); |
5228 |
03 Feb 10 |
nicklas |
431 |
dc.saveItem(t); |
5228 |
03 Feb 10 |
nicklas |
432 |
|
5228 |
03 Feb 10 |
nicklas |
433 |
BioAssaySet bas = t.newProduct(null, "new", true); |
5228 |
03 Feb 10 |
nicklas |
434 |
bas.setName(name); |
5228 |
03 Feb 10 |
nicklas |
435 |
bas.setIntensityTransform(source.getIntensityTransform()); |
5228 |
03 Feb 10 |
nicklas |
436 |
dc.saveItem(bas); |
5228 |
03 Feb 10 |
nicklas |
437 |
|
5228 |
03 Feb 10 |
nicklas |
438 |
int numSpots = 0; |
5228 |
03 Feb 10 |
nicklas |
439 |
SpotBatcher spotBatcher = bas.getSpotBatcher(); |
5228 |
03 Feb 10 |
nicklas |
440 |
|
5228 |
03 Feb 10 |
nicklas |
441 |
DynamicSpotQuery query = source.getSpotData(); |
5228 |
03 Feb 10 |
nicklas |
442 |
query.select(Dynamic.select(VirtualColumn.COLUMN)); |
5228 |
03 Feb 10 |
nicklas |
443 |
query.select(Dynamic.select(VirtualColumn.POSITION)); |
5228 |
03 Feb 10 |
nicklas |
444 |
query.select( |
5228 |
03 Feb 10 |
nicklas |
445 |
Selects.expression( |
5228 |
03 Feb 10 |
nicklas |
446 |
Expressions.multiply( |
5228 |
03 Feb 10 |
nicklas |
447 |
Dynamic.column(VirtualColumn.channelRaw(1)), |
5228 |
03 Feb 10 |
nicklas |
448 |
Expressions.aFloat(factor) |
5228 |
03 Feb 10 |
nicklas |
449 |
), |
5228 |
03 Feb 10 |
nicklas |
450 |
"ch1" |
5228 |
03 Feb 10 |
nicklas |
451 |
) |
5228 |
03 Feb 10 |
nicklas |
452 |
); |
5228 |
03 Feb 10 |
nicklas |
453 |
query.select( |
5228 |
03 Feb 10 |
nicklas |
454 |
Selects.expression( |
5228 |
03 Feb 10 |
nicklas |
455 |
Expressions.divide( |
5228 |
03 Feb 10 |
nicklas |
456 |
Dynamic.column(VirtualColumn.channelRaw(2)), |
5228 |
03 Feb 10 |
nicklas |
457 |
Expressions.aFloat(factor) |
5228 |
03 Feb 10 |
nicklas |
458 |
), |
5228 |
03 Feb 10 |
nicklas |
459 |
"ch2" |
5228 |
03 Feb 10 |
nicklas |
460 |
) |
5228 |
03 Feb 10 |
nicklas |
461 |
); |
5228 |
03 Feb 10 |
nicklas |
462 |
spotBatcher.insert(query); |
5228 |
03 Feb 10 |
nicklas |
463 |
spotBatcher.close(); |
5228 |
03 Feb 10 |
nicklas |
464 |
|
5228 |
03 Feb 10 |
nicklas |
465 |
dc.commit(); |
5228 |
03 Feb 10 |
nicklas |
466 |
id = bas.getId(); |
5228 |
03 Feb 10 |
nicklas |
467 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
468 |
dc.reattachItem(bas, false); |
5228 |
03 Feb 10 |
nicklas |
469 |
write_item(0, bas); |
5228 |
03 Feb 10 |
nicklas |
470 |
write("--Create bioassayset OK ("+numSpots+" spots inserted)"); |
5228 |
03 Feb 10 |
nicklas |
471 |
} |
5228 |
03 Feb 10 |
nicklas |
472 |
catch (Throwable ex) |
5228 |
03 Feb 10 |
nicklas |
473 |
{ |
5228 |
03 Feb 10 |
nicklas |
474 |
write("--Create bioassayset FAILED"); |
5228 |
03 Feb 10 |
nicklas |
475 |
ex.printStackTrace(); |
5228 |
03 Feb 10 |
nicklas |
476 |
ok = false; |
5228 |
03 Feb 10 |
nicklas |
477 |
} |
5228 |
03 Feb 10 |
nicklas |
478 |
finally |
5228 |
03 Feb 10 |
nicklas |
479 |
{ |
5228 |
03 Feb 10 |
nicklas |
480 |
if (dc != null) dc.close(); |
5228 |
03 Feb 10 |
nicklas |
481 |
} |
5228 |
03 Feb 10 |
nicklas |
482 |
return id; |
5228 |
03 Feb 10 |
nicklas |
483 |
} |
5228 |
03 Feb 10 |
nicklas |
484 |
|
5228 |
03 Feb 10 |
nicklas |
485 |
static int test_filter_bioassayset(int bioAssaySetId, String name, float factor) |
5228 |
03 Feb 10 |
nicklas |
486 |
{ |
5228 |
03 Feb 10 |
nicklas |
487 |
if (bioAssaySetId == 0) return 0; |
5228 |
03 Feb 10 |
nicklas |
488 |
int id = 0; |
5228 |
03 Feb 10 |
nicklas |
489 |
DbControl dc = null; |
5228 |
03 Feb 10 |
nicklas |
490 |
try |
5228 |
03 Feb 10 |
nicklas |
491 |
{ |
5228 |
03 Feb 10 |
nicklas |
492 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
493 |
BioAssaySet source = BioAssaySet.getById(dc, bioAssaySetId); |
5228 |
03 Feb 10 |
nicklas |
494 |
|
5228 |
03 Feb 10 |
nicklas |
495 |
Transformation t = source.newTransformation(null); |
5228 |
03 Feb 10 |
nicklas |
496 |
t.setName(name); |
5228 |
03 Feb 10 |
nicklas |
497 |
dc.saveItem(t); |
5228 |
03 Feb 10 |
nicklas |
498 |
|
5228 |
03 Feb 10 |
nicklas |
499 |
BioAssaySet bas = t.newProduct(null, null, true); |
5228 |
03 Feb 10 |
nicklas |
500 |
bas.setName(name); |
5228 |
03 Feb 10 |
nicklas |
501 |
bas.setIntensityTransform(source.getIntensityTransform()); |
5228 |
03 Feb 10 |
nicklas |
502 |
dc.saveItem(bas); |
5228 |
03 Feb 10 |
nicklas |
503 |
|
5228 |
03 Feb 10 |
nicklas |
504 |
DynamicSpotQuery query = source.getSpotData(); |
5228 |
03 Feb 10 |
nicklas |
505 |
query.select(Dynamic.select(VirtualColumn.COLUMN)); |
5228 |
03 Feb 10 |
nicklas |
506 |
query.select(Dynamic.select(VirtualColumn.POSITION)); |
5228 |
03 Feb 10 |
nicklas |
507 |
query.restrict( |
5228 |
03 Feb 10 |
nicklas |
508 |
Restrictions.gt( |
5228 |
03 Feb 10 |
nicklas |
509 |
Dynamic.column(VirtualColumn.channelRaw(1)), |
5228 |
03 Feb 10 |
nicklas |
510 |
Expressions.multiply( |
5228 |
03 Feb 10 |
nicklas |
511 |
Expressions.parameter("factor"), |
5228 |
03 Feb 10 |
nicklas |
512 |
Dynamic.column(VirtualColumn.channelRaw(2)) |
5228 |
03 Feb 10 |
nicklas |
513 |
) |
5228 |
03 Feb 10 |
nicklas |
514 |
) |
5228 |
03 Feb 10 |
nicklas |
515 |
); |
5228 |
03 Feb 10 |
nicklas |
516 |
query.setParameter("factor", factor, Type.FLOAT); |
5228 |
03 Feb 10 |
nicklas |
517 |
|
5228 |
03 Feb 10 |
nicklas |
518 |
FilterBatcher filterBatcher = bas.getFilterBatcher(); |
5228 |
03 Feb 10 |
nicklas |
519 |
DynamicResultIterator spots = query.iterate(dc); |
5228 |
03 Feb 10 |
nicklas |
520 |
int column = spots.getIndex(VirtualColumn.COLUMN.getName()); |
5228 |
03 Feb 10 |
nicklas |
521 |
int position = spots.getIndex(VirtualColumn.POSITION.getName()); |
5228 |
03 Feb 10 |
nicklas |
522 |
int numSpots = 0; |
5228 |
03 Feb 10 |
nicklas |
523 |
while (spots.hasNext()) |
5228 |
03 Feb 10 |
nicklas |
524 |
{ |
5228 |
03 Feb 10 |
nicklas |
525 |
SqlResult r = spots.next(); |
5228 |
03 Feb 10 |
nicklas |
526 |
filterBatcher.insert(r.getShort(column), r.getInt(position)); |
5228 |
03 Feb 10 |
nicklas |
527 |
numSpots++; |
5228 |
03 Feb 10 |
nicklas |
528 |
} |
5228 |
03 Feb 10 |
nicklas |
529 |
filterBatcher.close(); |
5228 |
03 Feb 10 |
nicklas |
530 |
|
5228 |
03 Feb 10 |
nicklas |
531 |
dc.commit(); |
5228 |
03 Feb 10 |
nicklas |
532 |
id = bas.getId(); |
5228 |
03 Feb 10 |
nicklas |
533 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
534 |
dc.reattachItem(bas, false); |
5228 |
03 Feb 10 |
nicklas |
535 |
write_item(0, bas); |
5228 |
03 Feb 10 |
nicklas |
536 |
write("--Create filtered bioassayset OK ("+numSpots+" spots inserted)"); |
5228 |
03 Feb 10 |
nicklas |
537 |
} |
5228 |
03 Feb 10 |
nicklas |
538 |
catch (Throwable ex) |
5228 |
03 Feb 10 |
nicklas |
539 |
{ |
5228 |
03 Feb 10 |
nicklas |
540 |
write("--Create filtered bioassayset FAILED"); |
5228 |
03 Feb 10 |
nicklas |
541 |
ex.printStackTrace(); |
5228 |
03 Feb 10 |
nicklas |
542 |
ok = false; |
5228 |
03 Feb 10 |
nicklas |
543 |
} |
5228 |
03 Feb 10 |
nicklas |
544 |
finally |
5228 |
03 Feb 10 |
nicklas |
545 |
{ |
5228 |
03 Feb 10 |
nicklas |
546 |
if (dc != null) dc.close(); |
5228 |
03 Feb 10 |
nicklas |
547 |
} |
5228 |
03 Feb 10 |
nicklas |
548 |
return id; |
5228 |
03 Feb 10 |
nicklas |
549 |
} |
5228 |
03 Feb 10 |
nicklas |
550 |
|
5228 |
03 Feb 10 |
nicklas |
551 |
static int test_calculate_spotextravalues(int bioAssaySetId, String childName, |
5228 |
03 Feb 10 |
nicklas |
552 |
int intExtraId, int floatExtraId, int stringExtraId) |
5228 |
03 Feb 10 |
nicklas |
553 |
{ |
5228 |
03 Feb 10 |
nicklas |
554 |
if (bioAssaySetId == 0) return 0; |
5228 |
03 Feb 10 |
nicklas |
555 |
int id = 0; |
5228 |
03 Feb 10 |
nicklas |
556 |
DbControl dc = null; |
5228 |
03 Feb 10 |
nicklas |
557 |
try |
5228 |
03 Feb 10 |
nicklas |
558 |
{ |
5228 |
03 Feb 10 |
nicklas |
559 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
560 |
BioAssaySet source = BioAssaySet.getById(dc, bioAssaySetId); |
5228 |
03 Feb 10 |
nicklas |
561 |
|
5228 |
03 Feb 10 |
nicklas |
562 |
Transformation t = source.newTransformation(null); |
5228 |
03 Feb 10 |
nicklas |
563 |
dc.saveItem(t); |
5228 |
03 Feb 10 |
nicklas |
564 |
|
5228 |
03 Feb 10 |
nicklas |
565 |
BioAssaySet addTo = source; |
5228 |
03 Feb 10 |
nicklas |
566 |
if (childName != null) |
5228 |
03 Feb 10 |
nicklas |
567 |
{ |
5228 |
03 Feb 10 |
nicklas |
568 |
t.setName(childName); |
5228 |
03 Feb 10 |
nicklas |
569 |
BioAssaySet child = t.newProduct(null, null, true); |
5228 |
03 Feb 10 |
nicklas |
570 |
child.setName(childName); |
5228 |
03 Feb 10 |
nicklas |
571 |
dc.saveItem(child); |
5228 |
03 Feb 10 |
nicklas |
572 |
addTo = child; |
5228 |
03 Feb 10 |
nicklas |
573 |
} |
5228 |
03 Feb 10 |
nicklas |
574 |
|
5228 |
03 Feb 10 |
nicklas |
575 |
SpotExtraValueBatcher<Integer> intBatcher = null; |
5228 |
03 Feb 10 |
nicklas |
576 |
if (intExtraId != 0) |
5228 |
03 Feb 10 |
nicklas |
577 |
{ |
5228 |
03 Feb 10 |
nicklas |
578 |
ExtraValueType intExtraValue = ExtraValueType.getById(dc, intExtraId); |
5228 |
03 Feb 10 |
nicklas |
579 |
intBatcher = addTo.getSpotExtraValueBatcher(Integer.class, intExtraValue, null); |
5228 |
03 Feb 10 |
nicklas |
580 |
} |
5228 |
03 Feb 10 |
nicklas |
581 |
SpotExtraValueBatcher<Float> floatBatcher = null; |
5228 |
03 Feb 10 |
nicklas |
582 |
if (floatExtraId != 0) |
5228 |
03 Feb 10 |
nicklas |
583 |
{ |
5228 |
03 Feb 10 |
nicklas |
584 |
ExtraValueType floatExtraValue = ExtraValueType.getById(dc, floatExtraId); |
5228 |
03 Feb 10 |
nicklas |
585 |
floatBatcher = addTo.getSpotExtraValueBatcher(Float.class, floatExtraValue, null); |
5228 |
03 Feb 10 |
nicklas |
586 |
} |
5228 |
03 Feb 10 |
nicklas |
587 |
SpotExtraValueBatcher<String> stringBatcher = null; |
5228 |
03 Feb 10 |
nicklas |
588 |
if (stringExtraId != 0) |
5228 |
03 Feb 10 |
nicklas |
589 |
{ |
5228 |
03 Feb 10 |
nicklas |
590 |
ExtraValueType stringExtraValue = ExtraValueType.getById(dc, stringExtraId); |
5228 |
03 Feb 10 |
nicklas |
591 |
stringBatcher = addTo.getSpotExtraValueBatcher(String.class, stringExtraValue, null); |
5228 |
03 Feb 10 |
nicklas |
592 |
} |
5228 |
03 Feb 10 |
nicklas |
593 |
|
5228 |
03 Feb 10 |
nicklas |
594 |
DynamicSpotQuery query = source.getSpotData(); |
5228 |
03 Feb 10 |
nicklas |
595 |
DynamicResultIterator spots = query.iterate(dc); |
5228 |
03 Feb 10 |
nicklas |
596 |
int column = spots.getIndex(VirtualColumn.COLUMN.getName()); |
5228 |
03 Feb 10 |
nicklas |
597 |
int position = spots.getIndex(VirtualColumn.POSITION.getName()); |
5228 |
03 Feb 10 |
nicklas |
598 |
int ch1 = spots.getIndex(VirtualColumn.channelIntensity(1).getName()); |
5228 |
03 Feb 10 |
nicklas |
599 |
int ch2 = spots.getIndex(VirtualColumn.channelIntensity(2).getName()); |
5228 |
03 Feb 10 |
nicklas |
600 |
int numSpots = 0; |
5228 |
03 Feb 10 |
nicklas |
601 |
while (spots.hasNext()) |
5228 |
03 Feb 10 |
nicklas |
602 |
{ |
5228 |
03 Feb 10 |
nicklas |
603 |
numSpots++; |
5228 |
03 Feb 10 |
nicklas |
604 |
SqlResult r = spots.next(); |
5228 |
03 Feb 10 |
nicklas |
605 |
|
5228 |
03 Feb 10 |
nicklas |
606 |
if (numSpots == 1) |
5228 |
03 Feb 10 |
nicklas |
607 |
{ |
5228 |
03 Feb 10 |
nicklas |
// Test NULL and Float.NaN |
5228 |
03 Feb 10 |
nicklas |
609 |
if (intBatcher != null) intBatcher.insert(r.getShort(column), r.getInt(position), null); |
5228 |
03 Feb 10 |
nicklas |
610 |
if (floatBatcher != null) floatBatcher.insert(r.getShort(column), r.getInt(position), Float.NaN); |
5228 |
03 Feb 10 |
nicklas |
611 |
if (stringBatcher != null) stringBatcher.insert(r.getShort(column), r.getInt(position), null); |
5228 |
03 Feb 10 |
nicklas |
612 |
} |
5228 |
03 Feb 10 |
nicklas |
613 |
else |
5228 |
03 Feb 10 |
nicklas |
614 |
{ |
5228 |
03 Feb 10 |
nicklas |
615 |
if (intBatcher != null) intBatcher.insert(r.getShort(column), r.getInt(position), numSpots); |
5228 |
03 Feb 10 |
nicklas |
616 |
if (floatBatcher != null) floatBatcher.insert(r.getShort(column), r.getInt(position), r.getFloat(ch1) * r.getFloat(ch2)); |
5228 |
03 Feb 10 |
nicklas |
617 |
if (stringBatcher != null) stringBatcher.insert(r.getShort(column), r.getInt(position), "Spot number " + numSpots); |
5228 |
03 Feb 10 |
nicklas |
618 |
} |
5228 |
03 Feb 10 |
nicklas |
619 |
} |
5228 |
03 Feb 10 |
nicklas |
620 |
|
5228 |
03 Feb 10 |
nicklas |
621 |
if (intBatcher != null) intBatcher.close(); |
5228 |
03 Feb 10 |
nicklas |
622 |
if (floatBatcher != null) floatBatcher.close(); |
5228 |
03 Feb 10 |
nicklas |
623 |
if (stringBatcher != null) stringBatcher.close(); |
5228 |
03 Feb 10 |
nicklas |
624 |
|
5228 |
03 Feb 10 |
nicklas |
625 |
dc.commit(); |
5228 |
03 Feb 10 |
nicklas |
626 |
id = addTo.getId(); |
5228 |
03 Feb 10 |
nicklas |
627 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
628 |
dc.reattachItem(addTo, false); |
5228 |
03 Feb 10 |
nicklas |
629 |
write_item(0, addTo); |
5228 |
03 Feb 10 |
nicklas |
630 |
write("--Calculate spot extra values OK ("+numSpots+" values inserted)"); |
5228 |
03 Feb 10 |
nicklas |
631 |
|
5228 |
03 Feb 10 |
nicklas |
632 |
} |
5228 |
03 Feb 10 |
nicklas |
633 |
catch (Throwable ex) |
5228 |
03 Feb 10 |
nicklas |
634 |
{ |
5228 |
03 Feb 10 |
nicklas |
635 |
write("--Calculate spot extra values FAILED"); |
5228 |
03 Feb 10 |
nicklas |
636 |
ex.printStackTrace(); |
5228 |
03 Feb 10 |
nicklas |
637 |
ok = false; |
5228 |
03 Feb 10 |
nicklas |
638 |
} |
5228 |
03 Feb 10 |
nicklas |
639 |
finally |
5228 |
03 Feb 10 |
nicklas |
640 |
{ |
5228 |
03 Feb 10 |
nicklas |
641 |
if (dc != null) dc.close(); |
5228 |
03 Feb 10 |
nicklas |
642 |
} |
5228 |
03 Feb 10 |
nicklas |
643 |
return id; |
5228 |
03 Feb 10 |
nicklas |
644 |
} |
5228 |
03 Feb 10 |
nicklas |
645 |
|
5228 |
03 Feb 10 |
nicklas |
646 |
static int test_calculate_positionextravalues(int bioAssaySetId, String childName, int intExtraId, int floatExtraId, int stringExtraId) |
5228 |
03 Feb 10 |
nicklas |
647 |
{ |
5228 |
03 Feb 10 |
nicklas |
648 |
if (bioAssaySetId == 0) return 0; |
5228 |
03 Feb 10 |
nicklas |
649 |
int id = 0; |
5228 |
03 Feb 10 |
nicklas |
650 |
DbControl dc = null; |
5228 |
03 Feb 10 |
nicklas |
651 |
try |
5228 |
03 Feb 10 |
nicklas |
652 |
{ |
5228 |
03 Feb 10 |
nicklas |
653 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
654 |
BioAssaySet source = BioAssaySet.getById(dc, bioAssaySetId); |
5228 |
03 Feb 10 |
nicklas |
655 |
|
5228 |
03 Feb 10 |
nicklas |
656 |
Transformation t = source.newTransformation(null); |
5228 |
03 Feb 10 |
nicklas |
657 |
t.setName(childName); |
5228 |
03 Feb 10 |
nicklas |
658 |
dc.saveItem(t); |
5228 |
03 Feb 10 |
nicklas |
659 |
|
5228 |
03 Feb 10 |
nicklas |
660 |
BioAssaySet bas = t.newProduct(null, null, true); |
5228 |
03 Feb 10 |
nicklas |
661 |
bas.setName(childName); |
5228 |
03 Feb 10 |
nicklas |
662 |
IntensityTransform transform = source.getIntensityTransform(); |
5228 |
03 Feb 10 |
nicklas |
663 |
bas.setIntensityTransform(transform); |
5228 |
03 Feb 10 |
nicklas |
664 |
dc.saveItem(bas); |
5228 |
03 Feb 10 |
nicklas |
665 |
|
5228 |
03 Feb 10 |
nicklas |
666 |
PositionExtraValueBatcher<Integer> intBatcher = null; |
5228 |
03 Feb 10 |
nicklas |
667 |
if (intExtraId != 0) |
5228 |
03 Feb 10 |
nicklas |
668 |
{ |
5228 |
03 Feb 10 |
nicklas |
669 |
ExtraValueType intExtraValue = ExtraValueType.getById(dc, intExtraId); |
5228 |
03 Feb 10 |
nicklas |
670 |
intBatcher = bas.getPositionExtraValueBatcher(Integer.class, intExtraValue, null); |
5228 |
03 Feb 10 |
nicklas |
671 |
} |
5228 |
03 Feb 10 |
nicklas |
672 |
PositionExtraValueBatcher<Float> floatBatcher = null; |
5228 |
03 Feb 10 |
nicklas |
673 |
if (floatExtraId != 0) |
5228 |
03 Feb 10 |
nicklas |
674 |
{ |
5228 |
03 Feb 10 |
nicklas |
675 |
ExtraValueType floatExtraValue = ExtraValueType.getById(dc, floatExtraId); |
5228 |
03 Feb 10 |
nicklas |
676 |
floatBatcher = bas.getPositionExtraValueBatcher(Float.class, floatExtraValue, null); |
5228 |
03 Feb 10 |
nicklas |
677 |
} |
5228 |
03 Feb 10 |
nicklas |
678 |
PositionExtraValueBatcher<String> stringBatcher = null; |
5228 |
03 Feb 10 |
nicklas |
679 |
if (stringExtraId != 0) |
5228 |
03 Feb 10 |
nicklas |
680 |
{ |
5228 |
03 Feb 10 |
nicklas |
681 |
ExtraValueType stringExtraValue = ExtraValueType.getById(dc, stringExtraId); |
5228 |
03 Feb 10 |
nicklas |
682 |
stringBatcher = bas.getPositionExtraValueBatcher(String.class, stringExtraValue, null); |
5228 |
03 Feb 10 |
nicklas |
683 |
} |
5228 |
03 Feb 10 |
nicklas |
684 |
|
5228 |
03 Feb 10 |
nicklas |
685 |
Formula.AverageMethod avgMethod = transform.getAverageMethod(); |
5228 |
03 Feb 10 |
nicklas |
686 |
Expression avgCh1 = avgMethod.getAverageExpression(Dynamic.column(VirtualColumn.channelRaw(1))); |
5228 |
03 Feb 10 |
nicklas |
687 |
Expression avgCh2 = avgMethod.getAverageExpression(Dynamic.column(VirtualColumn.channelRaw(2))); |
5228 |
03 Feb 10 |
nicklas |
688 |
Expression product = Expressions.multiply(avgCh1, avgCh2); |
5228 |
03 Feb 10 |
nicklas |
689 |
DynamicSpotQuery query = source.getSpotData(); |
5228 |
03 Feb 10 |
nicklas |
690 |
query.select(Dynamic.select(VirtualColumn.POSITION)); |
5228 |
03 Feb 10 |
nicklas |
691 |
query.select(Selects.expression(product, "product")); |
5228 |
03 Feb 10 |
nicklas |
692 |
query.select(Selects.expression(Expressions.string("static"), "static")); |
5228 |
03 Feb 10 |
nicklas |
693 |
query.group(Dynamic.column(VirtualColumn.POSITION)); |
5228 |
03 Feb 10 |
nicklas |
694 |
|
5228 |
03 Feb 10 |
nicklas |
695 |
DynamicResultIterator spots = query.iterate(dc); |
5228 |
03 Feb 10 |
nicklas |
696 |
int position = spots.getIndex(VirtualColumn.POSITION.getName()); |
5228 |
03 Feb 10 |
nicklas |
697 |
int prod = spots.getIndex("product"); |
5228 |
03 Feb 10 |
nicklas |
698 |
int stat = spots.getIndex("static"); |
5228 |
03 Feb 10 |
nicklas |
699 |
int numSpots = 0; |
5228 |
03 Feb 10 |
nicklas |
700 |
while (spots.hasNext()) |
5228 |
03 Feb 10 |
nicklas |
701 |
{ |
5228 |
03 Feb 10 |
nicklas |
702 |
numSpots++; |
5228 |
03 Feb 10 |
nicklas |
703 |
SqlResult r = spots.next(); |
5228 |
03 Feb 10 |
nicklas |
704 |
if (numSpots == 1) |
5228 |
03 Feb 10 |
nicklas |
705 |
{ |
5228 |
03 Feb 10 |
nicklas |
706 |
if (intBatcher != null) intBatcher.insert(r.getInt(position), null); |
5228 |
03 Feb 10 |
nicklas |
707 |
if (floatBatcher != null) floatBatcher.insert(r.getInt(position), Float.NaN); |
5228 |
03 Feb 10 |
nicklas |
708 |
if (stringBatcher != null) stringBatcher.insert(r.getInt(position), null); |
5228 |
03 Feb 10 |
nicklas |
709 |
} |
5228 |
03 Feb 10 |
nicklas |
710 |
else |
5228 |
03 Feb 10 |
nicklas |
711 |
{ |
5228 |
03 Feb 10 |
nicklas |
712 |
if (intBatcher != null) intBatcher.insert(r.getInt(position), numSpots); |
5228 |
03 Feb 10 |
nicklas |
713 |
if (floatBatcher != null) floatBatcher.insert(r.getInt(position), r.getFloat(prod)); |
5228 |
03 Feb 10 |
nicklas |
714 |
if (stringBatcher != null) stringBatcher.insert(r.getInt(position), r.getString(stat)); |
5228 |
03 Feb 10 |
nicklas |
715 |
} |
5228 |
03 Feb 10 |
nicklas |
716 |
} |
5228 |
03 Feb 10 |
nicklas |
717 |
|
5228 |
03 Feb 10 |
nicklas |
718 |
if (intBatcher != null) intBatcher.close(); |
5228 |
03 Feb 10 |
nicklas |
719 |
if (floatBatcher != null) floatBatcher.close(); |
5228 |
03 Feb 10 |
nicklas |
720 |
if (stringBatcher != null) stringBatcher.close(); |
5228 |
03 Feb 10 |
nicklas |
721 |
|
5228 |
03 Feb 10 |
nicklas |
722 |
dc.commit(); |
5228 |
03 Feb 10 |
nicklas |
723 |
id = bas.getId(); |
5228 |
03 Feb 10 |
nicklas |
724 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
725 |
dc.reattachItem(bas, false); |
5228 |
03 Feb 10 |
nicklas |
726 |
write_item(0, bas); |
5228 |
03 Feb 10 |
nicklas |
727 |
write("--Calculate position extra values OK ("+numSpots+" values inserted)"); |
5228 |
03 Feb 10 |
nicklas |
728 |
|
5228 |
03 Feb 10 |
nicklas |
729 |
} |
5228 |
03 Feb 10 |
nicklas |
730 |
catch (Throwable ex) |
5228 |
03 Feb 10 |
nicklas |
731 |
{ |
5228 |
03 Feb 10 |
nicklas |
732 |
write("--Calculate position extra values FAILED"); |
5228 |
03 Feb 10 |
nicklas |
733 |
ex.printStackTrace(); |
5228 |
03 Feb 10 |
nicklas |
734 |
ok = false; |
5228 |
03 Feb 10 |
nicklas |
735 |
} |
5228 |
03 Feb 10 |
nicklas |
736 |
finally |
5228 |
03 Feb 10 |
nicklas |
737 |
{ |
5228 |
03 Feb 10 |
nicklas |
738 |
if (dc != null) dc.close(); |
5228 |
03 Feb 10 |
nicklas |
739 |
} |
5228 |
03 Feb 10 |
nicklas |
740 |
return id; |
5228 |
03 Feb 10 |
nicklas |
741 |
} |
5228 |
03 Feb 10 |
nicklas |
742 |
|
5228 |
03 Feb 10 |
nicklas |
743 |
|
5230 |
04 Feb 10 |
nicklas |
744 |
|
5228 |
03 Feb 10 |
nicklas |
745 |
|
5228 |
03 Feb 10 |
nicklas |
746 |
static void test_list_bioassays(int bioassaysetId, int expectedResults) |
5228 |
03 Feb 10 |
nicklas |
747 |
{ |
5228 |
03 Feb 10 |
nicklas |
748 |
if (bioassaysetId == 0) return; |
5228 |
03 Feb 10 |
nicklas |
749 |
DbControl dc = null; |
5228 |
03 Feb 10 |
nicklas |
750 |
try |
5228 |
03 Feb 10 |
nicklas |
751 |
{ |
5228 |
03 Feb 10 |
nicklas |
752 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
753 |
BioAssaySet bas = BioAssaySet.getById(dc, bioassaysetId); |
5228 |
03 Feb 10 |
nicklas |
754 |
|
5228 |
03 Feb 10 |
nicklas |
755 |
ItemResultList<BioAssay> l = bas.getBioAssays().list(dc); |
5228 |
03 Feb 10 |
nicklas |
756 |
for (int i = 0; i < l.size(); i++) |
5228 |
03 Feb 10 |
nicklas |
757 |
{ |
5228 |
03 Feb 10 |
nicklas |
758 |
BioAssay ba = l.get(i); |
5228 |
03 Feb 10 |
nicklas |
759 |
write_item(i, ba); |
5228 |
03 Feb 10 |
nicklas |
760 |
for (RawBioAssay rba : ba.getRawBioAssays().list(dc)) |
5228 |
03 Feb 10 |
nicklas |
761 |
{ |
5228 |
03 Feb 10 |
nicklas |
762 |
write_item(i, rba); |
5228 |
03 Feb 10 |
nicklas |
763 |
} |
5228 |
03 Feb 10 |
nicklas |
764 |
} |
5228 |
03 Feb 10 |
nicklas |
765 |
if (expectedResults >= 0 && expectedResults != l.size()) |
5228 |
03 Feb 10 |
nicklas |
766 |
{ |
5228 |
03 Feb 10 |
nicklas |
767 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
5228 |
03 Feb 10 |
nicklas |
768 |
} |
5228 |
03 Feb 10 |
nicklas |
769 |
write("--List bioassays OK ("+l.size()+")"); |
5228 |
03 Feb 10 |
nicklas |
770 |
} |
5228 |
03 Feb 10 |
nicklas |
771 |
catch (Throwable ex) |
5228 |
03 Feb 10 |
nicklas |
772 |
{ |
5228 |
03 Feb 10 |
nicklas |
773 |
write("--List bioassays FAILED"); |
5228 |
03 Feb 10 |
nicklas |
774 |
ex.printStackTrace(); |
5228 |
03 Feb 10 |
nicklas |
775 |
ok = false; |
5228 |
03 Feb 10 |
nicklas |
776 |
} |
5228 |
03 Feb 10 |
nicklas |
777 |
finally |
5228 |
03 Feb 10 |
nicklas |
778 |
{ |
5228 |
03 Feb 10 |
nicklas |
779 |
if (dc != null) dc.close(); |
5228 |
03 Feb 10 |
nicklas |
780 |
} |
5228 |
03 Feb 10 |
nicklas |
781 |
} |
5228 |
03 Feb 10 |
nicklas |
782 |
|
5228 |
03 Feb 10 |
nicklas |
783 |
static void test_list_bioassaysets(int experimentId, int expectedResults) |
5228 |
03 Feb 10 |
nicklas |
784 |
{ |
5228 |
03 Feb 10 |
nicklas |
785 |
if (experimentId == 0) return; |
5228 |
03 Feb 10 |
nicklas |
786 |
DbControl dc = null; |
5228 |
03 Feb 10 |
nicklas |
787 |
try |
5228 |
03 Feb 10 |
nicklas |
788 |
{ |
5228 |
03 Feb 10 |
nicklas |
789 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
790 |
Experiment e = Experiment.getById(dc, experimentId); |
5228 |
03 Feb 10 |
nicklas |
791 |
|
5228 |
03 Feb 10 |
nicklas |
792 |
ItemResultList<BioAssaySet> l = e.getBioAssaySets().list(dc); |
5228 |
03 Feb 10 |
nicklas |
793 |
for (int i = 0; i<l.size(); i++) |
5228 |
03 Feb 10 |
nicklas |
794 |
{ |
5228 |
03 Feb 10 |
nicklas |
795 |
BioAssaySet bas = l.get(i); |
5228 |
03 Feb 10 |
nicklas |
796 |
write_item(i, bas); |
5228 |
03 Feb 10 |
nicklas |
797 |
|
5228 |
03 Feb 10 |
nicklas |
798 |
ItemResultList<ExtraValue> ev = bas.getExtraValues().list(dc); |
5228 |
03 Feb 10 |
nicklas |
799 |
|
5228 |
03 Feb 10 |
nicklas |
800 |
for (int j = 0; j < ev.size(); j++) |
5228 |
03 Feb 10 |
nicklas |
801 |
{ |
5228 |
03 Feb 10 |
nicklas |
802 |
write_item(j, ev.get(j)); |
5228 |
03 Feb 10 |
nicklas |
803 |
} |
5228 |
03 Feb 10 |
nicklas |
804 |
} |
5228 |
03 Feb 10 |
nicklas |
805 |
if (expectedResults >= 0 && expectedResults != l.size()) |
5228 |
03 Feb 10 |
nicklas |
806 |
{ |
5228 |
03 Feb 10 |
nicklas |
807 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
5228 |
03 Feb 10 |
nicklas |
808 |
} |
5228 |
03 Feb 10 |
nicklas |
809 |
write("--List bioassaysets OK ("+l.size()+")"); |
5228 |
03 Feb 10 |
nicklas |
810 |
} |
5228 |
03 Feb 10 |
nicklas |
811 |
catch (Throwable ex) |
5228 |
03 Feb 10 |
nicklas |
812 |
{ |
5228 |
03 Feb 10 |
nicklas |
813 |
write("--List bioassaysets FAILED"); |
5228 |
03 Feb 10 |
nicklas |
814 |
ex.printStackTrace(); |
5228 |
03 Feb 10 |
nicklas |
815 |
ok = false; |
5228 |
03 Feb 10 |
nicklas |
816 |
} |
5228 |
03 Feb 10 |
nicklas |
817 |
finally |
5228 |
03 Feb 10 |
nicklas |
818 |
{ |
5228 |
03 Feb 10 |
nicklas |
819 |
if (dc != null) dc.close(); |
5228 |
03 Feb 10 |
nicklas |
820 |
} |
5228 |
03 Feb 10 |
nicklas |
821 |
} |
5228 |
03 Feb 10 |
nicklas |
822 |
|
5228 |
03 Feb 10 |
nicklas |
823 |
static void test_list_bioassayset_data(int bioAssaySetId, int limit, int offset, int... extraValueTypes) |
5228 |
03 Feb 10 |
nicklas |
824 |
{ |
5228 |
03 Feb 10 |
nicklas |
825 |
if (bioAssaySetId == 0) return; |
5228 |
03 Feb 10 |
nicklas |
826 |
DbControl dc = null; |
5228 |
03 Feb 10 |
nicklas |
827 |
try |
5228 |
03 Feb 10 |
nicklas |
828 |
{ |
5228 |
03 Feb 10 |
nicklas |
829 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
830 |
BioAssaySet bas = BioAssaySet.getById(dc, bioAssaySetId); |
5228 |
03 Feb 10 |
nicklas |
831 |
|
5228 |
03 Feb 10 |
nicklas |
832 |
DynamicSpotQuery query = bas.getSpotData(); |
5228 |
03 Feb 10 |
nicklas |
833 |
query.select(Dynamic.select(VirtualColumn.COLUMN)); |
5228 |
03 Feb 10 |
nicklas |
834 |
query.select(Dynamic.select(VirtualColumn.POSITION)); |
5228 |
03 Feb 10 |
nicklas |
835 |
query.select(Dynamic.select(VirtualColumn.channelRaw(1))); |
5228 |
03 Feb 10 |
nicklas |
836 |
query.select(Dynamic.select(VirtualColumn.channelRaw(2))); |
5228 |
03 Feb 10 |
nicklas |
837 |
query.select(Dynamic.selectReporter("externalId")); |
5228 |
03 Feb 10 |
nicklas |
838 |
query.select(Dynamic.selectRawData("x")); |
5228 |
03 Feb 10 |
nicklas |
839 |
query.select(Dynamic.selectRawData("y")); |
5228 |
03 Feb 10 |
nicklas |
840 |
query.joinReporters(JoinType.LEFT); |
5228 |
03 Feb 10 |
nicklas |
841 |
query.joinRawData(JoinType.LEFT); |
5228 |
03 Feb 10 |
nicklas |
842 |
|
5228 |
03 Feb 10 |
nicklas |
843 |
for (int extraValueTypeId : extraValueTypes) |
5228 |
03 Feb 10 |
nicklas |
844 |
{ |
5228 |
03 Feb 10 |
nicklas |
845 |
ExtraValueType evt = ExtraValueType.getById(dc, extraValueTypeId); |
5228 |
03 Feb 10 |
nicklas |
846 |
ExtraValue ev = bas.getExtraValue(evt); |
5228 |
03 Feb 10 |
nicklas |
847 |
query.joinExtraValue(ev, JoinType.INNER); |
5228 |
03 Feb 10 |
nicklas |
848 |
query.select(Dynamic.select(ev, "ev"+extraValueTypeId)); |
5228 |
03 Feb 10 |
nicklas |
849 |
} |
5228 |
03 Feb 10 |
nicklas |
850 |
|
5228 |
03 Feb 10 |
nicklas |
851 |
query.setMaxResults(limit); |
5228 |
03 Feb 10 |
nicklas |
852 |
query.setFirstResult(offset); |
5228 |
03 Feb 10 |
nicklas |
853 |
query.setReturnTotalCount(true); |
5228 |
03 Feb 10 |
nicklas |
854 |
|
5228 |
03 Feb 10 |
nicklas |
855 |
DynamicResultIterator spots = query.iterate(dc); |
5228 |
03 Feb 10 |
nicklas |
856 |
int column = spots.getIndex(VirtualColumn.COLUMN.getName()); |
5228 |
03 Feb 10 |
nicklas |
857 |
int position = spots.getIndex(VirtualColumn.POSITION.getName()); |
5228 |
03 Feb 10 |
nicklas |
858 |
int ch1 = spots.getIndex(VirtualColumn.channelRaw(1).getName()); |
5228 |
03 Feb 10 |
nicklas |
859 |
int ch2 = spots.getIndex(VirtualColumn.channelRaw(2).getName()); |
5228 |
03 Feb 10 |
nicklas |
860 |
int reporter = spots.getIndex("externalId"); |
5228 |
03 Feb 10 |
nicklas |
861 |
int x = spots.getIndex("x"); |
5228 |
03 Feb 10 |
nicklas |
862 |
int y = spots.getIndex("y"); |
5228 |
03 Feb 10 |
nicklas |
863 |
int[] extraIndex = new int[extraValueTypes.length]; |
5228 |
03 Feb 10 |
nicklas |
864 |
for (int i = 0; i < extraIndex.length; ++i) |
5228 |
03 Feb 10 |
nicklas |
865 |
{ |
5228 |
03 Feb 10 |
nicklas |
866 |
extraIndex[i] = spots.getIndex("ev"+extraValueTypes[i]); |
5228 |
03 Feb 10 |
nicklas |
867 |
} |
5228 |
03 Feb 10 |
nicklas |
868 |
List<Object> extraValues = new ArrayList<Object>(extraIndex.length); |
5228 |
03 Feb 10 |
nicklas |
869 |
int listed = 0; |
5228 |
03 Feb 10 |
nicklas |
870 |
while (spots.hasNext()) |
5228 |
03 Feb 10 |
nicklas |
871 |
{ |
5228 |
03 Feb 10 |
nicklas |
872 |
SqlResult r = spots.next(); |
5228 |
03 Feb 10 |
nicklas |
873 |
for (int i = 0; i < extraIndex.length; ++i) |
5228 |
03 Feb 10 |
nicklas |
874 |
{ |
5228 |
03 Feb 10 |
nicklas |
875 |
extraValues.add(r.getObject(extraIndex[i])); |
5228 |
03 Feb 10 |
nicklas |
876 |
} |
5228 |
03 Feb 10 |
nicklas |
877 |
write_data(listed, r.getShort(column), r.getInt(position), |
5228 |
03 Feb 10 |
nicklas |
878 |
r.getFloat(ch1), r.getFloat(ch2), r.getString(reporter), |
5228 |
03 Feb 10 |
nicklas |
879 |
r.getFloat(x), r.getFloat(y), extraValues); |
5228 |
03 Feb 10 |
nicklas |
880 |
extraValues.clear(); |
5228 |
03 Feb 10 |
nicklas |
881 |
listed++; |
5228 |
03 Feb 10 |
nicklas |
882 |
} |
5228 |
03 Feb 10 |
nicklas |
883 |
spots.close(); |
5228 |
03 Feb 10 |
nicklas |
884 |
|
5228 |
03 Feb 10 |
nicklas |
885 |
dc.close(); |
5228 |
03 Feb 10 |
nicklas |
886 |
write("--List bioassayset data (listed = " + listed + "; total = " + spots.getTotalCount() + ") OK"); |
5228 |
03 Feb 10 |
nicklas |
887 |
} |
5228 |
03 Feb 10 |
nicklas |
888 |
catch (Throwable ex) |
5228 |
03 Feb 10 |
nicklas |
889 |
{ |
5228 |
03 Feb 10 |
nicklas |
890 |
write("--List bioassayset data FAILED"); |
5228 |
03 Feb 10 |
nicklas |
891 |
ex.printStackTrace(); |
5228 |
03 Feb 10 |
nicklas |
892 |
ok = false; |
5228 |
03 Feb 10 |
nicklas |
893 |
} |
5228 |
03 Feb 10 |
nicklas |
894 |
finally |
5228 |
03 Feb 10 |
nicklas |
895 |
{ |
5228 |
03 Feb 10 |
nicklas |
896 |
if (dc != null) dc.close(); |
5228 |
03 Feb 10 |
nicklas |
897 |
} |
5228 |
03 Feb 10 |
nicklas |
898 |
} |
5228 |
03 Feb 10 |
nicklas |
899 |
|
5228 |
03 Feb 10 |
nicklas |
900 |
static void test_list_extra_values(int bioAssaySetId, int extraValueTypeId, int limit, int offset) |
5228 |
03 Feb 10 |
nicklas |
901 |
{ |
5228 |
03 Feb 10 |
nicklas |
902 |
if (bioAssaySetId == 0 || extraValueTypeId == 0) return; |
5228 |
03 Feb 10 |
nicklas |
903 |
DbControl dc = null; |
5228 |
03 Feb 10 |
nicklas |
904 |
try |
5228 |
03 Feb 10 |
nicklas |
905 |
{ |
5228 |
03 Feb 10 |
nicklas |
906 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
907 |
BioAssaySet bas = BioAssaySet.getById(dc, bioAssaySetId); |
5228 |
03 Feb 10 |
nicklas |
908 |
ExtraValueType evt = ExtraValueType.getById(dc, extraValueTypeId); |
5228 |
03 Feb 10 |
nicklas |
909 |
ExtraValue ev = bas.getExtraValue(evt); |
5228 |
03 Feb 10 |
nicklas |
910 |
|
5228 |
03 Feb 10 |
nicklas |
911 |
DynamicExtraValueQuery query = ev.getValues(); |
5228 |
03 Feb 10 |
nicklas |
912 |
query.setMaxResults(limit); |
5228 |
03 Feb 10 |
nicklas |
913 |
query.setFirstResult(offset); |
5228 |
03 Feb 10 |
nicklas |
914 |
query.setReturnTotalCount(true); |
5228 |
03 Feb 10 |
nicklas |
915 |
|
5228 |
03 Feb 10 |
nicklas |
916 |
DynamicResultIterator values = query.iterate(dc); |
5228 |
03 Feb 10 |
nicklas |
917 |
int column = values.getIndex(VirtualColumn.COLUMN.getName()); |
5228 |
03 Feb 10 |
nicklas |
918 |
int position = values.getIndex(VirtualColumn.POSITION.getName()); |
5228 |
03 Feb 10 |
nicklas |
919 |
int extra = values.getIndex(ev.getVirtualColumn().getName()); |
5228 |
03 Feb 10 |
nicklas |
920 |
int listed = 0; |
5228 |
03 Feb 10 |
nicklas |
921 |
while (values.hasNext()) |
5228 |
03 Feb 10 |
nicklas |
922 |
{ |
5228 |
03 Feb 10 |
nicklas |
923 |
SqlResult r = values.next(); |
5228 |
03 Feb 10 |
nicklas |
924 |
write_extra_value(listed, r.getShort(column), r.getInt(position), |
5228 |
03 Feb 10 |
nicklas |
925 |
r.getObject(extra)); |
5228 |
03 Feb 10 |
nicklas |
926 |
listed++; |
5228 |
03 Feb 10 |
nicklas |
927 |
} |
5228 |
03 Feb 10 |
nicklas |
928 |
values.close(); |
5228 |
03 Feb 10 |
nicklas |
929 |
|
5228 |
03 Feb 10 |
nicklas |
930 |
dc.close(); |
5228 |
03 Feb 10 |
nicklas |
931 |
write("--List extra values (listed = " + listed + "; total = " + values.getTotalCount() + ") OK"); |
5228 |
03 Feb 10 |
nicklas |
932 |
} |
5228 |
03 Feb 10 |
nicklas |
933 |
catch (Throwable ex) |
5228 |
03 Feb 10 |
nicklas |
934 |
{ |
5228 |
03 Feb 10 |
nicklas |
935 |
write("--List extra values FAILED"); |
5228 |
03 Feb 10 |
nicklas |
936 |
ex.printStackTrace(); |
5228 |
03 Feb 10 |
nicklas |
937 |
ok = false; |
5228 |
03 Feb 10 |
nicklas |
938 |
} |
5228 |
03 Feb 10 |
nicklas |
939 |
finally |
5228 |
03 Feb 10 |
nicklas |
940 |
{ |
5228 |
03 Feb 10 |
nicklas |
941 |
if (dc != null) dc.close(); |
5228 |
03 Feb 10 |
nicklas |
942 |
} |
5228 |
03 Feb 10 |
nicklas |
943 |
|
5228 |
03 Feb 10 |
nicklas |
944 |
} |
5228 |
03 Feb 10 |
nicklas |
945 |
|
5228 |
03 Feb 10 |
nicklas |
946 |
static void test_delete_data_files(int bioAssaySetId) |
5228 |
03 Feb 10 |
nicklas |
947 |
{ |
5228 |
03 Feb 10 |
nicklas |
948 |
if (bioAssaySetId == 0) return; |
5228 |
03 Feb 10 |
nicklas |
949 |
DbControl dc = null; |
5228 |
03 Feb 10 |
nicklas |
950 |
try |
5228 |
03 Feb 10 |
nicklas |
951 |
{ |
5228 |
03 Feb 10 |
nicklas |
952 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
953 |
BioAssaySet bas = BioAssaySet.getById(dc, bioAssaySetId); |
5228 |
03 Feb 10 |
nicklas |
954 |
List<File> files = new ArrayList<File>(); |
5228 |
03 Feb 10 |
nicklas |
955 |
if (bas.hasFileSet()) |
5228 |
03 Feb 10 |
nicklas |
956 |
{ |
5228 |
03 Feb 10 |
nicklas |
957 |
FileSet fs = bas.getFileSet(); |
5228 |
03 Feb 10 |
nicklas |
958 |
List<FileSetMember> members = fs.getMembers().list(dc); |
5228 |
03 Feb 10 |
nicklas |
959 |
for (FileSetMember fm : members) |
5228 |
03 Feb 10 |
nicklas |
960 |
{ |
5228 |
03 Feb 10 |
nicklas |
961 |
files.add(fm.getFile()); |
5713 |
02 Sep 11 |
nicklas |
962 |
fs.removeMember(fm); |
5228 |
03 Feb 10 |
nicklas |
963 |
} |
5228 |
03 Feb 10 |
nicklas |
964 |
} |
5228 |
03 Feb 10 |
nicklas |
965 |
bas.setNumFileReporters(0); |
5228 |
03 Feb 10 |
nicklas |
966 |
bas.setNumFileSpots(0); |
5228 |
03 Feb 10 |
nicklas |
967 |
dc.commit(); |
5228 |
03 Feb 10 |
nicklas |
968 |
|
5228 |
03 Feb 10 |
nicklas |
969 |
dc = TestUtil.getDbControl(); |
5228 |
03 Feb 10 |
nicklas |
970 |
for (File f : files) |
5228 |
03 Feb 10 |
nicklas |
971 |
{ |
5228 |
03 Feb 10 |
nicklas |
972 |
dc.deleteItem(f); |
5228 |
03 Feb 10 |
nicklas |
973 |
} |
5228 |
03 Feb 10 |
nicklas |
974 |
dc.commit(); |
5228 |
03 Feb 10 |
nicklas |
975 |
write("--Delete data files OK (" + files.size() + ")"); |
5228 |
03 Feb 10 |
nicklas |
976 |
} |
5228 |
03 Feb 10 |
nicklas |
977 |
catch (Throwable ex) |
5228 |
03 Feb 10 |
nicklas |
978 |
{ |
5228 |
03 Feb 10 |
nicklas |
979 |
write("--Delete data files FAILED"); |
5228 |
03 Feb 10 |
nicklas |
980 |
ex.printStackTrace(); |
5228 |
03 Feb 10 |
nicklas |
981 |
ok = false; |
5228 |
03 Feb 10 |
nicklas |
982 |
} |
5228 |
03 Feb 10 |
nicklas |
983 |
finally |
5228 |
03 Feb 10 |
nicklas |
984 |
{ |
5228 |
03 Feb 10 |
nicklas |
985 |
if (dc != null) dc.close(); |
5228 |
03 Feb 10 |
nicklas |
986 |
} |
5228 |
03 Feb 10 |
nicklas |
987 |
} |
5228 |
03 Feb 10 |
nicklas |
988 |
} |