help > Difficulty with batch_process/6_singlesubjectRSFC
Showing 1-2 of 2 posts
Display:
Results per page:
Mar 2, 2020  08:03 AM | Megan Kangiser
Difficulty with batch_process/6_singlesubjectRSFC
Hello,

I am using the Fcon1000 scripts on my own data to run a seed-based RSFC analysis. The data have already been pre-processed. I created a left PCC seed using 3dcalc in AFNI.

When I run batch_process with the single-subject RSFC option selected, I receive this output/error message for each subject (see my note in caps early in the output):

--------------------------
running subject MJ0099
--------------------------
------------------------
running seed left_PCC_seed_BA23+tlrc
------------------------
Extracting timeseries for seed left_PCC_seed_BA23+tlrc
** ERROR (nifti_image_read): failed to find header file for '/Volumes/LS2/Lisdah/func/rest_res2standard.nii.gz'e/MJ0099   (THIS SEEMS LIKE THERE MAY BE TWO LINES OF TEXT IN ONE PLACE?)
Warning: Cannot open input dataset /Volumes/LS2/Lisdahl/ImagingData/MJMRI/Restin/func/rest_res2standard.nii.gz
Computing Correlation for seed left_PCC_seed_BA23+tlrc
++ 3dfim+: AFNI version=AFNI_17.1.12 (Jun 23 2017) [64-bit]
++ Authored by: B. Douglas Ward
** ERROR (nifti_image_read): failed to find header file for '/Volumes/LS2/Lisdah/func/rest_res.nii.gz'stingState/MJ0099
3dfim+ Error: Unable to open data file: /Volumes/LS2/Lisdahl/ImagingData/MJMRI/R/func/rest_res.nii.gz
Z-transforming correlations for seed left_PCC_seed_BA23+tlrc
++ 3dcalc: AFNI version=AFNI_17.1.12 (Jun 23 2017) [64-bit]
++ Authored by: A cast of thousands
** ERROR (nifti_image_read): failed to find header file for '/Volumes/LS2/Lisdah/func/RSFC/left_PCC_seed_BA23+tlrc_corr.nii.gz'
** FATAL ERROR: can't open dataset /Volumes/LS2/Lisdahl/ImagingData/MJMRI/Restin/func/RSFC/left_PCC_seed_BA23+tlrc_corr.nii.gz
** Program compile date = Jun 23 2017
Registering Z-transformed map to standard space
Image Exception : #22 :: ERROR: Could not open image /Volumes/LS2/Lisdahl/Imagin/func/RSFC/left_PCC_seed_BA23+tlrc_Z
libc++abi.dylib: terminating with uncaught exception of type RBD_COMMON::BaseException
/Volumes/LS2/Lisdahl/ImagingData/MJMRI/Scripts/RestingScripts/fcon1000scripts/6_singlesubjectRSFC.sh: line 64: 95990 Abort trap: 6 flirt -in ${RSFC_dir}/${seed_name}_Z.nii.gz -ref ${standard} -applyxfm -init ${reg_dir}/example_func2standard.mat -out ${RSFC_dir}/${seed_name}_Z_2standard.nii.gz


I have run this multiple times and the error messages are slightly different each time, but the theme is that it keeps saying "failed to find header....". I am not sure why it seems like some lines are overwritten a few times in the text.

I previously ran this and it created a (seed).1D file in "seed_ts" for each subject (although it did create an entirely new subject folder to do so...). Since it created that file, I thought it had worked, but I came to find that the (seed)_corr.nii.gz, (seed)_Z_2standard.nii.gz, and (seed)_Z.nii.gz files were not created in the individual subjects' RSFC directories.

I have done my best to check for spelling errors etc, and of course I could have missed one!

Any guidance would be appreciated. My scripts/files are copied below.

Thanks,
Megan






My batch_process script is below: 
#!/bin/bash

