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

Add group directives to mrtpipelines.smk #12

Merged
merged 3 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions dbsc/config/snakebids.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ derivatives: False # Search in bids/derivatives if True; can also be path(s) to

# List of analysis levels in bids app
analysis_levels: &analysis_levels
- participant
- participant1
- group
- participant2

# Mapping from analysis_level to set of target rules or files
targets_by_analysis_level:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to update this to reflect participant1 and participant2 analysis levels.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed this in c258563 - this is actually still suppose to be participant and group. Got this part mixed up with the group directive usage within the .smk file.

Expand Down Expand Up @@ -93,8 +94,8 @@ parse_args:
nargs: "+"

--step:
help: '(Mrtrix3) set the step size of the algorithm in mm
(default: 0.35mm)'
help: '(Mrtrix3) set the step size of the algorithm in mm. Should set to
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we're going to include this recommendation it would be good to briefly explain why or give a reference.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added reasoning in 36529fd

4 steps per voxel (e.g. 1/4 * voxel size). (default: 0.35mm)'
default: 0.35

--sl_count:
Expand All @@ -114,17 +115,10 @@ parse_args:
node is found within this radius, the streamline endpoint is not
assigned to any node. (default: 1.5mm)'
default: 1.5

--exclude_gm:
help: 'Exclude streamlines passing through other GM nodes along its
trajectory (default: True)'
default: True
action: 'store_false'

#-----------------------------------------------------#

# Workflow specific config
# Space (MNI152, MNINlin2009bAsym)
# Spaces available (MNI152, MNINlin2009bAsym)
space: MNI152

zona_bb_subcortex:
Expand All @@ -137,11 +131,12 @@ zona_bb_subcortex:
seg: 'resources/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_ZonaBBSubCorSeg.nii.gz'
exclude: 'resources/MNI152/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_desc-exclude_ROI.nii.gz'

# NOTE: This may not be needed with labelmerge
freesurfer:
labels: 'resources/freesurfer/fs_labels.csv'

# Containers
# Note: Update from latest to use specific tags
# NOTE: Update from latest to use specific tags
singularity:
freesurfer: "docker://pwighton/freesurfer:7.2.0"
neuroglia-core: "docker://khanlab/neuroglia-core:latest"
Expand Down
30 changes: 20 additions & 10 deletions dbsc/workflow/rules/mrtpipelines.smk
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ rule nii_to_mif:
shell:
'mrconvert -nthreads {threads} -fslgrad {input.bvecs} {input.bvals} {input.dwi} {output.dwi} '
'mrconvert -nthreads {threads} {input.mask} {output.mask}'
group: participant1


rule estimate_response:
Expand Down Expand Up @@ -91,8 +92,9 @@ rule estimate_response:
config['singularity']['mrtpipelines']
shell:
'dwi2response dhollander {input.dwi} {output.sfwm} {output.gm} {output.csf} -nthreads {threads}'
group: participant1


# TODO: Add check for pre-computed group response function
rule avg_response:
"""Compute average response function"""
input:
Expand Down Expand Up @@ -122,6 +124,7 @@ rule avg_response:
config['singularity']['mrtpipelines']
shell:
'average_response {input.sfwm} {output.avg_sfwm} {input.gm} {output.avg_gm} {input.csf} {output.csf}'
group: group


rule compute_fod:
Expand Down Expand Up @@ -161,10 +164,11 @@ rule compute_fod:
config['singularity']['mrtpipelines']
shell:
'if [ {params.shell} == "" ] && [ {params.lmax} == "" ]; then'
' dwi2fod -nthreads {params.threads} -shell {params.shell} -lmax {params.lmax} -mask {input.mask} msmt_csd {input.dwi} {input.avg_sfwm} {output.wm_fod} {input.avg_gm} {output.gm_fod} {input.avg_csf} {output.csf} '
'else '
' dwi2fod -nthreads {params.threads} -mask {input.mask} msmt_csd {input.dwi} {input.avg_sfwm} {output.wm_fod} {input.avg_gm} {output.gm_fod} {input.avg_csf} {output.avg_csf} '
'else '
' dwi2fod -nthreads {params.threads} -shell {params.shell} -lmax {params.lmax} -mask {input.mask} msmt_csd {input.dwi} {input.avg_sfwm} {output.wm_fod} {input.avg_gm} {output.gm_fod} {input.avg_csf} {output.csf} '
'fi'
group: participant2


