EASY refactor: First attempt
This commit is contained in:
@@ -3,18 +3,25 @@
|
||||
% Updated 240724 Bryan C Roessler to improve file operations and portability
|
||||
%
|
||||
function varargout = EASYconsole(varargin)
|
||||
global startDir
|
||||
global easyDir
|
||||
global easySuffix
|
||||
global scansDir
|
||||
global easyResultsDir
|
||||
global easyResultsDirName
|
||||
global fotosResultsDir
|
||||
global figsResultsDir
|
||||
global pointMapsResultsDir
|
||||
global pointMapsFile
|
||||
global printResultsDir
|
||||
global matDir
|
||||
global matFile
|
||||
global drugMediaFile
|
||||
global masterPlateFile
|
||||
global mpdmFile
|
||||
global userName
|
||||
global srchRange
|
||||
|
||||
% Initialize some variables from matlab
|
||||
startDir=pwd;
|
||||
easyPath=which(mfilename);
|
||||
[easyDir,easyFileName]=fileparts(easyPath);
|
||||
easyDir=fullfile(easyDir);
|
||||
@@ -27,22 +34,27 @@ function varargout = EASYconsole(varargin)
|
||||
% Set scansDir intelligently (project scans directory)
|
||||
% 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')
|
||||
if exist('PROJECT', 'env') && ~isempty(getenv('PROJECT'))
|
||||
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')
|
||||
elseif exist('SCANS_DIR', 'env') && ~isempty(getenv('SCANS_DIR'))
|
||||
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
|
||||
dirToScan=fullfile(parentDir,'ExpJobs'); % hardcoded relative to easy script dir TODO: if we change pj layout this will change
|
||||
dirs=dir(fullfile(dirToScan, 'dir')); % filter for dirs only
|
||||
[~, sortedIndices] = sort(datenum({dirs.date}), 'descend'); % sort by newest first
|
||||
sortedDirs=dirs{sortedIndices};
|
||||
scansDir=sortedDirs{1};
|
||||
disp('Beginning in newest project scans directory');
|
||||
disp(strcat('Using scans directory: ', scansDir, ' from hardcoded default'));
|
||||
disp('This usually indicates that we are in standalone mode');
|
||||
disp('This usually indicates that we are in stand-alone mode');
|
||||
end
|
||||
|
||||
% If we don't have the EASY_SUFFIX from the module, generate it from scanDir
|
||||
if exist('EASY_SUFFIX', 'env')
|
||||
% If we don't have the EASY_SUFFIX from the module, generate it from scansDir
|
||||
if exist('EASY_SUFFIX', 'env') && ~isempty(getenv('EASY_SUFFIX'))
|
||||
easySuffix=get_env('EASY_SUFFIX');
|
||||
else
|
||||
[dirName, ~]=fileparts(scansDir);
|
||||
@@ -69,10 +81,11 @@ function varargout = EASYconsole(varargin)
|
||||
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')
|
||||
if exist('EASY_DIR','env') && ~isempty(getenv('EASY_DIR'))
|
||||
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");
|
||||
disp("WARNING: EASY_DIR does not match this script's hardcoded EASY location");
|
||||
disp("This is probably OK but if strange beahvior arises, we'll need to fix it in code");
|
||||
easyDir=EASY_DIR;
|
||||
end
|
||||
disp(strcat('Using EASY script directory: ', easyDir, ' from environment variable EASY_DIR'));
|
||||
@@ -80,12 +93,7 @@ function varargout = EASYconsole(varargin)
|
||||
disp(strcat('Using EASY script directory: ', easyDir, ' from hardcoded default'));
|
||||
end
|
||||
|
||||
% Now that we have easyDir let's add it to the path just to be safe
|
||||
% TODO I have no idea if this is necessary or effective but we'll see
|
||||
% I could image it would reduce some weird matlab errors?
|
||||
addpath(easyDir);
|
||||
|
||||
if exist('EASY_RESULTS_DIR', 'env')
|
||||
if exist('EASY_RESULTS_DIR', 'env') && ~isempty(getenv('EASY_RESULTS_DIR'))
|
||||
easyResultsDir=fullfile(get_env('EASY_RESULTS_DIR'));
|
||||
disp(strcat('Using project prefix: ', easyResultsDir, ' from environment variable EASY_RESULTS_DIR'))
|
||||
else
|
||||
@@ -95,21 +103,73 @@ function varargout = EASYconsole(varargin)
|
||||
disp(strcat('Using project prefix: ', PROJECT_PREFIX, ' from environment variable PROJECT_PREFIX'))
|
||||
end
|
||||
|
||||
if exist('PROJECT_USER', 'env')
|
||||
if exist('PROJECT_USER', 'env') && ~isempty(getenv('PROJECT_USER'))
|
||||
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'));
|
||||
if exist('MASTER_PLATE_FILE', 'env') && ~isempty(getenv('MASTER_PLATE_FILE'))
|
||||
masterPlateFile=fullfile(get_env('MASTER_PLATE_FILE'));
|
||||
disp(strcat('Using drug media file: ', masterPlateFile, ' from environment variable MASTER_PLATE_FILE'))
|
||||
else
|
||||
% Try to find MasterPlate_ file on our own
|
||||
mp=fullfile(scansDir,'MasterPlateFiles',strcat('MasterPlate_', easySuffix,'.xlsx'));
|
||||
if exist(mp, 'file'))
|
||||
masterPlateFile=mp;
|
||||
disp(strcat('Using drug media file: ', masterPlateFile, ' from internal logic'))
|
||||
else
|
||||
disp("WARNING: Have you created a MasterPlate_ file?")
|
||||
end
|
||||
end
|
||||
|
||||
% Play around with making some common variables from our input data
|
||||
% resDirName=fullfile(SCANS_DIR,'Results',dateStr,'_', PROJECT_SUFFIX);
|
||||
% resDir=fullfile(SCANS_DIR,resDirName);
|
||||
% ExpOutmat=fullfile(matDir,strcat(datestr(now,29),newExpfile));
|
||||
% ExpPath=fullfile(newExppath);
|
||||
% ExpFile=fullfile(matDir,)
|
||||
if exist('DRUG_MEDIA_FILE', 'env') && ~isempty(getenv('DRUG_MEDIA_FILE'))
|
||||
drugMediaFile=fullfile(get_env('DRUG_MEDIA_FILE'));
|
||||
disp(strcat('Using drug media file: ', drugMediaFile, ' from environment variable DRUG_MEDIA_FILE'))
|
||||
else
|
||||
% Try to find MasterPlate_ file on our own
|
||||
dm=fullfile(scansDir,'MasterPlateFiles',strcat('DrugMedia_', easySuffix,'.xlsx'));
|
||||
if exist(mp, 'file'))
|
||||
drugMediaFile=dm;
|
||||
disp(strcat('Using drug media file: ', drugMediaFile, ' from internal logic'))
|
||||
else
|
||||
disp("WARNING: Have you created a DrugMedia_ file?")
|
||||
end
|
||||
end
|
||||
|
||||
matDir=fullfile(easyResultsDir,'matResults');
|
||||
if ~exist(matDir, 'dir')
|
||||
mkdir(matDir);
|
||||
end
|
||||
matFile=fullfile(matDir,strcat(easyResultsDirName,'.mat'));
|
||||
% Pulled these out of par4GblFnc8c
|
||||
printResultsDir=fullfile(easyResultsDir,'PrintResults');
|
||||
fotosResultsDir=fullfile(easyResultsDir,'Fotos');
|
||||
figsResultsDir=fullfile(easyResultsDir,'figs');
|
||||
pointMapsResultsDir=fullfile(easyResultsDir,'PTmats');
|
||||
pointMapsFile=fullfile(pointMapsResultsDir,'NImParameters.mat')
|
||||
oldPointMapsFile=fullfile(pointMapsResultsDir,'ImParameters.mat')
|
||||
CSearchRangeFile=fullfile(fotosResultsDir,'CSearchRange.mat');
|
||||
mpdmFile=fullfile(matDir,'MPDM.mat');
|
||||
|
||||
% This can be removed, I think it should add the previous search range?
|
||||
% Might be nice feature but can remove if it causes issues
|
||||
% We are using searchRangeNum to hold old CSrchRange value(s)
|
||||
if exist(CSearchRangeFile, 'file')
|
||||
searchRangeNum=load(CSearchRangeFile);
|
||||
end
|
||||
% Add easyDir to the MATLAB path
|
||||
% I have not idea if this is necessary or works but theoretically should
|
||||
% reduce directory scoping issues when calling scripts w/o a path
|
||||
addpath(easyDir);
|
||||
|
||||
% Pulled this out of the opening function
|
||||
% Seems better to wait until we have our ars set
|
||||
if exist('scansDir','var') && ~isempty(scansDir)
|
||||
set(fhconsole,'Name',strcat('EASYconsole - ',char(scansDir)));
|
||||
else
|
||||
set(fhconsole,'Name','EASYconsole - No Active Experiment.')
|
||||
end
|
||||
|
||||
% GUI interface design
|
||||
gui_Singleton=1;
|
||||
@@ -164,15 +224,6 @@ function EASYconsole_OpeningFcn(hObject, ~, handles, varargin)
|
||||
fhconsole=gcf;
|
||||
set(fhconsole,'Toolbar','none');
|
||||
fhconsole=gcf;
|
||||
|
||||
% BCR this is set in the global function so I think we're good here
|
||||
% easyResultsDirName=strcat('Results',todayStr,newExpfilePref);
|
||||
|
||||
if exist('easyResultsDir','var') && ~isempty(easyResultsDir)
|
||||
set(fhconsole,'Name',strcat('EASYconsole- ',char(easyResultsDir)));
|
||||
else
|
||||
set(fhconsole,'Name','EASYconsole -Exp. Analysis NOT selected.')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -200,7 +251,6 @@ end
|
||||
|
||||
% New Experiment Button Interface
|
||||
function NewExpDat_Callback(~, ~, ~)
|
||||
global SWnewExp
|
||||
global matDir
|
||||
global matFile
|
||||
global easyResultsDir
|
||||
@@ -213,8 +263,6 @@ function NewExpDat_Callback(~, ~, ~)
|
||||
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;
|
||||
|
||||
inputFileName=strrep(inputFile,'.mat','');
|
||||
easyResultsDirName=strcat('Results_',todayStr,'_',userName,'_',inputFileName);
|
||||
|
||||
@@ -263,8 +311,7 @@ function NewExpDat_Callback(~, ~, ~)
|
||||
sbdg= cell(1,scanMax);
|
||||
save((fullfile(easyResultsDir,'Fotos','Nbdg')),'sbdg');
|
||||
catch ME
|
||||
% returnStartDir
|
||||
disp('Error Creating a New Experiment')
|
||||
disp(strcat('ERROR: ', ME.message))
|
||||
end
|
||||
|
||||
% set the title for fhconsole depending on existence
|
||||
@@ -278,39 +325,50 @@ end
|
||||
|
||||
% Load a previous experiment
|
||||
function LoadDatFile_Callback(~, ~, ~)
|
||||
global SWnewExp
|
||||
global matDir
|
||||
global matFile
|
||||
global easyResultsDir
|
||||
global easyPath
|
||||
global fhconsole
|
||||
%global ImParMat
|
||||
|
||||
try
|
||||
questdlg('\fontsize{20} Load file from ExpJobs/YourJob/YourResults/matResults','File Creation','OK', struct('Default','OK','Interpreter','tex'));
|
||||
[inputFile,inputPath]=uigetfile('.mat','Open Experiment folder and data storage .mat file name','MultiSelect','off');
|
||||
SWnewExp=0;
|
||||
matDir=fullfile(inputPath);
|
||||
matFile=fullfile(inputPath,inputFile);
|
||||
load(matFile);
|
||||
easyResultsDir=fullfile(matDir,'..');
|
||||
scansDir=fullfile(matDir,'..', '..');
|
||||
point
|
||||
|
||||
% TODO this is pretty hacky and needs something more explicit
|
||||
if isfolder(fullfile(matDir, '..','..','1')) % If Inovation Vrobot Then
|
||||
if exist(fullfile(easyResultsDir,'PTmats','NImParameters.mat'), 'file')
|
||||
load(fullfile(easyResultsDir,'PTmats','NImParameters.mat'));
|
||||
else
|
||||
load(fullfile(easyPath,'NImParameters.mat'));
|
||||
try
|
||||
exist(pointMapsFile, 'file')
|
||||
load(pointMapsFile);
|
||||
catch
|
||||
try
|
||||
load(fullfile(easyPath,'NImParameters.mat')); % hardcoded default
|
||||
catch
|
||||
disp("Could not load the NImParameters.mat file")
|
||||
end
|
||||
end
|
||||
else % If Epson 10Plate Scans Then>
|
||||
if exist(fullfile(easyResultsDir,'PTmats','ImParameters.mat'), 'file')
|
||||
load(fullfile(easyResultsDir,'PTmats','ImParameters.mat'));
|
||||
if exist(fullfile(pointMapsResultsDir,'ImParameters.mat'), 'file')
|
||||
load(fullfile(pointMapsResultsDir,'ImParameters.mat'));
|
||||
else
|
||||
load(fullfile(easyPath,'ImParameters.mat'));
|
||||
try
|
||||
load(fullfile(easyPath,'ImParameters.mat'));
|
||||
catch
|
||||
disp("Could not load the ImParameters.mat file")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mkdir(fullfile(matDir,'BkUp'));
|
||||
bkupDir=fullfile(matDir,'BkUp');
|
||||
if ~exist(bkupDir, 'dir')
|
||||
mkkdir(bkupDir);
|
||||
end
|
||||
|
||||
% Create supporting dirs
|
||||
dirs={'PrintResults', 'figs', 'CFfigs', 'PTmats', 'Fotos'}
|
||||
@@ -333,8 +391,8 @@ function LoadDatFile_Callback(~, ~, ~)
|
||||
end
|
||||
end
|
||||
|
||||
%% CALLBACKS %%
|
||||
% callback for the 'Run' in the dropdown menu
|
||||
% Callbacks
|
||||
% 'Run' in the dropdown menu
|
||||
function run_Callback(~, ~, ~)
|
||||
end
|
||||
|
||||
@@ -378,8 +436,7 @@ end
|
||||
|
||||
function runDMPexcel_Callback(~, ~, ~)
|
||||
try
|
||||
% DMPexcel2mat_2024winLinix %DMPexcel2mat_2023winLinix
|
||||
DMPexcel2mat % TODO Can't find above so using what I have available
|
||||
DMPexcel2mat
|
||||
catch
|
||||
EASYconsole
|
||||
end
|
||||
@@ -387,7 +444,7 @@ end
|
||||
|
||||
function runResults_DBcombo_Callback(~, ~, ~)
|
||||
try
|
||||
DgenResults240430 %similar but semicolons removed to restore so cmdLine display info.
|
||||
DgenResults %similar but semicolons removed to restore so cmdLine display info.
|
||||
%Dgen241010qhtcp %par4global -convert 1x1cell of 384cells to be like previous 1x384 cells CFparameter
|
||||
catch ME
|
||||
disp(strcat('Error in DgenResults240430: ', ME.message))
|
||||
|
||||
Reference in New Issue
Block a user