# HG changeset patch # User fubar # Date 1420167277 18000 # Node ID 4b62ea84c3183404cd9779a466d98e1584280960 # Parent 4e4f094c338c452b63e6efc56525c5801449b426 Uploaded diff -r 4e4f094c338c -r 4b62ea84c318 rgToolFactory.py --- a/rgToolFactory.py Sun Dec 21 05:49:14 2014 -0500 +++ b/rgToolFactory.py Thu Jan 01 21:54:37 2015 -0500 @@ -113,7 +113,7 @@ """class is a wrapper for an arbitrary script """ - def __init__(self,opts=None,treatbashSpecial=True): + def __init__(self,opts=None): """ cleanup inputs, setup some outputs @@ -122,7 +122,6 @@ self.useIM = cmd_exists('convert') self.useGS = cmd_exists('gs') self.temp_warned = False # we want only one warning if $TMP not set - self.treatbashSpecial = treatbashSpecial if opts.output_dir: # simplify for the tool tarball os.chdir(opts.output_dir) self.thumbformat = 'png' @@ -149,18 +148,8 @@ artifact = open(artpath,'w') # use self.sfile as script source for Popen artifact.write(self.script) artifact.close() - self.cl = [] self.html = [] - a = self.cl.append - a(opts.interpreter) - # cannot use pipe input on test - change so always eg Rscript myscript.R - #if self.treatbashSpecial and opts.interpreter in ['bash','sh']: - # a(self.sfile) - #else: - # a('-') # stdin - #a(opts.input_tab) - #a(opts.output_tab) - a(self.sfile) + self.cl = (opts.interpreter,self.sfile) self.outFormats = 'tabular' # TODO make this an option at tool generation time self.inputFormats = 'tabular' # TODO make this an option at tool generation time self.test1Input = '%s_test1_input.xls' % self.toolname @@ -545,79 +534,35 @@ scripts must be small enough not to fill the pipe! """ my_env = os.environ.copy() - if self.treatbashSpecial and self.opts.interpreter in ['bash','sh']: - retval = self.runBash() - else: - if self.opts.output_dir: - ste = open(self.elog,'w') - sto = open(self.tlog,'w') - sto.write('## Toolfactory running %s as %s script\n' % (self.toolname,self.opts.interpreter)) - sto.flush() - p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=ste,cwd=self.opts.output_dir,env=my_env) - else: - p = subprocess.Popen(self.cl,shell=False,cwd=self.opts.output_dir,env=my_env) - # p.stdin.write(self.script) - #print >> p.stdin, self.script - #p.stdin.close() + if self.opts.output_dir: + ste = open(self.elog,'w') + sto = open(self.tlog,'w') + sto.write('## Toolfactory running %s as %s script\n' % (self.toolname,self.opts.interpreter)) + sto.flush() + p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=ste,cwd=self.opts.output_dir,env=my_env) retval = p.wait() - if self.opts.output_dir: - sto.close() - ste.close() - # get stderr, allowing for case where it's very large - tmp_stderr = open( self.elog, 'rb' ) - stderr = '' - try: - while True: - stderr += tmp_stderr.read( buffsize ) - if not stderr or len( stderr ) % buffsize != 0: - break - except OverflowError: - pass - tmp_stderr.close() - if self.opts.make_HTML: - self.makeHtml() + sto.close() + ste.close() + # get stderr, allowing for case where it's very large + tmp_stderr = open( self.elog, 'rb' ) + stderr = '' + try: + while True: + stderr += tmp_stderr.read( buffsize ) + if not stderr or len( stderr ) % buffsize != 0: + break + except OverflowError: + pass + tmp_stderr.close() + else: + p = subprocess.Popen(self.cl,shell=False,env=my_env) + retval = p.wait() + if self.opts.make_HTML: + self.makeHtml() return retval - def old_run(self): - """ - can't use pipe as stdin on test. go figure - scripts must be small enough not to fill the pipe! - """ - my_env = os.environ.copy() - if self.treatbashSpecial and self.opts.interpreter in ['bash','sh']: - retval = self.runBash() - else: - if self.opts.output_dir: - ste = open(self.elog,'w') - sto = open(self.tlog,'w') - sto.write('## Toolfactory running %s as %s script\n' % (self.toolname,self.opts.interpreter)) - sto.flush() - p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=ste,stdin=subprocess.PIPE,cwd=self.opts.output_dir,env=my_env) - else: - p = subprocess.Popen(self.cl,shell=False,stdin=subprocess.PIPE,env=my_env) - # p.stdin.write(self.script) - print >> p.stdin, self.script - p.stdin.close() - retval = p.wait() - if self.opts.output_dir: - sto.close() - ste.close() - # get stderr, allowing for case where it's very large - tmp_stderr = open( self.elog, 'rb' ) - stderr = '' - try: - while True: - stderr += tmp_stderr.read( buffsize ) - if not stderr or len( stderr ) % buffsize != 0: - break - except OverflowError: - pass - tmp_stderr.close() - if self.opts.make_HTML: - self.makeHtml() - return retval - def runBash(self): + def remove_me_runBash(self): """ cannot use - for bash so use self.sfile """ @@ -645,16 +590,21 @@ except OverflowError: pass tmp_stderr.close() - if self.opts.make_HTML: - self.makeHtml() return retval def main(): u = """ - This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as: - rgBaseScriptWrapper.py --script_path "$scriptPath" --tool_name "foo" --interpreter "Rscript" + This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as (eg): + rgToolFactory.py --script_path "$scriptPath" --tool_name "foo" --interpreter "Rscript" + The tool writes a script to a scriptPath using a configfile. + Some things in the script are templates. + The idea here is that depending on how this code is called, it uses the specified interpreter + to run a (hopefully correct) script/template. Optionally generates a clone of itself + which will run that same script/template as a toolshed repository tarball for uploading to a toolshed. + There's now an updated version which allows arbitrary parameters. + And so it goes. """ op = optparse.OptionParser() a = op.add_option diff -r 4e4f094c338c -r 4b62ea84c318 rglasso_cox.xml --- a/rglasso_cox.xml Sun Dec 21 05:49:14 2014 -0500 +++ b/rglasso_cox.xml Thu Jan 01 21:54:37 2015 -0500 @@ -132,18 +132,22 @@ + + - + - - + + + - - + + + diff -r 4e4f094c338c -r 4b62ea84c318 test-data/coxlassotest.html --- a/test-data/coxlassotest.html Sun Dec 21 05:49:14 2014 -0500 +++ b/test-data/coxlassotest.html Thu Jan 01 21:54:37 2015 -0500 @@ -8,7 +8,7 @@
-
Galaxy Tool "rglasso" run at 19/10/2014 13:11:14

