view toolRPViz.py @ 26:fbf2e5072b32 draft

planemo upload commit c74b3ff2329f69ac7b309cc7d9bdf7b9d78106fb-dirty
author pablocarb
date Fri, 05 Jul 2019 17:29:50 -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 )