Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #404 from a3sha2/surface_processing
Browse files Browse the repository at this point in the history
Surface processing
  • Loading branch information
a3sha2 committed Nov 1, 2020
2 parents 4b3e2be + 8918f03 commit 5e7e9fd
Show file tree
Hide file tree
Showing 6 changed files with 573 additions and 60 deletions.
28 changes: 28 additions & 0 deletions core/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,34 @@ def ulify(elements):
html_report = html_report+' <div class="elem-image"> <object class="svg-reportlet" type="image/svg+xml" data="'+qcfcfig + '">filename:'+qcfcfig+' " alt="Segmentation" width="1000"height="800"</object> \
</div> <div class="elem-filename"> Get figure file: <a href="'+qcfcfig+'" target="_blank">' + qcfcfig + '</a> </div> '

if os.path.isfile(outdir+'/figures/'+ prefix +'_prestats_dtseries.svg'):
precifti='figures/'+ prefix +'_prestats_dtseries.svg'
postcifti='figures/'+ prefix +'_residualized_dtseries.svg'
html_report = html_report+'<div id="qcfc"> </div> </ul><h2 class="elem-title"> Assessment of CIFTI Files residual. \
</h2><p class="elem-desc"> \
The first panel shows the spike plot consisting of dvars (DVARS), and framewise displacement (FD). \
The mid carpet plot is raw CIFTI data, while the bottom carpet plot is residualized CIFTI data\
A carpet plot shows the time series for all CIFTI grayordinates. <p><br /> \
<div class="elem-image"> <object class="svg-reportlet" type="image/svg+xml" data="'+precifti+ '">filename:'+precifti + '" alt="Segmentation" width="1000"height="800" </object> \
</div> <div class="elem-filename"> Get figure file: <a href="'+precifti + '" target="_blank">' + precifti + '</a> </div> '

html_report = html_report+' <div class="elem-image"> <object class="svg-reportlet" type="image/svg+xml" data="'+postcifti + '">filename:'+postcifti+' " alt="Segmentation" width="1000"height="800"</object> \
</div> <div class="elem-filename"> Get figure file: <a href="'+postcifti+'" target="_blank">' + postcifti + '</a> </div> '

if os.path.isfile(outdir+'/figures/'+ prefix +'_prestats_hemi-R_bold.func.svg'):
pregifti='figures/'+ prefix +'_prestats_hemi-R_bold.func.svg'
postgifti='figures/'+ prefix +'_residualized_hemi-R_bold.func.svg'
html_report = html_report+'<div id="qcfc"> </div> </ul><h2 class="elem-title"> Assessment of GIFTI Files residual . \
</h2><p class="elem-desc"> \
The first panel shows the spike plot consisting of dvars (DVARS), and framewise displacement (FD). \
The mid carpet plot is raw GIFTI data (FreeSurface native space), while the bottom carpet plot is residualized GIFTI data\
A carpet plot shows the time series for all GIFTI veritices. <p><br /> \
<div class="elem-image"> <object class="svg-reportlet" type="image/svg+xml" data="'+pregifti+ '">filename:'+pregifti + '" alt="Segmentation" width="1000"height="800" </object> \
</div> <div class="elem-filename"> Get figure file: <a href="'+pregifti + '" target="_blank">' + pregifti + '</a> </div> '
html_report = html_report+' <div class="elem-image"> <object class="svg-reportlet" type="image/svg+xml" data="'+postgifti + '">filename:'+postgifti+' " alt="Segmentation" width="1000"height="800"</object> \
</div> <div class="elem-filename"> Get figure file: <a href="'+postgifti+'" target="_blank">' + postgifti + '</a> </div> '


