Missing mm and mm_delt Files for All Runs in AFNI Output

Hi AFNI Experts,

I’ve encountered an issue during my analysis pipeline where I expected to see mm and mm_delt files generated for all runs of my data, but they are only present for one run. Here’s a summary of my setup and the problem:

Pipeline Details

  • I’m using afni_proc.py for preprocessing with the following blocks: tcat, align, tlrc, volreg, blur, scale, regress.
  • The volreg block includes the -volreg_opts_vr -twopass -twodup -maxdisp1D mm option to compute motion metrics.
  • I have 3 runs in the experiment, I am concatenating all of them into one as a part of preprocesisng.

Problem

  • After running the pipeline, I find that the mm (max displacement) and mm_delt (delta motion metrics) files are generated, but only for one run instead of all runs.
  • I expected separate mm and mm_delt files for each run in the results directory (or maybe one file with all runs concatenated, similar to how other motion parameters (e.g., motion_demean.1D and motion_deriv.1D) are provided).

Questions

  1. Is this the intended behavior of AFNI, or should mm and mm_delt files be generated for all runs?
  2. If this is not expected, could it be related to the way I’ve structured my input files or pipeline options?
  3. Are there specific flags or settings in afni_proc.py that I need to adjust to ensure mm and mm_delt files are created for all runs?

Additional Details

  • AFNI version: Precompiled binary linux_ubuntu_16_64: Feb 6 2023 (Version AFNI_23.0.03 ‘Commodus’)

  • OS: Linux 5.4.0-113-generic #127-Ubuntu SMP Wed May 18 14:30:56 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

  • The command used:

#!/bin/bash

...

afni_proc.py \
    -subj_id "$subject_id" \
    -script "$script_path" \
    -out_dir "$results_path" \
    -dsets "$data_folder"/"$subject_id"/*movt*_"$run1".nii \
           "$data_folder"/"$subject_id"/*movt*_"$run2".nii \
           "$data_folder"/"$subject_id"/*movt*_"$run3".nii \
    -blip_reverse_dset "$data_folder"/"$subject_id"/*PErev*_"$phasereverse".nii \
    -blocks tcat align tlrc volreg blur scale regress \
    -radial_correlate_blocks volreg regress \
    -tlrc_base MNI152_2009_template.nii.gz \
    -tcat_remove_first_trs "$n_trs_remove" \
    -copy_anat "$data_folder"/"$subject_id"/*MPRAGE*_"$mprage".nii \
    -volreg_align_to first \
    -volreg_opts_vr -twopass -twodup -maxdisp1D mm \
    -volreg_compute_tsnr yes \
    -remove_preproc_files \
    -html_review_style pythonic

(
tcsh -xef "$script_path" 2>&1 | tee "$output_path"
) & # Run in the background
...

I look into my proc. script and it seems like the file is overwritten in each iteration. Correct me if I am wrong:

# ================================= volreg =================================
# align each dset to base volume, blip warp
# (final warp input is same as blip input)

foreach run ( $runs )
    # register each volume to the base image
    3dvolreg -verbose -zpad 1 -base vr_base+orig      
             -1Dfile dfile.r$run.1D -prefix rm.epi.volreg.r$run
             -cubic
             -twopass -twodup -maxdisp1D mm
             -1Dmatrix_save mat.r$run.vr.aff12.1D 
             pb01.$subj.r$run.blip+orig
    ...

end

If anyone has encountered a similar issue or knows how to ensure mm and mm_delt files are generated for all runs, I’d greatly appreciate your insights.

Thank you in advance for your help!

Best regards,
Egor Levchenko

hi there Egor-

maybe better a question for Rick on the AFNI list, but I’ll chime in for now. when you add one of the “opts” to an afni_proc script it just simply adds whatever text to the appropriate command in the proc.* file. so i wonder 2 things:

if you can change your afni_proc line to read something like

-volreg_opts_vr -twopass -twodup -maxdisp1D mm'$run'

where you’ve added the run variable to what it simply adds into the 3dvolreg command. keep in mind the single quote is critical for that whole bit to just be added as-is and not interpreted by the shell. i just tried it out and it seemed to work for me.

but if that doesn’t work for you you could just go in and manually change the 3dvolreg command in the proc.* before execution to see if it performs the desired behavior. manually changing a proc is less than ideal but could help you narrow down what’s happening and what you need (and what feature you could potentially ask Rick for).

hope that helps!

-Sam

Hi Sam and Egor,

Indeed, putting an escaped $run in there should work well (quoting or escaping, whatever you need to do to get $run into the proc script, still as a variable).

-rick

2 Likes

Thank you, Rick and Sam! I’ll give it a try and let you know :slight_smile: