diff options
author | BonfaceKilz | 2021-07-16 13:56:10 +0300 |
---|---|---|
committer | BonfaceKilz | 2021-08-03 15:49:50 +0300 |
commit | b0514de0f73a9a6d756d7d5daa2a0641c5456ff2 (patch) | |
tree | 6590e1bf781f10cb7b9e6dc55e49c272d27d8c7f | |
parent | 78f0e216c165eb7879ab07755a2d74deec3a11d5 (diff) | |
download | genenetwork2-b0514de0f73a9a6d756d7d5daa2a0641c5456ff2.tar.gz |
wqflask: views: Add endpoint for getting the csv data
-rw-r--r-- | wqflask/wqflask/views.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 1bd11c4e..b97f15a4 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -38,6 +38,7 @@ from gn3.db.phenotypes import Probeset from gn3.db.phenotypes import Publication from gn3.db.phenotypes import PublishXRef from gn3.db.phenotypes import probeset_mapping +from gn3.db.traits import get_trait_csv_sample_data from flask import current_app @@ -1313,3 +1314,19 @@ def json_default_handler(obj): else: raise TypeError('Object of type %s with value of %s is not JSON serializable' % ( type(obj), repr(obj))) + + +@app.route("/trait/<trait_name>/sampledata/<phenotype_id>") +def get_sample_data_as_csv(trait_name: int, phenotype_id: int): + conn = MySQLdb.Connect(db=current_app.config.get("DB_NAME"), + user=current_app.config.get("DB_USER"), + passwd=current_app.config.get("DB_PASS"), + host=current_app.config.get("DB_HOST")) + csv_data = get_trait_csv_sample_data(conn, str(trait_name), + str(phenotype_id)) + return Response( + csv_data, + mimetype="text/csv", + headers={"Content-disposition": + "attachment; filename=myplot.csv"} + ) |