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

WIP - Update scilpy & tractometry #2

Merged
merged 14 commits into from
Oct 21, 2020
2 changes: 1 addition & 1 deletion USAGE
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DESCRIPTION

[root]
├── S1
│ ├── *anat.nii.gz
│ ├── *fa.nii.gz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it really need to be an FA?
For instance, in my test case, I have b0 and I believe it should work, no?

Can you add something in the help about that please?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also,

  1. Can you provide a link to your zenodo URL please
  2. Can you add a centroids directory or download on the zenodo?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, a lot of our flows use --root, others use --input. Can we harmonize this?

--input or --root?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--input

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should work with anything, but I want to leave *fa.nii.gz as an input name

│ └── *tracking.trk
└── S2
└── *
Expand Down
62 changes: 32 additions & 30 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,28 @@ log.info ""
log.info "Input: $params.root"
root = file(params.root)
/* Watch out, files are ordered alphabetically in channel */
in_data = Channel
.fromFilePairs("$root/**/{*tracking.trk,*anat.nii.gz}",
size: 2,
maxDepth:2,
flat: true) {it.parent.name}

atlas_anat = Channel.fromPath("$params.atlas_anat")
atlas_config = Channel.fromPath("$params.atlas_config")
atlas_directory = Channel.fromPath("$params.atlas_directory")

if (params.atlas_centroids) {
atlas_centroids = Channel.fromPath("$params.atlas_centroids/*.trk")
}
else {
atlas_centroids = Channel.empty()
}

(anat_for_registration, anat_for_reference, tractogram_for_recognition) = in_data
.map{sid, anat, tractogram ->
[tuple(sid, anat),
tuple(sid, anat),
tuple(sid, tractogram)]}
.separate(3)
Channel
.fromPath("$root/**/*tracking*.trk",
maxDepth:1)
.map{[it.parent.name, it]}
.set{tractogram_for_recognition}

Channel
.fromPath("$root/**/*fa.nii.gz",
maxDepth:1)
.map{[it.parent.name, it]}
.into{anat_for_registration;anat_for_reference_c;anat_for_reference_b}
frheault marked this conversation as resolved.
Show resolved Hide resolved

atlas_anat = Channel.fromPath("$params.atlas_anat")
frheault marked this conversation as resolved.
Show resolved Hide resolved
atlas_config = Channel.fromPath("$params.atlas_config")
atlas_directory = Channel.fromPath("$params.atlas_directory")

if (params.atlas_centroids) {
atlas_centroids = Channel.fromPath("$params.atlas_centroids/*_centroid.trk")
}
else {
atlas_centroids = Channel.empty()
}

workflow.onComplete {
log.info "Pipeline completed at: $workflow.complete"
Expand All @@ -95,17 +94,16 @@ process Register_Anat {
set sid, file(native_anat), file(atlas) from anats_for_registration

output:
set sid, "${sid}__output0GenericAffine.txt" into transformation_for_recognition, transformation_for_centroids
set sid, "${sid}__output0GenericAffine.mat" into transformation_for_recognition, transformation_for_centroids
file "${sid}__outputWarped.nii.gz"
script:
"""
antsRegistrationSyNQuick.sh -d 3 -f ${native_anat} -m ${atlas} -n ${params.register_processes} -o ${sid}__output -t a
ConvertTransformFile 3 ${sid}__output0GenericAffine.mat ${sid}__output0GenericAffine.txt --hm --ras
"""
}


anat_for_reference
anat_for_reference_c
.join(transformation_for_centroids, by: 0)
.set{anat_and_transformation}
process Transform_Centroids {
Expand All @@ -116,29 +114,33 @@ process Transform_Centroids {
file "${sid}__${centroid.baseName}.trk"
script:
"""
scil_apply_transform_to_tractogram.py ${centroid} ${anat} ${transfo} ${sid}__${centroid.baseName}.trk --inverse --remove_invalid
scil_apply_transform_to_tractogram.py ${centroid} ${anat} ${transfo} ${sid}__${centroid.baseName}.trk --inverse --cut_invalid
"""
}


tractogram_for_recognition
.combine(transformation_for_recognition, by: 0)
.join(anat_for_reference_b)
.join(transformation_for_recognition)
.combine(atlas_config)
.combine(atlas_directory)
.set{tractogram_and_transformation}
process Recognize_Bundles {
cpus params.rbx_processes
input:
set sid, file(tractogram), file(transfo), file(config), file(directory) from tractogram_and_transformation
set sid, file(tractogram), file(refenrence), file(transfo), file(config), file(directory) from tractogram_and_transformation
output:
set sid, "*.trk" into bundles_for_cleaning
file "results.json"
file "logfile.txt"
script:
"""
scil_remove_invalid_streamlines.py ${tractogram} tractogram_ic.trk --reference ${refenrence}
mkdir tmp/
scil_recognize_multi_bundles.py ${tractogram} ${config} ${directory}/*/ ${transfo} --inverse --output tmp/ \
scil_recognize_multi_bundles.py tractogram_ic.trk ${config} ${directory}/*/ ${transfo} --inverse --out_dir tmp/ \
--log_level DEBUG --multi_parameters $params.multi_parameters --minimal_vote_ratio $params.minimal_vote_ratio \
--tractogram_clustering_thr $params.wb_clustering_thr --seeds $params.seeds --processes $params.rbx_processes
rm tractogram_ic.trk
mv tmp/* ./
"""
}
Expand Down