AFNI resting state uber.subject.py problem

Dear Afni users,

I am trying to process some resting state data with AFNI [ Precompiled binary linux_openmp_64: Jun 16 2016 (Version AFNI_16.1.26) ], after having successfully installed it and checked the software with the command afni_system_check.py -check_all. Unfortunately, I’m stuck at the first step (uber_subject.py), since there seems to be some problems with my script. What I did was selecting “rest” in the analysis initialisation box, choosing the T1 image in the anatomical dataset, choosing the EPI files for the subject (I’ve tried both 4D.nii image and the complete set of .nii files) and of course deselected “stimulus timing files”.
This is the script that was generated.


#!/usr/bin/env tcsh

# created by uber_subject.py: version 0.39 (March 21, 2016)
# creation date: Tue Jun 21 01:22:38 2016

# set data directories
set top_dir   = /home/michele/Desktop/8888/session_1
set anat_dir  = $top_dir/anat_1
set epi_dir   = $top_dir/rest_1

# set subject and group identifiers
set subj      = s001
set group_id  = navi

# run afni_proc.py to create a single subject processing script
afni_proc.py -subj_id $subj                                        \
        -script proc.$subj -scr_overwrite                          \
        -blocks despike tshift align tlrc volreg blur mask regress \
        -copy_anat $anat_dir/structurelle_sujet1.nii               \
        -tcat_remove_first_trs 0                                   \
        -dsets $epi_dir/4D.nii                                     \
        -volreg_align_to third                                     \
        -volreg_align_e2a                                          \
        -volreg_tlrc_warp                                          \
        -blur_size 4.0                                             \
        -regress_censor_motion 0.2                                 \
        -regress_bandpass 0.01 0.1                                 \
        -regress_apply_mot_types demean deriv                      \
        -regress_est_blur_errts                                    \
        -regress_run_clustsim no

and this is the error that appears when I check the script with the command “show proc script”:


-- applying orig view as +tlrc
** already in tlrc space: -volreg_tlrc_* is not allowed
** invalid block : volreg
----------------------------------------------------------------------
** failed command (create_blocks):

  afni_proc.py -subj_id s001 -script proc.s001 -scr_overwrite -blocks despike \
      tshift align tlrc volreg blur mask regress -copy_anat                   \
      /home/michele/Desktop/8888/session_1/anat_1/structurelle_sujet1.nii     \
      -tcat_remove_first_trs 0 -dsets                                         \
      /home/michele/Desktop/8888/session_1/rest_1/4D.nii -volreg_align_to     \
      third -volreg_align_e2a -volreg_tlrc_warp -blur_size 4.0                \
      -regress_censor_motion 0.2 -regress_bandpass 0.01 0.1                   \
      -regress_apply_mot_types demean deriv -regress_est_blur_errts           \
      -regress_run_clustsim no
----------------------------------------------------------------------

Did anyone else have this problem? Am I following a wrong procedure?
Thank you in advance for the attention,

Michele Deantoni

P.S. I don’t know if it’s usefull, but I am running AFNI on an Ubuntu virtual machine with VMware (ubunto version 14.04.4)

Hi Michele-

For whatever reason, AFNI believes your data are already in standard space. Has the data been preprocessed in any other software? How was it converted from DICOM?

If you are certain that the functional data is in subject space (+ORIG), then you can use 3drefit to adjust the parameters of the file and re-run your command.

Best,
Peter

Hello Peter,

First of all, thank you very much for the reply. I’ve followed your suggestion and I’ve tried to know more about my 4D.nii file. Giving the command “3dinfo”, I’ve discovered that the file was actually in TLRC template space, so I used the function -space ORIG of 3drefit to change it in ORIG template space.
Now, I’ve run again the script and at least it is working (on the status bar I read “process finished: SUCCESS”), the only thing is that is displaying an error in the resample step:


** ERROR: Could not resample

and also during the “removing skull or area outside brain” step:


AttributeError: 'NoneType' object has no attribute 'input'

Do you think these two errors are the outcome of an incorrect conversion TLRC>ORIG or if it could be something negligeable?

P.S. I’m sure about the fact that the functional data is in the subject space and I’ve used SPM to obtain the 4D.nii image. Regarding the DICOM conversion, I’m asking my lab for more informations, since we use an automatic script right after the aquisition.

Hello,

