Mercurial > repos > fubar > rglasso_1_9_8
changeset 9:4b62ea84c318 draft
Uploaded
author | fubar |
---|---|
date | Thu, 01 Jan 2015 21:54:37 -0500 |
parents | 4e4f094c338c |
children | 8738aeafbd4e |
files | rgToolFactory.py rglasso_cox.xml test-data/coxlassotest.html test-data/coxlassotest_modelres.xls tool_dependencies.xml |
diffstat | 5 files changed, 118 insertions(+), 137 deletions(-) [+] |
line wrap: on
line diff
--- 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: - <command interpreter="python">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): + <command interpreter="python">rgToolFactory.py --script_path "$scriptPath" --tool_name "foo" --interpreter "Rscript" </command> + 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
--- 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 @@ <param name='do_standard' value="True" /> <param name='cox_time' value='1' /> <param name='cox_status' value='2' /> + <param name='cox_id' value='2' /> + <param name='predict_at' value='' /> <param name='fam' value='cox' /> - <param name='model.yvar_cols' value='' /> + <param name='yvar_cols' value='' /> <param name='xvar_cols' value='3,4,5' /> <param name='force_xvar_cols' value='3' /> - <param name='output_full' value='0' /> - <output name='model_file'> + <param name='output_full' value='F' /> + <param name='output_pred' value='F' /> + <output name='model_file' file='coxlassotest_modelres.xls'> <assert_contents> <has_text text="rhubarb" /> <has_text text="TRUE" /> <!-- 	 is XML escape code for tab --> - <has_line line="regulator	partial_likelihood	forced_in	glmnet_model	best_lambda" /> - <has_n_columns n="5" /> + <!-- has_line line="regulator	partial_likelihood	forced_in	glmnet_model	best_lambda" / --> + <has_line line="regulator	partial_likelihood	forced_in	glmnet_model	best_lambda	lambdaChoice	alpha" /> + <has_n_columns n="7" /> </assert_contents> </output> <output name='html_file' file='coxlassotest.html' compare='diff' lines_diff='10' />
--- 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 @@ <body> <div class="toolFormBody"> -<div class="infomessage">Galaxy Tool "rglasso" run at 19/10/2014 13:11:14</div><br/> +<div class="infomessage">Galaxy Tool "rglasso" run at 28/12/2014 13:07:57</div><br/> <div class="toolFormTitle">cox images and outputs</div> (Click on a thumbnail image to download the corresponding original PDF image)<br/> <div><table class="simple" cellpadding="2" cellspacing="2"> @@ -26,17 +26,23 @@ <pre> -[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 </pre> @@ -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 </pre> @@ -82,45 +94,61 @@ <pre> -## 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 </pre> @@ -129,12 +157,13 @@ <div><table class="colored" cellpadding="3" cellspacing="3"><tr><th>Output File Name (click to view)</th><th>Size</th></tr> -<tr><td><a href="cox_Coxglmnettest_glmnet_cvdeviance.pdf">cox_Coxglmnettest_glmnet_cvdeviance.pdf</a></td><td>6.4 KB</td></tr> -<tr class="odd_row"><td><a href="cox_Coxglmnettest_glmnetdev.pdf">cox_Coxglmnettest_glmnetdev.pdf</a></td><td>5.2 KB</td></tr> -<tr><td><a href="cox_rglasso.log">cox_rglasso.log</a></td><td>228 B</td></tr> -<tr class="odd_row"><td><a href="rglasso.Rscript">rglasso.Rscript</a></td><td>9.8 KB</td></tr> -<tr><td><a href="rglasso_error.log">rglasso_error.log</a></td><td>671 B</td></tr> -<tr class="odd_row"><td><a href="rglasso_runner.log">rglasso_runner.log</a></td><td>1.1 KB</td></tr> +<tr><td><a href="cox_Coxglmnettest_glmnet_cvdeviance.pdf">cox_Coxglmnettest_glmnet_cvdeviance.pdf</a></td><td>6.3 KB</td></tr> +<tr class="odd_row"><td><a href="cox_Coxglmnettest_glmnetdev.pdf">cox_Coxglmnettest_glmnetdev.pdf</a></td><td>5.3 KB</td></tr> +<tr><td><a href="cox_cross_validation_model_counts.xls">cox_cross_validation_model_counts.xls</a></td><td>47 B</td></tr> +<tr class="odd_row"><td><a href="cox_rglasso.log">cox_rglasso.log</a></td><td>563 B</td></tr> +<tr><td><a href="rglasso.Rscript">rglasso.Rscript</a></td><td>21.5 KB</td></tr> +<tr class="odd_row"><td><a href="rglasso_error.log">rglasso_error.log</a></td><td>803 B</td></tr> +<tr><td><a href="rglasso_runner.log">rglasso_runner.log</a></td><td>1.7 KB</td></tr> </table></div><br/> </div></body></html>
--- 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