Last active
October 2, 2020 23:52
-
-
Save akhanf/9f1e8f91d2b53be880fa148843bd2ee1 to your computer and use it in GitHub Desktop.
Example of recipe for iteratively building a template using recursion (view graph with: snakemake -np --dag | dot | display)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input_images = ['A','B','C'] | |
shell('touch {input_images}') | |
max_iters = 4 | |
#need this to make sure iterations don't go below 0! | |
wildcard_constraints: | |
iteration="[0-9]+" | |
rule all: | |
input: 'iter_{iteration}/template.nii.gz'.format(iteration=max_iters) | |
rule init_template: | |
input: input_images | |
output: 'iter_0/template.nii.gz' | |
shell: | |
'init_template {input} {output}' | |
rule reg_to_template: | |
input: | |
template = 'iter_{iteration}/template.nii.gz', | |
image = 'inputs/{image}.nii.gz' | |
output: | |
warp = 'iter_{iteration}/{image}_warp_{iteration}.nii.gz' | |
group: 'reg' | |
shell: | |
'reg_to_template {input} {output}' | |
rule update_template: | |
input: | |
images = lambda wildcards: expand('iter_{iteration}/{image}_warp_{iteration}.nii.gz',image=input_images,iteration=int(wildcards.iteration)-1), | |
template = lambda wildcards: 'iter_{iteration}/template.nii.gz'.format(iteration=int(wildcards.iteration)-1) | |
output: | |
template = 'iter_{iteration}/template.nii.gz' | |
shell: | |
'update_template {input} {output}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
However, it works as expected if only a subset of the dag is used, when there are no repeated rules, e.g.:
snakemake -np --group-components reg=3 --cluster "sbatch" iter_1/template.nii.gz