From 8f3b998db0698298f828698e93e1f8f19a9c23d7 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 20 Jun 2023 08:11:04 +0300 Subject: Restore configuration variables' names The names had been changed when refactoring the code but can now be restored. --- wqflask/base/data_set/datasetgroup.py | 2 +- wqflask/base/data_set/utils.py | 4 +-- wqflask/base/webqtlConfig.py | 35 +++++++++++----------- wqflask/wqflask/correlation/pre_computes.py | 2 +- .../wqflask/correlation_matrix/show_corr_matrix.py | 2 +- .../marker_regression/display_mapping_results.py | 4 +-- wqflask/wqflask/marker_regression/rqtl_mapping.py | 4 +-- wqflask/wqflask/marker_regression/run_mapping.py | 2 +- wqflask/wqflask/views.py | 4 +-- 9 files changed, 29 insertions(+), 30 deletions(-) diff --git a/wqflask/base/data_set/datasetgroup.py b/wqflask/base/data_set/datasetgroup.py index a44cf18d..7c3301fe 100644 --- a/wqflask/base/data_set/datasetgroup.py +++ b/wqflask/base/data_set/datasetgroup.py @@ -129,7 +129,7 @@ class DatasetGroup: return study_samples def get_genofiles(self): - jsonfile = "%s/%s.json" % (get_setting(app, "WEBQTL_GENODIR"), self.name) + jsonfile = "%s/%s.json" % (get_setting(app, "GENODIR"), self.name) try: f = open(jsonfile) except: diff --git a/wqflask/base/data_set/utils.py b/wqflask/base/data_set/utils.py index 11391d69..7f55989f 100644 --- a/wqflask/base/data_set/utils.py +++ b/wqflask/base/data_set/utils.py @@ -57,7 +57,7 @@ def cache_dataset_results(dataset_name: str, dataset_type: str, samplelist: List samplelist_as_str = ",".join(samplelist) file_name = generate_hash_file(dataset_name, dataset_type, table_timestamp, samplelist_as_str) - file_path = os.path.join(app.config["WEBQTL_TMPDIR"], f"{file_name}.json") + file_path = os.path.join(app.config["TMPDIR"], f"{file_name}.json") with open(file_path, "w") as file_handler: json.dump(query_results, file_handler) @@ -70,7 +70,7 @@ def fetch_cached_results(dataset_name: str, dataset_type: str, samplelist: List) samplelist_as_str = ",".join(samplelist) file_name = generate_hash_file(dataset_name, dataset_type, table_timestamp, samplelist_as_str) - file_path = os.path.join(app.config["WEBQTL_TMPDIR"], f"{file_name}.json") + file_path = os.path.join(app.config["TMPDIR"], f"{file_name}.json") try: with open(file_path, "r") as file_handler: diff --git a/wqflask/base/webqtlConfig.py b/wqflask/base/webqtlConfig.py index 600c6800..a5797f60 100644 --- a/wqflask/base/webqtlConfig.py +++ b/wqflask/base/webqtlConfig.py @@ -91,34 +91,33 @@ def init_app(app): TEMPDIR = app.config["TEMPDIR"] mkdir_with_temp_dir = lambda child: mkdir_with_assert_writable( TEMPDIR, child) - WEBQTL_TMPDIR = mkdir_with_temp_dir("/gn2/") - app.config["WEBQTL_TMPDIR"] = WEBQTL_TMPDIR - app.config["TMPDIR"] = WEBQTL_TMPDIR - app.config["WEBQTL_CACHEDIR"] = mkdir_with_temp_dir( - f"{WEBQTL_TMPDIR}cache/") + TMPDIR = mkdir_with_temp_dir("/gn2/") + app.config["TMPDIR"] = TMPDIR + app.config["CACHEDIR"] = mkdir_with_temp_dir( + f"{TMPDIR}cache/") # We can no longer write into the git tree: - app.config["WEBQTL_GENERATED_IMAGE_DIR"] = mkdir_with_temp_dir( - f"{WEBQTL_TMPDIR}generated/") - app.config["WEBQTL_GENERATED_TEXT_DIR"] = mkdir_with_temp_dir( - f"{WEBQTL_TMPDIR}generated_text/") + app.config["GENERATED_IMAGE_DIR"] = mkdir_with_temp_dir( + f"{TMPDIR}generated/") + app.config["GENERATED_TEXT_DIR"] = mkdir_with_temp_dir( + f"{TMPDIR}generated_text/") # Flat file directories - app.config["WEBQTL_GENODIR"] = flat_files(app, 'genotype/') + app.config["GENODIR"] = flat_files(app, 'genotype/') # JSON genotypes are OBSOLETE - WEBQTL_JSON_GENODIR = flat_files(app, 'genotype/json/') - if not valid_path(WEBQTL_JSON_GENODIR): + JSON_GENODIR = flat_files(app, 'genotype/json/') + if not valid_path(JSON_GENODIR): # fall back on old location (move the dir, FIXME) - WEBQTL_JSON_GENODIR = flat_files('json') - app.config["WEBQTL_JSON_GENODIR"] = WEBQTL_JSON_GENODIR + JSON_GENODIR = flat_files('json') + app.config["JSON_GENODIR"] = JSON_GENODIR - app.config["WEBQTL_TEXTDIR"] = os.path.join( + app.config["TEXTDIR"] = os.path.join( app.config.get("GNSHARE", "/gnshare/gn/"), "web/ProbeSetFreeze_DataMatrix") # Are we using the following...? - app.config["WEBQTL_PORTADDR"] = "http://50.16.251.170" - app.config["WEBQTL_INFOPAGEHREF"] = '/dbdoc/%s.html' - app.config["WEBQTL_CGIDIR"] = '/webqtl/' # XZ: The variable name 'CGIDIR' should be changed to 'PYTHONDIR' + app.config["PORTADDR"] = "http://50.16.251.170" + app.config["INFOPAGEHREF"] = '/dbdoc/%s.html' + app.config["CGIDIR"] = '/webqtl/' # XZ: The variable name 'CGIDIR' should be changed to 'PYTHONDIR' return app diff --git a/wqflask/wqflask/correlation/pre_computes.py b/wqflask/wqflask/correlation/pre_computes.py index 308614f0..c08b2d28 100644 --- a/wqflask/wqflask/correlation/pre_computes.py +++ b/wqflask/wqflask/correlation/pre_computes.py @@ -102,7 +102,7 @@ def fetch_text_file(dataset_name, conn, text_dir=None): # checks first for recently generated textfiles if not use gn1 datamatrix return __file_scanner__(text_dir, results[0]) or __file_scanner__( - get_setting(app, "WEBQTL_TEXTDIR"), results[0]) + get_setting(app, "TEXTDIR"), results[0]) except Exception: pass diff --git a/wqflask/wqflask/correlation_matrix/show_corr_matrix.py b/wqflask/wqflask/correlation_matrix/show_corr_matrix.py index 5848a756..2440b05d 100644 --- a/wqflask/wqflask/correlation_matrix/show_corr_matrix.py +++ b/wqflask/wqflask/correlation_matrix/show_corr_matrix.py @@ -225,7 +225,7 @@ def export_corr_matrix(corr_results): ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6)) matrix_export_path = "{}{}.csv".format( - get_setting(app, "WEBQTL_GENERATED_TEXT_DIR"), corr_matrix_filename) + get_setting(app, "GENERATED_TEXT_DIR"), corr_matrix_filename) with open(matrix_export_path, "w+") as output_file: output_file.write( "Time/Date: " + datetime.datetime.now().strftime("%x / %X") + "\n") diff --git a/wqflask/wqflask/marker_regression/display_mapping_results.py b/wqflask/wqflask/marker_regression/display_mapping_results.py index c544190a..48ccd93c 100644 --- a/wqflask/wqflask/marker_regression/display_mapping_results.py +++ b/wqflask/wqflask/marker_regression/display_mapping_results.py @@ -608,7 +608,7 @@ class DisplayMappingResults: self.filename = webqtlUtil.genRandStr("Itvl_") intCanvas.save( "{}.png".format( - os.path.join(get_setting(app, "WEBQTL_GENERATED_IMAGE_DIR"), self.filename)), + os.path.join(get_setting(app, "GENERATED_IMAGE_DIR"), self.filename)), format='png') intImg = HtmlGenWrapper.create_image_tag( src="/image/{}.png".format(self.filename), @@ -623,7 +623,7 @@ class DisplayMappingResults: intCanvasX2, startMb=self.startMb, endMb=self.endMb, showLocusForm=showLocusForm, zoom=2) intCanvasX2.save( "{}.png".format( - os.path.join(get_setting(app, "WEBQTL_GENERATED_IMAGE_DIR"), + os.path.join(get_setting(app, "GENERATED_IMAGE_DIR"), self.filename + "X2")), format='png') diff --git a/wqflask/wqflask/marker_regression/rqtl_mapping.py b/wqflask/wqflask/marker_regression/rqtl_mapping.py index bd3fdbc8..7d617f06 100644 --- a/wqflask/wqflask/marker_regression/rqtl_mapping.py +++ b/wqflask/wqflask/marker_regression/rqtl_mapping.py @@ -90,7 +90,7 @@ def write_covarstruct_file(cofactors: str) -> str: writer.writerow([cofactor_name, datatype]) hash_of_file = get_hash_of_textio(covar_struct_file) - file_path = get_setting(app, "WEBQTL_TMPDIR") + hash_of_file + ".csv" + file_path = get_setting(app, "TMPDIR") + hash_of_file + ".csv" with open(file_path, "w") as fd: covar_struct_file.seek(0) @@ -133,7 +133,7 @@ def write_phenotype_file(trait_name: str, writer.writerow(this_row) hash_of_file = get_hash_of_textio(pheno_file) - file_path = get_setting(app, "WEBQTL_TMPDIR") + hash_of_file + ".csv" + file_path = get_setting(app, "TMPDIR") + hash_of_file + ".csv" with open(file_path, "w") as fd: pheno_file.seek(0) diff --git a/wqflask/wqflask/marker_regression/run_mapping.py b/wqflask/wqflask/marker_regression/run_mapping.py index a478f875..f7ab8ddc 100644 --- a/wqflask/wqflask/marker_regression/run_mapping.py +++ b/wqflask/wqflask/marker_regression/run_mapping.py @@ -465,7 +465,7 @@ class RunMapping: self.this_trait, self.dataset, self.vals, pheno_filename=output_filename) rqtl_command = './plink --noweb --ped %s.ped --no-fid --no-parents --no-sex --no-pheno --map %s.map --pheno %s/%s.txt --pheno-name %s --maf %s --missing-phenotype -9999 --out %s%s --assoc ' % ( - self.dataset.group.name, self.dataset.group.name, get_setting(app, "WEBQTL_TMPDIR"), plink_output_filename, self.this_trait.name, self.maf, get_setting(app, "WEBQTL_TMPDIR"), plink_output_filename) + self.dataset.group.name, self.dataset.group.name, get_setting(app, "TMPDIR"), plink_output_filename, self.this_trait.name, self.maf, get_setting(app, "TMPDIR"), plink_output_filename) os.system(rqtl_command) diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index de2e803a..c7f741c2 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -118,7 +118,7 @@ def index_page(): @app.route("/tmp/") def tmp_page(img_path): initial_start_vars = request.form - imgfile = open(get_setting(app, "WEBQTL_GENERATED_IMAGE_DIR") + img_path, 'rb') + imgfile = open(get_setting(app, "GENERATED_IMAGE_DIR") + img_path, 'rb') imgdata = imgfile.read() imgB64 = base64.b64encode(imgdata) bytesarray = array.array('B', imgB64) @@ -229,7 +229,7 @@ def docedit(): @app.route('/generated/') def generated_file(filename): - return send_from_directory(get_setting(app, "WEBQTL_GENERATED_IMAGE_DIR"), filename) + return send_from_directory(get_setting(app, "GENERATED_IMAGE_DIR"), filename) @app.route("/help") -- cgit v1.2.3