DanuserLab / u-probe

Processing of raw ratiometric biosensor images (for example based on FRET) into fully corrected "ratio maps" or "activation maps" — images showing the localized activation of the biosensor.
https://pubmed.ncbi.nlm.nih.gov/20235099/
GNU General Public License v3.0
6 stars 1 forks source link

Automatic method to pre-load previous analysis settings. #3

Closed AdvancedImagingUTSW closed 11 months ago

DanuserLab commented 11 months ago

Thank you for reaching out and expressing your interest in automating the pre-loading of previous analysis settings. We appreciate your engagement with our Biosensor package.

For advanced users seeking to streamline the analysis process within the provided GUI, we recommend utilizing a MATLAB script. Below is an illustrative example script that demonstrates the potential capability to perform batch processing. It is imperative to acknowledge that this script requires careful customization on a case-by-case basis. Additionally, proficiency with our package infrastructure and a comprehensive understanding of MATLAB programming are prerequisites for its successful implementation.

% Example Matlab script for batch processing in the Biosensor package GUI
% Please customize according to specific requirements
% Danuser Lab, Dec 2023

%% Create movieData from BioFormats image
i = 1;

imgFolder = 'PathTo\ImageFolder';

saveFolder = 'PathTo\SaveFolder';

% Initialize MovieData from BioFormats data
bfDataPath = fullfile(imgFolder, sprintf('Cell %d.tif', i));
MD = MovieData(bfDataPath, saveFolder);

% Set some additional movie properties
% MD.timeInterval_ = 30.094; % please change accordingly.
MD.save;

MD.sanityCheck;
MD.save;
MD.reset();

%% Generate Package
Package_ = BiosensorsPackage(MD);
MD.addPackage(Package_);

%% Step 1: Dark Current Correction
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
disp('% Step 1: Dark Current Correction');
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');

step_ = 1;
if isempty(MD.getPackage(1).processes_{step_})
    MD.getPackage(1).createDefaultProcess(step_);
end
funParams = MD.getPackage(1).processes_{step_}.funParams_;

% Please set your own DarkImageDirectories for each channels accordingly!
darkCurrentDir = [imgFolder filesep 'darkcurrent-4DOX'];
darkCurrentDirs{1} = [darkCurrentDir filesep 'cfp_channel'];
darkCurrentDirs{2} = [darkCurrentDir filesep 'yfp_channel'];
funParams.DarkImageDirectories = darkCurrentDirs;

MD.getPackage(1).getProcess(step_).setPara(funParams);
MD.getPackage(1).processes_{step_}.run();

%% Step 2: Shade Correction
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
disp('% Step 2: Shade Correction');
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');

step_ = 2;
if isempty(MD.getPackage(1).processes_{step_})
    MD.getPackage(1).createDefaultProcess(step_);
end
funParams = MD.getPackage(1).processes_{step_}.funParams_;

funParams.GaussFilterSigma = 1;

% Please set your own ShadeImageDirectories for each channels accordingly!
shadeDir = [imgFolder filesep 'ShadeCorrect'];
shadeDirs{1} = [shadeDir filesep 'cfp'];
shadeDirs{2} = [shadeDir filesep 'yfp'];
funParams.ShadeImageDirectories = shadeDirs;

MD.getPackage(1).getProcess(step_).setPara(funParams);
MD.getPackage(1).processes_{step_}.run();

%% New Step 3: Crop Region of Interest
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
disp('% Step 3: Crop Region of Interest');
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');

step_ = 3;
if isempty(MD.getPackage(1).processes_{step_})
    MD.getPackage(1).createDefaultProcess(step_);
end
funParams = MD.getPackage(1).processes_{step_}.funParams_;

funParams.ProcessIndex = 2; % use output from 2nd proc, ShadeCorrectionProcess
funParams.cropROIpositions = [202 133 567 630]; % this was set differently per each cell!
funParams.currentImg = 1; % image selected for cropping ROI on GUI

MD.getPackage(1).getProcess(step_).setPara(funParams);
MD.getPackage(1).processes_{step_}.run();

%% Step 4: Segmentation
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
disp('% Step 4: Multi-scale Automatic Segmentation');
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');

step_ = 4;
% add msaSeg proc which is not defaultProcess of this package:
MD.addProcess(MultiScaleAutoSegmentationProcess(MD));
MD.getPackage(1).setProcess(step_, MD.processes_{step_});
MD.getPackage(1).sanityCheck();

funParams = MD.getPackage(1).processes_{step_}.funParams_;

funParams.ProcessIndex = 3;

MD.getPackage(1).getProcess(step_).setPara(funParams);
MD.getPackage(1).processes_{step_}.run();

%% Step 5: Background mask
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
disp('% Step 5: Background mask');
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');

step_ = 5;
if isempty(MD.getPackage(1).processes_{step_})
    MD.getPackage(1).createDefaultProcess(step_);
end
funParams = MD.getPackage(1).processes_{step_}.funParams_;

funParams.SegProcessIndex = 4;

MD.getPackage(1).getProcess(step_).setPara(funParams);
MD.getPackage(1).processes_{step_}.run();

%% Step 6: Mask Refinement
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
disp('% Step 5: % Mask Refinement');
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');

step_ = 6;
if isempty(MD.getPackage(1).processes_{step_})
    MD.getPackage(1).createDefaultProcess(step_);
end
funParams = MD.getPackage(1).processes_{step_}.funParams_;

funParams.SegProcessIndex = 4;

MD.getPackage(1).getProcess(step_).setPara(funParams);
MD.getPackage(1).processes_{step_}.run();

%% Step 7: Background Subtraction
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
disp('% Step 7: Background Subtraction');
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');

step_ = 7;
if isempty(MD.getPackage(1).processes_{step_})
    MD.getPackage(1).createDefaultProcess(step_);
end
funParams = MD.getPackage(1).processes_{step_}.funParams_;

MD.getPackage(1).getProcess(step_).setPara(funParams);
MD.getPackage(1).processes_{step_}.run();
MD.save

%% (skipped Bleedthrough Correction step)

%% Step 8: Ratioing
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
disp('%% Step 8: Ratioing');
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');

step_ = 8;
MD.addProcess(RatioProcess(MD));
MD.getPackage(1).setProcess(step_, MD.processes_{step_});

funParams = MD.getPackage(1).processes_{step_}.funParams_;

funParams.SegProcessIndex = [4 6];
funParams.ChannelIndex = [2, 1];
funParams.MaskChannelIndex = [2, 1];

MD.getPackage(1).getProcess(step_).setPara(funParams);
MD.getPackage(1).processes_{step_}.run();
MD.save

%% Step 9: Photobleach Correction
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
disp('% Step 9: Photobleach Correction');
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');

step_ = 9;
MD.addProcess(PhotobleachCorrectionProcess(MD));
MD.getPackage(1).setProcess(step_, MD.processes_{step_});

funParams = MD.getPackage(1).processes_{step_}.funParams_;

funParams.ChannelIndex = 2; % Numerator of ratio channel

MD.getPackage(1).getProcess(step_).setPara(funParams);

MD.getPackage(1).sanityCheck();

MD.getPackage(1).processes_{step_}.run();
MD.save

%% Step 10: Output Ratio
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
disp('% Step 10: Output Ratio');
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');

step_ = 10;
MD.addProcess(OutputRatioProcess(MD));
MD.getPackage(1).setProcess(step_, MD.processes_{step_});

funParams = MD.getPackage(1).processes_{step_}.funParams_;

funParams.ChannelIndex = 2; % Numerator of ratio channel

MD.getPackage(1).getProcess(step_).setPara(funParams);

MD.getPackage(1).sanityCheck();

MD.getPackage(1).processes_{step_}.run();
MD.save