Mercurial > repos > pieterlukasse > nist_wrapper
view nist_controller.py @ 0:cce6989ed423
new NIST wrapper demo tools
author | pieter.lukasse@wur.nl |
---|---|
date | Thu, 22 Jan 2015 16:14:57 +0100 |
parents | |
children |
line wrap: on
line source
""" Controller for integration with NIST data. Place this in: <galaxy_home>/lib/galaxy/webapps/galaxy/controllers and then it can be accessed via URL: http://<galaxy_url>/nist_controller/get_nistdata e.g. http://dev1.ab.wurnet.nl:8088/nist_controller/get_nistdata """ import urllib2 from galaxy.web.base.controller import BaseUIController, url_for, error, web class NistController( BaseUIController ): """ Provides some services for the NIST html report """ @web.expose def get_nistdata( self, trans, casnr=None ): """ Generate a redirect to NIST webbook web app casNr example: "C537268" """ nist_response = _fire_query_and_return_content("http://webbook.nist.gov/cgi/cbook.cgi?JCAMP="+ casnr + "&Index=0&Type=Mass") peak_table = nist_response.split("##PEAK TABLE=(XY..XY)")[1].split("##END=")[0] peak_table = peak_table.replace("\n", " ").strip() return peak_table def _fire_query_and_return_content(url): ''' This method will fire the HTTP call and return the results ''' try: data = urllib2.urlopen(url).read() return data except urllib2.HTTPError, e: raise Exception( "HTTP error for URL: " + url + " : %s - " % e.code + e.reason) except urllib2.URLError, e: raise Exception( "Network error: %s" % e.reason.args[1] + ". Error accessing remote service [" + url + "] ")