Skip to content

Module 4 MRI QA and 3D Print Prep

Jared Tanner edited this page May 16, 2024 · 38 revisions

View FreeSurfer Output

If you do not know how to view the FreeSurfer output on HiPerGator, watch this video for an extended walk-through (I recommend watching at 1.5 speed). This was recorded in a previous semester so update paths accordingly! Also, logging in to HiPerGator and interacting with files and applications has changed somewhat, but this should be close enough to figure out.

https://youtu.be/kEZKqIcwIKE

FreeSurfer Quality Assessment

There are many ways to assess the quality of FreeSurfer outputs. These would only be a small part of that assessment. We will not cover editing and reprocessing files, although that might need to be done in some instances. There are fairly standardized methods for doing that but we won't cover them.

What we will do for quality assessment is use two semi-automated tools to provide a way to view the images and outputs. These will also provide some metrics of quality that can be considered in analyses.

Doing the first tutorial requires you to have completed the two recon-all commands. Some students had issues with running out of memory. Rather than keeping trying over and over, I've made the two processed brains available to students who need these. Copy (don't move) the two sub- directories into your directory (probably best in your ADNI_bids [or whatever you called it]/derivatives/freesurfer directory).

The processed brains are in /blue/clp7934/share/Module4

Again, you'll only need to copy those if your processing for Module3 failed and I already gave you credit for it.

  1. Watch this tutorial and follow along.

https://youtu.be/5svhiqgO6g0Links to an external site.

Key commands are as follows (this assumes you are in your freesurfer output directory where the recon-all command saved the processed images). This will need to be changed to match what you called your subjects (some of you have done 011_S_6303 or sub-6303 or something like that -- pay attention to names and paths).

#This mkdir command assumes you are where you want to make this directory. I was in my freesurfer output directory so you'll want to run something like this first (update as appropriate):

cd /blue/clp7934/share/jjtanner/ADNI_bids/derivatives/freesurfer

mkdir fsqc_out

apptainer run -B $PWD:/in -B $PWD/fsqc_out:/out /blue/clp7934/share/fsqc.sif --subjects_dir /in --subjects sub-011S6303 sub-011S6367 --output_dir /out --skullstrip-html --surfaces-html --screenshots-html --fornix-html

#In the previous command $PWD is a variable that prints (calls) your current directory. Only use this if you are where the data are. Otherwise put in the full path (usually safer). Something like: apptainer run -B /blue/clp7934/share/jjtanner/ADNI_bids/derivatives/freesurfer:/in

#Pay attention to spaces in the apptainer command. There are places where there are no spaces. Also, pay attention to the dashes. Some of them are single and some are double.
  1. Then watch this video and follow along

https://youtu.be/c2z2FwUEWp0Links to an external site.

There isn't really a script or standard commands for this. You'll just need to follow along because it's more "visual" than command line.

At the end of these you will have the files needed to submit for the homework.

Preparing for 3D Printing

This is more for fun, but will give you additional experience with containers and scripting (if you choose to script).

Watch this video and follow along. I show both running the processing "live" and in a script (script is the last part of the video). You can do either method or both, for the experience.

If you use the script, it's in /blue/clp7934/share/Module4

Please copy (not move) it from there into somewhere in your own directory. Then edit it to match your paths and files.

https://youtu.be/ROm5F_075acLinks to an external site.

At the end of this you will have 1 or 2 .stl files that are 3D models of human brains. These could be imported into 3D modeling software, or, with some additional minor preparation, are ready for 3D printing.

Here is the script's contents with commands used in the video. If you put these into terminal to run this live (only do that in an interactive session or in the Terminal in a HiPerGator Desktop), it's best to have each command as one line (example after this next section).

#!/bin/bash

#SBATCH --job-name=3dprintprep # Job name

#SBATCH --mail-type=END,FAIL # Mail events (NONE, BEGIN, END, FAIL, ALL)

#SBATCH --mail-user=jjtanner@ufl.edu # Where to send mail 

#SBATCH --ntasks=1 # Run on a single CPU

#SBATCH --mem=4gb # Job memory request

#SBATCH --time=00:20:00 # Time limit hrs:min:sec

#SBATCH --account=clp7934

#SBATCH --qos=clp7934

#SBATCH --output=3dprintprep_%j.log # Standard output and error log

pwd; hostname; date


cd /blue/clp7934/share/jjtanner/ADNI_bids/derivatives/freesurfer


module load freesurfer/7.1.1


apptainer run \

--env FREESURFER_HOME=/opt/freesurfer \

--env PATH=/opt/freesurfer/bin:$PATH \

-B $PWD:/in \

-B $PWD/3dprint/:/out \

-B $FREESURFER_HOME:/opt/freesurfer \

/blue/clp7934/share/fsqc.sif \

--subjects_dir /in \

--subjects sub-011S6367 \

--output_dir /out \

--shape


cd /blue/clp7934/share/jjtanner/ADNI_bids/derivatives/freesurfer/3dprint


apptainer run \

-B /blue/clp7934/share/jjtanner/ADNI_bids/derivatives/freesurfer/3dprint/brainprint/sub-011S6367/surfaces/:/in \

-B /blue/clp7934/share/jjtanner/ADNI_bids/derivatives/freesurfer/3dprint:/out \

/blue/clp7934/share/3dprintprep.sif \

/in \

/out/sub-011S6367.stl


date

Here is an example of the apptainer run commands as a single line. It looks like it's multiple lines but that's just because of text wrapping with the constraints of the text box here

#Run fsqc to create the brain "shape" files

apptainer run --env FREESURFER_HOME=/opt/freesurfer --env PATH=/opt/freesurfer/bin:$PATH -B $PWD:/in -B $PWD/3dprint/:/out -B $FREESURFER_HOME:/opt/freesurfer /blue/clp7934/share/fsqc.sif --subjects_dir /in --subjects sub-011S6367 --output_dir /out --shape

#Convert those "shape" files to stl, combine them, and perform smoothing of the surface.

apptainer run -B /blue/clp7934/share/jjtanner/ADNI_bids/derivatives/freesurfer/3dprint/brainprint/sub-011S6367/surfaces/:/in -B /blue/clp7934/share/jjtanner/ADNI_bids/derivatives/freesurfer/3dprint:/out /blue/clp7934/share/3dprintprep.sif /in /out/sub-011S6367.stl

Clone this wiki locally