% prerona - 22/Dec/2013
% Inputs necessary to run everything from start to finish.  Outside inputs
% necessary are the names of what VOI will be used, along with its
% coordinates.
%
% Modified from Akos's gPPPI wrapper. Changed all parameter setting to root
% script. 
%
% B - CONTROLS
%
% ========================================================================
%
% Last Change Date: 18-Mar-2014
%
% VOI - Left Amygdala
% Derivation: Regions which showed pattern of greater activation with
% loading: None < Neutral < Fear




addpath(genpath('/media2/Data/fmri/scripts/downloaded_ppiscripts'));
addpath(genpath('/home/mohantylab/SPM'));
addpath(genpath('/media2/Data/fmri/scripts/ppi'));

VOIname = 'l_amy_tr';
VOIdef = 'sphere';                                  % type of VOI
VOIradius = 8; 

nsessions = 8; %this refers to the number of contrasts, at least here
rootDIR         = '/media2/Data/fmri';
data_dir = 'data';
first_lev_dir = 'Stats_Analysis_EPI';
prefix = 'Sub_';
amr_postfix = '_nback_EPI';
amr_prefix = 'Stats_sub_';
directories = [44]
    %217 243 259 269 289 364 379 380 400 409 441 458 487 530 611 631 634 670 676 687 706 717 763 764 780 796 797 801 802 809 866 881 929 933 955 973 980 1000 1007 1026 1035 1092 1095 1096 1141 1188 1198 1433 17 223 124]; 

% LEFT OUT - 565 (not found) 

contrasts={'Fear_v_Neut','Fear_v_None','Neut_v_None','Neut_v_Fear','FearNeut_v_None','Fear_all','Neut_all','None_all'};
% Fear_v_Neut','Fear_v_None','Neut_v_None','Neut_v_Fear','FearNeut_v_None'
% pos neu neg negVneu posVneu valen arous neuVneg
% neg v neu; pos v neu; pos v neg; pos+neg v neu; neu v neg

%All naming of VOIs should be done from here.  The convention currently is
%to do an underscore, followed by the name of the region, followed by where
%you got it from (paper authors, group from which it was obtained)
%this should be a variable called additions, which should be a cell
%composed of strings.
%There should also be variables X, Y, and Z.  These should be matrices
%(they should be in [] brackets) containing integers, either positive or
%negative.  X is for the X coordinate in MNI space, Y is for the Y
%coordinate, and Z is for Z.  Note: MNI space is in mm, not voxels.
%functional defined right dorsal ACC
additions={'Left_Amy_trend'}; % converted to MNI (were from mriCron)
 X=[-34.3434];
 Y=[-69.0880];
 Z=[-25.4477];
 
 
% Please attempt to put every instance of additions in here.  This will
% serve as an accumulated record of what has been run.


% % All actual steps proceed from here. (Note: any attempts to re-run
% % preprocessing and so on will need to alter the code slightly to only run
% % on usable subjects.  Which subjects are usable are found in the log and
% % in the PPI codes.
% PreProcessBatch4 %standard preprocessing
% preProc_11001 %preprocessing for 11001 (it never
% % cooperates)
% Individual_batch_due_to_errors_v2 %preprocessing for 11117
% % PreProcess_11140 %preprocessing for 11140 (also never cooperates)
% % (deprecated)
% design_attempt_12 %standard processing
% % Re_process_after_testing %processing 11001 (may not be necessary)
% % Process_due_to_errors %processing 11117 (may not be necessary)
% % Process_11140 %processing 11140 (deprecated)
% group_stats_4 %this does second-level analyses based on contrast alone,
% % which can be useful
% group_stats_7 %this does second-level analyses based on group and
% % contrast, which is the standard approach
% Flex_fact_v1 %This performs flexible factorial analyses on the processed
% % data.  This may or may not be useful, but it's good to have.
for i=1:length(additions)
    Contrast_names={1};
    for x=1:length(contrasts)
        Contrast_names(x)=cellstr(strcat(contrasts(x),'_',additions(i)));
    end
    %seed=char(additions{i}(2:end));
    seed=char(additions{i}(1:end));
    
    batch_spm2_VOI(VOIname,VOIdef,VOIradius,nsessions,prefix,amr_prefix,amr_postfix,first_lev_dir,rootDIR,directories,Contrast_names,double(X(i)),double(Y(i)),double(Z(i))) %creates the VOIs
%     PPI_1_group_v_2(Contrast_names) %runs PPI from the VOI just created
%     PPI_last_step_v_1(Contrast_names) %performs first-level analyses on the PPI
%     group_stats_8(Contrast_names) %performs second-level analyses on the results
    PPPI_v_2(seed,directories,contrasts,prefix,data_dir,rootDIR)
%     group_stats_9(seed) 
%     group_stats_10(seed)
    Flex_fact_v3(seed)
end
% batch_beta_extract_v6
