aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-06-16 08:00:33 +0300
committerFrederick Muriuki Muriithi2023-06-20 13:36:50 +0300
commit3ac57ba09a504bf0f03c0786c1d2504363a660ec (patch)
treeac7a75e41d655504ebcee720674919b46eb8901e /wqflask
parentaa4d213692cb27a903fe1593e2dd3387e638b350 (diff)
downloadgenenetwork2-3ac57ba09a504bf0f03c0786c1d2504363a660ec.tar.gz
Add blueprint and rework configuration retrieval
Add a blueprint for the `wqflask.api` package and register the `wqflask.api.router` module as a child. Rework the cascading imports to use the new configuration system to avoid circular imports.
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/utility/pillow_utils.py5
-rw-r--r--wqflask/wqflask/__init__.py1
-rw-r--r--wqflask/wqflask/api/__init__.py9
-rw-r--r--wqflask/wqflask/api/router.py107
-rw-r--r--wqflask/wqflask/marker_regression/gemma_mapping.py79
-rw-r--r--wqflask/wqflask/show_trait/show_trait.py6
-rw-r--r--wqflask/wqflask/top_level_routes.py3
7 files changed, 110 insertions, 100 deletions
diff --git a/wqflask/utility/pillow_utils.py b/wqflask/utility/pillow_utils.py
index e302df18..eca45244 100644
--- a/wqflask/utility/pillow_utils.py
+++ b/wqflask/utility/pillow_utils.py
@@ -1,6 +1,7 @@
+from flask import current_app as app
from PIL import Image, ImageColor, ImageDraw, ImageFont
-from utility.tools import TEMPDIR
+from utility.configuration import get_setting
BLACK = ImageColor.getrgb("black")
WHITE = ImageColor.getrgb("white")
@@ -15,7 +16,7 @@ def draw_rotated_text(canvas, text, font, xy, fill=BLACK, angle=-90):
draw_text = ImageDraw.Draw(tmp_img)
draw_text.text(text=text, xy=(0, 0), font=font, fill=fill)
tmp_img2 = tmp_img.rotate(angle, expand=1)
- tmp_img2.save("/{0}/{1}.png".format(TEMPDIR, text), format="png")
+ tmp_img2.save("/{0}/{1}.png".format(get_setting(app, "TEMPDIR"), text), format="png")
canvas.paste(im=tmp_img2, box=tuple([int(i) for i in xy]))
# def draw_open_polygon(canvas: Image, xy: tuple, fill: ImageColor=WHITE, outline: ImageColor=BLACK):
diff --git a/wqflask/wqflask/__init__.py b/wqflask/wqflask/__init__.py
index fe66d1b7..45b5a14b 100644
--- a/wqflask/wqflask/__init__.py
+++ b/wqflask/wqflask/__init__.py
@@ -130,7 +130,6 @@ def include_data_role_class():
return {'DataRole': DataRole}
-from wqflask.api import router
from wqflask import group_manager
from wqflask import resource_manager
from wqflask import search_results
diff --git a/wqflask/wqflask/api/__init__.py b/wqflask/wqflask/api/__init__.py
index e69de29b..abeb6e56 100644
--- a/wqflask/wqflask/api/__init__.py
+++ b/wqflask/wqflask/api/__init__.py
@@ -0,0 +1,9 @@
+"""
+Set up the package's top-level objects.
+"""
+from flask import Blueprint
+
+from . import router as router
+
+api_bp = Blueprint("api", __name__)
+api_bp.register_blueprint(router.pre1_router)
diff --git a/wqflask/wqflask/api/router.py b/wqflask/wqflask/api/router.py
index d7eeac34..afa150dc 100644
--- a/wqflask/wqflask/api/router.py
+++ b/wqflask/wqflask/api/router.py
@@ -11,30 +11,27 @@ from zipfile import ZipFile, ZIP_DEFLATED
import flask
-from flask import current_app
-from wqflask.database import database_connection
from flask import request
-from flask import make_response
+from flask import Blueprint
from flask import send_file
+from flask import make_response
+from flask import current_app as app
-from wqflask import app
-
-from wqflask.api import correlation, mapping, gen_menu
-
-from utility.tools import flat_files
+from utility.configuration import flat_files
from wqflask.database import database_connection
+from wqflask.api import correlation, mapping, gen_menu
version = "pre1"
+pre1_router = Blueprint("pre1_router", __name__)
-
-@app.route("/api/v_{}/".format(version))
+@pre1_router.route("/v_{}/".format(version))
def hello_world():
return flask.jsonify({"hello": "world"})
-@app.route("/api/v_{}/species".format(version))
+@pre1_router.route("/v_{}/species".format(version))
def get_species_list():
species_list = []
with database_connection() as conn, conn.cursor() as cursor:
@@ -52,8 +49,8 @@ def get_species_list():
return flask.jsonify(species_list)
-@app.route("/api/v_{}/species/<path:species_name>".format(version))
-@app.route("/api/v_{}/species/<path:species_name>.<path:file_format>".format(version))
+@pre1_router.route("/v_{}/species/<path:species_name>".format(version))
+@pre1_router.route("/v_{}/species/<path:species_name>.<path:file_format>".format(version))
def get_species_info(species_name, file_format="json"):
with database_connection() as conn, conn.cursor() as cursor:
cursor.execute(
@@ -71,8 +68,8 @@ def get_species_info(species_name, file_format="json"):
return flask.jsonify(species_dict)
-@app.route("/api/v_{}/groups".format(version))
-@app.route("/api/v_{}/groups/<path:species_name>".format(version))
+@pre1_router.route("/v_{}/groups".format(version))
+@pre1_router.route("/v_{}/groups/<path:species_name>".format(version))
def get_groups_list(species_name=None):
_groups = ()
with database_connection() as conn, conn.cursor() as cursor:
@@ -117,10 +114,10 @@ def get_groups_list(species_name=None):
return return_error(code=204, source=request.url_rule.rule, title="No Results", details="")
-@app.route("/api/v_{}/group/<path:group_name>".format(version))
-@app.route("/api/v_{}/group/<path:group_name>.<path:file_format>".format(version))
-@app.route("/api/v_{}/group/<path:species_name>/<path:group_name>".format(version))
-@app.route("/api/v_{}/group/<path:species_name>/<path:group_name>.<path:file_format>".format(version))
+@pre1_router.route("/v_{}/group/<path:group_name>".format(version))
+@pre1_router.route("/v_{}/group/<path:group_name>.<path:file_format>".format(version))
+@pre1_router.route("/v_{}/group/<path:species_name>/<path:group_name>".format(version))
+@pre1_router.route("/v_{}/group/<path:species_name>/<path:group_name>.<path:file_format>".format(version))
def get_group_info(group_name, species_name=None, file_format="json"):
group = ()
with database_connection() as conn, conn.cursor() as cursor:
@@ -172,8 +169,8 @@ def get_group_info(group_name, species_name=None, file_format="json"):
return return_error(code=204, source=request.url_rule.rule, title="No Results", details="")
-@app.route("/api/v_{}/datasets/<path:group_name>".format(version))
-@app.route("/api/v_{}/datasets/<path:species_name>/<path:group_name>".format(version))
+@pre1_router.route("/v_{}/datasets/<path:group_name>".format(version))
+@pre1_router.route("/v_{}/datasets/<path:species_name>/<path:group_name>".format(version))
def get_datasets_for_group(group_name, species_name=None):
_datasets = ()
with database_connection() as conn, conn.cursor() as cursor:
@@ -237,10 +234,10 @@ def get_datasets_for_group(group_name, species_name=None):
return return_error(code=204, source=request.url_rule.rule, title="No Results", details="")
-@app.route("/api/v_{}/dataset/<path:dataset_name>".format(version))
-@app.route("/api/v_{}/dataset/<path:dataset_name>.<path:file_format>".format(version))
-@app.route("/api/v_{}/dataset/<path:group_name>/<path:dataset_name>".format(version))
-@app.route("/api/v_{}/dataset/<path:group_name>/<path:dataset_name>.<path:file_format>".format(version))
+@pre1_router.route("/v_{}/dataset/<path:dataset_name>".format(version))
+@pre1_router.route("/v_{}/dataset/<path:dataset_name>.<path:file_format>".format(version))
+@pre1_router.route("/v_{}/dataset/<path:group_name>/<path:dataset_name>".format(version))
+@pre1_router.route("/v_{}/dataset/<path:group_name>/<path:dataset_name>.<path:file_format>".format(version))
def get_dataset_info(dataset_name, group_name=None, file_format="json"):
# ZS: First get ProbeSet (mRNA expression) datasets and then get Phenotype datasets
@@ -343,8 +340,8 @@ def get_dataset_info(dataset_name, group_name=None, file_format="json"):
return return_error(code=204, source=request.url_rule.rule, title="No Results", details="")
-@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",))
+@pre1_router.route("/v_{}/traits/<path:dataset_name>".format(version), methods=("GET",))
+@pre1_router.route("/v_{}/traits/<path:dataset_name>.<path:file_format>".format(version), methods=("GET",))
def fetch_traits(dataset_name, file_format="json"):
trait_ids, trait_names, data_type, dataset_id = get_dataset_trait_ids(
dataset_name, request.args)
@@ -492,8 +489,8 @@ def fetch_traits(dataset_name, file_format="json"):
details="")
-@app.route("/api/v_{}/sample_data/<path:dataset_name>".format(version))
-@app.route("/api/v_{}/sample_data/<path:dataset_name>.<path:file_format>".format(version))
+@pre1_router.route("/v_{}/sample_data/<path:dataset_name>".format(version))
+@pre1_router.route("/v_{}/sample_data/<path:dataset_name>.<path:file_format>".format(version))
def all_sample_data(dataset_name, file_format="csv"):
trait_ids, trait_names, data_type, dataset_id = get_dataset_trait_ids(
dataset_name, request.args)
@@ -601,8 +598,8 @@ def all_sample_data(dataset_name, file_format="csv"):
return return_error(code=204, source=request.url_rule.rule, title="No Results", details="")
-@app.route("/api/v_{}/sample_data/<path:dataset_name>/<path:trait_name>".format(version))
-@app.route("/api/v_{}/sample_data/<path:dataset_name>/<path:trait_name>.<path:file_format>".format(version))
+@pre1_router.route("/v_{}/sample_data/<path:dataset_name>/<path:trait_name>".format(version))
+@pre1_router.route("/v_{}/sample_data/<path:dataset_name>/<path:trait_name>.<path:file_format>".format(version))
def trait_sample_data(dataset_name, trait_name, file_format="json"):
with database_connection() as conn, conn.cursor() as cursor:
cursor.execute(
@@ -688,10 +685,10 @@ def trait_sample_data(dataset_name, trait_name, file_format="json"):
return return_error(code=204, source=request.url_rule.rule, title="No Results", details="")
-@app.route("/api/v_{}/trait/<path:dataset_name>/<path:trait_name>".format(version))
-@app.route("/api/v_{}/trait/<path:dataset_name>/<path:trait_name>.<path:file_format>".format(version))
-@app.route("/api/v_{}/trait_info/<path:dataset_name>/<path:trait_name>".format(version))
-@app.route("/api/v_{}/trait_info/<path:dataset_name>/<path:trait_name>.<path:file_format>".format(version))
+@pre1_router.route("/v_{}/trait/<path:dataset_name>/<path:trait_name>".format(version))
+@pre1_router.route("/v_{}/trait/<path:dataset_name>/<path:trait_name>.<path:file_format>".format(version))
+@pre1_router.route("/v_{}/trait_info/<path:dataset_name>/<path:trait_name>".format(version))
+@pre1_router.route("/v_{}/trait_info/<path:dataset_name>/<path:trait_name>.<path:file_format>".format(version))
def get_trait_info(dataset_name, trait_name, file_format="json"):
with database_connection() as conn, conn.cursor() as cursor:
cursor.execute(
@@ -753,7 +750,7 @@ def get_trait_info(dataset_name, trait_name, file_format="json"):
return return_error(code=204, source=request.url_rule.rule, title="No Results", details="")
-@app.route("/api/v_{}/correlation".format(version), methods=("GET",))
+@pre1_router.route("/v_{}/correlation".format(version), methods=("GET",))
def get_corr_results():
results = correlation.do_correlation(request.args)
@@ -764,7 +761,7 @@ def get_corr_results():
return return_error(code=204, source=request.url_rule.rule, title="No Results", details="")
-@app.route("/api/v_{}/mapping".format(version), methods=("GET",))
+@pre1_router.route("/v_{}/mapping".format(version), methods=("GET",))
def get_mapping_results():
results, format = mapping.do_mapping_for_api(request.args)
@@ -788,18 +785,18 @@ def get_mapping_results():
return return_error(code=204, source=request.url_rule.rule, title="No Results", details="")
-@app.route("/api/v_{}/genotypes/view/<string:group_name>".format(version))
+@pre1_router.route("/v_{}/genotypes/view/<string:group_name>".format(version))
def view_genotype_files(group_name):
- if os.path.isfile("{0}/{1}.json".format(flat_files("genotype"), group_name)):
- with open("{0}/{1}.json".format(flat_files("genotype"), group_name)) as geno_json:
+ if os.path.isfile("{0}/{1}.json".format(flat_files(app, "genotype"), group_name)):
+ with open("{0}/{1}.json".format(flat_files(app, "genotype"), group_name)) as geno_json:
return flask.jsonify(json.load(geno_json))
-@app.route("/api/v_{}/genotypes/<string:file_format>/<string:group_name>/<string:dataset_name>.zip".format(version))
-@app.route("/api/v_{}/genotypes/<string:file_format>/<string:group_name>/<string:dataset_name>".format(version))
-@app.route("/api/v_{}/genotypes/<string:file_format>/<string:group_name>.zip".format(version))
-@app.route("/api/v_{}/genotypes/<string:file_format>/<string:group_name>".format(version))
-@app.route("/api/v_{}/genotypes/<string:group_name>.<string:file_format>".format(version))
+@pre1_router.route("/v_{}/genotypes/<string:file_format>/<string:group_name>/<string:dataset_name>.zip".format(version))
+@pre1_router.route("/v_{}/genotypes/<string:file_format>/<string:group_name>/<string:dataset_name>".format(version))
+@pre1_router.route("/v_{}/genotypes/<string:file_format>/<string:group_name>.zip".format(version))
+@pre1_router.route("/v_{}/genotypes/<string:file_format>/<string:group_name>".format(version))
+@pre1_router.route("/v_{}/genotypes/<string:group_name>.<string:file_format>".format(version))
def get_genotypes(group_name, file_format="csv", dataset_name=None):
limit_num = None
if 'limit_to' in request.args:
@@ -810,9 +807,9 @@ def get_genotypes(group_name, file_format="csv", dataset_name=None):
if file_format == "csv" or file_format == "geno":
filename = group_name + ".geno"
- if os.path.isfile("{0}/{1}.geno".format(flat_files("genotype"), group_name)):
+ if os.path.isfile("{0}/{1}.geno".format(flat_files(app, "genotype"), group_name)):
output_lines = []
- with open("{0}/{1}.geno".format(flat_files("genotype"), group_name)) as genofile:
+ with open("{0}/{1}.geno".format(flat_files(app, "genotype"), group_name)) as genofile:
i = 0
for line in genofile:
if line[0] == "#" or line[0] == "@":
@@ -834,18 +831,18 @@ def get_genotypes(group_name, file_format="csv", dataset_name=None):
else:
filename = group_name
- if os.path.isfile("{0}/{1}_geno.csv".format(flat_files("genotype/rqtl2"), group_name)):
+ if os.path.isfile("{0}/{1}_geno.csv".format(flat_files(app, "genotype/rqtl2"), group_name)):
yaml_file = json.load(
- open("{0}/{1}.json".format(flat_files("genotype/rqtl2"), group_name)))
+ open("{0}/{1}.json".format(flat_files(app, "genotype/rqtl2"), group_name)))
yaml_file["geno"] = filename + "_geno.csv"
yaml_file["gmap"] = filename + "_gmap.csv"
yaml_file["pheno"] = filename + "_pheno.csv"
config_file = [filename + ".json", json.dumps(yaml_file)]
- #config_file = [filename + ".yaml", open("{0}/{1}.yaml".format(flat_files("genotype/rqtl2"), group_name))]
+ #config_file = [filename + ".yaml", open("{0}/{1}.yaml".format(flat_files(app, "genotype/rqtl2"), group_name))]
geno_file = [filename + "_geno.csv",
- open("{0}/{1}_geno.csv".format(flat_files("genotype/rqtl2"), group_name))]
+ open("{0}/{1}_geno.csv".format(flat_files(app, "genotype/rqtl2"), group_name))]
gmap_file = [filename + "_gmap.csv",
- open("{0}/{1}_gmap.csv".format(flat_files("genotype/rqtl2"), group_name))]
+ open("{0}/{1}_gmap.csv".format(flat_files(app, "genotype/rqtl2"), group_name))]
if dataset_name:
phenotypes = requests.get(
"http://gn2.genenetwork.org/api/v_pre1/sample_data/" + dataset_name)
@@ -867,9 +864,9 @@ def get_genotypes(group_name, file_format="csv", dataset_name=None):
else:
filename = group_name + ".bimbam"
- if os.path.isfile("{0}/{1}.geno".format(flat_files("genotype"), group_name)):
+ if os.path.isfile("{0}/{1}.geno".format(flat_files(app, "genotype"), group_name)):
output_lines = []
- with open("{0}/{1}_geno.txt".format(flat_files("genotype/bimbam"), group_name)) as genofile:
+ with open("{0}/{1}_geno.txt".format(flat_files(app, "genotype/bimbam"), group_name)) as genofile:
i = 0
for line in genofile:
if limit_num and i >= limit_num:
@@ -890,7 +887,7 @@ def get_genotypes(group_name, file_format="csv", dataset_name=None):
return output
-@app.route("/api/v_{}/gen_dropdown".format(version), methods=("GET",))
+@pre1_router.route("/v_{}/gen_dropdown".format(version), methods=("GET",))
def gen_dropdown_menu():
with database_connection() as conn:
results = gen_menu.gen_dropdown_json(conn)
diff --git a/wqflask/wqflask/marker_regression/gemma_mapping.py b/wqflask/wqflask/marker_regression/gemma_mapping.py
index 4420796c..d6e75b86 100644
--- a/wqflask/wqflask/marker_regression/gemma_mapping.py
+++ b/wqflask/wqflask/marker_regression/gemma_mapping.py
@@ -4,22 +4,23 @@ import string
import random
import json
+from flask import current_app as app
+
+from gn3.computations.gemma import generate_hash_of_string
+
from base import webqtlConfig
from base.trait import create_trait
from base.data_set import create_dataset
from utility.redis_tools import get_redis_conn
-from utility.tools import flat_files, assert_file
-from utility.tools import GEMMA_WRAPPER_COMMAND
-from utility.tools import TEMPDIR
-from utility.tools import WEBSERVER_MODE
+from utility.configuration import flat_files, assert_file, get_setting
from wqflask.database import database_connection
-from gn3.computations.gemma import generate_hash_of_string
-
-GEMMAOPTS = "-debug"
-if WEBSERVER_MODE == 'PROD':
- GEMMAOPTS = "-no-check"
+def gemma_options():
+ GEMMAOPTS = "-debug"
+ if get_setting(app, "WEBSERVER_MODE") == 'PROD':
+ GEMMAOPTS = "-no-check"
+ return GEMMAOPTS
def generate_random_n_string(n):
return ''.join(random.choice(string.ascii_uppercase + string.digits)
@@ -59,66 +60,66 @@ def run_gemma(this_trait, this_dataset, samples, vals, covariates, use_loco,
if covariates != "":
covar_filename = gen_covariates_file(this_dataset, covariates, samples)
if str(use_loco).lower() == "true":
- bimbam_dir = flat_files('genotype/bimbam')
+ bimbam_dir = flat_files(app, 'genotype/bimbam')
geno_filepath = assert_file(
f"{bimbam_dir}/{genofile_name}_geno.txt")
- pheno_filepath = f"{TEMPDIR}/gn2/{pheno_filename}.txt"
+ pheno_filepath = f"{get_setting(app, 'TEMPDIR')}/gn2/{pheno_filename}.txt"
snps_filepath = assert_file(
f"{bimbam_dir}/{genofile_name}_snps.txt")
- k_json_output_filepath = f"{TEMPDIR}/gn2/{k_output_filename}.json"
- generate_k_command = (f"{GEMMA_WRAPPER_COMMAND} --json --loco "
- f"{chr_list_string} -- {GEMMAOPTS} "
+ k_json_output_filepath = f"{get_setting(app, 'TEMPDIR')}/gn2/{k_output_filename}.json"
+ generate_k_command = (f"{get_setting(app, 'GEMMA_WRAPPER_COMMAND')} --json --loco "
+ f"{chr_list_string} -- {gemma_options()} "
f"-g {geno_filepath} -p "
f"{pheno_filepath} -a "
f"{snps_filepath} -gk > "
f"{k_json_output_filepath}")
os.system(generate_k_command)
- gemma_command = (f"{GEMMA_WRAPPER_COMMAND} --json --loco "
+ gemma_command = (f"{get_setting(app, 'GEMMA_WRAPPER_COMMAND')} --json --loco "
f"--input {k_json_output_filepath} "
- f"-- {GEMMAOPTS} "
+ f"-- {gemma_options()} "
f"-g {geno_filepath} "
f"-p {pheno_filepath} ")
if covariates != "":
- gemma_command += (f"-c {flat_files('mapping')}/"
+ gemma_command += (f"-c {flat_files(app, 'mapping')}/"
f"{covar_filename}.txt "
- f"-a {flat_files('genotype/bimbam')}/"
+ f"-a {flat_files(app, 'genotype/bimbam')}/"
f"{genofile_name}_snps.txt "
- f"-lmm 9 -maf {maf} > {TEMPDIR}/gn2/"
+ f"-lmm 9 -maf {maf} > {get_setting(app, 'TEMPDIR')}/gn2/"
f"{gwa_output_filename}.json")
else:
- gemma_command += (f"-a {flat_files('genotype/bimbam')}/"
+ gemma_command += (f"-a {flat_files(app, 'genotype/bimbam')}/"
f"{genofile_name}_snps.txt -lmm 9 -maf "
f"{maf} > "
- f"{TEMPDIR}/gn2/{gwa_output_filename}.json")
+ f"{get_setting(app, 'TEMPDIR')}/gn2/{gwa_output_filename}.json")
else:
- generate_k_command = (f"{GEMMA_WRAPPER_COMMAND} --json -- "
- f"{GEMMAOPTS} "
- f" -g {flat_files('genotype/bimbam')}/"
+ generate_k_command = (f"{get_setting(app, 'GEMMA_WRAPPER_COMMAND')} --json -- "
+ f"{gemma_options()} "
+ f" -g {flat_files(app, 'genotype/bimbam')}/"
f"{genofile_name}_geno.txt -p "
- f"{TEMPDIR}/gn2/{pheno_filename}.txt -a "
- f"{flat_files('genotype/bimbam')}/"
+ f"{get_setting(app, 'TEMPDIR')}/gn2/{pheno_filename}.txt -a "
+ f"{flat_files(app, 'genotype/bimbam')}/"
f"{genofile_name}_snps.txt -gk > "
- f"{TEMPDIR}/gn2/{k_output_filename}.json")
+ f"{get_setting(app, 'TEMPDIR')}/gn2/{k_output_filename}.json")
os.system(generate_k_command)
- gemma_command = (f"{GEMMA_WRAPPER_COMMAND} --json --input "
- f"{TEMPDIR}/gn2/{k_output_filename}.json -- "
- f"{GEMMAOPTS} "
- f"-a {flat_files('genotype/bimbam')}/"
+ gemma_command = (f"{get_setting(app, 'GEMMA_WRAPPER_COMMAND')} --json --input "
+ f"{get_setting(app, 'TEMPDIR')}/gn2/{k_output_filename}.json -- "
+ f"{gemma_options()} "
+ f"-a {flat_files(app, 'genotype/bimbam')}/"
f"{genofile_name}_snps.txt "
- f"-lmm 9 -g {flat_files('genotype/bimbam')}/"
+ f"-lmm 9 -g {flat_files(app, 'genotype/bimbam')}/"
f"{genofile_name}_geno.txt -p "
- f"{TEMPDIR}/gn2/{pheno_filename}.txt ")
+ f"{get_setting(app, 'TEMPDIR')}/gn2/{pheno_filename}.txt ")
if covariates != "":
- gemma_command += (f" -c {flat_files('mapping')}/"
+ gemma_command += (f" -c {flat_files(app, 'mapping')}/"
f"{covar_filename}.txt > "
- f"{TEMPDIR}/gn2/{gwa_output_filename}.json")
+ f"{get_setting(app, 'TEMPDIR')}/gn2/{gwa_output_filename}.json")
else:
- gemma_command += f" > {TEMPDIR}/gn2/{gwa_output_filename}.json"
+ gemma_command += f" > {get_setting(app, 'TEMPDIR')}/gn2/{gwa_output_filename}.json"
os.system(gemma_command)
else:
@@ -138,7 +139,7 @@ def gen_pheno_txt_file(this_dataset, genofile_name, vals):
filename = "PHENO_" + generate_hash_of_string(this_dataset.name + str(vals)).replace("/", "_")
- with open(f"{TEMPDIR}/gn2/{filename}.txt", "w") as outfile:
+ with open(f"{get_setting(app, 'TEMPDIR')}/gn2/{filename}.txt", "w") as outfile:
for value in vals:
if value == "x":
outfile.write("NA\n")
@@ -178,7 +179,7 @@ def gen_covariates_file(this_dataset, covariates, samples):
filename = "COVAR_" + generate_hash_of_string(this_dataset.name + str(covariate_data_object)).replace("/", "_")
- with open((f"{flat_files('mapping')}/"
+ with open((f"{flat_files(app, 'mapping')}/"
f"{filename}.txt"),
"w") as outfile:
for i in range(len(covariate_data_object[0])):
@@ -191,7 +192,7 @@ def gen_covariates_file(this_dataset, covariates, samples):
def parse_loco_output(this_dataset, gwa_output_filename, loco="True"):
- output_filename = f"{TEMPDIR}/gn2/{gwa_output_filename}.json"
+ output_filename = f"{get_setting(app, 'TEMPDIR')}/gn2/{gwa_output_filename}.json"
if os.stat(output_filename).st_size == 0:
return {}
diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py
index ae5e1ebb..3ae7d1b9 100644
--- a/wqflask/wqflask/show_trait/show_trait.py
+++ b/wqflask/wqflask/show_trait/show_trait.py
@@ -10,6 +10,7 @@ from collections import OrderedDict
import numpy as np
import scipy.stats as ss
+from flask import current_app as app
from wqflask.database import database_connection
@@ -18,8 +19,7 @@ from wqflask.show_trait.SampleList import SampleList
from base.trait import create_trait
from base import data_set
from utility import helper_functions
-from utility.tools import locate_ignore_error
-from utility.tools import GN_PROXY_URL
+from utility.configuration import locate_ignore_error
from utility.redis_tools import get_redis_conn, get_resource_id
from gn3.authentication import get_highest_user_access_role
@@ -753,7 +753,7 @@ def get_genotype_scales(genofiles):
def get_scales_from_genofile(file_location):
- geno_path = locate_ignore_error(file_location, 'genotype')
+ geno_path = locate_ignore_error(app, file_location, 'genotype')
# ZS: This is just to allow the code to run when
if not geno_path:
return [["physic", "Mb"]]
diff --git a/wqflask/wqflask/top_level_routes.py b/wqflask/wqflask/top_level_routes.py
index 73a91dfc..680736ec 100644
--- a/wqflask/wqflask/top_level_routes.py
+++ b/wqflask/wqflask/top_level_routes.py
@@ -1,6 +1,7 @@
"""Top-Level routes."""
from flask import Blueprint
+from .api import api_bp
# from .views import main_views
from base.trait import trait_bp
from .collect import collections_bp
@@ -14,3 +15,5 @@ toplevel.register_blueprint(trait_bp)
toplevel.register_blueprint(pcorrs_bp)
# toplevel.register_blueprint(main_views)
toplevel.register_blueprint(collections_bp)
+
+toplevel.register_blueprint(api_bp, url_prefix="/api")