comparison rgToolFactory.py @ 13:7725e4ab27e1

Adding tests - problem to find the script - needs a fixed string somewhere. Updated readme
author ross lazarus ross.lazarus@gmail.com
date Sun, 03 Jun 2012 22:25:46 +1000
parents d12728e33c3d
children 8594478e8d2c
comparison
equal deleted inserted replaced
12:d12728e33c3d 13:7725e4ab27e1
91 91
92 92
93 def makeXML(self): 93 def makeXML(self):
94 """ 94 """
95 Create a Galaxy xml tool wrapper for the new script as a string to write out 95 Create a Galaxy xml tool wrapper for the new script as a string to write out
96 fixme - use templating or something less fugly than this 96 fixme - use templating or something less fugly than this.
97 Here's an example of what we produce
98
99 <tool id="reverse" name="reverse" version="0.01">
100 <description>a tabular file</description>
101 <command interpreter="python">
102 reverse.py --script_path "$runMe" --interpreter "python"
103 --tool_name "reverse" --input_tab "$input1" --output_tab "$tab_file"
104 </command>
105 <inputs>
106 <param name="input1" type="data" format="tabular" label="Select a suitable input file from your history"/><param name="job_name" type="text" label="Supply a name for the outputs to remind you what they contain" value="reverse"/>
107
108 </inputs>
109 <outputs>
110 <data format="tabular" name="tab_file" label="${job_name}"/>
111
112 </outputs>
113 <help>
114
115 **What it Does**
116
117 Reverse the columns in a tabular file
118
119 </help>
120 <configfiles>
121 <configfile name="runMe">
122
123 # reverse order of columns in a tabular file
124 import sys
125 inp = sys.argv[1]
126 outp = sys.argv[2]
127 i = open(inp,'r')
128 o = open(outp,'w')
129 for row in i:
130 rs = row.rstrip().split('\t')
131 rs.reverse()
132 o.write('\t'.join(rs))
133 o.write('\n')
134 i.close()
135 o.close()
136
137
138 </configfile>
139 </configfiles>
140 </tool>
141
97 """ 142 """
98 newXML="""<tool id="%(toolid)s" name="%(toolname)s" version="0.01"> 143 newXML="""<tool id="%(toolid)s" name="%(toolname)s" version="0.01">
99 %(tooldesc)s 144 %(tooldesc)s
100 %(command)s 145 %(command)s
101 <inputs> 146 <inputs>
110 <configfiles> 155 <configfiles>
111 <configfile name="runMe"> 156 <configfile name="runMe">
112 %(script)s 157 %(script)s
113 </configfile> 158 </configfile>
114 </configfiles> 159 </configfiles>
160 %(tooltests)s
115 </tool>""" # needs a dict with toolname, toolid, interpreter, scriptname, command, inputs as a multi line string ready to write, outputs ditto, help ditto 161 </tool>""" # needs a dict with toolname, toolid, interpreter, scriptname, command, inputs as a multi line string ready to write, outputs ditto, help ditto
116 162
117 newCommand="""<command interpreter="python"> 163 newCommand="""<command interpreter="python">
118 %(toolname)s.py --script_path "$runMe" --interpreter "%(interpreter)s" 164 %(toolname)s.py --script_path "$runMe" --interpreter "%(interpreter)s"
119 --tool_name "%(toolname)s" %(command_inputs)s %(command_outputs)s 165 --tool_name "%(toolname)s" %(command_inputs)s %(command_outputs)s
120 </command>""" # may NOT be an input or htmlout 166 </command>""" # may NOT be an input or htmlout
121 167 tooltests = """<tests><test>
168 <param name="input1" value="%s" ftype="%s"/>
169 <param name="job_name" value="test1"/>
170 <param name="runMe" value="$runMe"/>
171 </test><tests>"""
122 xdict = {} 172 xdict = {}
123 xdict['script'] = self.script # configfile is least painful way to embed script to avoid external dependencies 173 xdict['script'] = self.script # configfile is least painful way to embed script to avoid external dependencies
124 if self.opts.help_text: 174 if self.opts.help_text:
125 xdict['help'] = open(self.opts.help_text,'r').read() 175 xdict['help'] = open(self.opts.help_text,'r').read()
126 else: 176 else: