From 6d2d648126b112ca1455c6e1f2d344a4d8d27c1d Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Mon, 2 Nov 2020 11:06:36 +0300 Subject: add tests for show trait module --- .../tests/wqflask/show_trait/test_show_trait.py | 267 +++++++++++++++++++++ 1 file changed, 267 insertions(+) create mode 100644 wqflask/tests/wqflask/show_trait/test_show_trait.py diff --git a/wqflask/tests/wqflask/show_trait/test_show_trait.py b/wqflask/tests/wqflask/show_trait/test_show_trait.py new file mode 100644 index 00000000..37eae06e --- /dev/null +++ b/wqflask/tests/wqflask/show_trait/test_show_trait.py @@ -0,0 +1,267 @@ +"""test for wqflask/show_trait/test_show_trait.py""" + + +import unittest +from unittest import mock +from wqflask import app +from wqflask.show_trait.show_trait import check_if_attr_exists +from wqflask.show_trait.show_trait import requests + +from wqflask.show_trait.show_trait import get_ncbi_summary + +from wqflask.show_trait.show_trait import has_num_cases + +from wqflask.show_trait.show_trait import get_table_widths + +from wqflask.show_trait.show_trait import get_categorical_variables +from wqflask.show_trait.show_trait import get_trait_units + +from wqflask.show_trait.show_trait import get_nearest_marker + +from wqflask.show_trait.show_trait import get_genotype_scales + +class TraitObject: + def __init__(self, obj): + for key, value in obj.items(): + setattr(self, key, value) + + +class TestTraits(unittest.TestCase): + def setUp(self): + self.app_context = app.app_context() + self.app_context.push() + + def tearDown(self): + self.app_context.pop() + + def test_check_if_attr_exists_truthy(self): + """"test if attributes exists with true return""" + trait_obj = TraitObject({"id_type": "id"}) + trait_obj2 = TraitObject({"sample_name": ['samp1']}) + results = check_if_attr_exists(trait_obj, "id_type") + result2 = check_if_attr_exists(trait_obj2, "sample_name") + self.assertIsInstance(trait_obj, TraitObject) + self.assertEqual(results, True) + self.assertEqual(result2, True) + + def test_check_if_attr_exists_empty_attr(self): + """test if attributes exists with empty attributes""" + trait_obj = TraitObject({"sample": ""}) + trait_obj2 = TraitObject({"group": None}) + result = check_if_attr_exists(trait_obj, "sample") + result2 = check_if_attr_exists(trait_obj, "group") + self.assertEqual(result, False) + self.assertEqual(result2, False) + + def test_check_if_attr_exists_falsey(self): + """check if attribute exists with empty attributes""" + trait_obj = TraitObject({}) + results = check_if_attr_exists(trait_obj, "any") + self.assertEqual(results, False) + + @mock.patch("wqflask.show_trait.show_trait.requests.get") + @mock.patch("wqflask.show_trait.show_trait.check_if_attr_exists") + def test_get_ncbi_summary_request_success(self, mock_exists, mock_get): + """test for getting ncbi summary with + successful request""" + trait = TraitObject({"geneid": "id"}) + mock_exists.return_value = True + content_json_string = """{ + "result":{ + "id":{ + "summary":"this is a summary of the geneid" + } + } + } + """ + + get_return_obj = TraitObject({"content": content_json_string}) + + mock_get.return_value = get_return_obj + + results = get_ncbi_summary(trait) + mock_exists.assert_called_once() + mock_get.assert_called_once_with(f"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=gene&id={trait.geneid}&retmode=json") + + self.assertEqual(results, "this is a summary of the geneid") + + @mock.patch("wqflask.show_trait.show_trait.requests.get") + @mock.patch("wqflask.show_trait.show_trait.check_if_attr_exists") + def test_get_ncbi_summary_request_fail(self, mock_exists, mock_get_fail): + """test for getting ncbi summary with request fail""" + trait = TraitObject({"geneid": "id"}) + mock_exists.return_value = True + mock_get_fail.side_effect = Exception("an error occurred") + content_json_string = """{ + "result":{ + "id":{ + "summary":"this is a summary of the geneid" + } + } + } + """ + + results = get_ncbi_summary(trait) + self.assertEqual(results, None) + + def test_hash_num_cases_is_probeset(self): + """test for hash num_cases with dataset.type set to Probeset""" + create_dataset = TraitObject({"type": "ProbeSet"}) + create_trait = TraitObject({"dataset": create_dataset}) + + self.assertEqual(has_num_cases(create_trait), False) + + def test_hash_num_cases_no_probeset(self): + """test for hash num cases with dataset.type not Probeset""" + create_dataset = TraitObject({"type": "Temp"}) + + construct_data = { + "nm1": TraitObject({"num_cases": False}), + "nm2": TraitObject({"num_cases": True}), + "nm3": TraitObject({"num_cases": False}) + } + construct_data2 = { + "nm1": TraitObject({"num_cases": False}), + "nm2": TraitObject({"num_cases": False}), + "nm3": TraitObject({"num_cases": False}) + + + } + + create_trait = TraitObject( + {"dataset": create_dataset, "data": construct_data}) + create_trait2 = TraitObject( + {"dataset": create_dataset, "data": construct_data2}) + + results = has_num_cases(create_trait) + + self.assertEqual(has_num_cases(create_trait), True) + self.assertEqual(has_num_cases(create_trait2), False) + + def test_get_table_widths(self): + """test for getting table widths""" + sample_groups = [TraitObject({'se_exists': True, "attributes": ["attr1", "attr2", "attr3"]} + ), TraitObject( + {"se_exists": False, "attributes": ["at1", "at2"] + })] + + results_with_numcase = get_table_widths(sample_groups, True) + result_no_numcase = get_table_widths(sample_groups, False) + + results_one_sample = get_table_widths( + [TraitObject({"se_exists": True, "attributes": []})], True) + expected_with_numcase = (450, "750px") + expected_no_numcase = (450, "670px") + expected_one_sample = (250, "540px") + + self.assertEqual(results_with_numcase, expected_with_numcase) + self.assertEqual(result_no_numcase, expected_no_numcase) + self.assertEqual(results_one_sample, + expected_one_sample) + + def test_get_categorical_variables_no_sample_attributes(self): + """test for getting categorical variable names with no samples""" + trait = TraitObject({}) + sample_list = TraitObject({"se_exists": True, "attributes": []}) + + self.assertEqual(get_categorical_variables(trait, sample_list), []) + + def test_get_categorical_variables_with_sample_attributes(self): + pass + + def test_get_trait_units(self): + """test for gettting trait units""" + trait = TraitObject( + {"description_fmt": "[this is a description] another test [N/A]"}) + + trait_no_unit_type = TraitObject({"description_fmt": ""}) + + results = get_trait_units(trait) + results_no_unit = get_trait_units(trait_no_unit_type) + self.assertEqual(results, "this is a descriptionN/A") + self.assertEqual(results_no_unit, "Value") + + @mock.patch("wqflask.show_trait.show_trait.g") + def test_get_nearest_marker(self, mock_db): + """test for getting nearest marker with non-empty db""" + + mock_db.db.execute.return_value.fetchall.return_value = [ + ["Geno1", "Geno2"], ["Geno3"]] + + trait = TraitObject({"locus_chr": "test_chr", "locus_mb": "test_mb"}) + + group_name = TraitObject({"name": "group_name"}) + + this_db = TraitObject({"group": group_name}) + + results_with_item_db = get_nearest_marker(trait, this_db) + + called_with_value = """SELECT Geno.Name + FROM Geno, GenoXRef, GenoFreeze + WHERE Geno.Chr = 'test_chr' AND + GenoXRef.GenoId = Geno.Id AND + GenoFreeze.Id = GenoXRef.GenoFreezeId AND + GenoFreeze.Name = 'group_nameGeno' + ORDER BY ABS( Geno.Mb - test_mb) LIMIT 1""" + + mock_db.db.execute.assert_called_with(called_with_value) + + self.assertEqual(results_with_item_db, "Geno1") + + @mock.patch("wqflask.show_trait.show_trait.g") + def test_get_nearest_marker_empty_db(self, mock_db): + """test for getting nearest marker with empty db""" + mock_db.db.execute.return_value.fetchall.return_value = [] + + trait = TraitObject({"locus_chr": "test_chr", "locus_mb": "test_mb"}) + group_name = TraitObject({"name": "group_name"}) + this_db = TraitObject({"group": group_name}) + + results_empty_db = get_nearest_marker(trait, this_db) + mock_db.db.execute.assert_called_once() + self.assertEqual(results_empty_db, "") + + + @mock.patch("wqflask.show_trait.show_trait.get_scales_from_genofile") + def test_get_genotype_scales_with_genofile_is_list(self,mock_get_scales): + """test for getting genotype scales with genofile as list """ + #where genofile is instance of list + genofiles_list = [{"filename":"file1","location":"~/data/files/f1"},{"filename":"file2","location":"~/data/files/f2"},{"filename":"file3","location":"~/data/files/f3"}] + + mock_get_scales.side_effect = [[["morgan", "cM"]],[["morgan", "cM"]],[["physic", "Mb"]]] + + results = get_genotype_scales(genofiles_list) + + expected_results = { + "~/data/files/f1":[["morgan","cM"]], + "~/data/files/f2":[["morgan","cM"]], + "~/data/files/f3":[["physic","Mb"]] + } + + multiple_calls = [mock.call('~/data/files/f1'),mock.call('~/data/files/f2'), + mock.call('~/data/files/f3')] + + + mock_get_scales.assert_has_calls(multiple_calls) + self.assertEqual(results,expected_results) + + + @mock.patch("wqflask.show_trait.show_trait.get_scales_from_genofile") + def test_genotype_scales_with_genofile_other(self,mock_get_scales): + """test for getting genotype scales with genofile as a strig""" + file_location = "~/another_file_location" + mock_get_scales.return_value = [["physic","Mb"]] + + expected_results = {f"{file_location}":[["physic","Mb"]]} + + + self.assertEqual(get_genotype_scales(file_location),expected_results) + mock_get_scales.assert_called_once_with(file_location) + + + + + + + + -- cgit v1.2.3 From 62996d6b521379576992172fdee99468cb0260c9 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Mon, 2 Nov 2020 13:35:59 +0300 Subject: add function docstring --- wqflask/tests/wqflask/show_trait/test_show_trait.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wqflask/tests/wqflask/show_trait/test_show_trait.py b/wqflask/tests/wqflask/show_trait/test_show_trait.py index 37eae06e..1b5d2265 100644 --- a/wqflask/tests/wqflask/show_trait/test_show_trait.py +++ b/wqflask/tests/wqflask/show_trait/test_show_trait.py @@ -45,7 +45,7 @@ class TestTraits(unittest.TestCase): self.assertEqual(result2, True) def test_check_if_attr_exists_empty_attr(self): - """test if attributes exists with empty attributes""" + """test if attributes exists with false return""" trait_obj = TraitObject({"sample": ""}) trait_obj2 = TraitObject({"group": None}) result = check_if_attr_exists(trait_obj, "sample") @@ -248,7 +248,7 @@ class TestTraits(unittest.TestCase): @mock.patch("wqflask.show_trait.show_trait.get_scales_from_genofile") def test_genotype_scales_with_genofile_other(self,mock_get_scales): - """test for getting genotype scales with genofile as a strig""" + """test for getting genotype scales with genofile as a string""" file_location = "~/another_file_location" mock_get_scales.return_value = [["physic","Mb"]] -- cgit v1.2.3 From 2883f17236081bc11faf4c4202393998bde0924d Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Mon, 2 Nov 2020 13:50:25 +0300 Subject: add better formatting --- .../tests/wqflask/show_trait/test_show_trait.py | 47 +++++++++------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/wqflask/tests/wqflask/show_trait/test_show_trait.py b/wqflask/tests/wqflask/show_trait/test_show_trait.py index 1b5d2265..408797b9 100644 --- a/wqflask/tests/wqflask/show_trait/test_show_trait.py +++ b/wqflask/tests/wqflask/show_trait/test_show_trait.py @@ -20,6 +20,7 @@ from wqflask.show_trait.show_trait import get_nearest_marker from wqflask.show_trait.show_trait import get_genotype_scales + class TraitObject: def __init__(self, obj): for key, value in obj.items(): @@ -141,7 +142,7 @@ class TestTraits(unittest.TestCase): def test_get_table_widths(self): """test for getting table widths""" sample_groups = [TraitObject({'se_exists': True, "attributes": ["attr1", "attr2", "attr3"]} - ), TraitObject( + ), TraitObject( {"se_exists": False, "attributes": ["at1", "at2"] })] @@ -221,47 +222,39 @@ class TestTraits(unittest.TestCase): mock_db.db.execute.assert_called_once() self.assertEqual(results_empty_db, "") - @mock.patch("wqflask.show_trait.show_trait.get_scales_from_genofile") - def test_get_genotype_scales_with_genofile_is_list(self,mock_get_scales): + def test_get_genotype_scales_with_genofile_is_list(self, mock_get_scales): """test for getting genotype scales with genofile as list """ - #where genofile is instance of list - genofiles_list = [{"filename":"file1","location":"~/data/files/f1"},{"filename":"file2","location":"~/data/files/f2"},{"filename":"file3","location":"~/data/files/f3"}] + # where genofile is instance of list + genofiles_list = [{"filename": "file1", "location": "~/data/files/f1"}, + {"filename": "file2", "location": "~/data/files/f2"}, + {"filename": "file3", "location": "~/data/files/f3"}] - mock_get_scales.side_effect = [[["morgan", "cM"]],[["morgan", "cM"]],[["physic", "Mb"]]] + mock_get_scales.side_effect = [[["morgan", "cM"]], + [["morgan", "cM"]], + [["physic", "Mb"]]] results = get_genotype_scales(genofiles_list) expected_results = { - "~/data/files/f1":[["morgan","cM"]], - "~/data/files/f2":[["morgan","cM"]], - "~/data/files/f3":[["physic","Mb"]] + "~/data/files/f1": [["morgan", "cM"]], + "~/data/files/f2": [["morgan", "cM"]], + "~/data/files/f3": [["physic", "Mb"]] } - multiple_calls = [mock.call('~/data/files/f1'),mock.call('~/data/files/f2'), - mock.call('~/data/files/f3')] - + multiple_calls = [mock.call('~/data/files/f1'), mock.call('~/data/files/f2'), + mock.call('~/data/files/f3')] mock_get_scales.assert_has_calls(multiple_calls) - self.assertEqual(results,expected_results) - + self.assertEqual(results, expected_results) @mock.patch("wqflask.show_trait.show_trait.get_scales_from_genofile") - def test_genotype_scales_with_genofile_other(self,mock_get_scales): + def test_genotype_scales_with_genofile_other(self, mock_get_scales): """test for getting genotype scales with genofile as a string""" file_location = "~/another_file_location" - mock_get_scales.return_value = [["physic","Mb"]] + mock_get_scales.return_value = [["physic", "Mb"]] - expected_results = {f"{file_location}":[["physic","Mb"]]} + expected_results = {f"{file_location}": [["physic", "Mb"]]} - - self.assertEqual(get_genotype_scales(file_location),expected_results) + self.assertEqual(get_genotype_scales(file_location), expected_results) mock_get_scales.assert_called_once_with(file_location) - - - - - - - - -- cgit v1.2.3 From 251113ee34819afdc3e2abc63d59a01bd6a560cb Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Tue, 3 Nov 2020 10:32:36 +0300 Subject: use assertTrue and assertFalse in while testing boolean --- .../tests/wqflask/show_trait/test_show_trait.py | 38 ++++++++-------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/wqflask/tests/wqflask/show_trait/test_show_trait.py b/wqflask/tests/wqflask/show_trait/test_show_trait.py index 408797b9..a2ef71dd 100644 --- a/wqflask/tests/wqflask/show_trait/test_show_trait.py +++ b/wqflask/tests/wqflask/show_trait/test_show_trait.py @@ -1,24 +1,12 @@ """test for wqflask/show_trait/test_show_trait.py""" - import unittest from unittest import mock from wqflask import app -from wqflask.show_trait.show_trait import check_if_attr_exists -from wqflask.show_trait.show_trait import requests - -from wqflask.show_trait.show_trait import get_ncbi_summary - -from wqflask.show_trait.show_trait import has_num_cases - -from wqflask.show_trait.show_trait import get_table_widths - -from wqflask.show_trait.show_trait import get_categorical_variables -from wqflask.show_trait.show_trait import get_trait_units - -from wqflask.show_trait.show_trait import get_nearest_marker - -from wqflask.show_trait.show_trait import get_genotype_scales +from wqflask.show_trait.show_trait import (check_if_attr_exists, get_ncbi_summary, + has_num_cases, get_table_widths, + get_categorical_variables, + get_trait_units, get_nearest_marker, get_genotype_scales, requests) class TraitObject: @@ -42,8 +30,8 @@ class TestTraits(unittest.TestCase): results = check_if_attr_exists(trait_obj, "id_type") result2 = check_if_attr_exists(trait_obj2, "sample_name") self.assertIsInstance(trait_obj, TraitObject) - self.assertEqual(results, True) - self.assertEqual(result2, True) + self.assertTrue(results, True) + self.assertTrue(result2, True) def test_check_if_attr_exists_empty_attr(self): """test if attributes exists with false return""" @@ -51,14 +39,14 @@ class TestTraits(unittest.TestCase): trait_obj2 = TraitObject({"group": None}) result = check_if_attr_exists(trait_obj, "sample") result2 = check_if_attr_exists(trait_obj, "group") - self.assertEqual(result, False) - self.assertEqual(result2, False) + self.assertFalse(result, False) + self.assertFalse(result2, False) def test_check_if_attr_exists_falsey(self): """check if attribute exists with empty attributes""" trait_obj = TraitObject({}) results = check_if_attr_exists(trait_obj, "any") - self.assertEqual(results, False) + self.assertFalse(results, False) @mock.patch("wqflask.show_trait.show_trait.requests.get") @mock.patch("wqflask.show_trait.show_trait.check_if_attr_exists") @@ -110,7 +98,7 @@ class TestTraits(unittest.TestCase): create_dataset = TraitObject({"type": "ProbeSet"}) create_trait = TraitObject({"dataset": create_dataset}) - self.assertEqual(has_num_cases(create_trait), False) + self.assertFalse(has_num_cases(create_trait), False) def test_hash_num_cases_no_probeset(self): """test for hash num cases with dataset.type not Probeset""" @@ -136,8 +124,8 @@ class TestTraits(unittest.TestCase): results = has_num_cases(create_trait) - self.assertEqual(has_num_cases(create_trait), True) - self.assertEqual(has_num_cases(create_trait2), False) + self.assertTrue(has_num_cases(create_trait), True) + self.assertFalse(has_num_cases(create_trait2), False) def test_get_table_widths(self): """test for getting table widths""" @@ -171,7 +159,7 @@ class TestTraits(unittest.TestCase): pass def test_get_trait_units(self): - """test for gettting trait units""" + """test for getting trait units""" trait = TraitObject( {"description_fmt": "[this is a description] another test [N/A]"}) -- cgit v1.2.3 From ef0c9bb30523b32decc163dcb62c125e7ba5a076 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Tue, 3 Nov 2020 16:50:23 +0300 Subject: switch from assertTrue/False to assertIs to make the tests tighter --- wqflask/tests/wqflask/show_trait/test_show_trait.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/wqflask/tests/wqflask/show_trait/test_show_trait.py b/wqflask/tests/wqflask/show_trait/test_show_trait.py index a2ef71dd..f666912b 100644 --- a/wqflask/tests/wqflask/show_trait/test_show_trait.py +++ b/wqflask/tests/wqflask/show_trait/test_show_trait.py @@ -1,5 +1,4 @@ """test for wqflask/show_trait/test_show_trait.py""" - import unittest from unittest import mock from wqflask import app @@ -30,8 +29,9 @@ class TestTraits(unittest.TestCase): results = check_if_attr_exists(trait_obj, "id_type") result2 = check_if_attr_exists(trait_obj2, "sample_name") self.assertIsInstance(trait_obj, TraitObject) - self.assertTrue(results, True) - self.assertTrue(result2, True) + self.assertIs(results, True) + self.assertIs(result2, True) + def test_check_if_attr_exists_empty_attr(self): """test if attributes exists with false return""" @@ -39,14 +39,14 @@ class TestTraits(unittest.TestCase): trait_obj2 = TraitObject({"group": None}) result = check_if_attr_exists(trait_obj, "sample") result2 = check_if_attr_exists(trait_obj, "group") - self.assertFalse(result, False) - self.assertFalse(result2, False) + self.assertIs(result, False) + self.assertIs(result2, False) def test_check_if_attr_exists_falsey(self): """check if attribute exists with empty attributes""" trait_obj = TraitObject({}) results = check_if_attr_exists(trait_obj, "any") - self.assertFalse(results, False) + self.assertIs(results, False) @mock.patch("wqflask.show_trait.show_trait.requests.get") @mock.patch("wqflask.show_trait.show_trait.check_if_attr_exists") @@ -124,8 +124,8 @@ class TestTraits(unittest.TestCase): results = has_num_cases(create_trait) - self.assertTrue(has_num_cases(create_trait), True) - self.assertFalse(has_num_cases(create_trait2), False) + self.assertIs(has_num_cases(create_trait), True) + self.assertIs(has_num_cases(create_trait2), False) def test_get_table_widths(self): """test for getting table widths""" -- cgit v1.2.3 From 7da9a5206800d305f97b025e180300ca451ac92d Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Tue, 3 Nov 2020 17:08:05 +0300 Subject: switch from assertFalse to assertIs --- wqflask/tests/wqflask/show_trait/test_show_trait.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wqflask/tests/wqflask/show_trait/test_show_trait.py b/wqflask/tests/wqflask/show_trait/test_show_trait.py index f666912b..ec45d558 100644 --- a/wqflask/tests/wqflask/show_trait/test_show_trait.py +++ b/wqflask/tests/wqflask/show_trait/test_show_trait.py @@ -31,7 +31,6 @@ class TestTraits(unittest.TestCase): self.assertIsInstance(trait_obj, TraitObject) self.assertIs(results, True) self.assertIs(result2, True) - def test_check_if_attr_exists_empty_attr(self): """test if attributes exists with false return""" @@ -98,7 +97,7 @@ class TestTraits(unittest.TestCase): create_dataset = TraitObject({"type": "ProbeSet"}) create_trait = TraitObject({"dataset": create_dataset}) - self.assertFalse(has_num_cases(create_trait), False) + self.assertIs(has_num_cases(create_trait), False) def test_hash_num_cases_no_probeset(self): """test for hash num cases with dataset.type not Probeset""" -- cgit v1.2.3 From 4b6d964ccf484225f568361b3bc6136a758cd475 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Tue, 3 Nov 2020 20:15:39 +0300 Subject: add tests for the get_categorical_variables function --- wqflask/tests/wqflask/show_trait/test_show_trait.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/wqflask/tests/wqflask/show_trait/test_show_trait.py b/wqflask/tests/wqflask/show_trait/test_show_trait.py index ec45d558..f7133292 100644 --- a/wqflask/tests/wqflask/show_trait/test_show_trait.py +++ b/wqflask/tests/wqflask/show_trait/test_show_trait.py @@ -155,7 +155,22 @@ class TestTraits(unittest.TestCase): self.assertEqual(get_categorical_variables(trait, sample_list), []) def test_get_categorical_variables_with_sample_attributes(self): - pass + this_trait=TraitObject({"data":{ + "Gene1":TraitObject({"extra_attributes":{"ex1":"ex1value"}}), + "Gene2":TraitObject({"extra_attributes":{"ex2":"ex2value"}}), + "Gene3":TraitObject({"extra_attributes":{"ex3":"ex3value"}}) + }}) + sample_list=TraitObject({"attributes":{ + "sample_attribute_1":TraitObject({"name":"ex1"}), + "sample_attribute_2":TraitObject({"name":"ex2"}), + "sample_attribute_3":TraitObject({"name":"ex3"}), + "sample_attribute_4":TraitObject({"name":"not_in_extra_attributes"}), + + + }}) + + results=get_categorical_variables(this_trait,sample_list) + self.assertEqual(["ex1","ex2","ex3","not_in_extra_attributes"],results) def test_get_trait_units(self): """test for getting trait units""" -- cgit v1.2.3 From 68f71e11343789266ccac6e079dd0bc1b16d407f Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Tue, 3 Nov 2020 20:23:19 +0300 Subject: add pep8 formatting --- wqflask/tests/wqflask/show_trait/test_show_trait.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wqflask/tests/wqflask/show_trait/test_show_trait.py b/wqflask/tests/wqflask/show_trait/test_show_trait.py index f7133292..f41b7288 100644 --- a/wqflask/tests/wqflask/show_trait/test_show_trait.py +++ b/wqflask/tests/wqflask/show_trait/test_show_trait.py @@ -155,6 +155,7 @@ class TestTraits(unittest.TestCase): self.assertEqual(get_categorical_variables(trait, sample_list), []) def test_get_categorical_variables_with_sample_attributes(self): + """test for getting categorical variable names with no samples""" this_trait=TraitObject({"data":{ "Gene1":TraitObject({"extra_attributes":{"ex1":"ex1value"}}), "Gene2":TraitObject({"extra_attributes":{"ex2":"ex2value"}}), @@ -169,6 +170,8 @@ class TestTraits(unittest.TestCase): }}) + # + results=get_categorical_variables(this_trait,sample_list) self.assertEqual(["ex1","ex2","ex3","not_in_extra_attributes"],results) -- cgit v1.2.3 From 8630b727d80f52b3e846c9eb3bf7dd4e844fa626 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Tue, 3 Nov 2020 20:34:00 +0300 Subject: remove unnecessary comments --- .../tests/wqflask/show_trait/test_show_trait.py | 35 +++++++++++----------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/wqflask/tests/wqflask/show_trait/test_show_trait.py b/wqflask/tests/wqflask/show_trait/test_show_trait.py index f41b7288..c617e9f2 100644 --- a/wqflask/tests/wqflask/show_trait/test_show_trait.py +++ b/wqflask/tests/wqflask/show_trait/test_show_trait.py @@ -156,24 +156,23 @@ class TestTraits(unittest.TestCase): def test_get_categorical_variables_with_sample_attributes(self): """test for getting categorical variable names with no samples""" - this_trait=TraitObject({"data":{ - "Gene1":TraitObject({"extra_attributes":{"ex1":"ex1value"}}), - "Gene2":TraitObject({"extra_attributes":{"ex2":"ex2value"}}), - "Gene3":TraitObject({"extra_attributes":{"ex3":"ex3value"}}) - }}) - sample_list=TraitObject({"attributes":{ - "sample_attribute_1":TraitObject({"name":"ex1"}), - "sample_attribute_2":TraitObject({"name":"ex2"}), - "sample_attribute_3":TraitObject({"name":"ex3"}), - "sample_attribute_4":TraitObject({"name":"not_in_extra_attributes"}), - - - }}) - - # - - results=get_categorical_variables(this_trait,sample_list) - self.assertEqual(["ex1","ex2","ex3","not_in_extra_attributes"],results) + this_trait = TraitObject({"data": { + "Gene1": TraitObject({"extra_attributes": {"ex1": "ex1value"}}), + "Gene2": TraitObject({"extra_attributes": {"ex2": "ex2value"}}), + "Gene3": TraitObject({"extra_attributes": {"ex3": "ex3value"}}) + }}) + sample_list = TraitObject({"attributes": { + "sample_attribute_1": TraitObject({"name": "ex1"}), + "sample_attribute_2": TraitObject({"name": "ex2"}), + "sample_attribute_3": TraitObject({"name": "ex3"}), + "sample_attribute_4": TraitObject({"name": "not_in_extra_attributes"}), + + + }}) + + results = get_categorical_variables(this_trait, sample_list) + self.assertEqual( + ["ex1", "ex2", "ex3", "not_in_extra_attributes"], results) def test_get_trait_units(self): """test for getting trait units""" -- cgit v1.2.3 From bd8c764f49703ecc5cf25153144ad439c1ca2442 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 3 Nov 2020 22:08:59 +0300 Subject: Update issue and PR templates * .github/ISSUE_TEMPLATE/bug_report.md: Provide explanations in commented out blocks. * .github/ISSUE_TEMPLATE/feature_request.md: Ditto. * .github/PULL_REQUEST_TEMPLATE.md: Ditto. * .github/ISSUE_TEMPLATE/user_story.md: Ditto. --- .github/ISSUE_TEMPLATE/bug_report.md | 16 ++++++++-------- .github/ISSUE_TEMPLATE/feature_request.md | 23 +++++++++++++++-------- .github/ISSUE_TEMPLATE/user_story.md | 8 ++++---- .github/PULL_REQUEST_TEMPLATE.md | 9 +++++++++ 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 7d7e34a5..48bad39b 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -9,26 +9,26 @@ assignees: '' **Describe the bug** -A clear and concise description of what the bug is. + **To Reproduce** -Steps to reproduce the behavior + **Expected behavior** -A clear and concise description of what you expected to happen. + **Screenshots** -If applicable, add screenshots to help explain your problem. + **Environment setup (please complete the following information):** -- OS: [e.g. Linux] -- Guix Version (optional) -- [Anything else you think is relevant] + + + **Additional context** -Add any other context about the problem here. + diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 254754c6..eb6c3e4b 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -9,26 +9,33 @@ assignees: '' ## Is your feature request related to a problem? Please describe. -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + + + ## Describe the solution you'd like -A clear and concise description of what you want to happen. + ## Describe alternatives you've considered -A clear and concise description of any alternative solutions or features you've considered. + ## User Stories (optional) -As a _[role or persona]_, I want _[goal/ need]_ so that _[why]_ + + + + + -**Feature:** _[Brief description of feature]_ + -_[Any additional descriptions on feature]_ + ## Additional context -Add any other context or screenshots about the feature request here. + diff --git a/.github/ISSUE_TEMPLATE/user_story.md b/.github/ISSUE_TEMPLATE/user_story.md index 2682fc98..52ae775d 100644 --- a/.github/ISSUE_TEMPLATE/user_story.md +++ b/.github/ISSUE_TEMPLATE/user_story.md @@ -7,10 +7,10 @@ assignees: '' --- -As a _[role or persona]_, I want _[goal/ need]_ so that _[why]_ + -**Feature:** _[Brief description of feature]_ + -_[Any additional descriptions on feature]_ + -**Scenario:** Please use _[Gherkin](https://cucumber.io/docs/gherkin/reference/)_ here + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 223e24ef..f3371183 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,11 +1,20 @@ #### Description + #### How should this be tested? + #### Any background context you want to provide? + + #### What are the relevant pivotal tracker stories? + + #### Screenshots (if appropriate) #### Questions + + -- cgit v1.2.3 From 1d00c9ad8348f7d58e3a6371a67df479d78ae45e Mon Sep 17 00:00:00 2001 From: zsloan Date: Tue, 3 Nov 2020 13:52:29 -0600 Subject: Joined sample names in primary_samples and all_samples with commas because this list was being split to get the N of samples; not sure why this was working before * wqflask/wqflask/show_trait/show_trait.py primary_samples and all_samples passed as hidden form inputs now have names split by commas so they can be counted correctly when displaying the N on the mapping loading screen --- wqflask/wqflask/show_trait/show_trait.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py index edf9638c..25ba1a1d 100644 --- a/wqflask/wqflask/show_trait/show_trait.py +++ b/wqflask/wqflask/show_trait/show_trait.py @@ -228,8 +228,8 @@ class ShowTrait(object): hddn = OrderedDict() if self.dataset.group.allsamples: - hddn['allsamples'] = ''.join(self.dataset.group.allsamples) - hddn['primary_samples'] = ''.join(self.primary_sample_names) + hddn['allsamples'] = ','.join(self.dataset.group.allsamples) + hddn['primary_samples'] = ','.join(self.primary_sample_names) hddn['trait_id'] = self.trait_id hddn['trait_display_name'] = self.this_trait.display_name hddn['dataset'] = self.dataset.name -- cgit v1.2.3 From 5e08316b491a6225eddbc27cfdd799cff1bc0283 Mon Sep 17 00:00:00 2001 From: zsloan Date: Tue, 3 Nov 2020 15:18:25 -0600 Subject: Fixed a sort used when doing the haplotype analysis to be compatible with Python 3 * wqflask/wqflask/marker_regression/display_mapping_results.py - The arguments for sort are different in Python 3, so it was changed to be compatible --- wqflask/wqflask/marker_regression/display_mapping_results.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wqflask/wqflask/marker_regression/display_mapping_results.py b/wqflask/wqflask/marker_regression/display_mapping_results.py index 7e43f6bd..b5686b70 100644 --- a/wqflask/wqflask/marker_regression/display_mapping_results.py +++ b/wqflask/wqflask/marker_regression/display_mapping_results.py @@ -1460,7 +1460,7 @@ class DisplayMappingResults(object): else: continue - smd.sort(lambda A, B: cmp(A.value, B.value)) + smd.sort(key = lambda A: A.value) smd.reverse() samplelist = list(self.genotype.prgy) -- cgit v1.2.3 From 96b095aa83ed113250442e4c6f180c7dd66d3e0e Mon Sep 17 00:00:00 2001 From: zsloan Date: Tue, 3 Nov 2020 15:20:05 -0600 Subject: Changed the syntax for the "sort" function in the docstring of GeneralObject to be compatible with Python 3 syntax * wqflask/base/GeneralObject.py - edited docstring to be correct for Python 3 --- wqflask/base/GeneralObject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wqflask/base/GeneralObject.py b/wqflask/base/GeneralObject.py index 0122ee32..249195e2 100644 --- a/wqflask/base/GeneralObject.py +++ b/wqflask/base/GeneralObject.py @@ -28,7 +28,7 @@ class GeneralObject: """ Base class to define an Object. a = [Spam(1, 4), Spam(9, 3), Spam(4,6)] - a.sort(lambda x, y: cmp(x.eggs, y.eggs)) + a.sort(key = lambda x: x.eggs) """ def __init__(self, *args, **kw): -- cgit v1.2.3 From 23915d8102b8a05930cf3fd16d651a460ebd2f58 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Wed, 4 Nov 2020 09:49:13 +0300 Subject: remove whitespace and assertIs --- .../tests/wqflask/show_trait/test_show_trait.py | 30 ++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/wqflask/tests/wqflask/show_trait/test_show_trait.py b/wqflask/tests/wqflask/show_trait/test_show_trait.py index c617e9f2..04c68045 100644 --- a/wqflask/tests/wqflask/show_trait/test_show_trait.py +++ b/wqflask/tests/wqflask/show_trait/test_show_trait.py @@ -2,11 +2,15 @@ import unittest from unittest import mock from wqflask import app -from wqflask.show_trait.show_trait import (check_if_attr_exists, get_ncbi_summary, - has_num_cases, get_table_widths, - get_categorical_variables, - get_trait_units, get_nearest_marker, get_genotype_scales, requests) - +from wqflask.show_trait.show_trait import check_if_attr_exists +from wqflask.show_trait.show_trait import get_ncbi_summary +from wqflask.show_trait.show_trait import has_num_cases +from wqflask.show_trait.show_trait import get_table_widths +from wqflask.show_trait.show_trait import get_categorical_variables +from wqflask.show_trait.show_trait import get_trait_units +from wqflask.show_trait.show_trait import get_nearest_marker +from wqflask.show_trait.show_trait import get_genotype_scales +from wqflask.show_trait.show_trait import requests class TraitObject: def __init__(self, obj): @@ -29,8 +33,8 @@ class TestTraits(unittest.TestCase): results = check_if_attr_exists(trait_obj, "id_type") result2 = check_if_attr_exists(trait_obj2, "sample_name") self.assertIsInstance(trait_obj, TraitObject) - self.assertIs(results, True) - self.assertIs(result2, True) + self.assertTrue(results) + self.assertTrue(result2) def test_check_if_attr_exists_empty_attr(self): """test if attributes exists with false return""" @@ -38,14 +42,14 @@ class TestTraits(unittest.TestCase): trait_obj2 = TraitObject({"group": None}) result = check_if_attr_exists(trait_obj, "sample") result2 = check_if_attr_exists(trait_obj, "group") - self.assertIs(result, False) - self.assertIs(result2, False) + self.assertFalse(result) + self.assertFalse(result2) def test_check_if_attr_exists_falsey(self): """check if attribute exists with empty attributes""" trait_obj = TraitObject({}) results = check_if_attr_exists(trait_obj, "any") - self.assertIs(results, False) + self.assertFalse(results) @mock.patch("wqflask.show_trait.show_trait.requests.get") @mock.patch("wqflask.show_trait.show_trait.check_if_attr_exists") @@ -97,7 +101,7 @@ class TestTraits(unittest.TestCase): create_dataset = TraitObject({"type": "ProbeSet"}) create_trait = TraitObject({"dataset": create_dataset}) - self.assertIs(has_num_cases(create_trait), False) + self.assertFalse(has_num_cases(create_trait)) def test_hash_num_cases_no_probeset(self): """test for hash num cases with dataset.type not Probeset""" @@ -123,8 +127,8 @@ class TestTraits(unittest.TestCase): results = has_num_cases(create_trait) - self.assertIs(has_num_cases(create_trait), True) - self.assertIs(has_num_cases(create_trait2), False) + self.assertTrue(has_num_cases(create_trait)) + self.assertFalse(has_num_cases(create_trait2)) def test_get_table_widths(self): """test for getting table widths""" -- cgit v1.2.3 From 9d2134202c0435ad4a18e0ac74ce4a99508f1a76 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Wed, 4 Nov 2020 09:57:35 +0300 Subject: remove whitespace --- wqflask/tests/wqflask/show_trait/test_show_trait.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/wqflask/tests/wqflask/show_trait/test_show_trait.py b/wqflask/tests/wqflask/show_trait/test_show_trait.py index 04c68045..f82a4c04 100644 --- a/wqflask/tests/wqflask/show_trait/test_show_trait.py +++ b/wqflask/tests/wqflask/show_trait/test_show_trait.py @@ -3,7 +3,7 @@ import unittest from unittest import mock from wqflask import app from wqflask.show_trait.show_trait import check_if_attr_exists -from wqflask.show_trait.show_trait import get_ncbi_summary +from wqflask.show_trait.show_trait import get_ncbi_summary from wqflask.show_trait.show_trait import has_num_cases from wqflask.show_trait.show_trait import get_table_widths from wqflask.show_trait.show_trait import get_categorical_variables @@ -12,6 +12,7 @@ from wqflask.show_trait.show_trait import get_nearest_marker from wqflask.show_trait.show_trait import get_genotype_scales from wqflask.show_trait.show_trait import requests + class TraitObject: def __init__(self, obj): for key, value in obj.items(): @@ -169,9 +170,7 @@ class TestTraits(unittest.TestCase): "sample_attribute_1": TraitObject({"name": "ex1"}), "sample_attribute_2": TraitObject({"name": "ex2"}), "sample_attribute_3": TraitObject({"name": "ex3"}), - "sample_attribute_4": TraitObject({"name": "not_in_extra_attributes"}), - - + "sample_attribute_4": TraitObject({"name": "not_in_extra_attributes"}) }}) results = get_categorical_variables(this_trait, sample_list) -- cgit v1.2.3 From 1ef7c3cd7bc148bac8a6b47f62ba02c3819bf1f3 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Wed, 4 Nov 2020 10:08:32 +0300 Subject: remove whitespace in line 119-120 --- wqflask/tests/wqflask/show_trait/test_show_trait.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/wqflask/tests/wqflask/show_trait/test_show_trait.py b/wqflask/tests/wqflask/show_trait/test_show_trait.py index f82a4c04..70061e2d 100644 --- a/wqflask/tests/wqflask/show_trait/test_show_trait.py +++ b/wqflask/tests/wqflask/show_trait/test_show_trait.py @@ -117,8 +117,6 @@ class TestTraits(unittest.TestCase): "nm1": TraitObject({"num_cases": False}), "nm2": TraitObject({"num_cases": False}), "nm3": TraitObject({"num_cases": False}) - - } create_trait = TraitObject( -- cgit v1.2.3 From f90e77fab78c4504ac9dabb188459ab5d03ac287 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Wed, 4 Nov 2020 10:15:05 +0300 Subject: remove extra whitespace --- wqflask/tests/wqflask/show_trait/test_show_trait.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/wqflask/tests/wqflask/show_trait/test_show_trait.py b/wqflask/tests/wqflask/show_trait/test_show_trait.py index 70061e2d..ce850c8b 100644 --- a/wqflask/tests/wqflask/show_trait/test_show_trait.py +++ b/wqflask/tests/wqflask/show_trait/test_show_trait.py @@ -67,11 +67,8 @@ class TestTraits(unittest.TestCase): } } """ - get_return_obj = TraitObject({"content": content_json_string}) - mock_get.return_value = get_return_obj - results = get_ncbi_summary(trait) mock_exists.assert_called_once() mock_get.assert_called_once_with(f"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=gene&id={trait.geneid}&retmode=json") @@ -93,7 +90,6 @@ class TestTraits(unittest.TestCase): } } """ - results = get_ncbi_summary(trait) self.assertEqual(results, None) @@ -101,13 +97,11 @@ class TestTraits(unittest.TestCase): """test for hash num_cases with dataset.type set to Probeset""" create_dataset = TraitObject({"type": "ProbeSet"}) create_trait = TraitObject({"dataset": create_dataset}) - self.assertFalse(has_num_cases(create_trait)) def test_hash_num_cases_no_probeset(self): """test for hash num cases with dataset.type not Probeset""" create_dataset = TraitObject({"type": "Temp"}) - construct_data = { "nm1": TraitObject({"num_cases": False}), "nm2": TraitObject({"num_cases": True}), @@ -125,7 +119,6 @@ class TestTraits(unittest.TestCase): {"dataset": create_dataset, "data": construct_data2}) results = has_num_cases(create_trait) - self.assertTrue(has_num_cases(create_trait)) self.assertFalse(has_num_cases(create_trait2)) @@ -144,7 +137,6 @@ class TestTraits(unittest.TestCase): expected_with_numcase = (450, "750px") expected_no_numcase = (450, "670px") expected_one_sample = (250, "540px") - self.assertEqual(results_with_numcase, expected_with_numcase) self.assertEqual(result_no_numcase, expected_no_numcase) self.assertEqual(results_one_sample, @@ -154,7 +146,6 @@ class TestTraits(unittest.TestCase): """test for getting categorical variable names with no samples""" trait = TraitObject({}) sample_list = TraitObject({"se_exists": True, "attributes": []}) - self.assertEqual(get_categorical_variables(trait, sample_list), []) def test_get_categorical_variables_with_sample_attributes(self): @@ -179,9 +170,7 @@ class TestTraits(unittest.TestCase): """test for getting trait units""" trait = TraitObject( {"description_fmt": "[this is a description] another test [N/A]"}) - trait_no_unit_type = TraitObject({"description_fmt": ""}) - results = get_trait_units(trait) results_no_unit = get_trait_units(trait_no_unit_type) self.assertEqual(results, "this is a descriptionN/A") @@ -195,13 +184,9 @@ class TestTraits(unittest.TestCase): ["Geno1", "Geno2"], ["Geno3"]] trait = TraitObject({"locus_chr": "test_chr", "locus_mb": "test_mb"}) - group_name = TraitObject({"name": "group_name"}) - this_db = TraitObject({"group": group_name}) - results_with_item_db = get_nearest_marker(trait, this_db) - called_with_value = """SELECT Geno.Name FROM Geno, GenoXRef, GenoFreeze WHERE Geno.Chr = 'test_chr' AND @@ -218,11 +203,9 @@ class TestTraits(unittest.TestCase): def test_get_nearest_marker_empty_db(self, mock_db): """test for getting nearest marker with empty db""" mock_db.db.execute.return_value.fetchall.return_value = [] - trait = TraitObject({"locus_chr": "test_chr", "locus_mb": "test_mb"}) group_name = TraitObject({"name": "group_name"}) this_db = TraitObject({"group": group_name}) - results_empty_db = get_nearest_marker(trait, this_db) mock_db.db.execute.assert_called_once() self.assertEqual(results_empty_db, "") @@ -240,7 +223,6 @@ class TestTraits(unittest.TestCase): [["physic", "Mb"]]] results = get_genotype_scales(genofiles_list) - expected_results = { "~/data/files/f1": [["morgan", "cM"]], "~/data/files/f2": [["morgan", "cM"]], @@ -249,7 +231,6 @@ class TestTraits(unittest.TestCase): multiple_calls = [mock.call('~/data/files/f1'), mock.call('~/data/files/f2'), mock.call('~/data/files/f3')] - mock_get_scales.assert_has_calls(multiple_calls) self.assertEqual(results, expected_results) @@ -258,8 +239,6 @@ class TestTraits(unittest.TestCase): """test for getting genotype scales with genofile as a string""" file_location = "~/another_file_location" mock_get_scales.return_value = [["physic", "Mb"]] - expected_results = {f"{file_location}": [["physic", "Mb"]]} - self.assertEqual(get_genotype_scales(file_location), expected_results) mock_get_scales.assert_called_once_with(file_location) -- cgit v1.2.3 From 3f08f54fe3d42eca0ccf98831e4e339defa17720 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Wed, 4 Nov 2020 10:25:50 +0300 Subject: correct a typo --- wqflask/tests/wqflask/show_trait/test_show_trait.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/wqflask/tests/wqflask/show_trait/test_show_trait.py b/wqflask/tests/wqflask/show_trait/test_show_trait.py index ce850c8b..24150738 100644 --- a/wqflask/tests/wqflask/show_trait/test_show_trait.py +++ b/wqflask/tests/wqflask/show_trait/test_show_trait.py @@ -112,7 +112,6 @@ class TestTraits(unittest.TestCase): "nm2": TraitObject({"num_cases": False}), "nm3": TraitObject({"num_cases": False}) } - create_trait = TraitObject( {"dataset": create_dataset, "data": construct_data}) create_trait2 = TraitObject( @@ -161,7 +160,6 @@ class TestTraits(unittest.TestCase): "sample_attribute_3": TraitObject({"name": "ex3"}), "sample_attribute_4": TraitObject({"name": "not_in_extra_attributes"}) }}) - results = get_categorical_variables(this_trait, sample_list) self.assertEqual( ["ex1", "ex2", "ex3", "not_in_extra_attributes"], results) -- cgit v1.2.3 From 1948d1ed9e8647b1f54c87a59aa308b9d22c7f8e Mon Sep 17 00:00:00 2001 From: zsloan Date: Wed, 4 Nov 2020 15:57:58 -0600 Subject: Changed numeric-html sorting for the Tissue/Lit r columns to natural-minus-na so it deals with the "--" values * wqflask/wqflask/templates/correlation_page.html - Replaced numeric-html sorting with natural-minus-na for the lit/tissue r columns --- wqflask/wqflask/templates/correlation_page.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wqflask/wqflask/templates/correlation_page.html b/wqflask/wqflask/templates/correlation_page.html index 134f15be..bc0b592c 100644 --- a/wqflask/wqflask/templates/correlation_page.html +++ b/wqflask/wqflask/templates/correlation_page.html @@ -367,8 +367,8 @@ { "orderDataType": "dom-innertext", 'orderSequence': [ "desc", "asc"] }, { "type": "natural" }, { "type": "scientific" }, - { "type": "numeric-html", 'orderSequence': [ "desc", "asc"] }, - { "type": "numeric-html", 'orderSequence': [ "desc", "asc"] }, + { "type": "natural-minus-na", 'orderSequence': [ "desc", "asc"] }, + { "type": "natural-minus-na", 'orderSequence': [ "desc", "asc"] }, { "type": "scientific" }, { "type": "natural-minus-na" }, { "type": "natural-minus-na" }, -- cgit v1.2.3 From 97a61adb2516da2a286e9c01352c0d0d62041523 Mon Sep 17 00:00:00 2001 From: zsloan Date: Fri, 6 Nov 2020 13:55:13 -0600 Subject: After I changed some class names in the trait page to use - instead of _ (to keep naming consistent) I forgot to change the references in show_trait_mapping_tools.js (which broke the functionality of clicking a tab doing mapping) --- wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js b/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js index c0f36eaa..34582f21 100644 --- a/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js +++ b/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js @@ -147,7 +147,7 @@ var mapping_input_list = ['temp_uuid', 'trait_id', 'dataset', 'tool_used', 'form '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'] -$(".rqtl_tab, #rqtl_geno_compute").on("click", (function(_this) { +$(".rqtl-tab, #rqtl_geno_compute").on("click", (function(_this) { return function() { if ($(this).hasClass('active') || $(this).attr('id') == "rqtl_geno_compute"){ var form_data, url; @@ -171,7 +171,7 @@ $(".rqtl_tab, #rqtl_geno_compute").on("click", (function(_this) { }; })(this)); -$(".gemma_tab, #gemma_compute").on("click", (function(_this) { +$(".gemma-tab, #gemma_compute").on("click", (function(_this) { return function() { if ($(this).hasClass('active') || $(this).attr('id') == "gemma_compute"){ var form_data, url; @@ -192,7 +192,7 @@ $(".gemma_tab, #gemma_compute").on("click", (function(_this) { }; })(this)); -$(".reaper_tab, #interval_mapping_compute").on("click", (function(_this) { +$(".reaper-tab, #interval_mapping_compute").on("click", (function(_this) { return function() { if ($(this).hasClass('active') || $(this).attr('id') == "interval_mapping_compute"){ var form_data, url; @@ -260,7 +260,7 @@ $("#mapmethod_rqtl_geno").change(function() { } }); -$("li.mapping_tab").click(function() { +$("li.mapping-tab").click(function() { if ($(this).hasClass("rqtl")){ $(".rqtl_description").css("display", "block"); } else { -- cgit v1.2.3 From 795ac6bc82d7501a8898fea69141fc942c1ae1aa Mon Sep 17 00:00:00 2001 From: zsloan Date: Fri, 6 Nov 2020 13:59:51 -0600 Subject: Increased the min-width for the show_trait page container div for all the accordion sections, since previously it could get too narrow and cause text to extend beyong the borders of each accordion area --- wqflask/wqflask/static/new/css/show_trait.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wqflask/wqflask/static/new/css/show_trait.css b/wqflask/wqflask/static/new/css/show_trait.css index d8964f5d..5e1a279b 100644 --- a/wqflask/wqflask/static/new/css/show_trait.css +++ b/wqflask/wqflask/static/new/css/show_trait.css @@ -67,7 +67,7 @@ table.dataTable.cell-border tbody tr td:first-child { } .showtrait-main-div { - min-width: 700px; + min-width: 1100px; } table.dataTable tbody td.column_name-Checkbox { -- cgit v1.2.3 From 9fec6272f967adf6ad417dbdd96ebd63a411eb3b Mon Sep 17 00:00:00 2001 From: zsloan Date: Fri, 6 Nov 2020 14:15:43 -0600 Subject: Added new css file for pages that have trait list tables (not sure what else to call them, but pages like search results, view collection, and correlation results) --- wqflask/wqflask/static/new/css/trait_list.css | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 wqflask/wqflask/static/new/css/trait_list.css diff --git a/wqflask/wqflask/static/new/css/trait_list.css b/wqflask/wqflask/static/new/css/trait_list.css new file mode 100644 index 00000000..7db3f7b8 --- /dev/null +++ b/wqflask/wqflask/static/new/css/trait_list.css @@ -0,0 +1,7 @@ +div.tool-button-container { + min-width: 950px; +} + +div.collection-table-options{ + min-width: 1100px; +} \ No newline at end of file -- cgit v1.2.3 From b2a126af326b78f414fba3397a4c628a8575b3a6 Mon Sep 17 00:00:00 2001 From: zsloan Date: Fri, 6 Nov 2020 14:16:49 -0600 Subject: Added min-width for the divs containing the analysis tools and table options, since they would look weird if the window shrunk below a certain width Also made some indentation more consistent --- wqflask/wqflask/templates/collections/view.html | 33 ++++++++++++++----------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/wqflask/wqflask/templates/collections/view.html b/wqflask/wqflask/templates/collections/view.html index d1a97310..13497823 100644 --- a/wqflask/wqflask/templates/collections/view.html +++ b/wqflask/wqflask/templates/collections/view.html @@ -4,6 +4,7 @@ + {% endblock %} {% block content %} @@ -16,7 +17,7 @@

