view 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
line wrap: on
line source

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mar 19

@author: Pablo Carbonell
@description: Query RPViz: pathway visualizer.

"""
import requests
import argparse
import csv
import os
import json

def arguments():
    parser = argparse.ArgumentParser(description='toolRPViz: Pathway visualizer. Pablo Carbonell, SYNBIOCHEM, 2019')
    parser.add_argument('infile', 
                        help='Pathways in SBML format.')
    parser.add_argument('outfile', 
                        help='HTML visualizer file.')
    parser.add_argument('-server', default='http://rpviz.synbiochem.co.uk/REST',
                        help='RPViz server.')
    return parser

def testApp(url):
    r = requests.get( url )
    res = json.loads( r.content.decode('utf-8') )
    print( res )
    
def pathwayUpload(infile, outfile, url):
    files = { 'file': open(infile, 'rb' ) }
    r = requests.post( os.path.join(url, 'Query' ), files=files )
    res = json.loads( r.content.decode('utf-8') )
    html = res['data']['html']
    with open(outfile, 'w') as h:
        h.write(html)
    print( 'Success!')


if __name__ == "__main__":
    parser = arguments()
    arg = parser.parse_args()
    assert os.path.exists(arg.infile)
    pathwayUpload( arg.infile, arg.outfile, arg.server )