From 911e0b036f609331169ccc5e9cf541024d8c03ef Mon Sep 17 00:00:00 2001 From: Christian Mertes Date: Thu, 31 Oct 2019 11:31:35 +0100 Subject: [PATCH 1/4] correct dependency to snakemake --- setup.py | 14 ++++++-------- tox.ini | 11 ++++++----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/setup.py b/setup.py index 5ddcebf..ac7a391 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,11 @@ """The setup script.""" from setuptools import setup, find_packages +import sys + +if sys.version_info < (3, 5): + print("At least Python 3.5 is required.\n", file=sys.stderr) + exit(1) with open('README.rst') as readme_file: readme = readme_file.read() @@ -15,8 +20,7 @@ 'Click>=6.0', 'click-log', 'PyYAML>=4.2b1', - 'snakemake>=3.13.2', - # TODO: put package requirements here + 'snakemake>=5.5.1', ] setup_requirements = [ @@ -54,12 +58,6 @@ 'Development Status :: 2 - Pre-Alpha', 'Intended Audience :: Developers', 'Natural Language :: English', - "Programming Language :: Python :: 2", - 'Programming Language :: Python :: 2.6', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', ], test_suite='tests', diff --git a/tox.ini b/tox.ini index 4b97ecb..25b2520 100644 --- a/tox.ini +++ b/tox.ini @@ -1,13 +1,14 @@ [tox] -envlist = py26, py27, py33, py34, py35, flake8 +envlist = py35, flake8 +# py26, py27, py33, py3i4 [travis] python = 3.5: py35 - 3.4: py34 - 3.3: py33 - 2.7: py27 - 2.6: py26 +# 3.4: py34 +# 3.3: py33 +# 2.7: py27 +# 2.6: py26 [testenv:flake8] basepython=python From d37c6a3487693af4476bfcfcd7f6a2f33f39c4d2 Mon Sep 17 00:00:00 2001 From: Christian Mertes Date: Thu, 31 Oct 2019 11:46:27 +0100 Subject: [PATCH 2/4] add package install check --- wbuild/.wBuild/wBuildParser.R | 18 +++++++++++------- wbuild/.wBuild/wBuildParser2.R | 4 ++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/wbuild/.wBuild/wBuildParser.R b/wbuild/.wBuild/wBuildParser.R index 3986a9b..f8b257c 100644 --- a/wbuild/.wBuild/wBuildParser.R +++ b/wbuild/.wBuild/wBuildParser.R @@ -1,3 +1,12 @@ +for(p in c("stringr", "yaml", "magrittr", "gsubfn")) + if(!requireNamespace(p, quietly=TRUE)) + install.packages(p) +library(stringr) +library(methods) +library(yaml) +library(magrittr) +library(gsubfn) + parseWBHeader = function(filename, ...) { addWildCards = list(...) @@ -6,7 +15,6 @@ parseWBHeader = function(filename, ...) filename = snakemake@input[['RScript']] } - library(stringr) wbPD = 'Output/ProcessedData' wildcards = list( `wbPD` = 'Output/ProcessedData', @@ -17,11 +25,7 @@ parseWBHeader = function(filename, ...) wildcards = c(wildcards,addWildCards) if(!exists('snakemake') || snakemake@rule == 'WB') { - library(methods) - library(yaml) - library(magrittr) - library(gsubfn) - + wb = readLines(filename)%>%str_subset("^#'")%>%str_replace("^#'",'')%>%paste0(collapse='\n')%>% str_replace("\\n---(.|\\n)*",'')%>%yaml.load%>%`[[`('wb') @@ -120,4 +124,4 @@ wbRead = function(name) return(wbReadRDS(name)) } stop('Could not determine format of ', snakemake@input[[name]]) -} \ No newline at end of file +} diff --git a/wbuild/.wBuild/wBuildParser2.R b/wbuild/.wBuild/wBuildParser2.R index a0f2034..dbb3c06 100644 --- a/wbuild/.wBuild/wBuildParser2.R +++ b/wbuild/.wBuild/wBuildParser2.R @@ -1,5 +1,9 @@ +for(p in c("stringr", "gsubfn")) + if(!requireNamespace(p, quietly=TRUE)) + install.packages(p) library(stringr) library(gsubfn) + parseWBHeader2 = function(file, wildcards = list(), debug = T) { # Are we interactive or in real snakemake run? From cb76e39cdf60d1fb999c89dc5db1c082241210e6 Mon Sep 17 00:00:00 2001 From: Christian Mertes Date: Thu, 31 Oct 2019 11:57:31 +0100 Subject: [PATCH 3/4] improve wildcard handling --- wbuild/.wBuild/wBuildParser2.R | 43 ++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/wbuild/.wBuild/wBuildParser2.R b/wbuild/.wBuild/wBuildParser2.R index dbb3c06..0813b4e 100644 --- a/wbuild/.wBuild/wBuildParser2.R +++ b/wbuild/.wBuild/wBuildParser2.R @@ -4,37 +4,50 @@ for(p in c("stringr", "gsubfn")) library(stringr) library(gsubfn) -parseWBHeader2 = function(file, wildcards = list(), debug = T) -{ +parseWBHeader2 <- function(file, wildcards=list(), debug=TRUE, options=c(), + rerun=FALSE){ + # Are we interactive or in real snakemake run? - if(exists('snakemake')&&is.null(snakemake@config[['wbDump']])) - { + if(exists('snakemake') && is.null(snakemake@config[['wbDump']]) && + !isTRUE(rerun)){ return (snakemake) } + #' Create dependency file - system2('python',c('.wBuild/wbParse.py',file)) + system2('python', c('.wBuild/wbParse.py',file)) + #' Replace wildcards if necessary - if(length(wildcards)>0) - { - names(wildcards) = paste0('{',names(wildcards),'}') - dependencyfile = readLines('.wBuild.depend') - dependencyfile_wild <- gsubfn('\\{[^\\}]+\\}', wildcards,dependencyfile) + if(length(wildcards) > 0){ + wildcards2rep <- rep(wildcards, each=2) + names(wildcards2rep) <- paste0( + c('{', '{{'), names(wildcards2rep), c('}', '}}')) + dependencyfile <- readLines('.wBuild.depend') + dependencyfile_wild <- gsubfn( + '\\{+[^\\}]+\\}+', wildcards2rep, dependencyfile) writeLines(dependencyfile_wild, con=".wBuild.depend") } + #' Extract rule name (1st in file) dependencyfile = readLines('.wBuild.depend') rule_name = str_extract(dependencyfile,'(?<=rule )[A-z0-9_]*') rule_name = rule_name[!is.na(rule_name)][1] - - if(debug==T) - { + + if(isTRUE(debug)){ writeLines(dependencyfile) } + #' Run snakemake to dump snakemake object, dumps some error yet - system2('snakemake',c(rule_name,'--config','wbDump=T','--nolock','--latency-wait','0','-q','-F','--allowed-rules',rule_name,'--mode','2')) + system2('snakemake', c(rule_name, '--config', 'wbDump=T', '--nolock', + '--latency-wait', '0', '-q', '-F', '--allowed-rules', rule_name, + '--mode', '2', options)) #' Read snakemake object in - snakemake <<- readRDS('.wBuild/snakemake.dump') + ans <- readRDS('.wBuild/snakemake.dump') + slot(ans, "wildcards", check=FALSE) <- wildcards + + snakemake <<- ans } + + # #parseWBHeader2('Scripts/Analysis1/010_BasicInput/020_BasicInput.R',debug=F) #parseWBHeader2(file ='Scripts/Analysis1/050_PythonCode/030_AnalysisTemplate.R',list(id='anton')) From d6219e33f10ec401ef6a955b8e443432cdeee42f Mon Sep 17 00:00:00 2001 From: Christian Mertes Date: Thu, 31 Oct 2019 12:27:30 +0100 Subject: [PATCH 4/4] check wbuild path if provided --- wbuild/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wbuild/utils.py b/wbuild/utils.py index 541c2bd..63d357a 100644 --- a/wbuild/utils.py +++ b/wbuild/utils.py @@ -275,6 +275,8 @@ def __init__(self): self.path = p break else: + if type(self.path) is list: + self.path=self.path[0] self.path=os.path.abspath(self.path) # this is taken from the snakemake main file