##########################################################################################################################
## SCRIPT TO BATCH PROCESS DATASETS INCLUDED IN THE 1000 FUNCTIONAL CONNECTOMES PROJECT
##
## Written by Maarten Mennes & Michael Milham
## for more information see http://www.nitrc.org/projects/fcon_1000
##
## MAKE SURE TO CHECK/CHANGE ALL PARAMETERS BEFORE RUNNING THE SCRIPT
##
##########################################################################################################################
####################
## scripts directory
####################
## directory where you put the scripts downloaded from http://www.nitrc.org/projects/fcon_1000
## e.g. /home/fcon_1000/scripts
scripts_dir=/Volumes/LS2/Lisdahl/ImagingData/MJMRI/Scripts/RestingScripts/fcon1000scripts
###########################
## what do you want to run?
###########################
## 1 - general RSFC preprocessing
## 2 - single-subject RSFC (requires general preprocessing to be completed)
## 3 - ALFF/fALFF (default frequency band of interest is 0.01-0.1Hz)
## 4 - Dual Regression
what_to_do=2
#######################
## some important names
#######################
## anatomical scan you want to use (no extension)
anat_name=spgr1_strip
## resting-state scan you want to use (no extension)
rest_name=rest
################################################
## Extra parameters needed to run postprocessing
################################################
## image you want to use to calculate RSFC for.
## This is usually the image containing resting-state scan after regressing out the nuisance parameters
postprocessing_image=${rest_name}_res.nii.gz
## path to list of seeds you want to calculate RSFC for e.g. /home/fcon_1000/scripts/my_seeds.txt
## DEFAULT path = within the scripts directory specified above
## the list includes the full path for each seed e.g. /home/my_seeds/connectomes_seed_3mm.nii.gz
seed_list=${scripts_dir}/Megan.lPCC.SEED_LIST.txt
## image you want to use for postprocessing in MNI space
## This image is used in the dual regression step. Dual regression is applied to this image.
postprocessing_mni_image=${rest_name}_res2standard.nii.gz
## mask used for Dual Regression; default = MNI based mask
## the resolution has to be consistent with the DR templates
mask=${scripts_dir}/templates/MNI152_T1_3mm_brain_mask.nii.gz
## template used for Dual Regression
## default = the metaICA image, including 20 ICA components as derived in Biswal et al. 2010, PNAS
## running Dual Regression is tuned to run for 20 components you will have to edit 8_singlesubjectDR.sh if you want to use a different template
DR_template=${scripts_dir}/templates/metaICA.nii.gz
#######################################
## Standard brain used for registration
## include the /full/path/to/it
#######################################
standard_brain=${scripts_dir}/templates/MNI152_T1_3mm_brain.nii.gz
#####################################################################################
## batch processing parameter list
## DO NOT FORGET TO EDIT batch_list.txt itself to include the appropriate directories
#####################################################################################
## path to batch_list.txt, e.g., /home/fcon_1000/scripts/my_batch_list.txt.
## DEFAULT = within the scripts directory specified above
## This file contains the sites (and their parameters) you want to process.
## batch_list.txt contains 1 line per site listing:
## - analysis directory, i.e. full/path/to/site
## - subjectlist, i.e. full/path/to/site/site_subjects.txt
## - first timepoint, default = 0 (start with the 1st volume)
## - last timepoint = number of timepoints - 1 (since count starts at 0)
## - number of timepoints in the timeseries
## - TR
batch_list=${scripts_dir}/batch_list_MK.txt
##########################################################################################################################
##---START OF SCRIPT---------------------------------------------------------------------------------------------------------------------##
##---NO EDITING BELOW UNLESS YOU KNOW WHAT YOU ARE DOING----------------------------------------------------------------##
##########################################################################################################################
while read line
do
## 1. cut site specific parameters from batch_list
analysisdirectory=$( echo $line | cut -d ' ' -f1 )
subject_list=$( echo $line | cut -d ' ' -f2 )
first_vol=$( echo $line | cut -d ' ' -f3 )
last_vol=$( echo $line | cut -d ' ' -f4 )
n_vols=$( echo $line | cut -d ' ' -f5 )
TR=$( echo $line | cut -d ' ' -f6 )
## 2. do the processing asked for
case ${what_to_do} in
1) echo ${analysisdirectory} + ${subject_list} + ${first_vol} + ${last_vol} + ${n_vols} + ${TR}
sh ${scripts_dir}/0_preprocess.sh ${scripts_dir} ${analysisdirectory} ${subject_list} ${anat_name} ${rest_name} ${first_vol} ${last_vol} ${n_vols} ${TR} ${standard_brain}
;;
2) echo ${analysisdirectory} + ${subject_list} + ${postprocessing_image} + ${rest_name} + ${seed_list} + ${standard_brain}
sh ${scripts_dir}/6_singlesubjectRSFC.sh ${analysisdirectory} ${subject_list} ${postprocessing_image} ${rest_name} ${seed_list} ${standard_brain}
;;
3) echo ${analysisdirectory} + ${subject_list} + ${rest_name} + ${n_vols} + ${TR} + ${standard_brain}
sh ${scripts_dir}/7_singlesubjectfALFF.sh ${analysisdirectory} ${subject_list} ${rest_name} ${n_vols} ${TR} ${standard_brain}
;;
4) echo ${analysisdirectory} + ${subject_list} + ${postprocessing_mni_image} + ${DR_template} + ${mask}
sh ${scripts_dir}/8_singlesubjectDR.sh ${analysisdirectory} ${subject_list} ${postprocessing_mni_image} ${DR_template} ${mask}
;;
esac
done < ${batch_list}


