From c49e62a5bceb1d9255d6ed4ecae579b55a14a4f3 Mon Sep 17 00:00:00 2001 From: Mingxun Wang Date: Fri, 7 Feb 2020 18:34:29 -0800 Subject: [PATCH 1/4] adding proxi interface --- views.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/views.py b/views.py index 7ff8965..6ab747e 100644 --- a/views.py +++ b/views.py @@ -373,6 +373,24 @@ def peak_json(): 'precursor_mz': spectrum.precursor_mz} return flask.jsonify(spectrum_dict) +@app.route('/api/proxi/v0.1/spectra') +def peak_proxi_json(): + spectrum, _ = parsing.parse_usi(flask.request.args.get('usi')) + + spectrum_dict = {'intensities': [str(intensity) for intensity in spectrum.intensity], + 'mzs' : [str(mz) for mz in spectrum.mz], + 'attributes': [ + { + 'accession' : "MS:1000827", + 'name' : 'isolation window target m/z', + 'value' : str(spectrum.precursor_mz) + } + ]} + + spectrum_list = [spectrum_dict] + + return flask.jsonify(spectrum_dict) + @app.route('/csv/') def peak_csv(): From 53b308cd42c6c8138895d1d8257ae9e7997e3312 Mon Sep 17 00:00:00 2001 From: Mingxun Wang Date: Thu, 19 Mar 2020 17:15:12 -0700 Subject: [PATCH 2/4] resolving comments --- views.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/views.py b/views.py index 6ab747e..ba36a45 100644 --- a/views.py +++ b/views.py @@ -377,19 +377,24 @@ def peak_json(): def peak_proxi_json(): spectrum, _ = parsing.parse_usi(flask.request.args.get('usi')) - spectrum_dict = {'intensities': [str(intensity) for intensity in spectrum.intensity], - 'mzs' : [str(mz) for mz in spectrum.mz], + spectrum_dict = {'intensities': [ + str(intensity) for intensity in spectrum.intensity + ], + 'mzs': [str(mz) for mz in spectrum.mz], 'attributes': [ { - 'accession' : "MS:1000827", - 'name' : 'isolation window target m/z', + 'accession' : "MS:1000744", + 'name' : 'selected ion m/z', 'value' : str(spectrum.precursor_mz) + }, + { + 'accession' : "MS:1000041", + 'name' : 'precursor charge ', + 'value' : str(spectrum.precursor_charge) } ]} - - spectrum_list = [spectrum_dict] - return flask.jsonify(spectrum_dict) + return flask.jsonify([spectrum_dict]) @app.route('/csv/') From 80be63419306c3d39def3cd8759a8a7ae620d8d1 Mon Sep 17 00:00:00 2001 From: Mingxun Wang Date: Thu, 19 Mar 2020 17:17:46 -0700 Subject: [PATCH 3/4] integration testing --- test-production-integration/test_integration.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test-production-integration/test_integration.py b/test-production-integration/test_integration.py index 7b2a8cf..0b42922 100644 --- a/test-production-integration/test_integration.py +++ b/test-production-integration/test_integration.py @@ -35,4 +35,15 @@ def test_img(): url = f"{PRODUCTION_URL}/png/?usi={quote(usi)}" r = requests.get(url) - r.raise_for_status() \ No newline at end of file + r.raise_for_status() + +def test_json(): + from urllib.parse import quote + for usi in test_usi_list: + url = f"{PRODUCTION_URL}/json/?usi={quote(usi)}" + r = requests.get(url) + r.raise_for_status() + + url = f"{PRODUCTION_URL}/api/proxi/v0.1/spectra?usi={quote(usi)}" + r = requests.get(url) + r.raise_for_status() From 5b8ff395ab84cc9be61e9ceae7214909395e7735 Mon Sep 17 00:00:00 2001 From: Wout Date: Thu, 19 Mar 2020 18:54:10 -0700 Subject: [PATCH 4/4] Better formatting --- views.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/views.py b/views.py index ba36a45..e53ef8a 100644 --- a/views.py +++ b/views.py @@ -373,26 +373,27 @@ def peak_json(): 'precursor_mz': spectrum.precursor_mz} return flask.jsonify(spectrum_dict) + @app.route('/api/proxi/v0.1/spectra') def peak_proxi_json(): spectrum, _ = parsing.parse_usi(flask.request.args.get('usi')) - - spectrum_dict = {'intensities': [ - str(intensity) for intensity in spectrum.intensity - ], - 'mzs': [str(mz) for mz in spectrum.mz], - 'attributes': [ - { - 'accession' : "MS:1000744", - 'name' : 'selected ion m/z', - 'value' : str(spectrum.precursor_mz) - }, - { - 'accession' : "MS:1000041", - 'name' : 'precursor charge ', - 'value' : str(spectrum.precursor_charge) - } - ]} + + spectrum_dict = { + 'intensities': [str(intensity) for intensity in spectrum.intensity], + 'mzs': [str(mz) for mz in spectrum.mz], + 'attributes': [ + { + 'accession': 'MS:1000744', + 'name': 'selected ion m/z', + 'value': str(spectrum.precursor_mz) + }, + { + 'accession': 'MS:1000041', + 'name': 'precursor charge', + 'value': str(spectrum.precursor_charge) + } + ] + } return flask.jsonify([spectrum_dict])