Last active
March 20, 2020 14:42
-
-
Save kaspermunch/89c2a62afab40518cf58a1da941a4a22 to your computer and use it in GitHub Desktop.
Naming of reused GWF templates using groups
This file contains 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
from gwf import Workflow, AnonymousTarget | |
from groups import Group # separate Gist | |
def mask_template(path): | |
inputs = {'path': path} | |
outputs = {'path': path + '.masked'} | |
options = {} | |
spec = """./some_command {}""".format(path) | |
return AnonymousTarget(inputs=inputs, outputs=outputs, options=options, spec=spec) | |
def step_one_template(path): | |
inputs = {'path': path} | |
outputs = {'path': path + '.first'} | |
options = {} | |
spec = """./some_command {}""".format(path) | |
return AnonymousTarget(inputs=inputs, outputs=outputs, options=options, spec=spec) | |
def step_two_template(path): | |
inputs = {'path': path} | |
outputs = {'path': path + '.second'} | |
options = {} | |
spec = """./some_command {}""".format(path) | |
return AnonymousTarget(inputs=inputs, outputs=outputs, options=options, spec=spec) | |
input_files = {'CEU': ['ceu_chr1.txt', 'ceu_chr2.txt'], | |
'CHB': ['chb_chr1.txt', 'chb_chr2.txt'], | |
} | |
gwf = Workflow() | |
with Group(gwf, prefix='with_repeats') as g: # <- NB g | |
for pop, paths in input_files.items(): | |
with Group(g, prefix=pop) as gg: # <- NB gg | |
# så kan du lave dine maps som om der kun var en population: | |
step_one_tasks = gg.map(step_one_template, paths, name='step_one') # <- NB gg not gwf | |
step_two_tasks = gg.map(step_two_template, step_one_tasks.outputs, name='step_two') | |
with Group(gwf, prefix='no_repeats') as g: | |
for pop, paths in input_files.items(): | |
with Group(g, prefix=pop) as gg: | |
# så kan du lave dine maps som om der kun var en population: | |
mask_tasks = gg.map(mask_template, paths, name='mask') | |
step_one_tasks = gg.map(step_one_template, mask_tasks.outputs, name='step_one') | |
step_two_tasks = gg.map(step_two_template, step_one_tasks.outputs, name='step_two') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment