### Fetch example data Source: https://qsiprep.readthedocs.io/en/latest/api/qsiprep.interfaces.bids.html Initializes the environment with BIDS example data for testing purposes. ```python >>> import os >>> from niworkflows import data >>> data_root = data.get_bids_examples(variant='BIDS-examples-1-enh-ds054') >>> os.chdir(data_root) ``` -------------------------------- ### Install QSIPrep via pip Source: https://qsiprep.readthedocs.io/en/latest/_sources/installation.rst.txt Installs the QSIPrep Python library. Note that this method does not include required non-Python dependencies. ```bash $ pip install --user --upgrade qsiprep ``` -------------------------------- ### Example file representation of QSIPrep settings Source: https://qsiprep.readthedocs.io/en/latest/api.html A sample ToML configuration file used to store and pass QSIPrep settings across processes. ```toml [environment] cpu_count = 1 exec_env = "docker" free_mem = 52.2 overcommit_policy = "heuristic" overcommit_limit = "50%" nipype_version = "1.9.1" templateflow_version = "23.1.0" version = "1.0.0rc2.dev29+gdee1425.d20250113" [execution] bids_dir = "/tmp/src/qsiprep/.circleci/data/forrest_gump" bids_database_dir = "/tmp/src/qsiprep/.circleci/work/forrest_gump/20250113-154517_1f7046f7-c5b1-4151-84ca-755a96dfbb55/bids_db" bids_description_hash = "86891931159357fa937a6724ac27013f79ca56859100547ed9793245866312cd" boilerplate_only = false sloppy = true debug = [] layout = "BIDS Layout: ...ep/.circleci/data/forrest_gump | Subjects: 1 | Sessions: 1 | Runs: 0" log_dir = "/tmp/src/qsiprep/.circleci/out/forrest_gump/logs" log_level = 15 low_mem = false notrack = true output_dir = "/tmp/src/qsiprep/.circleci/out/forrest_gump" reports_only = false run_uuid = "20250113-154517_1f7046f7-c5b1-4151-84ca-755a96dfbb55" participant_label = [ "01",] processing_list = [ "01:forrestgump",] skip_anat_based_spatial_normalization = false templateflow_home = "/home/qsiprep/.cache/templateflow" work_dir = "/tmp/src/qsiprep/.circleci/work/forrest_gump" write_graph = true [workflow] anat_modality = "T1w" anat_only = false anatomical_template = "MNI152NLin2009cAsym" b0_threshold = 100 b0_motion_corr_to = "iterative" b0_to_t1w_transform = "Rigid" b1_biascorrect_stage = "none" denoise_after_combining = false denoise_method = "none" distortion_group_merge = "none" dwi_denoise_window = "auto" dwi_no_biascorr = false dwi_only = false fmap_bspline = false force_syn = false hmc_model = "eddy" hmc_transform = "Affine" ignore = [] infant = false intramodal_template_iters = 0 intramodal_template_transform = "BSplineSyN" subject_anatomical_reference = "first-lex" longitudinal = false no_b0_harmonization = false output_resolution = 5.0 pepolar_method = "TOPUP" separate_all_dwis = false shoreline_iters = 2 use_syn_sdc = false spaces = "MNI152NLin2009cAsym" [nipype] crashfile_format = "txt" get_linked_libs = false nprocs = 4 omp_nthreads = 4 plugin = "MultiProc" remove_unnecessary_outputs = true resource_monitor = false stop_on_first_crash = true [seeds] master = 20506 ants = 2720 numpy = 32806 [execution.derivatives] [execution.dataset_links] raw = "/tmp/src/qsiprep/.circleci/data/forrest_gump" templateflow = "/home/qsiprep/.cache/templateflow" [nipype.plugin_args] maxtasksperchild = 1 raise_insufficient = false [execution.bids_filters.t1w] reconstruction = "autobox" [execution.bids_filters.t2w] reconstruction = "autobox" ``` -------------------------------- ### Install apt packages in Dockerfile Source: https://qsiprep.readthedocs.io/en/latest/contributors.html Use this command within the Dockerfile to install system-level dependencies via apt-get. ```dockerfile RUN apt-get update && \ apt-get install -y ``` -------------------------------- ### Filtering by session and run Source: https://qsiprep.readthedocs.io/en/latest/_sources/preprocessing.rst.txt Example of a BIDS filter file selecting specific sessions and runs. ```json { "t1w": { "session": "MR1" }, "dwi": { "session": "MR1", "run": "1" } } ``` -------------------------------- ### Generate TOPUP selection report Source: https://qsiprep.readthedocs.io/en/latest/api/qsiprep.interfaces.reports.html Examples demonstrating how to generate a text summary of image selections for TOPUP distortion correction. ```python >>> selected_indices = [0, 15, 30, 45] >>> original_files = ["sub-1_dir-AP_dwi.nii.gz"] * 30 + ["sub-1_dir-PA_dwi.nii.gz"] * 30 >>> spec_lookup = {"sub-1_dir-AP_dwi.nii.gz": "0 1 0 0.087", ... "sub-1_dir-PA_dwi.nii.gz": "0 -1 0 0.087"} >>> print(topup_selection_to_report(selected_indices, original_files, spec_lookup)) A total of 2 distortion groups was included in the combined dwi data. Distortion group '0 1 0 0.087' was represented by images 0, 15 from sub-1_dir-AP_dwi.nii.gz. Distortion group '0 -1 0 0.087' was represented by images 0, 15 from sub-1_dir-PA_dwi.nii.gz. ``` ```python >>> selected_indices = [0, 15, 30, 45] >>> original_files = ["sub-1_dir-AP_run-1_dwi.nii.gz"] * 15 + [ ... "sub-1_dir-AP_run-2_dwi.nii.gz"] * 15 + [ ... "sub-1_dir-PA_dwi.nii.gz"] * 30 >>> spec_lookup = {"sub-1_dir-AP_run-1_dwi.nii.gz": "0 1 0 0.087", ... "sub-1_dir-AP_run-2_dwi.nii.gz": "0 1 0 0.087", ... "sub-1_dir-PA_dwi.nii.gz": "0 -1 0 0.087"} >>> print(topup_selection_to_report(selected_indices, original_files, spec_lookup)) A total of 2 distortion groups was included in the combined dwi data. Distortion group '0 1 0 0.087' was represented by image 0 from sub-1_dir-AP_run-1_dwi.nii.gz and image 0 from sub-1_dir-AP_run-2_dwi.nii.gz. Distortion group '0 -1 0 0.087' was represented by images 0, 15 from sub-1_dir-PA_dwi.nii.gz. ``` -------------------------------- ### AddTSVHeader usage example Source: https://qsiprep.readthedocs.io/en/latest/api/qsiprep.interfaces.utils.html Demonstrates how to use AddTSVHeader to prepend column headers to an existing TSV file. ```python >>> import os >>> import pandas as pd >>> import numpy as np >>> from tempfile import TemporaryDirectory >>> tmpdir = TemporaryDirectory() >>> os.chdir(tmpdir.name) ``` ```python >>> np.savetxt('data.tsv', np.arange(30).reshape((6, 5)), delimiter=' ') ``` ```python >>> from qsiprep.interfaces import AddTSVHeader >>> addheader = AddTSVHeader() >>> addheader.inputs.in_file = 'data.tsv' >>> addheader.inputs.columns = ['a', 'b', 'c', 'd', 'e'] >>> res = addheader.run() >>> pd.read_csv(res.outputs.out_file, sep='\s+', index_col=None, ... engine='python') a b c d e 0 0.0 1.0 2.0 3.0 4.0 1 5.0 6.0 7.0 8.0 9.0 2 10.0 11.0 12.0 13.0 14.0 3 15.0 16.0 17.0 18.0 19.0 4 20.0 21.0 22.0 23.0 24.0 5 25.0 26.0 27.0 28.0 29.0 ``` ```python >>> tmpdir.cleanup() ``` -------------------------------- ### Install apt dependencies in Dockerfile Source: https://qsiprep.readthedocs.io/en/latest/_sources/contributors.rst.txt Add non-Python system dependencies using the RUN command in the Dockerfile. ```dockerfile RUN apt-get update && \ apt-get install -y ``` -------------------------------- ### Interpret QSIPrep verbose terminal output Source: https://qsiprep.readthedocs.io/en/latest/quickstart.html Example of the log output showing active nodes and resource utilization during workflow execution. ```text [Node] Setting-up "qsiprep_wf.single_subject_PNC_wf.dwi_finalize_acq_realistic_wf.transform_dwis_t1.final_b0_ref.b0ref_reportlet" in "/scratch/qsiprep_wf/single_subject_PNC_wf/dwi_finalize_acq_realistic_wf/transform_dwis_t1/final_b0_ref/b0ref_reportlet". 201229-21:33:46,213 nipype.workflow INFO: [Node] Running "b0ref_reportlet" ("niworkflows.interfaces.registration.SimpleBeforeAfterRPT") 201229-21:33:48,51 nipype.workflow INFO: [MultiProc] Running 2 tasks, and 3 jobs ready. Free memory (GB): 3.70/4.00, Free processors: 0/2. Currently running: * qsiprep_wf.single_subject_PNC_wf.dwi_finalize_acq_realistic_wf.transform_dwis_t1.final_b0_ref.b0ref_reportlet * qsiprep_wf.single_subject_PNC_wf.anat_preproc_wf.mni_mask ``` -------------------------------- ### Example BIDS input file structure Source: https://qsiprep.readthedocs.io/en/latest/_sources/quickstart.rst.txt A representation of the expected file hierarchy for DWI and fieldmap data in a BIDS-compliant directory. ```text sub-1/ses-1/dwi/sub-1_ses-1_acq-multishell_run-01_dwi.nii.gz sub-1/ses-1/dwi/sub-1_ses-1_acq-multishell_run-01_dwi.nii.gz sub-1/ses-1/dwi/sub-1_ses-1_acq-multishell_run-03_dwi.nii.gz sub-1/ses-1/fmap/sub-1_ses-1_dir-PA_epi.nii.gz ``` -------------------------------- ### Model Diffusion Signal with SHORE Basis Source: https://qsiprep.readthedocs.io/en/latest/api/qsiprep.utils.brainsuite_shore.html Example demonstrating how to model the diffusion signal using the SHORE basis and compute the analytical ODF. ```python from dipy.data import get_data,get_sphere sphere = get_sphere(‘symmetric724’) fimg, fbvals, fbvecs = get_data(‘ISBI_testing_2shells_table’) bvals, bvecs = read_bvals_bvecs(fbvals, fbvecs) gtab = gradient_table(bvals, bvecs) from dipy.sims.voxel import SticksAndBall data, golden_directions = SticksAndBall( > gtab, d=0.0015, S0=1., angles=[(0, 0), (90, 0)], fractions=[50, 50], snr=None) from dipy.reconst.canal import ShoreModel radial_order = 4 zeta = 700 asm = ShoreModel(gtab, radial_order=radial_order, zeta=zeta, > lambdaN=1e-8, lambdaL=1e-8) asmfit = asm.fit(data) odf= asmfit.odf(sphere) ``` -------------------------------- ### Build and Run QSIPrep with Apptainer Source: https://qsiprep.readthedocs.io/en/latest/_sources/installation.rst.txt Commands to build an Apptainer image and execute it with necessary bindings for data and licenses. ```bash $ apptainer build qsiprep-.sif docker://pennlinc/qsiprep: ``` ```bash $ apptainer run --containall --writable-tmpfs \ -B $HOME/fullds005,$HOME/dockerout,${FREESURFER_HOME}/license.txt:/opt/freesurfer/license.txt \ qsiprep-.sif \ $HOME/fullds005 $HOME/dockerout participant \ --fs-license-file /opt/freesurfer/license.txt \ --output-resolution 2 ``` -------------------------------- ### QSIPrep Command-Line Help Source: https://qsiprep.readthedocs.io/en/latest/usage.html Full list of available command-line arguments and flags for QSIPrep. ```bash usage: qsiprep [-h] [--skip-bids-validation] [--participant-label PARTICIPANT_LABEL [PARTICIPANT_LABEL ...]] [--session-id SESSION_ID [SESSION_ID ...]] [--bids-filter-file FILE] [--bids-database-dir PATH] [--nprocs NPROCS] [--omp-nthreads OMP_NTHREADS] [--mem MEMORY_MB] [--low-mem] [--use-plugin FILE] [--sloppy] [--anat-only] [--dwi-only] [--boilerplate-only] [--reports-only] [--ignore {fieldmaps,t2w,phase} [{fieldmaps,t2w,phase} ...]] [--infant] [--longitudinal] [--subject-anatomical-reference {first-lex,unbiased,sessionwise,first-alphabetically}] [--skip-anat-based-spatial-normalization] [--anat-modality {T1w,T2w,none}] [--b0-threshold B0_THRESHOLD] [--dwi-denoise-window DWI_DENOISE_WINDOW] [--denoise-method {dwidenoise,patch2self,none}] [--unringing-method {none,mrdegibbs,rpg}] [--dwi-no-biascorr] [--b1-biascorrect-stage {final,none,legacy}] [--no-b0-harmonization] [--denoise-after-combining] [--separate-all-dwis] [--distortion-group-merge {concat,average,none}] [--anatomical-template {MNI152NLin2009cAsym}] --output-resolution OUTPUT_RESOLUTION [--b0-to-t1w-transform {Rigid,Affine}] [--intramodal-template-iters INTRAMODAL_TEMPLATE_ITERS] [--intramodal-template-transform {Rigid,Affine,BSplineSyN,SyN}] [--fs-license-file PATH] [--b0-motion-corr-to {iterative,first}] [--hmc-transform {Affine,Rigid}] [--hmc-model {none,3dSHORE,eddy,tensor}] [--eddy-config EDDY_CONFIG] [--shoreline-iters SHORELINE_ITERS] [--pepolar-method {TOPUP,DRBUDDI,TOPUP+DRBUDDI}] [--fmap-bspline] [--fmap-no-demean] [--use-syn-sdc [{warn,error}]] [--force-syn] [--version] [-v] [-w WORK_DIR] [--resource-monitor] [--config-file FILE] [--write-graph] [--stop-on-first-crash] [--notrack] [--debug {fieldmaps,pdb,all} [{fieldmaps,pdb,all} ...]] bids_dir output_dir {participant} ``` -------------------------------- ### DWI Transform File Structure Source: https://qsiprep.readthedocs.io/en/latest/_sources/preprocessing.rst.txt Example directory structure for DWI transform files. ```text sub-