comparison toolRPViz.py @ 27:b30e3e5ee8f8 draft

planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
author pablocarb
date Fri, 02 Aug 2019 05:17:33 -0400
parents cb029043c1d6
children d854b21ada0c
comparison
equal deleted inserted replaced
26:fbf2e5072b32 27:b30e3e5ee8f8
10 import requests 10 import requests
11 import argparse 11 import argparse
12 import csv 12 import csv
13 import os 13 import os
14 import json 14 import json
15 import tarfile
15 16
16 def arguments(): 17 def arguments():
17 parser = argparse.ArgumentParser(description='toolRPViz: Pathway visualizer. Pablo Carbonell, SYNBIOCHEM, 2019') 18 parser = argparse.ArgumentParser(description='toolRPViz: Pathway visualizer. Pablo Carbonell, SYNBIOCHEM, 2019')
18 parser.add_argument('infile', 19 parser.add_argument('infile',
19 help='Pathways in SBML format.') 20 help='Pathways in SBML format.')
20 parser.add_argument('outfile', 21 parser.add_argument('outfile',
21 help='HTML visualizer file.') 22 help='HTML visualizer file.')
23 parser.add_argument('--input_format', default='sbml',
24 help='Input format: sbml|json')
25 parser.add_argument('--choice', default="5",
26 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')
27 parser.add_argument('--selenzyme_table',
28 default="N",
29 help='Do you want to display the selenzyme information ? Y/N')
30 parser.add_argument('--outfolder',
31 help='Location of additional files')
22 parser.add_argument('-server', default='http://rpviz.synbiochem.co.uk/REST', 32 parser.add_argument('-server', default='http://rpviz.synbiochem.co.uk/REST',
23 help='RPViz server.') 33 help='RPViz server.')
24 return parser 34 return parser
25 35
26 def testApp(url): 36 def testApp(url):
27 r = requests.get( url ) 37 r = requests.get( url )
28 res = json.loads( r.content.decode('utf-8') ) 38 res = json.loads( r.content.decode('utf-8') )
29 print( res ) 39 print( res )
30 40
31 def pathwayUpload(infile, outfile, url): 41 def pathwayUpload( arg ):
32 files = { 'file': open(infile, 'rb' ) } 42 files = { 'file': open(arg.infile, 'rb' ) }
33 r = requests.post( os.path.join(url, 'Query' ), files=files ) 43 data = {'selenzyme_table': arg.selenzyme_table, 'input_format': arg.input_format}
34 res = json.loads( r.content.decode('utf-8') ) 44 print('Sending query to '+arg.server)
35 html = res['data']['html'] 45 r=requests.post( arg.server+'/Query',files=files,data=data )
36 with open(outfile, 'w') as h: 46 if arg.outfolder is None:
37 h.write(html) 47 arg.outfolder = os.path.dirname( arg.outfile )
38 print( 'Success!') 48 if not os.path.exists(outfolder):
49 os.mkdir(arg.outfolder)
50 outtar = os.path.join( arg.outfolder, 'out.tar' )
51 open(outtar,'wb').write( r.content )
52 print( 'Response successfully received' )
53 tar = tarfile.open(outtar)
54 tar.extractall(path=arg.outfolder)
55 html = os.path.join( arg.outfolder, 'index.html' )
56 shutil.cp( html, arg.outfile )
57 print( 'Files extracted' )
39 58
40 59
41 if __name__ == "__main__": 60 if __name__ == "__main__":
42 parser = arguments() 61 parser = arguments()
43 arg = parser.parse_args() 62 arg = parser.parse_args()
44 assert os.path.exists(arg.infile) 63 assert os.path.exists( arg.infile )
45 pathwayUpload( arg.infile, arg.outfile, arg.server ) 64 pathwayUpload( arg )