#html_report=html_report + '<h1> qcfc module </h1> <h3> <p> The spike plot consists of dvars (DV), relative motion (RMS) and framewise displacement (FD), \
#The middle carpet plot is the raw BOLD data and bottom carpet plot is residualized BOLD data </p> <p> Check motionDVCorrInit (correlation of DV and RMS before regression) and motionDVCorrFinal \
#(correlation of DV and RMS after regression) in the QC table above </p> </h3> <object type="image/svg+xml" data="'+ prestatsfig + '" alt="Segmentation" width="2000"height="1500"></object>'
Expand Down
8 changes: 8 additions & 0 deletions docs/modules/regress.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ For scrubbing, the threshold will be ``fds:0.167`` which implies that the actual
Scrubbing also includes masking out the non-contiguous segments of data between outliers. The number of contiguous volumes required to survive masking is set flexibly by ``censor_contig[cst]=x``, where ``x`` is the minimum number of contiguous threshold-surviving time points required for those time points to survive masking. The default found in non-scrubbing design files is zero. This can be configured by setting::
*confound2_censor_contig[cxt]=5

Surface processing
^^^^^^^^^^^^^^^^^^^
THe xcpEngine also regresses out the confound regressors from the gifti and cifti files if they are available in the
fmriprep output. The esidualised files are as follows:

* prefix_residualized.dtseries # residualised cifti files
* prefix_residualized_hemi-R_bold.func.gii # residualized gifti files


``regress_process``
^^^^^^^^^^^^^^^^^^^^
Expand Down
91 changes: 31 additions & 60 deletions modules/regress/regress.mod
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ if is_image ${intermediate_root}${buffer}.nii.gz
then
subroutine @0.2
processed=$(readlink -f ${intermediate}.nii.gz)
exec_fsl immv ${processed} ${denoised[cxt]}
exec_fsl imcp ${processed} ${denoised[cxt]}
trep=$(exec_fsl fslval ${img[sub]} pixdim4)
exec_xcp addTR.py -i ${denoised[cxt]} -o ${denoised[cxt]} -t ${trep}
else
Expand Down Expand Up @@ -448,68 +448,39 @@ smooth_spatial --SIGNPOST=${signpost} \
--USAN=${regress_usan[cxt]} \
--USPACE=${regress_usan_space[cxt]}

