#!/bin/tcsh -xef echo "auto-generated by afni_proc.py, Thu May 26 14:41:33 2016" echo "(version 4.60, May 3, 2016)" echo "execution started: `date`" # execute via : # tcsh -xef proc.CAJe_110 |& tee output.proc.CAJe_110 # =========================== auto block: setup ============================ # script setup # take note of the AFNI version afni -ver # check that the current AFNI version is recent enough afni_history -check_date 28 Oct 2015 if ( $status ) then echo "** this script requires newer AFNI binaries (than 28 Oct 2015)" echo " (consider: @update.afni.binaries -defaults)" exit endif # the user may specify a single subject to run with if ( $#argv > 0 ) then set subj = $argv[1] else set subj = CAJe_110 endif # assign output directory name set output_dir = $subj.results # verify that the results directory does not yet exist if ( -d $output_dir ) then echo output dir "$subj.results" already exists exit endif # set list of runs set runs = (`count -digits 2 1 1`) # create results and stimuli directories mkdir $output_dir mkdir $output_dir/stimuli # copy anatomy to results dir 3dcopy /mnt/nfs2/users/alans/CAJe/CAJe_110BRIKS/CAJe_110+orig \ $output_dir/CAJe_110 # ============================ auto block: tcat ============================ # apply 3dTcat to copy input dsets to results dir, while # removing the first 2 TRs 3dTcat -prefix $output_dir/pb00.$subj.r01.tcat \ /mnt/nfs2/users/alans/CAJe/CAJe_110BRIKS/CAJe_110MS+orig'[2..$]' # and make note of repetitions (TRs) per run set tr_counts = ( 368 ) # ------------------------------------------------------- # enter the results directory (can begin processing data) cd $output_dir # ========================== auto block: outcount ========================== # data check: compute outlier fraction for each volume touch out.pre_ss_warn.txt foreach run ( $runs ) 3dToutcount -automask -fraction -polort 4 -legendre \ pb00.$subj.r$run.tcat+orig > outcount.r$run.1D # outliers at TR 0 might suggest pre-steady state TRs if ( `1deval -a outcount.r$run.1D"{0}" -expr "step(a-0.4)"` ) then echo "** TR #0 outliers: possible pre-steady state TRs in run $run" \ >> out.pre_ss_warn.txt endif end # catenate outlier counts into a single time series cat outcount.r*.1D > outcount_rall.1D # get run number and TR index for minimum outlier volume set minindex = `3dTstat -argmin -prefix - outcount_rall.1D\'` set ovals = ( `1d_tool.py -set_run_lengths $tr_counts \ -index_to_run_tr $minindex` ) # save run and TR indices for extraction of vr_base_min_outlier set minoutrun = $ovals[1] set minouttr = $ovals[2] echo "min outlier: run $minoutrun, TR $minouttr" | tee out.min_outlier.txt # ================================ despike ================================= # apply 3dDespike to each run foreach run ( $runs ) 3dDespike -NEW -ignore 2 -nomask -prefix pb01.$subj.r$run.despike \ pb00.$subj.r$run.tcat+orig end # ================================= tshift ================================= # time shift data so all slice timing is the same foreach run ( $runs ) 3dTshift -tzero 0 -quintic -prefix pb02.$subj.r$run.tshift \ pb01.$subj.r$run.despike+orig end # -------------------------------- # extract volreg registration base 3dbucket -prefix vr_base_min_outlier \ pb02.$subj.r$minoutrun.tshift+orig"[$minouttr]" # ================================= align ================================== # for e2a: compute anat alignment transformation to EPI registration base # (new anat will be intermediate, stripped, CAJe_110_ns+orig) align_epi_anat.py -anat2epi -anat CAJe_110+orig \ -save_skullstrip -suffix _al_junk \ -epi vr_base_min_outlier+orig -epi_base 0 \ -epi_strip 3dAutomask \ -volreg off -tshift off # ================================== tlrc ================================== # warp anatomy to standard space @auto_tlrc -base TT_N27+tlrc -input CAJe_110_ns+orig -no_ss # store forward transformation matrix in a text file cat_matvec CAJe_110_ns+tlrc::WARP_DATA -I > warp.anat.Xat.1D # ================================= volreg ================================= # align each dset to base volume, align to anat, warp to tlrc space # verify that we have a +tlrc warp dataset if ( ! -f CAJe_110_ns+tlrc.HEAD ) then echo "** missing +tlrc warp dataset: CAJe_110_ns+tlrc.HEAD" exit endif # register and warp foreach run ( $runs ) # register each volume to the base 3dvolreg -verbose -zpad 1 -base vr_base_min_outlier+orig \ -1Dfile dfile.r$run.1D -prefix rm.epi.volreg.r$run \ -cubic \ -1Dmatrix_save mat.r$run.vr.aff12.1D \ pb02.$subj.r$run.tshift+orig # create an all-1 dataset to mask the extents of the warp 3dcalc -overwrite -a pb02.$subj.r$run.tshift+orig -expr 1 \ -prefix rm.epi.all1 # catenate volreg, epi2anat and tlrc transformations cat_matvec -ONELINE \ CAJe_110_ns+tlrc::WARP_DATA -I \ CAJe_110_al_junk_mat.aff12.1D -I \ mat.r$run.vr.aff12.1D > mat.r$run.warp.aff12.1D # apply catenated xform : volreg, epi2anat and tlrc 3dAllineate -base CAJe_110_ns+tlrc \ -input pb02.$subj.r$run.tshift+orig \ -1Dmatrix_apply mat.r$run.warp.aff12.1D \ -mast_dxyz 3.5 \ -prefix rm.epi.nomask.r$run # warp the all-1 dataset for extents masking 3dAllineate -base CAJe_110_ns+tlrc \ -input rm.epi.all1+orig \ -1Dmatrix_apply mat.r$run.warp.aff12.1D \ -mast_dxyz 3.5 -final NN -quiet \ -prefix rm.epi.1.r$run # make an extents intersection mask of this run 3dTstat -min -prefix rm.epi.min.r$run rm.epi.1.r$run+tlrc end # make a single file of registration params cat dfile.r*.1D > dfile_rall.1D # compute motion magnitude time series: the Euclidean norm # (sqrt(sum squares)) of the motion parameter derivatives 1d_tool.py -infile dfile_rall.1D -set_nruns 1 \ -derivative -collapse_cols euclidean_norm \ -write motion_${subj}_enorm.1D # ---------------------------------------- # create the extents mask: mask_epi_extents+tlrc # (this is a mask of voxels that have valid data at every TR) # (only 1 run, so just use 3dcopy to keep naming straight) 3dcopy rm.epi.min.r01+tlrc mask_epi_extents # and apply the extents mask to the EPI data # (delete any time series with missing data) foreach run ( $runs ) 3dcalc -a rm.epi.nomask.r$run+tlrc -b mask_epi_extents+tlrc \ -expr 'a*b' -prefix pb03.$subj.r$run.volreg end # create an anat_final dataset, aligned with stats 3dcopy CAJe_110_ns+tlrc anat_final.$subj # ----------------------------------------- # warp anat follower datasets (affine) 3dAllineate -source CAJe_110+orig \ -master anat_final.$subj+tlrc \ -final wsinc5 -1Dmatrix_apply warp.anat.Xat.1D \ -prefix anat_w_skull_warped # ================================== blur ================================== # blur each volume of each run foreach run ( $runs ) 3dBlurInMask -preserve -FWHM 4.0 -automask \ -prefix pb04.$subj.r$run.blur \ pb03.$subj.r$run.volreg+tlrc end # ================================== mask ================================== # create 'full_mask' dataset (union mask) foreach run ( $runs ) 3dAutomask -dilate 1 -prefix rm.mask_r$run pb04.$subj.r$run.blur+tlrc end # create union of inputs, output type is byte 3dmask_tool -inputs rm.mask_r*+tlrc.HEAD -union -prefix full_mask.$subj # ---- create subject anatomy mask, mask_anat.$subj+tlrc ---- # (resampled from tlrc anat) 3dresample -master full_mask.$subj+tlrc -input CAJe_110_ns+tlrc \ -prefix rm.resam.anat # convert to binary anat mask; fill gaps and holes 3dmask_tool -dilate_input 5 -5 -fill_holes -input rm.resam.anat+tlrc \ -prefix mask_anat.$subj # compute overlaps between anat and EPI masks 3dABoverlap -no_automask full_mask.$subj+tlrc mask_anat.$subj+tlrc \ |& tee out.mask_ae_overlap.txt # note Dice coefficient of masks, as well 3ddot -dodice full_mask.$subj+tlrc mask_anat.$subj+tlrc \ |& tee out.mask_ae_dice.txt # ---- create group anatomy mask, mask_group+tlrc ---- # (resampled from tlrc base anat, TT_N27+tlrc) 3dresample -master full_mask.$subj+tlrc -prefix ./rm.resam.group \ -input /abin/TT_N27+tlrc # convert to binary group mask; fill gaps and holes 3dmask_tool -dilate_input 5 -5 -fill_holes -input rm.resam.group+tlrc \ -prefix mask_group # ================================= scale ================================== # scale each voxel time series to have a mean of 100 # (be sure no negatives creep in) # (subject to a range of [0,200]) foreach run ( $runs ) 3dTstat -prefix rm.mean_r$run pb04.$subj.r$run.blur+tlrc 3dcalc -a pb04.$subj.r$run.blur+tlrc -b rm.mean_r$run+tlrc \ -c mask_epi_extents+tlrc \ -expr 'c * min(200, a/b*100)*step(a)*step(b)' \ -prefix pb05.$subj.r$run.scale end # ================== auto block: generate review scripts =================== # generate a review script for the unprocessed EPI data gen_epi_review.py -script @epi_review.$subj \ -dsets pb00.$subj.r*.tcat+orig.HEAD # generate scripts to review single subject results # (try with defaults, but do not allow bad exit status) gen_ss_review_scripts.py -exit0 # ========================== auto block: finalize ========================== # remove temporary files \rm -f rm.* # if the basic subject review script is here, run it # (want this to be the last text output) if ( -e @ss_review_basic ) ./@ss_review_basic |& tee out.ss_review.$subj.txt # return to parent directory cd .. echo "execution finished: `date`" # ========================================================================== # script generated by the command: # # afni_proc.py -subj_id CAJe_110 -script proc.CAJe_110 -scr_overwrite -blocks \ # despike tshift align tlrc volreg blur mask scale -despike_opts_3dDes \ # -ignore 2 -copy_anat \ # /mnt/nfs2/users/alans/CAJe/CAJe_110BRIKS/CAJe_110+orig -dsets \ # /mnt/nfs2/users/alans/CAJe/CAJe_110BRIKS/CAJe_110MS+orig.HEAD \ # -tcat_remove_first_trs 2 -tlrc_base TT_N27+tlrc -volreg_align_to \ # MIN_OUTLIER -volreg_align_e2a -volreg_tlrc_warp -blur_in_automask \ # -blur_size 4.0