Explorar el Código

Fix wildcard constraints in Snakefile

They have to be on the outputs, not the inputs.
Ryan C. Thompson hace 5 años
padre
commit
6663f647e6
Se han modificado 1 ficheros con 15 adiciones y 8 borrados
  1. 15 8
      Snakefile

+ 15 - 8
Snakefile

@@ -209,14 +209,21 @@ since the BibTeX setup in LyX can't handle them.'''
 rule pdf_extract_page:
     '''Extract a single page from a multi-page PDF.'''
     # Input is a PDF whose basename doesn't already have a page number
-    input: pdf = 'graphics/{basename,.*(?!PAGE[0-9]+)}.pdf'
+    input: pdf = 'graphics/{basename}.pdf'
     output: pdf = 'graphics/{basename}-PAGE{pagenum,[1-9][0-9]*}.pdf'
-    shell: 'pdfseparate -f {wildcards.pagenum:q} -l {wildcards.pagenum:q} {input:q} {output:q}'
+    run:
+        # This could be done with a regex constraint on basename,
+        # except that variable width lookbehind isn't supported.
+        # Unfortunately, that makes this a runtime error instead of an
+        # error during DAG construction.
+        if regex.search('-PAGE[0-9]+$', wildcards.basename):
+            raise ValueError("Can't extract page from extracted page PDF.")
+        shell('pdfseparate -f {wildcards.pagenum:q} -l {wildcards.pagenum:q} {input:q} {output:q}')
 
 rule pdf_crop:
     '''Crop away empty margins from a PDF.'''
-    input: pdf = 'graphics/{basename,.*(?!CROP).*}.pdf'
-    output: pdf = 'graphics/{basename}-CROP.pdf'
+    input: pdf = 'graphics/{basename}.pdf'
+    output: pdf = 'graphics/{basename,.*(?<!-CROP)}-CROP.pdf'
     shell: 'pdfcrop --resolution 300 {input:q} {output:q}'
 
 rule pdf_raster:
@@ -227,8 +234,8 @@ rule pdf_raster:
 
 rule png_crop:
     '''Crop away empty margins from a PNG.'''
-    input: pdf = 'graphics/{basename,.*(?!CROP).*}.png'
-    output: pdf = 'graphics/{basename}-CROP.png'
+    input: pdf = 'graphics/{basename}.png'
+    output: pdf = 'graphics/{basename,.*(?<!-CROP)}-CROP.png'
     shell: 'convert {input:q} -trim {output:q}'
 
 rule svg_to_pdf:
@@ -238,6 +245,6 @@ rule svg_to_pdf:
 
 rule R_to_html:
     '''Render an R script as syntax-hilighted HTML.'''
-    input: '{dirname}/{basename,[^/]+}.R'
-    output: '{dirname}/{basename}.R.html'
+    input: '{dirname}/{basename}.R'
+    output: '{dirname}/{basename,[^/]+}.R.html'
     shell: 'pygmentize -f html -O full -l R -o {output:q} {input:q}'