use of cbit.vcell.microscopy.MicroscopyXmlReader in project vcell by virtualcell.
the class SingleFileDescriptor method preNextProcess.
// load the data before the panel disappears
public ArrayList<AsynchClientTask> preNextProcess() {
// create AsynchClientTask arraylist
ArrayList<AsynchClientTask> taskArrayList = new ArrayList<AsynchClientTask>();
if (singleFilePanel.getFileName().length() > 0) {
final String fileStr = singleFilePanel.getFileName();
final String LOADING_MESSAGE = "Loading " + fileStr + "...";
AsynchClientTask updateUIBeforeLoadTask = new AsynchClientTask("", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
VirtualFrapBatchRunFrame.updateStatus(LOADING_MESSAGE);
}
};
AsynchClientTask loadTask = new AsynchClientTask(LOADING_MESSAGE, AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPStudy newFRAPStudy = null;
File inFile = new File(fileStr);
if (// .log (vcell log file)
inFile.getName().endsWith(SimDataConstants.LOGFILE_EXTENSION)) {
DataIdentifier[] dataIdentifiers = FrapDataUtils.getDataIdentiferListFromVCellSimulationData(inFile, 0);
String[][] rowData = new String[dataIdentifiers.length][1];
for (int i = 0; i < dataIdentifiers.length; i++) {
if (dataIdentifiers[i].getVariableType().equals(VariableType.VOLUME)) {
rowData[i][0] = dataIdentifiers[i].getName();
}
}
int[] selectedIndexArr = DialogUtils.showComponentOKCancelTableList(SingleFileDescriptor.this.getPanelComponent(), "Select Volume Variable", new String[] { "Volume Variable Name" }, rowData, ListSelectionModel.SINGLE_SELECTION);
if (selectedIndexArr != null && selectedIndexArr.length > 0) {
// newFRAPStudy = getFrapWorkspace().loadFRAPDataFromVcellLogFile(inFile, dataIdentifiers[selectedIndexArr[0]].getName(), this.getClientTaskStatusSupport());
isFileLoaded = true;
} else {
throw UserCancelException.CANCEL_GENERIC;
}
} else if (// .vfrap
inFile.getName().endsWith(VirtualFrapLoader.VFRAP_EXTENSION)) {
String xmlString = XmlUtil.getXMLString(inFile.getAbsolutePath());
MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
newFRAPStudy = xmlReader.getFrapStudy(XmlUtil.stringToXML(xmlString, null).getRootElement(), this.getClientTaskStatusSupport());
newFRAPStudy.setXmlFilename(inFile.getAbsolutePath());
if (!FRAPWorkspace.areExternalDataOK(localWorkspace, newFRAPStudy.getFrapDataExternalDataInfo(), newFRAPStudy.getRoiExternalDataInfo())) {
newFRAPStudy.setFrapDataExternalDataInfo(null);
newFRAPStudy.setRoiExternalDataInfo(null);
}
} else // .lsm or other image formatss
{
newFRAPStudy = FRAPWorkspace.loadFRAPDataFromImageFile(inFile, this.getClientTaskStatusSupport());
isFileLoaded = true;
}
// otherwise, popup a dialog saying the result will be invalid.
if (!batchRunWorkspace.isBatchRunResultsAvailable()) {
hashTable.put(FRAPStudyPanel.NEW_FRAPSTUDY_KEY, newFRAPStudy);
} else if ((batchRunWorkspace.isBatchRunResultsAvailable() && inFile.getName().endsWith(VirtualFrapLoader.VFRAP_EXTENSION)) && ((newFRAPStudy.getFrapModel(batchRunWorkspace.getSelectedModel()) != null) && (newFRAPStudy.getFrapModel(batchRunWorkspace.getSelectedModel()).getModelParameters() != null))) {
// put newfrapstudy into hashtable to be used for next task
hashTable.put(FRAPStudyPanel.NEW_FRAPSTUDY_KEY, newFRAPStudy);
} else {
String continueStr = "Remove results and continue";
String cancelStr = "Cancel loading data";
String msg = "Loading a new data file,\n or a vfrap file with no model data,\n or a vfrap file with different selected model type, \n will INVALID the existing resuls.";
String choice = DialogUtils.showWarningDialog(singleFilePanel, msg, new String[] { continueStr, cancelStr }, continueStr);
if (choice == continueStr) {
hashTable.put(CLEAR_RESULT_KEY, new Boolean(true));
hashTable.put(FRAPStudyPanel.NEW_FRAPSTUDY_KEY, newFRAPStudy);
} else // cancel
{
throw UserCancelException.CANCEL_GENERIC;
}
}
}
};
AsynchClientTask afterLoadingSwingTask = new AsynchClientTask(LOADING_MESSAGE, AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
// check to see if results need to be cleared
Boolean needClear = (Boolean) hashTable.get(CLEAR_RESULT_KEY);
if (needClear != null && needClear.booleanValue()) {
double[][] oldAnalysisData = batchRunWorkspace.getAnalysisMSESummaryData();
double[][] newAnalysisData = null;
batchRunWorkspace.firePropertyChange(FRAPBatchRunWorkspace.PROPERTY_CHANGE_BATCHRUN_CLEAR_RESULTS, oldAnalysisData, newAnalysisData);
}
FRAPStudy newFRAPStudy = (FRAPStudy) hashTable.get(FRAPStudyPanel.NEW_FRAPSTUDY_KEY);
// setFrapStudy fires property change, so we have to put it in Swing thread.
getBatchRunWorkspace().getWorkingSingleWorkspace().setFrapStudy(newFRAPStudy, true);
VirtualFrapBatchRunFrame.updateProgress(0);
if (isFileLoaded) {
VirtualFrapBatchRunFrame.updateStatus("Loaded " + fileStr);
} else {
VirtualFrapBatchRunFrame.updateStatus("Failed loading " + fileStr + ".");
}
}
};
taskArrayList.add(updateUIBeforeLoadTask);
taskArrayList.add(loadTask);
taskArrayList.add(afterLoadingSwingTask);
} else {
DialogUtils.showErrorDialog(singleFilePanel, "Load File name is empty. Please input a file name to continue.");
throw new RuntimeException("Load File name is empty. Please input a file name to continue.");
}
return taskArrayList;
}
use of cbit.vcell.microscopy.MicroscopyXmlReader in project vcell by virtualcell.
the class FRAPBatchRunWorkspace method getLoadSingleFilesTask.
// get client task for loading each single vfrap files in a batch run
public AsynchClientTask getLoadSingleFilesTask(LocalWorkspace arg_localWorkspace) {
final LocalWorkspace localWorkspace = arg_localWorkspace;
AsynchClientTask openSingleFilesTask = new AsynchClientTask("", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPBatchRunWorkspace tempBatchRunWorkspace = (FRAPBatchRunWorkspace) hashTable.get(BATCH_RUN_WORKSPACE_KEY);
if (tempBatchRunWorkspace != null) {
ArrayList<FRAPStudy> fStudyList = tempBatchRunWorkspace.getFrapStudies();
int size = fStudyList.size();
for (int i = 0; i < size; i++) {
String fileName = fStudyList.get(i).getXmlFilename();
File fStudyFile = new File(fileName);
if (// .vfrap
fileName.endsWith("." + VirtualFrapLoader.VFRAP_EXTENSION) || fileName.endsWith(".xml")) {
this.getClientTaskStatusSupport().setMessage("Loading(.vfrap) " + (i + 1) + " of " + size + " : " + fileName);
FRAPStudy newFRAPStudy = null;
String xmlString = XmlUtil.getXMLString(fStudyFile.getAbsolutePath());
MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
newFRAPStudy = xmlReader.getFrapStudy(XmlUtil.stringToXML(xmlString, null).getRootElement(), this.getClientTaskStatusSupport());
// if((newFRAPStudy.getFrapDataExternalDataInfo() != null || newFRAPStudy.getRoiExternalDataInfo() != null) &&
// !FRAPWorkspace.areExternalDataOK(localWorkspace,newFRAPStudy.getFrapDataExternalDataInfo(),newFRAPStudy.getRoiExternalDataInfo()))
// {
// throw new Exception("External Files of Frap Document " + fStudyFile.getAbsolutePath() + " are corrupted");
// }
newFRAPStudy.setXmlFilename(fileName);
// get dimentsion reduced experimental data
newFRAPStudy.getDimensionReducedExpData();
// restore the dimension reduced fitting data(2 dimensional array).
int selectedModelIdx = tempBatchRunWorkspace.getSelectedModel();
FRAPModel frapModel = newFRAPStudy.getFrapModel(selectedModelIdx);
// optimization was done but data wasn't save with file, need to restore data
if (frapModel != null && frapModel.getModelParameters() != null && frapModel.getModelParameters().length > 0 && frapModel.getData() == null) {
if (frapModel.getModelIdentifer().equals(FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_REACTION_OFF_RATE])) {
FRAPOptFunctions frapOptFunc = new FRAPOptFunctions(newFRAPStudy);
newFRAPStudy.setFrapOptFunc(frapOptFunc);
frapModel.setData(frapOptFunc.getFitData(frapModel.getModelParameters()));
} else {
FRAPOptData optData = new FRAPOptData(newFRAPStudy, frapModel.getModelParameters().length, localWorkspace, newFRAPStudy.getStoredRefData());
newFRAPStudy.setFrapOptData(optData);
frapModel.setData(optData.getFitData(frapModel.getModelParameters()));
}
}
tempBatchRunWorkspace.getFrapStudies().remove(i);
tempBatchRunWorkspace.getFrapStudies().add(i, newFRAPStudy);
}
}
// save loaded tempBatchRunWorkspace to hashtable
hashTable.put(BATCH_RUN_WORKSPACE_KEY, tempBatchRunWorkspace);
}
}
};
return openSingleFilesTask;
}
use of cbit.vcell.microscopy.MicroscopyXmlReader in project vcell by virtualcell.
the class BatchRunDisplayPanel method getFRAPDataPanel.
public FRAPDataPanel getFRAPDataPanel() {
if (frapDataPanel == null) {
// the frap data panel in the main frame is not editable
frapDataPanel = new FRAPDataPanel(false);
// set display mode
frapDataPanel.adjustComponents(VFrap_OverlayEditorPanelJAI.DISPLAY_WITH_ROIS);
Hashtable<String, Cursor> cursorsForROIsHash = new Hashtable<String, Cursor>();
cursorsForROIsHash.put(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name(), FRAPStudyPanel.ROI_CURSORS[FRAPStudyPanel.CURSOR_CELLROI]);
cursorsForROIsHash.put(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name(), FRAPStudyPanel.ROI_CURSORS[FRAPStudyPanel.CURSOR_BLEACHROI]);
cursorsForROIsHash.put(FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name(), FRAPStudyPanel.ROI_CURSORS[FRAPStudyPanel.CURSOR_BACKGROUNDROI]);
frapDataPanel.getOverlayEditorPanelJAI().setCursorsForROIs(cursorsForROIsHash);
VFrap_OverlayEditorPanelJAI.CustomROIImport importVFRAPROI = new VFrap_OverlayEditorPanelJAI.CustomROIImport() {
public boolean importROI(File inputFile) throws Exception {
try {
if (!VirtualFrapLoader.filter_vfrap.accept(inputFile)) {
return false;
}
String xmlString = XmlUtil.getXMLString(inputFile.getAbsolutePath());
MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
FRAPStudy importedFrapStudy = xmlReader.getFrapStudy(XmlUtil.stringToXML(xmlString, null).getRootElement(), null);
VirtualFrapMainFrame.updateProgress(0);
ROI roi = getBatchRunWorkspace().getWorkingSingleWorkspace().getWorkingFrapStudy().getFrapData().getCurrentlyDisplayedROI();
ROI[] importedROIs = importedFrapStudy.getFrapData().getRois();
if (importedFrapStudy.getFrapData() != null && importedROIs != null) {
if (!importedROIs[0].getISize().compareEqual(roi.getISize())) {
throw new Exception("Imported ROI mask size (" + importedROIs[0].getISize().getX() + "," + importedROIs[0].getISize().getY() + "," + importedROIs[0].getISize().getZ() + ")" + " does not match current Frap DataSet size (" + roi.getISize().getX() + "," + roi.getISize().getY() + "," + roi.getISize().getZ() + ")");
}
for (int i = 0; i < importedROIs.length; i++) {
getBatchRunWorkspace().getWorkingSingleWorkspace().getWorkingFrapStudy().getFrapData().addReplaceRoi(importedROIs[i]);
}
// undoableEditSupport.postEdit(FRAPStudyPanel.CLEAR_UNDOABLE_EDIT);
}
return true;
} catch (Exception e1) {
throw new Exception("VFRAP ROI Import - " + e1.getMessage());
}
}
};
frapDataPanel.getOverlayEditorPanelJAI().setCustomROIImport(importVFRAPROI);
}
return frapDataPanel;
}
use of cbit.vcell.microscopy.MicroscopyXmlReader in project vcell by virtualcell.
the class FRAPStudyPanel method open.
// open .vfrap document
public AsynchClientTask[] open(final File inFile) {
final String LOADING_MESSAGE = "Loading " + inFile.getAbsolutePath() + "...";
ArrayList<AsynchClientTask> totalTasks = new ArrayList<AsynchClientTask>();
// check if save is needed before loading data
if (getFrapWorkspace().getWorkingFrapStudy().isSaveNeeded()) {
String choice = DialogUtils.showWarningDialog(FRAPStudyPanel.this, "There are unsaved changes. Save current document before loading new document?", new String[] { SAVE_CONTINUE_MSG, NO_THANKS_MSG }, SAVE_CONTINUE_MSG);
if (choice.equals(SAVE_CONTINUE_MSG)) {
AsynchClientTask[] saveTasks = save();
for (int i = 0; i < saveTasks.length; i++) {
totalTasks.add(saveTasks[i]);
}
}
}
AsynchClientTask preOpenTask = new AsynchClientTask(LOADING_MESSAGE, AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
VirtualFrapMainFrame.updateStatus(LOADING_MESSAGE);
}
};
totalTasks.add(preOpenTask);
AsynchClientTask loadTask = new AsynchClientTask(LOADING_MESSAGE, AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPStudy newFRAPStudy = null;
String newVFRAPFileName = null;
if (// .vfrap
inFile.getName().endsWith("." + VirtualFrapLoader.VFRAP_EXTENSION) || inFile.getName().endsWith(".xml")) {
String xmlString = XmlUtil.getXMLString(inFile.getAbsolutePath());
MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
newFRAPStudy = xmlReader.getFrapStudy(XmlUtil.stringToXML(xmlString, null).getRootElement(), this.getClientTaskStatusSupport());
if (!FRAPWorkspace.areExternalDataOK(getLocalWorkspace(), newFRAPStudy.getFrapDataExternalDataInfo(), newFRAPStudy.getRoiExternalDataInfo())) {
newFRAPStudy.setFrapDataExternalDataInfo(null);
newFRAPStudy.setRoiExternalDataInfo(null);
}
newVFRAPFileName = inFile.getAbsolutePath();
// for loaded file
newFRAPStudy.setXmlFilename(newVFRAPFileName);
hashTable.put(FRAPStudyPanel.NEW_FRAPSTUDY_KEY, newFRAPStudy);
} else {
throw new Exception("Invalid Virtual Frap file name!");
}
}
};
totalTasks.add(loadTask);
AsynchClientTask updateUIAfterLoadingTask = new AsynchClientTask(LOADING_MESSAGE, AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPStudy fStudy = (FRAPStudy) hashTable.get(FRAPStudyPanel.NEW_FRAPSTUDY_KEY);
getFrapWorkspace().setFrapStudy(fStudy, true);
String fName = "";
if (fStudy != null && fStudy.getXmlFilename() != null && fStudy.getXmlFilename().length() > 0) {
fName = fStudy.getXmlFilename();
VirtualFrapLoader.mf.setMainFrameTitle(fName);
VirtualFrapMainFrame.updateStatus("Loaded " + fName);
} else {
VirtualFrapMainFrame.updateStatus(LOADING_MESSAGE + " Failed.");
}
VirtualFrapMainFrame.updateProgress(0);
// clear movie buffer
clearMovieBuffer();
// clear plot selected indices
if (diffOneDescriptor != null && diffTwoDescriptor != null) {
diffOneDescriptor.clearSelectedPlotIndices();
diffTwoDescriptor.clearSelectedPlotIndices();
}
}
};
totalTasks.add(updateUIAfterLoadingTask);
return totalTasks.toArray(new AsynchClientTask[totalTasks.size()]);
}
use of cbit.vcell.microscopy.MicroscopyXmlReader in project vcell by virtualcell.
the class FRAPDataPanel method initialize.
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
gridBagConstraints1.gridx = 0;
gridBagConstraints1.ipadx = 0;
gridBagConstraints1.ipady = 0;
gridBagConstraints1.fill = GridBagConstraints.BOTH;
gridBagConstraints1.weighty = 1.0D;
gridBagConstraints1.weightx = 1.0D;
gridBagConstraints1.gridy = 0;
this.setSize(653, 492);
this.setLayout(new GridBagLayout());
this.add(getOverlayEditorPanelJAI(), gridBagConstraints1);
getOverlayEditorPanelJAI().addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(VFrap_OverlayEditorPanelJAI.FRAP_DATA_TIMEPLOTROI_PROPERTY)) {
try {
plotROI();
} catch (Exception e) {
DialogUtils.showErrorDialog(FRAPDataPanel.this, "Error Time Plot ROI:\n" + e.getMessage());
}
} else if (evt.getPropertyName().equals(VFrap_OverlayEditorPanelJAI.FRAP_DATA_CURRENTROI_PROPERTY)) {
try {
String roiName = (String) evt.getNewValue();
if (roiName != null) {
getFrapWorkspace().getWorkingFrapStudy().getFrapData().setCurrentlyDisplayedROI(getFrapWorkspace().getWorkingFrapStudy().getFrapData().getRoi(roiName), false);
}
} catch (Exception e) {
DialogUtils.showErrorDialog(FRAPDataPanel.this, "Error Setting Current ROI:\n" + e.getMessage());
}
} else if (evt.getPropertyName().equals(VFrap_OverlayEditorPanelJAI.FRAP_DATA_UNDOROI_PROPERTY)) {
try {
ROI undoableROI = (ROI) evt.getNewValue();
getFrapWorkspace().getWorkingFrapStudy().getFrapData().addReplaceRoi(undoableROI);
} catch (Exception e) {
PopupGenerator.showErrorDialog(FRAPDataPanel.this, "Error Setting Current ROI:\n" + e.getMessage());
}
}
}
});
VFrap_OverlayEditorPanelJAI.CustomROIImport importVFRAPROI = new VFrap_OverlayEditorPanelJAI.CustomROIImport() {
public boolean importROI(File inputFile) throws Exception {
try {
if (!VirtualFrapLoader.filter_vfrap.accept(inputFile)) {
return false;
}
String xmlString = XmlUtil.getXMLString(inputFile.getAbsolutePath());
MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
FRAPStudy importedFrapStudy = xmlReader.getFrapStudy(XmlUtil.stringToXML(xmlString, null).getRootElement(), null);
VirtualFrapMainFrame.updateProgress(0);
ROI roi = getFrapWorkspace().getWorkingFrapStudy().getFrapData().getCurrentlyDisplayedROI();
ROI[] importedROIs = importedFrapStudy.getFrapData().getRois();
if (importedFrapStudy.getFrapData() != null && importedROIs != null) {
if (!importedROIs[0].getISize().compareEqual(roi.getISize())) {
throw new Exception("Imported ROI mask size (" + importedROIs[0].getISize().getX() + "," + importedROIs[0].getISize().getY() + "," + importedROIs[0].getISize().getZ() + ")" + " does not match current Frap DataSet size (" + roi.getISize().getX() + "," + roi.getISize().getY() + "," + roi.getISize().getZ() + ")");
}
for (int i = 0; i < importedROIs.length; i++) {
getFrapWorkspace().getWorkingFrapStudy().getFrapData().addReplaceRoi(importedROIs[i]);
}
// undoableEditSupport.postEdit(FRAPStudyPanel.CLEAR_UNDOABLE_EDIT);
}
return true;
} catch (Exception e1) {
throw new Exception("VFRAP ROI Import - " + e1.getMessage());
}
}
};
getOverlayEditorPanelJAI().setCustomROIImport(importVFRAPROI);
}
Aggregations