1
votes

I am new to Snakemake, using snakemake-minimal 5.4.5. I have a rule that looks something like this:

rule make_grm:
   input:
      inc_snps: "path/snps_for_test_chr{chromosome}.txt",
      inc_samples: "path/samples_for_test_chr{chromosome}.txt"
   params:
      plink_root="path/data_chr{chromosome}",
      output_root="path/snpgrm_chr{chromosome}"
   output:
      expand("path/snpgrm_chr{chromosome}.grm.{ext}", ext=["gz", "id"])
   conda:
      "path/environment.yaml"
   shell:
      "gcta64 --bfile {params.plink_root} --make-grm-gz --keep {input.inc_samples} --extract {input.inc_snps} --out {params.output_root}"

Essentially it takes a number of inputs and runs them through GCTA which produces two output files: an .id file and a .gz file.

If I am explicit about all file names in this rule (i.e. I use a chromosome number in place of the {chromosome} wildcard) it works perfectly. Now I am trying to make it so that I can specify which chromosome to look at from the command line but snakemake complains about my use of wildcards:

Wildcard error in line 40 of Snakefile
Wildcards in input files cannot be determined from output files: chromosome

Any ideas why if I run something like this in my shell:

snakemake --use-conda path/snpgrm_chr18.grm.gz

Snakemake cannot infer that {chromosome}=18 as it would do for my other rules?

(I do also run this on a SGE cluster but I've left these details out as I don't think they are involved in this behaviour and add a lot of clutter)

2

2 Answers

2
votes

You have to double the brackets if you want to make a wildcard inside an expand function:

expand("path/snpgrm_chr{{chromosome}}.grm.{ext}", ext=["gz", "id"])

here, {{chromosome}} is a wildcard, {ext} is just a placeholder for the argument of the expand function

2
votes

I see another issue in your code:

   output:
      expand("path/snpgrm_chr{chromosome}.grm.{ext}", ext=["gz", "id"])

The expand function requires all parameters to be filled, and the {chromosome} is not. Actually what you meant is that {chromosome} is a wildcard. You need to put it into double braces:

   output:
      expand("path/snpgrm_chr{{chromosome}}.grm.{ext}", ext=["gz", "id"])

The rest worked on my machine.