Mercurial > repos > pablocarb > synbiodesign
comparison toolRPViz.py @ 29:d854b21ada0c draft
planemo upload commit c56eddc745b70354680c2a2b605840ed72bb98ef
author | pablocarb |
---|---|
date | Wed, 07 Aug 2019 05:13:27 -0400 |
parents | b30e3e5ee8f8 |
children |
comparison
equal
deleted
inserted
replaced
28:501f39987c9b | 29:d854b21ada0c |
---|---|
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 import tarfile |
16 import shutil | |
16 | 17 |
17 def arguments(): | 18 def arguments(): |
18 parser = argparse.ArgumentParser(description='toolRPViz: Pathway visualizer. Pablo Carbonell, SYNBIOCHEM, 2019') | 19 parser = argparse.ArgumentParser(description='toolRPViz: Pathway visualizer. Pablo Carbonell, SYNBIOCHEM, 2019') |
19 parser.add_argument('infile', | 20 parser.add_argument('infile', |
20 help='Pathways in SBML format.') | 21 help='Pathways in SBML format.') |
37 r = requests.get( url ) | 38 r = requests.get( url ) |
38 res = json.loads( r.content.decode('utf-8') ) | 39 res = json.loads( r.content.decode('utf-8') ) |
39 print( res ) | 40 print( res ) |
40 | 41 |
41 def pathwayUpload( arg ): | 42 def pathwayUpload( arg ): |
42 files = { 'file': open(arg.infile, 'rb' ) } | 43 # Post request |
43 data = {'selenzyme_table': arg.selenzyme_table, 'input_format': arg.input_format} | 44 data = {'selenzyme_table': arg.selenzyme_table, 'input_format': arg.input_format} |
45 files = { 'file': open(arg.infile, 'rb' ), 'data': ('data.json', json.dumps(data)) } | |
44 print('Sending query to '+arg.server) | 46 print('Sending query to '+arg.server) |
45 r=requests.post( arg.server+'/Query',files=files,data=data ) | 47 r=requests.post(arg.server+'/Query',files=files) |
46 if arg.outfolder is None: | 48 # Read response |
47 arg.outfolder = os.path.dirname( arg.outfile ) | 49 if not os.path.exists(arg.outfolder): |
48 if not os.path.exists(outfolder): | |
49 os.mkdir(arg.outfolder) | 50 os.mkdir(arg.outfolder) |
50 outtar = os.path.join( arg.outfolder, 'out.tar' ) | 51 outtar = os.path.join( arg.outfolder, 'out.tar' ) |
51 open(outtar,'wb').write( r.content ) | 52 open(outtar,'wb').write( r.content ) |
52 print( 'Response successfully received' ) | 53 print( 'Response successfully received' ) |
53 tar = tarfile.open(outtar) | 54 tar = tarfile.open(outtar) |
54 tar.extractall(path=arg.outfolder) | 55 tar.extractall(path=arg.outfolder) |
55 html = os.path.join( arg.outfolder, 'index.html' ) | 56 html = os.path.join( arg.outfolder, 'index.html' ) |
56 shutil.cp( html, arg.outfile ) | 57 shutil.copy( html, arg.outfile ) |
57 print( 'Files extracted' ) | 58 print( 'Files extracted' ) |
58 | 59 |
59 | 60 |
60 if __name__ == "__main__": | 61 if __name__ == "__main__": |
61 parser = arguments() | 62 parser = arguments() |