Can you post the entire output? Also, what’s the output of 3dinfo on the structural scan (structurelle_sujet1.nii)?

-PM

Of course! This is the output of 3dinfo (template space was TLRC originally):


++ 3dinfo: AFNI version=AFNI_16.1.26 (Jun 16 2016) [64-bit]

Dataset File:    4D.nii
Identifier Code: NII_qCASPEHo_w6mrUbYelD-1A  Creation Date: Tue Jun 21 07:07:22 2016
Template Space:  ORIG
Dataset Type:    Echo Planar (-epan)
Byte Order:      LSB_FIRST {assumed} [this CPU native = LSB_FIRST]
Storage Mode:    NIFTI
Storage Space:   99,283,968 (99 million [mega]) bytes
Geometry String: "MATRIX(3,0,0,-108,0,-2.981304,0.418008,54.86181,0,0.334407,3.72663,-57.04074):72,72,36"
Data Axes Tilt:  Oblique (6.400 deg. from plumb)
Data Axes Approximate Orientation:
  first  (x) = Right-to-Left
  second (y) = Posterior-to-Anterior
  third  (z) = Inferior-to-Superior   [-orient RPI]
R-to-L extent:  -108.000 [R] -to-   105.000 [L] -step-     3.000 mm [ 72 voxels]
A-to-P extent:  -158.138 [A] -to-    54.862 [P] -step-     3.000 mm [ 72 voxels]
I-to-S extent:   -57.041 [I] -to-    74.209 [S] -step-     3.750 mm [ 36 voxels]
Number of time steps = 133  Time step = 1.00000s  Origin = 0.00000s
  -- At sub-brick #0 '?' datum type is float:            0 to       2948.99
  -- At sub-brick #1 '?' datum type is float:            0 to       2968.97
  -- At sub-brick #2 '?' datum type is float:            0 to       2999.04
** For info on all 133 sub-bricks, use '3dinfo -verb' **

And this is the output of the script:


echo auto-generated by afni_proc.py, Tue Jun 21 10:03:29 2016
auto-generated by afni_proc.py, Tue Jun 21 10:03:29 2016
echo (version 4.67, June 16, 2016)
(version 4.67, June 16, 2016)
echo execution started: `date`
date
execution started: Tue Jun 21 10:03:38 PDT 2016
afni -ver
Precompiled binary linux_openmp_64: Jun 16 2016 (Version AFNI_16.1.26)
afni_history -check_date 28 Oct 2015
-- is current: afni_history as new as: 28 Oct 2015
               most recent entry is:   16 Jun 2016
if ( 0 ) then
if ( 0 > 0 ) then
set subj = s001
endif
set output_dir = s001.results
if ( -d s001.results ) then
set runs = ( `count -digits 2 1 1` )
count -digits 2 1 1
mkdir s001.results
mkdir s001.results/stimuli
3dcopy /home/michele/Desktop/8888/session_1/anat_1/structurelle_sujet1.nii s001.results/structurelle_sujet1
++ 3dcopy: AFNI version=AFNI_16.1.26 (Jun 16 2016) [64-bit]
** AFNI converts NIFTI_datatype=512 (UINT16) in file /home/michele/Desktop/8888/session_1/anat_1/structurelle_sujet1.nii to FLOAT32
     Warnings of this type will be muted for this session.
     Set AFNI_NIFTI_TYPE_WARN to YES to see them all, NO to see none.
