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

Added spinal cord analysis pipeline (Nextflow) #13

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
157 changes: 157 additions & 0 deletions USAGE-ANAT
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
qMRflow mt_sat pipeline
https://qmrlab.org
===================

USAGE

nextflow run mtsatflow_BIDS.nf [OPTIONAL_ARGUMENTS] (--root)

DESCRIPTION

--root=/path/to/[root] Root folder containing multiple subjects

FOLDER ORGANIZATION

BIDS convention For mtsatflow_BIDS.nf

[root]
├── sub-01
│ │── anat
│ │ ├── sub-01_acq-MTon_MTS.nii.gz
| | ├── sub-01_acq-MTon_MTS.json
│ │ ├── sub-01_acq-MToff_MTS.nii.gz
│ │ ├── sub-01_acq-MToff_MTS.json
│ │ ├── sub-01_acq-T1w_MTS.nii.gz
│ │ └── sub-01_acq-T1w_MTS.json
│ └── fmap
│ └── sub-01_B1plusmap.nii.gz (optional)
└── sub-02
│── anat
│ ├── sub-02_acq-MTon_MTS.nii.gz
| ├── sub-02_acq-MTon_MTS.json
│ ├── sub-02_acq-MToff_MTS.nii.gz
│ ├── sub-02_acq-MToff_MTS.json
│ ├── sub-02_acq-T1w_MTS.nii.gz
│ └── sub-02_acq-T1w_MTS.json
└── fmap
└── sub-02_B1plusmap.nii.gz (optional)

OPTIONAL ARGUMENTS

