comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:cce6989ed423
1 """
2 Controller for integration with NIST data.
3
4 Place this in: <galaxy_home>/lib/galaxy/webapps/galaxy/controllers
5 and then it can be accessed via URL:
6
7 http://<galaxy_url>/nist_controller/get_nistdata
8 e.g.
9 http://dev1.ab.wurnet.nl:8088/nist_controller/get_nistdata
10
11 """
12
13 import urllib2
14 from galaxy.web.base.controller import BaseUIController, url_for, error, web
15
16
17 class NistController( BaseUIController ):
18 """
19 Provides some services for the NIST html report
20 """
21
22 @web.expose
23 def get_nistdata( self, trans, casnr=None ):
24 """
25 Generate a redirect to NIST webbook web app
26 casNr example: "C537268"
27
28 """
29
30 nist_response = _fire_query_and_return_content("http://webbook.nist.gov/cgi/cbook.cgi?JCAMP="+ casnr + "&Index=0&Type=Mass")
31 peak_table = nist_response.split("##PEAK TABLE=(XY..XY)")[1].split("##END=")[0]
32 peak_table = peak_table.replace("\n", " ").strip()
33 return peak_table
34
35
36
37
38
39 def _fire_query_and_return_content(url):
40 '''
41 This method will fire the HTTP call and
42 return the results
43 '''
44
45 try:
46 data = urllib2.urlopen(url).read()
47
48 return data
49
50 except urllib2.HTTPError, e:
51 raise Exception( "HTTP error for URL: " + url + " : %s - " % e.code + e.reason)
52 except urllib2.URLError, e:
53 raise Exception( "Network error: %s" % e.reason.args[1] + ". Error accessing remote service [" + url + "] ")
54