Rename easyProjectDir

This commit is contained in:
2024-08-01 14:22:27 -04:00
parent e3f4c1ee9c
commit e2b399a34c
2 changed files with 80 additions and 69 deletions

View File

@@ -3,6 +3,7 @@
function varargout = EASYconsole(varargin) function varargout = EASYconsole(varargin)
global easyDir global easyDir
global projectName
global projectScansDir global projectScansDir
global easyResultsDir global easyResultsDir
global easyProjectName global easyProjectName
@@ -40,23 +41,32 @@ function varargout = EASYconsole(varargin)
fprintf('This script name: %s\n', easyFileName); fprintf('This script name: %s\n', easyFileName);
% Set projectScansDir (project scans directory) intelligently % Allow EASY_DIR env to override hardcoded default EASY directory
if ~isempty(getenv('EASY_DIR'))
ed=fullfile(getenv('EASY_DIR'));
if ~strcmp(easyDir, ed) % sanity check
disp("WARNING: EASY_DIR does not match this script's hardcoded EASY location");
disp("This is probably OK but this pathway is not well-tested");
easyDir=ed;
end
fprintf('Using EASY script directory: %s from environment variable EASY_DIR\n', easyDir);
else
fprintf('Using EASY script directory: %s from hardcoded default\n', easyDir);
end
% Set projectScansDir intelligently
if ~isempty(getenv('PROJECT_SCANS_DIR')) if ~isempty(getenv('PROJECT_SCANS_DIR'))
projectScansDir=fullfile(getenv('PROJECT_SCANS_DIR')); projectScansDir=fullfile(getenv('PROJECT_SCANS_DIR'));
if exist(projectScansDir, 'dir') if exist(projectScansDir, 'dir')
fprintf('Using scans directory: %s from environment variable PROJECT_SCANS_DIR\n', projectScansDir); fprintf('Using scans directory: %s from environment variable PROJECT_SCANS_DIR\n', projectScansDir);
disp('This usually indicates that we are in module mode'); disp('This usually indicates that we are in module mode');
if isempty(getenv('PROJECT'))
dirInfo=fileparts(projectScansDir);
project=dirInfo.name;
end
else else
disp('WARNING: PROJECT_SCANS_DIR does not exist'); disp('WARNING: PROJECT_SCANS_DIR does not exist');
end end
elseif ~isempty(getenv('PROJECT')) % for standalone mode elseif ~isempty(getenv('PROJECT_NAME')) % for standalone mode
% projectScansDir=fullfile(parentDir, '..', '..', 'scans', getenv('PROJECT') 'out', 'easy', getenv('PROJECT')); projectName=getenv('PROJECT_NAME');
project=getenv('PROJECT'); projectScansDir=fullfile(parentDir, '..', '..', 'scans', projectName);
projectScansDir=fullfile(parentDir, '..', '..', 'scans', project);
fprintf('Using project path: %s from environment variable PROJECT\n', projectScansDir); fprintf('Using project path: %s from environment variable PROJECT\n', projectScansDir);
disp('This usually indicates that we are in standalone mode'); disp('This usually indicates that we are in standalone mode');
else else
@@ -85,38 +95,21 @@ function varargout = EASYconsole(varargin)
end end
whos whos
if ~isempty(matchedDirs) if ~isempty(matchedDirs)
fprintf('Found a non-empty scans directory in our list: %s\n', d); fprintf('Using scansDir %s\n', char(d));
fprintf('Setting projectScansDir to %s\n', char(d));
projectScansDir=fullfile(d);
end end
fprintf('Scanning inside %s for a project directory\n', d); fprintf('Scanning inside %s for a project directory\n', d);
sortedMatchedDirs=sortrows(matchedDirs); sortedMatchedDirs=sortrows(matchedDirs);
project=sortedMatchedDirs{1}; % select the latest dir (by date prefix) projectScansDir=fullfile(sortedMatchedDirs{end}); % select the latest dir (by date prefix)
fprintf('Selected latest project directory %s\n', char(project)); fprintf('Using project scans directory: %s\n', char(projectScansDir));
break
end end
end end
end end
% User sanity check and warning % Get the name of the project
if ~isempty(getenv('PROJECT_USER')) projectName=basename(projectScansDir);
if ~strcmp(getenv('PROJECT_USER'), userName)
disp("WARNING: PROJECT_USER does not match the current namespace");
end
end
% Allow module to override hardcoded default EASY directory
if ~isempty(getenv('EASY_DIR'))
ed=fullfile(getenv('EASY_DIR'));
if ~strcmp(easyDir, ed) % sanity check
disp("WARNING: EASY_DIR does not match this script's hardcoded EASY location");
disp("This is probably OK but this pathway is not well-tested");
easyDir=ed;
end
fprintf('Using EASY script directory: %s from environment variable EASY_DIR\n', easyDir);
else
fprintf('Using EASY script directory: %s from hardcoded default\n', easyDir);
end
% Set the run-specific EASY output directory
if ~isempty(getenv('EASY_RESULTS_DIR')) if ~isempty(getenv('EASY_RESULTS_DIR'))
easyResultsDir=fullfile(getenv('EASY_RESULTS_DIR')); easyResultsDir=fullfile(getenv('EASY_RESULTS_DIR'));
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);
@@ -130,18 +123,32 @@ function varargout = EASYconsole(varargin)
end end
end end
% Get the name of the EASY project
if ~isempty(getenv('EASY_PROJECT_NAME'))
easyProjectName=getenv('EASY_PROJECT_NAME');
else
easyProjectName=basename(easyResultsDir);
end
% User sanity check and warning
if ~isempty(getenv('PROJECT_USER'))
if ~strcmp(getenv('PROJECT_USER'), userName)
disp("WARNING: PROJECT_USER does not match the current namespace");
end
end
if ~isempty(getenv('MASTER_PLATE_FILE')) if ~isempty(getenv('MASTER_PLATE_FILE'))
masterPlateFile=fullfile(getenv('MASTER_PLATE_FILE')); masterPlateFile=fullfile(getenv('MASTER_PLATE_FILE'));
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(projectScansDir, strcat('MasterPlate_', project,'.xlsx')); mp=fullfile(easyResultsDir, strcat('MasterPlate_', projectName,'.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 master plate file: %s from internal logic\n', masterPlateFile);
else else
fprintf('WARNING: Have you created a MasterPlate_ file in %s/easy_in/?\n', projectScansDir); fprintf('WARNING: Could not find MasterPlate file: %s\n', mp);
fprintf('WARNING: Have you created a MasterPlate_ file in %s', easyResultsDir);
end end
end end
@@ -149,17 +156,17 @@ 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
dm=fullfile(projectScansDir,'easy_in',strcat('DrugMedia_', project,'.xlsx')); dm=fullfile(easyResultsDir, strcat('DrugMedia_', projectName,'.xlsx'));
if exist(mp, 'file') if exist(dm, '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);
else else
fprintf('WARNING: Have you created a DrugMedia_ file in %s/MasterPlateFiles/?\n', projectScansDir); fprintf('WARNING: Have you created a DrugMedia_ file in %s?\n', easyResultsDir);
end end
end end
matDir=fullfile(easyResultsDir); matDir=fullfile(easyResultsDir, 'matResults');
matFile=fullfile(matDir,easyResultsDirName,'.mat'); matFile=fullfile(matDir,easyProjectName,'.mat');
mpdmFile=fullfile(matDir,'MPDM.mat'); mpdmFile=fullfile(matDir,'MPDM.mat');
printResultsDir=fullfile(easyResultsDir,'PrintResults'); printResultsDir=fullfile(easyResultsDir,'PrintResults');
fotosResultsDir=fullfile(easyResultsDir,'Fotos'); fotosResultsDir=fullfile(easyResultsDir,'Fotos');
@@ -265,7 +272,7 @@ function NewExpDat_Callback(~, ~, ~)
global matDir global matDir
global matFile global matFile
global easyResultsDir global easyResultsDir
global easyResultsDirName global easyProjectName
global fhconsole global fhconsole
global scan global scan
global userName global userName
@@ -276,12 +283,11 @@ function NewExpDat_Callback(~, ~, ~)
questdlg('\fontsize{20} NAME the file and NAVIGATE to the directory with the image folders.','File Creation','OK', struct('Default','OK','Interpreter','tex')); questdlg('\fontsize{20} NAME the file and NAVIGATE to the directory with the image folders.','File Creation','OK', struct('Default','OK','Interpreter','tex'));
[matfile,easyResultsDir]=uiputfile('.mat'); [matfile,easyResultsDir]=uiputfile('.mat');
inputFileName=strrep(inputFile,'.mat',''); inputFileName=strrep(inputFile,'.mat','');
% easyResultsDirName=strcat('Results_',todayStr,'_',userName,'_',inputFileName);
project=basename(easyResultsDir); projectName=basename(easyResultsDir);
% Set paths % Set paths
matDir=fullfile(easyResultsDir,'matResults'); matDir=fullfile(easyResultsDir,'matResults');
easyProjectName=strcat(todayStr,'_',userName,'_', project); matFile=fullfile(matDir, projectName, '.mat');
matFile=fullfile(matDir,strcat(todayStr,'_',userName,'_',inputFile));
% Added for 'parfor global' to preallocate 'scan' structure % Added for 'parfor global' to preallocate 'scan' structure
nlist=dir(fullfile(projectScansDir,'*')); nlist=dir(fullfile(projectScansDir,'*'));
@@ -338,19 +344,19 @@ end
function LoadDatFile_Callback(~, ~, ~) function LoadDatFile_Callback(~, ~, ~)
global matDir global matDir
global matFile global matFile
global projectName
global easyResultsDir global easyResultsDir
global easyProjectName
global easyPath global easyPath
global fhconsole global fhconsole
try try
questdlg('Load results .mat from ../out/project/','File Creation','OK', struct('Default','OK','Interpreter','tex')); questdlg('Load results .mat from ../out/project/','File Creation','OK', struct('Default','OK','Interpreter','tex'));
[inputFile,inputPath]=uigetfile('.mat','Open Experiment folder and data storage .mat file name','MultiSelect','off'); [matDir,matFile]=uigetfile('.mat','Open Experiment folder and data storage .mat file name','MultiSelect','off');
matDir=fullfile(inputPath);
matFile=fullfile(inputPath,inputFile);
load(matFile); load(matFile);
easyResultsDir=fullfile(matDir,'..'); easyResultsDir=fullfile(matDir,'..');
project=basename(easyResultsDir); projectName=basename(easyResultsDir);
projectScansDir=fullfile(easyResultsDir, '..', '..', 'scans', project); projectScansDir=fullfile(easyResultsDir, '..', '..', 'scans', projectName);
% TODO this is pretty hacky and needs something more explicit % TODO this is pretty hacky and needs something more explicit
if isfolder(fullfile(matDir, '..','..','1')) % If Inovation Vrobot Then if isfolder(fullfile(matDir, '..','..','1')) % If Inovation Vrobot Then

View File

@@ -592,10 +592,14 @@ easy() {
script="$EASY_DIR/EASYconsole.m" script="$EASY_DIR/EASYconsole.m"
# Prompt user for suffix # Prompt user for suffix
echo "Default EASY results directory: $EASY_RESULTS_DIR" echo "Using default EASY results directory: $EASY_RESULTS_DIR"
((YES)) || read -r -p "Enter a custom suffix and/or hit enter to use the default (no suffix): " EASY_SUFFIX ((YES)) || read -r -p "Enter a custom suffix and/or hit enter to use the default (no suffix): " EASY_SUFFIX
[[ -n $EASY_SUFFIX ]] && EASY_RESULTS_DIR+="_$EASY_SUFFIX" [[ -n $EASY_SUFFIX ]] && EASY_RESULTS_DIR+="_$EASY_SUFFIX"
# This dirname is separate from the project's so multiple EASY results can be generated
declare -gx EASY_PROJECT_NAME="${EASY_RESULTS_DIR##*/}"
debug "EASY results output name: $EASY_PROJECT_NAME"
# Backup and create EASY results dirs # Backup and create EASY results dirs
[[ -d $EASY_RESULTS_DIR ]] && backup "$EASY_RESULTS_DIR" [[ -d $EASY_RESULTS_DIR ]] && backup "$EASY_RESULTS_DIR"
[[ -d $EASY_RESULTS_DIR ]] || mkdir -p "$EASY_RESULTS_DIR" [[ -d $EASY_RESULTS_DIR ]] || mkdir -p "$EASY_RESULTS_DIR"
@@ -1566,22 +1570,23 @@ main() {
done done
# Loop over projects # Loop over projects
for PROJECT in "${PROJECTS[@]}"; do for PROJECT_NAME in "${PROJECTS[@]}"; do
declare -gx PROJECT_SCANS_DIR="$SCANS_DIR/$PROJECT" declare -gx PROJECT_NAME
declare -gx PROJECT_DATE="${PROJECT%"${PROJECT#????????}"}" # e.g. 20240723 declare -gx PROJECT_SCANS_DIR="$SCANS_DIR/$PROJECT_NAME"
declare -gx PROJECT_SUFFIX="${PROJECT#????????_*_}" declare -gx PROJECT_DATE="${PROJECT_NAME%"${PROJECT_NAME#????????}"}" # e.g. 20240723
declare -gx PROJECT_USER="${PROJECT#????????_}"; PROJECT_USER="${PROJECT_USER%%_*}" declare -gx PROJECT_SUFFIX="${PROJECT_NAME#????????_*_}"
declare -gx PROJECT_USER="${PROJECT_NAME#????????_}"; PROJECT_USER="${PROJECT_USER%%_*}"
declare -gx STUDIES_ARCHIVE_FILE="$OUT_DIR/StudiesDataArchive.txt" declare -gx STUDIES_ARCHIVE_FILE="$OUT_DIR/StudiesDataArchive.txt"
declare -gx QHTCP_PROJECT_DIR="$OUT_DIR/$PROJECT" declare -gx QHTCP_PROJECT_DIR="$OUT_DIR/$PROJECT_NAME"
declare -gx QHTCP_TEMPLATE_DIR="$TEMPLATES_DIR/qhtcp" declare -gx QHTCP_TEMPLATE_DIR="$TEMPLATES_DIR/qhtcp"
declare -gx STUDY_TEMPLATE_DIR="$TEMPLATES_DIR/exp" declare -gx STUDY_TEMPLATE_DIR="$TEMPLATES_DIR/exp"
declare -gx STUDY_INFO_FILE="$QHTCP_PROJECT_DIR/StudyInfo.csv" declare -gx STUDY_INFO_FILE="$QHTCP_PROJECT_DIR/StudyInfo.csv"
declare -gx EASY_OUT_DIR="$QHTCP_PROJECT_DIR/easy" declare -gx EASY_OUT_DIR="$QHTCP_PROJECT_DIR/easy"
if ((DEBUG)); then if ((DEBUG)); then
declare -p SCANS_DIR OUT_DIR TEMPLATES_DIR APPS_DIR \ declare -p SCANS_DIR OUT_DIR TEMPLATES_DIR APPS_DIR \
PROJECTS PROJECT \ PROJECTS PROJECT_NAME \
PROJECT_SCANS_DIR PROJECT_DATE PROJECT_SUFFIX \ PROJECT_SCANS_DIR PROJECT_DATE PROJECT_SUFFIX PROJECT_USER \
PROJECT_USER STUDIES_ARCHIVE_FILE QHTCP_PROJECT_DIR QHTCP_TEMPLATE_DIR \ STUDIES_ARCHIVE_FILE QHTCP_PROJECT_DIR QHTCP_TEMPLATE_DIR \
STUDY_TEMPLATE_DIR STUDY_INFO_FILE STUDY_TEMPLATE_DIR STUDY_INFO_FILE
fi fi