Mercurial > repos > pablocarb > synbiodesign
annotate toolRPViz.py @ 29:d854b21ada0c draft
planemo upload commit c56eddc745b70354680c2a2b605840ed72bb98ef
author | pablocarb |
---|---|
date | Wed, 07 Aug 2019 05:13:27 -0400 |
parents | b30e3e5ee8f8 |
children |
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 |
27
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
15 import tarfile |
29
d854b21ada0c
planemo upload commit c56eddc745b70354680c2a2b605840ed72bb98ef
pablocarb
parents:
27
diff
changeset
|
16 import shutil |
19
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
17 |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
18 def arguments(): |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
19 parser = argparse.ArgumentParser(description='toolRPViz: Pathway visualizer. Pablo Carbonell, SYNBIOCHEM, 2019') |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
20 parser.add_argument('infile', |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
21 help='Pathways in SBML format.') |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
22 parser.add_argument('outfile', |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
23 help='HTML visualizer file.') |
27
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
24 parser.add_argument('--input_format', default='sbml', |
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
25 help='Input format: sbml|json') |
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
26 parser.add_argument('--choice', default="5", |
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
27 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') |
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
28 parser.add_argument('--selenzyme_table', |
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
29 default="N", |
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
30 help='Do you want to display the selenzyme information ? Y/N') |
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
31 parser.add_argument('--outfolder', |
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
32 help='Location of additional files') |
19
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
33 parser.add_argument('-server', default='http://rpviz.synbiochem.co.uk/REST', |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
34 help='RPViz server.') |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
35 return parser |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
36 |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
37 def testApp(url): |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
38 r = requests.get( url ) |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
39 res = json.loads( r.content.decode('utf-8') ) |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
40 print( res ) |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
41 |
27
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
42 def pathwayUpload( arg ): |
29
d854b21ada0c
planemo upload commit c56eddc745b70354680c2a2b605840ed72bb98ef
pablocarb
parents:
27
diff
changeset
|
43 # Post request |
27
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
44 data = {'selenzyme_table': arg.selenzyme_table, 'input_format': arg.input_format} |
29
d854b21ada0c
planemo upload commit c56eddc745b70354680c2a2b605840ed72bb98ef
pablocarb
parents:
27
diff
changeset
|
45 files = { 'file': open(arg.infile, 'rb' ), 'data': ('data.json', json.dumps(data)) } |
27
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
46 print('Sending query to '+arg.server) |
29
d854b21ada0c
planemo upload commit c56eddc745b70354680c2a2b605840ed72bb98ef
pablocarb
parents:
27
diff
changeset
|
47 r=requests.post(arg.server+'/Query',files=files) |
d854b21ada0c
planemo upload commit c56eddc745b70354680c2a2b605840ed72bb98ef
pablocarb
parents:
27
diff
changeset
|
48 # Read response |
d854b21ada0c
planemo upload commit c56eddc745b70354680c2a2b605840ed72bb98ef
pablocarb
parents:
27
diff
changeset
|
49 if not os.path.exists(arg.outfolder): |
27
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
50 os.mkdir(arg.outfolder) |
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
51 outtar = os.path.join( arg.outfolder, 'out.tar' ) |
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
52 open(outtar,'wb').write( r.content ) |
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
53 print( 'Response successfully received' ) |
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
54 tar = tarfile.open(outtar) |
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
55 tar.extractall(path=arg.outfolder) |
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
56 html = os.path.join( arg.outfolder, 'index.html' ) |
29
d854b21ada0c
planemo upload commit c56eddc745b70354680c2a2b605840ed72bb98ef
pablocarb
parents:
27
diff
changeset
|
57 shutil.copy( html, arg.outfile ) |
27
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
58 print( 'Files extracted' ) |
19
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
59 |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
60 |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
61 if __name__ == "__main__": |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
62 parser = arguments() |
dbc40b306014
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
pablocarb
parents:
diff
changeset
|
63 arg = parser.parse_args() |
27
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
64 assert os.path.exists( arg.infile ) |
b30e3e5ee8f8
planemo upload commit 708fd9f837af7425a8986c336aab18cec7ff5b05
pablocarb
parents:
21
diff
changeset
|
65 pathwayUpload( arg ) |