marmoset template building WIP

public public 1yr ago 0 bookmarks

Workflow to build cohort templates based on multiple participants_tsv files

This workflow uses greedy instead of ANTS, for the sake of efficiency, in fact, the registrations as compared to ants_build_template seem to be more accurate (though that of course is likely just due to parameter selection, not an inherent limitation of ANTS).. There is ~20-30x speedup for a single pairwise registration compared to ANTS, making template-generation for hundreds of subjects a job that can be completed in around a day with modest resources (32cores). The 4-core 16gb memory greedy registration jobs take <30mins.

Running with a cluster profile (e.g. cc-slurm)

This option will be the most # of jobs ( num_iters * num_subjects * num_cohorts ), but will maximize parallelization on a cluster

snakemake --profile cc-slurm

Running with cluster profile, but grouping registration jobs together in chunks of 8

This will reduce the number of jobs by factor of 8 by grouping the 8 4core jobs to fill the 32-core nodes

HOWEVER -- if you are using the --group-components option to group the registrations in chunks of 8, you MUST run each iteration separately, using the --config run_iter=# option, where # is the iteration to run -- this seems to be a bug/limitation of the group-components option when a job has recursively-defined rules. (open issue as of Oct 3 2020: https://github.com/snakemake/snakemake/issues/656)

snakemake --config run_iter=2 --profile cc-slurm --group-components reg=8 composite=100

Note: composite=100 is for the composing warps to another ref space (e.g. mni) to combine 100 subjects in a single job (each is relatively quick and disk-bound)..

Running as a single job

This is the most frugal for resources (32-cores max), but is simple in that only a single job is spawned.. This is the method to use if you are running this on a single machine. Four iterations of building a single 1mm template with 100 subjects takes < 24hrs on a 32core system.

regularSubmit -j Fat snakemake --use-singularity -j32

Running each cohort in parallel with single jobs and the --nolock flag

This runs each cohort separately with single-node jobs.. This is a happy medium for running on a cluster while not needing hundreds (or thousands) of short jobs..

WARNING: make sure your cohorts are mutually-exclusive when using this method, as it is running snakemake in parallel on the same directory with the --nolock option -- if cohorts are not mutually-exclusive, you can still use this method, but only after all the pre-processing (e.g. T2/T1 registration, is completed)

for cohort in young middle1 middle2 old1 old2; do regularSubmit -j Fat snakemake --use-singularity -j32 --nolock --config run_cohort=$cohort; done

Code Snippets

12
13
shell:
    'AverageImages {params.dim} {output} {params.use_n4} {input} &> {log}'
20
shell: 'cp -v {input} {output} &> {log}'
30
shell: 'cp -v {input} {output}'
75
76
shell:
    'AverageImages {params.dim} {output} {params.use_n4} {input} &> {log}'
89
90
shell:
    'AverageImages {params.dim} {output} {params.use_n4} {input} &> {log}'
101
102
shell:
    'MultiplyImages {params.dim} {input} {params.gradient_step} {output} &> {log}' 
114
115
shell:
    'AverageAffineTransformNoRigid {params.dim} {output} {input} &> {log}'
129
130
shell:
    'antsApplyTransforms {params.dim} -e vector -i {input.invwarp} -o {output} -t [{input.affine},1] -r {input.ref} --verbose 1 &> {log}'
144
145
146
147
148
149
150
151
152
    shell:
        'antsApplyTransforms {params.dim} --float 1 --verbose 1 -i {input.template} -o {output.template} -t [{input.affine},1] '
        ' -t {input.invwarp} -t {input.invwarp} -t {input.invwarp} -t {input.invwarp} -r {input.template} &> {log}' #apply warp 4 times


#resample the template to a new resolution, based on the schedule in config
rule resample_template:
    input:
        template =  'results/cohort-{cohort}/iter_{iteration}/templateupd_{channel}.nii.gz'
158
159
shell:
    'c3d {input} -resample {params.resample} {output}'
67
68
69
70
shell: 'greedy -d 3 -rf {input.ref_std} '
      ' -r {input.cohort2std_warp} {input.cohort2std_affine_xfm_ras} '
      '  {input.subj2cohort_warp} {input.subj2cohort_affine_xfm_ras} '
      ' -rc {output.subj2std_warp}'
103
104
105
106
107
108
shell: 'greedy -d 3 -rf {input.ref_subj} -r '
      ' {input.subj2cohort_affine_xfm_ras},-1 '
      ' {input.subj2cohort_invwarp}'
      ' {input.cohort2std_affine_xfm_ras},-1 '
      ' {input.cohort2std_invwarp} '
      ' -rc {output.subj2std_invwarp}'
118
119
shell:
    'greedy -d 3 -rf {input.ref} -r {input.subj2std_invwarp} -rm {input.seg} {output.seg}'
128
129
shell:
    'greedy -d 3 -rf {input.ref} -r {input.subj2std_invwarp} -rm {input.seg} {output.seg}'
138
139
shell:
    'greedy -d 3 -rf {input.ref} -r {input.subj2std_invwarp} -rm {input.seg} {output.seg} -ri NN'
10
11
12
shell:
    'ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS={threads} '
    'N4BiasFieldCorrection -d 3 -i {input.img} -o {output}'
27
28
shell:
    'c3d {input} -resample {params.resample} {output}'
43
44
shell:
    'c3d {input} -pad-to {params.pad} 0 {output}'
ShowHide 16 more snippets with no or duplicated tags.

Login to post a comment if you would like to share your experience with this workflow.

Do you know this workflow well? If so, you can request seller status , and start supporting this workflow.

Free

Created: 1yr ago
Updated: 1yr ago
Maitainers: public
URL: https://github.com/akhanf/greedy_template_marm
Name: greedy_template_marm
Version: 1
Badge:
workflow icon

Insert copied code into your website to add a link to this workflow.

Downloaded: 0
Copyright: Public Domain
License: MIT License
  • Future updates

Related Workflows

cellranger-snakemake-gke
snakemake workflow to run cellranger on a given bucket using gke.
A Snakemake workflow for running cellranger on a given bucket using Google Kubernetes Engine. The usage of this workflow ...