Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions FirstLevel/FirstLevel_mc_template.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,30 @@
%%% These options are the same between Preprocessing and First level
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% The path to SPM on your system
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
spmpath = '/net/dysthymia/spm8';

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% The folder that contains your subject folders
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Exp = '/net/data4/MAS/';

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Path where your logfiles will be stored
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
LogTemplate = '[Exp]/Logs';

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Path where your images are located
%%
%% Variables you can use in your template are:
%% Exp = path to your experiment directory
%% iSubject = index for subject
%% Subject = name of subject from SubjDir (using iSubject as index of row)
%% iRun = index of run (listed in Column 3 of SubjDir)
%% Run = name of run from RunDir (using iRun as index of row)
%% * = wildcard (can only be placed in final part of template)
%% Examples:
%% ImageTemplate = '[Exp]/Subjects/[Subject]/func/run_0[iRun]/';
%% ImageTemplate = '[Exp]/Subjects/[Subject]/TASK/func/[Run]/'
%%% Path where your images are located
%%%
%%% Variables you can use in your template are:
%%% Exp = path to your experiment directory
%%% iSubject = index for subject
%%% Subject = name of subject from SubjDir (using iSubject as index of row)
%%% iRun = index of run (listed in Column 3 of SubjDir)
%%% Run = name of run from RunDir (using iRun as index of row)
%%% * = wildcard (can only be placed in final part of template)
%%% Examples:
%%% ImageTemplate = '[Exp]/Subjects/[Subject]/func/run_0[iRun]/';
%%% ImageTemplate = '[Exp]/Subjects/[Subject]/TASK/func/[Run]/'
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ImageTemplate = '[Exp]/Subjects/[Subject]/TASK/func/[Run]zz/';

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -389,6 +387,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end

global mcRoot;
%DEVSTART
mcRoot = fullfile(fileparts(mfilename('fullpath')),'..');
%DEVSTOP
Expand Down
14 changes: 12 additions & 2 deletions FirstLevel/PreprocessFirstLevel_central.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
%%% Instead make a copy of PreprocessingFirstLevel_template.m
%%% and edit that to match your data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
addpath /net/dysthymia/slab/users/sripada/repos/matlabScripts %%%% this is for generate_path_CSS

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Code to create logfile name
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
LogDirectory = mc_GenPath(struct('Template',LogTemplate,'mode','makedir'));
result = mc_Logger('setup',LogDirectory);
if (~result)
%error with setting up logging
mc_Error('There was an error creating your logfiles.\nDo you have permission to write to %s?',LogDirectory);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% General calculations that apply to both Preprocessing and First Level
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -38,7 +48,7 @@
Pwra = [nop rep stp];
Pswra = [smp nop rep stp];

addpath(spmpath);
%addpath(spmpath);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear, this was removed since path adding happens in the template script now, right?

addpath(pwd);
spm('defaults','fmri');
global defaults
Expand Down
9 changes: 5 additions & 4 deletions FirstLevel/Preprocess_mc_template.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% The path to SPM on your system
%%% The folder that contains your subject folders
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
spmpath = '/net/dysthymia/spm8';
Exp = '/net/data4/MAS/';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are good fixes, but some are going to make pulling in @heffjos pull request that has similar changes to Preprocess_mc_template and similar changes in FirstLevel_mc_template a bit tricky. check out the diff at https://github.com/UMPsychMethodsCore/MethodsCore/pull/43/files#diff-10


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% The folder that contains your subject folders
%%% Path where your logfiles will be stored
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Exp = '/net/data4/MAS/';
LogTemplate = '[Exp]/Logs';


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -203,6 +203,7 @@
donormalize = 1;
dosmooth = 1;

global mcRoot;
%DEVSTART
mcRoot = fullfile(fileparts(mfilename('fullpath')),'..');
%DEVSTOP
Expand Down
9 changes: 6 additions & 3 deletions matlabScripts/mc_Error.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function mc_Error(errorString,varargin)
% A utility function to make error handling and logging more compact
% A single call to mc_Error will log the error to the global mc_LogName,
% A single call to mc_Error will log the error to the global mcLog,
% bring up an error dialog box with your error message, and actually throw
% an exception with the Matlab error function.
%
Expand Down Expand Up @@ -37,8 +37,11 @@ function mc_Error(errorString,varargin)
errormsg = errorString;
end

%add future code to call mc_Logger with loglevel Error

global mcLog
if (~isempty(mcLog))
%call logging function
mc_Logger('log',errormsg,1);
end
errordlg(errormsg);
error(errormsg);

