% Remove SPM from the common folder from your matlabpath
% Instead add with subfolders in the matlab path: /home/control/ilima/PULSE_data/spm8 as this contains the gPPI toolbox

% to run on current Mentat: for s = 3001:3032; PPI_Stroop_IM_RK2(s); end  
% can also run on torque

function PPI_TD_parietal(subject)  
%  subject=101;
 %try
  
%Set current directory
% for s = 1: length (subject);
%     subject = s;
%   clea
dir_level1='/home/decision/eridwat/Data/CombinedData'; 
% dir_level2='/home/decision/eridwat/Data/nifti/SPMfiles_PPI_TD_dACC';
folder1='models';
folder2 ='TDpar';
toolboxdir = '/home/decision/eridwat/spm8';
display ('busy')
% Add the path to the gPPPI toolbox. I'm assuming SPM8 is already in the path.
spmpath=fileparts(which('spm.m'));
addpath([toolboxdir filesep 'toolbox']);
addpath([toolboxdir filesep 'toolbox' filesep 'PPPI']);
spm('defaults','fmri')

display('checkpoint')
% Set up the control param structure P which determines the run
%name_ROI = 'All_-8_6_0';
name_ROI = 'parietal';
main_dir=fullfile(dir_level1, sprintf('%3d', subject), folder1, folder2);
display(main_dir);
name_ROInii = sprintf('%s.nii',name_ROI);
P.subject = sprintf('%3d',subject);
P.directory = main_dir;
P.VOI = fullfile('/home/decision/eridwat/Data/nifti/PPI_seeds',name_ROInii);

P.Region=name_ROI;
P.analysis='psy';
P.method='cond';
P.Estimate=1;
P.contrast=0; % 
P.extract='eig'; 

%display(fullfile(P.directory, ['PPI_' name_ROI]));

% P.Tasks={} ;
% MvH Would Tasks = {} be helpful for example if I have some condition (e.g. missed responses) that may occur for some,but not all, subjects on some sessions? Would leaving it empty yield the exact same results as long as I am sure no condition is missing for any subject?
% DmcL>> Yes. You could do this, just be aware that if other conditions are missing the program will not tell you. Contrasts using a missing condition will not be computed.
% this will model all available regressors (fixes the unequal misses
% between sessions).
% 
% P.Tasks ={ '1'...
%     'WcR1' 'WiR_ir1' 'WiR_in1' 'WcN1' 'WiN_ir1' 'WiN_in1'...
%     'WcR2' 'WiR_ir2' 'WiR_in2' 'WcN2' 'WiN_ir2' 'WiN_in2'};
P.Tasks ={ '0'...
  'DRmoney' 'IRmoney' 'Control' 'DRcandy' 'IRcandy'};

% P.Tasks ={ '1'...
%     'WiN_in1' 'WiN_in2'...
%     'WcN1', 'WcN2'};

P.Weights=[];
P.equalroi=0; % default is 1, and error occurs because VOI extends outside subject mask (e.g. OFC edge)
% Set P.equalroi=0 and P.FLmask=1; this will allow unequal sized ROI and allow them to be trimmed by the 1st level mask.
% http://www.nitrc.org/forum/message.php?msg_id=11928


P.FLmask=1; % default is 0
P.CompContrasts=1; % default is 0

P.Contrasts(1).name='TD_control';
P.Contrasts(1).left={'DRmoney' 'DRcandy' 'IRmoney' 'IRcandy'};
P.Contrasts(1).right={'Control'};
P.Contrasts(1).MinEvents=1;
P.Contrasts(1).STAT='T';

% 
% P.Contrasts(4).name='StroopIRReward';
% P.Contrasts(4).left=    {'WiR_ir1' 'WiR_ir2'};
% P.Contrasts(4).right=  {'WcR1' 'WcR2'};
% P.Contrasts(4).MinEvents=1;
% P.Contrasts(4).STAT='T';
% 
% 
% P.Contrasts(5).name='StroopReward';
% P.Contrasts(5).left=    {'WiN_ir1' 'WiN_ir2'};
% P.Contrasts(5).right=  {'WcN1' 'WcN2'};
% P.Contrasts(5).MinEvents=1;
% P.Contrasts(5).STAT='T';


