QSIprep and pyAFQ to generate individual tracts and visualizations

Hi all,

I’m wondering what’s the best way to generate the individual tracts and visualizations when running QSIprep (prep and recon) on diffusion data. The recon step (pyafq_tractometry) outputs many files, including 2 trk files which contain a collection of tracts bundled in a single tractogram.

  • sub-#_ses-#_space-T1w_desc-preproc_dwi_space-RASMM_model-probCSD_algo-AFQ_tractography.trk
  • sub-#_ses-#_space-T1w_desc-preproc_dwi_space-RASMM_model-probCSD_algo-AFQ_desc-clean_tractography.trk

After exploring the pyAFQ documentation, I found that I can use the pyAFQ command-line-interface by running pyAFQ /path/to/config.toml where config.toml is filled out with the proper paths and specs. This produces individual tracts and viz from the QSIprep output. Is there a standard way to build this into the QSIprep recon step so it’s all done at once when run on my HPC?

Moreover, is there a way that I can customize the visualizations that are output? i.e. make color-coded tract scenes that are automatically generated?

Thank you so much!

Hi @mkersey and welcome to neurostars!

It also makes the individual bundles files by default, which seems to be what you are looking for. Is it not making those for you?

Yes, you can see that pyAFQ has an argument for this.

        help="Generate two default json files at the path"
        + " (which should be a folder) specified without running pyAFQ;"
        + " this json can be used to define a recon workflow in qsiprep.")

Use that to make a recon spec JSON similar to qsiprep/qsiprep/data/pipelines/pyafq_tractometry.json at 5ca5161743b8815b46cafb9191445f4f61113d65 · PennLINC/qsiprep · GitHub, and then pass in that file to the QSIPrep --recon-spec.

Don’t know about that, sorry.


1 Like

Thank you, Steven!

Correct, QSIprep is not outputting individual tracts for me. This is what my output looks like inside qsiprep_output/qsirecon/sub-#/ses-#/:

This is how I’m running it:

singularity run --cleanenv -B $DATADIR:/data:ro \
    -B $OUTDIR:/out \
    -B $FS_LICENSE/license.txt:/license/license.txt \
    $SIMGDIR/qsiprep-0.18.0.simg \
    /data /out participant \
    --participant-label ${sub} \
    -w /out/workdir \
    --recon-spec pyafq_tractometry \
    --recon-input /out/qsiprep \
    --freesurfer-input /out/freesurfer \
    --fs-license-file /license/license.txt \
    --output-resolution 1.2

So, using the pyAFQ CLI I would need to generate a QSIprep JSON and modify it, and pass it into QSIprep --recon-spec? Sorry for my inexperience. Thanks!

Hm, I used pyafq on QSIPrep 0.18.0 and I was able to get the bundles and clean_bundles folders. Did your process complete without crashing?

Looks okay to me (although, the --recon-input is ignored unless you also pass in --recon-only, which skips preprocessing).



Hmm interesting. I wonder why it’s not outputting the bundles and clean_bundles. It’s not crashing so that doesn’t make sense.
The end of my operational file looks like this:

230623-16:14:42,635 nipype.workflow INFO:
         [Node] Finished "run_afq", elapsed time 24830.610387s.

@Ariel_Rokem Would you possibly have a suggestion?

Thank you!!

Hi @mkersey!

Thanks for using pyAFQ and for your questions!

I am not sure why you are not getting these bundle folders. It does look like everything is completing as intended and they should be there.

There should also be another output in each subject’s folder, which is a .html file that contains a visualization with color-coded bundles that can be viewed interactively. Do I understand correctly that this file also isn’t generated?

In addition to this visualization, you can use the fury to generate publication-quality visualizations such as those in this example.


1 Like

Hey @mkersey, one more question: how confident are you that the qsiprep image that you are using is indeed running version 0.18 of qsiprep? The reason I ask is that this should have been fixed in 0.18, and I worry that you might be seeing this because you are inadvertently running a previous version. Thanks!


Hi @Ariel_Rokem, thank you for you reply!

I was actually running the recon separately from the prep with the —recon-only flag so that I could try multiple different recon options, which I should have specified earlier. I just tried running it altogether (prep + recon) on another case and triple checked that I was using version 0.18. Now I see the bundles and viz files! I’m amazed by how great the visualizations look. I don’t know why it didn’t it didn’t produce these folders when I ran recon-only after running prep.

Thank you so much!