Search in sources :

Example 16 with ClientTaskStatusSupport

use of org.vcell.util.ClientTaskStatusSupport in project vcell by virtualcell.

the class FRAPParamTest method runProfileLikelihood.

public void runProfileLikelihood() {
    String errorMsg = checkFrapStudyValidity();
    if (!errorMsg.equals("")) {
        System.out.println("Application terminated due to " + errorMsg);
        System.exit(1);
    } else {
        try {
            ClientTaskStatusSupport ctss = new ClientTaskStatusSupport() {

                public void setProgress(int progress) {
                    System.out.println(progress);
                }

                public void setMessage(String message) {
                    System.out.println(message);
                }

                public boolean isInterrupted() {
                    // TODO Auto-generated method stub
                    return false;
                }

                public int getProgress() {
                    // TODO Auto-generated method stub
                    return 0;
                }

                public void addProgressDialogListener(ProgressDialogListener progressDialogListener) {
                    throw new RuntimeException("not yet implemented");
                }
            };
            // get startign index
            if (frapStudy.getStartingIndexForRecovery() == null) {
                int index = FRAPDataAnalysis.calculateRecoveryIndex(frapStudy.getFrapData());
                frapStudy.setStartingIndexForRecovery(index);
            }
            // get dependent rois
            if (frapStudy.getFrapData().getRois().length < 4) {
                frapStudy.refreshDependentROIs();
            }
            // get selected ROIs
            if (frapStudy.getSelectedROIsForErrorCalculation() == null) {
                boolean[] selectedROIs = new boolean[FRAPData.VFRAP_ROI_ENUM.values().length];
                int counter = 0;
                for (FRAPData.VFRAP_ROI_ENUM roiEnum : FRAPData.VFRAP_ROI_ENUM.values()) {
                    if (roiEnum.name().equals(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()) || roiEnum.name().equals(FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name())) {
                        counter++;
                        continue;
                    }
                    if (frapStudy.getFrapData().getRoi(roiEnum.name()).getNonzeroPixelsCount() > 0) {
                        selectedROIs[counter] = true;
                        counter++;
                    }
                }
                frapStudy.setSelectedROIsForErrorCalculation(selectedROIs);
            }
            // get frap opt data
            if (frapStudy.getFrapOptData() == null) {
                if (!FRAPWorkspace.areExternalDataOK(getLocalWorkspace(), frapStudy.getFrapDataExternalDataInfo(), frapStudy.getRoiExternalDataInfo())) {
                    // if external files are missing/currupt or ROIs are changed, create keys and save them
                    frapStudy.setFrapDataExternalDataInfo(FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.IMAGE_EXTDATA_NAME));
                    frapStudy.setRoiExternalDataInfo(FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.ROI_EXTDATA_NAME));
                    frapStudy.saveROIsAsExternalData(localWorkspace, frapStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), frapStudy.getStartingIndexForRecovery());
                    frapStudy.saveImageDatasetAsExternalData(localWorkspace, frapStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), frapStudy.getStartingIndexForRecovery());
                }
                // run ref sim
                frapStudy.setFrapOptData(new FRAPOptData(frapStudy, FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF, localWorkspace, ctss));
            }
            FRAPOptData optData = frapStudy.getFrapOptData();
            // create frapModels
            if (frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] == null) {
                frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] = new FRAPModel(FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT], null, null, null);
                if (frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters() == null) {
                    frapStudy.getFrapOptData().setNumEstimatedParams(FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF);
                    Parameter[] initialParams = FRAPModel.getInitialParameters(frapStudy.getFrapData(), FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT], frapStudy.getStartingIndexForRecovery());
                    Parameter[] bestParameters = frapStudy.getFrapOptData().getBestParamters(initialParams, frapStudy.getSelectedROIsForErrorCalculation());
                    frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].setModelParameters(bestParameters);
                }
            }
            if (frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] == null) {
                frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] = new FRAPModel(FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS], null, null, null);
                if (frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters() == null) {
                    frapStudy.getFrapOptData().setNumEstimatedParams(FRAPModel.NUM_MODEL_PARAMETERS_TWO_DIFF);
                    Parameter[] initialParams = FRAPModel.getInitialParameters(frapStudy.getFrapData(), FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS], frapStudy.getStartingIndexForRecovery());
                    Parameter[] bestParameters = frapStudy.getFrapOptData().getBestParamters(initialParams, frapStudy.getSelectedROIsForErrorCalculation());
                    frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].setModelParameters(bestParameters);
                }
            }
            // try diffusion with one diffusing component model
            System.out.println("Evaluating parameters in diffusion with one diffusing compoent model...");
            Parameter[] bestParameters = frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters();
            ProfileData[] profileData = optData.evaluateParameters(bestParameters, ctss);
            // output profile likelihood
            File outputDir_oneComponent = new File(getLocalWorkspace().getDefaultWorkspaceDirectory() + SUB_DIRECTORY + "OneComponent_SAVED_AT_" + BeanUtils.generateDateTimeString() + System.getProperty("file.separator"));
            if (!outputDir_oneComponent.exists()) {
                outputDir_oneComponent.mkdirs();
            }
            for (int i = 0; i < profileData.length; i++) {
                ProfileDataElement profileDataElement = profileData[i].getProfileDataElements().get(0);
                outputProfileLikelihood(profileData[i].getProfileDataElements(), profileDataElement.getParamName(), outputDir_oneComponent);
            }
            // try diffusion with two diffusing components model
            System.out.println("Evaluating parameters in diffusion with two diffusing compoents model...");
            bestParameters = frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters();
            profileData = optData.evaluateParameters(bestParameters, ctss);
            // output profile likelihood
            File outputDir_twoComponents = new File(getLocalWorkspace().getDefaultWorkspaceDirectory() + SUB_DIRECTORY + "TwoComponents_SAVED_AT_" + BeanUtils.generateDateTimeString() + System.getProperty("file.separator"));
            if (!outputDir_twoComponents.exists()) {
                outputDir_twoComponents.mkdirs();
            }
            for (int i = 0; i < profileData.length; i++) {
                ProfileDataElement profileDataElement = profileData[i].getProfileDataElements().get(0);
                outputProfileLikelihood(profileData[i].getProfileDataElements(), profileDataElement.getParamName(), outputDir_twoComponents);
            }
        } catch (Exception e) {
            e.printStackTrace(System.out);
            System.exit(1);
        }
    }
}
Also used : ProfileData(org.vcell.optimization.ProfileData) Point(java.awt.Point) IOException(java.io.IOException) ProgressDialogListener(org.vcell.util.ProgressDialogListener) ProfileDataElement(org.vcell.optimization.ProfileDataElement) ClientTaskStatusSupport(org.vcell.util.ClientTaskStatusSupport) Parameter(cbit.vcell.opt.Parameter) File(java.io.File)

Aggregations

ClientTaskStatusSupport (org.vcell.util.ClientTaskStatusSupport)16 File (java.io.File)8 ProgressDialogListener (org.vcell.util.ProgressDialogListener)8 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)6 LocalWorkspace (org.vcell.vmicro.workflow.data.LocalWorkspace)5 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)3 ImportRawTimeSeriesFromVFrapOp (org.vcell.vmicro.op.ImportRawTimeSeriesFromVFrapOp)3 ImageTimeSeries (org.vcell.vmicro.workflow.data.ImageTimeSeries)3 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 Parameter (cbit.vcell.opt.Parameter)2 Hashtable (java.util.Hashtable)2 UserCancelException (org.vcell.util.UserCancelException)2 ImageException (cbit.image.ImageException)1 ImageSizeInfo (cbit.image.ImageSizeInfo)1 ROI (cbit.vcell.VirtualMicroscopy.ROI)1 TestCriteriaNew (cbit.vcell.numericstest.TestCriteriaNew)1 ResourceUtil (cbit.vcell.resource.ResourceUtil)1 ExternalDocInfo (cbit.vcell.xml.ExternalDocInfo)1 Point (java.awt.Point)1 BufferedReader (java.io.BufferedReader)1