# Snakefile
# each input is 8 lines
SCRATCH = 'test'


rule all:
    input:
        'out.txt'
    run:
        if os.listdir('test'):
            raise ValueError('not all temp files have been deleted')


rule gather: 
    input: 
        dynamic('{}/split_1.{{id}}'.format(SCRATCH)),
        dynamic('{}/split_2.{{id}}'.format(SCRATCH))
    output: 'out.txt'
    shell:
        'touch {output}'

rule scatter:
    input: 'test1.txt', 'test2.txt'
    output: 
        temp(dynamic('{}/split_1.{{id}}'.format(SCRATCH))), 
        temp(dynamic('{}/split_2.{{id}}'.format(SCRATCH)))
    shell: 
        ('cat {{input[0]}} | head -8 | split -a 4 -l 4 - {}/split_1.; '
         'cat {{input[1]}} | head -8 | split -a 4 -l 4 - {}/split_2.'
         .format(SCRATCH, SCRATCH))
