annotate toolRPViz.py @ 20:f3a219de2d1b draft

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