Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generation of scene/snapshots for fMRIQC #203

Merged
merged 17 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions PostFreeSurfer/PostFreeSurferPipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,6 @@ fi
#display the parsed/default values
opts_ShowValues

#processing code goes here

verbose_red_echo "---> Starting ${log_ToolName}"
verbose_echo " "
verbose_echo " Using environment setting ..."
verbose_echo " HCPPIPEDIR: ${HCPPIPEDIR}"
verbose_echo " "

log_Check_Env_Var FSLDIR

HCPPIPEDIR_PostFS="$HCPPIPEDIR/PostFreeSurfer/scripts"
PipelineScripts="$HCPPIPEDIR_PostFS"

doProcessing=1
doQC=1

Expand All @@ -104,12 +91,26 @@ case "$QCMode" in
;;
(only)
doProcessing=0
log_Warn "Only generating structural QC scene and snapshots from existing data (no other processing)"
;;
(*)
log_Err_Abort "unrecognized value '$QCMode' for --structural-qc, use 'yes', 'no', or 'only'"
;;
esac

#processing code goes here

verbose_red_echo "---> Starting ${log_ToolName}"
verbose_echo " "
verbose_echo " Using environment setting ..."
verbose_echo " HCPPIPEDIR: ${HCPPIPEDIR}"
verbose_echo " "

log_Check_Env_Var FSLDIR

HCPPIPEDIR_PostFS="$HCPPIPEDIR/PostFreeSurfer/scripts"
PipelineScripts="$HCPPIPEDIR_PostFS"

# ------------------------------------------------------------------------------
# Naming Conventions
# Do NOT include spaces in any of these names
Expand Down Expand Up @@ -282,6 +283,7 @@ if ((doProcessing)); then
fi

if ((doQC)); then
log_Msg "Generating structural QC scene and snapshots"
"$PipelineScripts"/GenerateStructuralScenes.sh \
--study-folder="$StudyFolder" \
--subject="$Subject" \
Expand Down
1 change: 1 addition & 0 deletions PostFreeSurfer/scripts/GenerateStructuralScenes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,4 @@ done
# Cleanup
rm "$OutputSceneFolder/$Subject.$mapName."{L,R}".$mesh.func.gii"

log_Msg "structural QC scene generation completed"
79 changes: 57 additions & 22 deletions fMRISurface/GenericfMRISurfaceProcessingPipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ Usage: ${script_name} [options]
--smoothingFWHM=<smoothing FWHM (mm)>
--grayordinatesres=<grayordinates res (mm)>
[--regname=<surface registration name>] defaults to 'MSMSulc'
[--fmri-qc=<"YES|NO|ONLY">
Controls whether to generate a QC scene and snapshots (default=YES).
ONLY executes *just* the QC script, skipping everything else (e.g., for previous data)

EOF
}
Expand Down Expand Up @@ -94,13 +97,16 @@ FinalfMRIResolution=`opts_GetOpt1 "--fmrires" $@`
SmoothingFWHM=`opts_GetOpt1 "--smoothingFWHM" $@`
GrayordinatesResolution=`opts_GetOpt1 "--grayordinatesres" $@`
RegName=`opts_GetOpt1 "--regname" $@`

if [ -z "${RegName}" ]; then
RegName="MSMSulc"
fi
RegName=`opts_DefaultOpt $RegName MSMSulc`
QCMode=`opts_GetOpt1 "--fmri-qc" $@`
QCMode=`opts_DefaultOpt $QCMode YES`
QCMode="$(echo ${QCMode} | tr '[:upper:]' '[:lower:]')" # Convert to all lowercase

RUN=`opts_GetOpt1 "--printcom" $@` # use ="echo" for just printing everything and not running the commands (default is to run)

doProcessing=1
doQC=1

log_Msg "Path: ${Path}"
log_Msg "Subject: ${Subject}"
log_Msg "NameOffMRI: ${NameOffMRI}"
Expand All @@ -109,6 +115,21 @@ log_Msg "FinalfMRIResolution: ${FinalfMRIResolution}"
log_Msg "SmoothingFWHM: ${SmoothingFWHM}"
log_Msg "GrayordinatesResolution: ${GrayordinatesResolution}"
log_Msg "RegName: ${RegName}"
log_Msg "QCMode: $QCMode"
case "$QCMode" in
(yes)
;;
(no)
doQC=0
;;
(only)
doProcessing=0
log_Warn "Only generating fMRI QC scene and snapshots from existing data (no other processing)"
;;
(*)
log_Err_Abort "unrecognized value '$QCMode' for --fmri-qc, use 'YES', 'NO', or 'ONLY'"
;;
esac
log_Msg "RUN: ${RUN}"

if [ "${RegName}" = "FS" ] ; then
Expand Down Expand Up @@ -139,25 +160,39 @@ T1wFolder="$Path"/"$Subject"/"$T1wFolder"
ResultsFolder="$AtlasSpaceFolder"/"$ResultsFolder"/"$NameOffMRI"
ROIFolder="$AtlasSpaceFolder"/"$ROIFolder"