This collection has {{ '{}'.format(numify(trait_obs|count, "record", "records")) }}

-
+
@@ -68,20 +69,22 @@

- - - - - - - - - - - - - - +
+
+ + + + + + + + + + + + +
+
Show/Hide Columns:
-- cgit v1.2.3 From 4fd42c0dfce935935fa041a5eaaed6fafea2785b Mon Sep 17 00:00:00 2001 From: zsloan Date: Fri, 6 Nov 2020 14:46:30 -0600 Subject: Changed the show/hide column buttons to use DataTables API + a few other changes (for some reason none of my changes could be pushed from one of my local branches to origin/testing, so they're combined in this commit) - Fixed a couple column header glossary links to point to GN1 - Added trait_list.css for styling a couple elements common to similar pages (like correlations or view collection) --- wqflask/wqflask/static/new/css/trait_list.css | 7 ++- wqflask/wqflask/templates/search_result_page.html | 76 ++++++++++++++--------- 2 files changed, 54 insertions(+), 29 deletions(-) diff --git a/wqflask/wqflask/static/new/css/trait_list.css b/wqflask/wqflask/static/new/css/trait_list.css index 7db3f7b8..691dcb12 100644 --- a/wqflask/wqflask/static/new/css/trait_list.css +++ b/wqflask/wqflask/static/new/css/trait_list.css @@ -2,6 +2,11 @@ div.tool-button-container { min-width: 950px; } -div.collection-table-options{ +div.collection-table-options { min-width: 1100px; +} + +div.show-hide-container { + margin-bottom: 5px; + margin-top: 10px; } \ No newline at end of file diff --git a/wqflask/wqflask/templates/search_result_page.html b/wqflask/wqflask/templates/search_result_page.html index 2318bfb8..38f224e0 100644 --- a/wqflask/wqflask/templates/search_result_page.html +++ b/wqflask/wqflask/templates/search_result_page.html @@ -5,6 +5,7 @@ + {% endblock %} {% block content %} @@ -40,10 +41,10 @@ {% elif word.search_term|length == 5 %} with {{ word.key|upper }} between {{ word.search_term[0] }} and {{ word.search_term[1] }} on chromosome {{ word.search_term[2] }} between {{ word.search_term[3] }} and {{ word.search_term[4] }} Mb{% if loop.last %}.{% else %} and {% endif %} {% endif %} - {% elif word.key|lower == "position" %} - with target genes on chromosome {% if word.search_term[0].split('chr')|length > 1 %}{{ word.search_term[0].split('chr')[1] }}{% elif word.search_term[0].split('CHR')|length > 1 %}{{ word.search_term[0].split('CHR')[1] }}{% else %}{{ word.search_term[0] }}{% endif %} between {{ word.search_term[1] }} and {{ word.search_term[2] }} Mb{% if loop.last %}.{% else %} and {% endif %} + {% elif word.key|lower == "position" or word.key|lower == "mb" %} + with target genes on chromosome {% if (word.search_term[0]|lower).split('chr')|length > 1 %}{{ (word.search_term[0]|lower).split('chr')[1] }}{% else %}{{ word.search_term[0] }}{% endif %} between {{ word.search_term[1] }} and {{ word.search_term[2] }} Mb{% if loop.last %}.{% else %} and {% endif %} {% else %} - {% if word.search_term[0] == "*" %} in the dataset.{% else %}{% if loop.first %}that match:
{% endif %}"{{ word.search_term[0] }}"{% if loop.last %}{% else %} and {% endif %}{% endif %} + {% if word.search_term[0] == "*" %} in the dataset.{% else %}{% if loop.first %}that match:
{% endif %}{{ word.search_term[0] }}{% if loop.last %}{% else %} and {% endif %}{% endif %} {% endif %} {% endfor %} {% endif %} @@ -133,11 +134,29 @@
-
{% if dataset.type != 'Geno' %} -
-
+
Show/Hide Columns: +
+ + + {% if dataset.type == 'ProbeSet' %} + + + + + + + + {% elif dataset.type == 'Publish' %} + + + + + + + + {% endif %}
{% endif %}
@@ -209,7 +228,7 @@ } //ZS: Need to make sort by symbol, also need to make sure blank symbol fields at the bottom and symbols starting with numbers below letters - $('#trait_table').DataTable( { + trait_table = $('#trait_table').DataTable( { 'drawCallback': function( settings ) { $('#trait_table tr').click(function(event) { if (event.target.type !== 'checkbox' && event.target.tagName.toLowerCase() !== 'a') { @@ -312,7 +331,7 @@ 'orderSequence': [ "desc", "asc"] }, { - 'title': "High P ?", + 'title': "High P ?", 'type': "natural-minus-na", 'data': "lrs_score", 'width': "60px", @@ -325,7 +344,7 @@ 'data': "lrs_location" }, { - 'title': "Effect Size ?", + 'title': "Effect Size ?", 'type': "natural-minus-na", 'data': "additive", 'width': "85px", @@ -381,7 +400,7 @@ 'orderSequence': [ "desc", "asc"] }, { - 'title': "Max LRS ?", + 'title': "High P ?", 'type': "natural-minus-na", 'data': "lrs_score", 'width': "80px", @@ -394,7 +413,7 @@ 'data': "lrs_location" }, { - 'title': "Effect Size ?", + 'title': "Effect Size ?", 'type': "natural-minus-na", 'width': "120px", 'data': "additive", @@ -408,24 +427,7 @@ }{% endif %} ], "order": [[1, "asc" ]], - {% if dataset.type != 'Geno' %} - buttons: [ - { - extend: 'columnsToggle', - columns: function( idx, data, node ) { - if (idx != 0) { - return true; - } else { - return false; - } - }, - postfixButtons: [ 'colvisRestore' ] - } - ], - 'sDom': "Bpitirp", - {% else %} 'sDom': "pitirp", - {% endif %} 'iDisplayLength': 500, 'deferRender': true, 'paging': true, @@ -439,6 +441,23 @@ console.timeEnd("Creating table"); + $('.toggle-vis').on( 'click', function (e) { + e.preventDefault(); + + // Get the column API object + var column = trait_table.column( $(this).attr('data-column') ); + + // Toggle the visibility + column.visible( ! column.visible() ); + + if (column.visible()){ + $(this).removeClass("active"); + } else { + $(this).addClass("active"); + } + } ); + + $('#redraw').click(function() { var table = $('#trait_table').DataTable(); table.colReorder.reset() @@ -452,3 +471,4 @@ }); {% endblock %} + -- cgit v1.2.3 From 9560e6337d00a82d8f36073b31215735eb9a8c01 Mon Sep 17 00:00:00 2001 From: zsloan Date: Fri, 6 Nov 2020 14:49:15 -0600 Subject: Removed the page selection from the top of the table because it created an awkward gap between the column show/hide buttons and the table, and this table will be changed to use Scroller instead of paging soon regardless --- 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 38f224e0..b3f56293 100644 --- a/wqflask/wqflask/templates/search_result_page.html +++ b/wqflask/wqflask/templates/search_result_page.html @@ -427,7 +427,7 @@ }{% endif %} ], "order": [[1, "asc" ]], - 'sDom': "pitirp", + 'sDom': "itirp", 'iDisplayLength': 500, 'deferRender': true, 'paging': true, -- cgit v1.2.3 From ddcd54b505384b3d8f70c82cc97b9781672c5fb6 Mon Sep 17 00:00:00 2001 From: zsloan Date: Tue, 10 Nov 2020 13:02:15 -0600 Subject: Changed "BXD-Harvested" to "BXD-Longevity" since that group was renamed and using the wrong name was causing correlations to not work. --- wqflask/wqflask/show_trait/show_trait.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py index 25ba1a1d..0c6ae198 100644 --- a/wqflask/wqflask/show_trait/show_trait.py +++ b/wqflask/wqflask/show_trait/show_trait.py @@ -372,7 +372,7 @@ class ShowTrait(object): # We're checking a string here! assert isinstance(this_group, str), "We need a string type thing here" - if this_group[:3] == 'BXD' and this_group != "BXD-Harvested": + if this_group[:3] == 'BXD' and this_group != "BXD-Longevity": this_group = 'BXD' if this_group: -- cgit v1.2.3 From 61280ad47d8c0486b776011391deadcf7df39819 Mon Sep 17 00:00:00 2001 From: zsloan Date: Tue, 10 Nov 2020 13:36:13 -0600 Subject: Fixed issue where strain values in bytes needed to be decoded when loading a Temp trait --- wqflask/wqflask/show_trait/SampleList.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wqflask/wqflask/show_trait/SampleList.py b/wqflask/wqflask/show_trait/SampleList.py index 37c1d6d5..99ca7f88 100644 --- a/wqflask/wqflask/show_trait/SampleList.py +++ b/wqflask/wqflask/show_trait/SampleList.py @@ -35,7 +35,7 @@ class SampleList(object): # ZS: self.this_trait will be a list if it is a Temp trait if isinstance(self.this_trait, list): if (counter <= len(self.this_trait) and - str(self.this_trait[counter-1]).upper() != 'X'): + self.this_trait[counter-1].decode("utf-8").lower() != 'x'): sample = webqtlCaseData.webqtlCaseData( name=sample_name, value=float(self.this_trait[counter-1])) -- cgit v1.2.3 From 25f7d30b9f052ec5d812bfe3bf9713df850cc267 Mon Sep 17 00:00:00 2001 From: zsloan Date: Tue, 10 Nov 2020 14:24:26 -0600 Subject: Changed logic for creating temp trait SampleList to account for both traits encoded as bytes and traits encoded as strings, since temp traits created before and after the Python 3 switchover will have different encoding --- wqflask/wqflask/show_trait/SampleList.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/wqflask/wqflask/show_trait/SampleList.py b/wqflask/wqflask/show_trait/SampleList.py index 99ca7f88..a535c493 100644 --- a/wqflask/wqflask/show_trait/SampleList.py +++ b/wqflask/wqflask/show_trait/SampleList.py @@ -34,13 +34,18 @@ class SampleList(object): # ZS: self.this_trait will be a list if it is a Temp trait if isinstance(self.this_trait, list): - if (counter <= len(self.this_trait) and - self.this_trait[counter-1].decode("utf-8").lower() != 'x'): - sample = webqtlCaseData.webqtlCaseData( - name=sample_name, - value=float(self.this_trait[counter-1])) - else: - sample = webqtlCaseData.webqtlCaseData(name=sample_name) + sample = webqtlCaseData.webqtlCaseData(name=sample_name) + if counter <= len(self.this_trait): + if isinstance(self.this_trait[counter-1], (bytes, bytearray)): + if (self.this_trait[counter-1].decode("utf-8").lower() != 'x'): + sample = webqtlCaseData.webqtlCaseData( + name=sample_name, + value=float(self.this_trait[counter-1])) + else: + if (self.this_trait[counter-1].lower() != 'x'): + sample = webqtlCaseData.webqtlCaseData( + name=sample_name, + value=float(self.this_trait[counter-1])) else: # ZS - If there's no value for the sample/strain, # create the sample object (so samples with no value -- cgit v1.2.3