5233 |
04 Feb 10 |
nicklas |
1 |
/* |
5233 |
04 Feb 10 |
nicklas |
$Id $ |
5233 |
04 Feb 10 |
nicklas |
3 |
|
5233 |
04 Feb 10 |
nicklas |
Copyright (C) 2010 Nicklas Nordborg |
5233 |
04 Feb 10 |
nicklas |
5 |
|
5233 |
04 Feb 10 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5233 |
04 Feb 10 |
nicklas |
Available at http://base.thep.lu.se/ |
5233 |
04 Feb 10 |
nicklas |
8 |
|
5233 |
04 Feb 10 |
nicklas |
BASE is free software; you can redistribute it and/or modify it |
5233 |
04 Feb 10 |
nicklas |
under the terms of the GNU General Public License as published by |
5233 |
04 Feb 10 |
nicklas |
the Free Software Foundation; either version 3 of the License, or |
5233 |
04 Feb 10 |
nicklas |
at your option) any later version. |
5233 |
04 Feb 10 |
nicklas |
13 |
|
5233 |
04 Feb 10 |
nicklas |
BASE is distributed in the hope that it will be useful, but |
5233 |
04 Feb 10 |
nicklas |
WITHOUT ANY WARRANTY; without even the implied warranty of |
5233 |
04 Feb 10 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
5233 |
04 Feb 10 |
nicklas |
General Public License for more details. |
5233 |
04 Feb 10 |
nicklas |
18 |
|
5233 |
04 Feb 10 |
nicklas |
You should have received a copy of the GNU General Public License |
5233 |
04 Feb 10 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5233 |
04 Feb 10 |
nicklas |
21 |
*/ |
5233 |
04 Feb 10 |
nicklas |
22 |
|
5233 |
04 Feb 10 |
nicklas |
23 |
import net.sf.basedb.core.AnnotationType; |
5319 |
20 Apr 10 |
nicklas |
24 |
import net.sf.basedb.core.BioAssay; |
5233 |
04 Feb 10 |
nicklas |
25 |
import net.sf.basedb.core.BioAssaySet; |
5233 |
04 Feb 10 |
nicklas |
26 |
import net.sf.basedb.core.DbControl; |
5233 |
04 Feb 10 |
nicklas |
27 |
import net.sf.basedb.core.Directory; |
5233 |
04 Feb 10 |
nicklas |
28 |
import net.sf.basedb.core.File; |
5233 |
04 Feb 10 |
nicklas |
29 |
import net.sf.basedb.core.Formula; |
5319 |
20 Apr 10 |
nicklas |
30 |
import net.sf.basedb.core.Item; |
5233 |
04 Feb 10 |
nicklas |
31 |
import net.sf.basedb.core.ItemQuery; |
5233 |
04 Feb 10 |
nicklas |
32 |
import net.sf.basedb.core.Transformation; |
5233 |
04 Feb 10 |
nicklas |
33 |
import net.sf.basedb.core.Type; |
5233 |
04 Feb 10 |
nicklas |
34 |
import net.sf.basedb.core.VirtualColumn; |
5233 |
04 Feb 10 |
nicklas |
35 |
import net.sf.basedb.core.query.Dynamic; |
5233 |
04 Feb 10 |
nicklas |
36 |
import net.sf.basedb.core.query.Expressions; |
5233 |
04 Feb 10 |
nicklas |
37 |
import net.sf.basedb.core.query.Hql; |
5233 |
04 Feb 10 |
nicklas |
38 |
import net.sf.basedb.core.query.Restrictions; |
5233 |
04 Feb 10 |
nicklas |
39 |
import net.sf.basedb.util.ConsoleProgressReporter; |
5236 |
05 Feb 10 |
nicklas |
40 |
import net.sf.basedb.util.FileUtil; |
5236 |
05 Feb 10 |
nicklas |
41 |
import net.sf.basedb.util.Values; |
5236 |
05 Feb 10 |
nicklas |
42 |
import net.sf.basedb.util.bfs.AnnotationModel; |
5236 |
05 Feb 10 |
nicklas |
43 |
import net.sf.basedb.util.bfs.AnnotationParser; |
5233 |
04 Feb 10 |
nicklas |
44 |
import net.sf.basedb.util.bfs.AnnotationWriter; |
5233 |
04 Feb 10 |
nicklas |
45 |
import net.sf.basedb.util.bfs.BaseInputStreamLocator; |
5236 |
05 Feb 10 |
nicklas |
46 |
import net.sf.basedb.util.bfs.BfsParser; |
5236 |
05 Feb 10 |
nicklas |
47 |
import net.sf.basedb.util.bfs.DataParser; |
5236 |
05 Feb 10 |
nicklas |
48 |
import net.sf.basedb.util.bfs.DataWriter; |
5236 |
05 Feb 10 |
nicklas |
49 |
import net.sf.basedb.util.bfs.EventHandler; |
5236 |
05 Feb 10 |
nicklas |
50 |
import net.sf.basedb.util.bfs.EventType; |
5238 |
09 Feb 10 |
nicklas |
51 |
import net.sf.basedb.util.bfs.GenericExtraFileImporter; |
5233 |
04 Feb 10 |
nicklas |
52 |
import net.sf.basedb.util.bfs.GenericBaseDataWriterFactory; |
5236 |
05 Feb 10 |
nicklas |
53 |
import net.sf.basedb.util.bfs.MetadataModel; |
5233 |
04 Feb 10 |
nicklas |
54 |
import net.sf.basedb.util.bfs.MetadataParser; |
5233 |
04 Feb 10 |
nicklas |
55 |
import net.sf.basedb.util.bfs.MetadataWriter; |
5233 |
04 Feb 10 |
nicklas |
56 |
import net.sf.basedb.util.bfs.SuggestedFilenameGenerator; |
5236 |
05 Feb 10 |
nicklas |
57 |
import net.sf.basedb.util.bfs.MetadataModel.Section; |
5233 |
04 Feb 10 |
nicklas |
58 |
import net.sf.basedb.util.export.spotdata.AssayField; |
5233 |
04 Feb 10 |
nicklas |
59 |
import net.sf.basedb.util.export.spotdata.BfsExporter; |
5233 |
04 Feb 10 |
nicklas |
60 |
import net.sf.basedb.util.export.spotdata.DynamicField; |
5319 |
20 Apr 10 |
nicklas |
61 |
import net.sf.basedb.util.export.spotdata.ExportableFieldConverter; |
5233 |
04 Feb 10 |
nicklas |
62 |
import net.sf.basedb.util.export.spotdata.ExportableFieldFactory; |
5233 |
04 Feb 10 |
nicklas |
63 |
import net.sf.basedb.util.export.spotdata.MatrixBfsExporter; |
5233 |
04 Feb 10 |
nicklas |
64 |
import net.sf.basedb.util.export.spotdata.SerialBfsExporter; |
5319 |
20 Apr 10 |
nicklas |
65 |
import net.sf.basedb.util.export.spotdata.StandardFieldConverter; |
5233 |
04 Feb 10 |
nicklas |
66 |
import net.sf.basedb.util.importer.spotdata.BfsImporter; |
5233 |
04 Feb 10 |
nicklas |
67 |
|
5233 |
04 Feb 10 |
nicklas |
68 |
import java.util.ArrayList; |
5233 |
04 Feb 10 |
nicklas |
69 |
import java.util.List; |
5233 |
04 Feb 10 |
nicklas |
70 |
|
5233 |
04 Feb 10 |
nicklas |
71 |
|
5233 |
04 Feb 10 |
nicklas |
72 |
public class TestBfsExporterImporter |
5233 |
04 Feb 10 |
nicklas |
73 |
{ |
5233 |
04 Feb 10 |
nicklas |
74 |
static boolean ok = true; |
5233 |
04 Feb 10 |
nicklas |
75 |
|
5233 |
04 Feb 10 |
nicklas |
76 |
public static void main(String[] args) |
5233 |
04 Feb 10 |
nicklas |
77 |
{ |
5233 |
04 Feb 10 |
nicklas |
78 |
TestUtil.checkArgs(args); |
5233 |
04 Feb 10 |
nicklas |
79 |
TestUtil.begin(); |
5233 |
04 Feb 10 |
nicklas |
80 |
ok = test_all(); |
5233 |
04 Feb 10 |
nicklas |
81 |
TestUtil.stop(); |
5233 |
04 Feb 10 |
nicklas |
82 |
} |
5233 |
04 Feb 10 |
nicklas |
83 |
|
5233 |
04 Feb 10 |
nicklas |
84 |
static boolean test_all() |
5233 |
04 Feb 10 |
nicklas |
85 |
{ |
5233 |
04 Feb 10 |
nicklas |
86 |
boolean wasSetup = TestAnalyzeUtil.setupExperiment(); |
5233 |
04 Feb 10 |
nicklas |
87 |
write("++Testing BFS exporter and importer"); |
5233 |
04 Feb 10 |
nicklas |
88 |
try |
5233 |
04 Feb 10 |
nicklas |
89 |
{ |
5233 |
04 Feb 10 |
nicklas |
90 |
int experimentId = TestAnalyzeUtil.getItemId("experiment.genepix"); |
5233 |
04 Feb 10 |
nicklas |
91 |
int rootBasId = TestAnalyzeUtil.getItemId("bioassayset.root"); |
5233 |
04 Feb 10 |
nicklas |
92 |
int tempFactorId = TestAnalyzeUtil.getItemId("factor.temperature"); |
5233 |
04 Feb 10 |
nicklas |
93 |
|
5233 |
04 Feb 10 |
nicklas |
94 |
if (experimentId == 0 || rootBasId == 0) |
5233 |
04 Feb 10 |
nicklas |
95 |
{ |
5233 |
04 Feb 10 |
nicklas |
96 |
ok = false; |
5233 |
04 Feb 10 |
nicklas |
97 |
write("Test experiment was not setup correctly."); |
5233 |
04 Feb 10 |
nicklas |
98 |
return ok; |
5233 |
04 Feb 10 |
nicklas |
99 |
} |
5233 |
04 Feb 10 |
nicklas |
100 |
|
5319 |
20 Apr 10 |
nicklas |
101 |
int assayAnnotationId = TestAnnotationType.test_create("Assay mean", Type.FLOAT, 0, null, null, Item.BIOASSAY, 1, null, false); |
5319 |
20 Apr 10 |
nicklas |
102 |
|
5233 |
04 Feb 10 |
nicklas |
103 |
int bfsSerialDir = TestDirectory.test_create(true, "bfs-serial"); |
5233 |
04 Feb 10 |
nicklas |
104 |
int bfsMatrixDir = TestDirectory.test_create(true, "bfs-matrix"); |
5236 |
05 Feb 10 |
nicklas |
105 |
int bfsMergeAssaysDir = TestDirectory.test_create(true, "bfs-merge-assays"); |
5236 |
05 Feb 10 |
nicklas |
106 |
int bfsMergeReportersDir = TestDirectory.test_create(true, "bfs-merge-reporters"); |
5319 |
20 Apr 10 |
nicklas |
107 |
|
5233 |
04 Feb 10 |
nicklas |
108 |
int exportRoot = TestAnalyzeUtil.clone_bioassay_set(rootBasId, "BfsExporter"); |
5319 |
20 Apr 10 |
nicklas |
109 |
test_annotate_assays(exportRoot, assayAnnotationId, 4.5f, 7.8f); |
5233 |
04 Feb 10 |
nicklas |
110 |
|
5319 |
20 Apr 10 |
nicklas |
111 |
test_export(exportRoot, bfsSerialDir, "Temperature", "Assay mean", false); |
5319 |
20 Apr 10 |
nicklas |
112 |
test_export(exportRoot, bfsMatrixDir, "Temperature", "Assay mean", true); |
5233 |
04 Feb 10 |
nicklas |
113 |
|
5233 |
04 Feb 10 |
nicklas |
114 |
test_import(exportRoot, bfsSerialDir, false, "Imported Serial BFS"); |
5233 |
04 Feb 10 |
nicklas |
115 |
test_import(exportRoot, bfsMatrixDir, true, "Imported Matrix BFS"); |
5238 |
09 Feb 10 |
nicklas |
116 |
|
5238 |
09 Feb 10 |
nicklas |
117 |
test_upload_extra_file("data/test.upload.txt", "x-table.txt", bfsMergeAssaysDir); |
5238 |
09 Feb 10 |
nicklas |
118 |
test_upload_extra_file("data/test.upload.png", "x-plot.png", bfsMergeAssaysDir); |
5236 |
05 Feb 10 |
nicklas |
119 |
|
5236 |
05 Feb 10 |
nicklas |
120 |
test_merge_assays(bfsMatrixDir, bfsMergeAssaysDir); |
5236 |
05 Feb 10 |
nicklas |
121 |
test_import(exportRoot, bfsMergeAssaysDir, true, "Merged assays"); |
5237 |
08 Feb 10 |
nicklas |
122 |
test_merge_reporters(bfsMatrixDir, bfsMergeReportersDir); |
5237 |
08 Feb 10 |
nicklas |
123 |
test_import(exportRoot, bfsMergeReportersDir, true, "Merged reporters"); |
5236 |
05 Feb 10 |
nicklas |
124 |
|
5233 |
04 Feb 10 |
nicklas |
125 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
5233 |
04 Feb 10 |
nicklas |
126 |
TestAnalyzeUtil.test_delete_bioassayset(exportRoot); |
5233 |
04 Feb 10 |
nicklas |
127 |
TestDirectory.test_delete(bfsSerialDir, true); |
5233 |
04 Feb 10 |
nicklas |
128 |
TestDirectory.test_delete(bfsMatrixDir, true); |
5236 |
05 Feb 10 |
nicklas |
129 |
TestDirectory.test_delete(bfsMergeAssaysDir, true); |
5236 |
05 Feb 10 |
nicklas |
130 |
TestDirectory.test_delete(bfsMergeReportersDir, true); |
5319 |
20 Apr 10 |
nicklas |
131 |
TestAnnotationType.test_delete(assayAnnotationId); |
5233 |
04 Feb 10 |
nicklas |
132 |
} |
5233 |
04 Feb 10 |
nicklas |
133 |
finally |
5233 |
04 Feb 10 |
nicklas |
134 |
{ |
5233 |
04 Feb 10 |
nicklas |
135 |
if (wasSetup) TestAnalyzeUtil.cleanupExperiment(); |
5233 |
04 Feb 10 |
nicklas |
136 |
write("++Testing BFS exporter and importer "+(ok ? "OK" : "Failed")+"\n"); |
5233 |
04 Feb 10 |
nicklas |
137 |
} |
5233 |
04 Feb 10 |
nicklas |
138 |
return ok; |
5233 |
04 Feb 10 |
nicklas |
139 |
} |
5233 |
04 Feb 10 |
nicklas |
140 |
|
6875 |
20 Apr 15 |
nicklas |
141 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
5233 |
04 Feb 10 |
nicklas |
142 |
static void test_export(int bioAssaySetId, int directoryId, |
5319 |
20 Apr 10 |
nicklas |
143 |
String experimentalFactor, String assayAnnotation, boolean matrix) |
5233 |
04 Feb 10 |
nicklas |
144 |
{ |
5384 |
13 Aug 10 |
nicklas |
145 |
if (bioAssaySetId == 0 || directoryId == 0) return; |
5233 |
04 Feb 10 |
nicklas |
146 |
DbControl dc = null; |
5233 |
04 Feb 10 |
nicklas |
147 |
try |
5233 |
04 Feb 10 |
nicklas |
148 |
{ |
5233 |
04 Feb 10 |
nicklas |
149 |
dc = TestUtil.getDbControl(); |
5233 |
04 Feb 10 |
nicklas |
150 |
BioAssaySet bas = BioAssaySet.getById(dc, bioAssaySetId); |
5233 |
04 Feb 10 |
nicklas |
151 |
Directory dir = Directory.getById(dc, directoryId); |
5233 |
04 Feb 10 |
nicklas |
152 |
|
5233 |
04 Feb 10 |
nicklas |
// Create exporter |
5233 |
04 Feb 10 |
nicklas |
154 |
BfsExporter bfs = matrix ? new MatrixBfsExporter() : new SerialBfsExporter(); |
5233 |
04 Feb 10 |
nicklas |
155 |
bfs.setDbControl(dc); |
5233 |
04 Feb 10 |
nicklas |
156 |
bfs.setSource(bas); |
5233 |
04 Feb 10 |
nicklas |
157 |
if (!TestUtil.getSilent()) bfs.setProgressReporter(new ConsoleProgressReporter()); |
5233 |
04 Feb 10 |
nicklas |
158 |
|
5233 |
04 Feb 10 |
nicklas |
// Create files and file factory |
5233 |
04 Feb 10 |
nicklas |
160 |
File metadata = createFile(dc, dir, "metadata.txt"); |
5233 |
04 Feb 10 |
nicklas |
161 |
File reporter = createFile(dc, dir, "rdata.txt"); |
5233 |
04 Feb 10 |
nicklas |
162 |
File assay = createFile(dc, dir, "pdata.txt"); |
5233 |
04 Feb 10 |
nicklas |
163 |
bfs.setMetadataWriter(MetadataWriter.create( |
5233 |
04 Feb 10 |
nicklas |
164 |
metadata.getUploadStream(false), metadata.getName())); |
5233 |
04 Feb 10 |
nicklas |
165 |
bfs.setReporterAnnotationsWriter(AnnotationWriter.create( |
5233 |
04 Feb 10 |
nicklas |
166 |
reporter.getUploadStream(false), reporter.getName())); |
5233 |
04 Feb 10 |
nicklas |
167 |
bfs.setAssayAnnotationsWriter(AnnotationWriter.create( |
5233 |
04 Feb 10 |
nicklas |
168 |
assay.getUploadStream(false), assay.getName())); |
5233 |
04 Feb 10 |
nicklas |
169 |
bfs.setDataWriterFactory(new GenericBaseDataWriterFactory(dc, dir, new SuggestedFilenameGenerator())); |
5233 |
04 Feb 10 |
nicklas |
170 |
|
5233 |
04 Feb 10 |
nicklas |
// Parameters that go in the 'settings' section |
5233 |
04 Feb 10 |
nicklas |
172 |
bfs.setParameter("b", "some parameter"); |
5233 |
04 Feb 10 |
nicklas |
173 |
bfs.setParameter("a", "some other parameter"); |
5233 |
04 Feb 10 |
nicklas |
174 |
|
5319 |
20 Apr 10 |
nicklas |
175 |
ExportableFieldConverter fieldConverter = new StandardFieldConverter(dc, bas); |
5319 |
20 Apr 10 |
nicklas |
176 |
|
5233 |
04 Feb 10 |
nicklas |
// Configure the spot fields to export |
5319 |
20 Apr 10 |
nicklas |
178 |
|
5233 |
04 Feb 10 |
nicklas |
179 |
List<DynamicField> spotFields = new ArrayList<DynamicField>(); |
5319 |
20 Apr 10 |
nicklas |
180 |
spotFields.add(fieldConverter.getSpotField("Ch 1", true)); |
5319 |
20 Apr 10 |
nicklas |
181 |
spotFields.add(fieldConverter.getSpotField("Ch 2", true)); |
5319 |
20 Apr 10 |
nicklas |
182 |
spotFields.add(fieldConverter.getSpotField("row", true)); |
5319 |
20 Apr 10 |
nicklas |
183 |
spotFields.add(fieldConverter.getSpotField("flags", true)); |
5319 |
20 Apr 10 |
nicklas |
184 |
spotFields.add(fieldConverter.getSpotField("Ratio, ch1 / ch2", true)); |
5319 |
20 Apr 10 |
nicklas |
185 |
bfs.addSpotFields(spotFields); |
5233 |
04 Feb 10 |
nicklas |
186 |
|
5233 |
04 Feb 10 |
nicklas |
// Configure the reporter fields to export |
5233 |
04 Feb 10 |
nicklas |
188 |
List<DynamicField> reporterFields = new ArrayList<DynamicField>(); |
5319 |
20 Apr 10 |
nicklas |
189 |
reporterFields.add(ExportableFieldFactory.simple(Dynamic.column(VirtualColumn.POSITION), "Position", Type.INT, Formula.AverageMethod.NONE, null)); |
5319 |
20 Apr 10 |
nicklas |
190 |
reporterFields.add(fieldConverter.getReporterField("Name", true)); |
5319 |
20 Apr 10 |
nicklas |
191 |
reporterFields.add(fieldConverter.getReporterField("External ID", true)); |
5233 |
04 Feb 10 |
nicklas |
192 |
bfs.addReporterFields(reporterFields); |
5233 |
04 Feb 10 |
nicklas |
193 |
|
5233 |
04 Feb 10 |
nicklas |
// Configure assay fields to export |
5233 |
04 Feb 10 |
nicklas |
195 |
List<AssayField> assayFields = new ArrayList<AssayField>(); |
5319 |
20 Apr 10 |
nicklas |
196 |
assayFields.add(fieldConverter.getAssayField("Name", true)); |
5319 |
20 Apr 10 |
nicklas |
197 |
if (experimentalFactor != null) |
5233 |
04 Feb 10 |
nicklas |
198 |
{ |
5319 |
20 Apr 10 |
nicklas |
199 |
assayFields.add(fieldConverter.getAssayField(experimentalFactor, true)); |
5233 |
04 Feb 10 |
nicklas |
200 |
} |
5319 |
20 Apr 10 |
nicklas |
201 |
if (assayAnnotation != null) |
5319 |
20 Apr 10 |
nicklas |
202 |
{ |
5319 |
20 Apr 10 |
nicklas |
203 |
assayFields.add(fieldConverter.getAssayField(assayAnnotation, true)); |
5319 |
20 Apr 10 |
nicklas |
204 |
} |
5233 |
04 Feb 10 |
nicklas |
205 |
bfs.addAssayFields(assayFields); |
5233 |
04 Feb 10 |
nicklas |
206 |
|
5233 |
04 Feb 10 |
nicklas |
207 |
bfs.doExport(); |
5233 |
04 Feb 10 |
nicklas |
208 |
if (!TestUtil.getSilent()) write(""); |
5233 |
04 Feb 10 |
nicklas |
209 |
dc.commit(); |
5233 |
04 Feb 10 |
nicklas |
210 |
write("--Exporting bfs [" + (matrix ? "matrix" : "serial") + "] OK"); |
5233 |
04 Feb 10 |
nicklas |
211 |
} |
5233 |
04 Feb 10 |
nicklas |
212 |
catch (Throwable ex) |
5233 |
04 Feb 10 |
nicklas |
213 |
{ |
5233 |
04 Feb 10 |
nicklas |
214 |
write("--Exporting bfs [" + (matrix ? "matrix" : "serial") + "] FAILED"); |
5233 |
04 Feb 10 |
nicklas |
215 |
ex.printStackTrace(); |
5233 |
04 Feb 10 |
nicklas |
216 |
ok = false; |
5233 |
04 Feb 10 |
nicklas |
217 |
} |
5233 |
04 Feb 10 |
nicklas |
218 |
finally |
5233 |
04 Feb 10 |
nicklas |
219 |
{ |
5233 |
04 Feb 10 |
nicklas |
220 |
if (dc != null) dc.close(); |
5233 |
04 Feb 10 |
nicklas |
221 |
} |
5233 |
04 Feb 10 |
nicklas |
222 |
|
5233 |
04 Feb 10 |
nicklas |
223 |
} |
5233 |
04 Feb 10 |
nicklas |
224 |
|
5233 |
04 Feb 10 |
nicklas |
225 |
|
5233 |
04 Feb 10 |
nicklas |
226 |
static int test_import(int bioAssaySetId, int directoryId, boolean matrix, String childName) |
5233 |
04 Feb 10 |
nicklas |
227 |
{ |
5233 |
04 Feb 10 |
nicklas |
228 |
DbControl dc = null; |
5233 |
04 Feb 10 |
nicklas |
229 |
if (bioAssaySetId == 0 || directoryId == 0) return 0; |
5233 |
04 Feb 10 |
nicklas |
230 |
int id = 0; |
5233 |
04 Feb 10 |
nicklas |
231 |
try |
5233 |
04 Feb 10 |
nicklas |
232 |
{ |
5233 |
04 Feb 10 |
nicklas |
233 |
dc = TestUtil.getDbControl(); |
5233 |
04 Feb 10 |
nicklas |
234 |
BioAssaySet bas = BioAssaySet.getById(dc, bioAssaySetId); |
5233 |
04 Feb 10 |
nicklas |
235 |
Directory dir = Directory.getById(dc, directoryId); |
5233 |
04 Feb 10 |
nicklas |
236 |
File metadata = File.getFile(dc, dir, "metadata.txt", false); |
5233 |
04 Feb 10 |
nicklas |
237 |
Transformation t = bas.newTransformation(null); |
5233 |
04 Feb 10 |
nicklas |
238 |
t.setName("Importing " + (matrix ? "matrix" : "serial") + " BFS"); |
5233 |
04 Feb 10 |
nicklas |
239 |
|
5233 |
04 Feb 10 |
nicklas |
240 |
BfsImporter bfs = new BfsImporter(); |
5233 |
04 Feb 10 |
nicklas |
241 |
bfs.setDbControl(dc); |
5233 |
04 Feb 10 |
nicklas |
242 |
bfs.setTransformation(t); |
5233 |
04 Feb 10 |
nicklas |
243 |
dc.saveItem(t); |
5233 |
04 Feb 10 |
nicklas |
244 |
bfs.setMetadataParser(MetadataParser.create(metadata)); |
5233 |
04 Feb 10 |
nicklas |
245 |
bfs.setInputStreamLocator(new BaseInputStreamLocator(dc, dir)); |
5238 |
09 Feb 10 |
nicklas |
246 |
bfs.setExtraFileImporter(new GenericExtraFileImporter(dc, dir, false)); |
5233 |
04 Feb 10 |
nicklas |
247 |
if (!TestUtil.getSilent()) bfs.setProgressReporter(new ConsoleProgressReporter()); |
5233 |
04 Feb 10 |
nicklas |
248 |
BioAssaySet child = bfs.doImport(); |
5233 |
04 Feb 10 |
nicklas |
249 |
if (!TestUtil.getSilent()) write("\n"); |
5233 |
04 Feb 10 |
nicklas |
250 |
child.setName(childName); |
5233 |
04 Feb 10 |
nicklas |
251 |
dc.commit(); |
5233 |
04 Feb 10 |
nicklas |
252 |
|
5233 |
04 Feb 10 |
nicklas |
253 |
id = child.getId(); |
5233 |
04 Feb 10 |
nicklas |
254 |
write("--Importing bfs [" + (matrix ? "matrix" : "serial") + "] OK"); |
5233 |
04 Feb 10 |
nicklas |
255 |
} |
5233 |
04 Feb 10 |
nicklas |
256 |
catch (Throwable ex) |
5233 |
04 Feb 10 |
nicklas |
257 |
{ |
5233 |
04 Feb 10 |
nicklas |
258 |
write("--Importing bfs [" + (matrix ? "matrix" : "serial") + "] FAILED"); |
5233 |
04 Feb 10 |
nicklas |
259 |
ex.printStackTrace(); |
5233 |
04 Feb 10 |
nicklas |
260 |
ok = false; |
5233 |
04 Feb 10 |
nicklas |
261 |
} |
5233 |
04 Feb 10 |
nicklas |
262 |
finally |
5233 |
04 Feb 10 |
nicklas |
263 |
{ |
5233 |
04 Feb 10 |
nicklas |
264 |
if (dc != null) dc.close(); |
5233 |
04 Feb 10 |
nicklas |
265 |
} |
5233 |
04 Feb 10 |
nicklas |
266 |
return id; |
5233 |
04 Feb 10 |
nicklas |
267 |
} |
5233 |
04 Feb 10 |
nicklas |
268 |
|
5236 |
05 Feb 10 |
nicklas |
269 |
static int test_merge_assays(int sourceDirId, int mergeDirId) |
5236 |
05 Feb 10 |
nicklas |
270 |
{ |
5236 |
05 Feb 10 |
nicklas |
271 |
DbControl dc = null; |
5236 |
05 Feb 10 |
nicklas |
272 |
if (sourceDirId == 0 || mergeDirId == 0) return 0; |
5236 |
05 Feb 10 |
nicklas |
273 |
int id = 0; |
5236 |
05 Feb 10 |
nicklas |
274 |
try |
5236 |
05 Feb 10 |
nicklas |
275 |
{ |
5236 |
05 Feb 10 |
nicklas |
276 |
dc = TestUtil.getDbControl(); |
5236 |
05 Feb 10 |
nicklas |
277 |
Directory sourceDir = Directory.getById(dc, sourceDirId); |
5236 |
05 Feb 10 |
nicklas |
278 |
Directory mergeDir = Directory.getById(dc, mergeDirId); |
5236 |
05 Feb 10 |
nicklas |
279 |
|
5236 |
05 Feb 10 |
nicklas |
280 |
File ch1In = File.getFile(dc, sourceDir, "Ch 1.txt", false); |
5236 |
05 Feb 10 |
nicklas |
281 |
File ch2In = File.getFile(dc, sourceDir, "Ch 2.txt", false); |
5236 |
05 Feb 10 |
nicklas |
282 |
File reporterIn = File.getFile(dc, sourceDir, "rdata.txt", false); |
5236 |
05 Feb 10 |
nicklas |
283 |
File assaysIn = File.getFile(dc, sourceDir, "pdata.txt", false); |
5236 |
05 Feb 10 |
nicklas |
284 |
|
5236 |
05 Feb 10 |
nicklas |
// Create the new metadata file |
5236 |
05 Feb 10 |
nicklas |
286 |
File metadataOut = File.getFile(dc, mergeDir, "metadata.txt", true); |
5236 |
05 Feb 10 |
nicklas |
287 |
dc.saveItem(metadataOut); |
5236 |
05 Feb 10 |
nicklas |
288 |
MetadataModel metadata = new MetadataModel(); |
5236 |
05 Feb 10 |
nicklas |
289 |
metadata.setSubtype("matrix"); |
5236 |
05 Feb 10 |
nicklas |
290 |
metadata.addFile("sdata1", "Ch 1.txt"); |
5236 |
05 Feb 10 |
nicklas |
291 |
metadata.addFile("sdata2", "Ch 2.txt"); |
5236 |
05 Feb 10 |
nicklas |
292 |
metadata.addFile("pdata", "pdata.txt"); |
5236 |
05 Feb 10 |
nicklas |
293 |
metadata.addFile("rdata", "rdata.txt"); |
5238 |
09 Feb 10 |
nicklas |
294 |
|
5238 |
09 Feb 10 |
nicklas |
// Extra files |
5238 |
09 Feb 10 |
nicklas |
296 |
ItemQuery<File> query = mergeDir.getFiles(); |
5238 |
09 Feb 10 |
nicklas |
297 |
query.restrict(Restrictions.like(Hql.property("name"), Expressions.string("x-%"))); |
5238 |
09 Feb 10 |
nicklas |
298 |
List<File> extraFiles = query.list(dc); |
5238 |
09 Feb 10 |
nicklas |
299 |
for (File f : extraFiles) |
5238 |
09 Feb 10 |
nicklas |
300 |
{ |
5238 |
09 Feb 10 |
nicklas |
301 |
metadata.addFile(f.getName(), f.getName()); |
5238 |
09 Feb 10 |
nicklas |
302 |
} |
5238 |
09 Feb 10 |
nicklas |
303 |
|
5236 |
05 Feb 10 |
nicklas |
304 |
Section sdata = metadata.addSection("sdata"); |
5236 |
05 Feb 10 |
nicklas |
305 |
sdata.addEntry("Ch 1", "float"); |
5236 |
05 Feb 10 |
nicklas |
306 |
sdata.addEntry("Ch 2", "float"); |
5236 |
05 Feb 10 |
nicklas |
307 |
Section settings = metadata.addSection("settings"); |
5236 |
05 Feb 10 |
nicklas |
308 |
settings.addEntry("new-data-cube", "1"); |
5236 |
05 Feb 10 |
nicklas |
309 |
settings.addEntry("multi-assay-parents", "1"); |
5236 |
05 Feb 10 |
nicklas |
310 |
MetadataWriter metadataWriter = MetadataWriter.create(metadataOut); |
5236 |
05 Feb 10 |
nicklas |
311 |
metadata.print(metadataWriter); |
5236 |
05 Feb 10 |
nicklas |
312 |
metadataWriter.close(); |
5236 |
05 Feb 10 |
nicklas |
313 |
|
5236 |
05 Feb 10 |
nicklas |
// The reporter annotations file is simply copied since we keep the positions |
5236 |
05 Feb 10 |
nicklas |
315 |
File reporterOut = File.getFile(dc, mergeDir, "rdata.txt", true); |
5236 |
05 Feb 10 |
nicklas |
316 |
dc.saveItem(reporterOut); |
5236 |
05 Feb 10 |
nicklas |
317 |
FileUtil.copy(reporterIn.getDownloadStream(0), reporterOut.getUploadStream(false)); |
5236 |
05 Feb 10 |
nicklas |
318 |
|
5236 |
05 Feb 10 |
nicklas |
// We create a new assay annotations file |
5236 |
05 Feb 10 |
nicklas |
320 |
File assaysOut = File.getFile(dc, mergeDir, "pdata.txt", true); |
5236 |
05 Feb 10 |
nicklas |
321 |
dc.saveItem(assaysOut); |
5236 |
05 Feb 10 |
nicklas |
322 |
AnnotationModel assayAnnotations = new AnnotationModel(); |
5236 |
05 Feb 10 |
nicklas |
323 |
AnnotationParser assayParser = AnnotationParser.create(assaysIn); |
5236 |
05 Feb 10 |
nicklas |
324 |
assayParser.parse(assayAnnotations); |
5236 |
05 Feb 10 |
nicklas |
325 |
AnnotationWriter assayWriter = AnnotationWriter.create(assaysOut); |
5236 |
05 Feb 10 |
nicklas |
326 |
assayWriter.bfsPrintHeaders("Parent ID", "Name"); |
5236 |
05 Feb 10 |
nicklas |
327 |
StringBuilder sb = new StringBuilder(); |
5236 |
05 Feb 10 |
nicklas |
328 |
for (int i = 0; i < assayAnnotations.getRowCount(); ++i) |
5236 |
05 Feb 10 |
nicklas |
329 |
{ |
5236 |
05 Feb 10 |
nicklas |
330 |
if (i > 0) sb.append(","); |
5236 |
05 Feb 10 |
nicklas |
331 |
sb.append(assayAnnotations.getRowId(i)); |
5236 |
05 Feb 10 |
nicklas |
332 |
} |
5236 |
05 Feb 10 |
nicklas |
333 |
assayWriter.bfsPrintData(1, sb.toString(), "Merged from " + sb.toString()); |
5236 |
05 Feb 10 |
nicklas |
334 |
assayWriter.close(); |
5236 |
05 Feb 10 |
nicklas |
335 |
|
5236 |
05 Feb 10 |
nicklas |
336 |
File ch1Out = File.getFile(dc, mergeDir, "Ch 1.txt", true); |
5236 |
05 Feb 10 |
nicklas |
337 |
dc.saveItem(ch1Out); |
5236 |
05 Feb 10 |
nicklas |
338 |
DataWriter ch1Writer = DataWriter.create(ch1Out); |
5236 |
05 Feb 10 |
nicklas |
339 |
DataParser ch1Parser = DataParser.create(ch1In); |
5237 |
08 Feb 10 |
nicklas |
340 |
ch1Parser.parse(new MergeAssaysEventHandler(ch1Writer)); |
5236 |
05 Feb 10 |
nicklas |
341 |
ch1Writer.close(); |
5236 |
05 Feb 10 |
nicklas |
342 |
|
5236 |
05 Feb 10 |
nicklas |
343 |
File ch2Out = File.getFile(dc, mergeDir, "Ch 2.txt", true); |
5236 |
05 Feb 10 |
nicklas |
344 |
dc.saveItem(ch2Out); |
5236 |
05 Feb 10 |
nicklas |
345 |
DataWriter ch2Writer = DataWriter.create(ch2Out); |
5236 |
05 Feb 10 |
nicklas |
346 |
DataParser ch2Parser = DataParser.create(ch2In); |
5237 |
08 Feb 10 |
nicklas |
347 |
ch2Parser.parse(new MergeAssaysEventHandler(ch2Writer)); |
5236 |
05 Feb 10 |
nicklas |
348 |
ch2Writer.close(); |
5236 |
05 Feb 10 |
nicklas |
349 |
|
5236 |
05 Feb 10 |
nicklas |
350 |
dc.commit(); |
5236 |
05 Feb 10 |
nicklas |
351 |
|
5236 |
05 Feb 10 |
nicklas |
352 |
write("--Merge assays OK"); |
5236 |
05 Feb 10 |
nicklas |
353 |
} |
5236 |
05 Feb 10 |
nicklas |
354 |
catch (Throwable ex) |
5236 |
05 Feb 10 |
nicklas |
355 |
{ |
5236 |
05 Feb 10 |
nicklas |
356 |
write("--Merge assays FAILED"); |
5236 |
05 Feb 10 |
nicklas |
357 |
ex.printStackTrace(); |
5236 |
05 Feb 10 |
nicklas |
358 |
ok = false; |
5236 |
05 Feb 10 |
nicklas |
359 |
} |
5236 |
05 Feb 10 |
nicklas |
360 |
finally |
5236 |
05 Feb 10 |
nicklas |
361 |
{ |
5236 |
05 Feb 10 |
nicklas |
362 |
if (dc != null) dc.close(); |
5236 |
05 Feb 10 |
nicklas |
363 |
} |
5236 |
05 Feb 10 |
nicklas |
364 |
return id; |
5236 |
05 Feb 10 |
nicklas |
365 |
} |
5236 |
05 Feb 10 |
nicklas |
366 |
|
5237 |
08 Feb 10 |
nicklas |
367 |
static int test_merge_reporters(int sourceDirId, int mergeDirId) |
5237 |
08 Feb 10 |
nicklas |
368 |
{ |
5237 |
08 Feb 10 |
nicklas |
369 |
DbControl dc = null; |
5237 |
08 Feb 10 |
nicklas |
370 |
if (sourceDirId == 0 || mergeDirId == 0) return 0; |
5237 |
08 Feb 10 |
nicklas |
371 |
int id = 0; |
5237 |
08 Feb 10 |
nicklas |
372 |
try |
5237 |
08 Feb 10 |
nicklas |
373 |
{ |
5237 |
08 Feb 10 |
nicklas |
374 |
dc = TestUtil.getDbControl(); |
5237 |
08 Feb 10 |
nicklas |
375 |
Directory sourceDir = Directory.getById(dc, sourceDirId); |
5237 |
08 Feb 10 |
nicklas |
376 |
Directory mergeDir = Directory.getById(dc, mergeDirId); |
5237 |
08 Feb 10 |
nicklas |
377 |
|
5237 |
08 Feb 10 |
nicklas |
378 |
File ch1In = File.getFile(dc, sourceDir, "Ch 1.txt", false); |
5237 |
08 Feb 10 |
nicklas |
379 |
File ch2In = File.getFile(dc, sourceDir, "Ch 2.txt", false); |
5237 |
08 Feb 10 |
nicklas |
380 |
File reporterIn = File.getFile(dc, sourceDir, "rdata.txt", false); |
5237 |
08 Feb 10 |
nicklas |
381 |
File assaysIn = File.getFile(dc, sourceDir, "pdata.txt", false); |
5237 |
08 Feb 10 |
nicklas |
382 |
|
5237 |
08 Feb 10 |
nicklas |
// Create the new metadata file |
5237 |
08 Feb 10 |
nicklas |
384 |
File metadataOut = File.getFile(dc, mergeDir, "metadata.txt", true); |
5237 |
08 Feb 10 |
nicklas |
385 |
dc.saveItem(metadataOut); |
5237 |
08 Feb 10 |
nicklas |
386 |
MetadataModel metadata = new MetadataModel(); |
5237 |
08 Feb 10 |
nicklas |
387 |
metadata.setSubtype("matrix"); |
5237 |
08 Feb 10 |
nicklas |
388 |
metadata.addFile("sdata1", "Ch 1.txt"); |
5237 |
08 Feb 10 |
nicklas |
389 |
metadata.addFile("sdata2", "Ch 2.txt"); |
5237 |
08 Feb 10 |
nicklas |
390 |
metadata.addFile("pdata", "pdata.txt"); |
5237 |
08 Feb 10 |
nicklas |
391 |
metadata.addFile("rdata", "rdata.txt"); |
5237 |
08 Feb 10 |
nicklas |
392 |
Section sdata = metadata.addSection("sdata"); |
5237 |
08 Feb 10 |
nicklas |
393 |
sdata.addEntry("Ch 1", "float"); |
5237 |
08 Feb 10 |
nicklas |
394 |
sdata.addEntry("Ch 2", "float"); |
5237 |
08 Feb 10 |
nicklas |
395 |
Section settings = metadata.addSection("settings"); |
5237 |
08 Feb 10 |
nicklas |
396 |
settings.addEntry("new-data-cube", "1"); |
5237 |
08 Feb 10 |
nicklas |
397 |
MetadataWriter metadataWriter = MetadataWriter.create(metadataOut); |
5237 |
08 Feb 10 |
nicklas |
398 |
metadata.print(metadataWriter); |
5237 |
08 Feb 10 |
nicklas |
399 |
metadataWriter.close(); |
5237 |
08 Feb 10 |
nicklas |
400 |
|
5237 |
08 Feb 10 |
nicklas |
// The assay annotations file is simply copied since we keep the parents |
5237 |
08 Feb 10 |
nicklas |
402 |
File assaysOut = File.getFile(dc, mergeDir, "pdata.txt", true); |
5237 |
08 Feb 10 |
nicklas |
403 |
dc.saveItem(assaysOut); |
5237 |
08 Feb 10 |
nicklas |
404 |
FileUtil.copy(assaysIn.getDownloadStream(0), assaysOut.getUploadStream(false)); |
5237 |
08 Feb 10 |
nicklas |
405 |
|
5237 |
08 Feb 10 |
nicklas |
// We create a new reporter annotations file |
5237 |
08 Feb 10 |
nicklas |
407 |
File reportersOut = File.getFile(dc, mergeDir, "rdata.txt", true); |
5237 |
08 Feb 10 |
nicklas |
408 |
dc.saveItem(reportersOut); |
5237 |
08 Feb 10 |
nicklas |
409 |
AnnotationModel reporterAnnotations = new AnnotationModel(); |
5237 |
08 Feb 10 |
nicklas |
410 |
AnnotationParser reporterParser = AnnotationParser.create(reporterIn); |
5237 |
08 Feb 10 |
nicklas |
411 |
reporterParser.parse(reporterAnnotations); |
5237 |
08 Feb 10 |
nicklas |
412 |
AnnotationWriter reporterWriter = AnnotationWriter.create(reportersOut); |
5237 |
08 Feb 10 |
nicklas |
413 |
reporterWriter.bfsPrintHeaders("External ID"); |
5237 |
08 Feb 10 |
nicklas |
414 |
int externalIdIndex = reporterAnnotations.getColumnIndex("External ID"); |
5237 |
08 Feb 10 |
nicklas |
415 |
for (int i = 0; i < reporterAnnotations.getRowCount(); i+=2) |
5237 |
08 Feb 10 |
nicklas |
416 |
{ |
5237 |
08 Feb 10 |
nicklas |
417 |
reporterWriter.bfsPrintData(1 + i / 2, reporterAnnotations.getData(i, externalIdIndex)); |
5237 |
08 Feb 10 |
nicklas |
418 |
} |
5237 |
08 Feb 10 |
nicklas |
419 |
reporterWriter.close(); |
5237 |
08 Feb 10 |
nicklas |
420 |
|
5237 |
08 Feb 10 |
nicklas |
421 |
File ch1Out = File.getFile(dc, mergeDir, "Ch 1.txt", true); |
5237 |
08 Feb 10 |
nicklas |
422 |
dc.saveItem(ch1Out); |
5237 |
08 Feb 10 |
nicklas |
423 |
DataWriter ch1Writer = DataWriter.create(ch1Out); |
5237 |
08 Feb 10 |
nicklas |
424 |
DataParser ch1Parser = DataParser.create(ch1In); |
5237 |
08 Feb 10 |
nicklas |
425 |
ch1Parser.parse(new MergeReportersEventHandler(ch1Writer)); |
5237 |
08 Feb 10 |
nicklas |
426 |
ch1Writer.close(); |
5237 |
08 Feb 10 |
nicklas |
427 |
|
5237 |
08 Feb 10 |
nicklas |
428 |
File ch2Out = File.getFile(dc, mergeDir, "Ch 2.txt", true); |
5237 |
08 Feb 10 |
nicklas |
429 |
dc.saveItem(ch2Out); |
5237 |
08 Feb 10 |
nicklas |
430 |
DataWriter ch2Writer = DataWriter.create(ch2Out); |
5237 |
08 Feb 10 |
nicklas |
431 |
DataParser ch2Parser = DataParser.create(ch2In); |
5237 |
08 Feb 10 |
nicklas |
432 |
ch2Parser.parse(new MergeReportersEventHandler(ch2Writer)); |
5237 |
08 Feb 10 |
nicklas |
433 |
ch2Writer.close(); |
5237 |
08 Feb 10 |
nicklas |
434 |
|
5237 |
08 Feb 10 |
nicklas |
435 |
dc.commit(); |
5237 |
08 Feb 10 |
nicklas |
436 |
|
5237 |
08 Feb 10 |
nicklas |
437 |
write("--Merge assays OK"); |
5237 |
08 Feb 10 |
nicklas |
438 |
} |
5237 |
08 Feb 10 |
nicklas |
439 |
catch (Throwable ex) |
5237 |
08 Feb 10 |
nicklas |
440 |
{ |
5237 |
08 Feb 10 |
nicklas |
441 |
write("--Merge assays FAILED"); |
5237 |
08 Feb 10 |
nicklas |
442 |
ex.printStackTrace(); |
5237 |
08 Feb 10 |
nicklas |
443 |
ok = false; |
5237 |
08 Feb 10 |
nicklas |
444 |
} |
5237 |
08 Feb 10 |
nicklas |
445 |
finally |
5237 |
08 Feb 10 |
nicklas |
446 |
{ |
5237 |
08 Feb 10 |
nicklas |
447 |
if (dc != null) dc.close(); |
5237 |
08 Feb 10 |
nicklas |
448 |
} |
5237 |
08 Feb 10 |
nicklas |
449 |
return id; |
5237 |
08 Feb 10 |
nicklas |
450 |
} |
5237 |
08 Feb 10 |
nicklas |
451 |
|
5233 |
04 Feb 10 |
nicklas |
452 |
static void write(String message) |
5233 |
04 Feb 10 |
nicklas |
453 |
{ |
5233 |
04 Feb 10 |
nicklas |
454 |
System.out.println(message); |
5233 |
04 Feb 10 |
nicklas |
455 |
} |
5233 |
04 Feb 10 |
nicklas |
456 |
|
5233 |
04 Feb 10 |
nicklas |
457 |
static File createFile(DbControl dc, Directory dir, String name) |
5233 |
04 Feb 10 |
nicklas |
458 |
{ |
5233 |
04 Feb 10 |
nicklas |
459 |
File f = File.getNew(dc, dir); |
5233 |
04 Feb 10 |
nicklas |
460 |
f.setName(name); |
5233 |
04 Feb 10 |
nicklas |
461 |
f.setCharacterSet("UTF-8"); |
5233 |
04 Feb 10 |
nicklas |
462 |
f.setMimeType("text/plain"); |
5233 |
04 Feb 10 |
nicklas |
463 |
dc.saveItem(f); |
5233 |
04 Feb 10 |
nicklas |
464 |
return f; |
5233 |
04 Feb 10 |
nicklas |
465 |
} |
5233 |
04 Feb 10 |
nicklas |
466 |
|
5238 |
09 Feb 10 |
nicklas |
467 |
static int test_upload_extra_file(String file, String name, int directoryId) |
5238 |
09 Feb 10 |
nicklas |
468 |
{ |
5238 |
09 Feb 10 |
nicklas |
469 |
if (directoryId == 0) return 0; |
5238 |
09 Feb 10 |
nicklas |
470 |
int id = 0; |
5238 |
09 Feb 10 |
nicklas |
471 |
DbControl dc = null; |
5238 |
09 Feb 10 |
nicklas |
472 |
try |
5238 |
09 Feb 10 |
nicklas |
473 |
{ |
5238 |
09 Feb 10 |
nicklas |
474 |
dc = TestUtil.getDbControl(); |
5238 |
09 Feb 10 |
nicklas |
475 |
Directory d = Directory.getById(dc, directoryId); |
5238 |
09 Feb 10 |
nicklas |
476 |
File f = File.getNew(dc, d); |
5238 |
09 Feb 10 |
nicklas |
477 |
f.setName(name); |
5238 |
09 Feb 10 |
nicklas |
478 |
f.setMimeTypeAuto(null, null); |
5238 |
09 Feb 10 |
nicklas |
479 |
dc.saveItem(f); |
5238 |
09 Feb 10 |
nicklas |
480 |
FileUtil.copy(FileUtil.getInputStream(new java.io.File(file)), f.getUploadStream(false)); |
5238 |
09 Feb 10 |
nicklas |
481 |
dc.commit(); |
5238 |
09 Feb 10 |
nicklas |
482 |
write("--Upload extra file '" + file + "' OK"); |
5238 |
09 Feb 10 |
nicklas |
483 |
} |
5238 |
09 Feb 10 |
nicklas |
484 |
catch (Throwable ex) |
5238 |
09 Feb 10 |
nicklas |
485 |
{ |
5238 |
09 Feb 10 |
nicklas |
486 |
write("--Upload extra file '" + file + "' FAILED"); |
5238 |
09 Feb 10 |
nicklas |
487 |
ex.printStackTrace(); |
5238 |
09 Feb 10 |
nicklas |
488 |
ok = false; |
5238 |
09 Feb 10 |
nicklas |
489 |
} |
5238 |
09 Feb 10 |
nicklas |
490 |
|
5238 |
09 Feb 10 |
nicklas |
491 |
finally |
5238 |
09 Feb 10 |
nicklas |
492 |
{ |
5238 |
09 Feb 10 |
nicklas |
493 |
if (dc != null) dc.close(); |
5238 |
09 Feb 10 |
nicklas |
494 |
} |
5238 |
09 Feb 10 |
nicklas |
495 |
return id; |
5238 |
09 Feb 10 |
nicklas |
496 |
|
5238 |
09 Feb 10 |
nicklas |
497 |
} |
5238 |
09 Feb 10 |
nicklas |
498 |
|
5319 |
20 Apr 10 |
nicklas |
499 |
static void test_annotate_assays(int bioassaySetId, int annotationTypeId, Object... values) |
5319 |
20 Apr 10 |
nicklas |
500 |
{ |
5319 |
20 Apr 10 |
nicklas |
501 |
if (bioassaySetId == 0 || annotationTypeId == 0) return; |
5319 |
20 Apr 10 |
nicklas |
502 |
int id = 0; |
5319 |
20 Apr 10 |
nicklas |
503 |
DbControl dc = null; |
5319 |
20 Apr 10 |
nicklas |
504 |
try |
5319 |
20 Apr 10 |
nicklas |
505 |
{ |
5319 |
20 Apr 10 |
nicklas |
506 |
dc = TestUtil.getDbControl(); |
5319 |
20 Apr 10 |
nicklas |
507 |
BioAssaySet bas = BioAssaySet.getById(dc, bioassaySetId); |
5319 |
20 Apr 10 |
nicklas |
508 |
AnnotationType at = AnnotationType.getById(dc, annotationTypeId); |
5319 |
20 Apr 10 |
nicklas |
509 |
|
5319 |
20 Apr 10 |
nicklas |
510 |
int i = 0; |
5319 |
20 Apr 10 |
nicklas |
511 |
int count = 0; |
5319 |
20 Apr 10 |
nicklas |
512 |
for (BioAssay ba : bas.getBioAssays().list(dc)) |
5319 |
20 Apr 10 |
nicklas |
513 |
{ |
5319 |
20 Apr 10 |
nicklas |
514 |
Object value = values[i]; |
7120 |
15 Apr 16 |
nicklas |
515 |
ba.getAnnotationSet().getAnnotation(at).setValueIfDifferent(value, null); |
5319 |
20 Apr 10 |
nicklas |
516 |
++i; |
5319 |
20 Apr 10 |
nicklas |
517 |
if (i >= values.length) i = 0; |
5319 |
20 Apr 10 |
nicklas |
518 |
count++; |
5319 |
20 Apr 10 |
nicklas |
519 |
} |
5319 |
20 Apr 10 |
nicklas |
520 |
|
5319 |
20 Apr 10 |
nicklas |
521 |
dc.commit(); |
5319 |
20 Apr 10 |
nicklas |
522 |
write("--Annotated " + count + " assays OK"); |
5319 |
20 Apr 10 |
nicklas |
523 |
} |
5319 |
20 Apr 10 |
nicklas |
524 |
catch (Throwable ex) |
5319 |
20 Apr 10 |
nicklas |
525 |
{ |
5319 |
20 Apr 10 |
nicklas |
526 |
write("--Annotated assays FAILED"); |
5319 |
20 Apr 10 |
nicklas |
527 |
ex.printStackTrace(); |
5319 |
20 Apr 10 |
nicklas |
528 |
ok = false; |
5319 |
20 Apr 10 |
nicklas |
529 |
} |
5319 |
20 Apr 10 |
nicklas |
530 |
|
5319 |
20 Apr 10 |
nicklas |
531 |
finally |
5319 |
20 Apr 10 |
nicklas |
532 |
{ |
5319 |
20 Apr 10 |
nicklas |
533 |
if (dc != null) dc.close(); |
5319 |
20 Apr 10 |
nicklas |
534 |
} |
5319 |
20 Apr 10 |
nicklas |
535 |
return; |
5319 |
20 Apr 10 |
nicklas |
536 |
} |
5319 |
20 Apr 10 |
nicklas |
537 |
|
5237 |
08 Feb 10 |
nicklas |
538 |
static class MergeAssaysEventHandler |
5236 |
05 Feb 10 |
nicklas |
539 |
implements EventHandler |
5236 |
05 Feb 10 |
nicklas |
540 |
{ |
5236 |
05 Feb 10 |
nicklas |
541 |
|
5236 |
05 Feb 10 |
nicklas |
542 |
private DataWriter dataWriter; |
5236 |
05 Feb 10 |
nicklas |
543 |
|
5237 |
08 Feb 10 |
nicklas |
544 |
MergeAssaysEventHandler(DataWriter dataWriter) |
5236 |
05 Feb 10 |
nicklas |
545 |
{ |
5236 |
05 Feb 10 |
nicklas |
546 |
this.dataWriter = dataWriter; |
5236 |
05 Feb 10 |
nicklas |
547 |
} |
5236 |
05 Feb 10 |
nicklas |
548 |
|
6875 |
20 Apr 15 |
nicklas |
549 |
@SuppressWarnings("rawtypes") |
5236 |
05 Feb 10 |
nicklas |
550 |
@Override |
5236 |
05 Feb 10 |
nicklas |
551 |
public void handleEvent(EventType eventType, Object eventData, |
5236 |
05 Feb 10 |
nicklas |
552 |
BfsParser parser) |
5236 |
05 Feb 10 |
nicklas |
553 |
{ |
5236 |
05 Feb 10 |
nicklas |
554 |
|
5236 |
05 Feb 10 |
nicklas |
555 |
if (eventType == DataParser.DATA_EVENT) |
5236 |
05 Feb 10 |
nicklas |
556 |
{ |
5236 |
05 Feb 10 |
nicklas |
557 |
String[] data = (String[])eventData; |
5236 |
05 Feb 10 |
nicklas |
558 |
double sum = 0.0; |
5236 |
05 Feb 10 |
nicklas |
559 |
for (int i = 0; i < data.length; ++i) |
5236 |
05 Feb 10 |
nicklas |
560 |
{ |
5236 |
05 Feb 10 |
nicklas |
561 |
sum += Values.getDouble(data[0], Double.NaN); |
5236 |
05 Feb 10 |
nicklas |
562 |
} |
5236 |
05 Feb 10 |
nicklas |
563 |
dataWriter.bfsPrintData(sum / data.length); |
5236 |
05 Feb 10 |
nicklas |
564 |
} |
5236 |
05 Feb 10 |
nicklas |
565 |
|
5236 |
05 Feb 10 |
nicklas |
566 |
} |
5237 |
08 Feb 10 |
nicklas |
567 |
} |
5236 |
05 Feb 10 |
nicklas |
568 |
|
5237 |
08 Feb 10 |
nicklas |
569 |
static class MergeReportersEventHandler |
5237 |
08 Feb 10 |
nicklas |
570 |
implements EventHandler |
5237 |
08 Feb 10 |
nicklas |
571 |
{ |
5236 |
05 Feb 10 |
nicklas |
572 |
|
5237 |
08 Feb 10 |
nicklas |
573 |
private DataWriter dataWriter; |
5237 |
08 Feb 10 |
nicklas |
574 |
private String[] line1; |
5237 |
08 Feb 10 |
nicklas |
575 |
|
5237 |
08 Feb 10 |
nicklas |
576 |
MergeReportersEventHandler(DataWriter dataWriter) |
5237 |
08 Feb 10 |
nicklas |
577 |
{ |
5237 |
08 Feb 10 |
nicklas |
578 |
this.dataWriter = dataWriter; |
5237 |
08 Feb 10 |
nicklas |
579 |
} |
5237 |
08 Feb 10 |
nicklas |
580 |
|
6875 |
20 Apr 15 |
nicklas |
581 |
@SuppressWarnings("rawtypes") |
5237 |
08 Feb 10 |
nicklas |
582 |
@Override |
5237 |
08 Feb 10 |
nicklas |
583 |
public void handleEvent(EventType eventType, Object eventData, |
5237 |
08 Feb 10 |
nicklas |
584 |
BfsParser parser) |
5237 |
08 Feb 10 |
nicklas |
585 |
{ |
5237 |
08 Feb 10 |
nicklas |
586 |
|
5237 |
08 Feb 10 |
nicklas |
587 |
if (eventType == DataParser.DATA_EVENT) |
5237 |
08 Feb 10 |
nicklas |
588 |
{ |
5237 |
08 Feb 10 |
nicklas |
589 |
String[] data = (String[])eventData; |
5237 |
08 Feb 10 |
nicklas |
590 |
if (line1 == null) |
5237 |
08 Feb 10 |
nicklas |
591 |
{ |
5237 |
08 Feb 10 |
nicklas |
592 |
line1 = data; |
5237 |
08 Feb 10 |
nicklas |
593 |
} |
5237 |
08 Feb 10 |
nicklas |
594 |
else |
5237 |
08 Feb 10 |
nicklas |
595 |
{ |
5237 |
08 Feb 10 |
nicklas |
596 |
Object[] newData = new Object[data.length]; |
5237 |
08 Feb 10 |
nicklas |
597 |
for (int i = 0; i < data.length; ++i) |
5237 |
08 Feb 10 |
nicklas |
598 |
{ |
5237 |
08 Feb 10 |
nicklas |
599 |
float sum = Values.getFloat(line1[i], Float.NaN) + Values.getFloat(data[i], Float.NaN); |
5237 |
08 Feb 10 |
nicklas |
600 |
newData[i] = sum / 2; |
5237 |
08 Feb 10 |
nicklas |
601 |
} |
5237 |
08 Feb 10 |
nicklas |
602 |
dataWriter.bfsPrintData(newData); |
5237 |
08 Feb 10 |
nicklas |
603 |
} |
5237 |
08 Feb 10 |
nicklas |
604 |
} |
5237 |
08 Feb 10 |
nicklas |
605 |
|
5237 |
08 Feb 10 |
nicklas |
606 |
} |
5237 |
08 Feb 10 |
nicklas |
607 |
|
5236 |
05 Feb 10 |
nicklas |
608 |
} |
5233 |
04 Feb 10 |
nicklas |
609 |
} |