1091 |
27 May 09 |
nicklas |
1 |
package net.sf.basedb.genepattern.plugin; |
1091 |
27 May 09 |
nicklas |
2 |
|
1091 |
27 May 09 |
nicklas |
3 |
import java.io.IOException; |
1091 |
27 May 09 |
nicklas |
4 |
import java.io.OutputStreamWriter; |
1091 |
27 May 09 |
nicklas |
5 |
import java.util.ArrayList; |
1091 |
27 May 09 |
nicklas |
6 |
import java.util.Arrays; |
1091 |
27 May 09 |
nicklas |
7 |
import java.util.Collections; |
1091 |
27 May 09 |
nicklas |
8 |
import java.util.List; |
1091 |
27 May 09 |
nicklas |
9 |
import java.util.Set; |
1091 |
27 May 09 |
nicklas |
10 |
|
1091 |
27 May 09 |
nicklas |
11 |
import net.sf.basedb.core.BaseException; |
1091 |
27 May 09 |
nicklas |
12 |
import net.sf.basedb.core.BioAssaySet; |
1091 |
27 May 09 |
nicklas |
13 |
import net.sf.basedb.core.BooleanParameterType; |
1091 |
27 May 09 |
nicklas |
14 |
import net.sf.basedb.core.Config; |
1091 |
27 May 09 |
nicklas |
15 |
import net.sf.basedb.core.DataFileType; |
1091 |
27 May 09 |
nicklas |
16 |
import net.sf.basedb.core.DbControl; |
1091 |
27 May 09 |
nicklas |
17 |
import net.sf.basedb.core.ExtendedProperties; |
1091 |
27 May 09 |
nicklas |
18 |
import net.sf.basedb.core.ExtendedProperty; |
1091 |
27 May 09 |
nicklas |
19 |
import net.sf.basedb.core.File; |
1091 |
27 May 09 |
nicklas |
20 |
import net.sf.basedb.core.FileSetMember; |
1091 |
27 May 09 |
nicklas |
21 |
import net.sf.basedb.core.FileStoreUtil; |
1091 |
27 May 09 |
nicklas |
22 |
import net.sf.basedb.core.FileType; |
1091 |
27 May 09 |
nicklas |
23 |
import net.sf.basedb.core.Item; |
1091 |
27 May 09 |
nicklas |
24 |
import net.sf.basedb.core.ItemNotFoundException; |
1091 |
27 May 09 |
nicklas |
25 |
import net.sf.basedb.core.ItemParameterType; |
1091 |
27 May 09 |
nicklas |
26 |
import net.sf.basedb.core.Job; |
1091 |
27 May 09 |
nicklas |
27 |
import net.sf.basedb.core.Path; |
1091 |
27 May 09 |
nicklas |
28 |
import net.sf.basedb.core.Permission; |
1091 |
27 May 09 |
nicklas |
29 |
import net.sf.basedb.core.PluginDefinition; |
1091 |
27 May 09 |
nicklas |
30 |
import net.sf.basedb.core.PluginParameter; |
1091 |
27 May 09 |
nicklas |
31 |
import net.sf.basedb.core.ProgressReporter; |
1091 |
27 May 09 |
nicklas |
32 |
import net.sf.basedb.core.RequestInformation; |
1091 |
27 May 09 |
nicklas |
33 |
import net.sf.basedb.core.StringParameterType; |
1091 |
27 May 09 |
nicklas |
34 |
import net.sf.basedb.core.SystemItems; |
1091 |
27 May 09 |
nicklas |
35 |
import net.sf.basedb.core.plugin.About; |
1091 |
27 May 09 |
nicklas |
36 |
import net.sf.basedb.core.plugin.AboutImpl; |
1091 |
27 May 09 |
nicklas |
37 |
import net.sf.basedb.core.plugin.AbstractExporterPlugin; |
1091 |
27 May 09 |
nicklas |
38 |
import net.sf.basedb.core.plugin.ExportOutputStream; |
1091 |
27 May 09 |
nicklas |
39 |
import net.sf.basedb.core.plugin.GuiContext; |
1091 |
27 May 09 |
nicklas |
40 |
import net.sf.basedb.core.plugin.InteractivePlugin; |
1091 |
27 May 09 |
nicklas |
41 |
import net.sf.basedb.core.plugin.Request; |
1091 |
27 May 09 |
nicklas |
42 |
import net.sf.basedb.core.plugin.Response; |
1091 |
27 May 09 |
nicklas |
43 |
import net.sf.basedb.core.signal.SignalHandler; |
1091 |
27 May 09 |
nicklas |
44 |
import net.sf.basedb.core.signal.SignalTarget; |
1091 |
27 May 09 |
nicklas |
45 |
import net.sf.basedb.core.signal.ThreadSignalHandler; |
1091 |
27 May 09 |
nicklas |
46 |
import net.sf.basedb.genepattern.GenePattern; |
1091 |
27 May 09 |
nicklas |
47 |
import net.sf.basedb.genepattern.export.GctExporter; |
1091 |
27 May 09 |
nicklas |
48 |
import net.sf.basedb.plugins.util.Parameters; |
1091 |
27 May 09 |
nicklas |
49 |
import net.sf.basedb.util.Enumeration; |
1091 |
27 May 09 |
nicklas |
50 |
import net.sf.basedb.util.export.TableWriter; |
1091 |
27 May 09 |
nicklas |
51 |
import net.sf.basedb.util.export.spotdata.ExportableFieldFactory; |
1091 |
27 May 09 |
nicklas |
52 |
|
1091 |
27 May 09 |
nicklas |
53 |
/** |
1091 |
27 May 09 |
nicklas |
Plug-in for exporting data to GenePattern GCT format. |
1091 |
27 May 09 |
nicklas |
55 |
|
1091 |
27 May 09 |
nicklas |
@author Nicklas |
1091 |
27 May 09 |
nicklas |
@since 1.0 |
1091 |
27 May 09 |
nicklas |
58 |
*/ |
1091 |
27 May 09 |
nicklas |
59 |
public class GctExporterPlugin |
1091 |
27 May 09 |
nicklas |
60 |
extends AbstractExporterPlugin |
1091 |
27 May 09 |
nicklas |
61 |
implements InteractivePlugin, SignalTarget |
1091 |
27 May 09 |
nicklas |
62 |
{ |
1091 |
27 May 09 |
nicklas |
63 |
|
1091 |
27 May 09 |
nicklas |
64 |
private ThreadSignalHandler signalHandler; |
1091 |
27 May 09 |
nicklas |
65 |
private RequestInformation configureJob; |
1091 |
27 May 09 |
nicklas |
66 |
|
1091 |
27 May 09 |
nicklas |
67 |
public GctExporterPlugin() |
1091 |
27 May 09 |
nicklas |
68 |
{} |
1091 |
27 May 09 |
nicklas |
69 |
|
1091 |
27 May 09 |
nicklas |
70 |
/* |
1091 |
27 May 09 |
nicklas |
From the Plugin interface |
1091 |
27 May 09 |
nicklas |
72 |
------------------------------------------- |
1091 |
27 May 09 |
nicklas |
73 |
*/ |
1091 |
27 May 09 |
nicklas |
74 |
@Override |
1091 |
27 May 09 |
nicklas |
75 |
public About getAbout() |
1091 |
27 May 09 |
nicklas |
76 |
{ |
1091 |
27 May 09 |
nicklas |
77 |
return new AboutImpl( |
1091 |
27 May 09 |
nicklas |
78 |
"GenePattern GCT exporter", |
1091 |
27 May 09 |
nicklas |
79 |
"Exports bioassay set data to GenePattern GCT format. The " + |
1091 |
27 May 09 |
nicklas |
80 |
"resulting file can be used in GenePattern for further analysis.", |
1091 |
27 May 09 |
nicklas |
81 |
GenePattern.VERSION, |
1091 |
27 May 09 |
nicklas |
82 |
GenePattern.COPYRIGHT, |
1091 |
27 May 09 |
nicklas |
83 |
null, |
1091 |
27 May 09 |
nicklas |
84 |
GenePattern.EMAIL, |
1091 |
27 May 09 |
nicklas |
85 |
GenePattern.URL |
1091 |
27 May 09 |
nicklas |
86 |
); |
1091 |
27 May 09 |
nicklas |
87 |
} |
1091 |
27 May 09 |
nicklas |
88 |
@Override |
1091 |
27 May 09 |
nicklas |
89 |
public boolean supportsConfigurations() |
1091 |
27 May 09 |
nicklas |
90 |
{ |
1091 |
27 May 09 |
nicklas |
91 |
return false; |
1091 |
27 May 09 |
nicklas |
92 |
} |
1091 |
27 May 09 |
nicklas |
93 |
@Override |
1091 |
27 May 09 |
nicklas |
94 |
public boolean requiresConfiguration() |
1091 |
27 May 09 |
nicklas |
95 |
{ |
1091 |
27 May 09 |
nicklas |
96 |
return false; |
1091 |
27 May 09 |
nicklas |
97 |
} |
1091 |
27 May 09 |
nicklas |
98 |
// ----------------------------------------------- |
1091 |
27 May 09 |
nicklas |
99 |
/* |
1091 |
27 May 09 |
nicklas |
From the InteractivePlugin interface |
1091 |
27 May 09 |
nicklas |
101 |
------------------------------------------- |
1091 |
27 May 09 |
nicklas |
102 |
*/ |
1091 |
27 May 09 |
nicklas |
103 |
@Override |
1091 |
27 May 09 |
nicklas |
104 |
public Set<GuiContext> getGuiContexts() |
1091 |
27 May 09 |
nicklas |
105 |
{ |
1091 |
27 May 09 |
nicklas |
106 |
return Collections.singleton(GuiContext.item(Item.BIOASSAYSET)); |
1091 |
27 May 09 |
nicklas |
107 |
} |
1091 |
27 May 09 |
nicklas |
108 |
@Override |
1091 |
27 May 09 |
nicklas |
109 |
public String isInContext(GuiContext context, Object item) |
1091 |
27 May 09 |
nicklas |
110 |
{ |
1091 |
27 May 09 |
nicklas |
111 |
String message = null; |
1091 |
27 May 09 |
nicklas |
112 |
if (item == null) |
1091 |
27 May 09 |
nicklas |
113 |
{ |
1091 |
27 May 09 |
nicklas |
114 |
message = "The object is null"; |
1091 |
27 May 09 |
nicklas |
115 |
} |
1091 |
27 May 09 |
nicklas |
116 |
else if (!(item instanceof BioAssaySet)) |
1091 |
27 May 09 |
nicklas |
117 |
{ |
1091 |
27 May 09 |
nicklas |
118 |
message = "The object is not a BioAssaySet: " + item; |
1091 |
27 May 09 |
nicklas |
119 |
} |
1091 |
27 May 09 |
nicklas |
120 |
else |
1091 |
27 May 09 |
nicklas |
121 |
{ |
1091 |
27 May 09 |
nicklas |
122 |
BioAssaySet bas = (BioAssaySet)item; |
1091 |
27 May 09 |
nicklas |
123 |
if (bas.getNumSpots() <= 0) |
1091 |
27 May 09 |
nicklas |
124 |
{ |
1091 |
27 May 09 |
nicklas |
125 |
message = "This plug-in requires spot data in the database"; |
1091 |
27 May 09 |
nicklas |
126 |
} |
1091 |
27 May 09 |
nicklas |
127 |
} |
1091 |
27 May 09 |
nicklas |
128 |
return message; |
1091 |
27 May 09 |
nicklas |
129 |
} |
1091 |
27 May 09 |
nicklas |
130 |
|
1091 |
27 May 09 |
nicklas |
131 |
@Override |
1091 |
27 May 09 |
nicklas |
132 |
public RequestInformation getRequestInformation(GuiContext context, String command) |
1091 |
27 May 09 |
nicklas |
133 |
throws BaseException |
1091 |
27 May 09 |
nicklas |
134 |
{ |
1091 |
27 May 09 |
nicklas |
135 |
RequestInformation requestInformation = null; |
1091 |
27 May 09 |
nicklas |
136 |
if (command.equals(Request.COMMAND_CONFIGURE_JOB)) |
1091 |
27 May 09 |
nicklas |
137 |
{ |
1091 |
27 May 09 |
nicklas |
138 |
requestInformation = getConfigureJobParameters(context, null); |
1091 |
27 May 09 |
nicklas |
139 |
} |
1091 |
27 May 09 |
nicklas |
140 |
return requestInformation; |
1091 |
27 May 09 |
nicklas |
141 |
} |
1091 |
27 May 09 |
nicklas |
142 |
|
1091 |
27 May 09 |
nicklas |
143 |
@Override |
1091 |
27 May 09 |
nicklas |
144 |
public void configure(GuiContext context, Request request, Response response) |
1091 |
27 May 09 |
nicklas |
145 |
{ |
1091 |
27 May 09 |
nicklas |
146 |
try |
1091 |
27 May 09 |
nicklas |
147 |
{ |
1091 |
27 May 09 |
nicklas |
148 |
String command = request.getCommand(); |
1091 |
27 May 09 |
nicklas |
149 |
if (command.equals(Request.COMMAND_CONFIGURE_JOB)) |
1091 |
27 May 09 |
nicklas |
150 |
{ |
1091 |
27 May 09 |
nicklas |
151 |
RequestInformation ri = getConfigureJobParameters(context, !request.isAllowedImmediateExecution()); |
1091 |
27 May 09 |
nicklas |
152 |
List<Throwable> errors = validateRequestParameters(ri.getParameters(), request); |
1091 |
27 May 09 |
nicklas |
153 |
if (errors != null) |
1091 |
27 May 09 |
nicklas |
154 |
{ |
1091 |
27 May 09 |
nicklas |
155 |
response.setError(errors.size()+" invalid parameter(s) were found " + |
1091 |
27 May 09 |
nicklas |
156 |
"in the request", errors); |
1091 |
27 May 09 |
nicklas |
157 |
return; |
1091 |
27 May 09 |
nicklas |
158 |
} |
1091 |
27 May 09 |
nicklas |
159 |
String fileName = (String)request.getParameterValue(SAVE_AS); |
1091 |
27 May 09 |
nicklas |
160 |
if (fileName == null) |
1091 |
27 May 09 |
nicklas |
161 |
{ |
1091 |
27 May 09 |
nicklas |
162 |
if (!request.isAllowedImmediateExecution()) |
1091 |
27 May 09 |
nicklas |
163 |
{ |
1091 |
27 May 09 |
nicklas |
164 |
response.setError("Immediate download is not allowed. Please specify a filename", null); |
1091 |
27 May 09 |
nicklas |
165 |
return; |
1091 |
27 May 09 |
nicklas |
166 |
} |
1091 |
27 May 09 |
nicklas |
167 |
} |
1091 |
27 May 09 |
nicklas |
168 |
else |
1091 |
27 May 09 |
nicklas |
169 |
{ |
1091 |
27 May 09 |
nicklas |
170 |
boolean overwrite = Boolean.TRUE.equals(request.getParameterValue(OVERWRITE)); |
1091 |
27 May 09 |
nicklas |
171 |
if (!pathCanBeUsed(fileName, overwrite)) |
1091 |
27 May 09 |
nicklas |
172 |
{ |
1091 |
27 May 09 |
nicklas |
173 |
response.setError("File exists: " + fileName + |
1091 |
27 May 09 |
nicklas |
174 |
"; Please select a different file name.", null); |
1091 |
27 May 09 |
nicklas |
175 |
return; |
1091 |
27 May 09 |
nicklas |
176 |
} |
1091 |
27 May 09 |
nicklas |
177 |
} |
1091 |
27 May 09 |
nicklas |
178 |
|
1091 |
27 May 09 |
nicklas |
// Source and file options |
1091 |
27 May 09 |
nicklas |
180 |
storeValue(job, request, ri.getParameter("source")); |
1091 |
27 May 09 |
nicklas |
181 |
storeValue(job, request, ri.getParameter("descriptionProperty")); |
1091 |
27 May 09 |
nicklas |
182 |
storeValue(job, request, ri.getParameter(SAVE_AS)); |
1091 |
27 May 09 |
nicklas |
183 |
storeValue(job, request, ri.getParameter(Parameters.CHARSET_PARAMETER)); |
1091 |
27 May 09 |
nicklas |
184 |
storeValue(job, request, ri.getParameter(OVERWRITE)); |
1091 |
27 May 09 |
nicklas |
185 |
storeValue(job, request, ri.getParameter("attachToBioAssaySet")); |
1091 |
27 May 09 |
nicklas |
186 |
|
1091 |
27 May 09 |
nicklas |
187 |
if (job.getValue(SAVE_AS) == null) |
1091 |
27 May 09 |
nicklas |
188 |
{ |
1091 |
27 May 09 |
nicklas |
// No filename --> immediate download |
1091 |
27 May 09 |
nicklas |
190 |
BioAssaySet source = (BioAssaySet)request.getParameterValue("source"); |
1091 |
27 May 09 |
nicklas |
191 |
response.setDownloadImmediately("Export bioassay set " + |
1091 |
27 May 09 |
nicklas |
192 |
source.getName(), Job.ExecutionTime.SHORT, true); |
1091 |
27 May 09 |
nicklas |
193 |
} |
1091 |
27 May 09 |
nicklas |
194 |
else |
1091 |
27 May 09 |
nicklas |
195 |
{ |
1091 |
27 May 09 |
nicklas |
196 |
response.setDone("Job configuration complete", Job.ExecutionTime.SHORT); |
1091 |
27 May 09 |
nicklas |
197 |
} |
1091 |
27 May 09 |
nicklas |
198 |
} |
1091 |
27 May 09 |
nicklas |
199 |
} |
1091 |
27 May 09 |
nicklas |
200 |
catch (Throwable ex) |
1091 |
27 May 09 |
nicklas |
201 |
{ |
1091 |
27 May 09 |
nicklas |
202 |
response.setError(ex.getMessage(), Arrays.asList(ex)); |
1091 |
27 May 09 |
nicklas |
203 |
} |
1091 |
27 May 09 |
nicklas |
204 |
} |
1091 |
27 May 09 |
nicklas |
205 |
// -------------------------------------------- |
1091 |
27 May 09 |
nicklas |
206 |
/* |
1091 |
27 May 09 |
nicklas |
From the SignalTarget interface |
1091 |
27 May 09 |
nicklas |
208 |
------------------------------------------- |
1091 |
27 May 09 |
nicklas |
209 |
*/ |
1091 |
27 May 09 |
nicklas |
210 |
@Override |
1091 |
27 May 09 |
nicklas |
211 |
public SignalHandler getSignalHandler() |
1091 |
27 May 09 |
nicklas |
212 |
{ |
1091 |
27 May 09 |
nicklas |
213 |
signalHandler = new ThreadSignalHandler(); |
1091 |
27 May 09 |
nicklas |
214 |
return signalHandler; |
1091 |
27 May 09 |
nicklas |
215 |
} |
1091 |
27 May 09 |
nicklas |
216 |
// ------------------------------------------- |
1091 |
27 May 09 |
nicklas |
217 |
/* |
1091 |
27 May 09 |
nicklas |
From AbstractExporterPlugin |
1091 |
27 May 09 |
nicklas |
219 |
------------------------------------------. |
1091 |
27 May 09 |
nicklas |
220 |
*/ |
1091 |
27 May 09 |
nicklas |
221 |
private DbControl dc; |
1091 |
27 May 09 |
nicklas |
222 |
private BioAssaySet bas; |
1091 |
27 May 09 |
nicklas |
223 |
|
1091 |
27 May 09 |
nicklas |
224 |
@Override |
1091 |
27 May 09 |
nicklas |
225 |
protected void begin(DbControl dc) |
1091 |
27 May 09 |
nicklas |
226 |
{ |
1091 |
27 May 09 |
nicklas |
227 |
super.begin(dc); |
1091 |
27 May 09 |
nicklas |
228 |
this.dc = dc; |
1091 |
27 May 09 |
nicklas |
229 |
bas = (BioAssaySet)job.getValue("source"); |
1091 |
27 May 09 |
nicklas |
230 |
} |
1091 |
27 May 09 |
nicklas |
231 |
|
1091 |
27 May 09 |
nicklas |
232 |
@Override |
1091 |
27 May 09 |
nicklas |
233 |
protected void performExport(ExportOutputStream out, ProgressReporter progress) |
1091 |
27 May 09 |
nicklas |
234 |
throws IOException |
1091 |
27 May 09 |
nicklas |
235 |
{ |
1091 |
27 May 09 |
nicklas |
236 |
if (signalHandler != null) signalHandler.setWorkerThread(null); |
1091 |
27 May 09 |
nicklas |
237 |
|
1091 |
27 May 09 |
nicklas |
// Get job configuration parameters |
1091 |
27 May 09 |
nicklas |
239 |
BioAssaySet source = (BioAssaySet)job.getValue("source"); |
1091 |
27 May 09 |
nicklas |
240 |
source = BioAssaySet.getById(dc, source.getId()); |
1091 |
27 May 09 |
nicklas |
241 |
boolean attachToBioAssaySet = Boolean.TRUE.equals(job.getValue("attachToBioAssaySet")); |
1091 |
27 May 09 |
nicklas |
242 |
String characterSet = (String)job.getValue(Parameters.CHARSET_PARAMETER); |
1091 |
27 May 09 |
nicklas |
243 |
if (characterSet == null) characterSet = Config.getCharset(); |
1091 |
27 May 09 |
nicklas |
244 |
String description = (String)job.getValue("descriptionProperty"); |
1091 |
27 May 09 |
nicklas |
245 |
|
1091 |
27 May 09 |
nicklas |
246 |
if (progress != null) progress.display(0, "Exporting ..."); |
1091 |
27 May 09 |
nicklas |
247 |
|
1091 |
27 May 09 |
nicklas |
// Make settings on the exported file |
1091 |
27 May 09 |
nicklas |
249 |
out.setMimeType("text/plain"); |
1091 |
27 May 09 |
nicklas |
250 |
String filename = source.getName() + "-" + source.getId() + ".gct"; |
1091 |
27 May 09 |
nicklas |
251 |
out.setFilename(Path.makeSafeFilename(filename, "")); |
1091 |
27 May 09 |
nicklas |
252 |
out.setCharacterSet(characterSet); |
1091 |
27 May 09 |
nicklas |
253 |
File exportFile = out.getFile(); |
1091 |
27 May 09 |
nicklas |
254 |
|
1091 |
27 May 09 |
nicklas |
// Prepare for export |
1091 |
27 May 09 |
nicklas |
256 |
GctExporter exporter = new GctExporter(); |
1091 |
27 May 09 |
nicklas |
257 |
|
1091 |
27 May 09 |
nicklas |
258 |
exporter.setDbControl(dc); |
1091 |
27 May 09 |
nicklas |
259 |
exporter.setProgressReporter(progress); |
1091 |
27 May 09 |
nicklas |
260 |
exporter.setSource(source); |
1091 |
27 May 09 |
nicklas |
261 |
if (description != null) |
1091 |
27 May 09 |
nicklas |
262 |
{ |
1091 |
27 May 09 |
nicklas |
263 |
exporter.setDescriptionField(ExportableFieldFactory.reporter(description, "Description", null, null)); |
1091 |
27 May 09 |
nicklas |
264 |
} |
1091 |
27 May 09 |
nicklas |
265 |
exporter.setWriter(new TableWriter(new OutputStreamWriter(out, characterSet))); |
1091 |
27 May 09 |
nicklas |
266 |
exporter.doExport(); |
1091 |
27 May 09 |
nicklas |
267 |
|
1091 |
27 May 09 |
nicklas |
268 |
if (attachToBioAssaySet && exportFile != null) |
1091 |
27 May 09 |
nicklas |
269 |
{ |
1091 |
27 May 09 |
nicklas |
270 |
FileSetMember file = FileStoreUtil.setDataFile(dc, source, GenePattern.GCT_FILE, exportFile); |
1091 |
27 May 09 |
nicklas |
271 |
file.setValid(true, null); |
1091 |
27 May 09 |
nicklas |
272 |
} |
1091 |
27 May 09 |
nicklas |
273 |
} |
1091 |
27 May 09 |
nicklas |
274 |
|
1091 |
27 May 09 |
nicklas |
275 |
@Override |
1091 |
27 May 09 |
nicklas |
276 |
protected void end(boolean success) |
1091 |
27 May 09 |
nicklas |
277 |
{ |
1091 |
27 May 09 |
nicklas |
278 |
this.dc = null; |
1091 |
27 May 09 |
nicklas |
279 |
} |
1091 |
27 May 09 |
nicklas |
280 |
|
1091 |
27 May 09 |
nicklas |
281 |
@Override |
1091 |
27 May 09 |
nicklas |
282 |
protected String getSuccessMessage() |
1091 |
27 May 09 |
nicklas |
283 |
{ |
1091 |
27 May 09 |
nicklas |
284 |
return "Bioassay set '" + bas.getName() + |
1091 |
27 May 09 |
nicklas |
285 |
"' exported successfully to GenePattern GCT format"; |
1091 |
27 May 09 |
nicklas |
286 |
} |
1091 |
27 May 09 |
nicklas |
287 |
// ------------------------------------------- |
1091 |
27 May 09 |
nicklas |
288 |
|
1091 |
27 May 09 |
nicklas |
289 |
private RequestInformation getConfigureJobParameters(GuiContext context, Boolean requireFile) |
1091 |
27 May 09 |
nicklas |
290 |
{ |
1091 |
27 May 09 |
nicklas |
291 |
if (configureJob != null) return configureJob; |
1091 |
27 May 09 |
nicklas |
292 |
|
1091 |
27 May 09 |
nicklas |
293 |
DbControl dc = null; |
1091 |
27 May 09 |
nicklas |
294 |
try |
1091 |
27 May 09 |
nicklas |
295 |
{ |
1091 |
27 May 09 |
nicklas |
296 |
dc = sc.newDbControl(); |
1091 |
27 May 09 |
nicklas |
297 |
int currentBioAssaySetId = sc.getCurrentContext(Item.BIOASSAYSET).getId(); |
1091 |
27 May 09 |
nicklas |
298 |
BioAssaySet source = BioAssaySet.getById(dc, currentBioAssaySetId); |
1091 |
27 May 09 |
nicklas |
299 |
|
1091 |
27 May 09 |
nicklas |
// Generate a default path if a file is required |
1091 |
27 May 09 |
nicklas |
301 |
String defaultPath = null; |
1091 |
27 May 09 |
nicklas |
302 |
if (requireFile == null) |
1091 |
27 May 09 |
nicklas |
303 |
{ |
1091 |
27 May 09 |
nicklas |
304 |
PluginDefinition pd = job.getPluginDefinition(); |
1091 |
27 May 09 |
nicklas |
305 |
requireFile = pd == null ? false : !pd.getAllowImmediateExecution(); |
1091 |
27 May 09 |
nicklas |
306 |
} |
1091 |
27 May 09 |
nicklas |
307 |
if (requireFile) |
1091 |
27 May 09 |
nicklas |
308 |
{ |
1091 |
27 May 09 |
nicklas |
309 |
defaultPath = "~/" + Path.makeSafeFilename( |
1091 |
27 May 09 |
nicklas |
310 |
source.getName() + "-" + source.getId(), "").toLowerCase() + "tdms.txt"; |
1091 |
27 May 09 |
nicklas |
311 |
} |
1091 |
27 May 09 |
nicklas |
312 |
|
1091 |
27 May 09 |
nicklas |
313 |
List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>(); |
1091 |
27 May 09 |
nicklas |
314 |
|
1091 |
27 May 09 |
nicklas |
// Source bioassay set parameter |
1091 |
27 May 09 |
nicklas |
316 |
parameters.add(new PluginParameter<BioAssaySet>( |
1091 |
27 May 09 |
nicklas |
317 |
"source", |
1091 |
27 May 09 |
nicklas |
318 |
"Bioassay set", |
1091 |
27 May 09 |
nicklas |
319 |
"The bioassay set to export", |
1091 |
27 May 09 |
nicklas |
320 |
new ItemParameterType<BioAssaySet>(BioAssaySet.class, source, true, 1, null) |
1091 |
27 May 09 |
nicklas |
321 |
)); |
1091 |
27 May 09 |
nicklas |
322 |
|
1091 |
27 May 09 |
nicklas |
323 |
Enumeration<String, String> reporterProperties = new Enumeration<String, String>(); |
1091 |
27 May 09 |
nicklas |
324 |
reporterProperties.add("name", "Name"); |
1091 |
27 May 09 |
nicklas |
325 |
reporterProperties.add("symbol", "Gene symbol"); |
1091 |
27 May 09 |
nicklas |
326 |
reporterProperties.add("description", "Description"); |
1091 |
27 May 09 |
nicklas |
327 |
for (ExtendedProperty ep : ExtendedProperties.getProperties("ReporterData")) |
1091 |
27 May 09 |
nicklas |
328 |
{ |
1091 |
27 May 09 |
nicklas |
329 |
String name = ep.getName(); |
1091 |
27 May 09 |
nicklas |
330 |
reporterProperties.add(name, ep.getTitle()); |
1091 |
27 May 09 |
nicklas |
331 |
} |
1091 |
27 May 09 |
nicklas |
332 |
|
1091 |
27 May 09 |
nicklas |
333 |
StringParameterType columnParameterType = new StringParameterType( |
1091 |
27 May 09 |
nicklas |
334 |
255, null, false, 1, 0, 0, reporterProperties); |
1091 |
27 May 09 |
nicklas |
335 |
parameters.add(new PluginParameter<String>( |
1091 |
27 May 09 |
nicklas |
336 |
"descriptionProperty", |
1091 |
27 May 09 |
nicklas |
337 |
"Description", |
1091 |
27 May 09 |
nicklas |
338 |
"Select the reporter annotation that you want to use as a " + |
1091 |
27 May 09 |
nicklas |
339 |
"description, or leave it empty if you don't need it.", |
1091 |
27 May 09 |
nicklas |
340 |
"description", |
1091 |
27 May 09 |
nicklas |
341 |
columnParameterType |
1091 |
27 May 09 |
nicklas |
342 |
)); |
1091 |
27 May 09 |
nicklas |
343 |
|
1091 |
27 May 09 |
nicklas |
344 |
|
1091 |
27 May 09 |
nicklas |
// Save to file options |
1091 |
27 May 09 |
nicklas |
346 |
parameters.add(getSaveAsParameter(null, null, defaultPath, requireFile)); |
1091 |
27 May 09 |
nicklas |
347 |
parameters.add(Parameters.charsetParameter( |
1091 |
27 May 09 |
nicklas |
348 |
"Character set", |
1091 |
27 May 09 |
nicklas |
349 |
"The character set to use when writing the GCT file. If this parameter " + |
1091 |
27 May 09 |
nicklas |
350 |
"is not set, the system default is used (" + Config.getCharset() + ").", |
1091 |
27 May 09 |
nicklas |
351 |
Config.getCharset())); |
1091 |
27 May 09 |
nicklas |
352 |
parameters.add(getOverwriteParameter(null, null)); |
1091 |
27 May 09 |
nicklas |
353 |
if (checkGctFileType(dc) != null) |
1091 |
27 May 09 |
nicklas |
354 |
{ |
1091 |
27 May 09 |
nicklas |
355 |
parameters.add(new PluginParameter<Boolean>( |
1091 |
27 May 09 |
nicklas |
356 |
"attachToBioAssaySet", |
1091 |
27 May 09 |
nicklas |
357 |
"Attach file to bioassay set", |
1091 |
27 May 09 |
nicklas |
358 |
"Deselect this option if you don't want the generated file to " + |
1091 |
27 May 09 |
nicklas |
359 |
"become attached to the current bioassay set. This option is ignored " + |
1091 |
27 May 09 |
nicklas |
360 |
"if the file isn't saved in the BASE file system.", |
1091 |
27 May 09 |
nicklas |
361 |
new BooleanParameterType(true, false) |
1091 |
27 May 09 |
nicklas |
362 |
)); |
1091 |
27 May 09 |
nicklas |
363 |
} |
1091 |
27 May 09 |
nicklas |
364 |
dc.commit(); |
1091 |
27 May 09 |
nicklas |
365 |
|
1091 |
27 May 09 |
nicklas |
366 |
configureJob = new RequestInformation( |
1091 |
27 May 09 |
nicklas |
367 |
Request.COMMAND_CONFIGURE_JOB, |
1091 |
27 May 09 |
nicklas |
368 |
"Select export options.", |
1091 |
27 May 09 |
nicklas |
369 |
"Select a file name (if required) and other options such as " + |
1091 |
27 May 09 |
nicklas |
370 |
"which fields to export.", |
1091 |
27 May 09 |
nicklas |
371 |
parameters |
1091 |
27 May 09 |
nicklas |
372 |
); |
1091 |
27 May 09 |
nicklas |
373 |
} |
1091 |
27 May 09 |
nicklas |
374 |
finally |
1091 |
27 May 09 |
nicklas |
375 |
{ |
1091 |
27 May 09 |
nicklas |
376 |
if (dc != null) dc.close(); |
1091 |
27 May 09 |
nicklas |
377 |
} |
1091 |
27 May 09 |
nicklas |
378 |
return configureJob; |
1091 |
27 May 09 |
nicklas |
379 |
} |
1091 |
27 May 09 |
nicklas |
380 |
|
1091 |
27 May 09 |
nicklas |
381 |
public DataFileType checkGctFileType(DbControl dc) |
1091 |
27 May 09 |
nicklas |
382 |
{ |
1091 |
27 May 09 |
nicklas |
383 |
DataFileType gct = null; |
1091 |
27 May 09 |
nicklas |
384 |
try |
1091 |
27 May 09 |
nicklas |
385 |
{ |
1091 |
27 May 09 |
nicklas |
386 |
gct = DataFileType.getByExternalId(dc, GenePattern.GCT_FILE); |
1091 |
27 May 09 |
nicklas |
387 |
} |
1091 |
27 May 09 |
nicklas |
388 |
catch (ItemNotFoundException ex) |
1091 |
27 May 09 |
nicklas |
389 |
{ |
1091 |
27 May 09 |
nicklas |
390 |
if (dc.getSessionControl().hasPermission(Permission.CREATE, Item.DATAFILETYPE)) |
1091 |
27 May 09 |
nicklas |
391 |
{ |
1091 |
27 May 09 |
nicklas |
392 |
gct = DataFileType.getNew(dc, GenePattern.GCT_FILE, Item.BIOASSAYSET); |
1091 |
27 May 09 |
nicklas |
393 |
gct.setName("GenePattern GCT"); |
1091 |
27 May 09 |
nicklas |
394 |
gct.setDescription("A GenePattern GCT file"); |
1091 |
27 May 09 |
nicklas |
395 |
gct.setGenericType(FileType.getById(dc, SystemItems.getId(FileType.SPOT_DATA))); |
1091 |
27 May 09 |
nicklas |
396 |
dc.saveItem(gct); |
1091 |
27 May 09 |
nicklas |
397 |
} |
1091 |
27 May 09 |
nicklas |
398 |
} |
1091 |
27 May 09 |
nicklas |
399 |
catch (Exception ex) |
1091 |
27 May 09 |
nicklas |
400 |
{} |
1091 |
27 May 09 |
nicklas |
401 |
return gct; |
1091 |
27 May 09 |
nicklas |
402 |
} |
1091 |
27 May 09 |
nicklas |
403 |
|
1091 |
27 May 09 |
nicklas |
404 |
|
1091 |
27 May 09 |
nicklas |
405 |
} |