+
Galaxy Tool "rglasso" run at 28/12/2014 13:07:57

cox images and outputs
(Click on a thumbnail image to download the corresponding original PDF image)
@@ -26,17 +26,23 @@
 
-[1] "All partial likelihood coefficients from Cox model at minimum lambda of 0.00138091491730048:"
+[1] @@@ Cox model will be predicted at times = 3.724234,1325.40516225,2373.090418,3650.1730825,4989.405682
+
+[1] Times each predictor was selected in CV models (excluding zero count predictors)
 
-3 x 1 sparse Matrix of class "dgCMatrix"
+         hits_lambda_1se hits_lambda_min
 
-                    1
+rhubarb               10              10
 
-rhubarb  1.124517e-03
+vegemite               3              10
+
+apple                  0               1
 
-vegemite 1.444990e-01
+[1] @@@ Results preview:
 
-apple    3.344565e-06
+        regulator partial_likelihood forced_in glmnet_model best_lambda lambdaChoice alpha
+
+rhubarb   rhubarb          0.0012215      TRUE          cox     0.04197   lambda.1se  0.95
 
 
 
@@ -53,27 +59,33 @@ Loaded lars 1.2 +Loading required package: splines + Warning messages: -1: In if (class(larsres) == "try-error") { : +1: In if (is.na(predict_at)) { : the condition has length > 1 and only the first element will be used -2: In plot.window(...) : "label" is not a graphical parameter +2: In if (class(p) == "try-error") { : -3: In plot.xy(xy, type, ...) : "label" is not a graphical parameter + the condition has length > 1 and only the first element will be used -4: In axis(side = side, at = at, labels = labels, ...) : +3: In plot.window(...) : "label" is not a graphical parameter - "label" is not a graphical parameter +4: In plot.xy(xy, type, ...) : "label" is not a graphical parameter 5: In axis(side = side, at = at, labels = labels, ...) : "label" is not a graphical parameter -6: In box(...) : "label" is not a graphical parameter +6: In axis(side = side, at = at, labels = labels, ...) : + + "label" is not a graphical parameter -7: In title(...) : "label" is not a graphical parameter +7: In box(...) : "label" is not a graphical parameter + +8: In title(...) : "label" is not a graphical parameter @@ -82,45 +94,61 @@
 
-## Toolfactory generated command line = Rscript - None None
-
-[1] Cox model: Got yvar= time,status cols 1 n preds= 3 forced in= 3
+## Toolfactory running rglasso as Rscript script
 
-[2] Cox model: Got yvar= time,status cols 2 n preds= 3 forced in= 3
+[1] @@@ Using alpha = 0.95 for all models
 
-[1] Results preview:
-
-         regulator partial_likelihood forced_in glmnet_model best_lambda
+[1] @@@@ Input has 500 samples and 3 predictors
 
-rhubarb    rhubarb        0.001180324      TRUE          cox  0.01508333
+[1] @@@ Cox model will predict yvar= status using cols= rhubarb,vegemite,apple n preds= 3 forced in= rhubarb
 
-vegemite  vegemite        0.093827440     FALSE          cox  0.01508333
+[1] @@@ SessionInfo for this R session:
 
-[1] SessionInfo for this R session:
+R version 3.0.2 (2013-09-25)
 
-R version 3.1.0 (2014-04-10)
-
-Platform: x86_64-unknown-linux-gnu (64-bit)
+Platform: x86_64-pc-linux-gnu (64-bit)
 
 locale:
 
- [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C               LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8    
-
- [5] LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8    LC_PAPER=en_AU.UTF-8       LC_NAME=C                 
-
- [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C       
+ [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C               LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8     LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8    LC_PAPER=en_AU.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C       
 
 attached base packages:
 
-[1] methods   stats     graphics  grDevices utils     datasets  base     
+[1] splines   methods   stats     graphics  grDevices utils     datasets  base     
 
 other attached packages:
 
-[1] lars_1.2     glmnet_1.9-8 Matrix_1.1-4
+[1] pec_2.4.4       survival_2.37-7 lars_1.2        glmnet_1.9-8    Matrix_1.1-4   
 
 loaded via a namespace (and not attached):
 
-[1] grid_3.1.0      lattice_0.20-29
+[1] codetools_0.2-9 foreach_1.4.2   grid_3.0.2      iterators_1.0.7 lattice_0.20-29 lava_1.3        prodlim_1.5.1  
+
+Warning messages:
+
+1: In if (is.na(predict_at)) { ... :
+
+  the condition has length > 1 and only the first element will be used
+
+2: In if (class(p) == "try-error") { ... :
+
+  the condition has length > 1 and only the first element will be used
+
+3: In plot.window(...) : "label" is not a graphical parameter
+
+4: In plot.xy(xy, type, ...) : "label" is not a graphical parameter
+
+5: In axis(side = side, at = at, labels = labels, ...) :
+
+  "label" is not a graphical parameter
+
+6: In axis(side = side, at = at, labels = labels, ...) :
+
+  "label" is not a graphical parameter
+
+7: In box(...) : "label" is not a graphical parameter
+
+8: In title(...) : "label" is not a graphical parameter
 
 
 
@@ -129,12 +157,13 @@
- - - - - - + + + + + + +
Output File Name (click to view)Size
cox_Coxglmnettest_glmnet_cvdeviance.pdf6.4 KB
cox_Coxglmnettest_glmnetdev.pdf5.2 KB
cox_rglasso.log228 B
rglasso.Rscript9.8 KB
rglasso_error.log671 B
rglasso_runner.log1.1 KB
cox_Coxglmnettest_glmnet_cvdeviance.pdf6.3 KB
cox_Coxglmnettest_glmnetdev.pdf5.3 KB
cox_cross_validation_model_counts.xls47 B
cox_rglasso.log563 B
rglasso.Rscript21.5 KB
rglasso_error.log803 B
rglasso_runner.log1.7 KB

diff -r 4e4f094c338c -r 4b62ea84c318 test-data/coxlassotest_modelres.xls --- a/test-data/coxlassotest_modelres.xls Sun Dec 21 05:49:14 2014 -0500 +++ b/test-data/coxlassotest_modelres.xls Thu Jan 01 21:54:37 2015 -0500 @@ -1,3 +1,2 @@ -regulator partial_likelihood forced_in glmnet_model best_lambda -rhubarb 0.0011803238918088 TRUE cox 0.0150833254995026 -vegemite 0.0938274399971897 FALSE cox 0.0150833254995026 +regulator partial_likelihood forced_in glmnet_model best_lambda lambdaChoice alpha +rhubarb 0.0012215 TRUE cox 0.04197 lambda.1se 0.95 diff -r 4e4f094c338c -r 4b62ea84c318 tool_dependencies.xml --- a/tool_dependencies.xml Sun Dec 21 05:49:14 2014 -0500 +++ b/tool_dependencies.xml Thu Jan 01 21:54:37 2015 -0500 @@ -42,8 +42,7 @@ - Yeee Haaa! - Lasso for Galaxy + Yee-Haw! Lasso for Galaxy!