changeset 27:b30e3e5ee8f8 draft

planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
author pablocarb
date Fri, 02 Aug 2019 05:17:33 -0400
parents fbf2e5072b32
children 501f39987c9b
files rpviz.xml toolRPViz.py
diffstat 2 files changed, 36 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/rpviz.xml	Fri Jul 05 17:29:50 2019 -0400
+++ b/rpviz.xml	Fri Aug 02 05:17:33 2019 -0400
@@ -7,13 +7,18 @@
      python $__tool_directory__/toolRPViz.py $input1 $output1 -server $server
    ]]></command>
     <inputs>
-        <param type="data" name="input1" format="xml" />
+        <param type="data" name="input1" format="tar" label="Input pathways"/>
+	<param name="input2" type="text" value="sbml" label="Input format">
+	  <option value="sbml">sbml</option>
+	  <option value="csv">CSV</option>
+	</param>
+	<param name="input3" type="boolean" truevalue="Y" falsevalue="N" checked="false" label="Retrieve Selenzyme information" />
     	<param name="server" type="text" label="RPViz RES server" value="http://rpviz.synbiochem.co.uk/REST" help="RPviz REST server" />
     </inputs>
     <outputs>
         <data name="output1" format="html" from_work_dir="out.html" />
     </outputs>
     <help><![CDATA[
-        python3 toolRPViz.py [server SERVER] inputfile outputfile
+        python3 toolRPViz.py [server SERVER] inputfile outputfile --input_format $input2 --selenzyme_table  --outfolder $outputfile.extra_files_path
     ]]></help>
 </tool>
--- a/toolRPViz.py	Fri Jul 05 17:29:50 2019 -0400
+++ b/toolRPViz.py	Fri Aug 02 05:17:33 2019 -0400
@@ -12,6 +12,7 @@
 import csv
 import os
 import json
+import tarfile
 
 def arguments():
     parser = argparse.ArgumentParser(description='toolRPViz: Pathway visualizer. Pablo Carbonell, SYNBIOCHEM, 2019')
@@ -19,6 +20,15 @@
                         help='Pathways in SBML format.')
     parser.add_argument('outfile', 
                         help='HTML visualizer file.')
+    parser.add_argument('--input_format', default='sbml',
+                        help='Input format: sbml|json')
+    parser.add_argument('--choice', default="5",
+                        help='What kind of output do you want ? \n 1/Single HTML file \n 2/Separated HTML files \n 3/View directly in Cytoscape \n 4/Generate a file readable in Cytoscape \n 5/Tar file')
+    parser.add_argument('--selenzyme_table',
+                        default="N",
+                        help='Do you want to display the selenzyme information ? Y/N')
+    parser.add_argument('--outfolder', 
+                        help='Location of additional files')
     parser.add_argument('-server', default='http://rpviz.synbiochem.co.uk/REST',
                         help='RPViz server.')
     return parser
@@ -28,18 +38,27 @@
     res = json.loads( r.content.decode('utf-8') )
     print( res )
     
-def pathwayUpload(infile, outfile, url):
-    files = { 'file': open(infile, 'rb' ) }
-    r = requests.post( os.path.join(url, 'Query' ), files=files )
-    res = json.loads( r.content.decode('utf-8') )
-    html = res['data']['html']
-    with open(outfile, 'w') as h:
-        h.write(html)
-    print( 'Success!')
+def pathwayUpload( arg ):
+    files = { 'file': open(arg.infile, 'rb' ) }
+    data = {'selenzyme_table': arg.selenzyme_table, 'input_format': arg.input_format}
+    print('Sending query to '+arg.server)
+    r=requests.post( arg.server+'/Query',files=files,data=data )
+    if arg.outfolder is None:
+        arg.outfolder = os.path.dirname( arg.outfile )
+    if not os.path.exists(outfolder):
+        os.mkdir(arg.outfolder)
+    outtar = os.path.join( arg.outfolder, 'out.tar' )
+    open(outtar,'wb').write( r.content )
+    print( 'Response successfully received' )
+    tar = tarfile.open(outtar)
+    tar.extractall(path=arg.outfolder)
+    html = os.path.join( arg.outfolder, 'index.html' )
+    shutil.cp( html, arg.outfile )  
+    print( 'Files extracted' )
 
 
 if __name__ == "__main__":
     parser = arguments()
     arg = parser.parse_args()
-    assert os.path.exists(arg.infile)
-    pathwayUpload( arg.infile, arg.outfile, arg.server )
+    assert os.path.exists( arg.infile )
+    pathwayUpload( arg )