3dTcat -prefix s001.results/pb00.s001.r01.tcat /home/michele/Desktop/8888/session_1/rest_1/4D.nii[0..$]
++ 3dTcat: AFNI version=AFNI_16.1.26 (Jun 16 2016) [64-bit]
++ elapsed time = 19.5 s
set tr_counts = ( 133 )
cd s001.results
touch out.pre_ss_warn.txt
foreach run ( 01 )
3dToutcount -automask -fraction -polort 1 -legendre pb00.s001.r01.tcat+orig
++ 3dToutcount: AFNI version=AFNI_16.1.26 (Jun 16 2016) [64-bit]
e[7m*+ WARNING:e[0m   If you are performing spatial transformations on an oblique dset, 
  such as ./pb00.s001.r01.tcat+orig.BRIK,
  or viewing/combining it with volumes of differing obliquity,
  you should consider running: 
     3dWarp -deoblique 
  on this and  other oblique datasets in the same session.
 See 3dWarp -help for details.
++ Oblique dataset:./pb00.s001.r01.tcat+orig.BRIK is 6.400001 degrees from plumb.
++ 35812 voxels passed mask/clip
if ( `1deval -a outcount.r$run.1D"{0}" -expr "step(a-0.4)"` ) then
1deval -a outcount.r01.1D{0} -expr step(a-0.4)
end
cat outcount.r01.1D
foreach run ( 01 )
3dDespike -NEW -nomask -prefix pb01.s001.r01.despike pb00.s001.r01.tcat+orig
++ 3dDespike: AFNI version=AFNI_16.1.26 (Jun 16 2016) [64-bit]
++ Authored by: RW Cox
e[7m*+ WARNING:e[0m   If you are performing spatial transformations on an oblique dset, 
  such as ./pb00.s001.r01.tcat+orig.BRIK,
  or viewing/combining it with volumes of differing obliquity,
  you should consider running: 
     3dWarp -deoblique 
  on this and  other oblique datasets in the same session.
 See 3dWarp -help for details.
++ Oblique dataset:./pb00.s001.r01.tcat+orig.BRIK is 6.400001 degrees from plumb.
++ Input data type = float
++ ignoring first 0 time points, using last 133
++ using 133 time points => -corder 4
++ Loading dataset pb00.s001.r01.tcat+orig
++ processing all 186624 voxels in dataset
++ Procesing time series with NEW model fit algorithm
++ smash edit thresholds: 3.1 .. 5.0 MADs
 +   [ 3.457% .. 0.072% of normal distribution]
 +   [ 8.839% .. 3.125% of Laplace distribution]
++ 36 slices to process
++ start OpenMP thread #0
................................................................................
++ Elapsed despike time =  8s 456ms

++ FINAL: 24476256 data points, 956509 edits [3.908%], 70924 big edits [0.290%]
++ Output dataset ./pb01.s001.r01.despike+orig.BRIK
end
foreach run ( 01 )
3dTshift -tzero 0 -quintic -prefix pb02.s001.r01.tshift pb01.s001.r01.despike+orig
++ 3dTshift: AFNI version=AFNI_16.1.26 (Jun 16 2016) [64-bit]
e[7m*+ WARNING:e[0m   If you are performing spatial transformations on an oblique dset, 
  such as ./pb01.s001.r01.despike+orig.BRIK,
  or viewing/combining it with volumes of differing obliquity,
  you should consider running: 
     3dWarp -deoblique 
  on this and  other oblique datasets in the same session.
 See 3dWarp -help for details.
++ Oblique dataset:./pb01.s001.r01.despike+orig.BRIK is 6.400001 degrees from plumb.
e[7m*+ WARNING:e[0m dataset is already aligned in time!
e[7m*+ WARNING:e[0m ==>> output dataset is just a copy of input dataset
end
3dbucket -prefix vr_base pb02.s001.r01.tshift+orig[2]
++ 3dbucket: AFNI version=AFNI_16.1.26 (Jun 16 2016) [64-bit]
align_epi_anat.py -anat2epi -anat structurelle_sujet1+tlrc -save_skullstrip -suffix _al_junk -epi vr_base+orig -epi_base 0 -epi_strip 3dAutomask -volreg off -tshift off
#++ align_epi_anat version: 1.53
#++ turning off volume registration
#Script is running (command trimmed):
  3dAttribute DELTA ./vr_base+orig
#Script is running (command trimmed):
  3dAttribute DELTA ./vr_base+orig
#Script is running (command trimmed):
  3dAttribute DELTA ./structurelle_sujet1+tlrc
#++ Multi-cost is lpc
#++ Removing all the temporary files
#Script is running:
  \rm -f ./__tt_vr_base*
#Script is running:
  \rm -f ./__tt_structurelle_sujet1*
#Script is running (command trimmed):
  3dcopy ./structurelle_sujet1+tlrc ./__tt_structurelle_sujet1+tlrc
++ 3dcopy: AFNI version=AFNI_16.1.26 (Jun 16 2016) [64-bit]
#++ Removing skull from anat data
#Script is running (command trimmed):
  3dSkullStrip -orig_vol -input ./__tt_structurelle_sujet1+tlrc -prefix ./__tt_structurelle_sujet1_ns
#Script is running (command trimmed):
  3dinfo ./__tt_structurelle_sujet1_ns+tlrc | \grep 'Data Axes Tilt:'|\grep 'Oblique'
#++ Dataset /home/michele/Desktop/8888/session_1/subject_results/group.navi/subj.s001/s001.results/__tt_structurelle_sujet1_ns+tlrc is not oblique
#Script is running (command trimmed):
  3dinfo ./vr_base+orig | \grep 'Data Axes Tilt:'|\grep 'Oblique'
#++ Dataset /home/michele/Desktop/8888/session_1/subject_results/group.navi/subj.s001/s001.results/vr_base+orig is ***oblique****
#Script is running (command trimmed):
  3dAttribute DELTA ./__tt_structurelle_sujet1_ns+tlrc
#++ Spacing for anat to oblique epi alignment is 1.000000
#++ Matching obliquity of anat to epi
#Script is running (command trimmed):
  3dWarp -verb -card2oblique ./vr_base+orig -prefix ./__tt_structurelle_sujet1_ns_ob -newgrid 1.000000 ./__tt_structurelle_sujet1_ns+tlrc | \grep -A 4 '# mat44 Obliquity Transformation ::' > ./__tt_structurelle_sujet1_ns_obla2e_mat.1D
++ 3dWarp: AFNI version=AFNI_16.1.26 (Jun 16 2016) [64-bit]
++ Authored by: RW Cox
#++ using 0th sub-brick because only one found
#Script is running (command trimmed):
  3dbucket -prefix ./__tt_vr_base_ts ./vr_base+orig'[0]'
++ 3dbucket: AFNI version=AFNI_16.1.26 (Jun 16 2016) [64-bit]
#++ resampling epi to match anat data
#Script is running (command trimmed):
  3dresample -master ./__tt_structurelle_sujet1_ns_ob+tlrc -prefix ./__tt_vr_base_ts_rs -inset ./__tt_vr_base_ts+orig'' -rmode Cu
e[7m*+ WARNING:e[0m   If you are performing spatial transformations on an oblique dset, 
  such as ./__tt_vr_base_ts+orig.BRIK,
  or viewing/combining it with volumes of differing obliquity,
  you should consider running: 
     3dWarp -deoblique 
  on this and  other oblique datasets in the same session.
 See 3dWarp -help for details.
++ Oblique dataset:./__tt_vr_base_ts+orig.BRIK is 6.400001 degrees from plumb.
** ERROR: Could not resample

#++ removing skull or area outside brain
Traceback (most recent call last):
  File "/home/michele/abin/align_epi_anat.py", line 3395, in <module>
    ps.process_epi(use_ss=ps.epi_strip_method)
  File "/home/michele/abin/align_epi_anat.py", line 3093, in process_epi
    skullstrip_o = self.skullstrip_data( e, use_ss, ps.skullstrip_opt, prefix)
  File "/home/michele/abin/align_epi_anat.py", line 2868, in skullstrip_data
    % (   n.pp(), e.input()), ps.oexec)
AttributeError: 'NoneType' object has no attribute 'input'

It looks like your structural image is also appearing in standard space (+tlrc). Again, if you are sure that it is in subject space, you can use 3drefit on the structurelle_sujet1.nii file just as you did before with the 4D.nii.

Along with Peter’s good suggestions, what does
nifti_tool say about the qform/sform codes?

nifti_tool -disp_hdr -infiles 4D.nii structurelle_sujet1.nii | grep form

It might be enough to set AFNI_NIFTI_VIEW to orig
in your ~/.afnirc file.

  • rick

Thank you for your replies,
these are the qform/sform codes for my anatomical image:


  qform_code           252      1    1
  sform_code           254      1    2

and these are the ones for the EPI 4D image:


  qform_code           252      1    1
  sform_code           254      1    1

Do you think this situation is suitable for the .afnirc file?

Anyway, following the instruction given me by Peter I was able to run the script without a single Error report, which is great (thank you very much for the support!).

Michele

That is great, Michele.

Based on that output, it looks like the anat dset
is the problem (sform = 2). Given that, the .afnirc
method should work, too.

You could even reset the code back to 1, but maybe
updating your .afnirc is better.

nifti_tool -mod_hdr -mod_field sform_code 1 -overwrite -infiles ANAT.nii
  • rick

That’s perfect. Thank you very much for your assistance.

Michele