Expand Down
114 changes: 114 additions & 0 deletions matlabScripts/mc_Logger.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
function result = mc_Logger(cmd,argument,loglevel)
% A utility function to setup script copies and log messages to a log file
% FORMAT [result] = mc_Logger(cmd,cmdstring[,loglevel]);
%
% cmd this command tells mc_Logger what mode to run in.
% Current options are:
% 'setup' - create a timestamped copy of the
% original calling script (usually the
% _mc_template script) and create a log
% file in the given directory. In this
% mode cmdstring should contain the log
% directory and loglevel is not needed.
% 'log' - write cmdstring to the log file.
%
% cmdstring in 'setup' mode this should be the log file directory
% to use. In 'log' mode this should be the string that
% will be written to the log file.
%
% loglevel This optional argument should only be used in 'log'
% mode. If given, it sets the level of importance for the
% current cmdstring. Current possible values are:
% 1 - ERROR
% 2 - WARNING
% 3 - STATUS
% If not given, it defaults to 1 (ERROR).
%

result = 0;
global mcLog;
global mcRoot;
switch(lower(cmd))
case 'setup'
%create copy of template script and create log file
[st i] = dbstack('-completenames');
callingscript = st(end).file;
[p f e ans] = fileparts(callingscript);
rightnow = now;
scriptcopy = fullfile(cmdstring,[f '_' datestr(rightnow,'yyyy-mm-dd_HHMMSSFFF') e]);
scriptlog = fullfile(cmdstring,[f '_' datestr(rightnow,'yyyy-mm-dd_HHMMSSFFF') '.log']);

headertxt = '';
lines = 0;
if (exist(fullfile(mcRoot,'.local/mc_releasetag')))
if (exist(fullfile(mcRoot,'.local/CurrentVersionSHA')))
%prepend both release and SHA to template copy
headertxt = sprintf('''This script was run on %s using the Methods Core release and SHA listed below''',datestr(rightnow,'mm/dd/yyyy HH:MM:SS'));
shellcommand = sprintf('echo %s | cat - %s %s %s > %s',headertxt,fullfile(mcRoot,'.local/mc_releasetag'),fullfile(mcRoot,'.local/CurrentVersionSHA'),callingscript,scriptcopy);
lines = 3;
else
%prepend just release to template copy
headertxt = sprintf('''This script was run on %s using the Methods Core release listed below''',datestr(rightnow,'mm/dd/yyyy HH:MM:SS'));
shellcommand = sprintf('echo %s | cat - %s %s > %s',headertxt,fullfile(mcRoot,'.local/mc_releasetag'),callingscript,scriptcopy);
lines = 2;
end
else
if (exist(fullfile(mcRoot,'.local/CurrentVersionSHA')))
%prepend just SHA to template copy
headertxt = sprintf('''This script was run on %s using the Methods Core SHA listed below''',datestr(rightnow,'mm/dd/yyyy HH:MM:SS'));
shellcommand = sprintf('echo %s | cat - %s %s > %s',headertxt,fullfile(mcRoot,'.local/CurrentVersionSHA'),callingscript,scriptcopy);
lines = 2;
else
%neither release nor SHA exist, just make template copy
headertxt = sprintf('''This script was run on %s''',datestr(rightnow,'mm/dd/yyyy HH:MM:SS'));
shellcommand = sprintf('echo %s | cat - %s > %s',headertxt,callingscript,scriptcopy);
lines = 1;
end
end
[status r] = system(shellcommand);
if (status ~= 0)
mc_Error(r);
end
shellcommand = sprintf('sed -i ''%s,%s s/^/%%/'' %s',num2str(1),num2str(lines),scriptcopy);
[status r] = system(shellcommand);
if (status ~= 0)
mc_Error(r);
end

mcLog = scriptlog;
result = 1;
case 'log'
if (~exist(loglevel,'var') || isempty(loglevel))
loglevel = 1;
end
switch(loglevel)
case 1
loglevelstr = 'ERROR: ';
case 2
loglevelstr = 'WARNING: ';
case 3
loglevelstr = 'STATUS: ';
otherwise
loglevelstr = 'UNKNOWN: ';
end
%log cmdstring to log file
if (isempty(mcLog))
%no log file defined
%just return so that scripts using mc_Error but not mcLog global
%can still function without errors
return;
end
if (exist('cmdstring')~=1 || isempty(cmdstring))
%function called but we didn't get anything to log
return;
end
fid = fopen(mcLog,'a');
if (fid == -1)
%could not open file for some reason
mc_Error('Could not open logfile %s for writing.',mcLog);
end
fprintf(fid,'%s\t%s\n',loglevelstr,cmdstring);
result = 1;
end

return;