view toolRPViz.py @ 19:dbc40b306014 draft

planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5-dirty
author pablocarb
date Thu, 13 Jun 2019 08:56:51 -0400
parents
children f3a219de2d1b
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!')

def testHTML(f='outfile.html', outfile):
    content = open(f).read()
    with open(outfile, 'w') as h:
        outfile.write(content)


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