rule normalise_fod:
Expand Down Expand Up @@ -204,7 +208,7 @@ rule normalise_fod:
config['singularity']['mrtpipelines']
shell:
'mtnormalise -nthreads {params.threads} -mask {input.mask} {input.wm_fod} {output.wm_fod} {input.gm_fod} {output.gm_fod} {input.csf_fod} {output.csf_fod}'

group: participant2

# DTI (Tensor) Processing
rule dwi_normalise:
Expand All @@ -226,6 +230,7 @@ rule dwi_normalise:
config['singularity']['mrtpipelines']
shell:
'dwinormalise -nthreads {params.threads} {input.dwi} {input.mask} {output.dwi}'
group: participant1


rule compute_tensor:
Expand Down Expand Up @@ -279,6 +284,7 @@ rule compute_tensor:
shell:
'dwi2tensor -nthreads {params.threads} -mask {input.mask} {input.dwi} {output.dti}'
'tensor2metric -nthreads {params.threads} -mask {input.mask} {output.dti} -fa {output.fa} -ad {output.ad} -rd {output.rd} -adc {output.md}'
group: participant1


# Tractography processing
Expand Down Expand Up @@ -306,6 +312,7 @@ rule gen_tractography:
config['singularity']['mrtpipelines']
shell:
'tckgen -nthreads {params.threads} -algorithm iFOD2 -step {params.step} -select {params.sl_count} -exclude {input.cortical_ribbon} -exclude {input.convex_hull} -include {input.subcortical_seg} -mask {input.mask} -seed_image {input.mask} {input.fod} {output.tck}'
group: participant2

rule weight_tractography:
input:
Expand Down Expand Up @@ -335,11 +342,12 @@ rule weight_tractography:
config['singularity']['mrtpipelines']
shell:
'tcksift2 -nthreads {params.threads} -out_mu {output.mu} {input.tck} {input.fod} {output.weights}'
group: participant2

# ADD OPTION TO OUTPUT TDI MAP
# TODO: ADD OPTION TO OUTPUT TDI MAP

# Connectivity map
# ADD OPTION TO MULTIPLY BY MU COEFFICIENT
# TODO: ADD OPTION TO MULTIPLY BY MU COEFFICIENT
rule connectome_map:
input:
weights=rules.weight_tractography.output.weights,
Expand Down Expand Up @@ -369,9 +377,8 @@ rule connectome_map:
config['singularity']['mrtpipelines']
shell:
'tck2connectome -nthreads {params.threads} -zero_diagonal -stat_edge sum -assignment_radial_search {params.radius} -tck_weights_in {input.weights} -out_assignments {output.sl_assignment} -symmetric {input.tck} {input.subcortical_seg} {output.node_weights} '
group: participant2

# Remove streamlines passing through other GM ROI
if config['exclude_gm']:
rule extract_tck:
input:
node_weights=rules.connectome_map.output.node_weights,
Expand Down Expand Up @@ -407,8 +414,9 @@ if config['exclude_gm']:
' nodes=$nodes,$i '
'done '
'connectome2tck -nthreads {params.threads} -nodes $nodes -exclusive -filters_per_edge -tck_weights_in {input.node_weights} -prefix_tck_weights_out {output.edge_weight} {input.tck} {input.sl_assignment} {output.edge_tck} '
group: participant2


# NOTE: Pass labelmerge split segs here?
rule create_roi_mask:
# EXPAND OVER NODE1 IN RULE ALL
input:
Expand Down Expand Up @@ -500,7 +508,7 @@ if config['exclude_gm']:
shell:
'mrcalc -nthreads {params.threads} {input.subcortical_seg} 0 -neq {input.roi1} -sub {input.roi2} -sub {input.lZI} -sub {input.rZI} -sub {output.filter_mask} '
'tckedit -nthreads {params.therads} -exclude {output.filter_mask} -tck_weights_in {input.weights} -tck_weights_out {output.filtered_weights} {input.tck} {output.filtered_tck} '

group: participant2

rule combine_filtered:
input:
Expand Down Expand Up @@ -528,6 +536,7 @@ if config['exclude_gm']:
shell:
'tckedit {input.tck} {output.combined_tck} '
'cat {input.weights} >> {output.combined_weights} '
group: participant2

rule filtered_connectome_map:
input:
Expand Down Expand Up @@ -558,3 +567,4 @@ if config['exclude_gm']:
config['singularity']['mrtpipelines']
shell:
'tck2connectome -nthreads {params.threads} -zero_diagonal -stat_edge sum -assignment_radial_search {params.radius} -tck_weights_in {input.weights} -out_assignments {output.sl_assignment} -symmetric {input.tck} {input.subcortical_seg} {output.node_weights} -force'
group: participant2