4239 |
22 Apr 08 |
nicklas |
1 |
/* |
4239 |
22 Apr 08 |
nicklas |
$Id$ |
4239 |
22 Apr 08 |
nicklas |
3 |
|
4239 |
22 Apr 08 |
nicklas |
Copyright (C) 2008 Nicklas Nordborg |
4239 |
22 Apr 08 |
nicklas |
5 |
|
4239 |
22 Apr 08 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
4239 |
22 Apr 08 |
nicklas |
Available at http://base.thep.lu.se/ |
4239 |
22 Apr 08 |
nicklas |
8 |
|
4239 |
22 Apr 08 |
nicklas |
BASE is free software; you can redistribute it and/or |
4239 |
22 Apr 08 |
nicklas |
modify it under the terms of the GNU General Public License |
4480 |
05 Sep 08 |
jari |
as published by the Free Software Foundation; either version 3 |
4239 |
22 Apr 08 |
nicklas |
of the License, or (at your option) any later version. |
4239 |
22 Apr 08 |
nicklas |
13 |
|
4239 |
22 Apr 08 |
nicklas |
BASE is distributed in the hope that it will be useful, |
4239 |
22 Apr 08 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4239 |
22 Apr 08 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4239 |
22 Apr 08 |
nicklas |
GNU General Public License for more details. |
4239 |
22 Apr 08 |
nicklas |
18 |
|
4239 |
22 Apr 08 |
nicklas |
You should have received a copy of the GNU General Public License |
4514 |
11 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
4239 |
22 Apr 08 |
nicklas |
21 |
*/ |
4239 |
22 Apr 08 |
nicklas |
22 |
|
4239 |
22 Apr 08 |
nicklas |
23 |
import java.io.PrintWriter; |
4239 |
22 Apr 08 |
nicklas |
24 |
import java.util.Arrays; |
4239 |
22 Apr 08 |
nicklas |
25 |
|
4239 |
22 Apr 08 |
nicklas |
26 |
import org.apache.commons.io.output.NullOutputStream; |
4239 |
22 Apr 08 |
nicklas |
27 |
|
4239 |
22 Apr 08 |
nicklas |
28 |
import net.sf.basedb.core.ArrayDesign; |
4239 |
22 Apr 08 |
nicklas |
29 |
import net.sf.basedb.core.DbControl; |
4239 |
22 Apr 08 |
nicklas |
30 |
import net.sf.basedb.core.Platform; |
4239 |
22 Apr 08 |
nicklas |
31 |
import net.sf.basedb.core.ProgressReporter; |
4239 |
22 Apr 08 |
nicklas |
32 |
import net.sf.basedb.plugins.GalExporter; |
4239 |
22 Apr 08 |
nicklas |
33 |
import net.sf.basedb.util.ConsoleProgressReporter; |
4239 |
22 Apr 08 |
nicklas |
34 |
|
4239 |
22 Apr 08 |
nicklas |
35 |
/** |
4239 |
22 Apr 08 |
nicklas |
@base.modified $Date$ |
4239 |
22 Apr 08 |
nicklas |
@author Nicklas |
4239 |
22 Apr 08 |
nicklas |
@version 2.7 |
4239 |
22 Apr 08 |
nicklas |
39 |
*/ |
4239 |
22 Apr 08 |
nicklas |
40 |
public class TestGalExporter |
4239 |
22 Apr 08 |
nicklas |
41 |
{ |
4239 |
22 Apr 08 |
nicklas |
42 |
static boolean ok = true; |
4239 |
22 Apr 08 |
nicklas |
43 |
|
4239 |
22 Apr 08 |
nicklas |
44 |
public static void main(String[] args) |
4239 |
22 Apr 08 |
nicklas |
45 |
{ |
4239 |
22 Apr 08 |
nicklas |
46 |
TestUtil.checkArgs(args); |
4239 |
22 Apr 08 |
nicklas |
47 |
TestUtil.begin(); |
4239 |
22 Apr 08 |
nicklas |
48 |
test_all(); |
4239 |
22 Apr 08 |
nicklas |
49 |
TestUtil.stop(); |
4239 |
22 Apr 08 |
nicklas |
50 |
} |
4239 |
22 Apr 08 |
nicklas |
51 |
|
4239 |
22 Apr 08 |
nicklas |
52 |
static boolean test_all() |
4239 |
22 Apr 08 |
nicklas |
53 |
{ |
4239 |
22 Apr 08 |
nicklas |
54 |
write("++Testing GAL export"); |
4239 |
22 Apr 08 |
nicklas |
55 |
|
4239 |
22 Apr 08 |
nicklas |
// Import reporters |
4239 |
22 Apr 08 |
nicklas |
57 |
TestReporter.test_import_from_file("data/test.rawdata.import.txt", "\"Block\"\\t\"Column\"\\t\"Row\"\\t\"Name\"\\t\"ID\".*", "\\t", 4, 3); |
4239 |
22 Apr 08 |
nicklas |
58 |
|
4239 |
22 Apr 08 |
nicklas |
// Create ArrayDesign needed for print map import |
4239 |
22 Apr 08 |
nicklas |
60 |
int arrayDesignId = TestArrayDesign.test_create(Platform.GENERIC, false); |
4239 |
22 Apr 08 |
nicklas |
61 |
int plateGeometryId = TestPlateGeometry.test_create(16, 24, false); |
4239 |
22 Apr 08 |
nicklas |
62 |
int plateTypeId = TestPlateType.test_create(plateGeometryId, false); |
4239 |
22 Apr 08 |
nicklas |
63 |
int plate384 = TestPlate.test_create(plateTypeId, true); |
4239 |
22 Apr 08 |
nicklas |
64 |
int[] plates = new int[4]; |
4239 |
22 Apr 08 |
nicklas |
65 |
Arrays.fill(plates, plate384); |
4239 |
22 Apr 08 |
nicklas |
66 |
TestArrayDesign.test_add_plates(arrayDesignId, plates); |
4239 |
22 Apr 08 |
nicklas |
67 |
|
4239 |
22 Apr 08 |
nicklas |
// Print map import |
4239 |
22 Apr 08 |
nicklas |
69 |
int fileId = TestFile.test_create("data/test.parse.printmap.tam", false, false); |
4239 |
22 Apr 08 |
nicklas |
70 |
int printMapPluginDefinitionId = TestPluginDefinition.test_get("net.sf.basedb.plugins.PrintMapFlatFileImporter"); |
4239 |
22 Apr 08 |
nicklas |
71 |
int jobId = TestPrintMapFlatFileImporter.test_create_job_printmap(printMapPluginDefinitionId, fileId, arrayDesignId); |
5319 |
20 Apr 10 |
nicklas |
72 |
ok &= TestJob.test_execute(jobId, false); |
4239 |
22 Apr 08 |
nicklas |
73 |
|
4239 |
22 Apr 08 |
nicklas |
// Export as GAL |
4239 |
22 Apr 08 |
nicklas |
75 |
test_gal_export(arrayDesignId); |
4239 |
22 Apr 08 |
nicklas |
76 |
|
4239 |
22 Apr 08 |
nicklas |
77 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
4239 |
22 Apr 08 |
nicklas |
78 |
|
4257 |
29 Apr 08 |
nicklas |
79 |
TestArrayDesign.test_delete(arrayDesignId); |
4239 |
22 Apr 08 |
nicklas |
80 |
TestJob.test_delete(jobId); |
4239 |
22 Apr 08 |
nicklas |
81 |
TestPlate.test_delete(plate384); |
4239 |
22 Apr 08 |
nicklas |
82 |
TestPlateType.test_delete(plateTypeId); |
4239 |
22 Apr 08 |
nicklas |
83 |
TestPlateGeometry.test_delete(plateGeometryId); |
4239 |
22 Apr 08 |
nicklas |
84 |
TestReporter.test_delete(); |
4239 |
22 Apr 08 |
nicklas |
85 |
TestFile.test_delete(fileId); |
4239 |
22 Apr 08 |
nicklas |
86 |
|
4239 |
22 Apr 08 |
nicklas |
87 |
write("++Testing GAL export "+(ok ? "OK" : "Failed")+"\n"); |
4239 |
22 Apr 08 |
nicklas |
88 |
return ok; |
4239 |
22 Apr 08 |
nicklas |
89 |
} |
4239 |
22 Apr 08 |
nicklas |
90 |
|
4239 |
22 Apr 08 |
nicklas |
91 |
|
4239 |
22 Apr 08 |
nicklas |
92 |
private static void test_gal_export(int arrayDesignId) |
4239 |
22 Apr 08 |
nicklas |
93 |
{ |
4239 |
22 Apr 08 |
nicklas |
94 |
if (arrayDesignId == 0) return; |
4239 |
22 Apr 08 |
nicklas |
95 |
int id = 0; |
4239 |
22 Apr 08 |
nicklas |
96 |
DbControl dc = null; |
4239 |
22 Apr 08 |
nicklas |
97 |
try |
4239 |
22 Apr 08 |
nicklas |
98 |
{ |
4239 |
22 Apr 08 |
nicklas |
99 |
dc = TestUtil.getDbControl(); |
4239 |
22 Apr 08 |
nicklas |
100 |
|
4239 |
22 Apr 08 |
nicklas |
101 |
ProgressReporter progress = null; |
4239 |
22 Apr 08 |
nicklas |
102 |
PrintWriter writer = null; |
4239 |
22 Apr 08 |
nicklas |
103 |
if (!TestUtil.getSilent()) |
4239 |
22 Apr 08 |
nicklas |
104 |
{ |
4239 |
22 Apr 08 |
nicklas |
105 |
writer = new PrintWriter(System.out); |
4239 |
22 Apr 08 |
nicklas |
106 |
progress = new ConsoleProgressReporter(); |
4239 |
22 Apr 08 |
nicklas |
107 |
} |
4239 |
22 Apr 08 |
nicklas |
108 |
else |
4239 |
22 Apr 08 |
nicklas |
109 |
{ |
4239 |
22 Apr 08 |
nicklas |
110 |
writer = new PrintWriter(new NullOutputStream()); |
4239 |
22 Apr 08 |
nicklas |
111 |
} |
4239 |
22 Apr 08 |
nicklas |
112 |
ArrayDesign design = ArrayDesign.getById(dc, arrayDesignId); |
4239 |
22 Apr 08 |
nicklas |
113 |
GalExporter exporter = new GalExporter(); |
4348 |
18 Jun 08 |
nicklas |
114 |
exporter.exportGal(dc, design, null, writer, progress); |
4239 |
22 Apr 08 |
nicklas |
115 |
write("--GAL export OK"); |
4239 |
22 Apr 08 |
nicklas |
116 |
} |
4239 |
22 Apr 08 |
nicklas |
117 |
catch (Throwable ex) |
4239 |
22 Apr 08 |
nicklas |
118 |
{ |
4239 |
22 Apr 08 |
nicklas |
119 |
write("--GAL export FAILED"); |
4239 |
22 Apr 08 |
nicklas |
120 |
ex.printStackTrace(); |
4239 |
22 Apr 08 |
nicklas |
121 |
ok = false; |
4239 |
22 Apr 08 |
nicklas |
122 |
} |
4239 |
22 Apr 08 |
nicklas |
123 |
finally |
4239 |
22 Apr 08 |
nicklas |
124 |
{ |
4239 |
22 Apr 08 |
nicklas |
125 |
if (dc != null) dc.close(); |
4239 |
22 Apr 08 |
nicklas |
126 |
} |
4239 |
22 Apr 08 |
nicklas |
127 |
} |
4239 |
22 Apr 08 |
nicklas |
128 |
|
4239 |
22 Apr 08 |
nicklas |
129 |
static void write(String message) |
4239 |
22 Apr 08 |
nicklas |
130 |
{ |
4239 |
22 Apr 08 |
nicklas |
131 |
System.out.println(message); |
4239 |
22 Apr 08 |
nicklas |
132 |
} |
4239 |
22 Apr 08 |
nicklas |
133 |
|
4239 |
22 Apr 08 |
nicklas |
134 |
} |