Mercurial > repos > pablocarb > synbiodesign
annotate toolRPViz.py @ 21:cb029043c1d6 draft
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
author | pablocarb |
---|---|
date | Thu, 13 Jun 2019 09:52:15 -0400 |
parents | f3a219de2d1b |
children | b30e3e5ee8f8 |
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 |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
40 |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
41 if __name__ == "__main__": |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
42 parser = arguments() |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
43 arg = parser.parse_args() |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
44 assert os.path.exists(arg.infile) |
21
cb029043c1d6
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
20
diff
changeset
|
45 pathwayUpload( arg.infile, arg.outfile, arg.server ) |