from pytools.persistent_dict import PersistentDict


storage = PersistentDict("storage")


rule merge:
    input: dynamic("in_{sample}.txt")
    output: "out.txt"
    shell:
        "touch {output}"


storage["split_counter"] = 0


rule split:
    input: "in.txt"
    output: dynamic("in_{sample}.txt")
    run:
        if storage["split_counter"] > 0:
            raise Exception("Rule split was executed multiple times.")
        storage["split_counter"] += 1
        shell("touch in_1.txt in_2.txt")