My batch_list is below:
/Volumes/LS2/Lisdahl/ImagingData/MJMRI/RestingState /Volumes/LS2/Lisdahl/ImagingData/MJMRI/Scripts/RestingScripts/fcon1000scripts/Megan_diss_subj_list.txt 3 239 240 2


My seed list is below:
/Volumes/LS2/Lisdahl/ImagingData/MJMRI/Scripts/RestingScripts/fcon1000scripts/seeds/left_PCC_seed_BA23+tlrc


The 6_singlesubjectRSFC.sh is below:
#!/bin/bash

##########################################################################################################################
## SCRIPT TO CALCULATE SEED-BASED RESTING-STATE FUNCTIONAL CONNECTIVITY
##
## This script can be run on its own, by filling in the appropriate parameters
## Alternatively this script gets called from batch_process.sh, where you can use it to run N sites, one after the other.
##
## Written by Clare Kelly, Maarten Mennes & Michael Milham
## for more information see http://www.nitrc.org/projects/fcon_1000
##
##########################################################################################################################
## analysisdirectory
dir=$1
## full/path/to/subject_list.txt containing subjects you want to run
subject_list=$2
## image to extract timeseries from. default = rest_res.nii.gz
postprocessing_image=$3
## name of resting-state scan (no extenstion)
rest=$4
## file containing list with full/path/to/seed.nii.gz
seed_list=$5
## standard brain as reference for registration
standard=$6
## directory setup
## see below
##########################################################################################################################
##---START OF SCRIPT----------------------------------------------------------------------------------------------------##
##########################################################################################################################
## Get subjects to run
subjects=$( cat ${subject_list} )
## Get seeds to run
seeds=$( cat ${seed_list} )
## A. SUBJECT LOOP
for subject in $subjects
do
## directory setup
func_dir=${dir}/${subject}/func
reg_dir=${dir}/${subject}/reg
## seed_timeseries
seed_ts_dir=${dir}/${subject}/func/seed_ts
## RSFC maps
RSFC_dir=${dir}/${subject}/func/RSFC
echo --------------------------
echo running subject ${subject}
echo --------------------------
mkdir -p ${seed_ts_dir}
mkdir -p ${RSFC_dir}
## B. SEED_LOOP
for seed in $seeds
do
seed_name=$( echo ${seed##*/} | sed s/\.nii\.gz//g )
echo \------------------------
echo running seed ${seed_name}
echo \------------------------
## Check if seed might have already been run
if [ -f ${RSFC_dir}/${seed_name}_Z_2standard.nii.gz ]; then echo final file for seed ${seed_name} already exists; continue; fi
## 1. Extract Timeseries
echo Extracting timeseries for seed ${seed_name}
3dROIstats -quiet -mask_f2short -mask ${seed} ${func_dir}/${rest}_res2standard.nii.gz > ${seed_ts_dir}/${seed_name}.1D
## 2. Compute voxel-wise correlation with Seed Timeseries
echo Computing Correlation for seed ${seed_name}
3dfim+ -input ${func_dir}/${postprocessing_image} -ideal_file ${seed_ts_dir}/${seed_name}.1D -out Correlation -bucket ${RSFC_dir}/${seed_name}_corr.nii.gz
## 3. Z-transform correlations
echo Z-transforming correlations for seed ${seed_name}
3dcalc -a ${RSFC_dir}/${seed_name}_corr.nii.gz -expr 'log((a+1)/(a-1))/2' -prefix ${RSFC_dir}/${seed_name}_Z.nii.gz
## 4. Register Z-transformed correlations to standard space
echo Registering Z-transformed map to standard space
flirt -in ${RSFC_dir}/${seed_name}_Z.nii.gz -ref ${standard} -applyxfm -init ${reg_dir}/example_func2standard.mat -out ${RSFC_dir}/${seed_name}_Z_2standard.nii.gz
## END OF SEED LOOP
done
## END OF SUBJECT LOOP
done
Mar 3, 2020  02:03 AM | Maarten Mennes
RE: Difficulty with batch_process/6_singlesubjectRSFC
Hello,

the error message indicates that it can't find a certain file. So it's either not created, or there is a typo somewhere in where you specify your paths. Did you double check batch_list_MK.txt?

Is the file where you expect it to be?

Maarten