view toolRPViz.py @ 22:638dcd2d93bc draft

planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
author pablocarb
date Fri, 14 Jun 2019 12:14:23 -0400
parents cb029043c1d6
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 )