--platform ["octave"/"matlab"] Platform choice.
--qmrlab_dir ["/path/to/qMRLab" OR null] Absolute path to the qMRLab's
root directory. If docker is enabled, MUST be set
to null (without double quotes). If docker is NOT enabled,
then the absolute path to the qMRLab MUST be provided.
Note that qMRLab version MUST be equal or greater than v2.3.1.
--octave_path ["/path/to/octave_exec" OR null] Absolute path to Octave's
executable. If docker is enabled, or, if you'd like to use
Octave executable saved to your system path, MUST be set to
null (without double quotes).
--matlab_path ["/path/to/matlab_exec" OR null] Absolute path to MATLAB's
executable. If you'd like to use MATLAB executable saved to
your system path, MUST be set to null (without double quotes).
Note that qMRLab requires MATLAB > R2014b. Docker image
containing MCR compiled version of this application is NOT
available yet. Therefore, container declerations for the
processes starting with Fit_ prefix MUST be set to null
(without double quotes).
--ants_dim [2/3/4] This option forces the image to be treated
as a specified-dimensional image. If not specified,
ANTs tries to infer the dimensionality.
--ants_metric ["MI"] Confined to MI: Mutual information, for this
particular pipeline.
--ants_metric_weight [0-1] If multimodal (i.e. changing contrast) use weight 1.
This parameter is used to modulate the per stagehting
of the metrics.
--ants_metric_bins [e.g. 32] Number of bins.
--ants_metric_sampling ["Regular","Random:]The point set can be on a regular
lattice or a random lattice of points slightly perturbed
to minimize aliasing artifacts.
--ants_metric_samplingprct [0-100] The fraction of points to select from the domain
--ants_transform "Rigid"
"Affine"
"CompositeAffine"
"Similarity"
"Translation"
"BSpline"
--ants_convergence [MxNxO,<convergenceThreshold=1e-6>,<convergenceWindowSize=10>]
Convergence is determined from the number of iterations per level
and is determined by fitting a line to the normalized energy
profile of the last N iterations (where N is specified by the window
size) and determining the slope which is then compared with the convergence threshold.
--ants_shrink [MxNxO] Specify the shrink factor for the virtual domain (typically
the fixed image) at each level.
--ants_smoothing [MxNxO] Specify the sigma of gaussian smoothing at each level.
Units are given in terms of voxels ('vox') or physical spacing ('mm').
Example usage is '4x2x1mm' and '4x2x1vox' where no units implies voxel spacing.
--use_b1cor [true/false] Use and RF transmit field to correct for flip
angle imperfections.
--b1cor_factor [0-1] Correction factor (empirical) for the transmit RF. Only
corrects MTSAT, not T1. Default 0.4.
--use_bet Use FSL's BET for skull stripping.
--bet_recursive [true/false] This option runs more "robust" brain center estimation.
--bet_threshold [0-1] Fractional intensity threshold (0->1); default=0.45;
smaller values give larger brain outline estimates


NOTES

- BIDS:

mtsatflow_BIDS.nf To process BIDSified MTsat data. Note that BIDS for
quantitative MRI data is under development as of
early 2020. You can visit the GitHub project page
[here](https://github.com/bids-standard/bep001).
- Example datasets:

Custom-organized data TBA
BIDSified MTsat data https://osf.io/k4bs5/

- Files should be compressed Nifti files (.nii.gz)

- Timing parameters in the .json files MUST be in seconds.

- Subject IDs are used as the primary process ID and tag throughout the pipeline.

- We adhere to a strict one-process one-container mapping, where possible using off-the shelf
qMRLab containers.

- All the OPTIONAL ARGUMENTS can be modified in the `nextflow.config` file. The same
config file is consumed by both `mtsatflow.nf` and `mtsatflow_BIDS.nf`.

- Unless the docker option is enabled in the `nextflow.config`, the following
dependencies must be installed and added to the system path:
* ANTs registration (https://github.com/ANTsX/ANTs)
* FSL (https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/)
* Octave/MATLAB (https://www.gnu.org/software/octave/)
(https://www.mathworks.com/)
* qMRLab > v2.3.1 (https://qmrlab.org)
* git

If you have Docker installed, enabling docker option will make use of the
following Docker images to execute processes:
- qmrlab/minimal (https://hub.docker.com/repository/docker/qmrlab/minimal)
594MB extends to 1.5GB
Built at each qMRLab release.
- qmrlab/antsfsl (https://hub.docker.com/repository/docker/qmrlab/antsfsl)
374MB extends to 1.2GB
Dockerfile is available at qMRLab/qMRflow.

- You can take advantage of Nextflow's comprehensive tracing and visualization
features while executing this pipeline: https://www.nextflow.io/docs/latest/tracing.html.

- For any requests, questions or contributions, please feel free to open
an issue at qMRflow's GitHub repo at https://github.com/qMRLab/qMRflow.

REFERENCES

Please cite the following if you use this module:

Helms, G. et al. 2008. High-resolution maps of magnetization transfer with inherent correction
for RF inhomogeneity and T1 relaxation obtained from 3D FLASH MRI. Magn. Reson. Med. 60, 1396?1407.

In addition to:

Karakuzu A. et al. 2019 The qMRLab workflow: From acquisition to publication., ISMRM 27th Annual
Meeting and Exhibition, Montreal, Canada.
79 changes: 79 additions & 0 deletions USAGE-SCT
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
Neuromod spinal cord data processing pipeline
===================

USAGE

Prototype:
----------
nextflow -C neuromod-process-spinalcord.config run neuromod-process-spinalcord.nf [OPTIONAL_ARGUMENTS] (--bids)

Example:
---------
nextflow -C neuromod-process-spinalcord.config -log log_directory/sct.log run neuromod-process-spinalcord.nf --bids /neuromod_bids_dir -w /work_directory -with-report report_spinal.html

DESCRIPTION

--bids=/path/to/[root] Root folder containing BIDS data
-C Use the specified configuration file overriding any defaults.
-log Set nextflow log file path
-w The working directory. Note that if you delete or move the pipeline
work directory, this will prevent to use the resume feature in subsequent
runs. Also note that the pipeline work directory is intended to be used as a
temporary scratch area. The final workflow outputs are expected to be stored in a
different location specified using the publishDir directive.
-with-report Specifcy a report name (e.g. report.html) for having interactive workflow execution report.
-resume Pass as the last argument if you'd like to resume a previously cached
workflow, which was interrupted previously.

FOLDER ORGANIZATION

BIDS convention For MTsat data

[root]
├── sub-01
│── ses-001/anat
│ ├── sub-01_acq-MTon_bp-spine_MTS.nii.gz
| ├── sub-01_acq-MTon_bp-spine_MTS.json
│ ├── sub-01_acq-MToff_bp-spine_MTS.nii.gz
│ ├── sub-01_acq-MToff_bp-spine_MTS.json
│ ├── sub-01_acq-T1w_bp-spine_MTS.nii.gz
│ └── sub-01_acq-T1w_bp-spine_MTS.json
└── fmap
└── sub-01_TB1map.nii.gz (optional)


OPTIONAL ARGUMENTS

When passed as an argument during `nextflow run` call, the respective value defined for that parameter
in the neuromod-process-spinalcord.config will be overridden.

--sct_parameter [/this/that/type] Explanation.
--sct_another_parameter [/this/that/type] Explanation.


NOTES

- Timing parameters in the .json files MUST be in seconds.

- Subject IDs are used as the primary process ID and tag throughout the pipeline. Defined by the
following BIDS entities:
- sub
- ses
- rec
- acq (unless reserved for inferring file pairs)



- All the OPTIONAL ARGUMENTS can be modified in the `nextflow.config` file. The same
config file is consumed by both `mtsatflow.nf` and `mtsatflow_BIDS.nf`.

- Unless the docker option is enabled in the `nextflow.config`, the following
dependencies must be installed and added to the system path:
* SCT

- You can take advantage of Nextflow's comprehensive tracing and visualization
features while executing this pipeline: https://www.nextflow.io/docs/latest/tracing.html.

REFERENCES

Please cite the following if you use this module:
29 changes: 29 additions & 0 deletions modules/spinalcord_mtsat.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Enable DSL2 so that this can be imported as a module
nextflow.enable.dsl=2

/* This PLACEHOLDER process is to explain the relationship
between the files emitted by the input channels, process and
how those files are process to emit outputs */

process MTS_Align_SpinalCord{
tag { sid }

input:
tuple val(sid), file(pdw), file(mtw), file(t1w)

output:
tuple val(sid), \
path("${sid}_MTSAT_example.txt"), \
emit: publish_spinal_mtsat

script:
"""
echo "sct_parameter was $params.sct_parameter\n" >> ${sid}_MTSAT_example.txt
echo "the other one was $params.sct_another_parameter\n" >> ${sid}_MTSAT_example.txt
echo "sid is ${sid}\n" >> ${sid}_MTSAT_example.txt
echo "MTon is $mtw\n" >> ${sid}_MTSAT_example.txt
echo "MToff is $pdw\n" >> ${sid}_MTSAT_example.txt
echo "T1w is $t1w\n" >> ${sid}_MTSAT_example.txt
echo "ENV vars can be captured: $PATH\n" >> ${sid}_MTSAT_example.txt
"""
}
43 changes: 43 additions & 0 deletions modules/spinalcord_segmentation.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Enable DSL2 so that this can be imported as a module
nextflow.enable.dsl=2

/* This PLACEHOLDER process is to explain the relationship
between the files emitted by the input channels, process and
how those files are process to emit outputs */

// TODO: find a way to avoid this code duplication below
process T1_Segment_SpinalCord{
tag { sid }

input:
tuple val(sid), file(t2w)

output:
tuple val(sid), \
path("${sid}_bp-cspine_T1w_seg.nii.gz"), \
emit: publish_spinalcord

script:
"""
sct_deepseg_sc -i $t2w -c t1 -qc $params.qcDir -qc-subject ${sid}
"""

}

process T2_Segment_SpinalCord{
tag { sid }

input:
tuple val(sid), file(t2w)

output:
tuple val(sid), \
path("${sid}_bp-cspine_T2w_seg.nii.gz"), \
emit: publish_spinal_seg

script:
"""
sct_deepseg_sc -i $t2w -c t2 -qc $params.qcDir -qc-subject ${sid}
"""

}
41 changes: 41 additions & 0 deletions neuromod-process-spinalcord.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//** Official documentation for config files: https://www.nextflow.io/docs/latest/config.html **//

process {

withName: SpinalCord {
cpus = 4
memory = 4.GB
maxForks = 2
}

}

params {

sct_parameter= "This is how default params are defined"
sct_another_parameter= 99
qcDir = "$params.bids/derivatives/SCT/qc"

}

//** Default one is standard (local), but other options are easily possible **//

profiles {

standard {
process.executor = 'local'
}

cluster {
process.executor = 'slurm'
process.queue = 'long'
process.memory = '10GB'
}

cloud {
process.executor = 'awsbatch'
process.container = 'docker.io/neuropoly/sct'
docker.enabled = true
}

}
Loading