changeset 2:6a3c292412fa draft

Uploaded
author fubar
date Sun, 11 Jan 2015 21:32:15 -0500
parents 323982517b30
children d75fd880fce2
files rgToolFactory2.py rgToolFactory2.xml
diffstat 2 files changed, 74 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/rgToolFactory2.py	Sat Jan 10 19:39:33 2015 -0500
+++ b/rgToolFactory2.py	Sun Jan 11 21:32:15 2015 -0500
@@ -121,7 +121,7 @@
 </tool_dependency>
 """
 
-toolhtmldepskel = """<?xml version="1.0"?>
+emptytoolhtmldepskel = """<?xml version="1.0"?>
 <tool_dependency>
         <readme>
            %s
@@ -230,48 +230,56 @@
             self.test1Inputs = ''
         # we always pass path,name pairs in using python optparse append
         # but the command line has to be different
-        self.infile_paths = ','.join([x.split(',')[0] for x in self.opts.input_tab])
-        self.infile_names = ','.join([x.split(',')[1] for x in self.opts.input_tab])
+        self.infile_paths = ''
+        self.infile_names = ''
+        if self.opts.input_tab:
+            self.infile_paths = ','.join([x.split(',')[0].strip() for x in self.opts.input_tab])
+            self.infile_names = ','.join([x.split(',')[1].strip() for x in self.opts.input_tab])
         if self.opts.interpreter == 'python':
             # yes, this is how additional parameters are always passed in python - to the TF itself and to
             # scripts to avoid having unknown parameter names (yes, they can be parsed but...) on the command line
-            a('--INPATHS "%s"' % (self.infile_paths)) 
-            a('--INNAMES "%s"' % (self.infile_names)) 
+            if self.opts.input_tab:
+                a('--INPATHS "%s"' % (self.infile_paths)) 
+                a('--INNAMES "%s"' % (self.infile_names)) 
             if self.opts.output_tab:
                 a('--OUTPATH "%s"' % self.opts.output_tab) 
             for p in opts.additional_parameters:
                 p = p.replace('"','')
-                psplit=p.split(',')
-                param = psplit[0]
-                value = psplit[1]
-                a('--additional_parameters "%s,%s"' % (param,value))
+                ps = p.split(',')
+                a('%s="%s"' % (ps[0],ps[1]))
         if (self.opts.interpreter == 'Rscript'):
             # pass params on command line
-            a('INPATHS "%s"' % self.infile_paths)
-            a('INNAMES "%s"' % self.infile_names)
+            if self.opts.input_tab:
+                a('INPATHS="%s"' % self.infile_paths)
+                a('INNAMES="%s"' % self.infile_names)
             if self.opts.output_tab:
-                a('OUTPATH "%s"' % self.opts.output_tab) 
-            for param in opts.additional_parameters:
-                param, value=param.split(',')
-                a('%s="%s"' % (param,value))
+                a('OUTPATH="%s"' % self.opts.output_tab) 
+            for p in opts.additional_parameters:
+                p = p.replace('"','')
+                ps = p.split(',')
+                a('%s="%s"' % (ps[0],ps[1]))
         if (self.opts.interpreter == 'perl'):
             # pass params on command line
-            a('%s' % self.infile_paths)
-            a('%s' % self.infile_names)
+            if self.opts.input_tab:
+                a('%s' % self.infile_paths)
+                a('%s' % self.infile_names)
             if self.opts.output_tab:
                 a('%s' % self.opts.output_tab)
-            for param in opts.additional_parameters:
-                param, value=param.split(',')
+            for p in opts.additional_parameters:
+                p = p.replace('"','')
+                ps = p.split(',')
+                param = ps[0]
+                value = ps[1]
                 if (value.find(' ') <> -1):
                     a('%s="%s"' % (param,value))
                 else:
                     a('%s=%s' % (param,value))
-                
         if self.opts.interpreter == 'sh' or self.opts.interpreter == 'bash':
               # more is better - now move all params into environment AND drop on to command line.
               self.cl.insert(0,'env')
-              self.cl.insert(1,'INPATHS=%s' % (self.infile_paths))
-              self.cl.insert(2,'INNAMES=%s' % (self.infile_names))
+              if self.opts.input_tab:
+                  self.cl.insert(1,'INPATHS=%s' % (self.infile_paths))
+                  self.cl.insert(2,'INNAMES=%s' % (self.infile_names))
               if self.opts.output_tab:
                   self.cl.insert(3,'OUTPATH=%s' % (self.opts.output_tab))
                   a('OUTPATH=%s' % (self.opts.output_tab))
@@ -415,9 +423,9 @@
         xdict['additionalInputs'] = ''
         if self.opts.additional_parameters:
             if self.opts.edit_additional_parameters: # add to new tool form with default value set to original value
-                xdict['additionalInputs'] = '\n'.join(['<param name="%s" value="%s" label="%s" help="%s" type="%s"/>' % (x.split(',')[0],x.split(',')[1],x.split(',')[2],
-                    x.split(',')[3], x.split(',')[4]) for x in self.opts.additional_parameters])
-            xdict['additionalParams'] = '\n'.join(['<param name="%s" value="%s" />' % (x.split(',')[0],x.split(',')[1]) for x in self.opts.additional_parameters])
+                xdict['additionalInputs'] = '\n'.join(['<param name="%s" value="%s" label="%s" help="%s" type="%s"/>' % (x.split(',')[0],html_escape(x.split(',')[1]),html_escape(x.split(',')[2]),
+                    html_escape(x.split(',')[3]), x.split(',')[4]) for x in self.opts.additional_parameters])
+            xdict['additionalParams'] = '\n'.join(['<param name="%s" value="%s" />' % (x.split(',')[0],html_escape(x.split(',')[1])) for x in self.opts.additional_parameters])
         xdict['requirements'] = ''
         if self.opts.make_HTML:
             if self.opts.include_dependencies == "yes":
@@ -455,10 +463,11 @@
             xdict['tooldesc'] = ''
         xdict['command_outputs'] = '' 
         xdict['outputs'] = '' 
-        if self.opts.input_tab <> 'None':
+        if self.opts.input_tab:
             cins = ['\n',]
+            cins.append('--input_formats %s' % self.opts.input_formats)
             cins.append('#for intab in $input1:')
-            cins.append('--input_tab "$intab,$intab.name"')
+            cins.append('--input_tab "${intab},${intab.name}"')
             cins.append('#end for\n')
             xdict['command_inputs'] = '\n'.join(cins)
             xdict['inputs'] = '''<param name="input_tab" multiple="true"  type="data" format="%s" label="Select one or more %s input files from your history"
@@ -469,12 +478,13 @@
         if (len(self.opts.additional_parameters) > 0):
             cins = ['\n',]
             for params in self.opts.additional_parameters:
-                if self.opts.edit_additional_parameters:
                     psplit = params.split(',') # name,value...
-                    psplit[1] = '$%s' % psplit[0] # replace with form value
-                    cins.append('--additional_parameters "%s"' % ','.join(psplit)) 
-                else:
-                    cins.append('--additional_parameters "%s"' % params)
+                    psplit[3] = html_escape(psplit[3])
+                    if self.opts.edit_additional_parameters:
+                        psplit[1] = '$%s' % psplit[0] # replace with form value
+                    else:
+                        psplit[1] = html_escape(psplit[1]) # leave prespecified value
+                    cins.append('--additional_parameters """%s"""' % ','.join(psplit)) 
             xdict['command_inputs'] = '%s\n%s' % (xdict['command_inputs'],'\n'.join(cins))
         xdict['inputs'] += '<param name="job_name" type="text" size="60" label="Supply a name for the outputs to remind you what they contain" value="%s"/> \n' % self.toolname
         xdict['toolname'] = self.toolname
@@ -520,20 +530,19 @@
         tdir = self.toolname
         os.mkdir(tdir)
         self.makeXML()
-        if self.opts.make_HTML:
-            if self.opts.help_text:
-                hlp = open(self.opts.help_text,'r').read()
-            else:
-                hlp = 'Please ask the tool author for help as none was supplied at tool generation\n'
-            if self.opts.include_dependencies == "yes":
-                tooldepcontent = toolhtmldepskel  % hlp
-            else:
-                tooldepcontent = emptytoolhtmldepskel  % hlp
-            depf = open(os.path.join(tdir,'tool_dependencies.xml'),'w')
-            depf.write(tooldepcontent)
-            depf.write('\n')
-            depf.close()
-        if self.opts.input_tab <> 'None': # no reproducible test otherwise? TODO: maybe..
+        if self.opts.help_text:
+            hlp = open(self.opts.help_text,'r').read()
+        else:
+            hlp = 'Please ask the tool author for help as none was supplied at tool generation\n'
+        if self.opts.include_dependencies == "yes":
+            tooldepcontent = toolhtmldepskel  % hlp
+        else:
+            tooldepcontent = emptytoolhtmldepskel  % hlp
+        depf = open(os.path.join(tdir,'tool_dependencies.xml'),'w')
+        depf.write(tooldepcontent)
+        depf.write('\n')
+        depf.close()
+        if self.opts.input_tab: # no reproducible test otherwise? TODO: maybe..
             testdir = os.path.join(tdir,'test-data')
             os.mkdir(testdir) # make tests directory
             for i,intab in enumerate(self.opts.input_tab):
@@ -544,7 +553,7 @@
                 dest = os.path.join(testdir,os.path.basename(si))
                 if si <> dest:
                     shutil.copyfile(si,dest)
-            if self.opts.output_tab <> None:
+            if self.opts.output_tab:
                 shutil.copyfile(self.opts.output_tab,os.path.join(testdir,self.test1Output))
             if self.opts.make_HTML:
                 shutil.copyfile(self.opts.output_html,os.path.join(testdir,self.test1HTML))
--- a/rgToolFactory2.xml	Sat Jan 10 19:39:33 2015 -0500
+++ b/rgToolFactory2.xml	Sun Jan 11 21:32:15 2015 -0500
@@ -40,10 +40,12 @@
     #else:
        --output_dir "."
     #end if
-    #if $input_tab != 'None':
+    #if len($input_tab) != 0:
         --input_formats "$input_formats"
-        #for intab in $input_tab:
-              --input_tab "$intab,$intab.name"
+        #for $intab in $input_tab:
+            #if $intab.ext != 'data':
+              --input_tab "${intab},${intab.name}"
+            #end if
         #end for
     #end if
 #end if 
@@ -153,34 +155,34 @@
           <mapping initial="none"/> 
         </sanitizer>
       </param>
-    <param name="param_type" type="select" label="Select the type for this parameter">
+      <param name="param_type" type="select" label="Select the type for this parameter">
         <option value="text" selected="true">text</option>
         <option value="integer">integer</option>
         <option value="float">float</option>
         <option value="file">file</option>
         <option value="library_data">library_data</option>
-    </param>
-     <param name="param_value" type="text" value="parameter_value" label="Enter this parameter's default value" size="60"
+      </param>
+      <param name="param_value" type="text" value="parameter_value" label="Enter this parameter's default value" size="60"
         help="Note that commas and double quotes cannot be used in this text field - please work around this technical limitation" >
         <sanitizer invalid_char="">
           <valid initial="string.printable"> <remove value=','/> <remove value='"'/> </valid>
           <mapping initial="none"/>
         </sanitizer>
-     </param>
-     <param name="param_label" type="text" value="parameter_label" label="Enter this parameter's label for the form" size="60" 
-     help="Note that commas and double quotes cannot be used in this text field - please creatively work around this technical limitation" >
+      </param>
+      <param name="param_label" type="text" value="parameter_label" label="Enter this parameter's label for the form" size="60" 
+         help="Note that commas and double quotes cannot be used in this text field - please creatively work around this technical limitation" >
         <sanitizer invalid_char="">
           <valid initial="string.printable"> <remove value=','/> <remove value='"'/> </valid>
           <mapping initial="none"/>
         </sanitizer>
-     </param>
-     <param name="param_help" type="text" value="parameter_help" label="Help for this parameter"
-     help="Note that commas and double quotes cannot be used in this text field - please work around this technical limitation" size="60">
+      </param>
+      <param name="param_help" type="text" value="parameter_help" label="Help for this parameter"
+         help="Note that commas and double quotes cannot be used in this text field - please work around this technical limitation" size="60">
         <sanitizer invalid_char="">
           <valid initial="string.printable"> <remove value=','/> <remove value='"'/> </valid>
           <mapping initial="none"/>
         </sanitizer>
-     </param>
+      </param>
     </repeat> 
     <param name="dynScript" label="Cut and paste the script to be executed here" type="text" value="" area="True" size="20x120"  
       help="Script must deal with three command line parameters: please cut and paste from examples below for the appropriate scripting language">
@@ -394,7 +396,6 @@
 
 ]]>
 
-**Citation**
 
 
 Paper_ :
@@ -403,7 +404,6 @@
 Ross Lazarus; Antony Kaspi; Mark Ziemann; The Galaxy Team
 Bioinformatics 2012; doi: 10.1093/bioinformatics/bts573
 
-
 **Licensing** 
 
 Copyright Ross Lazarus (ross period lazarus at gmail period com) May 2012
@@ -417,7 +417,9 @@
 
 
 </help>
-
+<citations>
+    <citation type="doi">doi: 10.1093/bioinformatics/bts573</citation>
+</citations>
 </tool>