#Make fMRI Ribbon
#Noisy Voxel Outlier Exclusion
#Ribbon-based Volume to Surface mapping and resampling to standard surface

log_Msg "Make fMRI Ribbon"
log_Msg "mkdir -p ${ResultsFolder}/RibbonVolumeToSurfaceMapping"
mkdir -p "$ResultsFolder"/RibbonVolumeToSurfaceMapping
"$PipelineScripts"/RibbonVolumeToSurfaceMapping.sh "$ResultsFolder"/RibbonVolumeToSurfaceMapping "$ResultsFolder"/"$NameOffMRI" "$Subject" "$AtlasSpaceFolder"/"$DownSampleFolder" "$LowResMesh" "$AtlasSpaceFolder"/"$NativeFolder" "${RegName}"

#Surface Smoothing
log_Msg "Surface Smoothing"
"$PipelineScripts"/SurfaceSmoothing.sh "$ResultsFolder"/"$NameOffMRI" "$Subject" "$AtlasSpaceFolder"/"$DownSampleFolder" "$LowResMesh" "$SmoothingFWHM"
# ------------------------------------------------------------------------------
# Start work
# ------------------------------------------------------------------------------

#Subcortical Processing
log_Msg "Subcortical Processing"
"$PipelineScripts"/SubcorticalProcessing.sh "$AtlasSpaceFolder" "$ROIFolder" "$FinalfMRIResolution" "$ResultsFolder" "$NameOffMRI" "$SmoothingFWHM" "$GrayordinatesResolution"
if ((doProcessing)); then
#Make fMRI Ribbon
#Noisy Voxel Outlier Exclusion
#Ribbon-based Volume to Surface mapping and resampling to standard surface
log_Msg "Make fMRI Ribbon"
coalsont marked this conversation as resolved.
Show resolved Hide resolved
log_Msg "mkdir -p ${ResultsFolder}/RibbonVolumeToSurfaceMapping"
mkdir -p "$ResultsFolder"/RibbonVolumeToSurfaceMapping
"$PipelineScripts"/RibbonVolumeToSurfaceMapping.sh "$ResultsFolder"/RibbonVolumeToSurfaceMapping "$ResultsFolder"/"$NameOffMRI" "$Subject" "$AtlasSpaceFolder"/"$DownSampleFolder" "$LowResMesh" "$AtlasSpaceFolder"/"$NativeFolder" "${RegName}"

#Surface Smoothing
log_Msg "Surface Smoothing"
"$PipelineScripts"/SurfaceSmoothing.sh "$ResultsFolder"/"$NameOffMRI" "$Subject" "$AtlasSpaceFolder"/"$DownSampleFolder" "$LowResMesh" "$SmoothingFWHM"

#Subcortical Processing
log_Msg "Subcortical Processing"
"$PipelineScripts"/SubcorticalProcessing.sh "$AtlasSpaceFolder" "$ROIFolder" "$FinalfMRIResolution" "$ResultsFolder" "$NameOffMRI" "$SmoothingFWHM" "$GrayordinatesResolution"

#Generation of Dense Timeseries
log_Msg "Generation of Dense Timeseries"
"$PipelineScripts"/CreateDenseTimeseries.sh "$AtlasSpaceFolder"/"$DownSampleFolder" "$Subject" "$LowResMesh" "$ResultsFolder"/"$NameOffMRI" "$SmoothingFWHM" "$ROIFolder" "$ResultsFolder"/"$OutputAtlasDenseTimeseries" "$GrayordinatesResolution"
fi

#Generation of Dense Timeseries
log_Msg "Generation of Dense Timeseries"
"$PipelineScripts"/CreateDenseTimeseries.sh "$AtlasSpaceFolder"/"$DownSampleFolder" "$Subject" "$LowResMesh" "$ResultsFolder"/"$NameOffMRI" "$SmoothingFWHM" "$ROIFolder" "$ResultsFolder"/"$OutputAtlasDenseTimeseries" "$GrayordinatesResolution"
if ((doQC)); then
log_Msg "Generating fMRI QC scene and snapshots"
"$PipelineScripts"/GenerateFMRIScenes.sh \
--study-folder="$Path" \
--subject="$Subject" \
--fmriname="$NameOffMRI" \
--output-folder="$ResultsFolder/fMRIQC"
fi

log_Msg "Completed!"
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ OutputSceneFolder=$(cd "$OutputSceneFolder"; pwd)
# ----------------------------

# The following are matched to actual strings in the TEMPLATE_fMRIQC.scene file
StudyFolderDummyStr="StudyFolder"
SubjectIDDummyStr="SubjectID"
fMRINameDummyStr="fMRIName"
StudyFolderDummyStr="STUDYDIR"
SubjectIDDummyStr="SESSION"
fMRINameDummyStr="FMRINAME"

# ----------------------------
# Begin main action of script
Expand All @@ -94,20 +94,20 @@ fi

