EASYconsole.m rewrite

This commit is contained in:
2024-07-26 02:53:58 -04:00
parent 7d621c96ac
commit 3f1cd6ef0e

View File

@@ -3,57 +3,134 @@
% Updated 240724 Bryan C Roessler to improve file operations and portability % Updated 240724 Bryan C Roessler to improve file operations and portability
% %
function varargout = EASYconsole(varargin) function varargout = EASYconsole(varargin)
% initialize global variables for function EASYconsole global startDir
%global ExpOutmat global easyDir
%global ExpPath global easySuffix
%global fhconsole global scansDir
%global resDir global easyResultsDir
global wCodeDir global easyResultsDirName
%global ImParMat global matDir
global matFile
global userName
wCodeDir=pwd; % Initialize some variables from matlab
startDir=pwd;
easyPath=which(mfilename);
[easyDir,easy_filename]=fileparts(easyPath);
easyDir=fullfile(easyDir)
[parentDir, ~]=fileparts(easyDir);
userName=system('whoami');
% changing directory to wCodeDir % Set scansDir intelligently (project scans directory)
% returnStartDir % Allow users to specify a PROJECT=/mnt/data/ExpJobs/Job directory to analyze with EASY
% This better enables running the new EASY in standalone mode
if exist('PROJECT', 'env')
scansDir=get_env('PROJECT');
disp(strcat('Using project path: ', scansDir, ' from environment variable PROJECT'));
disp('This usually indicates that we are in standalone mode');
elseif exist('SCANS_DIR', 'env')
scansDir=get_env('SCANS_DIR');
disp(strcat('Using scans directory: ', scansDir, ' from environment variable SCANS_DIR'));
disp('This usually indicates that we are in module mode');
else
scansDir=fullfile(parentDir,'ExpJobs'); % relative to easy script dir
disp(strcat('Using scans directory: ', scansDir, ' from hardcoded default'));
disp('This usually indicates that we are in standalone mode');
end
disp(getenv('SCANS_DIR')); % If we don't have the EASY_SUFFIX from the module, generate it from scanDir
if exist('EASY_SUFFIX', 'env')
%% GUI INTERFACE DESIGN %% easySuffix=get_env('EASY_SUFFIX');
% beginning of GUI formation & design, see help GUI or help GUIDE in else
% command window for more information [dirName, ~]=fileparts(scansDir);
gui_Singleton = 1; [date, userNameScans, easySuffix]=strsplit(dirName, '_');
gui_State = struct('gui_Name', mfilename, ... % The following is handled by the workflow script that calls this module
'gui_Singleton', gui_Singleton, ... % Reimplementing here for stand-alone mode
'gui_OpeningFcn', @EASYconsole_OpeningFcn, ... % While the easySuffix directory exists, increment by one and try again
'gui_OutputFcn', @EASYconsole_OutputFcn, ... if exist(easySuffix, 'dir')
'gui_LayoutFcn', [] , ... oldSuffix=easySuffix
'gui_Callback', []); while exist(easySuffix, 'dir')
if nargin && ischar(varargin{1}) count=1;
gui_State.gui_Callback = str2func(varargin{1}); easySuffix=strcat(oldSuffix,'.', num2str(count));
end
end end
% Might as well check this too
if nargout if userName ~= userNameScans
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); disp('WARNING: userName does not match userNameScans');
else disp("This usually means that you are attempting to run an EASY analysis on another user's project data scans");
gui_mainfcn(gui_State, varargin{:});
end end
% For happiness
if datestr(now, 'yyyymmdd') == date
disp("Early bird gets the worm")
end
end
% Helpful variables for running in workflow mode that I'll probably have to reimplement in matlab anyways for standalone mode
if exist('EASY_DIR','env')
EASY_DIR=fullfile(get_env('EASY_DIR'))
if easyDir ~= EASY_DIR % sanity check
disp("WARNING: EASY_DIR does not match this script's default EASY location");
easyDir=EASY_DIR
end
disp(strcat('Using EASY script directory: ', easyDir, ' from environment variable EASY_DIR'));
else
disp(strcat('Using EASY script directory: ', easyDir, ' from hardcoded default'));
end
if exist('EASY_RESULTS_DIR', 'env')
easyResultsDir=fullfile(get_env('EASY_RESULTS_DIR'));
disp(strcat('Using project prefix: ', easyResultsDir, ' from environment variable EASY_RESULTS_DIR'))
else
easyResultsDirName=strcat('Results_',datestr(now, 'yyyymmdd'),'_',easySuffix);
easyResultsDir=fullfile(scansDir,easyResultsDirName);
scansDir=fullfile(parent_dir,'ExpJobs') % relative to easy script dir
disp(strcat('Using project prefix: ', PROJECT_PREFIX, ' from environment variable PROJECT_PREFIX'))
end
if exist('PROJECT_USER', 'env')
if get_env('PROJECT_USER') ~= userName % sanity check
disp("WARNING: PROJECT_USER does not match the current namespace");
end
end
matDir=fullfile(easyResultsDir,'matResults');
matFile=fullfile(matDir,strcat(easyResultsDirName,'.mat'));
% Play around with making some common variables from our input data
% resDirName=fullfile(SCANS_DIR,'Results',strcat(datestr(now, 'yyyymmdd'),'_', PROJECT_SUFFIX);
% resDir=fullfile(SCANS_DIR,resDirName);
% ExpOutmat=fullfile(matDir,strcat(datestr(now,29),newExpfile));
% ExpPath=fullfile(newExppath);
% ExpFile=fullfile(matDir,)
% GUI interface design
gui_Singleton=1;
gui_State=struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @EASYconsole_OpeningFcn, ...
'gui_OutputFcn', @EASYconsole_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback=str2func(varargin{1});
end
if nargout
[varargout{1:nargout}]=gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
end end
% To remove?
% Try to enter WCodeDir % Try to enter
function returnStartDir function returnStartDir
global wCodeDir global
try try
cd(wCodeDir) cd(SCANS_DIR)
catch catch
msgbox('Failed to enter selected default directory so starting search at root.'); msgbox('Failed to enter the project directory so starting search from where we started.');
if ispc cd(start_dir)
cd('C:\');
elseif (isunix || ismac)
cd('/mnt/data');
else
msgbox('Unknown platform')
end
end end
end end
@@ -65,40 +142,40 @@ end
% handles--structure with handles and user data (see GUIDATA) % handles--structure with handles and user data (see GUIDATA)
% varargin--input arguments to EASYconsole (see VARARGIN) % varargin--input arguments to EASYconsole (see VARARGIN)
function EASYconsole_OpeningFcn(hObject, ~, handles, varargin) function EASYconsole_OpeningFcn(hObject, ~, handles, varargin)
%global ExpOutmat global fhconsole
%global ExpPath global easyResultsDir
global fhconsole
global resDir
%global ImParMat
% Choose default command line output for EASYconsole % Choose default command line output for EASYconsole
handles.output = hObject; handles.output = hObject;
% Update handles structure % Update handles structure
guidata(hObject, handles); guidata(hObject, handles);
%Figure header, Toolbar, etc. Setup %Figure header, Toolbar, etc. Setup
fhconsole=gcf; fhconsole=gcf;
set(fhconsole,'Toolbar','none'); set(fhconsole,'Toolbar','none');
fhconsole=gcf; fhconsole=gcf;
if exist('resDir','var')&&~isempty(resDir) % BCR this is set in the global function so I think we're good here
set(fhconsole,'Name',strcat('EASYconsole- ',char(resDir))); % easyResultsDirName=strcat('Results',datestr(now, 'yyyymmdd'),newExpfilePref);
else
set(fhconsole,'Name','EASYconsole -Exp. Analysis NOT selected.') if exist('easyResultsDir','var') && ~isempty(easyResultsDir)
end set(fhconsole,'Name',strcat('EASYconsole- ',char(easyResultsDir)));
else
set(fhconsole,'Name','EASYconsole -Exp. Analysis NOT selected.')
end
end end
%% EASYconsole OUTPUT FUNCTION %% % EASYconsole OUTPUT FUNCTION %%
% Outputs from this function are returned to the command line. % Outputs from this function are returned to the command line.
% varargout--cell array for returning output args (see VARARGOUT); % varargout--cell array for returning output args (see VARARGOUT);
% hObject--handle to figure % hObject--handle to figure
% eventdata reserved - to be defined in a future version of MATLAB % eventdata reserved - to be defined in a future version of MATLAB
% handles--structure with handles and user data (see GUIDATA) % handles--structure with handles and user data (see GUIDATA)
function varargout = EASYconsole_OutputFcn(~, ~, handles) function varargout = EASYconsole_OutputFcn(~, ~, handles)
% Get default command line output from handles structure % Get default command line output from handles structure
varargout{1} = handles.output; varargout{1} = handles.output;
end end
%% CONSOLE BUTTON INTERFACES %% %% CONSOLE BUTTON INTERFACES %%
@@ -114,194 +191,179 @@ end
% New Experiment Button Interface % New Experiment Button Interface
function NewExpDat_Callback(~, ~, ~) function NewExpDat_Callback(~, ~, ~)
global newExpfile global SWnewExp
global newExppath global matDir
global SWnewExp global matFile
global ExpOutmat global easyResultsDir
global ExpPath global easyResultsDirName
global matDir global fhconsole
global resDir global scan
global fhconsole global userName
global scan
% put all users on same working directory % Create a new experiment
%returnStartDir try
questdlg('\fontsize{20} NAME the file and NAVIGATE to the directory with the image folders.','File Creation','OK', struct('Default','OK','Interpreter','tex'));
[inputFile,inputPath]=uiputfile('.mat');
SWnewExp=1;
% Create a new experiment inputFileName=strrep(inputFile,'.mat','');
try easyResultsDirName=strcat('Results_',datestr(now,'yyyymmdd'),'_',userName,'_',inputFileName);
questdlg('\fontsize{20} NAME the file and NAVIGATE to the directory with the image folders.','File Creation','OK', struct('Default','OK','Interpreter','tex'));
[newExpfile,newExppath] = uiputfile(' .mat');
SWnewExp=1;
% Set paths % Set paths
newExpfilePref= strrep(newExpfile,'.mat',''); scansDir=fullfile(inputPath);
resDir=fullfile(newExppath,resDirName); easyResultsDir=fullfile(scansDir,easyResultsDirName);
matDir=fullfile(newExppath,resDirName,'matResults'); matDir=fullfile(easyResultsDir,'matResults');
ExpOutmat=fullfile(matDir,strcat(datestr(now,29),newExpfile)); matFile=fullfile(matDir,strcat(datestr(now,'yyyymmdd'),'_',userName,'_',inputFile));
ExpPath=fullfile(newExppath);
%***Added for 'parfor global' to preallocate 'scan' structure 20-0123***** %***Added for 'parfor global' to preallocate 'scan' structure 20-0123*****
nlist=dir(fullfile(ExpPath,'*')); nlist=dir(fullfile(scansDir,'*'));
nnn=0; nnn=0;
for n=1:size(nlist,1) for n=1:size(nlist,1)
if (~isempty(str2num(nlist(n).name))) if (~isempty(str2num(nlist(n).name)))
nnn=nnn+1; nnn=nnn+1;
PnumLst(nnn)= (str2num(nlist(n).name)); PnumLst(nnn)= (str2num(nlist(n).name));
sl(nnn,1)={(nlist(n).name)}; sl(nnn,1)={(nlist(n).name)};
end end
end end
scanSize= size(sl,1); scanSize=size(sl,1);
scanMax= max(str2double(sl)); scanMax=max(str2double(sl));
clear scan; clear scan;
scan(scanMax)= struct(); %changed for parfor global 20_0118 scan(scanMax)=struct(); % changed for parfor global 20_0118
save(ExpOutmat,'scan') save(matFile,'scan')
% BCR rewrote these but moved the functionality into the main workflow script % create supporting dirs
% % create supporting dirs % this is also in the workflow script but here for standalone mode
% dirs = {'PrintResults', 'CFfigs', 'Fotos', 'Fotos/BkUp'}; dirs = {'PrintResults', 'CFfigs', 'Fotos', 'Fotos/BkUp'};
% for i = 1:length(dirs) for i = 1:length(dirs)
% d = dirs{i}; d = dirs{i};
% if ~exist(fullfile(ExpPath, resDirName, d), 'dir') if ~exist(fullfile(easyResultsDir, d), 'dir')
% mkdir(fullfile(ExpPath, resDirName, d)); mkdir(fullfile(easyResultsDir, d));
% end end
% end
% % templateDirs are stored in the easy template directory
% templates = {'figs', 'PTmats'}
% for i = 1:length(templates)
% d = dirs{i};
% if ~exist(fullfile(ExpPath, resDirName, d), 'dir')
% copyfile((fullfile(wCodeDir,d)), (fullfile(ExpPath,resDirName,d)));
% end
% end
clear sbdg % reduce possible retention of a previous job sdbg
sbdg= cell(1,scanMax);
save((fullfile(resDir,'Fotos','Nbdg')),'sbdg');
catch ME
% returnStartDir
disp('Error Creating a New Experiment')
end end
% set the title for fhconsole depending on existence % templateDirs are stored in the easy template directory
if exist('resDir','var')&&~isempty(resDir) templates = {'figs', 'PTmats'}
set(fhconsole,'Name',strcat('EASYconsole- ',char(resDir))) for i = 1:length(templates)
else d = dirs{i};
set(fhconsole,'Name','EASYconsole -Exp. Analysis NOT selected.') if ~exist(fullfile(easyResultsDir, d), 'dir')
copyfile((fullfile(,d)), (fullfile(easyResultsDir,d)));
end
end end
clear sbdg % reduce possible retention of a previous job sdbg
sbdg= cell(1,scanMax);
save((fullfile(easyResultsDir,'Fotos','Nbdg')),'sbdg');
catch ME
% returnStartDir
disp('Error Creating a New Experiment')
end
% set the title for fhconsole depending on existence
if exist('easyResultsDir','var')&&~isempty(easyResultsDir)
set(fhconsole,'Name',strcat('EASYconsole- ',char(easyResultsDir)))
else
set(fhconsole,'Name','EASYconsole -Exp. Analysis NOT selected.')
end
end end
% Load a previous experiment % Load a previous experiment
function LoadDatFile_Callback(~, ~, ~) function LoadDatFile_Callback(~, ~, ~)
global openExpfile global SWnewExp
global openExppath global matDir
global SWnewExp global matFile
global ExpOutmat global easyResultsDir
global ExpPath global easyPath
global matDir global fhconsole
global resDir %global ImParMat
global fhconsole
%global ImParMat
% TODO this entire try block needs work try
try questdlg('\fontsize{20} Load file from ExpJobs/YourJob/YourResults/matResults','File Creation','OK', struct('Default','OK','Interpreter','tex'));
% TODO this whole block is highly questionable [inputFile,inputPath]=uigetfile('.mat','Open Experiment folder and data storage .mat file name','MultiSelect','off');
questdlg('\fontsize{20} Load file from ExpJobs/YourJob/YourResults/matResults','File Creation','OK', struct('Default','OK','Interpreter','tex')); SWnewExp=0;
[openExpfile,openExppath] = uigetfile('.mat','Open Experiment folder and data storage .mat file name','MultiSelect','off'); matDir=fullfile(inputPath)
SWnewExp=0; matFile=fullfile(inputPath,inputFile);
ExpOutmat= fullfile(openExppath,openExpfile); load(matFile);
load(ExpOutmat); easyResultsDir=fullfile(matDir,'..')
resdir=fullfile('../',openExppath) scansDir=fullfile(matDir,'..', '..')
ExpPath=fullfile('../../',openExppath)
if isfolder(fullfile(openExppath, '..','..','1')) %If Inovation Vrobot Then if isfolder(fullfile(matDir, '..','..','1')) % If Inovation Vrobot Then
if exist(fullfile(resDir,'PTmats','NImParameters.mat'), 'file') if exist(fullfile(easyResultsDir,'PTmats','NImParameters.mat'), 'file')
load(fullfile(resDir,'PTmats','NImParameters.mat')); load(fullfile(easyResultsDir,'PTmats','NImParameters.mat'));
else else
curDir=pwd; load(fullfile(easyPath,'NImParameters.mat'));
returnStartDir end
load NImParameters.mat else % If Epson 10Plate Scans Then>
cd(curDir) if exist(fullfile(easyResultsDir,'PTmats','ImParameters.mat'), 'file')
end load(fullfile(easyResultsDir,'PTmats','ImParameters.mat'));
else %If Epson 10Plate Scans Then> else
if exist(fullfile(resDir,'PTmats','ImParameters.mat'), 'file') load(fullfile(easyPath,'ImParameters.mat'));
load(fullfile(resDir,'PTmats','ImParameters.mat')); end
else
curDir=pwd;
returnStartDir
load ImParameters.mat
cd(curDir)
end
end
mkdir(fullfile(openExppath,'\BkUp'));
% create supporting dirs
% dirs = {'PrintResults', 'figs', 'CFfigs', 'PTmats', 'Fotos'}
% for i = 1:length(dirs)
% d = dirs{i}
% if ~exist(fullfile(resDir, d), 'dir')
% mkdir(fullfile(resDir, d));
% end
% end
catch
returnStartDir
end end
clear scan mkdir(fullfile(matDir,'BkUp'));
if exist('resDir','var')&&~isempty(resDir) % Create supporting dirs
fhconsole= gcf; dirs = {'PrintResults', 'figs', 'CFfigs', 'PTmats', 'Fotos'}
set(fhconsole,'Name',strcat('EASYconsole- ',char(resDir))) for i = 1:length(dirs)
else d = dirs{i}
set(fhconsole,'Name','EASYconsole -Exp. Analysis NOT selected.') if ~exist(fullfile(easyResultsDir, d), 'dir')
mkdir(fullfile(easyResultsDir, d));
end
end end
catch
returnStartDir
end
clear scan
if exist('easyResultsDir','var') && ~isempty(easyResultsDir)
fhconsole=gcf;
set(fhconsole,'Name',strcat('EASYconsole- ',char(easyResultsDir)))
else
set(fhconsole,'Name','EASYconsole -Exp. Analysis NOT selected.')
end
end end
%% CALLBACKS %% %% CALLBACKS %%
% callback for the 'Run' in the dropdown menu % callback for the 'Run' in the dropdown menu
function run_Callback(~, ~, ~) function run_Callback(~, ~, ~)
end end
function runPlateMapPintool_Callback(~, ~, ~) function runPlateMapPintool_Callback(~, ~, ~)
try try
NImapPT NImapPT
catch ME catch ME
returnStartDir returnStartDir
EASYconsole EASYconsole
end end
end end
function NImCFcombo_Callback(~, ~, ~) function NImCFcombo_Callback(~, ~, ~)
try try
par4Gbl_Main8c par4Gbl_Main8c
catch catch
returnStartDir returnStartDir
EASYconsole EASYconsole
end end
end end
function runPlateImAnal_Callback(~, ~, ~) function runPlateImAnal_Callback(~, ~, ~)
try try
NImStartupOnly NImStartupOnly
catch ME catch ME
returnStartDir returnStartDir
EASYconsole EASYconsole
end end
end end
function PlateCFit_Callback(~, ~, ~) function PlateCFit_Callback(~, ~, ~)
%global ExpOutmat % global matFile % TODO BCR not sure if needed
try try
NCstart NCstart
catch ME catch ME
returnStartDir returnStartDir
end end
end end
function GenPrintouts_Callback(~, ~, ~) function GenPrintouts_Callback(~, ~, ~)
@@ -311,83 +373,73 @@ function uploadExcelMP2DB_Callback(~, ~, ~)
end end
function runDMPexcel_Callback(~, ~, ~) function runDMPexcel_Callback(~, ~, ~)
global ExpPath try
try DMPexcel2mat_2024winLinix %DMPexcel2mat_2023winLinix
DMPexcel2mat_2024winLinix %DMPexcel2mat_2023winLinix catch ME
catch ME returnStartDir
returnStartDir EASYconsole
EASYconsole end
end
end end
function runResults_DBcombo_Callback(~, ~, ~) function runResults_DBcombo_Callback(~, ~, ~)
try
try DgenResults240430 %similar but semicolons removed to restore so cmdLine display info.
DgenResults240430 %similar but semicolons removed to restore so cmdLine display info. %Dgen241010qhtcp %par4global -convert 1x1cell of 384cells to be like previous 1x384 cells CFparameter
%Dgen241010qhtcp %par4global -convert 1x1cell of 384cells to be like previous 1x384 cells CFparameter catch ME
catch ME disp('Error in DgenResults240430')
disp('Error in DgenResults240430') EASYconsole
returnStartDir end
EASYconsole
end
end end
function Tools_Callback(~, ~, ~) function Tools_Callback(~, ~, ~)
end end
function runOverlayPlots_Callback(~, ~, ~) function runOverlayPlots_Callback(~, ~, ~)
try try
DoverlayPlots2 DoverlayPlots2
EASYconsole EASYconsole
catch ME catch ME
returnStartDir EASYconsole
EASYconsole end
end
end end
function runFotoStrip_Callback(~, ~, ~) function runFotoStrip_Callback(~, ~, ~)
try try
F_NImStartup_CentCir F_NImStartup_CentCir
EASYconsole EASYconsole
catch ME catch ME
returnStartDir EASYconsole
EASYconsole end
end
end end
function runDisplayFig_Callback(~, ~, ~) function runDisplayFig_Callback(~, ~, ~)
try try
UfigDisplay UfigDisplay
catch ME catch ME
returnStartDir EASYconsole
EASYconsole end
end
end end
function runViewParameters_Callback(~, ~, ~) function runViewParameters_Callback(~, ~, ~)
try try
catch ME catch ME
returnStartDir EASYconsole
EASYconsole end
end
end end
function QkviewN_Callback(~, ~, ~) function QkviewN_Callback(~, ~, ~)
try try
QkviewImages QkviewImages
catch ME catch ME
returnStartDir EASYconsole
EASYconsole end
end
end end
function CFdisplay_Callback(~, ~, ~) function CFdisplay_Callback(~, ~, ~)
try try
NCsingleDisplay NCsingleDisplay
returnStartDir EASYconsole
EASYconsole catch ME
catch ME EASYconsole
returnStartDir end
EASYconsole
end
end end