Skip to content

Commit

Permalink
Merge pull request #2 from frheault/update_scilpy
Browse files Browse the repository at this point in the history
WIP - Adaptation to scilpy
  • Loading branch information
GuillaumeTh authored Oct 23, 2020
2 parents aec0f54 + 2171c6f commit c0ba111
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
===================

Run the Bundle Specific Tractography pipeline.
To access the template in the original publication:
https://zenodo.org/record/4104309#.X4xduZ1KhdU

If you use this pipeline, please cite:

Expand Down
6 changes: 3 additions & 3 deletions USAGE
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Pipeline for bundle-specific tractography

USAGE

nextflow run main.nf --root ... [OPTIONAL_ARGUMENTS]
nextflow run main.nf --input ... [OPTIONAL_ARGUMENTS]

DESCRIPTION

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

[root]
├── S1
Expand Down Expand Up @@ -40,7 +40,7 @@ OPTIONAL ARGUMENTS (current value)
--seeding Seeding strategy, either npv or nts ($seeding)
--nbr_seeds Number of seeds to initialize, per voxel or total ($nbr_seeds)
--algo Choice between "prob", "det" or "prob,det" ($algo)
--basis SH basis of the input FOD ($basis)
--sh_basis SH basis of the input FOD, descoteaux07 or tournier07 ($sh_basis)
--min_length Minimal length in mm of streamline ($min_length)
--max_length Maximal length in mm of streamline ($max_length)
--compress_error_tolerance Error tolerance for streamline compression in mm ($compress_error_tolerance)
Expand Down
33 changes: 20 additions & 13 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if(params.help) {
"seeding":"$params.seeding",
"nbr_seeds":"$params.nbr_seeds",
"algo":"$params.algo",
"basis":"$params.basis",
"sh_basis":"$params.sh_basis",
"min_length":"$params.min_length",
"max_length":"$params.max_length",
"compress_error_tolerance":"$params.compress_error_tolerance",
Expand Down Expand Up @@ -81,8 +81,8 @@ log.info "Outlier Removal Alpha: $params.outlier_alpha"
log.info ""
log.info ""

log.info "Input: $params.root"
root = file(params.root)
log.info "Input: $params.input"
root = file(params.input)
/* Watch out, files are ordered alphabetically in channel */
in_data = Channel
.fromFilePairs("$root/**/{*fa.nii.gz,*fodf.nii.gz,*tracking_mask.nii.gz}",
Expand All @@ -96,6 +96,11 @@ root = file(params.root)
maxDepth:2,
flat: true) {it.parent.name}

if (!(params.atlas_anat) || !(params.atlas_directory)) {
error "You must specify all 2 atlas related input. --atlas_anat " +
"and --atlas_directory all are mandatory."
}

atlas_anat = Channel.fromPath("$params.atlas_anat")
atlas_bundles = Channel.fromPath("$params.atlas_directory/*.trk")
algo_list = params.algo?.tokenize(',')
Expand Down Expand Up @@ -130,6 +135,7 @@ process Register_Anat {
output:
set sid, "${sid}__output1InverseWarp.nii.gz", "${sid}__output0GenericAffine.mat" into deformation_for_warping
file "${sid}__outputWarped.nii.gz"
file "${sid}__output1Warp.nii.gz"
script:
"""
antsRegistrationSyNQuick.sh -d 3 -f ${native_anat} -m ${atlas} -n ${params.register_processes} -o ${sid}__output
Expand All @@ -150,9 +156,7 @@ process Warp_Bundle {
set sid, val(bundle_name.baseName), "${sid}__${bundle_name.baseName}_warp.trk" into bundles_for_priors, models_for_recobundles
script:
"""
ConvertTransformFile 3 ${affine} ${affine}.txt --hm --ras
scil_apply_transform_to_tractogram.py ${bundle_name} ${warp} ${affine}.txt ${bundle_name.baseName}_linear.trk --inverse --remove_invalid -f
scil_apply_warp_to_tractogram.py ${bundle_name.baseName}_linear.trk ${anat} ${warp} ${sid}__${bundle_name.baseName}_warp.trk --remove_invalid -f
scil_apply_transform_to_tractogram.py ${bundle_name} ${anat} ${affine} ${sid}__${bundle_name.baseName}_warp.trk --inverse --cut_invalid --in_deformation ${warp}
"""
}

Expand All @@ -179,8 +183,9 @@ process Generate_Priors {
set sid, val(bundle_name), "${sid}__${bundle_name}_endpoints_mask_dilate.nii.gz" into masks_for_map_in
script:
"""
scil_generate_priors_from_bundle.py ${bundle} ${fod} ${mask} \
--sh_basis $params.basis --output_prefix ${sid}__${bundle_name}_
scil_image_math.py convert ${mask} mask.nii.gz --data_type uint8
scil_generate_priors_from_bundle.py ${bundle} ${fod} mask.nii.gz \
--sh_basis $params.sh_basis --out_prefix ${sid}__${bundle_name}_
scil_image_math.py dilation ${sid}__${bundle_name}_todi_mask.nii.gz \
$params.bs_tracking_mask_dilation dilate_todi.nii.gz --data_type uint8
scil_image_math.py multiplication ${mask} dilate_todi.nii.gz \
Expand Down Expand Up @@ -226,11 +231,11 @@ process Tracking_Mask {
script:
if (params.use_bs_tracking_mask)
"""
mv ${bs_mask} ${sid}__${bundle_name}_tracking_mask.nii.gz
scil_image_math.py convert ${bs_mask} ${sid}__${bundle_name}_tracking_mask.nii.gz --data_type uint8
"""
else
"""
mv ${tracking_mask} ${sid}__${bundle_name}_tracking_mask.nii.gz
scil_image_math.py convert ${tracking_mask} ${sid}__${bundle_name}_tracking_mask.nii.gz --data_type uint8
"""
}

Expand Down Expand Up @@ -260,10 +265,12 @@ process Local_Tracking {
script:
"""
scil_compute_local_tracking.py ${efod} ${seeding_mask} ${tracking_mask} \
${sid}__${bundle_name}_${algo}_${params.seeding}_${params.nbr_seeds}.trk \
--sh_basis $params.basis --min_len $params.min_length --max_len $params.max_length \
tracking.trk --sh_basis $params.sh_basis --min_len $params.min_length --max_len $params.max_length \
--$params.seeding $params.nbr_seeds --compress $params.compress_error_tolerance \
--seed $params.tracking_seed --algo ${algo}
scil_remove_invalid_streamlines.py tracking.trk tracking_ic.trk
scil_filter_tractogram.py tracking_ic.trk ${sid}__${bundle_name}_${algo}_${params.seeding}_${params.nbr_seeds}.trk \
--drawn_roi ${seeding_mask} either_end include
"""
}

Expand Down Expand Up @@ -344,7 +351,7 @@ process PFT_Tracking {
"""
scil_compute_pft.py ${efod} ${seeding_mask} ${map_include} ${map_exclude} \
${sid}__${bundle_name}_${algo}_${params.seeding}_${params.nbr_seeds}.trk \
--algo $algo --sh_basis $params.basis --min_length $params.min_length \
--algo $algo --sh_basis $params.sh_basis --min_length $params.min_length \
--max_length $params.max_length --$seeding $params.nbr_seeds \
--compress $params.compress_error_tolerance --seed $params.tracking_seed
scil_remove_invalid_streamlines.py ${sid}__${bundle_name}_${algo}_${params.seeding}_${params.nbr_seeds}.trk ${sid}__${bundle_name}_${algo}_${params.seeding}_${params.nbr_seeds}.trk -f
Expand Down
2 changes: 1 addition & 1 deletion nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ params {
seeding="npv"
nbr_seeds=1
algo="prob"
basis="descoteaux07"
sh_basis="descoteaux07"
min_length=20
max_length=200
compress_error_tolerance=0.2
Expand Down

0 comments on commit c0ba111

Please sign in to comment.