Mercurial > repos > pablocarb > synbiodesign
comparison toolRPViz.py @ 19:dbc40b306014 draft
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
author | pablocarb |
---|---|
date | Thu, 13 Jun 2019 08:56:51 -0400 |
parents | |
children | f3a219de2d1b |
comparison
equal
deleted
inserted
replaced
18:612a2f94522f | 19:dbc40b306014 |
---|---|
1 #!/usr/bin/env python3 | |
2 # -*- coding: utf-8 -*- | |
3 """ | |
4 Created on Mar 19 | |
5 | |
6 @author: Pablo Carbonell | |
7 @description: Query RPViz: pathway visualizer. | |
8 | |
9 """ | |
10 import requests | |
11 import argparse | |
12 import csv | |
13 import os | |
14 import json | |
15 | |
16 def arguments(): | |
17 parser = argparse.ArgumentParser(description='toolRPViz: Pathway visualizer. Pablo Carbonell, SYNBIOCHEM, 2019') | |
18 parser.add_argument('infile', | |
19 help='Pathways in SBML format.') | |
20 parser.add_argument('outfile', | |
21 help='HTML visualizer file.') | |
22 parser.add_argument('-server', default='http://rpviz.synbiochem.co.uk/REST', | |
23 help='RPViz server.') | |
24 return parser | |
25 | |
26 def testApp(url): | |
27 r = requests.get( url ) | |
28 res = json.loads( r.content.decode('utf-8') ) | |
29 print( res ) | |
30 | |
31 def pathwayUpload(infile, outfile, url): | |
32 files = { 'file': open(infile, 'rb' ) } | |
33 r = requests.post( os.path.join(url, 'Query' ), files=files ) | |
34 res = json.loads( r.content.decode('utf-8') ) | |
35 html = res['data']['html'] | |
36 with open(outfile, 'w') as h: | |
37 h.write(html) | |
38 print( 'Success!') | |
39 | |
40 def testHTML(f='outfile.html', outfile): | |
41 content = open(f).read() | |
42 with open(outfile, 'w') as h: | |
43 outfile.write(content) | |
44 | |
45 | |
46 if __name__ == "__main__": | |
47 parser = arguments() | |
48 arg = parser.parse_args() | |
49 assert os.path.exists(arg.infile) | |
50 testHTML( 'outfile.html', arg.outfile ) | |
51 # pathwayUpload( arg.infile, arg.outfile, arg.server ) |