snakecharm icon indicating copy to clipboard operation
snakecharm copied to clipboard

AttributeError: 'Checkpoint' object has no attribute 'output'

Open iromeo opened this issue 5 years ago • 1 comments

Checkpoint type differs from Rule type: checkpoints.A.output.mydir leads to AttributeError: 'Checkpoint' object has no attribute 'output', should be checkpoints.A.get(**wildcards).output.mydir

Code example:

import os
from snakemake import shell

shell.prefix('set -vexu pipefail; ')

rule finish:
        input:
                "D/all.txt"

checkpoint A:
        output:
                mydir = directory("A")
        shell: """
                mkdir -p A
                N=$(( $RANDOM % 7 + 1))
                echo "N=$N"
                # Create a number of files. (
                for i in $(seq 1 $N); do
                        echo $i > "A/$i.txt"
                done
        """

rule B:
        output:
                txt = "B/{i}.txt",
        input:
                txt = "A/{i}.txt",
        shell: """
                mkdir -p B
                cp -f {input.txt} {output.txt}
        """

rule C:
        output:
                txt = "C/{i}.txt",
        input:
                # txt = "B/{i}.txt",
                txt = rules.B.output.txt,
        shell: """
                mkdir -p C
                cp -f {input.txt} {output.txt}
        """

def gatherForD_fromC_basedOnA(wildcards):
        checkpoint_output = checkpoints.A.get(**wildcards).output.mydir # ok
        # checkpoint_output = checkpoints.A.output.mydir # wrong
        # That will raise if not ready.

        ivals = glob_wildcards(os.path.join(checkpoint_output, "{i}.txt")).i
        print("ivals={}".format(ivals))
        return expand("C/{i}.txt", i=ivals)

rule D:
        output:
                combined = "D/all.txt",
        input:
                gathered = gatherForD_fromC_basedOnA,
        shell: """
                mkdir -p D
                cat {input.gathered} > {output.combined}
        """

(taken from https://stackoverflow.com/a/56451259/418358)

iromeo avatar Aug 21 '19 18:08 iromeo

And vice versa rules.B.get(**wildcards).output.txt isn't valid: 'RuleProxy' object has no attribute 'get'

iromeo avatar Aug 21 '19 18:08 iromeo