From 7932f962aff0ac35dd53b84e483f405de81c0612 Mon Sep 17 00:00:00 2001 From: zsloan Date: Thu, 5 Nov 2020 15:07:58 -0600 Subject: Imported Scroller and used it with correlation page table --- wqflask/wqflask/templates/correlation_page.html | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/wqflask/wqflask/templates/correlation_page.html b/wqflask/wqflask/templates/correlation_page.html index bc0b592c..06499ec6 100644 --- a/wqflask/wqflask/templates/correlation_page.html +++ b/wqflask/wqflask/templates/correlation_page.html @@ -215,6 +215,7 @@ + + @@ -331,10 +333,10 @@ 'orderSequence': [ "desc", "asc"] }, { - 'title': "High P ?", + 'title': "High P ", 'type': "natural-minus-na", 'data': "lrs_score", - 'width': "60px", + 'width': "65px", 'orderSequence': [ "desc", "asc"] }, { @@ -344,10 +346,10 @@ 'data': "lrs_location" }, { - 'title': "Effect Size ?", + 'title': "Effect Size ", 'type': "natural-minus-na", 'data': "additive", - 'width': "85px", + 'width': "90px", 'orderSequence': [ "desc", "asc"] }{% elif dataset.type == 'Publish' %}, { @@ -400,7 +402,7 @@ 'orderSequence': [ "desc", "asc"] }, { - 'title': "High P ?", + 'title': "High P ", 'type': "natural-minus-na", 'data': "lrs_score", 'width': "80px", @@ -413,7 +415,7 @@ 'data': "lrs_location" }, { - 'title': "Effect Size ?", + 'title': "Effect Size ", 'type': "natural-minus-na", 'width': "120px", 'data': "additive", -- cgit v1.2.3 From db0e80bef73eb163bfb747ec4d137d5c5069ade8 Mon Sep 17 00:00:00 2001 From: zsloan Date: Fri, 13 Nov 2020 13:40:40 -0600 Subject: Added cdn imports for fontawesome to correlation page and changed superscript i's to fontawesome icons for the glossary links in column headers --- wqflask/wqflask/templates/correlation_page.html | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/wqflask/wqflask/templates/correlation_page.html b/wqflask/wqflask/templates/correlation_page.html index bb7d3df6..6ea86609 100644 --- a/wqflask/wqflask/templates/correlation_page.html +++ b/wqflask/wqflask/templates/correlation_page.html @@ -4,6 +4,7 @@ + {% endblock %} {% block content %} @@ -145,7 +146,8 @@ - + + -- cgit v1.2.3 From 76d5b24b3d2e0b5e6be5b1cf4c125a9a812ff57a Mon Sep 17 00:00:00 2001 From: zsloan Date: Fri, 13 Nov 2020 15:25:32 -0600 Subject: Switched to using boolean casting to check if various trait attributes exist --- wqflask/wqflask/correlation/show_corr_results.py | 59 ++++++++++++------------ 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/wqflask/wqflask/correlation/show_corr_results.py b/wqflask/wqflask/correlation/show_corr_results.py index 17d3de54..87dd7597 100644 --- a/wqflask/wqflask/correlation/show_corr_results.py +++ b/wqflask/wqflask/correlation/show_corr_results.py @@ -494,61 +494,60 @@ def generate_corr_json(corr_results, this_trait, dataset, target_dataset, for_ap results_dict['mean'] = "N/A" results_dict['lrs_score'] = "N/A" results_dict['additive'] = "N/A" - if trait.description_display: + if bool(trait.description_display): results_dict['description'] = trait.description_display - if trait.mean and trait.mean != "": + if bool(trait.mean): results_dict['mean'] = float(trait.mean) if trait.LRS_score_repr != "N/A": results_dict['lrs_score'] = "%.1f" % float(trait.LRS_score_repr) results_dict['lrs_location'] = trait.LRS_location_repr - if trait.additive and trait.additive != "": + if bool(trait.additive): results_dict['additive'] = "%0.3f" % float(trait.additive) results_dict['sample_r'] = "%0.3f" % float(trait.sample_r) results_dict['num_overlap'] = trait.num_overlap results_dict['sample_p'] = "%0.3e" % float(trait.sample_p) - if trait.lit_corr == "" or trait.lit_corr == 0: - results_dict['lit_corr'] = "--" - else: + results_dict['lit_corr'] = "--" + results_dict['tissue_corr'] = "--" + results_dict['tissue_pvalue'] = "--" + if bool(trait.lit_corr): results_dict['lit_corr'] = "%0.3f" % float(trait.lit_corr) - if trait.tissue_corr == "" or trait.tissue_corr == 0: - results_dict['tissue_corr'] = "--" - results_dict['tissue_pvalue'] = "--" - else: + if bool(trait.tissue_corr): results_dict['tissue_corr'] = "%0.3f" % float(trait.tissue_corr) results_dict['tissue_pvalue'] = "%0.3e" % float(trait.tissue_pvalue) elif target_dataset.type == "Publish": results_dict['abbreviation_display'] = "N/A" - if trait.abbreviation: - results_dict['abbreviation_display'] = trait.abbreviation results_dict['description'] = "N/A" - if trait.description_display: - results_dict['description'] = trait.description_display - results_dict['authors'] = trait.authors - authors_list = trait.authors.split(',') - if len(authors_list) > 6: - results_dict['authors_display'] = ", ".join(authors_list[:6]) + ", et al." + results_dict['authors_display'] = "N/A" + results_dict['additive'] = "N/A" + if for_api: + results_dict['pubmed_id'] = "N/A" + results_dict['year'] = "N/A" else: - results_dict['authors_display'] = trait.authors - if trait.pubmed_id: + results_dict['pubmed_link'] = "N/A" + results_dict['pubmed_text'] = "N/A" + + if bool(trait.abbreviation): + results_dict['abbreviation_display'] = trait.abbreviation + if bool(trait.description_display): + results_dict['description'] = trait.description_display + if bool(trait.authors): + authors_list = trait.authors.split(',') + if len(authors_list) > 6: + results_dict['authors_display'] = ", ".join(authors_list[:6]) + ", et al." + else: + results_dict['authors_display'] = trait.authors + if bool(trait.pubmed_id): if for_api: results_dict['pubmed_id'] = trait.pubmed_id results_dict['year'] = trait.pubmed_text else: results_dict['pubmed_link'] = trait.pubmed_link results_dict['pubmed_text'] = trait.pubmed_text - else: - if for_api: - results_dict['pubmed_id'] = "N/A" - results_dict['year'] = "N/A" - else: - results_dict['pubmed_link'] = "N/A" - results_dict['pubmed_text'] = "N/A" + results_dict['lrs_score'] = trait.LRS_score_repr results_dict['lrs_location'] = trait.LRS_location_repr - if trait.additive and trait.additive != "": + if bool(trait.additive): results_dict['additive'] = "%0.3f" % float(trait.additive) - else: - results_dict['additive'] = "N/A" results_dict['sample_r'] = "%0.3f" % trait.sample_r results_dict['num_overlap'] = trait.num_overlap results_dict['sample_p'] = "%0.3e" % float(trait.sample_p) -- cgit v1.2.3 From 678d9cd4e073c3936c34d3b9b54f1e6c590def27 Mon Sep 17 00:00:00 2001 From: zsloan Date: Fri, 13 Nov 2020 15:37:49 -0600 Subject: Switched to using f-strings instead of the older method of string formatting --- wqflask/wqflask/correlation/show_corr_results.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/wqflask/wqflask/correlation/show_corr_results.py b/wqflask/wqflask/correlation/show_corr_results.py index 87dd7597..1b801b1d 100644 --- a/wqflask/wqflask/correlation/show_corr_results.py +++ b/wqflask/wqflask/correlation/show_corr_results.py @@ -499,21 +499,21 @@ def generate_corr_json(corr_results, this_trait, dataset, target_dataset, for_ap if bool(trait.mean): results_dict['mean'] = float(trait.mean) if trait.LRS_score_repr != "N/A": - results_dict['lrs_score'] = "%.1f" % float(trait.LRS_score_repr) + results_dict['lrs_score'] = f"{float(trait.LRS_score_repr):.1f}" results_dict['lrs_location'] = trait.LRS_location_repr if bool(trait.additive): - results_dict['additive'] = "%0.3f" % float(trait.additive) - results_dict['sample_r'] = "%0.3f" % float(trait.sample_r) + results_dict['additive'] = f"{float(trait.additive):.3f}" + results_dict['sample_r'] = f"{float(trait.sample_r):.3f}" results_dict['num_overlap'] = trait.num_overlap - results_dict['sample_p'] = "%0.3e" % float(trait.sample_p) + results_dict['sample_p'] = f"{float(trait.sample_p):.3e}" results_dict['lit_corr'] = "--" results_dict['tissue_corr'] = "--" results_dict['tissue_pvalue'] = "--" if bool(trait.lit_corr): - results_dict['lit_corr'] = "%0.3f" % float(trait.lit_corr) + results_dict['lit_corr'] = f"{float(trait.lit_corr):.3f}" if bool(trait.tissue_corr): - results_dict['tissue_corr'] = "%0.3f" % float(trait.tissue_corr) - results_dict['tissue_pvalue'] = "%0.3e" % float(trait.tissue_pvalue) + results_dict['tissue_corr'] = f"{float(trait.tissue_corr):.3f}" + results_dict['tissue_pvalue'] = f"{float(trait.tissue_pvalue):.3e}" elif target_dataset.type == "Publish": results_dict['abbreviation_display'] = "N/A" results_dict['description'] = "N/A" @@ -547,15 +547,15 @@ def generate_corr_json(corr_results, this_trait, dataset, target_dataset, for_ap results_dict['lrs_score'] = trait.LRS_score_repr results_dict['lrs_location'] = trait.LRS_location_repr if bool(trait.additive): - results_dict['additive'] = "%0.3f" % float(trait.additive) - results_dict['sample_r'] = "%0.3f" % trait.sample_r + results_dict['additive'] = f"{float(trait.additive):.3f}" + results_dict['sample_r'] = f"{float(trait.sample_r):.3f}" results_dict['num_overlap'] = trait.num_overlap - results_dict['sample_p'] = "%0.3e" % float(trait.sample_p) + results_dict['sample_p'] = f"{float(trait.sample_p):.3e}" else: results_dict['location'] = trait.location_repr - results_dict['sample_r'] = "%0.3f" % trait.sample_r + results_dict['sample_r'] = f"{float(trait.sample_r):.3f}" results_dict['num_overlap'] = trait.num_overlap - results_dict['sample_p'] = "%0.3e" % float(trait.sample_p) + results_dict['sample_p'] = f"{float(trait.sample_p):.3e}" results_list.append(results_dict) -- cgit v1.2.3 From ceeae6fd087d91637c5007e0433ce347048fa96d Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Tue, 17 Nov 2020 22:31:10 +0300 Subject: use better function names --- .../tests/wqflask/marker_regression/test_gemma_mapping.py | 14 +++++++------- .../tests/wqflask/marker_regression/test_rqtl_mapping.py | 2 +- .../tests/wqflask/marker_regression/test_run_mapping.py | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/wqflask/tests/wqflask/marker_regression/test_gemma_mapping.py b/wqflask/tests/wqflask/marker_regression/test_gemma_mapping.py index af20c1b8..4fafd95a 100644 --- a/wqflask/tests/wqflask/marker_regression/test_gemma_mapping.py +++ b/wqflask/tests/wqflask/marker_regression/test_gemma_mapping.py @@ -23,7 +23,7 @@ class MockDatasetGroup(AttributeSetter): class TestGemmaMapping(unittest.TestCase): @mock.patch("wqflask.marker_regression.gemma_mapping.parse_loco_output") - def test_run_gemma_first_run_loco_set_false(self, mock_parse_loco): + def test_run_gemma_firstrun_set_false(self, mock_parse_loco): """add tests for gemma function where first run is set to false""" dataset = AttributeSetter( {"group": AttributeSetter({"genofile": "genofile.geno"})}) @@ -49,7 +49,7 @@ class TestGemmaMapping(unittest.TestCase): @mock.patch("wqflask.marker_regression.run_mapping.random.choice") @mock.patch("wqflask.marker_regression.gemma_mapping.os") @mock.patch("wqflask.marker_regression.gemma_mapping.gen_pheno_txt_file") - def test_run_gemma_first_run_set_true(self, mock_gen_pheno_txt, mock_os, mock_choice, mock_gen_covar, mock_flat_files, mock_logger, mock_parse_loco): + def test_run_gemma_firstrun_set_true(self, mock_gen_pheno_txt, mock_os, mock_choice, mock_gen_covar, mock_flat_files, mock_logger, mock_parse_loco): """add tests for run_gemma where first run is set to true""" chromosomes = [] for i in range(1, 5): @@ -140,7 +140,7 @@ class TestGemmaMapping(unittest.TestCase): '-9\t'), mock.call('-9\t'), mock.call('-9\t'), mock.call('-9\t'), mock.call('\n')]) @mock.patch("wqflask.marker_regression.gemma_mapping.webqtlConfig.GENERATED_IMAGE_DIR", "/home/user/img/") - def test_parse_gemma_output_obj_returned(self): + def test_parse_gemma_output(self): """add test for generating gemma output with obj returned""" file = """X/Y\t gn2\t21\tQ\tE\tA\tP\tMMB\tCDE\t0.5 X/Y\tgn2\t21322\tQ\tE\tA\tP\tMMB\tCDE\t0.5 @@ -157,7 +157,7 @@ X\tgn7\t2324424\tQ\tE\tA\tP\tMMB\tCDE\t0.4 self.assertEqual(results, expected) @mock.patch("wqflask.marker_regression.gemma_mapping.webqtlConfig.GENERATED_IMAGE_DIR", "/home/user/img") - def test_parse_gemma_output_empty_return(self): + def test_parse_gemma_output_with_empty_return(self): """add tests for parse gemma output where nothing returned""" output_file_results = """chr\t today""" with mock.patch("builtins.open", mock.mock_open(read_data=output_file_results)) as mock_open: @@ -167,7 +167,7 @@ X\tgn7\t2324424\tQ\tE\tA\tP\tMMB\tCDE\t0.4 @mock.patch("wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/tmp") @mock.patch("wqflask.marker_regression.gemma_mapping.os") @mock.patch("wqflask.marker_regression.gemma_mapping.json") - def test_parse_loco_output_file_found(self, mock_json, mock_os): + def test_parse_loco_outputfile_found(self, mock_json, mock_os): """add tests for parse loco output file found""" mock_json.load.return_value = { "files": [["file_name", "user", "~/file1"], @@ -193,8 +193,8 @@ chr\tL3\t12312\tQ\tE\tA\tP\tMMB\tCDE\t0.7""" @mock.patch("wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/tmp") @mock.patch("wqflask.marker_regression.gemma_mapping.os") - def test_parse_loco_output_file_not_found(self, mock_os): - """add tests for parse loco output file not found""" + def test_parse_loco_outputfile_not_found(self, mock_os): + """add tests for parse loco output where output file not found""" mock_os.path.isfile.return_value = False file_to_write = """{"files":["file_1","file_2"]}""" diff --git a/wqflask/tests/wqflask/marker_regression/test_rqtl_mapping.py b/wqflask/tests/wqflask/marker_regression/test_rqtl_mapping.py index 9fd32a30..69f53721 100644 --- a/wqflask/tests/wqflask/marker_regression/test_rqtl_mapping.py +++ b/wqflask/tests/wqflask/marker_regression/test_rqtl_mapping.py @@ -17,7 +17,7 @@ class TestRqtlMapping(unittest.TestCase): @mock.patch("wqflask.marker_regression.rqtl_mapping.g") @mock.patch("wqflask.marker_regression.rqtl_mapping.logger") - def test_get_trait_data_type_found(self,mock_logger,mock_db): + def test_get_trait_data(self,mock_logger,mock_db): """test for getting trait data_type return True""" caller_value="""SELECT value FROM TraitMetadata WHERE type='trait_data_type'""" mock_db.db.execute.return_value.fetchone.return_value=["""{"type":"trait_data_type","name":"T1","traid_id":"fer434f"}"""] diff --git a/wqflask/tests/wqflask/marker_regression/test_run_mapping.py b/wqflask/tests/wqflask/marker_regression/test_run_mapping.py index 2af4c3e3..a134f551 100644 --- a/wqflask/tests/wqflask/marker_regression/test_run_mapping.py +++ b/wqflask/tests/wqflask/marker_regression/test_run_mapping.py @@ -62,7 +62,7 @@ class TestRunMapping(unittest.TestCase): self.assertEqual(result_2, []) @mock.patch("wqflask.marker_regression.run_mapping.data_set") - def test_geno_db_exists(self, mock_data_set): + def test_if_geno_db_exists(self, mock_data_set): mock_data_set.create_dataset.side_effect = [ AttributeSetter({}), Exception()] results_no_error = geno_db_exists(self.dataset) -- cgit v1.2.3 From 9d3493f2e8ee2d2185854b95d2b13a5d2b4e38e1 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Wed, 18 Nov 2020 02:18:45 +0300 Subject: use f strings in marker_regression/plink_mapping --- wqflask/wqflask/marker_regression/plink_mapping.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/wqflask/wqflask/marker_regression/plink_mapping.py b/wqflask/wqflask/marker_regression/plink_mapping.py index 8d57d556..5d675c38 100644 --- a/wqflask/wqflask/marker_regression/plink_mapping.py +++ b/wqflask/wqflask/marker_regression/plink_mapping.py @@ -9,11 +9,11 @@ import utility.logger logger = utility.logger.getLogger(__name__ ) def run_plink(this_trait, dataset, species, vals, maf): - plink_output_filename = webqtlUtil.genRandStr("%s_%s_"%(dataset.group.name, this_trait.name)) + plink_output_filename = webqtlUtil.genRandStr(f"{dataset.group.name}_{this_trait.name}_") gen_pheno_txt_file(dataset, vals) - plink_command = PLINK_COMMAND + ' --noweb --bfile %s/%s --no-pheno --no-fid --no-parents --no-sex --maf %s --out %s%s --assoc ' % ( - flat_files('mapping'), dataset.group.name, maf, TMPDIR, plink_output_filename) + + plink_command = f"{PLINK_COMMAND} --noweb --bfile {flat_files('mapping')}/{dataset.group.name} --no-pheno --no-fid --no-parents --no-sex --maf {maf} --out { TMPDIR}{plink_output_filename} --assoc " logger.debug("plink_command:", plink_command) os.system(plink_command) @@ -29,12 +29,12 @@ def gen_pheno_txt_file(this_dataset, vals): """Generates phenotype file for GEMMA/PLINK""" current_file_data = [] - with open("{}/{}.fam".format(flat_files('mapping'), this_dataset.group.name), "r") as outfile: + with open(f"{flat_files('mapping')}/{this_dataset.group.name}.fam", "r") as outfile: for i, line in enumerate(outfile): split_line = line.split() current_file_data.append(split_line) - with open("{}/{}.fam".format(flat_files('mapping'), this_dataset.group.name), "w") as outfile: + with open(f"{flat_files('mapping')}/{this_dataset.group.name}.fam","w") as outfile: for i, line in enumerate(current_file_data): if vals[i] == "x": this_val = -9 @@ -44,8 +44,8 @@ def gen_pheno_txt_file(this_dataset, vals): def gen_pheno_txt_file_plink(this_trait, dataset, vals, pheno_filename = ''): ped_sample_list = get_samples_from_ped_file(dataset) - output_file = open("%s%s.txt" % (TMPDIR, pheno_filename), "wb") - header = 'FID\tIID\t%s\n' % this_trait.name + output_file = open(f"{TMPDIR}{pheno_filename}.txt", "wb") + header = f"FID\tIID\t{this_trait.name}\n" output_file.write(header) new_value_list = [] @@ -65,7 +65,7 @@ def gen_pheno_txt_file_plink(this_trait, dataset, vals, pheno_filename = ''): for i, sample in enumerate(ped_sample_list): j = i+1 value = new_value_list[i] - new_line += '%s\t%s\t%s\n'%(sample, sample, value) + new_line += f"{sample}\t{sample}\t{value}\n" if j%1000 == 0: output_file.write(newLine) @@ -78,7 +78,7 @@ def gen_pheno_txt_file_plink(this_trait, dataset, vals, pheno_filename = ''): # get strain name from ped file in order def get_samples_from_ped_file(dataset): - ped_file= open("{}{}.ped".format(flat_files('mapping'), dataset.group.name), "r") + ped_file= open(f"{flat_files('mapping')}{dataset.group.name}.ped","r") line = ped_file.readline() sample_list=[] @@ -98,7 +98,7 @@ def parse_plink_output(output_filename, species): threshold_p_value = 1 - result_fp = open("%s%s.qassoc"% (TMPDIR, output_filename), "rb") + result_fp = open(f"{TMPDIR}{output_filename}.qassoc","rb") line = result_fp.readline() -- cgit v1.2.3 From 77dff447c83a4b0824fe6626d16484cfd826ca77 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Wed, 18 Nov 2020 03:06:27 +0300 Subject: use f strings in marker_regression/qtlreaper_mapping.py --- .../wqflask/marker_regression/qtlreaper_mapping.py | 46 +++++++++++++--------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/wqflask/wqflask/marker_regression/qtlreaper_mapping.py b/wqflask/wqflask/marker_regression/qtlreaper_mapping.py index 78b1f7b0..505ae295 100644 --- a/wqflask/wqflask/marker_regression/qtlreaper_mapping.py +++ b/wqflask/wqflask/marker_regression/qtlreaper_mapping.py @@ -17,22 +17,29 @@ def run_reaper(this_trait, this_dataset, samples, vals, json_data, num_perm, boo else: genofile_name = this_dataset.group.name - trait_filename = str(this_trait.name) + "_" + str(this_dataset.name) + "_pheno" + trait_filename =f"{str(this_trait.name)}_{str(this_dataset.name)}_pheno" gen_pheno_txt_file(samples, vals, trait_filename) - output_filename = this_dataset.group.name + "_GWA_" + ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6)) + output_filename = (f"{this_dataset.group.name}_GWA_"+ + ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6)) + ) bootstrap_filename = None permu_filename = None opt_list = [] if boot_check and num_bootstrap > 0: - bootstrap_filename = this_dataset.group.name + "_BOOTSTRAP_" + ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6)) + bootstrap_filename = (f"{this_dataset.group.name}_BOOTSTRAP_" + + ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6)) + ) opt_list.append("-b") - opt_list.append("--n_bootstrap " + str(num_bootstrap)) - opt_list.append("--bootstrap_output " + webqtlConfig.GENERATED_IMAGE_DIR + bootstrap_filename + ".txt") + opt_list.append(f"--n_bootstrap{str(num_bootstrap)}") + opt_list.append(f"--bootstrap_output{webqtlConfig.GENERATED_IMAGE_DIR}{bootstrap_filename}.txt") if num_perm > 0: - permu_filename = this_dataset.group.name + "_PERM_" + ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6)) + permu_filename =("{this_dataset.group.name}_PERM_" + + ''.join(random.choice(string.ascii_uppercase + + string.digits) for _ in range(6)) + ) opt_list.append("-n " + str(num_perm)) opt_list.append("--permu_output " + webqtlConfig.GENERATED_IMAGE_DIR + permu_filename + ".txt") if control_marker != "" and do_control == "true": @@ -40,13 +47,15 @@ def run_reaper(this_trait, this_dataset, samples, vals, json_data, num_perm, boo if manhattan_plot != True: opt_list.append("--interval 1") - reaper_command = REAPER_COMMAND + ' --geno {0}/{1}.geno --traits {2}/gn2/{3}.txt {4} -o {5}{6}.txt'.format(flat_files('genotype'), - genofile_name, - TEMPDIR, - trait_filename, - " ".join(opt_list), - webqtlConfig.GENERATED_IMAGE_DIR, - output_filename) + reaper_command = (REAPER_COMMAND + + ' --geno {0}/{1}.geno --traits {2}/gn2/{3}.txt {4} -o {5}{6}.txt'.format(flat_files('genotype'), + + genofile_name, + TEMPDIR, + trait_filename, + " ".join(opt_list), + webqtlConfig.GENERATED_IMAGE_DIR, + output_filename)) logger.debug("reaper_command:" + reaper_command) os.system(reaper_command) @@ -61,12 +70,13 @@ def run_reaper(this_trait, this_dataset, samples, vals, json_data, num_perm, boo suggestive = permu_vals[int(num_perm*0.37-1)] significant = permu_vals[int(num_perm*0.95-1)] - return marker_obs, permu_vals, suggestive, significant, bootstrap_vals, [output_filename, permu_filename, bootstrap_filename] + return (marker_obs, permu_vals, suggestive, significant, bootstrap_vals, + [output_filename, permu_filename, bootstrap_filename]) def gen_pheno_txt_file(samples, vals, trait_filename): """Generates phenotype file for GEMMA""" - with open("{}/gn2/{}.txt".format(TEMPDIR, trait_filename), "w") as outfile: + with open(f"{TEMPDIR}/gn2/{trait_filename}.txt","w") as outfile: outfile.write("Trait\t") filtered_sample_list = [] @@ -90,7 +100,7 @@ def parse_reaper_output(gwa_filename, permu_filename, bootstrap_filename): only_cm = False only_mb = False - with open("{}{}.txt".format(webqtlConfig.GENERATED_IMAGE_DIR, gwa_filename)) as output_file: + with open(f"{webqtlConfig.GENERATED_IMAGE_DIR}{gwa_filename}.txt") as output_file: for line in output_file: if line.startswith("ID\t"): if len(line.split("\t")) < 8: @@ -137,13 +147,13 @@ def parse_reaper_output(gwa_filename, permu_filename, bootstrap_filename): permu_vals = [] if permu_filename: - with open("{}{}.txt".format(webqtlConfig.GENERATED_IMAGE_DIR, permu_filename)) as permu_file: + with open(f"{webqtlConfig.GENERATED_IMAGE_DIR}{permu_filename}.txt") as permu_file: for line in permu_file: permu_vals.append(float(line)) bootstrap_vals = [] if bootstrap_filename: - with open("{}{}.txt".format(webqtlConfig.GENERATED_IMAGE_DIR, bootstrap_filename)) as bootstrap_file: + with open(f"{webqtlConfig.GENERATED_IMAGE_DIR}{bootstrap_filename}.txt") as bootstrap_file: for line in bootstrap_file: bootstrap_vals.append(int(line)) -- cgit v1.2.3 From cf4db5545efee6d9052153708fc05ca707ef1716 Mon Sep 17 00:00:00 2001 From: zsloan Date: Tue, 24 Nov 2020 12:51:17 -0600 Subject: Added html/css for new "Filter Samples by Value" feature and changed a couple class names to make more sense for being shared between both this feature and "Block Samples by Index" --- wqflask/wqflask/static/new/css/show_trait.css | 4 ++-- .../templates/show_trait_transform_and_filter.html | 23 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/wqflask/wqflask/static/new/css/show_trait.css b/wqflask/wqflask/static/new/css/show_trait.css index 5e1a279b..39c6ba53 100644 --- a/wqflask/wqflask/static/new/css/show_trait.css +++ b/wqflask/wqflask/static/new/css/show_trait.css @@ -145,11 +145,11 @@ input.corr-location { display: inline; } -div.block-by-index-div { +div.block-div { margin-bottom: 10px; } -div.block-by-attribute-div { +div.block-div-2 { margin-top:10px; margin-bottom:10px; } diff --git a/wqflask/wqflask/templates/show_trait_transform_and_filter.html b/wqflask/wqflask/templates/show_trait_transform_and_filter.html index 0418d972..22c52d8c 100644 --- a/wqflask/wqflask/templates/show_trait_transform_and_filter.html +++ b/wqflask/wqflask/templates/show_trait_transform_and_filter.html @@ -4,7 +4,7 @@ Reset option as needed.

-
+
+ + + + + + + + +
{% if sample_groups[0].attributes %} -
+
+ {% for attribute in sample_groups[0].attributes %} + {% if sample_groups[0].attributes[attribute].distinct_values|length <= 10 %} + + {% endif %} + {% endfor %} + + + + +
+ {% endif %}
- + + {% if sample_groups[0].attributes %} + + {% endif %}
- {% if sample_groups[0].attributes %} -
- - - - -
- {% endif %}
-- cgit v1.2.3 From a53302a077b8eea3591460a03a60c9621c3f4586 Mon Sep 17 00:00:00 2001 From: zsloan Date: Wed, 25 Nov 2020 13:11:11 -0600 Subject: Substituted CDN link to the font-awesome CSS with the local guix profile link --- wqflask/wqflask/templates/search_result_page.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wqflask/wqflask/templates/search_result_page.html b/wqflask/wqflask/templates/search_result_page.html index 8e2b06a4..35d8ed27 100644 --- a/wqflask/wqflask/templates/search_result_page.html +++ b/wqflask/wqflask/templates/search_result_page.html @@ -2,9 +2,9 @@ {% block title %}Search Results{% endblock %} {% block css %} + - {% endblock %} -- cgit v1.2.3 From c8a339616fb3dd3f63427378dc4285de9ad1ccef Mon Sep 17 00:00:00 2001 From: zsloan Date: Wed, 25 Nov 2020 13:11:48 -0600 Subject: Removed an unused console.timeEnd in the JS --- wqflask/wqflask/templates/search_result_page.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/wqflask/wqflask/templates/search_result_page.html b/wqflask/wqflask/templates/search_result_page.html index 35d8ed27..9a28a78e 100644 --- a/wqflask/wqflask/templates/search_result_page.html +++ b/wqflask/wqflask/templates/search_result_page.html @@ -440,8 +440,6 @@ 'processing': 'Loading...' } } ); - - console.timeEnd("Creating table"); $('.toggle-vis').on( 'click', function (e) { e.preventDefault(); -- cgit v1.2.3 From ab6681e545bd4c84e1f74107b90ea52f7d2ca24c Mon Sep 17 00:00:00 2001 From: zsloan Date: Wed, 25 Nov 2020 13:15:25 -0600 Subject: Added form options for changing manhattan plot color scheme + added necessary imports and hidden inputs --- wqflask/wqflask/templates/mapping_results.html | 47 +++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/wqflask/wqflask/templates/mapping_results.html b/wqflask/wqflask/templates/mapping_results.html index 28d93542..9542c29d 100644 --- a/wqflask/wqflask/templates/mapping_results.html +++ b/wqflask/wqflask/templates/mapping_results.html @@ -40,6 +40,9 @@ + {% if manhattan_plot == True %} + + {% endif %} @@ -55,7 +58,7 @@ -
+

Map Viewer: Whole Genome


Population: {{ dataset.group.species|capitalize }} {{ dataset.group.name }}
@@ -77,7 +80,7 @@ - - + @@ -114,11 +117,31 @@ -
Chr:  +
View: View:  to
Width:  + pixels (minimum=900)
+ {% if manhattan_plot == True and selectedChr == -1 %} + + + + + + +
+ Manhattan Plot Color Scheme:  + + + + + +
+ {% endif %}
{% if (mapping_method == "reaper" or mapping_method == "rqtl_geno") and nperm > 0 %} @@ -328,6 +351,9 @@ + {% if manhattan_plot == True and selectedChr == -1 %} + + {% endif %} @@ -423,7 +449,7 @@ var mapping_input_list = ['temp_uuid', 'trait_id', 'dataset', 'tool_used', 'form_url', 'method', 'transform', 'trimmed_markers', 'selected_chr', 'chromosomes', 'mapping_scale', 'score_type', 'suggestive', 'significant', 'num_perm', 'permCheck', 'perm_output', 'perm_strata', 'categorical_vars', 'num_bootstrap', 'bootCheck', 'bootstrap_results', - 'LRSCheck', 'covariates', 'maf', 'use_loco', 'manhattan_plot', 'control_marker', 'control_marker_db', 'do_control', 'genofile', + 'LRSCheck', 'covariates', 'maf', 'use_loco', 'manhattan_plot', 'color_scheme', 'manhattan_single_color', 'control_marker', 'control_marker_db', 'do_control', 'genofile', 'pair_scan', 'startMb', 'endMb', 'graphWidth', 'lrsMax', 'additiveCheck', 'showSNP', 'showGenes', 'viewLegend', 'haplotypeAnalystCheck', 'mapmethod_rqtl_geno', 'mapmodel_rqtl_geno', 'temp_trait', 'group', 'species', 'reaper_version', 'primary_samples', 'n_samples'] @@ -449,10 +475,21 @@ remap = function() { $('input[name=selected_chr]').val($('select[name=chromosomes]').val()); + $('input[name=color_scheme]').val($('select#color_scheme').val()); $('#marker_regression_form').attr('action', '/loading'); return $('#marker_regression_form').submit(); }; + {% if manhattan_plot == True and selectedChr == -1 %} + $('#color_scheme').change(function(){ + if ($(this).val() == "single"){ + $('#point_color_picker').show(); + } else { + $('#point_color_picker').hide(); + } + }); + {% endif %} + {% if mapping_method != "gemma" and mapping_method != "plink" %} $('#download_perm').click(function(){ perm_info_dict = { -- cgit v1.2.3 From a1563aee47a54d5ff4253e1da7e851afe28805c0 Mon Sep 17 00:00:00 2001 From: zsloan Date: Wed, 25 Nov 2020 13:16:26 -0600 Subject: Added code for passing around form parameters related to manhattan plot coloration to run_mapping.py and views.py --- wqflask/wqflask/marker_regression/run_mapping.py | 7 ++++++- wqflask/wqflask/views.py | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/wqflask/wqflask/marker_regression/run_mapping.py b/wqflask/wqflask/marker_regression/run_mapping.py index 31d6a67c..c474e0e0 100644 --- a/wqflask/wqflask/marker_regression/run_mapping.py +++ b/wqflask/wqflask/marker_regression/run_mapping.py @@ -138,7 +138,12 @@ class RunMapping(object): mapping_results_filename = self.dataset.group.name + "_" + ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6)) self.mapping_results_path = "{}{}.csv".format(webqtlConfig.GENERATED_IMAGE_DIR, mapping_results_filename) - if start_vars['manhattan_plot'] == "true": + if start_vars['manhattan_plot']: + self.color_scheme = "alternating" + if "color_scheme" in start_vars: + self.color_scheme = start_vars['color_scheme'] + if self.color_scheme == "single": + self.manhattan_single_color = start_vars['manhattan_single_color'] self.manhattan_plot = True else: self.manhattan_plot = False diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index b7c4d142..7118bab7 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -718,6 +718,8 @@ def mapping_results_page(): 'maf', 'use_loco', 'manhattan_plot', + 'color_scheme', + 'manhattan_single_color', 'control_marker', 'control_marker_db', 'do_control', -- cgit v1.2.3 From d1740605ffd36e49b9560e81c0e085c58ef8b688 Mon Sep 17 00:00:00 2001 From: zsloan Date: Wed, 25 Nov 2020 13:17:03 -0600 Subject: Added actual code for coloring manhattan plot differently to display_mapping_results.py --- .../marker_regression/display_mapping_results.py | 46 ++++++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/wqflask/wqflask/marker_regression/display_mapping_results.py b/wqflask/wqflask/marker_regression/display_mapping_results.py index 3f6de2b2..87910401 100644 --- a/wqflask/wqflask/marker_regression/display_mapping_results.py +++ b/wqflask/wqflask/marker_regression/display_mapping_results.py @@ -74,6 +74,34 @@ DARKVIOLET = ImageColor.getrgb("darkviolet") MEDIUMPURPLE = ImageColor.getrgb("mediumpurple") # ---- END: Define common colours ---- # +# ZS: List of distinct colors for manhattan plot if user selects "varied" +DISTINCT_COLOR_LIST = [ + ImageColor.getrgb("#FF0000"), + ImageColor.getrgb("#00FF00"), + ImageColor.getrgb("#0000FF"), + ImageColor.getrgb("#FFFF00"), + ImageColor.getrgb("#FF00FF"), + ImageColor.getrgb("#00FFFF"), + ImageColor.getrgb("#000000"), + ImageColor.getrgb("#800000"), + ImageColor.getrgb("#008000"), + ImageColor.getrgb("#000080"), + ImageColor.getrgb("#808000"), + ImageColor.getrgb("#800080"), + ImageColor.getrgb("#008080"), + ImageColor.getrgb("#808080"), + ImageColor.getrgb("#C00000"), + ImageColor.getrgb("#00C000"), + ImageColor.getrgb("#0000C0"), + ImageColor.getrgb("#C0C000"), + ImageColor.getrgb("#C000C0"), + ImageColor.getrgb("#00C0C0"), + ImageColor.getrgb("#C0C0C0"), + ImageColor.getrgb("#400000"), + ImageColor.getrgb("#004000"), + ImageColor.getrgb("#000040"), +] + # ---- FONT FILES ---- # VERDANA_FILE = "./wqflask/static/fonts/verdana.ttf" VERDANA_BOLD_FILE = "./wqflask/static/fonts/verdanab.ttf" @@ -293,6 +321,12 @@ class DisplayMappingResults(object): self.plotScale = "physic" self.manhattan_plot = start_vars['manhattan_plot'] + if self.manhattan_plot: + self.color_scheme = "alternating" + if 'color_scheme' in start_vars: + self.color_scheme = start_vars['color_scheme'] + if self.color_scheme == "single": + self.manhattan_single_color = ImageColor.getrgb("#" + start_vars['manhattan_single_color']) if 'permCheck' in list(start_vars.keys()): self.permChecked = start_vars['permCheck'] @@ -2424,10 +2458,16 @@ class DisplayMappingResults(object): Yc = yZero - qtlresult['lod_score']*LRSHeightThresh/LRS_LOD_Max if self.manhattan_plot == True: - if self.selectedChr == -1 and (previous_chr_as_int % 2 == 1): - point_color = RED + if self.color_scheme == "single": + point_color = self.manhattan_single_color + elif self.color_scheme == "varied": + point_color = DISTINCT_COLOR_LIST[previous_chr_as_int] else: - point_color = BLUE + if self.selectedChr == -1 and (previous_chr_as_int % 2 == 1): + point_color = RED + else: + point_color = BLUE + im_drawer.text( text="5", xy=( -- cgit v1.2.3 From 60447282a0f0063513ab10251945df3ab2c2dbfd Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 00:03:07 +0300 Subject: add reference markdown and github button --- wqflask/wqflask/templates/reference.html | 1541 +----------------------------- 1 file changed, 53 insertions(+), 1488 deletions(-) diff --git a/wqflask/wqflask/templates/reference.html b/wqflask/wqflask/templates/reference.html index d95d22e3..78469d39 100644 --- a/wqflask/wqflask/templates/reference.html +++ b/wqflask/wqflask/templates/reference.html @@ -1,1497 +1,62 @@ {% extends "base.html" %} -{% block title %}References{% endblock %} -{% block content %} - -

 Papers and References to GeneNetwork

- -
- - -Highlighted References | -Key References | -Background References | - - -

- -2020 | -2019 | -2018 | -2017 | -2016 | -2015 | -2014 | -2013 | -2012 | -2011 | -2010 | -2009 | -2008 | -2007 | -2006 | -2005 | -2004 | -2003 | - -
- - - Google Scholar search for "genenetwork" OR "webqtl" generated: -
    -
  1. 1430 hits on 2016/09/08 -
  2. 1730 hits on 2017/10/17 -
  3. 2020 hits on 2019/05/13) -
- -Google Scholar search for "genenetwork.org" generated: - -
    -
  1. 1030 hits on 2019/05/13 -
  2. 105 hits from 2018/01/01 to 2019/05/13 -
- -
- - -
- Highlighted References -
- -Please send us citations to articles that we may have missed. - -
    - -
  1. Mulligan MK, Mozhui K, Prins P, Williams RW (2017) GeneNetwork: A Toolbox for Systems Genetics. In Systems Genetics, Methods in Molecular Biology 1488:75-120 -[An updated primer in using GeneNetwork for molecular analysis of mouse and human cohorts.] -PDF version - -
    -
    - -
  2. Williams RW, Williams EG (2017) Resources for Systems Genetics. In Systems Genetics, Methods in Molecular Biology 1488:3-29. -[This review is intended to help you when making the hard choices about types of resources to use in system genetic studies. The short answer: embrace diversity in your resources. The computational barriers to joint analysis are now minimal.] -PDF version - -
    -
    - -
  3. Williams RW (2009) Herding cats: the sociology of data integration. Frontier in Neuroscience 3(2):154-6. -[An short but amusing commentary on predictive (someday perhaps even precision) medicine and how to get there using genetic reference populations such as the BXD and Collaborative Cross families.] -PDF version - -
    -
    - - -
  4. -Pinelli M, Carissimo A, Cutillo L, Lai CH, Mutarelli M, Moretti MN, Singh MV, Karali M, Carrella D, Pizzo M, Russo F, Ferrari S, Ponzin D, Angelini C, Banfi S, di Bernardo D (2016) An atlas of gene expression and gene co-regulation in the human retina.Nucleic Acids Res. 2016 Jul 8;44(12):5773-84 -RETINA database, and see the PDF. These data are now in GeneNetwork (Species = Human, Group = Retina). - - -
    -
    - - -
  5. -Williams EG, Wu Y, Pooja J, Dubuis S, Blattmann P, Argmann CA, Houten SM, Amariuta T, Wolski W, Zamboni N, Aebersold R, Auwerx J (2016) Systems proteomics and trans-omic integration illuminate new mechanisms in mitochondrial function. Science 352(6291):aad0189 -HTML version, PDF - -
    -
    - - - -
  6. -Sloan Z, Arends D, Broman KW, Centeno A, Furlotte N, Nijveen H, Yan L, Zhou X, Williams RW, Prins P (2016) GenetNetwork: framework for web-based genetics. The Journal of Open Source Software http://joss.theoj.org/papers/10.21105/joss.00025 (http://dx.doi.org/10.21105/joss.00025) -HTML version - -
    -
    - -
  7. Alam G, Miller DB, O'Callaghan JP, Lu L, Williams RW, Jones BC (2016) MPTP neurotoxicity is highly concordant between the sexes among BXD recombinant inbred mouse strains. Neurotoxicology in press -PDF version - -
    -
    - - -
  8. Merkwirth C, Jovaisaite V, Durieux J, Matilainen O, Jordan SD, Quiros PM, Steffen KK, Williams EG, Mouchiroud L, Tronnes SU, Murillo V, Wolff SC, Shaw RJ, Auwerx J, Dillin A (2016) Two conserved histone demethylases regulate mitochondrial stress-induced longevity. Cell 165:1209-1223 -
    -
    - - -
  9. Wang X, Pandey AK, Mulligan MK, Williams EG, Mozhui K, Li Z, Jovaisaite V, Quarles LD, Xiao Z, Huang J, Capra JA, Chen Z, Taylor WL, Bastarache L, Niu X, Pollard KS, Ciobanu DC, Reznik AO, Tishkov AV, Zhulin IB, Peng J, Nelson SF, Denny JC, Auwerx J, Lu L, Williams RW (2016). Joint mouse-human phenome-wide association to test gene function and disease risk. Nature Communications 7:10464 -[Best reference on the BXD family of strains and the wide range of phenotypes that have been generated over the past 40 years.] - -PDF version and the - -Supplementary Tables in one Excel file - - -
    -
    - - -
  10. Xue Y, Li J, Yan L, Lu L, Liao FF (2015) Genetic variability to diet-induced hippocampal dysfunction in BXD recombinant inbred (RI) mouse strains. Behav Brain Res 292:83-94 -
    -
    - -
  11. Chaum E, Winborn CS, Bhattacharya S (2015) Multilayered genetic and omics dissection of mitochondrial activity in a mouse reference population. Mamm Genome 26:210-221 -
    -
    - -
  12. Cheng Q, Seltzer Z, Sima C, Lakschevitz FS, Glogauer M. (2015) Quantitative Trait Loci and Candidate Genes for Neutrophil Recruitment in Sterile Inflammation Mapped in AXB-BXA Recombinant Inbred Mice. PLoS One 10:e0124117 -
    -
    - -
  13. Scott RE, Ghule PN, Stein JL, Stein GS (2015) Cell cycle gene expression networks discovered using systems biology: Significance in carcinogenesis. J Cell Physiol 230:2533-42 -
    -
    - -
  14. Williams EG, Auwerx J (2015) The convergence of systems and reductionist approaches in complex trait analysis. Cell 162:23-32. -
    -
    -
  15. Wu Y, Williams EG, Dubuis S, Mottis A, Jovaisaite V, Houten SM, Argmann CA, Faridi P, Wolski W, Kutalik Z, Zamboni N, Auwerx J, Aebersold R (2014) Multilayered genetic and omics dissection of mitochondrial activity in a mouse reference population. Cell 158:1415-1430 -
    -
    +{% block title %}Reference{% endblock %} -
  16. -Hayes SK, Hager R, Grencis RK (2014) Sex-dependent genetics effects on immune responses to parasitic nematodes. BMC Genomics 15:193 -
    -
    - -
  17. Harenza JL, Muldoon PP, De Biasi M, Damaj MI, Miles MF (2014) Genetic variation within the Chrna7 gene modulates nicotine reward-like phenotypes in mice. Genes Brain Behav 13:213-225 -
    -
    - - -
  18. -Ye R, Carneiro AM, Airey D, Sanders-Bush E, Williams RW, Lu L, Wang J, Zhang B, Blakely RD (2014) Evaluation of heritable determinants of blood and brain serotonin homeostasis using recombinant inbred mice. Genes Brain Behav. 13:247-260 +{% block css %} + +{% endblock %} -
    -
    -
  19. -Houtkooper RH, Mouchiroud L, Ryu D, Moullan N, Katsyuba E, Knott G, Williams RW, Auwerx J (2013) Mitonuclear protein imbalance as a conserved longevity mechanism. Nature 497:451-457 PDF version +{% block content %} -
    -
    + + +
    + {{ rendered_markdown|safe }} + + + +
    + + {% endblock %} + -- cgit v1.2.3 From 2681d11a9c39a3291db03521e5b7f73ed672533c Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 00:04:22 +0300 Subject: register references blueprint --- wqflask/wqflask/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wqflask/wqflask/__init__.py b/wqflask/wqflask/__init__.py index 874cde17..39a36fa3 100644 --- a/wqflask/wqflask/__init__.py +++ b/wqflask/wqflask/__init__.py @@ -7,6 +7,7 @@ from flask import g from flask import Flask from utility import formatting from wqflask.markdown_routes import glossary_blueprint +from wqflask.markdown_routes import references_blueprint app = Flask(__name__) @@ -19,6 +20,7 @@ app.jinja_env.globals.update( # Registering blueprints app.register_blueprint(glossary_blueprint, url_prefix="/glossary") +app.register_blueprint(references_blueprint,url_prefix="/references") @app.before_request def before_request(): @@ -39,4 +41,4 @@ from wqflask import db_info from wqflask import user_login from wqflask import user_session -import wqflask.views +import wqflask.views -- cgit v1.2.3 From 23d27c88bcc085bac3fb14b534cf1d4a7f11f22a Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 00:07:01 +0300 Subject: modify references links --- wqflask/wqflask/markdown_routes.py | 33 ++++++++++++++++++++++++++++++++- wqflask/wqflask/templates/base.html | 2 +- wqflask/wqflask/views.py | 5 ----- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/wqflask/wqflask/markdown_routes.py b/wqflask/wqflask/markdown_routes.py index 7a9fac41..60d4374c 100644 --- a/wqflask/wqflask/markdown_routes.py +++ b/wqflask/wqflask/markdown_routes.py @@ -9,7 +9,10 @@ from flask import Blueprint from flask import render_template glossary_blueprint = Blueprint('glossary_blueprint', __name__) - +references_blueprint=Blueprint("references_blueprint",__name__) +environments_blueprint=Blueprint("environments_blueprint",__name__) +links_blueprint=Blueprint("links_blueprint",__name__) +policies_blueprint=Blueprint("policies_blueprint",__name__) def render_markdown(file_name): """Try to fetch the file name from Github and if that fails, try to @@ -22,6 +25,7 @@ look for it inside the file system if md_content.status_code == 200: return markdown.Markdown().convert(md_content.content.decode("utf-8")) + # TODO: Add fallback on our git server by checking the mirror. # Content not available @@ -32,8 +36,35 @@ look for it inside the file system "Please reach out to the gn2 team to have a look at this") + + @glossary_blueprint.route('/') def glossary(): return render_template( "glossary.html", rendered_markdown=render_markdown("general/glossary/glossary.md")), 200 + + +@references_blueprint.route('/') +def references(): + return render_template( + "reference.html", + rendered_markdown=render_markdown("general/glossary/glossary.md")), 200 + + + +@environments_blueprint.route("/") +def references(): + return render_template("environments.html",rendered_markdown=render_markdown("general/environments/environments.md")) + + +@links_blueprint.route("/") +def links(): + return rendered_template("links.html",rendered_markdown=render_markdown("general/links/links.md")) + + +policies_blueprint.route("/") +def policies(): + return rendered_template("policies.html",rendered_markdown=rendered_markdown("general/policies/policies.md")) + + diff --git a/wqflask/wqflask/templates/base.html b/wqflask/wqflask/templates/base.html index 0e572fcf..ca6c9d9b 100644 --- a/wqflask/wqflask/templates/base.html +++ b/wqflask/wqflask/templates/base.html @@ -64,7 +64,7 @@
  20. -- cgit v1.2.3 From 828cb4d0b327bcb441dc523f4d825f660f371e01 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 15:04:30 +0300 Subject: add policies page --- wqflask/wqflask/templates/policies.html | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/wqflask/wqflask/templates/policies.html b/wqflask/wqflask/templates/policies.html index 83b6b3c0..ef481de2 100644 --- a/wqflask/wqflask/templates/policies.html +++ b/wqflask/wqflask/templates/policies.html @@ -1,18 +1,21 @@ {% extends "base.html" %} -{% block title %}Policies{% endblock %} + +{% block title %}Links{% endblock %} + +{% block css %} + +{% endblock %} + {% block content %} - - - -
    -

    WebQTL Conditions of Use

    - -

    -
    + + +
    + {{ rendered_markdown|safe }} + +
    + {% endblock %} \ No newline at end of file -- cgit v1.2.3 From 6ae545167f59b40ecd0cee2bebb1276b34fa7c5b Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 15:06:05 +0300 Subject: register view,policies blueprint --- wqflask/wqflask/__init__.py | 4 ++++ wqflask/wqflask/templates/references.html | 25 ++++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/wqflask/wqflask/__init__.py b/wqflask/wqflask/__init__.py index 39a36fa3..d7da3755 100644 --- a/wqflask/wqflask/__init__.py +++ b/wqflask/wqflask/__init__.py @@ -8,6 +8,8 @@ from flask import Flask from utility import formatting from wqflask.markdown_routes import glossary_blueprint from wqflask.markdown_routes import references_blueprint +from wqflask.markdown_routes import links_blueprint +from wqflask.markdown_routes import policies_blueprint app = Flask(__name__) @@ -21,6 +23,8 @@ app.jinja_env.globals.update( # Registering blueprints app.register_blueprint(glossary_blueprint, url_prefix="/glossary") app.register_blueprint(references_blueprint,url_prefix="/references") +app.register_blueprint(links_blueprint,url_prefix="/links") +app.register_blueprint(policies_blueprint,url_prefix="/policies") @app.before_request def before_request(): diff --git a/wqflask/wqflask/templates/references.html b/wqflask/wqflask/templates/references.html index 5e86d95b..c10576d8 100644 --- a/wqflask/wqflask/templates/references.html +++ b/wqflask/wqflask/templates/references.html @@ -3,13 +3,13 @@ {% block title %}Reference{% endblock %} {% block css %} - + {% endblock %} {% block content %}
    @@ -18,12 +18,23 @@
    -- cgit v1.2.3 From 2a346d94a978c8a7faf0d1435220816efc3c2c64 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 15:07:42 +0300 Subject: add edit button in glossary page --- wqflask/wqflask/templates/glossary.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wqflask/wqflask/templates/glossary.html b/wqflask/wqflask/templates/glossary.html index 146c7e86..395bcfea 100644 --- a/wqflask/wqflask/templates/glossary.html +++ b/wqflask/wqflask/templates/glossary.html @@ -8,9 +8,11 @@ {% block content %} +
    - - [Edit on Github] + {{ rendered_markdown|safe }}
    {% endblock %} -- cgit v1.2.3 From 416cb0cd272001651a3d9eb43500067ef524819d Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 15:09:37 +0300 Subject: add endpoint for polices,environments and policies --- wqflask/wqflask/markdown_routes.py | 51 ++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/wqflask/wqflask/markdown_routes.py b/wqflask/wqflask/markdown_routes.py index 60d4374c..5170fcf0 100644 --- a/wqflask/wqflask/markdown_routes.py +++ b/wqflask/wqflask/markdown_routes.py @@ -9,23 +9,31 @@ from flask import Blueprint from flask import render_template glossary_blueprint = Blueprint('glossary_blueprint', __name__) -references_blueprint=Blueprint("references_blueprint",__name__) -environments_blueprint=Blueprint("environments_blueprint",__name__) -links_blueprint=Blueprint("links_blueprint",__name__) -policies_blueprint=Blueprint("policies_blueprint",__name__) +references_blueprint = Blueprint("references_blueprint", __name__) +environments_blueprint = Blueprint("environments_blueprint", __name__) +links_blueprint = Blueprint("links_blueprint", __name__) +policies_blueprint = Blueprint("policies_blueprint", __name__) -def render_markdown(file_name): +#for debug +github_url = ("https://raw.githubusercontent.com/" + "genenetwork/gn-docs/master/general/glossary/glossary.md") + + + +def render_markdown(file_name,github_url="https://raw.githubusercontent.com/Alexanderlacuna/gn-docs/feature/add-markdown-pages/"): + + md_content=requests.get(f"{github_url}{file_name}") """Try to fetch the file name from Github and if that fails, try to look for it inside the file system - +po """ - github_url = ("https://raw.githubusercontent.com/" - "genenetwork/gn-docs/master/") - md_content = requests.get(f"{github_url}{file_name}") + # github_url = ("https://raw.githubusercontent.com/" + # "genenetwork/gn-docs/master/") + # md_content = requests.get(f"{github_url}{file_name}") if md_content.status_code == 200: + # print(md_content.content.decode("utf-8")) return markdown.Markdown().convert(md_content.content.decode("utf-8")) - # TODO: Add fallback on our git server by checking the mirror. # Content not available @@ -36,8 +44,6 @@ look for it inside the file system "Please reach out to the gn2 team to have a look at this") - - @glossary_blueprint.route('/') def glossary(): return render_template( @@ -48,23 +54,24 @@ def glossary(): @references_blueprint.route('/') def references(): return render_template( - "reference.html", - rendered_markdown=render_markdown("general/glossary/glossary.md")), 200 - + "references.html", + rendered_markdown=render_markdown("general/references/references.md")), 200 @environments_blueprint.route("/") -def references(): - return render_template("environments.html",rendered_markdown=render_markdown("general/environments/environments.md")) +def environments(): + return render_template("environments.html", rendered_markdown=render_markdown("general/links/links.md")) @links_blueprint.route("/") def links(): - return rendered_template("links.html",rendered_markdown=render_markdown("general/links/links.md")) + return render_template( + "links.html", + rendered_markdown=render_markdown("general/links/links.md")), 200 -policies_blueprint.route("/") +@policies_blueprint.route("/") def policies(): - return rendered_template("policies.html",rendered_markdown=rendered_markdown("general/policies/policies.md")) - - + return render_template( + "links.html", + rendered_markdown=render_markdown("general/policies/policies.md")), 200 -- cgit v1.2.3 From 52eea81494a507eb69751dea54f98270b53d9844 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 15:10:46 +0300 Subject: add links page --- wqflask/wqflask/templates/links.html | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 wqflask/wqflask/templates/links.html diff --git a/wqflask/wqflask/templates/links.html b/wqflask/wqflask/templates/links.html new file mode 100644 index 00000000..7b092839 --- /dev/null +++ b/wqflask/wqflask/templates/links.html @@ -0,0 +1,21 @@ +{% extends "base.html" %} + +{% block title %}Links{% endblock %} + +{% block css %} + +{% endblock %} + +{% block content %} + + + +
    + {{ rendered_markdown|safe }} + +
    + + +{% endblock %} \ No newline at end of file -- cgit v1.2.3 From c58751a8aa7ab0277096d91bb3e50c3ef0d62aab Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 15:18:04 +0300 Subject: add re-used css to markdown.css for easy maintenance and reusability --- wqflask/wqflask/templates/references.html | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/wqflask/wqflask/templates/references.html b/wqflask/wqflask/templates/references.html index c10576d8..e05c8440 100644 --- a/wqflask/wqflask/templates/references.html +++ b/wqflask/wqflask/templates/references.html @@ -17,25 +17,5 @@
- {% endblock %} \ No newline at end of file -- cgit v1.2.3 From 8a0e79d3186e340bc438dd07b4c2992f81c3e6d7 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 17:09:43 +0300 Subject: add environment markdown --- wqflask/wqflask/templates/environment.html | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 wqflask/wqflask/templates/environment.html diff --git a/wqflask/wqflask/templates/environment.html b/wqflask/wqflask/templates/environment.html new file mode 100644 index 00000000..a331d494 --- /dev/null +++ b/wqflask/wqflask/templates/environment.html @@ -0,0 +1,37 @@ +{% extends "base.html" %} + +{% block title %}Glossary{% endblock %} + +{% block css %} + +{% endblock %} + +{% block content %} + + +
+ +
{{ rendered_markdown|safe }}
+
+ + +{% endblock %} -- cgit v1.2.3 From b0c1d59d4e5a9580b4d15664a53845969db32d0a Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 17:11:55 +0300 Subject: remove environment from /wqflask/views.py --- wqflask/wqflask/templates/links.html | 2 +- wqflask/wqflask/views.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/wqflask/wqflask/templates/links.html b/wqflask/wqflask/templates/links.html index 7b092839..ef481de2 100644 --- a/wqflask/wqflask/templates/links.html +++ b/wqflask/wqflask/templates/links.html @@ -9,7 +9,7 @@ {% block content %}
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index cc2dc341..6cdce248 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -321,10 +321,10 @@ def credits(): #return render_template("docs.html", **doc.__dict__) return render_template("credits.html") -@app.route("/environments") -def environments(): - doc = Docs("environments", request.args) - return render_template("docs.html", **doc.__dict__) +# @app.route("/environments") +# def environments(): +# doc = Docs("environments", request.args) +# return render_template("docs.html", **doc.__dict__) #return render_template("environments.html", **doc.__dict__) @app.route("/update_text", methods=('POST',)) -- cgit v1.2.3 From d8fb319272a4833ed3045cdc5ed46e0e204f78e1 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 17:13:24 +0300 Subject: add and register environments blueprint --- wqflask/wqflask/__init__.py | 2 ++ wqflask/wqflask/templates/base.html | 2 +- wqflask/wqflask/templates/references.html | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/wqflask/wqflask/__init__.py b/wqflask/wqflask/__init__.py index d7da3755..f44b4bfd 100644 --- a/wqflask/wqflask/__init__.py +++ b/wqflask/wqflask/__init__.py @@ -10,6 +10,7 @@ from wqflask.markdown_routes import glossary_blueprint from wqflask.markdown_routes import references_blueprint from wqflask.markdown_routes import links_blueprint from wqflask.markdown_routes import policies_blueprint +from wqflask.markdown_routes import environments_blueprint app = Flask(__name__) @@ -25,6 +26,7 @@ app.register_blueprint(glossary_blueprint, url_prefix="/glossary") app.register_blueprint(references_blueprint,url_prefix="/references") app.register_blueprint(links_blueprint,url_prefix="/links") app.register_blueprint(policies_blueprint,url_prefix="/policies") +app.register_blueprint(environments_blueprint,url_prefix="/environments") @app.before_request def before_request(): diff --git a/wqflask/wqflask/templates/base.html b/wqflask/wqflask/templates/base.html index fefb519c..8ba5d0d5 100644 --- a/wqflask/wqflask/templates/base.html +++ b/wqflask/wqflask/templates/base.html @@ -70,7 +70,7 @@
  • FAQ
  • Policies
  • Links
  • -
  • Environments
  • +
  • Environments
  • GN1 News
  • diff --git a/wqflask/wqflask/templates/references.html b/wqflask/wqflask/templates/references.html index e05c8440..e2f152e3 100644 --- a/wqflask/wqflask/templates/references.html +++ b/wqflask/wqflask/templates/references.html @@ -9,7 +9,7 @@ {% block content %}
    -- cgit v1.2.3 From 66f4ab80a5dbfa8634c3a5df91a59a9119f57b2c Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 17:18:35 +0300 Subject: add table extension to support conversion of markdown tables to HTML --- wqflask/wqflask/markdown_routes.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/wqflask/wqflask/markdown_routes.py b/wqflask/wqflask/markdown_routes.py index 5170fcf0..073370c7 100644 --- a/wqflask/wqflask/markdown_routes.py +++ b/wqflask/wqflask/markdown_routes.py @@ -20,7 +20,24 @@ github_url = ("https://raw.githubusercontent.com/" + +def render_markdown_table(file_name,github_url="https://raw.githubusercontent.com/Alexanderlacuna/gn-docs/feature/add-markdown-pages/"): + + md_content=md_content=requests.get(f"{github_url}{file_name}") + if md_content.status_code==200: + return markdown.markdown(md_content.content.decode("utf-8"), extensions=['tables']) + return (f"\nContent for {file_name} not available. " + "Please check " + "(here to see where content exists)" + "[https://github.com/genenetwork/gn-docs]. " + "Please reach out to the gn2 team to have a look at this") + + + + def render_markdown(file_name,github_url="https://raw.githubusercontent.com/Alexanderlacuna/gn-docs/feature/add-markdown-pages/"): + github_url = ("https://raw.githubusercontent.com/" + "genenetwork/gn-docs/master/") md_content=requests.get(f"{github_url}{file_name}") """Try to fetch the file name from Github and if that fails, try to @@ -60,7 +77,7 @@ def references(): @environments_blueprint.route("/") def environments(): - return render_template("environments.html", rendered_markdown=render_markdown("general/links/links.md")) + return render_template("environment.html", rendered_markdown=render_markdown_table("general/environments/environments.md")),200 @links_blueprint.route("/") -- cgit v1.2.3 From 41988f8e92ea5a273e22a7176481cf2f4bd88b5b Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 17:22:44 +0300 Subject: delete environments html pagE --- wqflask/wqflask/templates/environments.html | 83 ----------------------------- 1 file changed, 83 deletions(-) delete mode 100644 wqflask/wqflask/templates/environments.html diff --git a/wqflask/wqflask/templates/environments.html b/wqflask/wqflask/templates/environments.html deleted file mode 100644 index 5ef91a95..00000000 --- a/wqflask/wqflask/templates/environments.html +++ /dev/null @@ -1,83 +0,0 @@ -{% extends "base.html" %} - -{% block title %}Environments{% endblock %} - -{% block content %} -
    -

    System Properties

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Operating System
    Ubuntu12.04.5 LTS 64-bithttp://www.ubuntu.com/Free software licenses (mainly GPL)
    Database
    MySQL5.5.40http://www.mysql.com/GPL (version 2) or proprietary
    Python
    Python2.7.3http://www.python.org/Python Software Foundation License
    Flask0.9http://flask.pocoo.org/BSD
    Jinja22.6http://jinja.pocoo.org/BSD
    NumPy1.7.0http://www.numpy.org/BSD-new
    SciPy0.11.0http://www.scipy.org/BSD-new
    JavaScript / CSS
    jQuery1.10.2http://jquery.com/MIT
    Bootstrap2.3.1http://getbootstrap.com/MIT License (Apache License 2.0 prior to 3.1.0)
    DataTables1.9.4http://www.datatables.net/MIT
    CKEditor4.4.5http://ckeditor.com/GPL, LGPL and MPL
    -
    -{% endblock %} -- cgit v1.2.3 From da73052c84d5566bf3d221d90f93688db125181d Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 18:13:00 +0300 Subject: add facilities page --- wqflask/wqflask/markdown_routes.py | 10 ++++++++-- wqflask/wqflask/templates/facilities.html | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 wqflask/wqflask/templates/facilities.html diff --git a/wqflask/wqflask/markdown_routes.py b/wqflask/wqflask/markdown_routes.py index 073370c7..7765af36 100644 --- a/wqflask/wqflask/markdown_routes.py +++ b/wqflask/wqflask/markdown_routes.py @@ -13,6 +13,7 @@ references_blueprint = Blueprint("references_blueprint", __name__) environments_blueprint = Blueprint("environments_blueprint", __name__) links_blueprint = Blueprint("links_blueprint", __name__) policies_blueprint = Blueprint("policies_blueprint", __name__) +facilities_blueprint=Blueprint("facilities",__name__) #for debug github_url = ("https://raw.githubusercontent.com/" @@ -36,8 +37,8 @@ def render_markdown_table(file_name,github_url="https://raw.githubusercontent.co def render_markdown(file_name,github_url="https://raw.githubusercontent.com/Alexanderlacuna/gn-docs/feature/add-markdown-pages/"): - github_url = ("https://raw.githubusercontent.com/" - "genenetwork/gn-docs/master/") + # github_url = ("https://raw.githubusercontent.com/" + # "genenetwork/gn-docs/master/") md_content=requests.get(f"{github_url}{file_name}") """Try to fetch the file name from Github and if that fails, try to @@ -92,3 +93,8 @@ def policies(): return render_template( "links.html", rendered_markdown=render_markdown("general/policies/policies.md")), 200 + + +@facilities_blueprint.route("/") +def facilities(): + return render_template("facilities",rendered_markdown=render_markdown("general/policies/policies.md")), 200 \ No newline at end of file diff --git a/wqflask/wqflask/templates/facilities.html b/wqflask/wqflask/templates/facilities.html new file mode 100644 index 00000000..5be0c96d --- /dev/null +++ b/wqflask/wqflask/templates/facilities.html @@ -0,0 +1,21 @@ +{% extends "base.html" %} + +{% block title %}Facilities{% endblock %} + +{% block css %} + +{% endblock %} + +{% block content %} + + + +
    + {{ rendered_markdown|safe }} + +
    + + +{% endblock %} \ No newline at end of file -- cgit v1.2.3 From 6ab58b529aca9c12bb26865a1d81a15aaad1fd5d Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 18:14:03 +0300 Subject: add and register facilities blueprint --- wqflask/wqflask/__init__.py | 2 ++ wqflask/wqflask/markdown_routes.py | 8 ++++---- wqflask/wqflask/templates/base.html | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/wqflask/wqflask/__init__.py b/wqflask/wqflask/__init__.py index f44b4bfd..0b69ec40 100644 --- a/wqflask/wqflask/__init__.py +++ b/wqflask/wqflask/__init__.py @@ -11,6 +11,7 @@ from wqflask.markdown_routes import references_blueprint from wqflask.markdown_routes import links_blueprint from wqflask.markdown_routes import policies_blueprint from wqflask.markdown_routes import environments_blueprint +from wqflask.markdown_routes import facilities_blueprint app = Flask(__name__) @@ -27,6 +28,7 @@ app.register_blueprint(references_blueprint,url_prefix="/references") app.register_blueprint(links_blueprint,url_prefix="/links") app.register_blueprint(policies_blueprint,url_prefix="/policies") app.register_blueprint(environments_blueprint,url_prefix="/environments") +app.register_blueprint(facilities_blueprint,url_prefix="/facilities") @app.before_request def before_request(): diff --git a/wqflask/wqflask/markdown_routes.py b/wqflask/wqflask/markdown_routes.py index 7765af36..d00628b9 100644 --- a/wqflask/wqflask/markdown_routes.py +++ b/wqflask/wqflask/markdown_routes.py @@ -13,7 +13,7 @@ references_blueprint = Blueprint("references_blueprint", __name__) environments_blueprint = Blueprint("environments_blueprint", __name__) links_blueprint = Blueprint("links_blueprint", __name__) policies_blueprint = Blueprint("policies_blueprint", __name__) -facilities_blueprint=Blueprint("facilities",__name__) +facilities_blueprint=Blueprint("facilities_blueprint",__name__) #for debug github_url = ("https://raw.githubusercontent.com/" @@ -37,8 +37,8 @@ def render_markdown_table(file_name,github_url="https://raw.githubusercontent.co def render_markdown(file_name,github_url="https://raw.githubusercontent.com/Alexanderlacuna/gn-docs/feature/add-markdown-pages/"): - # github_url = ("https://raw.githubusercontent.com/" - # "genenetwork/gn-docs/master/") + github_url = ("https://raw.githubusercontent.com/" + "genenetwork/gn-docs/master/") md_content=requests.get(f"{github_url}{file_name}") """Try to fetch the file name from Github and if that fails, try to @@ -97,4 +97,4 @@ def policies(): @facilities_blueprint.route("/") def facilities(): - return render_template("facilities",rendered_markdown=render_markdown("general/policies/policies.md")), 200 \ No newline at end of file + return render_template("facilities.html",rendered_markdown=render_markdown("general/help/facilities.md")), 200 \ No newline at end of file diff --git a/wqflask/wqflask/templates/base.html b/wqflask/wqflask/templates/base.html index 8ba5d0d5..faa59deb 100644 --- a/wqflask/wqflask/templates/base.html +++ b/wqflask/wqflask/templates/base.html @@ -70,6 +70,7 @@
  • FAQ
  • Policies
  • Links
  • +
  • Facilities
  • Environments
  • GN1 News
  • -- cgit v1.2.3 From 4f449007d7f4afe4b141851772fa694ced4e77e3 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 21:28:37 +0300 Subject: refactor render_markdown function in wqflask/markdown_routes.py --- wqflask/wqflask/markdown_routes.py | 45 +++++++---------------------- wqflask/wqflask/static/new/css/markdown.css | 17 ++++++----- 2 files changed, 19 insertions(+), 43 deletions(-) diff --git a/wqflask/wqflask/markdown_routes.py b/wqflask/wqflask/markdown_routes.py index d00628b9..0445ded1 100644 --- a/wqflask/wqflask/markdown_routes.py +++ b/wqflask/wqflask/markdown_routes.py @@ -13,47 +13,22 @@ references_blueprint = Blueprint("references_blueprint", __name__) environments_blueprint = Blueprint("environments_blueprint", __name__) links_blueprint = Blueprint("links_blueprint", __name__) policies_blueprint = Blueprint("policies_blueprint", __name__) -facilities_blueprint=Blueprint("facilities_blueprint",__name__) +facilities_blueprint = Blueprint("facilities_blueprint", __name__) -#for debug -github_url = ("https://raw.githubusercontent.com/" - "genenetwork/gn-docs/master/general/glossary/glossary.md") +# for debug +# https://raw.githubusercontent.com/Alexanderlacuna/gn-docs/feature/add-markdown-pages/ - - -def render_markdown_table(file_name,github_url="https://raw.githubusercontent.com/Alexanderlacuna/gn-docs/feature/add-markdown-pages/"): - - md_content=md_content=requests.get(f"{github_url}{file_name}") - if md_content.status_code==200: - return markdown.markdown(md_content.content.decode("utf-8"), extensions=['tables']) - return (f"\nContent for {file_name} not available. " - "Please check " - "(here to see where content exists)" - "[https://github.com/genenetwork/gn-docs]. " - "Please reach out to the gn2 team to have a look at this") - - - - -def render_markdown(file_name,github_url="https://raw.githubusercontent.com/Alexanderlacuna/gn-docs/feature/add-markdown-pages/"): +def render_markdown(file_name): github_url = ("https://raw.githubusercontent.com/" "genenetwork/gn-docs/master/") - - md_content=requests.get(f"{github_url}{file_name}") - """Try to fetch the file name from Github and if that fails, try to -look for it inside the file system -po - """ - # github_url = ("https://raw.githubusercontent.com/" - # "genenetwork/gn-docs/master/") - # md_content = requests.get(f"{github_url}{file_name}") + + md_content = requests.get(f"{github_url}{file_name}") if md_content.status_code == 200: - # print(md_content.content.decode("utf-8")) - return markdown.Markdown().convert(md_content.content.decode("utf-8")) + return markdown.markdown(md_content.content.decode("utf-8"), extensions=['tables']) + # return markdown.Markdown().convert(md_content.content.decode("utf-8")) # TODO: Add fallback on our git server by checking the mirror. - # Content not available return (f"\nContent for {file_name} not available. " "Please check " @@ -78,7 +53,7 @@ def references(): @environments_blueprint.route("/") def environments(): - return render_template("environment.html", rendered_markdown=render_markdown_table("general/environments/environments.md")),200 + return render_template("environment.html", rendered_markdown=render_markdown_table("general/environments/environments.md")), 200 @links_blueprint.route("/") @@ -97,4 +72,4 @@ def policies(): @facilities_blueprint.route("/") def facilities(): - return render_template("facilities.html",rendered_markdown=render_markdown("general/help/facilities.md")), 200 \ No newline at end of file + return render_template("facilities.html", rendered_markdown=render_markdown("general/help/facilities.md")), 200 diff --git a/wqflask/wqflask/static/new/css/markdown.css b/wqflask/wqflask/static/new/css/markdown.css index ad665835..6d76c190 100644 --- a/wqflask/wqflask/static/new/css/markdown.css +++ b/wqflask/wqflask/static/new/css/markdown.css @@ -35,7 +35,7 @@ /*background: #27407a;*/ background: blue; border-radius: 20px; - + /*text-align: center;*/ @@ -49,18 +49,19 @@ .container { -width:80vw; -margin: auto; -max-width:80vw; - + width: 80vw; + margin: auto; + max-width: 80vw; + } .container p { font-size: 17px; - word-spacing: 0.2em; + word-spacing: 0.2em; } -@media(max-width:650px){ - .container{ + +@media(max-width:650px) { + .container { width: 100vw; } } \ No newline at end of file -- cgit v1.2.3 From 001b10077517b24e0eecc16819c77f0eb3c31dc1 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 21:33:39 +0300 Subject: PEP8 format and remove unnecessary comments --- wqflask/wqflask/markdown_routes.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/wqflask/wqflask/markdown_routes.py b/wqflask/wqflask/markdown_routes.py index 0445ded1..093dffeb 100644 --- a/wqflask/wqflask/markdown_routes.py +++ b/wqflask/wqflask/markdown_routes.py @@ -15,10 +15,6 @@ links_blueprint = Blueprint("links_blueprint", __name__) policies_blueprint = Blueprint("policies_blueprint", __name__) facilities_blueprint = Blueprint("facilities_blueprint", __name__) -# for debug -# https://raw.githubusercontent.com/Alexanderlacuna/gn-docs/feature/add-markdown-pages/ - - def render_markdown(file_name): github_url = ("https://raw.githubusercontent.com/" "genenetwork/gn-docs/master/") -- cgit v1.2.3 From f900a574be30590cca0e9c962bfecf25121e4ab0 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 21:40:15 +0300 Subject: delete environment endpoint in wqflask/views.py --- wqflask/wqflask/views.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 6cdce248..91d0842c 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -321,12 +321,6 @@ def credits(): #return render_template("docs.html", **doc.__dict__) return render_template("credits.html") -# @app.route("/environments") -# def environments(): -# doc = Docs("environments", request.args) -# return render_template("docs.html", **doc.__dict__) - #return render_template("environments.html", **doc.__dict__) - @app.route("/update_text", methods=('POST',)) def update_page(): update_text(request.form) -- cgit v1.2.3 From 8a74593bfda0d9e5e681046044c262713073164b Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 22:55:39 +0300 Subject: pep8 format for blue_print,url_prefix --- wqflask/wqflask/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/wqflask/wqflask/__init__.py b/wqflask/wqflask/__init__.py index 0b69ec40..0564cfa7 100644 --- a/wqflask/wqflask/__init__.py +++ b/wqflask/wqflask/__init__.py @@ -24,11 +24,11 @@ app.jinja_env.globals.update( # Registering blueprints app.register_blueprint(glossary_blueprint, url_prefix="/glossary") -app.register_blueprint(references_blueprint,url_prefix="/references") -app.register_blueprint(links_blueprint,url_prefix="/links") -app.register_blueprint(policies_blueprint,url_prefix="/policies") -app.register_blueprint(environments_blueprint,url_prefix="/environments") -app.register_blueprint(facilities_blueprint,url_prefix="/facilities") +app.register_blueprint(references_blueprint, url_prefix="/references") +app.register_blueprint(links_blueprint, url_prefix="/links") +app.register_blueprint(policies_blueprint, url_prefix="/policies") +app.register_blueprint(environments_blueprint, url_prefix="/environments") +app.register_blueprint(facilities_blueprint, url_prefix="/facilities") @app.before_request def before_request(): -- cgit v1.2.3 From 63c90d88499c2cda1b3da0960e179856aaba05c9 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 23:00:53 +0300 Subject: add doc string for render_markdown in wqflask/markdown_routes.py --- wqflask/wqflask/markdown_routes.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wqflask/wqflask/markdown_routes.py b/wqflask/wqflask/markdown_routes.py index 093dffeb..7e6c7948 100644 --- a/wqflask/wqflask/markdown_routes.py +++ b/wqflask/wqflask/markdown_routes.py @@ -16,6 +16,8 @@ policies_blueprint = Blueprint("policies_blueprint", __name__) facilities_blueprint = Blueprint("facilities_blueprint", __name__) def render_markdown(file_name): + """Try to fetch the file name from Github and if that fails, try to +look for it inside the file system """ github_url = ("https://raw.githubusercontent.com/" "genenetwork/gn-docs/master/") -- cgit v1.2.3 From b86f0f6200cb435cea91077352d5d95f610162a6 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 26 Nov 2020 23:35:00 +0300 Subject: use css block in templates and remove comments --- wqflask/wqflask/markdown_routes.py | 3 ++- wqflask/wqflask/static/new/css/markdown.css | 7 ------- wqflask/wqflask/templates/environment.html | 2 -- wqflask/wqflask/templates/facilities.html | 3 +-- wqflask/wqflask/templates/links.html | 4 +--- wqflask/wqflask/templates/policies.html | 4 +--- wqflask/wqflask/templates/references.html | 3 +-- 7 files changed, 6 insertions(+), 20 deletions(-) diff --git a/wqflask/wqflask/markdown_routes.py b/wqflask/wqflask/markdown_routes.py index 7e6c7948..25eabe66 100644 --- a/wqflask/wqflask/markdown_routes.py +++ b/wqflask/wqflask/markdown_routes.py @@ -15,6 +15,7 @@ links_blueprint = Blueprint("links_blueprint", __name__) policies_blueprint = Blueprint("policies_blueprint", __name__) facilities_blueprint = Blueprint("facilities_blueprint", __name__) + def render_markdown(file_name): """Try to fetch the file name from Github and if that fails, try to look for it inside the file system """ @@ -51,7 +52,7 @@ def references(): @environments_blueprint.route("/") def environments(): - return render_template("environment.html", rendered_markdown=render_markdown_table("general/environments/environments.md")), 200 + return render_template("environment.html", rendered_markdown=render_markdown("general/environments/environments.md")), 200 @links_blueprint.route("/") diff --git a/wqflask/wqflask/static/new/css/markdown.css b/wqflask/wqflask/static/new/css/markdown.css index 6d76c190..91b72cb8 100644 --- a/wqflask/wqflask/static/new/css/markdown.css +++ b/wqflask/wqflask/static/new/css/markdown.css @@ -15,8 +15,6 @@ margin-left: auto; } - - .github-btn { margin: 20px 10px; display: flex; @@ -32,13 +30,8 @@ transition-duration: 0.5s; padding: 8px 12px; color: #fff; - /*background: #27407a;*/ background: blue; border-radius: 20px; - - /*text-align: center;*/ - - } .github-btn a:hover { diff --git a/wqflask/wqflask/templates/environment.html b/wqflask/wqflask/templates/environment.html index a331d494..f378e0b8 100644 --- a/wqflask/wqflask/templates/environment.html +++ b/wqflask/wqflask/templates/environment.html @@ -19,7 +19,6 @@ {% endblock %} diff --git a/wqflask/wqflask/templates/facilities.html b/wqflask/wqflask/templates/facilities.html index 5be0c96d..63f110dd 100644 --- a/wqflask/wqflask/templates/facilities.html +++ b/wqflask/wqflask/templates/facilities.html @@ -3,7 +3,7 @@ {% block title %}Facilities{% endblock %} {% block css %} - + {% endblock %} {% block content %} @@ -17,5 +17,4 @@
    - {% endblock %} \ No newline at end of file diff --git a/wqflask/wqflask/templates/links.html b/wqflask/wqflask/templates/links.html index ef481de2..94d8eab7 100644 --- a/wqflask/wqflask/templates/links.html +++ b/wqflask/wqflask/templates/links.html @@ -3,7 +3,7 @@ {% block title %}Links{% endblock %} {% block css %} - + {% endblock %} {% block content %} @@ -16,6 +16,4 @@ {{ rendered_markdown|safe }}
    - - {% endblock %} \ No newline at end of file diff --git a/wqflask/wqflask/templates/policies.html b/wqflask/wqflask/templates/policies.html index ef481de2..94d8eab7 100644 --- a/wqflask/wqflask/templates/policies.html +++ b/wqflask/wqflask/templates/policies.html @@ -3,7 +3,7 @@ {% block title %}Links{% endblock %} {% block css %} - + {% endblock %} {% block content %} @@ -16,6 +16,4 @@ {{ rendered_markdown|safe }}
    - - {% endblock %} \ No newline at end of file diff --git a/wqflask/wqflask/templates/references.html b/wqflask/wqflask/templates/references.html index e2f152e3..8dcf4493 100644 --- a/wqflask/wqflask/templates/references.html +++ b/wqflask/wqflask/templates/references.html @@ -3,7 +3,7 @@ {% block title %}Reference{% endblock %} {% block css %} - + {% endblock %} {% block content %} @@ -17,5 +17,4 @@
    - {% endblock %} \ No newline at end of file -- cgit v1.2.3 From cd27138b6cc963450851417ef06303027da51419 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Fri, 27 Nov 2020 00:15:18 +0300 Subject: remove commented code --- wqflask/wqflask/markdown_routes.py | 1 - 1 file changed, 1 deletion(-) diff --git a/wqflask/wqflask/markdown_routes.py b/wqflask/wqflask/markdown_routes.py index 25eabe66..601845d7 100644 --- a/wqflask/wqflask/markdown_routes.py +++ b/wqflask/wqflask/markdown_routes.py @@ -26,7 +26,6 @@ look for it inside the file system """ if md_content.status_code == 200: return markdown.markdown(md_content.content.decode("utf-8"), extensions=['tables']) - # return markdown.Markdown().convert(md_content.content.decode("utf-8")) # TODO: Add fallback on our git server by checking the mirror. # Content not available return (f"\nContent for {file_name} not available. " -- cgit v1.2.3 From 78fd4d4a89a02fc5233a1f5bbdfd3946ec08f3b7 Mon Sep 17 00:00:00 2001 From: zsloan Date: Thu, 26 Nov 2020 16:06:59 -0600 Subject: Changed the way the chromosome colors for the "color by chr" manhattan plot option are stored to using a list comprehension on a list of the just the hex strings --- .../marker_regression/display_mapping_results.py | 32 ++++------------------ 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/wqflask/wqflask/marker_regression/display_mapping_results.py b/wqflask/wqflask/marker_regression/display_mapping_results.py index 87910401..08c2d750 100644 --- a/wqflask/wqflask/marker_regression/display_mapping_results.py +++ b/wqflask/wqflask/marker_regression/display_mapping_results.py @@ -75,32 +75,12 @@ MEDIUMPURPLE = ImageColor.getrgb("mediumpurple") # ---- END: Define common colours ---- # # ZS: List of distinct colors for manhattan plot if user selects "varied" -DISTINCT_COLOR_LIST = [ - ImageColor.getrgb("#FF0000"), - ImageColor.getrgb("#00FF00"), - ImageColor.getrgb("#0000FF"), - ImageColor.getrgb("#FFFF00"), - ImageColor.getrgb("#FF00FF"), - ImageColor.getrgb("#00FFFF"), - ImageColor.getrgb("#000000"), - ImageColor.getrgb("#800000"), - ImageColor.getrgb("#008000"), - ImageColor.getrgb("#000080"), - ImageColor.getrgb("#808000"), - ImageColor.getrgb("#800080"), - ImageColor.getrgb("#008080"), - ImageColor.getrgb("#808080"), - ImageColor.getrgb("#C00000"), - ImageColor.getrgb("#00C000"), - ImageColor.getrgb("#0000C0"), - ImageColor.getrgb("#C0C000"), - ImageColor.getrgb("#C000C0"), - ImageColor.getrgb("#00C0C0"), - ImageColor.getrgb("#C0C0C0"), - ImageColor.getrgb("#400000"), - ImageColor.getrgb("#004000"), - ImageColor.getrgb("#000040"), -] +COLOR_CODES = ["#FF0000", "#00FF00", "#0000FF", "#FFFF00", "#FF00FF", "#00FFFF", + "#000000", "#800000", "#008000", "#000080", "#808000", "#800080", + "#008080", "#808080", "#C00000", "#00C000", "#0000C0", "#C0C000", + "#C000C0", "#00C0C0", "#C0C0C0", "#400000", "#004000", "#000040"] + +DISTINCT_COLOR_LIST = [ImageColor.getrgb(color) for color in COLOR_CODES] # ---- FONT FILES ---- # VERDANA_FILE = "./wqflask/static/fonts/verdana.ttf" -- cgit v1.2.3 From e396706f5c2bbb1bef21bcc8180565015aee3fb0 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Fri, 27 Nov 2020 12:59:18 +0300 Subject: add edit image --- wqflask/wqflask/static/images/edit.png | Bin 0 -> 2452 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 wqflask/wqflask/static/images/edit.png diff --git a/wqflask/wqflask/static/images/edit.png b/wqflask/wqflask/static/images/edit.png new file mode 100644 index 00000000..571b08cd Binary files /dev/null and b/wqflask/wqflask/static/images/edit.png differ -- cgit v1.2.3 From 5c4a2727f013785c8818864c0520321ef8d60dce Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Fri, 27 Nov 2020 13:00:47 +0300 Subject: add new github button and css --- wqflask/wqflask/static/new/css/markdown.css | 27 +++++++++++++-------------- wqflask/wqflask/templates/environment.html | 11 ++++++++--- wqflask/wqflask/templates/facilities.html | 12 ++++++++---- wqflask/wqflask/templates/glossary.html | 11 ++++++++--- wqflask/wqflask/templates/links.html | 11 ++++++++--- wqflask/wqflask/templates/policies.html | 12 ++++++++---- wqflask/wqflask/templates/references.html | 19 +++++++++---------- 7 files changed, 62 insertions(+), 41 deletions(-) diff --git a/wqflask/wqflask/static/new/css/markdown.css b/wqflask/wqflask/static/new/css/markdown.css index 91b72cb8..311962c1 100644 --- a/wqflask/wqflask/static/new/css/markdown.css +++ b/wqflask/wqflask/static/new/css/markdown.css @@ -15,29 +15,28 @@ margin-left: auto; } -.github-btn { +.github-btn-container { margin: 20px 10px; display: flex; width: 90vw; justify-content: flex-end; } -.github-btn a { - display: inline-block; - align-self: center; - text-decoration: none; - transition-property: all; - transition-duration: 0.5s; - padding: 8px 12px; - color: #fff; - background: blue; - border-radius: 20px; +.github-btn { + border: 3px solid #357ebd; + background: lightgrey; + padding: 6px 8px; + border-radius: 16px; } -.github-btn a:hover { - - background: #333; +.github-btn a { + font-weight: bold; + color: #357ebd; +} +.github-btn a img { + height: 40px; + width: 40px; } diff --git a/wqflask/wqflask/templates/environment.html b/wqflask/wqflask/templates/environment.html index f378e0b8..183518a5 100644 --- a/wqflask/wqflask/templates/environment.html +++ b/wqflask/wqflask/templates/environment.html @@ -8,9 +8,14 @@ {% block content %} - +
    {{ rendered_markdown|safe }}
    diff --git a/wqflask/wqflask/templates/facilities.html b/wqflask/wqflask/templates/facilities.html index 63f110dd..652746a7 100644 --- a/wqflask/wqflask/templates/facilities.html +++ b/wqflask/wqflask/templates/facilities.html @@ -8,10 +8,14 @@ {% block content %} - - +
    {{ rendered_markdown|safe }} diff --git a/wqflask/wqflask/templates/glossary.html b/wqflask/wqflask/templates/glossary.html index 395bcfea..f536d977 100644 --- a/wqflask/wqflask/templates/glossary.html +++ b/wqflask/wqflask/templates/glossary.html @@ -8,9 +8,14 @@ {% block content %} - +
    {{ rendered_markdown|safe }} diff --git a/wqflask/wqflask/templates/links.html b/wqflask/wqflask/templates/links.html index 94d8eab7..cf524496 100644 --- a/wqflask/wqflask/templates/links.html +++ b/wqflask/wqflask/templates/links.html @@ -8,9 +8,14 @@ {% block content %} - +
    {{ rendered_markdown|safe }} diff --git a/wqflask/wqflask/templates/policies.html b/wqflask/wqflask/templates/policies.html index 94d8eab7..420493ad 100644 --- a/wqflask/wqflask/templates/policies.html +++ b/wqflask/wqflask/templates/policies.html @@ -8,10 +8,14 @@ {% block content %} - - +
    {{ rendered_markdown|safe }} diff --git a/wqflask/wqflask/templates/references.html b/wqflask/wqflask/templates/references.html index 8dcf4493..caf87244 100644 --- a/wqflask/wqflask/templates/references.html +++ b/wqflask/wqflask/templates/references.html @@ -1,20 +1,19 @@ {% extends "base.html" %} - {% block title %}Reference{% endblock %} - {% block css %} {% endblock %} - {% block content %} - - - +
    - {{ rendered_markdown|safe }} - + {{ rendered_markdown|safe }}
    {% endblock %} \ No newline at end of file -- cgit v1.2.3 From a4842a8d54f891dcb59d29aa53a0e442f8f0e0c2 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Fri, 27 Nov 2020 13:33:47 +0300 Subject: update to edit text in static templates --- wqflask/wqflask/templates/environment.html | 2 +- wqflask/wqflask/templates/facilities.html | 2 +- wqflask/wqflask/templates/glossary.html | 2 +- wqflask/wqflask/templates/links.html | 2 +- wqflask/wqflask/templates/policies.html | 2 +- wqflask/wqflask/templates/references.html | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wqflask/wqflask/templates/environment.html b/wqflask/wqflask/templates/environment.html index 183518a5..94b31464 100644 --- a/wqflask/wqflask/templates/environment.html +++ b/wqflask/wqflask/templates/environment.html @@ -11,7 +11,7 @@
    diff --git a/wqflask/wqflask/templates/facilities.html b/wqflask/wqflask/templates/facilities.html index 652746a7..a022b657 100644 --- a/wqflask/wqflask/templates/facilities.html +++ b/wqflask/wqflask/templates/facilities.html @@ -11,7 +11,7 @@
    diff --git a/wqflask/wqflask/templates/glossary.html b/wqflask/wqflask/templates/glossary.html index f536d977..752c4b12 100644 --- a/wqflask/wqflask/templates/glossary.html +++ b/wqflask/wqflask/templates/glossary.html @@ -11,7 +11,7 @@
    diff --git a/wqflask/wqflask/templates/links.html b/wqflask/wqflask/templates/links.html index cf524496..072e8429 100644 --- a/wqflask/wqflask/templates/links.html +++ b/wqflask/wqflask/templates/links.html @@ -11,7 +11,7 @@
    diff --git a/wqflask/wqflask/templates/policies.html b/wqflask/wqflask/templates/policies.html index 420493ad..4e0985d3 100644 --- a/wqflask/wqflask/templates/policies.html +++ b/wqflask/wqflask/templates/policies.html @@ -11,7 +11,7 @@
    diff --git a/wqflask/wqflask/templates/references.html b/wqflask/wqflask/templates/references.html index caf87244..f723a1e8 100644 --- a/wqflask/wqflask/templates/references.html +++ b/wqflask/wqflask/templates/references.html @@ -7,7 +7,7 @@
    -- cgit v1.2.3 From 1cabb7810a8b2ab5171e1547e154244978fb37d4 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Fri, 27 Nov 2020 14:23:21 +0300 Subject: edit css for static page --- wqflask/wqflask/static/new/css/markdown.css | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wqflask/wqflask/static/new/css/markdown.css b/wqflask/wqflask/static/new/css/markdown.css index 311962c1..dca3e31d 100644 --- a/wqflask/wqflask/static/new/css/markdown.css +++ b/wqflask/wqflask/static/new/css/markdown.css @@ -23,13 +23,17 @@ } .github-btn { + display: flex; + justify-content: center; border: 3px solid #357ebd; background: lightgrey; - padding: 6px 8px; + padding: 3px 4px; + width: 200px; border-radius: 16px; } .github-btn a { + align-self: center; font-weight: bold; color: #357ebd; } @@ -37,6 +41,7 @@ .github-btn a img { height: 40px; width: 40px; + padding-left:5px; } -- cgit v1.2.3 From 7f35213b64707e7c61affb6fa376f561200ac1d6 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Fri, 27 Nov 2020 19:59:17 +0300 Subject: move tests to unit folder --- .../marker_regression/test_gemma_mapping.py | 205 +++++++++++++++ .../marker_regression/test_plink_mapping.py | 84 ++++++ .../marker_regression/test_qtlreaper_mapping.py | 21 ++ .../wqflask/marker_regression/test_rqtl_mapping.py | 48 ++++ .../wqflask/marker_regression/test_run_mapping.py | 284 +++++++++++++++++++++ .../marker_regression/test_gemma_mapping.py | 205 --------------- .../marker_regression/test_plink_mapping.py | 84 ------ .../marker_regression/test_qtlreaper_mapping.py | 21 -- .../wqflask/marker_regression/test_rqtl_mapping.py | 48 ---- .../wqflask/marker_regression/test_run_mapping.py | 284 --------------------- 10 files changed, 642 insertions(+), 642 deletions(-) create mode 100644 wqflask/tests/unit/wqflask/marker_regression/test_gemma_mapping.py create mode 100644 wqflask/tests/unit/wqflask/marker_regression/test_plink_mapping.py create mode 100644 wqflask/tests/unit/wqflask/marker_regression/test_qtlreaper_mapping.py create mode 100644 wqflask/tests/unit/wqflask/marker_regression/test_rqtl_mapping.py create mode 100644 wqflask/tests/unit/wqflask/marker_regression/test_run_mapping.py delete mode 100644 wqflask/tests/wqflask/marker_regression/test_gemma_mapping.py delete mode 100644 wqflask/tests/wqflask/marker_regression/test_plink_mapping.py delete mode 100644 wqflask/tests/wqflask/marker_regression/test_qtlreaper_mapping.py delete mode 100644 wqflask/tests/wqflask/marker_regression/test_rqtl_mapping.py delete mode 100644 wqflask/tests/wqflask/marker_regression/test_run_mapping.py diff --git a/wqflask/tests/unit/wqflask/marker_regression/test_gemma_mapping.py b/wqflask/tests/unit/wqflask/marker_regression/test_gemma_mapping.py new file mode 100644 index 00000000..5b621264 --- /dev/null +++ b/wqflask/tests/unit/wqflask/marker_regression/test_gemma_mapping.py @@ -0,0 +1,205 @@ +# test for wqflask/marker_regression/gemma_mapping.py +import unittest +import random +from unittest import mock +from wqflask.marker_regression.gemma_mapping import run_gemma +from wqflask.marker_regression.gemma_mapping import gen_pheno_txt_file +from wqflask.marker_regression.gemma_mapping import gen_covariates_file +from wqflask.marker_regression.gemma_mapping import parse_gemma_output +from wqflask.marker_regression.gemma_mapping import parse_loco_output + + +class AttributeSetter: + def __init__(self, obj): + for key, val in obj.items(): + setattr(self, key, val) + + +class MockGroup(AttributeSetter): + def get_samplelist(self): + return None + + +class TestGemmaMapping(unittest.TestCase): + + @mock.patch("wqflask.marker_regression.gemma_mapping.parse_loco_output") + def test_run_gemma_firstrun_set_false(self, mock_parse_loco): + """add tests for gemma function where first run is set to false""" + dataset = AttributeSetter( + {"group": AttributeSetter({"genofile": "genofile.geno"})}) + + output_file = "file1" + mock_parse_loco.return_value = [] + this_trait = AttributeSetter({"name": "t1"}) + + result = run_gemma(this_trait=this_trait, this_dataset=dataset, samples=[], vals=[ + ], covariates="", use_loco=True, first_run=False, output_files=output_file) + + expected_results = ([], "file1") + self.assertEqual(expected_results, result) + + @mock.patch("wqflask.marker_regression.gemma_mapping.webqtlConfig.GENERATED_IMAGE_DIR", "/home/user/img") + @mock.patch("wqflask.marker_regression.gemma_mapping.GEMMAOPTS", "-debug") + @mock.patch("wqflask.marker_regression.gemma_mapping.GEMMA_WRAPPER_COMMAND", "ghc") + @mock.patch("wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/user/data/") + @mock.patch("wqflask.marker_regression.gemma_mapping.parse_loco_output") + @mock.patch("wqflask.marker_regression.gemma_mapping.logger") + @mock.patch("wqflask.marker_regression.gemma_mapping.flat_files") + @mock.patch("wqflask.marker_regression.gemma_mapping.gen_covariates_file") + @mock.patch("wqflask.marker_regression.run_mapping.random.choice") + @mock.patch("wqflask.marker_regression.gemma_mapping.os") + @mock.patch("wqflask.marker_regression.gemma_mapping.gen_pheno_txt_file") + def test_run_gemma_firstrun_set_true(self, mock_gen_pheno_txt, mock_os, mock_choice, mock_gen_covar, mock_flat_files, mock_logger, mock_parse_loco): + """add tests for run_gemma where first run is set to true""" + chromosomes = [] + for i in range(1, 5): + chromosomes.append(AttributeSetter({"name": f"CH{i}"})) + chromo = AttributeSetter({"chromosomes": chromosomes}) + dataset_group = MockGroup( + {"name": "GP1", "genofile": "file_geno"}) + dataset = AttributeSetter({"group": dataset_group, "name": "dataset1_name", + "species": AttributeSetter({"chromosomes": chromo})}) + trait = AttributeSetter({"name": "trait1"}) + samples = [] + mock_gen_pheno_txt.return_value = None + mock_os.path.isfile.return_value = True + mock_gen_covar.return_value = None + mock_choice.return_value = "R" + mock_flat_files.return_value = "/home/genotype/bimbam" + mock_parse_loco.return_value = [] + results = run_gemma(this_trait=trait, this_dataset=dataset, samples=[ + ], vals=[], covariates="", use_loco=True) + system_calls = [mock.call('ghc --json -- -debug -g /home/genotype/bimbam/file_geno.txt -p /home/user/data//gn2/trait1_dataset1_name_pheno.txt -a /home/genotype/bimbam/file_snps.txt -gk > /home/user/data//gn2/GP1_K_RRRRRR.json'), + mock.call('ghc --json --input /home/user/data//gn2/GP1_K_RRRRRR.json -- -debug -a /home/genotype/bimbam/file_snps.txt -lmm 2 -g /home/genotype/bimbam/file_geno.txt -p /home/user/data//gn2/trait1_dataset1_name_pheno.txt > /home/user/data//gn2/GP1_GWA_RRRRRR.json')] + mock_os.system.assert_has_calls(system_calls) + mock_gen_pheno_txt.assert_called_once() + mock_parse_loco.assert_called_once_with(dataset, "GP1_GWA_RRRRRR") + mock_os.path.isfile.assert_called_once_with( + ('/home/user/imgfile_output.assoc.txt')) + self.assertEqual(mock_logger.debug.call_count, 2) + self.assertEqual(mock_flat_files.call_count, 4) + self.assertEqual(results, ([], "GP1_GWA_RRRRRR")) + + @mock.patch("wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/user/data") + def test_gen_pheno_txt_file(self): + """add tests for generating pheno txt file""" + with mock.patch("builtins.open", mock.mock_open())as mock_open: + gen_pheno_txt_file(this_dataset={}, genofile_name="", vals=[ + "x", "w", "q", "we", "R"], trait_filename="fitr.re") + mock_open.assert_called_once_with( + '/home/user/data/gn2/fitr.re.txt', 'w') + filehandler = mock_open() + values = ["x", "w", "q", "we", "R"] + write_calls = [mock.call('NA\n'), mock.call('w\n'), mock.call( + 'q\n'), mock.call('we\n'), mock.call('R\n')] + + filehandler.write.assert_has_calls(write_calls) + + @mock.patch("wqflask.marker_regression.gemma_mapping.flat_files") + @mock.patch("wqflask.marker_regression.gemma_mapping.create_trait") + @mock.patch("wqflask.marker_regression.gemma_mapping.create_dataset") + def test_gen_covariates_file(self, create_dataset, create_trait, flat_files): + """add tests for generating covariates files""" + covariates = "X1:X2,Y1:Y2,M1:M3,V1:V2" + samplelist = ["X1", "X2", "X3", "X4"] + create_dataset_side_effect = [] + create_trait_side_effect = [] + + for i in range(4): + create_dataset_side_effect.append(AttributeSetter({"name": f'name_{i}'})) + create_trait_side_effect.append( + AttributeSetter({"data": [f'data_{i}']})) + + create_dataset.side_effect = create_trait_side_effect + create_trait.side_effect = create_trait_side_effect + + group = MockGroup({"name": "group_X", "samplelist": samplelist}) + this_dataset = AttributeSetter({"group": group}) + flat_files.return_value = "Home/Genenetwork" + + with mock.patch("builtins.open", mock.mock_open())as mock_open: + gen_covariates_file(this_dataset=this_dataset, covariates=covariates, + samples=["x1", "x2", "X3"]) + + create_dataset.assert_has_calls( + [mock.call('X2'), mock.call('Y2'), mock.call('M3'), mock.call('V2')]) + mock_calls = [] + trait_names = ["X1", "Y1", "M1", "V1"] + + for i, trait in enumerate(create_trait_side_effect): + mock_calls.append( + mock.call(dataset=trait, name=trait_names[i], cellid=None)) + + create_trait.assert_has_calls(mock_calls) + + flat_files.assert_called_once_with('mapping') + mock_open.assert_called_once_with( + 'Home/Genenetwork/group_X_covariates.txt', 'w') + filehandler = mock_open() + filehandler.write.assert_has_calls([mock.call( + '-9\t'), mock.call('-9\t'), mock.call('-9\t'), mock.call('-9\t'), mock.call('\n')]) + + @mock.patch("wqflask.marker_regression.gemma_mapping.webqtlConfig.GENERATED_IMAGE_DIR", "/home/user/img/") + def test_parse_gemma_output(self): + """add test for generating gemma output with obj returned""" + file = """X/Y\t gn2\t21\tQ\tE\tA\tP\tMMB\tCDE\t0.5 +X/Y\tgn2\t21322\tQ\tE\tA\tP\tMMB\tCDE\t0.5 +chr\tgn1\t12312\tQ\tE\tA\tP\tMMB\tCDE\t0.7 +X\tgn7\t2324424\tQ\tE\tA\tP\tMMB\tCDE\t0.4 +125\tgn9\t433575\tQ\tE\tA\tP\tMMB\tCDE\t0.67 +""" + with mock.patch("builtins.open", mock.mock_open(read_data=file)) as mock_open: + results = parse_gemma_output(genofile_name="gema_file") + expected = [{'name': ' gn2', 'chr': 'X/Y', 'Mb': 2.1e-05, 'p_value': 0.5, 'lod_score': 0.3010299956639812}, {'name': 'gn2', 'chr': 'X/Y', 'Mb': 0.021322, 'p_value': 0.5, 'lod_score': 0.3010299956639812}, + {'name': 'gn7', 'chr': 'X', 'Mb': 2.324424, 'p_value': 0.4, 'lod_score': 0.3979400086720376}, {'name': 'gn9', 'chr': 125, 'Mb': 0.433575, 'p_value': 0.67, 'lod_score': 0.17392519729917352}] + mock_open.assert_called_once_with( + "/home/user/img/gema_file_output.assoc.txt") + self.assertEqual(results, expected) + + @mock.patch("wqflask.marker_regression.gemma_mapping.webqtlConfig.GENERATED_IMAGE_DIR", "/home/user/img") + def test_parse_gemma_output_with_empty_return(self): + """add tests for parse gemma output where nothing returned""" + output_file_results = """chr\t today""" + with mock.patch("builtins.open", mock.mock_open(read_data=output_file_results)) as mock_open: + results = parse_gemma_output(genofile_name="gema_file") + self.assertEqual(results, []) + + @mock.patch("wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/tmp") + @mock.patch("wqflask.marker_regression.gemma_mapping.os") + @mock.patch("wqflask.marker_regression.gemma_mapping.json") + def test_parse_loco_outputfile_found(self, mock_json, mock_os): + """add tests for parse loco output file found""" + mock_json.load.return_value = { + "files": [["file_name", "user", "~/file1"], + ["file_name", "user", "~/file2"]] + } + return_file_1 = """X/Y\t L1\t21\tQ\tE\tA\tP\tMMB\tCDE\t0.5 +X/Y\tL2\t21322\tQ\tE\tA\tP\tMMB\tCDE\t0.5 +chr\tL3\t12312\tQ\tE\tA\tP\tMMB\tCDE\t0.7""" + return_file_2 = """chr\tother\t21322\tQ\tE\tA\tP\tMMB\tCDE\t0.5""" + mock_os.path.isfile.return_value = True + file_to_write = """{"files":["file_1","file_2"]}""" + with mock.patch("builtins.open") as mock_open: + + handles = (mock.mock_open(read_data="gwas").return_value, mock.mock_open( + read_data=return_file_1).return_value, mock.mock_open(read_data=return_file_2).return_value) + mock_open.side_effect = handles + results = parse_loco_output( + this_dataset={}, gwa_output_filename=".xw/") + expected_results = [{'name': ' L1', 'chr': 'X/Y', 'Mb': 2.1e-05, 'p_value': 0.5, 'lod_score': 0.3010299956639812}, { + 'name': 'L2', 'chr': 'X/Y', 'Mb': 0.021322, 'p_value': 0.5, 'lod_score': 0.3010299956639812}] + + self.assertEqual(expected_results, results) + + @mock.patch("wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/tmp") + @mock.patch("wqflask.marker_regression.gemma_mapping.os") + def test_parse_loco_outputfile_not_found(self, mock_os): + """add tests for parse loco output where output file not found""" + + mock_os.path.isfile.return_value = False + file_to_write = """{"files":["file_1","file_2"]}""" + + with mock.patch("builtins.open", mock.mock_open(read_data=file_to_write)) as mock_open: + results = parse_loco_output( + this_dataset={}, gwa_output_filename=".xw/") + self.assertEqual(results, []) diff --git a/wqflask/tests/unit/wqflask/marker_regression/test_plink_mapping.py b/wqflask/tests/unit/wqflask/marker_regression/test_plink_mapping.py new file mode 100644 index 00000000..428f45b9 --- /dev/null +++ b/wqflask/tests/unit/wqflask/marker_regression/test_plink_mapping.py @@ -0,0 +1,84 @@ +# test for wqflask/marker_regression/plink_mapping.py +import unittest +from unittest import mock +from wqflask.marker_regression.plink_mapping import build_line_list +from wqflask.marker_regression.plink_mapping import get_samples_from_ped_file +from wqflask.marker_regression.plink_mapping import flat_files +from wqflask.marker_regression.plink_mapping import gen_pheno_txt_file_plink +from wqflask.marker_regression.plink_mapping import parse_plink_output + + +class AttributeSetter: + def __init__(self, obj): + for key, val in obj.items(): + setattr(self, key, val) +class TestPlinkMapping(unittest.TestCase): + + def test_build_line_list(self): + """testing for building line list""" + line_1 = "this is line one test" + irregular_line = " this is an, irregular line " + exp_line1 = ["this", "is", "line", "one", "test"] + + results = build_line_list(irregular_line) + self.assertEqual(exp_line1, build_line_list(line_1)) + self.assertEqual([], build_line_list()) + self.assertEqual(["this", "is", "an,", "irregular", "line"], results) + + @mock.patch("wqflask.marker_regression.plink_mapping.flat_files") + def test_get_samples_from_ped_file(self, mock_flat_files): + """test for getting samples from ped file""" + dataset = AttributeSetter({"group": AttributeSetter({"name": "n_1"})}) + file_sample = """Expected_1\tline test +Expected_2\there + Expected_3\tthree""" + mock_flat_files.return_value = "/home/user/" + with mock.patch("builtins.open", mock.mock_open(read_data=file_sample)) as mock_open: + results = get_samples_from_ped_file(dataset) + mock_flat_files.assert_called_once_with("mapping") + mock_open.assert_called_once_with("/home/user/n_1.ped", "r") + self.assertEqual( + ["Expected_1", "Expected_2", "Expected_3"], results) + + @mock.patch("wqflask.marker_regression.plink_mapping.TMPDIR", "/home/user/data/") + @mock.patch("wqflask.marker_regression.plink_mapping.get_samples_from_ped_file") + def test_gen_pheno_txt_file_plink(self, mock_samples): + """test for getting gen_pheno txt file""" + mock_samples.return_value = ["Expected_1", "Expected_2", "Expected_3"] + + trait = AttributeSetter({"name": "TX"}) + dataset = AttributeSetter({"group": AttributeSetter({"name": "n_1"})}) + vals = ["value=K1", "value=K2", "value=K3"] + with mock.patch("builtins.open", mock.mock_open()) as mock_open: + results = gen_pheno_txt_file_plink(this_trait=trait, dataset=dataset, + vals=vals, pheno_filename="ph_file") + mock_open.assert_called_once_with( + "/home/user/data/ph_file.txt", "wb") + filehandler = mock_open() + calls_expected = [mock.call('FID\tIID\tTX\n'), + mock.call('Expected_1\tExpected_1\tK1\nExpected_2\tExpected_2\tK2\nExpected_3\tExpected_3\tK3\n')] + + filehandler.write.assert_has_calls(calls_expected) + + filehandler.close.assert_called_once() + + @mock.patch("wqflask.marker_regression.plink_mapping.TMPDIR", "/home/user/data/") + @mock.patch("wqflask.marker_regression.plink_mapping.build_line_list") + def test_parse_plink_output(self, mock_line_list): + """test for parsing plink output""" + chromosomes = [0, 34, 110, 89, 123, 23, 2] + species = AttributeSetter( + {"name": "S1", "chromosomes": AttributeSetter({"chromosomes": chromosomes})}) + + fake_file = """0 AACCAT T98.6 0.89\n2 AATA B45 0.3\n121 ACG B56.4 NA""" + + mock_line_list.side_effect = [["0", "AACCAT", "T98.6", "0.89"], [ + "2", "AATA", "B45", "0.3"], ["121", "ACG", "B56.4", "NA"]] + with mock.patch("builtins.open", mock.mock_open(read_data=fake_file)) as mock_open: + parse_results = parse_plink_output( + output_filename="P1_file", species=species) + mock_open.assert_called_once_with( + "/home/user/data/P1_file.qassoc", "rb") + expected = (2, {'AACCAT': 0.89, 'AATA': 0.3}) + + self.assertEqual(parse_results, expected) diff --git a/wqflask/tests/unit/wqflask/marker_regression/test_qtlreaper_mapping.py b/wqflask/tests/unit/wqflask/marker_regression/test_qtlreaper_mapping.py new file mode 100644 index 00000000..b47f877a --- /dev/null +++ b/wqflask/tests/unit/wqflask/marker_regression/test_qtlreaper_mapping.py @@ -0,0 +1,21 @@ +import unittest +from unittest import mock +from wqflask.marker_regression.qtlreaper_mapping import gen_pheno_txt_file + +#issues some methods in genofile object are not defined +#modify samples should equal to vals +class TestQtlReaperMapping(unittest.TestCase): + @mock.patch("wqflask.marker_regression.qtlreaper_mapping.TEMPDIR", "/home/user/data") + def test_gen_pheno_txt_file(self): + vals=["V1","x","V4","V3","x"] + samples=["S1","S2","S3","S4","S5"] + trait_filename="trait_file" + with mock.patch("builtins.open", mock.mock_open())as mock_open: + gen_pheno_txt_file(samples=samples,vals=vals,trait_filename=trait_filename) + mock_open.assert_called_once_with("/home/user/data/gn2/trait_file.txt","w") + filehandler=mock_open() + write_calls= [mock.call('Trait\t'),mock.call('S1\tS3\tS4\n'),mock.call('T1\t'),mock.call('V1\tV4\tV3')] + + filehandler.write.assert_has_calls(write_calls) + + diff --git a/wqflask/tests/unit/wqflask/marker_regression/test_rqtl_mapping.py b/wqflask/tests/unit/wqflask/marker_regression/test_rqtl_mapping.py new file mode 100644 index 00000000..69f53721 --- /dev/null +++ b/wqflask/tests/unit/wqflask/marker_regression/test_rqtl_mapping.py @@ -0,0 +1,48 @@ +import unittest +from unittest import mock +from wqflask import app +from wqflask.marker_regression.rqtl_mapping import get_trait_data_type +from wqflask.marker_regression.rqtl_mapping import sanitize_rqtl_phenotype +from wqflask.marker_regression.rqtl_mapping import sanitize_rqtl_names + +class TestRqtlMapping(unittest.TestCase): + + def setUp(self): + self.app_context=app.app_context() + self.app_context.push() + + def tearDown(self): + self.app_context.pop() + + + @mock.patch("wqflask.marker_regression.rqtl_mapping.g") + @mock.patch("wqflask.marker_regression.rqtl_mapping.logger") + def test_get_trait_data(self,mock_logger,mock_db): + """test for getting trait data_type return True""" + caller_value="""SELECT value FROM TraitMetadata WHERE type='trait_data_type'""" + mock_db.db.execute.return_value.fetchone.return_value=["""{"type":"trait_data_type","name":"T1","traid_id":"fer434f"}"""] + results=get_trait_data_type("traid_id") + mock_db.db.execute.assert_called_with(caller_value) + self.assertEqual(results,"fer434f") + + def test_sanitize_rqtl_phenotype(self): + """test for sanitizing rqtl phenotype""" + vals=['f',"x","r","x","x"] + results=sanitize_rqtl_phenotype(vals) + expected_phenotype_string='c(f,NA,r,NA,NA)' + + self.assertEqual(results,expected_phenotype_string) + + def test_sanitize_rqtl_names(self): + """test for sanitzing rqtl names""" + vals=['f',"x","r","x","x"] + expected_sanitized_name="c('f',NA,'r',NA,NA)" + results=sanitize_rqtl_names(vals) + self.assertEqual(expected_sanitized_name,results) + + + + + + + diff --git a/wqflask/tests/unit/wqflask/marker_regression/test_run_mapping.py b/wqflask/tests/unit/wqflask/marker_regression/test_run_mapping.py new file mode 100644 index 00000000..4129cc0c --- /dev/null +++ b/wqflask/tests/unit/wqflask/marker_regression/test_run_mapping.py @@ -0,0 +1,284 @@ +import unittest +import datetime +from unittest import mock + +from wqflask.marker_regression.run_mapping import get_genofile_samplelist +from wqflask.marker_regression.run_mapping import geno_db_exists +from wqflask.marker_regression.run_mapping import write_input_for_browser +from wqflask.marker_regression.run_mapping import export_mapping_results +from wqflask.marker_regression.run_mapping import trim_markers_for_figure +from wqflask.marker_regression.run_mapping import get_perm_strata +from wqflask.marker_regression.run_mapping import get_chr_lengths + + +class AttributeSetter: + def __init__(self, obj): + for k, v in obj.items(): + setattr(self, k, v) + + +class MockGroup(AttributeSetter): + + def get_genofiles(self): + return [{"location": "~/genofiles/g1_file", "sample_list": ["S1", "S2", "S3", "S4"]}] + + +class TestRunMapping(unittest.TestCase): + def setUp(self): + + self.group = MockGroup( + {"genofile": "~/genofiles/g1_file", "name": "GP1_", "species": "Human"}) + chromosomes = { + "3": AttributeSetter({ + "name": "C1", + "length": "0.04" + }), + "4": AttributeSetter({ + "name": "C2", + "length": "0.03" + }), + "5": AttributeSetter({ + "name": "C4", + "length": "0.01" + }) + } + self.dataset = AttributeSetter( + {"fullname": "dataser_1", "group": self.group, "type": "ProbeSet"}) + + self.chromosomes = AttributeSetter({"chromosomes": chromosomes}) + self.trait = AttributeSetter( + {"symbol": "IGFI", "chr": "X1", "mb": 123313}) + + def tearDown(self): + self.dataset = AttributeSetter( + {"group": {"location": "~/genofiles/g1_file"}}) + + def test_get_genofile_samplelist(self): + + results_1 = get_genofile_samplelist(self.dataset) + self.assertEqual(results_1, ["S1", "S2", "S3", "S4"]) + self.group.genofile = "~/genofiles/g2_file" + result_2 = get_genofile_samplelist(self.dataset) + self.assertEqual(result_2, []) + + @mock.patch("wqflask.marker_regression.run_mapping.data_set") + def test_if_geno_db_exists(self, mock_data_set): + mock_data_set.create_dataset.side_effect = [ + AttributeSetter({}), Exception()] + results_no_error = geno_db_exists(self.dataset) + results_with_error = geno_db_exists(self.dataset) + + self.assertEqual(mock_data_set.create_dataset.call_count, 2) + self.assertEqual(results_with_error, "False") + self.assertEqual(results_no_error, "True") + + def test_trim_markers_for_figure(self): + + markers = [{ + "name": "MK1", + "chr": "C1", + "cM": "1", + "Mb": "12000", + "genotypes": [], + "dominance":"TT", + "additive":"VA", + "lod_score":0.5 + }, + { + "name": "MK2", + "chr": "C2", + "cM": "15", + "Mb": "10000", + "genotypes": [], + "lod_score":0.7 + }, + { + "name": "MK1", + "chr": "C3", + "cM": "45", + "Mb": "1", + "genotypes": [], + "dominance":"Tt", + "additive":"VE", + "lod_score":1 + }] + + marker_2 = [{ + "name": "MK1", + "chr": "C1", + "cM": "1", + "Mb": "12000", + "genotypes": [], + "dominance":"TT", + "additive":"VA", + "p_wald":4.6 + }] + results = trim_markers_for_figure(markers) + result_2 = trim_markers_for_figure(marker_2) + expected = [ + { + "name": "MK1", + "chr": "C1", + "cM": "1", + "Mb": "12000", + "genotypes": [], + "dominance":"TT", + "additive":"VA", + "lod_score":0.5 + }, + { + "name": "MK1", + "chr": "C3", + "cM": "45", + "Mb": "1", + "genotypes": [], + "dominance":"Tt", + "additive":"VE", + "lod_score":1 + } + + ] + self.assertEqual(results, expected) + self.assertEqual(result_2, marker_2) + + def test_export_mapping_results(self): + """test for exporting mapping results""" + datetime_mock = mock.Mock(wraps=datetime.datetime) + datetime_mock.now.return_value = datetime.datetime( + 2019, 9, 1, 10, 12, 12) + + markers = [{ + "name": "MK1", + "chr": "C1", + "cM": "1", + "Mb": "12000", + "genotypes": [], + "dominance":"TT", + "additive":"VA", + "lod_score":3 + }, + { + "name": "MK2", + "chr": "C2", + "cM": "15", + "Mb": "10000", + "genotypes": [], + "lod_score":7 + }, + { + "name": "MK1", + "chr": "C3", + "cM": "45", + "Mb": "1", + "genotypes": [], + "dominance":"Tt", + "additive":"VE", + "lod_score":7 + }] + + with mock.patch("builtins.open", mock.mock_open()) as mock_open: + + with mock.patch("wqflask.marker_regression.run_mapping.datetime.datetime", new=datetime_mock): + export_mapping_results(dataset=self.dataset, trait=self.trait, markers=markers, + results_path="~/results", mapping_scale="physic", score_type="-log(p)") + + write_calls = [ + mock.call('Time/Date: 09/01/19 / 10:12:12\n'), + mock.call('Population: Human GP1_\n'), mock.call( + 'Data Set: dataser_1\n'), + mock.call('Gene Symbol: IGFI\n'), mock.call( + 'Location: X1 @ 123313 Mb\n'), + mock.call('\n'), mock.call('Name,Chr,'), + mock.call('Mb,-log(p)'), mock.call('Cm,-log(p)'), + mock.call(',Additive'), mock.call(',Dominance'), + mock.call('\n'), mock.call('MK1,C1,'), + mock.call('12000,'), mock.call('1,'), + mock.call('3'), mock.call(',VA'), + mock.call(',TT'), mock.call('\n'), + mock.call('MK2,C2,'), mock.call('10000,'), + mock.call('15,'), mock.call('7'), + mock.call('\n'), mock.call('MK1,C3,'), + mock.call('1,'), mock.call('45,'), + mock.call('7'), mock.call(',VE'), + mock.call(',Tt') + + ] + mock_open.assert_called_once_with("~/results", "w+") + filehandler = mock_open() + filehandler.write.assert_has_calls(write_calls) + + @mock.patch("wqflask.marker_regression.run_mapping.random.choice") + def test_write_input_for_browser(self, mock_choice): + """test for writing input for browser""" + mock_choice.side_effect = ["F", "i", "l", "e", "s", "x"] + with mock.patch("builtins.open", mock.mock_open()) as mock_open: + expected = ['GP1__Filesx_GWAS', 'GP1__Filesx_ANNOT'] + + results = write_input_for_browser( + this_dataset=self.dataset, gwas_results={}, annotations={}) + self.assertEqual(results, expected) + + def test_get_perm_strata(self): + categorical_vars = ["C1", "C2", "W1"] + used_samples = ["S1", "S2"] + sample_list = AttributeSetter({"sample_attribute_values": { + "S1": { + "C1": "c1_value", + "C2": "c2_value", + "W1": "w1_value" + + }, + "S2": { + "W1": "w2_value", + "W2": "w2_value" + + }, + "S3": { + + "C1": "c1_value", + "C2": "c2_value" + + }, + + }}) + + results = get_perm_strata(this_trait={}, sample_list=sample_list, + categorical_vars=categorical_vars, used_samples=used_samples) + self.assertEqual(results, [2, 1]) + + def test_get_chr_length(self): + """test for getting chromosome length""" + chromosomes = AttributeSetter({"chromosomes": self.chromosomes}) + dataset = AttributeSetter({"species": chromosomes}) + results = get_chr_lengths( + mapping_scale="physic", mapping_method="reaper", dataset=dataset, qtl_results=[]) + chr_lengths = [] + for key, chromo in self.chromosomes.chromosomes.items(): + chr_lengths.append({"chr": chromo.name, "size": chromo.length}) + + self.assertEqual(chr_lengths, results) + + qtl_results = [{ + "chr": "16", + "cM": "0.2" + }, + { + "chr": "12", + "cM": "0.5" + }, + { + "chr": "18", + "cM": "0.1" + }, + { + "chr": "22", + "cM": "0.4" + }, + ] + + result_with_other_mapping_scale = get_chr_lengths( + mapping_scale="other", mapping_method="reaper", dataset=dataset, qtl_results=qtl_results) + expected_value = [{'chr': '1', 'size': '0'}, { + 'chr': '16', 'size': '500000.0'}, {'chr': '18', 'size': '400000.0'}] + + self.assertEqual(result_with_other_mapping_scale, expected_value) diff --git a/wqflask/tests/wqflask/marker_regression/test_gemma_mapping.py b/wqflask/tests/wqflask/marker_regression/test_gemma_mapping.py deleted file mode 100644 index 4fafd95a..00000000 --- a/wqflask/tests/wqflask/marker_regression/test_gemma_mapping.py +++ /dev/null @@ -1,205 +0,0 @@ -# test for wqflask/marker_regression/gemma_mapping.py -import unittest -import random -from unittest import mock -from wqflask.marker_regression.gemma_mapping import run_gemma -from wqflask.marker_regression.gemma_mapping import gen_pheno_txt_file -from wqflask.marker_regression.gemma_mapping import gen_covariates_file -from wqflask.marker_regression.gemma_mapping import parse_gemma_output -from wqflask.marker_regression.gemma_mapping import parse_loco_output - - -class AttributeSetter: - def __init__(self, obj): - for key, val in obj.items(): - setattr(self, key, val) - - -class MockDatasetGroup(AttributeSetter): - def get_samplelist(self): - return None - - -class TestGemmaMapping(unittest.TestCase): - - @mock.patch("wqflask.marker_regression.gemma_mapping.parse_loco_output") - def test_run_gemma_firstrun_set_false(self, mock_parse_loco): - """add tests for gemma function where first run is set to false""" - dataset = AttributeSetter( - {"group": AttributeSetter({"genofile": "genofile.geno"})}) - - output_file = "file1" - mock_parse_loco.return_value = [] - this_trait = AttributeSetter({"name": "t1"}) - - result = run_gemma(this_trait=this_trait, this_dataset=dataset, samples=[], vals=[ - ], covariates="", use_loco=True, first_run=False, output_files=output_file) - - expected_results = ([], "file1") - self.assertEqual(expected_results, result) - - @mock.patch("wqflask.marker_regression.gemma_mapping.webqtlConfig.GENERATED_IMAGE_DIR", "/home/user/img") - @mock.patch("wqflask.marker_regression.gemma_mapping.GEMMAOPTS", "-debug") - @mock.patch("wqflask.marker_regression.gemma_mapping.GEMMA_WRAPPER_COMMAND", "ghc") - @mock.patch("wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/user/data/") - @mock.patch("wqflask.marker_regression.gemma_mapping.parse_loco_output") - @mock.patch("wqflask.marker_regression.gemma_mapping.logger") - @mock.patch("wqflask.marker_regression.gemma_mapping.flat_files") - @mock.patch("wqflask.marker_regression.gemma_mapping.gen_covariates_file") - @mock.patch("wqflask.marker_regression.run_mapping.random.choice") - @mock.patch("wqflask.marker_regression.gemma_mapping.os") - @mock.patch("wqflask.marker_regression.gemma_mapping.gen_pheno_txt_file") - def test_run_gemma_firstrun_set_true(self, mock_gen_pheno_txt, mock_os, mock_choice, mock_gen_covar, mock_flat_files, mock_logger, mock_parse_loco): - """add tests for run_gemma where first run is set to true""" - chromosomes = [] - for i in range(1, 5): - chromosomes.append(AttributeSetter({"name": f"CH{i}"})) - chromo = AttributeSetter({"chromosomes": chromosomes}) - dataset_group = MockDatasetGroup( - {"name": "GP1", "genofile": "file_geno"}) - dataset = AttributeSetter({"group": dataset_group, "name": "dataset1_name", - "species": AttributeSetter({"chromosomes": chromo})}) - trait = AttributeSetter({"name": "trait1"}) - samples = [] - mock_gen_pheno_txt.return_value = None - mock_os.path.isfile.return_value = True - mock_gen_covar.return_value = None - mock_choice.return_value = "R" - mock_flat_files.return_value = "/home/genotype/bimbam" - mock_parse_loco.return_value = [] - results = run_gemma(this_trait=trait, this_dataset=dataset, samples=[ - ], vals=[], covariates="", use_loco=True) - system_calls = [mock.call('ghc --json -- -debug -g /home/genotype/bimbam/file_geno.txt -p /home/user/data//gn2/trait1_dataset1_name_pheno.txt -a /home/genotype/bimbam/file_snps.txt -gk > /home/user/data//gn2/GP1_K_RRRRRR.json'), - mock.call('ghc --json --input /home/user/data//gn2/GP1_K_RRRRRR.json -- -debug -a /home/genotype/bimbam/file_snps.txt -lmm 2 -g /home/genotype/bimbam/file_geno.txt -p /home/user/data//gn2/trait1_dataset1_name_pheno.txt > /home/user/data//gn2/GP1_GWA_RRRRRR.json')] - mock_os.system.assert_has_calls(system_calls) - mock_gen_pheno_txt.assert_called_once() - mock_parse_loco.assert_called_once_with(dataset, "GP1_GWA_RRRRRR") - mock_os.path.isfile.assert_called_once_with( - ('/home/user/imgfile_output.assoc.txt')) - self.assertEqual(mock_logger.debug.call_count, 2) - self.assertEqual(mock_flat_files.call_count, 4) - self.assertEqual(results, ([], "GP1_GWA_RRRRRR")) - - @mock.patch("wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/user/data") - def test_gen_pheno_txt_file(self): - """add tests for generating pheno txt file""" - with mock.patch("builtins.open", mock.mock_open())as mock_open: - gen_pheno_txt_file(this_dataset={}, genofile_name="", vals=[ - "x", "w", "q", "we", "R"], trait_filename="fitr.re") - mock_open.assert_called_once_with( - '/home/user/data/gn2/fitr.re.txt', 'w') - filehandler = mock_open() - values = ["x", "w", "q", "we", "R"] - write_calls = [mock.call('NA\n'), mock.call('w\n'), mock.call( - 'q\n'), mock.call('we\n'), mock.call('R\n')] - - filehandler.write.assert_has_calls(write_calls) - - @mock.patch("wqflask.marker_regression.gemma_mapping.flat_files") - @mock.patch("wqflask.marker_regression.gemma_mapping.create_trait") - @mock.patch("wqflask.marker_regression.gemma_mapping.create_dataset") - def test_gen_covariates_file(self, create_dataset, create_trait, flat_files): - """add tests for generating covariates files""" - covariates = "X1:X2,Y1:Y2,M1:M3,V1:V2" - samplelist = ["X1", "X2", "X3", "X4"] - create_dataset_side_effect = [] - create_trait_side_effect = [] - - for i in range(4): - create_dataset_side_effect.append(AttributeSetter({"name": f'name_{i}'})) - create_trait_side_effect.append( - AttributeSetter({"data": [f'data_{i}']})) - - create_dataset.side_effect = create_trait_side_effect - create_trait.side_effect = create_trait_side_effect - - group = MockDatasetGroup({"name": "group_X", "samplelist": samplelist}) - this_dataset = AttributeSetter({"group": group}) - flat_files.return_value = "Home/Genenetwork" - - with mock.patch("builtins.open", mock.mock_open())as mock_open: - gen_covariates_file(this_dataset=this_dataset, covariates=covariates, - samples=["x1", "x2", "X3"]) - - create_dataset.assert_has_calls( - [mock.call('X2'), mock.call('Y2'), mock.call('M3'), mock.call('V2')]) - mock_calls = [] - trait_names = ["X1", "Y1", "M1", "V1"] - - for i, trait in enumerate(create_trait_side_effect): - mock_calls.append( - mock.call(dataset=trait, name=trait_names[i], cellid=None)) - - create_trait.assert_has_calls(mock_calls) - - flat_files.assert_called_once_with('mapping') - mock_open.assert_called_once_with( - 'Home/Genenetwork/group_X_covariates.txt', 'w') - filehandler = mock_open() - filehandler.write.assert_has_calls([mock.call( - '-9\t'), mock.call('-9\t'), mock.call('-9\t'), mock.call('-9\t'), mock.call('\n')]) - - @mock.patch("wqflask.marker_regression.gemma_mapping.webqtlConfig.GENERATED_IMAGE_DIR", "/home/user/img/") - def test_parse_gemma_output(self): - """add test for generating gemma output with obj returned""" - file = """X/Y\t gn2\t21\tQ\tE\tA\tP\tMMB\tCDE\t0.5 -X/Y\tgn2\t21322\tQ\tE\tA\tP\tMMB\tCDE\t0.5 -chr\tgn1\t12312\tQ\tE\tA\tP\tMMB\tCDE\t0.7 -X\tgn7\t2324424\tQ\tE\tA\tP\tMMB\tCDE\t0.4 -125\tgn9\t433575\tQ\tE\tA\tP\tMMB\tCDE\t0.67 -""" - with mock.patch("builtins.open", mock.mock_open(read_data=file)) as mock_open: - results = parse_gemma_output(genofile_name="gema_file") - expected = [{'name': ' gn2', 'chr': 'X/Y', 'Mb': 2.1e-05, 'p_value': 0.5, 'lod_score': 0.3010299956639812}, {'name': 'gn2', 'chr': 'X/Y', 'Mb': 0.021322, 'p_value': 0.5, 'lod_score': 0.3010299956639812}, - {'name': 'gn7', 'chr': 'X', 'Mb': 2.324424, 'p_value': 0.4, 'lod_score': 0.3979400086720376}, {'name': 'gn9', 'chr': 125, 'Mb': 0.433575, 'p_value': 0.67, 'lod_score': 0.17392519729917352}] - mock_open.assert_called_once_with( - "/home/user/img/gema_file_output.assoc.txt") - self.assertEqual(results, expected) - - @mock.patch("wqflask.marker_regression.gemma_mapping.webqtlConfig.GENERATED_IMAGE_DIR", "/home/user/img") - def test_parse_gemma_output_with_empty_return(self): - """add tests for parse gemma output where nothing returned""" - output_file_results = """chr\t today""" - with mock.patch("builtins.open", mock.mock_open(read_data=output_file_results)) as mock_open: - results = parse_gemma_output(genofile_name="gema_file") - self.assertEqual(results, []) - - @mock.patch("wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/tmp") - @mock.patch("wqflask.marker_regression.gemma_mapping.os") - @mock.patch("wqflask.marker_regression.gemma_mapping.json") - def test_parse_loco_outputfile_found(self, mock_json, mock_os): - """add tests for parse loco output file found""" - mock_json.load.return_value = { - "files": [["file_name", "user", "~/file1"], - ["file_name", "user", "~/file2"]] - } - return_file_1 = """X/Y\t L1\t21\tQ\tE\tA\tP\tMMB\tCDE\t0.5 -X/Y\tL2\t21322\tQ\tE\tA\tP\tMMB\tCDE\t0.5 -chr\tL3\t12312\tQ\tE\tA\tP\tMMB\tCDE\t0.7""" - return_file_2 = """chr\tother\t21322\tQ\tE\tA\tP\tMMB\tCDE\t0.5""" - mock_os.path.isfile.return_value = True - file_to_write = """{"files":["file_1","file_2"]}""" - with mock.patch("builtins.open") as mock_open: - - handles = (mock.mock_open(read_data="gwas").return_value, mock.mock_open( - read_data=return_file_1).return_value, mock.mock_open(read_data=return_file_2).return_value) - mock_open.side_effect = handles - results = parse_loco_output( - this_dataset={}, gwa_output_filename=".xw/") - expected_results = [{'name': ' L1', 'chr': 'X/Y', 'Mb': 2.1e-05, 'p_value': 0.5, 'lod_score': 0.3010299956639812}, { - 'name': 'L2', 'chr': 'X/Y', 'Mb': 0.021322, 'p_value': 0.5, 'lod_score': 0.3010299956639812}] - - self.assertEqual(expected_results, results) - - @mock.patch("wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/tmp") - @mock.patch("wqflask.marker_regression.gemma_mapping.os") - def test_parse_loco_outputfile_not_found(self, mock_os): - """add tests for parse loco output where output file not found""" - - mock_os.path.isfile.return_value = False - file_to_write = """{"files":["file_1","file_2"]}""" - - with mock.patch("builtins.open", mock.mock_open(read_data=file_to_write)) as mock_open: - results = parse_loco_output( - this_dataset={}, gwa_output_filename=".xw/") - self.assertEqual(results, []) diff --git a/wqflask/tests/wqflask/marker_regression/test_plink_mapping.py b/wqflask/tests/wqflask/marker_regression/test_plink_mapping.py deleted file mode 100644 index 428f45b9..00000000 --- a/wqflask/tests/wqflask/marker_regression/test_plink_mapping.py +++ /dev/null @@ -1,84 +0,0 @@ -# test for wqflask/marker_regression/plink_mapping.py -import unittest -from unittest import mock -from wqflask.marker_regression.plink_mapping import build_line_list -from wqflask.marker_regression.plink_mapping import get_samples_from_ped_file -from wqflask.marker_regression.plink_mapping import flat_files -from wqflask.marker_regression.plink_mapping import gen_pheno_txt_file_plink -from wqflask.marker_regression.plink_mapping import parse_plink_output - - -class AttributeSetter: - def __init__(self, obj): - for key, val in obj.items(): - setattr(self, key, val) -class TestPlinkMapping(unittest.TestCase): - - def test_build_line_list(self): - """testing for building line list""" - line_1 = "this is line one test" - irregular_line = " this is an, irregular line " - exp_line1 = ["this", "is", "line", "one", "test"] - - results = build_line_list(irregular_line) - self.assertEqual(exp_line1, build_line_list(line_1)) - self.assertEqual([], build_line_list()) - self.assertEqual(["this", "is", "an,", "irregular", "line"], results) - - @mock.patch("wqflask.marker_regression.plink_mapping.flat_files") - def test_get_samples_from_ped_file(self, mock_flat_files): - """test for getting samples from ped file""" - dataset = AttributeSetter({"group": AttributeSetter({"name": "n_1"})}) - file_sample = """Expected_1\tline test -Expected_2\there - Expected_3\tthree""" - mock_flat_files.return_value = "/home/user/" - with mock.patch("builtins.open", mock.mock_open(read_data=file_sample)) as mock_open: - results = get_samples_from_ped_file(dataset) - mock_flat_files.assert_called_once_with("mapping") - mock_open.assert_called_once_with("/home/user/n_1.ped", "r") - self.assertEqual( - ["Expected_1", "Expected_2", "Expected_3"], results) - - @mock.patch("wqflask.marker_regression.plink_mapping.TMPDIR", "/home/user/data/") - @mock.patch("wqflask.marker_regression.plink_mapping.get_samples_from_ped_file") - def test_gen_pheno_txt_file_plink(self, mock_samples): - """test for getting gen_pheno txt file""" - mock_samples.return_value = ["Expected_1", "Expected_2", "Expected_3"] - - trait = AttributeSetter({"name": "TX"}) - dataset = AttributeSetter({"group": AttributeSetter({"name": "n_1"})}) - vals = ["value=K1", "value=K2", "value=K3"] - with mock.patch("builtins.open", mock.mock_open()) as mock_open: - results = gen_pheno_txt_file_plink(this_trait=trait, dataset=dataset, - vals=vals, pheno_filename="ph_file") - mock_open.assert_called_once_with( - "/home/user/data/ph_file.txt", "wb") - filehandler = mock_open() - calls_expected = [mock.call('FID\tIID\tTX\n'), - mock.call('Expected_1\tExpected_1\tK1\nExpected_2\tExpected_2\tK2\nExpected_3\tExpected_3\tK3\n')] - - filehandler.write.assert_has_calls(calls_expected) - - filehandler.close.assert_called_once() - - @mock.patch("wqflask.marker_regression.plink_mapping.TMPDIR", "/home/user/data/") - @mock.patch("wqflask.marker_regression.plink_mapping.build_line_list") - def test_parse_plink_output(self, mock_line_list): - """test for parsing plink output""" - chromosomes = [0, 34, 110, 89, 123, 23, 2] - species = AttributeSetter( - {"name": "S1", "chromosomes": AttributeSetter({"chromosomes": chromosomes})}) - - fake_file = """0 AACCAT T98.6 0.89\n2 AATA B45 0.3\n121 ACG B56.4 NA""" - - mock_line_list.side_effect = [["0", "AACCAT", "T98.6", "0.89"], [ - "2", "AATA", "B45", "0.3"], ["121", "ACG", "B56.4", "NA"]] - with mock.patch("builtins.open", mock.mock_open(read_data=fake_file)) as mock_open: - parse_results = parse_plink_output( - output_filename="P1_file", species=species) - mock_open.assert_called_once_with( - "/home/user/data/P1_file.qassoc", "rb") - expected = (2, {'AACCAT': 0.89, 'AATA': 0.3}) - - self.assertEqual(parse_results, expected) diff --git a/wqflask/tests/wqflask/marker_regression/test_qtlreaper_mapping.py b/wqflask/tests/wqflask/marker_regression/test_qtlreaper_mapping.py deleted file mode 100644 index b47f877a..00000000 --- a/wqflask/tests/wqflask/marker_regression/test_qtlreaper_mapping.py +++ /dev/null @@ -1,21 +0,0 @@ -import unittest -from unittest import mock -from wqflask.marker_regression.qtlreaper_mapping import gen_pheno_txt_file - -#issues some methods in genofile object are not defined -#modify samples should equal to vals -class TestQtlReaperMapping(unittest.TestCase): - @mock.patch("wqflask.marker_regression.qtlreaper_mapping.TEMPDIR", "/home/user/data") - def test_gen_pheno_txt_file(self): - vals=["V1","x","V4","V3","x"] - samples=["S1","S2","S3","S4","S5"] - trait_filename="trait_file" - with mock.patch("builtins.open", mock.mock_open())as mock_open: - gen_pheno_txt_file(samples=samples,vals=vals,trait_filename=trait_filename) - mock_open.assert_called_once_with("/home/user/data/gn2/trait_file.txt","w") - filehandler=mock_open() - write_calls= [mock.call('Trait\t'),mock.call('S1\tS3\tS4\n'),mock.call('T1\t'),mock.call('V1\tV4\tV3')] - - filehandler.write.assert_has_calls(write_calls) - - diff --git a/wqflask/tests/wqflask/marker_regression/test_rqtl_mapping.py b/wqflask/tests/wqflask/marker_regression/test_rqtl_mapping.py deleted file mode 100644 index 69f53721..00000000 --- a/wqflask/tests/wqflask/marker_regression/test_rqtl_mapping.py +++ /dev/null @@ -1,48 +0,0 @@ -import unittest -from unittest import mock -from wqflask import app -from wqflask.marker_regression.rqtl_mapping import get_trait_data_type -from wqflask.marker_regression.rqtl_mapping import sanitize_rqtl_phenotype -from wqflask.marker_regression.rqtl_mapping import sanitize_rqtl_names - -class TestRqtlMapping(unittest.TestCase): - - def setUp(self): - self.app_context=app.app_context() - self.app_context.push() - - def tearDown(self): - self.app_context.pop() - - - @mock.patch("wqflask.marker_regression.rqtl_mapping.g") - @mock.patch("wqflask.marker_regression.rqtl_mapping.logger") - def test_get_trait_data(self,mock_logger,mock_db): - """test for getting trait data_type return True""" - caller_value="""SELECT value FROM TraitMetadata WHERE type='trait_data_type'""" - mock_db.db.execute.return_value.fetchone.return_value=["""{"type":"trait_data_type","name":"T1","traid_id":"fer434f"}"""] - results=get_trait_data_type("traid_id") - mock_db.db.execute.assert_called_with(caller_value) - self.assertEqual(results,"fer434f") - - def test_sanitize_rqtl_phenotype(self): - """test for sanitizing rqtl phenotype""" - vals=['f',"x","r","x","x"] - results=sanitize_rqtl_phenotype(vals) - expected_phenotype_string='c(f,NA,r,NA,NA)' - - self.assertEqual(results,expected_phenotype_string) - - def test_sanitize_rqtl_names(self): - """test for sanitzing rqtl names""" - vals=['f',"x","r","x","x"] - expected_sanitized_name="c('f',NA,'r',NA,NA)" - results=sanitize_rqtl_names(vals) - self.assertEqual(expected_sanitized_name,results) - - - - - - - diff --git a/wqflask/tests/wqflask/marker_regression/test_run_mapping.py b/wqflask/tests/wqflask/marker_regression/test_run_mapping.py deleted file mode 100644 index a134f551..00000000 --- a/wqflask/tests/wqflask/marker_regression/test_run_mapping.py +++ /dev/null @@ -1,284 +0,0 @@ -import unittest -import datetime -from unittest import mock - -from wqflask.marker_regression.run_mapping import get_genofile_samplelist -from wqflask.marker_regression.run_mapping import geno_db_exists -from wqflask.marker_regression.run_mapping import write_input_for_browser -from wqflask.marker_regression.run_mapping import export_mapping_results -from wqflask.marker_regression.run_mapping import trim_markers_for_figure -from wqflask.marker_regression.run_mapping import get_perm_strata -from wqflask.marker_regression.run_mapping import get_chr_lengths - - -class AttributeSetter: - def __init__(self, obj): - for k, v in obj.items(): - setattr(self, k, v) - - -class MockDataSetGroup(AttributeSetter): - - def get_genofiles(self): - return [{"location": "~/genofiles/g1_file", "sample_list": ["S1", "S2", "S3", "S4"]}] - - -class TestRunMapping(unittest.TestCase): - def setUp(self): - - self.group = MockDataSetGroup( - {"genofile": "~/genofiles/g1_file", "name": "GP1_", "species": "Human"}) - chromosomes = { - "3": AttributeSetter({ - "name": "C1", - "length": "0.04" - }), - "4": AttributeSetter({ - "name": "C2", - "length": "0.03" - }), - "5": AttributeSetter({ - "name": "C4", - "length": "0.01" - }) - } - self.dataset = AttributeSetter( - {"fullname": "dataser_1", "group": self.group, "type": "ProbeSet"}) - - self.chromosomes = AttributeSetter({"chromosomes": chromosomes}) - self.trait = AttributeSetter( - {"symbol": "IGFI", "chr": "X1", "mb": 123313}) - - def tearDown(self): - self.dataset = AttributeSetter( - {"group": {"location": "~/genofiles/g1_file"}}) - - def test_get_genofile_samplelist(self): - - results_1 = get_genofile_samplelist(self.dataset) - self.assertEqual(results_1, ["S1", "S2", "S3", "S4"]) - self.group.genofile = "~/genofiles/g2_file" - result_2 = get_genofile_samplelist(self.dataset) - self.assertEqual(result_2, []) - - @mock.patch("wqflask.marker_regression.run_mapping.data_set") - def test_if_geno_db_exists(self, mock_data_set): - mock_data_set.create_dataset.side_effect = [ - AttributeSetter({}), Exception()] - results_no_error = geno_db_exists(self.dataset) - results_with_error = geno_db_exists(self.dataset) - - self.assertEqual(mock_data_set.create_dataset.call_count, 2) - self.assertEqual(results_with_error, "False") - self.assertEqual(results_no_error, "True") - - def test_trim_markers_for_figure(self): - - markers = [{ - "name": "MK1", - "chr": "C1", - "cM": "1", - "Mb": "12000", - "genotypes": [], - "dominance":"TT", - "additive":"VA", - "lod_score":0.5 - }, - { - "name": "MK2", - "chr": "C2", - "cM": "15", - "Mb": "10000", - "genotypes": [], - "lod_score":0.7 - }, - { - "name": "MK1", - "chr": "C3", - "cM": "45", - "Mb": "1", - "genotypes": [], - "dominance":"Tt", - "additive":"VE", - "lod_score":1 - }] - - marker_2 = [{ - "name": "MK1", - "chr": "C1", - "cM": "1", - "Mb": "12000", - "genotypes": [], - "dominance":"TT", - "additive":"VA", - "p_wald":4.6 - }] - results = trim_markers_for_figure(markers) - result_2 = trim_markers_for_figure(marker_2) - expected = [ - { - "name": "MK1", - "chr": "C1", - "cM": "1", - "Mb": "12000", - "genotypes": [], - "dominance":"TT", - "additive":"VA", - "lod_score":0.5 - }, - { - "name": "MK1", - "chr": "C3", - "cM": "45", - "Mb": "1", - "genotypes": [], - "dominance":"Tt", - "additive":"VE", - "lod_score":1 - } - - ] - self.assertEqual(results, expected) - self.assertEqual(result_2, marker_2) - - def test_export_mapping_results(self): - """test for exporting mapping results""" - datetime_mock = mock.Mock(wraps=datetime.datetime) - datetime_mock.now.return_value = datetime.datetime( - 2019, 9, 1, 10, 12, 12) - - markers = [{ - "name": "MK1", - "chr": "C1", - "cM": "1", - "Mb": "12000", - "genotypes": [], - "dominance":"TT", - "additive":"VA", - "lod_score":3 - }, - { - "name": "MK2", - "chr": "C2", - "cM": "15", - "Mb": "10000", - "genotypes": [], - "lod_score":7 - }, - { - "name": "MK1", - "chr": "C3", - "cM": "45", - "Mb": "1", - "genotypes": [], - "dominance":"Tt", - "additive":"VE", - "lod_score":7 - }] - - with mock.patch("builtins.open", mock.mock_open()) as mock_open: - - with mock.patch("wqflask.marker_regression.run_mapping.datetime.datetime", new=datetime_mock): - export_mapping_results(dataset=self.dataset, trait=self.trait, markers=markers, - results_path="~/results", mapping_scale="physic", score_type="-log(p)") - - write_calls = [ - mock.call('Time/Date: 09/01/19 / 10:12:12\n'), - mock.call('Population: Human GP1_\n'), mock.call( - 'Data Set: dataser_1\n'), - mock.call('Gene Symbol: IGFI\n'), mock.call( - 'Location: X1 @ 123313 Mb\n'), - mock.call('\n'), mock.call('Name,Chr,'), - mock.call('Mb,-log(p)'), mock.call('Cm,-log(p)'), - mock.call(',Additive'), mock.call(',Dominance'), - mock.call('\n'), mock.call('MK1,C1,'), - mock.call('12000,'), mock.call('1,'), - mock.call('3'), mock.call(',VA'), - mock.call(',TT'), mock.call('\n'), - mock.call('MK2,C2,'), mock.call('10000,'), - mock.call('15,'), mock.call('7'), - mock.call('\n'), mock.call('MK1,C3,'), - mock.call('1,'), mock.call('45,'), - mock.call('7'), mock.call(',VE'), - mock.call(',Tt') - - ] - mock_open.assert_called_once_with("~/results", "w+") - filehandler = mock_open() - filehandler.write.assert_has_calls(write_calls) - - @mock.patch("wqflask.marker_regression.run_mapping.random.choice") - def test_write_input_for_browser(self, mock_choice): - """test for writing input for browser""" - mock_choice.side_effect = ["F", "i", "l", "e", "s", "x"] - with mock.patch("builtins.open", mock.mock_open()) as mock_open: - expected = ['GP1__Filesx_GWAS', 'GP1__Filesx_ANNOT'] - - results = write_input_for_browser( - this_dataset=self.dataset, gwas_results={}, annotations={}) - self.assertEqual(results, expected) - - def test_get_perm_strata(self): - categorical_vars = ["C1", "C2", "W1"] - used_samples = ["S1", "S2"] - sample_list = AttributeSetter({"sample_attribute_values": { - "S1": { - "C1": "c1_value", - "C2": "c2_value", - "W1": "w1_value" - - }, - "S2": { - "W1": "w2_value", - "W2": "w2_value" - - }, - "S3": { - - "C1": "c1_value", - "C2": "c2_value" - - }, - - }}) - - results = get_perm_strata(this_trait={}, sample_list=sample_list, - categorical_vars=categorical_vars, used_samples=used_samples) - self.assertEqual(results, [2, 1]) - - def test_get_chr_length(self): - """test for getting chromosome length""" - chromosomes = AttributeSetter({"chromosomes": self.chromosomes}) - dataset = AttributeSetter({"species": chromosomes}) - results = get_chr_lengths( - mapping_scale="physic", mapping_method="reaper", dataset=dataset, qtl_results=[]) - chr_lengths = [] - for key, chromo in self.chromosomes.chromosomes.items(): - chr_lengths.append({"chr": chromo.name, "size": chromo.length}) - - self.assertEqual(chr_lengths, results) - - qtl_results = [{ - "chr": "16", - "cM": "0.2" - }, - { - "chr": "12", - "cM": "0.5" - }, - { - "chr": "18", - "cM": "0.1" - }, - { - "chr": "22", - "cM": "0.4" - }, - ] - - result_with_other_mapping_scale = get_chr_lengths( - mapping_scale="other", mapping_method="reaper", dataset=dataset, qtl_results=qtl_results) - expected_value = [{'chr': '1', 'size': '0'}, { - 'chr': '16', 'size': '500000.0'}, {'chr': '18', 'size': '400000.0'}] - - self.assertEqual(result_with_other_mapping_scale, expected_value) -- cgit v1.2.3 From c96c1db5660367f1f86cfa76309c87866e79bf79 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Sat, 28 Nov 2020 16:23:53 +0300 Subject: modify test for plink mapping and rqtl_mapping --- wqflask/tests/unit/wqflask/marker_regression/test_plink_mapping.py | 3 ++- wqflask/tests/unit/wqflask/marker_regression/test_rqtl_mapping.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/wqflask/tests/unit/wqflask/marker_regression/test_plink_mapping.py b/wqflask/tests/unit/wqflask/marker_regression/test_plink_mapping.py index 428f45b9..5eec93f1 100644 --- a/wqflask/tests/unit/wqflask/marker_regression/test_plink_mapping.py +++ b/wqflask/tests/unit/wqflask/marker_regression/test_plink_mapping.py @@ -14,8 +14,9 @@ class AttributeSetter: setattr(self, key, val) class TestPlinkMapping(unittest.TestCase): + def test_build_line_list(self): - """testing for building line list""" + """test for building line list""" line_1 = "this is line one test" irregular_line = " this is an, irregular line " exp_line1 = ["this", "is", "line", "one", "test"] diff --git a/wqflask/tests/unit/wqflask/marker_regression/test_rqtl_mapping.py b/wqflask/tests/unit/wqflask/marker_regression/test_rqtl_mapping.py index 69f53721..c585f1df 100644 --- a/wqflask/tests/unit/wqflask/marker_regression/test_rqtl_mapping.py +++ b/wqflask/tests/unit/wqflask/marker_regression/test_rqtl_mapping.py @@ -19,10 +19,10 @@ class TestRqtlMapping(unittest.TestCase): @mock.patch("wqflask.marker_regression.rqtl_mapping.logger") def test_get_trait_data(self,mock_logger,mock_db): """test for getting trait data_type return True""" - caller_value="""SELECT value FROM TraitMetadata WHERE type='trait_data_type'""" + query_value="""SELECT value FROM TraitMetadata WHERE type='trait_data_type'""" mock_db.db.execute.return_value.fetchone.return_value=["""{"type":"trait_data_type","name":"T1","traid_id":"fer434f"}"""] results=get_trait_data_type("traid_id") - mock_db.db.execute.assert_called_with(caller_value) + mock_db.db.execute.assert_called_with(query_value) self.assertEqual(results,"fer434f") def test_sanitize_rqtl_phenotype(self): -- cgit v1.2.3 From 668d6a97356030e0286365dad53c8d191c193290 Mon Sep 17 00:00:00 2001 From: zsloan Date: Wed, 2 Dec 2020 14:16:08 -0600 Subject: Made changes that should fix Heatmap errors + removed a console.log in panelutil.js --- wqflask/wqflask/static/new/javascript/lodheatmap.js | 6 ++++-- wqflask/wqflask/static/new/javascript/panelutil.js | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/wqflask/wqflask/static/new/javascript/lodheatmap.js b/wqflask/wqflask/static/new/javascript/lodheatmap.js index 965a1d53..b82c95ad 100644 --- a/wqflask/wqflask/static/new/javascript/lodheatmap.js +++ b/wqflask/wqflask/static/new/javascript/lodheatmap.js @@ -44,7 +44,9 @@ lodheatmap = function() { _ref = data.chrnames; for (_i = 0, _len = _ref.length; _i < _len; _i++) { chr = _ref[_i]; - xLR[chr[0]] = getLeftRight(data.posByChr[chr[0]]); + if (data.posByChr[chr[0]].length > 0){ + xLR[chr[0]] = getLeftRight(data.posByChr[chr[0]]); + } } zmin = 0; zmax = 0; @@ -144,7 +146,7 @@ lodheatmap = function() { }).attr("stroke", "none").attr("stroke-width", "1").on("mouseover.paneltip", function(d) { yaxis.select("text#yaxis" + d.lodindex).attr("opacity", 1); d3.select(this).attr("stroke", "black"); - return celltip.show(d); + return celltip.show(d, this); }).on("mouseout.paneltip", function(d) { yaxis.select("text#yaxis" + d.lodindex).attr("opacity", 0); d3.select(this).attr("stroke", "none"); diff --git a/wqflask/wqflask/static/new/javascript/panelutil.js b/wqflask/wqflask/static/new/javascript/panelutil.js index 3c715c81..ea55a7cf 100644 --- a/wqflask/wqflask/static/new/javascript/panelutil.js +++ b/wqflask/wqflask/static/new/javascript/panelutil.js @@ -159,7 +159,6 @@ chrscales = function(data, width, chrGap, leftMargin, pad4heatmap, mappingScale) if (mappingScale == "morgan") { max_pos = d3.max(data.posByChr[chr[0]]) - console.log("max_pos:", max_pos) data.xscale[chr[0]] = d3.scale.linear().domain([chrStart[i], max_pos]).range([data.chrStart[i], data.chrEnd[i]]); } else { -- cgit v1.2.3