-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVCellPluginDisplay.txt
328 lines (283 loc) · 13.3 KB
/
VCellPluginDisplay.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/*
* To the extent possible under law, the ImageJ developers have waived
* all copyright and related or neighboring rights to this tutorial code.
*
* See the CC0 1.0 Universal license for details:
* http://creativecommons.org/publicdomain/zero/1.0/
*/
package org.vcell.imagej.plugin;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.ChartPanel;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.DefaultXYDataset;
import javax.swing.JFrame;
import org.vcell.imagej.helper.VCellHelper.IJTimeSeriesJobResults;
import org.vcell.imagej.helper.VCellHelper.VCellModelSearch ;
import org.vcell.imagej.helper.VCellHelper.ModelType;
import org.vcell.imagej.helper.VCellHelper.VARTYPE_POSTPROC;
import org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults;
import java.awt.Dimension;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Hashtable;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import org.scijava.command.ContextCommand;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import org.scijava.ui.DialogPrompt.MessageType;
import org.scijava.ui.UIService;
import org.vcell.imagej.helper.VCellHelper;
import org.vcell.imagej.helper.VCellHelper.BasicStackDimensions;
import org.vcell.imagej.helper.VCellHelper.IJDataList;
import org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults;
import net.imagej.Dataset;
import net.imagej.ImageJ;
import net.imglib2.img.array.ArrayImg;
import net.imglib2.img.array.ArrayImgs;
import net.imglib2.img.basictypeaccess.array.DoubleArray;
import net.imglib2.type.numeric.real.DoubleType;
//(See https://github.com/virtualcell/vcell/tree/master/vcell-imagej-helper/src/main/java/org/vcell/imagej/helper/VCellHelper.java)
//Demo chart in ImageJ of line-scan values from VCell simulation results
// BioModel "Tutorial_FRAPbinding" owned by user "tutorial" in application "Spatial" for simulation "FRAP binding"
// values for variable="r" at timePoint=22.0
// line-scan along x-axis at y=0.0
// start and end indexes found by moving mouse over x,y data points (-9.24,0.0) and (9.24,0,0) and
// see index in "info' box at the bottom of the sim results viewer in VCell
//Create list of datapoint indexes to extract from data
@Plugin(type = ContextCommand.class, menuPath = "Plugins>VCellPluginDisplay")
public class VCellPluginDisplay extends ContextCommand {
//
// Feel free to add more parameters here...
//
@Parameter
private UIService uiService;
@Parameter
private VCellHelper vcellHelper;
@Parameter
private String vCellUser = "colreeze";
@Parameter
private String vCellModel = "Monkeyflower_pigmentation_v2";
@Parameter
private String application = "Pattern_formation";
@Parameter
private String simulation = "WT";
@Parameter
private String variable = "C_cyt";
@Parameter
private int timePoint = 50;
@Parameter
private String imageName = "test";
@Parameter
int[] timeIndex = {50};
/**
* This main function serves for development purposes.
* It allows you to run the plugin immediately out of
* your integrated development environment (IDE).
*
* @param args whatever, it's ignored
* @throws Exception
*/
public static void main(final String... args) throws Exception {
// create the ImageJ application context with all available services
final ImageJ ij = new ImageJ();
ij.ui().showUI();
}
private JDialog progressDialog = null;
private final Dimension dim = new Dimension(200,25);
private final JProgressBar jProgressBar = new JProgressBar(0,100) {
@Override
public Dimension getPreferredSize() {
// TODO Auto-generated method stub
return dim;
}
@Override
public Dimension getSize(Dimension rv) {
// TODO Auto-generated method stub
return dim;
}
};
private void displayProgressBar(boolean bShow,String message,String title) {
if(progressDialog == null) {
JFrame applicationFrame = (JFrame)uiService.getDefaultUI().getApplicationFrame();
progressDialog = new JDialog(applicationFrame,"Checking for VCell Client",false);
progressDialog.getContentPane().add(jProgressBar);
jProgressBar.setStringPainted(true);
progressDialog.pack();
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if(!bShow) {
progressDialog.setVisible(false);
return;
}
jProgressBar.setValue(0);
progressDialog.setTitle(title);
jProgressBar.setString(message);
progressDialog.setVisible(true);
}
});
}
private Hashtable<String,Thread> threadHash = new Hashtable<String,Thread>();
private void startJProgressThread0(String lastName,String newName) {
if(lastName != null && threadHash.get(lastName) != null) {
threadHash.get(lastName).interrupt();
while(threadHash.get(lastName) != null) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
break;
}
}
}
if(newName == null) {
return;
}
final Thread progressThread = new Thread(new Runnable(){
@Override
public void run() {
final int[] progress = new int[] {1};
while(progressDialog.isVisible()) {
if(Thread.currentThread().isInterrupted()) {
break;
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
jProgressBar.setValue(progress[0]);
}});
progress[0]++;
try {
Thread.sleep(500);
} catch (InterruptedException e) {
break;
}
}
threadHash.remove(Thread.currentThread().getName());
}});
threadHash.put(newName, progressThread);
progressThread.setName(newName);
progressThread.setDaemon(true);//So not block JVM exit
progressThread.start();
}
@Override
public void run() {
displayProgressBar(true, "Checking listening ports...", "Checking for VCell Client");
startJProgressThread0(null,"Check");
try {
//Find the port that a separately running VCell client is listening on
//
System.out.println("vcell service port="+vcellHelper.findVCellApiServerPort());
//uiService.getDisplayViewer(textDisplay).dispose();
displayProgressBar(false, null, null);
} catch (Exception e) {
//e.printStackTrace();
displayProgressBar(false, null, null);
//uiService.getDisplayViewer(textDisplay).dispose();
uiService.showDialog("Activate VCell client ImageJ service\nTools->'Start Fiji (ImageJ) service'\n"+e.getMessage(), "Couldn't contact VCell client", MessageType.ERROR_MESSAGE);
return;
}
displayProgressBar(true, "Searching...", "Searching VCell Models");
startJProgressThread0("Check","Search");
String theCacheKey = null;
VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(VCellHelper.ModelType.bm,vCellUser,vCellModel,application,simulation,null,null);
try {
ArrayList<VCellModelSearchResults> vcmsr = vcellHelper.getSearchedModelSimCacheKey(false,vcms,null);
if(vcmsr.size() == 0) {
throw new Exception("No Results for search found");
}
theCacheKey = vcmsr.get(0).getCacheKey();
System.out.println("theCacheKey="+theCacheKey);
displayProgressBar(false, null, null);
} catch (Exception e) {
// TODO Auto-generated catch block
//e.printStackTrace();
uiService.showDialog("VCellHelper.ModelType.bm,\"tutorial\",\"Tutorial_MultiApp\",\"3D pde\",\"Simulation4\",null,null\n"+e.getMessage(), "Search failed", MessageType.ERROR_MESSAGE);
displayProgressBar(false, null, null);
}
displayProgressBar(true, "Loading Data...", "Loading Data");
startJProgressThread0("Search","getTimePointData");
/*
try {
String var = variable;
int[] time = new int[] {timePoint};
IJDataList tpd = vcellHelper.getTimePointData(theCacheKey,var,VCellHelper.VARTYPE_POSTPROC.NotPostProcess,time,0);
double[] data = tpd.ijData[0].getDoubleData();
BasicStackDimensions bsd = tpd.ijData[0].stackInfo;
System.out.println(bsd.xsize+ imageName +bsd.ysize);
ArrayImg<DoubleType, DoubleArray> testimg = ArrayImgs.doubles( data, bsd.xsize,bsd.ysize);
uiService.show(testimg);
displayProgressBar(false, null, null);
} catch (Exception e) {
// TODO Auto-generated catch block
// e.printStackTrace();
uiService.showDialog("theCacheKey,var,VCellHelper.VARTYPE_POSTPROC.NotPostProcess,time,0\n"+e.getMessage(), "getTimePoint(...) failed", MessageType.ERROR_MESSAGE);
displayProgressBar(false, null, null);
}
*/
try {
String variableName = variable;
int[] timePointIndexes = new int[] {timePoint};
String simulationDataCacheKey = String.valueOf(theCacheKey);
SimpleDateFormat easyDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date searchFrom = easyDate.parse("2018-01-01 00:00:00");
Date searchTo = easyDate.parse("2100-01-01 00:00:00");
//int[] dataIndexes = new int[searchTo, searchFrom];
int simulationJobIndex;
// int[] dataIndexes = (endIndex-startIndex);
// int cachekey = Integer.valueOf(theCacheKey);
//Get the data values using the cache-key
//IJTimeSeriesJobResults getTimeSeries(String[] variableNames, int[] indices, double startTime, int step, double endTime,boolean calcSpaceStats, boolean calcTimeStats, int jobid, int cachekey) throws Exception{
//ijTimeSeriesJobResults = vh.getTimeSeries(vars, dataIndexes, 22 as double, 1, 22 as double, false, false, 0/*jobid, if parameter scan can be non-zero*/, theCacheKey as int)
//ijTimeSeriesJobResults.data[numVars][numDataPoints+1][numTimes] structure of ijTimeSeriesJobResults.data
//ijTimeSeriesJobResults.data[varIndex][0][0...numTimes-1] contains the timePoints
//ijTimeSeriesJobResults.data[varIndex][1...numDataPoints][0...numTimes-1] contains the data values at each index for each timePoint
//Demo TimePoints ijTimeSeriesJobResults.data[0][0] == array of timePoints for var="r", array has 1 value for timePoint=22.0
//Demo DataPoints ijTimeSeriesJobResults.data[0][1..numDataPoints][0] iterate over dataPoints at each timePoint for each var to get data for var,times
//double[] chartTheseDataPoints = new double[dataIndexes.length]
//for(int i=0;i<dataIndexes.length;i++){
// chartTheseDataPoints[i] =
// ijTimeSeriesJobResults.data[0/*index of "r"*/][i+1/*data, skip 0 because it holds copy of times*/][0/*0 always because we had only 1 timePoint=22.0*/]
//}
//Create JFreechart x,y axis arrays for plotting x=data indexes, y=dataPoint values
//double[][] data = [dataIndexes,chartTheseDataPoints];
/* public IJTimeSeriesJobResults getTimeSeries(String[] variableNames, int[] indices, double startTime, int step, double endTime,
boolean calcSpaceStats, boolean calcTimeStats, int jobid, int cachekey) throws Exception{
*/
//ijTimeSeriesJobResults = vh.getTimeSeries(vars, dataIndexes, 22 as double, 1, 22 as double, false, false, 0/*jobid, if parameter scan can be non-zero*/, theCacheKey as int)
//Get data at single time for a single variable
//TimePointData getTimePointData(String simulationDataCacheKey,String variableName,int[] timePointIndexes,int simulationJobIndex)
// ijDataList = vcHelper.getTimePointData(theCacheKey as String,var,VARTYPE_POSTPROC.NotPostProcess,timeIndex,0)
// bsd = ijDataList.ijData[0].stackInfo
// println(bsd.xsize+" "+bsd.ysize+" "+bsd.zsize)
// data = ijDataList.ijData[0].getDoubleData()
// notInDomainVal = ijDataList.ijData[0].notInDomainValue
//println(bsd.xsize+" "+bsd.ysize+" "+bsd.zsize)
//ds = imagej.dataset().create(new FloatType(),[5,5,5] as long[],"hello", [Axes.X,Axes.Y,Axes.Z] as AxisType[])
//imagej.display().createDisplay("dsimg",ds)
//ijDataList = vcHelper.getTimePointData(theCacheKey as String,var,VARTYPE_POSTPROC.NotPostProcess,timeIndex,0)
// public IJDataList getTimePointData(String simulationDataCacheKey,String variableName,VARTYPE_POSTPROC varTypePostProcess,int[] timePointIndexes,int simulationJobIndex)
IJDataList tpd = vcellHelper.getTimePointData(theCacheKey, variableName, VCellHelper.VARTYPE_POSTPROC.NotPostProcess, timePointIndexes, 0);
double[] data = tpd.ijData[0].getDoubleData();
BasicStackDimensions bsd = tpd.ijData[0].stackInfo;
System.out.println(bsd.xsize+" "+bsd.ysize);
ArrayImg<DoubleType, DoubleArray> testimg = ArrayImgs.doubles( data, bsd.xsize,bsd.ysize);
uiService.show(testimg);
displayProgressBar(false, null, null);
} catch (Exception e) {
// TODO Auto-generated catch block
// e.printStackTrace();
uiService.showDialog("theCacheKey,variable,VCellHelper.VARTYPE_POSTPROC.NotPostProcess,time,0\n"+e.getMessage(), "getTimePoint(...) failed", MessageType.ERROR_MESSAGE);
displayProgressBar(false, null, null);
}
startJProgressThread0("getTimePointData",null);
}
}