% P.Contrasts(3).name='Sn1reward';
% P.Contrasts(3).Prefix.Left={'Sn(1) PPI_Cue_high' };
% P.Contrasts(3).Prefix.Right ={'Sn(1) PPI_Cue_low' };
% P.Contrasts(3).MinEvents=1;
% P.Contrasts(3).STAT='T';
% % Sn(1) Cue_low
% P.Contrasts(4).name='Sn1RCA';
% P.Contrasts(4).prefix.left={'Sn(1) PPI_low_Ts_Rr_Arrow' 'Sn(1) PPI_low_Ts_Rr_Word' 'Sn(1) PPI_high_Tr_Rr_Arrow' 'Sn(1) PPI_high_Tr_Rr_Word'  'Sn(1) PPI_low_Tr_Rs_Arrow' 'Sn(1) PPI_low_Tr_Rs_Word' 'Sn(1) PPI_high_Ts_Rs_Arrow' 'Sn(1) PPI_high_Ts_Rs_Word'};
% P.Contrasts(4).prefix.right={'Sn(1) PPI_low_Tr_Rr_Arrow' 'Sn(1) PPI_low_Tr_Rr_Word' 'Sn(1) PPI_low_Ts_Rs_Arrow' 'Sn(1) PPI_low_Ts_Rs_Word' 'Sn(1) PPI_high_Tr_Rs_Arrow' 'Sn(1) PPI_high_Tr_Rs_Word' 'Sn(1) PPI_high_Ts_Rr_Arrow' 'Sn(1) PPI_high_Ts_Rr_Word'};
% P.Contrasts(4).MinEvents=1;
% P.Contrasts(4).STAT='T';
% 
% P.Contrasts(5).name='Sn2reward';
% P.Contrasts(5).Prefix.Left ={'Sn(2) PPI_Cue_high' };
% P.Contrasts(5).Prefix.Right ={'Sn(2) PPI_Cue_low' };
% P.Contrasts(5).MinEvents=1;
% P.Contrasts(5).STAT='T';
% 
% P.Contrasts(6).name='Sn2RCA';
% P.Contrasts(6).Prefix.Left={'Sn(2) PPI_low_Ts_Rr_Arrow' 'Sn(2) PPI_low_Ts_Rr_Word' 'Sn(2) PPI_high_Tr_Rr_Arrow' 'Sn(2) PPI_high_Tr_Rr_Word'  'Sn(2) PPI_low_Tr_Rs_Arrow' 'Sn(2) PPI_low_Tr_Rs_Word' 'Sn(2) PPI_high_Ts_Rs_Arrow' 'Sn(2) PPI_high_Ts_Rs_Word'};
% P.Contrasts(6).Prefix.Right={'Sn(2) PPI_low_Tr_Rr_Arrow' 'Sn(2) PPI_low_Tr_Rr_Word' 'Sn(2) PPI_low_Ts_Rs_Arrow' 'Sn(2) PPI_low_Ts_Rs_Word' 'Sn(2) PPI_high_Tr_Rs_Arrow' 'Sn(2) PPI_high_Tr_Rs_Word' 'Sn(2) PPI_high_Ts_Rr_Arrow' 'Sn(2) PPI_high_Ts_Rr_Word'};
% P.Contrasts(6).MinEvents=1;
% P.Contrasts(6).STAT='T';
% 
% P.Contrasts(7).name='Sn12reward';
% P.Contrasts(7).Prefix.Left={'Sn(2) PPI_Cue_high' 'Sn(1) PPI_Cue_low' };
% P.Contrasts(7).Prefix.Righ={'Sn(2) PPI_Cue_low' 'Sn(1) PPI_Cue_high' };
% P.Contrasts(7).MinEvents=1;
% P.Contrasts(7).STAT='T';
% % %
% %
% % % interaction between RCA and 2 OFC sessions, baseline has 'normal' (i.e.
% % % congruent < incongruent @ low) interaction, OFC opposite.
% P.Contrasts(8).name='Sn12RCA';
% P.Contrasts(8).Prefix.Left={...
%     'Sn(2) PPI_low_Ts_Rr_Arrow' 'Sn(2) PPI_low_Ts_Rr_Word' ...
%     'Sn(2) PPI_high_Tr_Rr_Arrow' 'Sn(2) PPI_high_Tr_Rr_Word'...
%     'Sn(2) PPI_low_Tr_Rs_Arrow' 'Sn(2) PPI_low_Tr_Rs_Word'...
%     'Sn(2) PPI_high_Ts_Rs_Arrow' 'Sn(2) PPI_high_Ts_Rs_Word'...
%     'Sn(1) PPI_low_Tr_Rr_Arrow' 'Sn(1) PPI_low_Tr_Rr_Word' ...
%     'Sn(1) PPI_low_Ts_Rs_Arrow' 'Sn(1) PPI_low_Ts_Rs_Word'...
%     'Sn(1) PPI_high_Tr_Rs_Arrow' 'Sn(1) PPI_high_Tr_Rs_Word'...
%     'Sn(1) PPI_high_Ts_Rr_Arrow' 'Sn(1) PPI_high_Ts_Rr_Word'...
%     };
% P.Contrasts(8).Prefix.Right={...
%     'Sn(2) PPI_low_Tr_Rr_Arrow' 'Sn(2) PPI_low_Tr_Rr_Word' ...
%     'Sn(2) PPI_low_Ts_Rs_Arrow' 'Sn(2) PPI_low_Ts_Rs_Word'...
%     'Sn(2) PPI_high_Tr_Rs_Arrow' 'Sn(2) PPI_high_Tr_Rs_Word'...
%     'Sn(2) PPI_high_Ts_Rr_Arrow' 'Sn(2) PPI_high_Ts_Rr_Word'...
%     'Sn(1) PPI_low_Ts_Rr_Arrow' 'Sn(1) PPI_low_Ts_Rr_Word' ...
%     'Sn(1) PPI_high_Tr_Rr_Arrow' 'Sn(1) PPI_high_Tr_Rr_Word'...
%     'Sn(1) PPI_low_Tr_Rs_Arrow' 'Sn(1) PPI_low_Tr_Rs_Word'...
%     'Sn(1) PPI_high_Ts_Rs_Arrow' 'Sn(1) PPI_high_Ts_Rs_Word'...
%     };
% P.Contrasts(8).MinEvents=1;
% P.Contrasts(8).STAT='T';
 
 %catch e
  %    fprintf('!!! Niet gelukt voor %d: %s\n', subject, getReport(e));
  % end
% PPPI(P, [workdir filesep 'sampleData' filesep 'stats' filesep 'gPPI_sampleDataTest.mat']);
PPPI(P, fullfile(P.directory, ['gPPI_' name_ROI]));
 end