aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzsloan2019-05-31 12:58:26 -0500
committerzsloan2019-05-31 12:58:26 -0500
commit84d165a30aaff2fcb4dd6b3bb7106ff0ceb495e9 (patch)
tree6bfe896ceddf7ecab9ea7ba3e16c2200e49bfc9d
parent9ba6aae14ac7c55db4c30476908268faf7ca4d92 (diff)
downloadgenenetwork2-84d165a30aaff2fcb4dd6b3bb7106ff0ceb495e9.tar.gz
Added option to get just trait names from traits query, and also fixed sample_data query to avoid duplicates
-rw-r--r--wqflask/wqflask/api/router.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/wqflask/wqflask/api/router.py b/wqflask/wqflask/api/router.py
index 4ecd6699..707e4e65 100644
--- a/wqflask/wqflask/api/router.py
+++ b/wqflask/wqflask/api/router.py
@@ -292,8 +292,8 @@ def get_dataset_info(dataset_name, group_name = None, file_format="json"):
@app.route("/api/v_{}/traits/<path:dataset_name>".format(version), methods=('GET',))
@app.route("/api/v_{}/traits/<path:dataset_name>.<path:file_format>".format(version), methods=('GET',))
-def fetch_traits(dataset_name, file_format = "csv"):
- trait_ids, _trait_names, data_type, dataset_id = get_dataset_trait_ids(dataset_name)
+def fetch_traits(dataset_name, file_format = "json"):
+ trait_ids, trait_names, data_type, dataset_id = get_dataset_trait_ids(dataset_name)
if ('ids_only' in request.args) and (len(trait_ids) > 0):
if file_format == "json":
filename = dataset_name + "_trait_ids.json"
@@ -308,6 +308,20 @@ def fetch_traits(dataset_name, file_format = "csv"):
output.headers["Content-Disposition"] = "attachment; filename=" + filename
output.headers["Content-type"] = "text/csv"
return output
+ elif ('names_only' in request.args) and (len(trait_ids) > 0):
+ if file_format == "json":
+ filename = dataset_name + "_trait_names.json"
+ return flask.jsonify(trait_names)
+ else:
+ filename = dataset_name + "_trait_names.csv"
+
+ si = StringIO.StringIO()
+ csv_writer = csv.writer(si)
+ csv_writer.writerows([[trait_name] for trait_name in trait_names])
+ output = make_response(si.getvalue())
+ output.headers["Content-Disposition"] = "attachment; filename=" + filename
+ output.headers["Content-type"] = "text/csv"
+ return output
else:
if len(trait_ids) > 0:
if data_type == "ProbeSet":
@@ -534,7 +548,7 @@ def trait_sample_data(dataset_name, trait_name, file_format = "json"):
dataset_or_group = dataset_name
pheno_query = """
- SELECT
+ SELECT DISTINCT
Strain.Name, Strain.Name2, PublishData.value, PublishData.Id, PublishSE.error, NStrain.count
FROM
(PublishData, Strain, PublishXRef, PublishFreeze)