strucn="${img1[sub]%/*/*}";
strucfile=$(ls -f ${strucn}/anat/*h5 2>/dev/null)
strucfile1=$(echo $strucfile | cut --delimiter " " --fields 1)

if [[ -f ${strucfile1} ]]; then
strucn=${strucn}
else
anatdir=$strucn/../
strucn=${anatdir}
# do the surface processing
imgname=$(basename ${img1[sub]})

if [[ "$imgname" == *_res-* ]]; then
imgprt=${img1[sub]%_*_*_*_*}
else
imgprt=${img1[sub]%_*_*_*}
fi

ciftifile=$(ls -f ${imgprt}*bold.dtseries.nii)
giftifile=$(ls -f ${imgprt}*fsnative_hemi-L_bold.func.gii)

if [[ -f ${ciftifile} ]]; then
mdkir -p ${out[sub]}/figures/ 2>/dev/null
python ${XCPEDIR}/utils/surfaceprocessing.py -p ${prefix} -o ${out[sub]}/regress -f ${out[sub]}/confound2/mc/${prefix}_fd.1D \
-d ${out[sub]}/confound2/mc/${prefix}_dvars-std.1D -t ${trep} -c ${out[sub]}/confound2/${prefix}_confmat.1D \
-g ${ciftifile} -r ${regress_process[cxt]} -l ${regress_lopass[cxt]} -s ${regress_hipass[cxt]}
fi

if [[ -f ${giftifile} ]]; then

giftifiles=$(ls -f ${imgprt}*fsnative_hemi-*_bold.func.gii)
mdkir -p ${out[sub]}/figures/ 2>/dev/null
for i in ${giftifiles}; do
python ${XCPEDIR}/utils/surfaceprocessing.py -p ${prefix} -o ${out[sub]}/regress -f ${out[sub]}/confound2/mc/${prefix}_fd.1D \
-d ${out[sub]}/confound2/mc/${prefix}_dvars-std.1D -t ${trep} -c ${out[sub]}/confound2/${prefix}_confmat.1D \
-g ${i} -r ${regress_process[cxt]} -l ${regress_lopass[cxt]} -s ${regress_hipass[cxt]}
done

fi


b1=${img1[sub]##*space-};
template_label=${b1%%_*}

surf=$( ls -f $strucn/anat/*hemi-L_inflated.surf.gii 2>/dev/null )
if [[ -f ${surf} ]] # this check if freesurfer exist
then
struct2=$(find $strucn/anat/ -type f -name "*desc-preproc_T1w.nii.gz" -not -path "*MNI*" -not -path "*space*" )

temptot1w1=$(find $strucn/anat/ -type f -name "*${template_label1}*to-T1w_mode-image_xfm.h5")
t1wtotemp1=$(find $strucn/anat/ -type f -name "*from-T1w_to*${template_label1}*_mode-image_xfm.h5")

temptot1w2=$(echo $temptot1w1 | cut --delimiter " " --fields 1)
t1wtotemp2=$(echo $t1wtotemp1 | cut --delimiter " " --fields 1)

ref=${XCPEDIR}/space/MNI/MNI-2x2x2.nii.gz

if [[ ${template_label} == 'T1w' ]]
then # reample bold to T1 dimension before freesurfer

exec_ants antsApplyTransforms -d 3 -e 3 -i ${denoised[cxt]} -r ${ref} -t ${1wtotemp2} \
-o ${outdir}/boldtoMNI.nii.gz -n LanczosWindowedSinc

else # reamsple template to T1 assuming the bold in MNI space


exec_ants antsApplyTransforms -d 3 -e 3 -i -i ${denoised[cxt]} -r ${ref} -t ${XCPEDIR}/utils/oneratiotransform.txt \
-o ${outdir}/boldtoMNI.nii.gz -n LanczosWindowedSinc

fi
source $FREESURFER_HOME/SetUpFreeSurfer.sh
exec_sys export SUBJECTS_DIR=${strucn}/../../freesurfer # freesurfer directory
xx=$( basename ${img1[sub]})
subjectid=$( echo ${xx} | head -n1 | cut -d "_" -f1 ) #get subjectid

surftemdir=${XCPEDIR}/thirdparty/standard_mesh_atlases/
#exec_fsl fslmaths ${outdir}/boldresampletoT1.nii.gz -Tmean ${outdir}/reference.nii.gz

# ${FREESURFER_HOME}/bin/bbregister --s ${subjectid} --mov ${outdir}/reference.nii.gz --reg ${outdir}/regis.dat --init-fsl --bold
#now do the surface
for hem in lh rh
do
${FREESURFER_HOME}/bin/mri_vol2surf --mov ${outdir}/boldtoMNI.nii.gz --regheader fsaverage --hemi ${hem} \
--o ${outdir}/${hem}_surface.nii.gz --projfrac-avg 0 1 0.1 --surf white
${FREESURFER_HOME}/bin/mris_convert -f ${outdir}/${hem}_surface.nii.gz ${SUBJECTS_DIR}/fsaverage/surf/${hem}.sphere ${outdir}/${prefix}_residual_${hem}.func.gii

done
exec_sys wb_command -cifti-create-dense-scalar ${outdir}/${prefix}_residual.dscalar.nii \
-left-metric ${outdir}/${prefix}_residual_lh.func.gii -right-metric ${outdir}/${prefix}_residual_rh.func.gii

exec_sys rm -rf ${outdir}/boldtoMNI.nii.gz ${outdir}/*surface.nii.gz ${outdir}/regis* ${outdir}/*surface2fsav.nii.gz
fi


routine_end
Expand Down

0 comments on commit 5e7e9fd

Please sign in to comment.