# Replace dummy strings in the template scenes to generate
# a scene file appropriate for each subject and fMRI run
sceneFile="$OutputSceneFolder/${Subject}_${fMRIName}.fMRIQC.wb_scene"
sceneFile="${Subject}_${fMRIName}.fMRIQC.wb_scene" # No path (file name only)
sed -e "s|${StudyFolderDummyStr}|${relPathToStudy}|g" \
-e "s|${SubjectIDDummyStr}|${Subject}|g" \
-e "s|${fMRINameDummyStr}|${fMRIName}|g" \
"$TemplatesFolder"/TEMPLATE_fMRIQC.scene > "$sceneFile"
"$TemplatesFolder"/TEMPLATE_fMRIQC.scene > "$OutputSceneFolder/$sceneFile"

# Generate snapshots
pngDir="$OutputSceneFolder/snapshots"
mkdir -p "${pngDir}"
#numScenes=$(grep "SceneInfo Index" "$OutputSceneFolder/$sceneFile" | wc -l)
#for ((ind = 1; ind <= numScenes; ind++)); do
scenesToCapture="1 2"
for $ind in $scenesToCapture; do
for ind in $scenesToCapture; do
wb_command -show-scene "$OutputSceneFolder/$sceneFile" $ind "${pngDir}/${sceneFile}${ind}.png" 1400 600 -logging OFF
done

log_Msg "fMRI scene generation completed"
log_Msg "fMRI QC scene generation completed"
37 changes: 0 additions & 37 deletions fMRIVolume/GenericfMRIVolumeProcessingPipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ Usage: ${script_name} [options]
is NOT applied, regardless of value).
Default: "TRUE" if using --dcmethod="${SPIN_ECHO_METHOD_OPT}"; "FALSE" for all other SDC methods.

[--fmri-qc=<"YES|NO|ONLY">

Controls whether to generate a QC scene and snapshots (YES=default).
ONLY executes *just* the QC script, skipping everything else (e.g., for previous data)

[--processing-mode=<"HCPStyleData" (default) or "LegacyStyleData">

Controls whether the HCP acquisition and processing guidelines should be treated as requirements.
Expand Down Expand Up @@ -573,18 +568,6 @@ then
log_Err_Abort "the --usejacobian option must be 'true' or 'false'"
fi

QCMode=`opts_GetOpt1 "--fmri-qc" $@`
QCMode=`opts_DefaultOpt $QCMode YES`
QCMode="$(echo ${QCMode} | tr '[:upper:]' '[:lower:]')" # Convert to all lowercase
case "$QCMode" in
(yes|no|only)
log_Msg "QCMode: $QCMode"
;;
(*)
log_Err_Abort "unrecognized value '$QCMode' for --fmri-qc, use 'YES', 'NO', or 'ONLY'"
;;
esac

RUN=`opts_GetOpt1 "--printcom" $@` # use ="echo" for just printing everything and not running the commands (default is to run)
log_Msg "RUN: ${RUN}"

Expand Down Expand Up @@ -831,16 +814,6 @@ T1wFolder="$Path"/"$Subject"/"$T1wFolder"
AtlasSpaceFolder="$Path"/"$Subject"/"$AtlasSpaceFolder"
ResultsFolder="$AtlasSpaceFolder"/"$ResultsFolder"/"$NameOffMRI"

if [[ $QCMode == "only" ]] ; then # Generate QC scene and return
log_Msg "Generating fMRI QC scene and snapshots, then exiting"
"$PipelineScripts"/GenerateFMRIScenes.sh \
--study-folder="$Path" \
--subject="$Subject" \
--fmriname="$NameOffMRI"
--output-folder="$ResultsFolder/fMRIQC"
return
fi

mkdir -p ${T1wFolder}/Results/${NameOffMRI}

if [ ! -e "$fMRIFolder" ] ; then
Expand Down Expand Up @@ -1149,16 +1122,6 @@ ${RUN} cp ${fMRIFolder}/Movement_AbsoluteRMS.txt ${ResultsFolder}
${RUN} cp ${fMRIFolder}/Movement_RelativeRMS_mean.txt ${ResultsFolder}
${RUN} cp ${fMRIFolder}/Movement_AbsoluteRMS_mean.txt ${ResultsFolder}

# Generate fMRIQC scene and snapshots
if [[ $QCMode == "yes" ]] ; then
log_Msg "Generating fMRI QC scene and snapshots"
"$PipelineScripts"/GenerateFMRIScenes.sh \
--study-folder="$Path" \
--subject="$Subject" \
--fmriname="$NameOffMRI"
--output-folder="$ResultsFolder/fMRIQC"
fi

#Basic Cleanup
${FSLDIR}/bin/imrm ${fMRIFolder}/${NameOffMRI}_nonlin_norm

Expand Down
25,588 changes: 25,588 additions & 0 deletions global/templates/fMRIQC/TEMPLATE_fMRIQC.scene

Large diffs are not rendered by default.