Cleanup EASY startup
This commit is contained in:
@@ -3,10 +3,9 @@
|
|||||||
|
|
||||||
function varargout = EASYconsole(varargin)
|
function varargout = EASYconsole(varargin)
|
||||||
global easyDir
|
global easyDir
|
||||||
global easySuffix
|
|
||||||
global scansDir
|
global scansDir
|
||||||
global easyResultsDir
|
global easyResultsDir
|
||||||
global easyResultsDirName
|
global easyProject
|
||||||
global fotosResultsDir
|
global fotosResultsDir
|
||||||
global figsResultsDir
|
global figsResultsDir
|
||||||
global pointMapsResultsDir
|
global pointMapsResultsDir
|
||||||
@@ -41,38 +40,52 @@ function varargout = EASYconsole(varargin)
|
|||||||
fprintf('This script name: %s\n', easyFileName);
|
fprintf('This script name: %s\n', easyFileName);
|
||||||
|
|
||||||
% Set scansDir (project scans directory) intelligently
|
% Set scansDir (project scans directory) intelligently
|
||||||
if exist('PROJECT', 'var') && ~isempty(getenv('PROJECT'))
|
|
||||||
scansDir=getenv('PROJECT');
|
if exist('PROJECT_SCANS_DIR', 'var') && ~isempty(getenv('PROJECT_SCANS_DIR'))
|
||||||
|
scansDir=fullfile(getenv('PROJECT_SCANS_DIR'));
|
||||||
|
if exist(scansDir, 'dir')
|
||||||
|
fprintf('Using scans directory: %s from environment variable PROJECT_SCANS_DIR\n', scansDir);
|
||||||
|
disp('This usually indicates that we are in module mode');
|
||||||
|
if ~exist('PROJECT', 'var') || isempty(getenv('PROJECT'))
|
||||||
|
dirInfo=fileparts(scansDir);
|
||||||
|
project=dirInfo.name;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
disp('WARNING: PROJECT_SCANS_DIR does not exist');
|
||||||
|
end
|
||||||
|
elseif exist('PROJECT', 'var') && ~isempty(getenv('PROJECT')) % for standalone mode
|
||||||
|
% scansDir=fullfile(parentDir, '..', '..', 'scans', getenv('PROJECT') 'out', 'easy', getenv('PROJECT'));
|
||||||
|
scansDir=fullfile(parentDir, '..', '..', 'scans', getenv('PROJECT'));
|
||||||
|
project=getenv('PROJECT');
|
||||||
fprintf('Using project path: %s from environment variable PROJECT\n', scansDir);
|
fprintf('Using project path: %s from environment variable PROJECT\n', scansDir);
|
||||||
disp('This usually indicates that we are in standalone mode');
|
disp('This usually indicates that we are in standalone mode');
|
||||||
elseif exist('PROJECT_SCANS_DIR', 'var') && ~isempty(getenv('PROJECT_SCANS_DIR'))
|
|
||||||
scansDir=getenv('PROJECT_SCANS_DIR');
|
|
||||||
fprintf('Using scans directory: %s from environment variable PROJECT_SCANS_DIR\n', scansDir);
|
|
||||||
disp('This usually indicates that we are in module mode');
|
|
||||||
else
|
else
|
||||||
% TODO Lots of this is hardcoded logic, this TODO is just a reminder to change this block
|
% TODO Lots of this is hardcoded logic, this TODO is just a reminder to change this block
|
||||||
% when changing EASY and other variables in the parent script
|
% when changing EASY and other variables in the parent script
|
||||||
|
fprintf('WARNING: Running in standalone mode without PROJECT or PROJECT_SCANS_DIR environment variables (not recommended)\n');
|
||||||
fprintf('Beginning parent scans directory search\n');
|
fprintf('Beginning parent scans directory search\n');
|
||||||
fprintf('This usually indicates that we are in stand-alone mode without PROJECT or PROJECT_SCANS_DIR environment variables\n');
|
|
||||||
dirsToScan={
|
dirsToScan={
|
||||||
fullfile(parentDir,'..', '..', 'scans'),
|
fullfile(parentDir, '..', '..', 'scans'),
|
||||||
fullfile(parentDir, '..', '..', 'ExpJobs'),
|
fullfile(parentDir, '..', '..', 'ExpJobs'),
|
||||||
fullfile('/mnt/data/scans'),
|
fullfile('mnt','data','scans'),
|
||||||
fullfile('/mnt/data/ExpJobs'),
|
fullfile('mnt','data', 'ExpJobs'),
|
||||||
fullfile(parentDir, '..', '..', 'templates', 'scans-demo')
|
fullfile(parentDir, '..', '..', 'templates', 'scans-demo')
|
||||||
};
|
};
|
||||||
for i=1:length(dirsToScan)
|
for i=1:length(dirsToScan)
|
||||||
d=dirsToScan(i);
|
d=dirsToScan(i);
|
||||||
if exist(d, 'dir')
|
if exist(d, 'dir')
|
||||||
subDirs=dir(d);
|
subDirs=dir(d);
|
||||||
if ~isempty(subDirs)
|
pattern='^\d{6}_.*_.*';
|
||||||
fprintf('Found a non-empty parent scans directory in our list: %s\n', d);
|
matchedDirs={dirs(regexp(subDirs.name, pattern)).name};
|
||||||
fprintf('Scanning inside for a project scan directory\n');
|
if ~isempty(matchedDirs)
|
||||||
[~, sortedIndices]=sort(datenum({dirs.date}), 'descend'); % sort by newest first
|
fprintf('Found a non-empty scans directory in our list: %s\n', char(d);
|
||||||
sortedDirs=dirs{sortedIndices};
|
fprintf('Setting scansDir to %s\n', char(d));
|
||||||
scansDir=sortedDirs{1};
|
scansDir=fullfile(d);
|
||||||
fprintf('Selected newest project scans directory: %s\n', scansDir);
|
|
||||||
end
|
end
|
||||||
|
fprintf('Scanning inside %s for a project directory\n', char(d));
|
||||||
|
sortedMatchedDirs=sortrows(matchedDirs);
|
||||||
|
project=sortedMatchedDirs{0}; % select the latest dir (by date prefix)
|
||||||
|
fprintf('Selected latest project directory %s\n', char(project));
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -97,37 +110,12 @@ function varargout = EASYconsole(varargin)
|
|||||||
fprintf('Using EASY script directory: %s from hardcoded default\n', easyDir);
|
fprintf('Using EASY script directory: %s from hardcoded default\n', easyDir);
|
||||||
end
|
end
|
||||||
|
|
||||||
% If we don't have tan EASY_SUFFIX from the module, generate it from scansDir
|
|
||||||
if exist('EASY_SUFFIX', 'var') && ~isempty(getenv('EASY_SUFFIX'))
|
|
||||||
easySuffix=getenv('EASY_SUFFIX');
|
|
||||||
else
|
|
||||||
% The following is a way to parse the project name from the scansDir
|
|
||||||
[ ~, dirName]=fileparts(scansDir);
|
|
||||||
parts=strsplit(dirName, '_');
|
|
||||||
scansDate=parts{1};
|
|
||||||
scansUserName=parts{2};
|
|
||||||
easySuffix=strjoin(parts(3:end), '_');
|
|
||||||
% Might as well check this too for fun
|
|
||||||
if ~strcmp(userName, scansUserName)
|
|
||||||
disp('WARNING: userName does not match scansUserName');
|
|
||||||
disp("This usually means that you are attempting to run an EASY analysis on another user's project data scans");
|
|
||||||
end
|
|
||||||
% For happiness
|
|
||||||
if strcmp(todayStr, scansDate)
|
|
||||||
disp("Early bird gets the worm");
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if (exist('EASY_RESULTS_DIR', 'var') && ~isempty(getenv('EASY_RESULTS_DIR')))
|
if (exist('EASY_RESULTS_DIR', 'var') && ~isempty(getenv('EASY_RESULTS_DIR')))
|
||||||
easyResultsDir=fullfile(getenv('EASY_RESULTS_DIR'));
|
easyResultsDir=fullfile(getenv('EASY_RESULTS_DIR'));
|
||||||
if exist(easyResultsDir, 'dir')
|
|
||||||
fprintf('WARNING: EASY results dir %s already exists\n', easyResultsDir);
|
|
||||||
disp('Files in this directory may be overwritten');
|
|
||||||
end
|
|
||||||
fprintf('Using output directory: %s from environment variable EASY_RESULTS_DIR\n', easyResultsDir);
|
fprintf('Using output directory: %s from environment variable EASY_RESULTS_DIR\n', easyResultsDir);
|
||||||
else
|
else
|
||||||
easyResultsDirName=strcat('Results_',todayStr,'_',userName,'_',easySuffix);
|
easyProject=strcat(todayStr,'_',userName,'_', project);
|
||||||
easyResultsDir=fullfile(scansDir,easyResultsDirName);
|
easyResultsDir=fullfile(parentDir, '..', '..', 'out', project, 'easy', easyProject);
|
||||||
if exist(easyResultsDir, 'dir')
|
if exist(easyResultsDir, 'dir')
|
||||||
fprintf('WARNING: EASY results dir %s already exists\n', easyResultsDir);
|
fprintf('WARNING: EASY results dir %s already exists\n', easyResultsDir);
|
||||||
disp('Files in this directory may be overwritten')
|
disp('Files in this directory may be overwritten')
|
||||||
@@ -140,12 +128,12 @@ function varargout = EASYconsole(varargin)
|
|||||||
fprintf('Using drug media file: %s from environment variable MASTER_PLATE_FILE\n', masterPlateFile);
|
fprintf('Using drug media file: %s from environment variable MASTER_PLATE_FILE\n', masterPlateFile);
|
||||||
else
|
else
|
||||||
% Try to find MasterPlate_ file on our own
|
% Try to find MasterPlate_ file on our own
|
||||||
mp=fullfile(scansDir,'MasterPlateFiles',strcat('MasterPlate_', easySuffix,'.xlsx'));
|
mp=fullfile(scansDir, strcat('MasterPlate_', project,'.xlsx'));
|
||||||
if exist(mp, 'file')
|
if exist(mp, 'file')
|
||||||
masterPlateFile=mp;
|
masterPlateFile=mp;
|
||||||
fprintf('Using drug media file: %s from internal logic\n', masterPlateFile);
|
fprintf('Using drug media file: %s from internal logic\n', masterPlateFile);
|
||||||
else
|
else
|
||||||
fprintf('WARNING: Have you created a MasterPlate_ file in %s/MasterPlateFiles/?\n', scansDir);
|
fprintf('WARNING: Have you created a MasterPlate_ file in %s/easy_in/?\n', scansDir);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -153,8 +141,7 @@ function varargout = EASYconsole(varargin)
|
|||||||
drugMediaFile=fullfile(getenv('DRUG_MEDIA_FILE'));
|
drugMediaFile=fullfile(getenv('DRUG_MEDIA_FILE'));
|
||||||
fprintf('Using drug media file: %s from environment variable DRUG_MEDIA_FILE\n', drugMediaFile);
|
fprintf('Using drug media file: %s from environment variable DRUG_MEDIA_FILE\n', drugMediaFile);
|
||||||
else
|
else
|
||||||
% Try to find MasterPlate_ file on our own
|
dm=fullfile(scansDir,'easy_in',strcat('DrugMedia_', project,'.xlsx'));
|
||||||
dm=fullfile(scansDir,'MasterPlateFiles',strcat('DrugMedia_', easySuffix,'.xlsx'));
|
|
||||||
if exist(mp, 'file')
|
if exist(mp, 'file')
|
||||||
drugMediaFile=dm;
|
drugMediaFile=dm;
|
||||||
fprintf('Using drug media file: %s from internal logic\n', drugMediaFile);
|
fprintf('Using drug media file: %s from internal logic\n', drugMediaFile);
|
||||||
@@ -163,12 +150,9 @@ function varargout = EASYconsole(varargin)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
matDir=fullfile(easyResultsDir,'matResults');
|
matDir=fullfile(easyResultsDir);
|
||||||
if ~exist(matDir, 'dir')
|
matFile=fullfile(matDir,easyResultsDirName,'.mat');
|
||||||
mkdir(matDir);
|
mpdmFile=fullfile(matDir,'MPDM.mat');
|
||||||
end
|
|
||||||
matFile=fullfile(matDir,strcat(easyResultsDirName,'.mat'));
|
|
||||||
% Pulled these out of par4GblFnc8c
|
|
||||||
printResultsDir=fullfile(easyResultsDir,'PrintResults');
|
printResultsDir=fullfile(easyResultsDir,'PrintResults');
|
||||||
fotosResultsDir=fullfile(easyResultsDir,'Fotos');
|
fotosResultsDir=fullfile(easyResultsDir,'Fotos');
|
||||||
figsResultsDir=fullfile(easyResultsDir,'figs');
|
figsResultsDir=fullfile(easyResultsDir,'figs');
|
||||||
@@ -176,8 +160,7 @@ function varargout = EASYconsole(varargin)
|
|||||||
pointMapsFile=fullfile(pointMapsResultsDir,'NImParameters.mat');
|
pointMapsFile=fullfile(pointMapsResultsDir,'NImParameters.mat');
|
||||||
oldPointMapsFile=fullfile(pointMapsResultsDir,'ImParameters.mat');
|
oldPointMapsFile=fullfile(pointMapsResultsDir,'ImParameters.mat');
|
||||||
searchRangeFile=fullfile(fotosResultsDir,'CSearchRange.mat');
|
searchRangeFile=fullfile(fotosResultsDir,'CSearchRange.mat');
|
||||||
mpdmFile=fullfile(matDir,'MPDM.mat');
|
|
||||||
|
|
||||||
% Decent time to print some helpful vars
|
% Decent time to print some helpful vars
|
||||||
if debug
|
if debug
|
||||||
disp('Vars at end of main loop:')
|
disp('Vars at end of main loop:')
|
||||||
@@ -190,6 +173,7 @@ function varargout = EASYconsole(varargin)
|
|||||||
if exist(searchRangeFile, 'file')
|
if exist(searchRangeFile, 'file')
|
||||||
searchRangeNum=load(searchRangeFile);
|
searchRangeNum=load(searchRangeFile);
|
||||||
end
|
end
|
||||||
|
|
||||||
% Add easyDir to the MATLAB path
|
% Add easyDir to the MATLAB path
|
||||||
% I have not idea if this is necessary or works but theoretically should
|
% I have not idea if this is necessary or works but theoretically should
|
||||||
% reduce directory scoping issues when calling scripts w/o a path
|
% reduce directory scoping issues when calling scripts w/o a path
|
||||||
@@ -197,12 +181,13 @@ function varargout = EASYconsole(varargin)
|
|||||||
|
|
||||||
% GUI interface design
|
% GUI interface design
|
||||||
gui_Singleton=1;
|
gui_Singleton=1;
|
||||||
gui_State=struct( 'gui_Name', mfilename, ...
|
gui_State=struct(...
|
||||||
'gui_Singleton', gui_Singleton, ...
|
'gui_Name', mfilename, ...
|
||||||
'gui_OpeningFcn', @EASYconsole_OpeningFcn, ...
|
'gui_Singleton', gui_Singleton, ...
|
||||||
'gui_OutputFcn', @EASYconsole_OutputFcn, ...
|
'gui_OpeningFcn', @EASYconsole_OpeningFcn, ...
|
||||||
'gui_LayoutFcn', [] , ...
|
'gui_OutputFcn', @EASYconsole_OutputFcn, ...
|
||||||
'gui_Callback', []);
|
'gui_LayoutFcn', [] , ...
|
||||||
|
'gui_Callback', []);
|
||||||
if nargin && ischar(varargin{1})
|
if nargin && ischar(varargin{1})
|
||||||
gui_State.gui_Callback=str2func(varargin{1});
|
gui_State.gui_Callback=str2func(varargin{1});
|
||||||
end
|
end
|
||||||
@@ -256,15 +241,15 @@ function varargout = EASYconsole_OutputFcn(~, ~, handles)
|
|||||||
varargout{1}=handles.output;
|
varargout{1}=handles.output;
|
||||||
end
|
end
|
||||||
|
|
||||||
%% CONSOLE BUTTON INTERFACES %%
|
% Console button interfaces
|
||||||
% File Button Interface
|
% File Button Interface
|
||||||
function FileMenu_Callback(~, ~, ~)
|
function FileMenu_Callback(~, ~, ~)
|
||||||
%returnStartDir
|
% returnStartDir
|
||||||
end
|
end
|
||||||
|
|
||||||
% Load Experiment Button Interface
|
% Load Experiment Button Interface
|
||||||
function LoadExp_Callback(~, ~, ~)
|
function LoadExp_Callback(~, ~, ~)
|
||||||
%returnStartDir
|
% returnStartDir
|
||||||
end
|
end
|
||||||
|
|
||||||
% New Experiment Button Interface
|
% New Experiment Button Interface
|
||||||
@@ -333,7 +318,7 @@ function NewExpDat_Callback(~, ~, ~)
|
|||||||
end
|
end
|
||||||
|
|
||||||
% set the title for fhconsole depending on existence
|
% set the title for fhconsole depending on existence
|
||||||
if exist('easyResultsDir','var')&&~isempty(easyResultsDir)
|
if exist('easyResultsDir','var') && ~isempty(easyResultsDir)
|
||||||
set(fhconsole,'Name',sprintf('EASYconsole - %s', easyResultsDir));
|
set(fhconsole,'Name',sprintf('EASYconsole - %s', easyResultsDir));
|
||||||
else
|
else
|
||||||
set(fhconsole,'Name','EASYconsole - Master Plate directory not selected.');
|
set(fhconsole,'Name','EASYconsole - Master Plate directory not selected.');
|
||||||
|
|||||||
Reference in New Issue
Block a user