From f745117da48e9d46e6a07fb7f930f208c489336a Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Thu, 29 Oct 2020 14:58:00 +0300 Subject: add test for show_trait/export_trait_data --- .../wqflask/show_trait/test_export_trait_data.py | 49 +++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/wqflask/tests/wqflask/show_trait/test_export_trait_data.py b/wqflask/tests/wqflask/show_trait/test_export_trait_data.py index 98d599b1..0c280315 100644 --- a/wqflask/tests/wqflask/show_trait/test_export_trait_data.py +++ b/wqflask/tests/wqflask/show_trait/test_export_trait_data.py @@ -1,10 +1,57 @@ import unittest +from unittest import mock from wqflask.show_trait.export_trait_data import dict_to_sorted_list from wqflask.show_trait.export_trait_data import cmp_samples - +from wqflask.show_trait.export_trait_data import export_sample_table class TestExportTraits(unittest.TestCase): """Test methods related to converting dict to sortedlist""" + @mock.patch("wqflask.show_trait.export_trait_data.dict_to_sorted_list") + @mock.patch("wqflask.show_trait.export_trait_data.get_export_metadata") + def test_export_sample_table(self, exp_metadata, dict_list): + """test for exporting sample table""" + targs_obj = { + "export_data": """{ + "primary_samples": [ + { + "other": "germanotta", + "name": "Sauroniops" + } + ], + "other_samples": [ + { + "se": 1, + "num_cases": 4, + "value": 6, + "name": 3 + } + ] + }""", + "trait_display_name": "Hair_color", + "trait_id": "23177fdc-312e-4084-ad0c-f3eae785fff5", + "dataset": { + } + } + exp_metadata.return_value = [["Phenotype ID:0a2be192-57f5-400b-bbbd-0cf50135995f"], ['Group:gp1'], ["Phenotype:p1"], [ + "Authors:N/A"], ["Title:research1"], ["Journal:N/A"], ["Dataset Link: http://gn1.genenetwork.org/webqtl/main.py?FormID=sharinginfo&InfoPageName=name1"], []] + expected = ('Hair_color', + [['Phenotype ID:0a2be192-57f5-400b-bbbd-0cf50135995f'], + ['Group:gp1'], + ['Phenotype:p1'], + ['Authors:N/A'], + ['Title:research1'], + ['Journal:N/A'], + ['Dataset Link: ' + 'http://gn1.genenetwork.org/webqtl/main.py?FormID=sharinginfo&InfoPageName=name1'], + [], + ['Sauroniops', 'germanotta'], + [3, 6, 1, 4]]) + + dict_list.side_effect = [['Sauroniops', 'germanotta'], [3, 6, 1, 4]] + + self.assertEqual(export_sample_table(targs_obj), expected) + exp_metadata.assert_called_with("23177fdc-312e-4084-ad0c-f3eae785fff5", {}) + self.assertEqual(dict_list.call_count, 2) def test_dict_to_sortedlist(self): """test for conversion of dict to sorted list""" -- cgit v1.2.3 From d72f053343292cf52c7f0dbb8eac03b39037cab1 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Thu, 29 Oct 2020 14:59:57 +0300 Subject: remove print statement in for loop --- wqflask/wqflask/show_trait/export_trait_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wqflask/wqflask/show_trait/export_trait_data.py b/wqflask/wqflask/show_trait/export_trait_data.py index 48feb492..374184eb 100644 --- a/wqflask/wqflask/show_trait/export_trait_data.py +++ b/wqflask/wqflask/show_trait/export_trait_data.py @@ -17,7 +17,7 @@ def export_sample_table(targs): for sample_group in ['primary_samples', 'other_samples']: for row in sample_data[sample_group]: sorted_row = dict_to_sorted_list(row) - print("sorted_row is:", pf(sorted_row)) + #print("sorted_row is:", pf(sorted_row)) final_sample_data.append(sorted_row) return trait_name, final_sample_data -- cgit v1.2.3 From a7c4affd6b50b00ab8801b6daa96b07e88034209 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Thu, 29 Oct 2020 15:02:09 +0300 Subject: format file --- wqflask/tests/wqflask/show_trait/test_export_trait_data.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wqflask/tests/wqflask/show_trait/test_export_trait_data.py b/wqflask/tests/wqflask/show_trait/test_export_trait_data.py index 0c280315..adecbf36 100644 --- a/wqflask/tests/wqflask/show_trait/test_export_trait_data.py +++ b/wqflask/tests/wqflask/show_trait/test_export_trait_data.py @@ -4,6 +4,7 @@ from wqflask.show_trait.export_trait_data import dict_to_sorted_list from wqflask.show_trait.export_trait_data import cmp_samples from wqflask.show_trait.export_trait_data import export_sample_table + class TestExportTraits(unittest.TestCase): """Test methods related to converting dict to sortedlist""" @mock.patch("wqflask.show_trait.export_trait_data.dict_to_sorted_list") @@ -50,7 +51,8 @@ class TestExportTraits(unittest.TestCase): dict_list.side_effect = [['Sauroniops', 'germanotta'], [3, 6, 1, 4]] self.assertEqual(export_sample_table(targs_obj), expected) - exp_metadata.assert_called_with("23177fdc-312e-4084-ad0c-f3eae785fff5", {}) + exp_metadata.assert_called_with( + "23177fdc-312e-4084-ad0c-f3eae785fff5", {}) self.assertEqual(dict_list.call_count, 2) def test_dict_to_sortedlist(self): -- cgit v1.2.3 From 18304a9b20bd4180b40be8296df26c2a0acf62fa Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Thu, 29 Oct 2020 16:07:52 +0300 Subject: resolve merge conflict --- wqflask/wqflask/show_trait/export_trait_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wqflask/wqflask/show_trait/export_trait_data.py b/wqflask/wqflask/show_trait/export_trait_data.py index 374184eb..48feb492 100644 --- a/wqflask/wqflask/show_trait/export_trait_data.py +++ b/wqflask/wqflask/show_trait/export_trait_data.py @@ -17,7 +17,7 @@ def export_sample_table(targs): for sample_group in ['primary_samples', 'other_samples']: for row in sample_data[sample_group]: sorted_row = dict_to_sorted_list(row) - #print("sorted_row is:", pf(sorted_row)) + print("sorted_row is:", pf(sorted_row)) final_sample_data.append(sorted_row) return trait_name, final_sample_data -- cgit v1.2.3 From 242c334dbaa84c93a0c45bc80a050cd0e240d81b Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Thu, 29 Oct 2020 17:23:46 +0300 Subject: add test for show_trait --- .../wqflask/show_trait/test_export_trait_data.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/wqflask/tests/wqflask/show_trait/test_export_trait_data.py b/wqflask/tests/wqflask/show_trait/test_export_trait_data.py index adecbf36..488c9d63 100644 --- a/wqflask/tests/wqflask/show_trait/test_export_trait_data.py +++ b/wqflask/tests/wqflask/show_trait/test_export_trait_data.py @@ -16,7 +16,14 @@ class TestExportTraits(unittest.TestCase): "primary_samples": [ { "other": "germanotta", - "name": "Sauroniops" + "name": "Sauroniops", + "se":{ + "name":"S2" + }, + "num_cases":{ + "k1":"value" + + } } ], "other_samples": [ @@ -33,8 +40,13 @@ class TestExportTraits(unittest.TestCase): "dataset": { } } - exp_metadata.return_value = [["Phenotype ID:0a2be192-57f5-400b-bbbd-0cf50135995f"], ['Group:gp1'], ["Phenotype:p1"], [ - "Authors:N/A"], ["Title:research1"], ["Journal:N/A"], ["Dataset Link: http://gn1.genenetwork.org/webqtl/main.py?FormID=sharinginfo&InfoPageName=name1"], []] + exp_metadata.return_value = [ + ["Phenotype ID:0a2be192-57f5-400b-bbbd-0cf50135995f"], ['Group:gp1'], + ["Phenotype:p1"], [ + "Authors:N/A"], + ["Title:research1"], + ["Journal:N/A"], + ["Dataset Link: http://gn1.genenetwork.org/webqtl/main.py?FormID=sharinginfo&InfoPageName=name1"], []] expected = ('Hair_color', [['Phenotype ID:0a2be192-57f5-400b-bbbd-0cf50135995f'], ['Group:gp1'], @@ -45,6 +57,7 @@ class TestExportTraits(unittest.TestCase): ['Dataset Link: ' 'http://gn1.genenetwork.org/webqtl/main.py?FormID=sharinginfo&InfoPageName=name1'], [], + ['Name', 'Value', 'SE', 'N'], ['Sauroniops', 'germanotta'], [3, 6, 1, 4]]) -- cgit v1.2.3 From fb9ff600a3cb420303632c8c8d690999a09846d0 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Fri, 30 Oct 2020 12:38:30 +0300 Subject: add test for get_export_metadata --- .../wqflask/show_trait/test_export_trait_data.py | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/wqflask/tests/wqflask/show_trait/test_export_trait_data.py b/wqflask/tests/wqflask/show_trait/test_export_trait_data.py index 488c9d63..5d0655ce 100644 --- a/wqflask/tests/wqflask/show_trait/test_export_trait_data.py +++ b/wqflask/tests/wqflask/show_trait/test_export_trait_data.py @@ -3,10 +3,72 @@ from unittest import mock from wqflask.show_trait.export_trait_data import dict_to_sorted_list from wqflask.show_trait.export_trait_data import cmp_samples from wqflask.show_trait.export_trait_data import export_sample_table +from wqflask.show_trait.export_trait_data import get_export_metadata + + +class MockGeneral(object): + def __init__(self, obj): + for key, value in obj.items(): + setattr(self, key, value) + + +class MockChild(object): + pass class TestExportTraits(unittest.TestCase): """Test methods related to converting dict to sortedlist""" + @mock.patch("wqflask.show_trait.export_trait_data.create_trait") + @mock.patch("wqflask.show_trait.export_trait_data.data_set") + def test_get_export_metadata_no_publish(self, mock_dataset, mock_trait): + """test for exporting metadata with no publish""" + mock_data_instance = MockGeneral( + {"type": "no_publish", "dataset_name": "Temp", "name": "Temp"}) + + group_obj = MockChild() + group_obj.name = "name" + mock_data_instance.group = group_obj + mock_dataset.create_dataset.return_value = mock_data_instance + mock_trait.return_value = MockGeneral({"symbol": "", "description_display": "Description", + "title": "research1", "journal": "", "authors": ""}) + + results = get_export_metadata("random_id", "Temp") + expected = [["Record ID: random_id"], + ["Trait URL: http://genenetwork.org/show_trait?trait_id=random_id&dataset=Temp"], + ["Dataset: Temp"], + ["Group: name"], []] + + mock_dataset.create_dataset.assert_called_with("Temp") + mock_trait.assert_called_with( + dataset=mock_data_instance, name="random_id", cellid=None, get_qtl_info=False) + self.assertEqual(results, expected) + + @mock.patch("wqflask.show_trait.export_trait_data.create_trait") + @mock.patch("wqflask.show_trait.export_trait_data.data_set") + def test_get_export_metadata_with_publish(self, data_mock, trait_mock): + """test for exporting metadata with dataset.type=Publish""" + mock_instance = MockGeneral({"type": "Publish", "dataset_name": "Temp", + "name": "Temp", "description_display": "Description goes here"}) + + group_obj = MockChild() + group_obj.name = "name" + mock_instance.group = group_obj + data_mock.create_dataset.return_value = mock_instance + trait_instance = MockGeneral({"symbol": "", "description_display": "Description", + "title": "research1", "journal": "", "authors": ""}) + trait_mock.return_value = trait_instance + + results = get_export_metadata( + "29ae0615-0d77-4814-97c7-c9e91f6bfd7b", "Temp") + + expected = [['Phenotype ID: 29ae0615-0d77-4814-97c7-c9e91f6bfd7b'], + ['Phenotype URL: http://genenetwork.org/show_trait?trait_id=29ae0615-0d77-4814-97c7-c9e91f6bfd7b&dataset=Temp'], [ + 'Group: name'], ['Phenotype: Description'], + ['Authors: N/A'], ['Title: research1'], + ['Journal: N/A'], ['Dataset Link: http://gn1.genenetwork.org/webqtl/main.py?FormID=sharinginfo&InfoPageName=Temp'], []] + + self.assertEqual(results, expected) + @mock.patch("wqflask.show_trait.export_trait_data.dict_to_sorted_list") @mock.patch("wqflask.show_trait.export_trait_data.get_export_metadata") def test_export_sample_table(self, exp_metadata, dict_list): -- cgit v1.2.3 From 7ba5eb8afcb251d271d24c4f8314cafd82d546bb Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Sat, 31 Oct 2020 15:06:04 +0300 Subject: Use more descriptive variable and class names --- .../wqflask/show_trait/test_export_trait_data.py | 38 +++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/wqflask/tests/wqflask/show_trait/test_export_trait_data.py b/wqflask/tests/wqflask/show_trait/test_export_trait_data.py index 5d0655ce..085c6a30 100644 --- a/wqflask/tests/wqflask/show_trait/test_export_trait_data.py +++ b/wqflask/tests/wqflask/show_trait/test_export_trait_data.py @@ -6,13 +6,13 @@ from wqflask.show_trait.export_trait_data import export_sample_table from wqflask.show_trait.export_trait_data import get_export_metadata -class MockGeneral(object): +class AttributesSetterClass: def __init__(self, obj): for key, value in obj.items(): setattr(self, key, value) -class MockChild(object): +class HelperClass: pass @@ -22,15 +22,15 @@ class TestExportTraits(unittest.TestCase): @mock.patch("wqflask.show_trait.export_trait_data.data_set") def test_get_export_metadata_no_publish(self, mock_dataset, mock_trait): """test for exporting metadata with no publish""" - mock_data_instance = MockGeneral( + mock_dataset_attributes = AttributesSetterClass( {"type": "no_publish", "dataset_name": "Temp", "name": "Temp"}) - group_obj = MockChild() - group_obj.name = "name" - mock_data_instance.group = group_obj - mock_dataset.create_dataset.return_value = mock_data_instance - mock_trait.return_value = MockGeneral({"symbol": "", "description_display": "Description", - "title": "research1", "journal": "", "authors": ""}) + mock_nested_attributes = HelperClass() + mock_nested_attributes.name = "name" + mock_dataset_attributes.group = mock_nested_attributes + mock_dataset.create_dataset.return_value = mock_dataset_attributes + mock_trait.return_value = AttributesSetterClass({"symbol": "", "description_display": "Description", + "title": "research1", "journal": "", "authors": ""}) results = get_export_metadata("random_id", "Temp") expected = [["Record ID: random_id"], @@ -40,22 +40,22 @@ class TestExportTraits(unittest.TestCase): mock_dataset.create_dataset.assert_called_with("Temp") mock_trait.assert_called_with( - dataset=mock_data_instance, name="random_id", cellid=None, get_qtl_info=False) + dataset=mock_dataset_attributes, name="random_id", cellid=None, get_qtl_info=False) self.assertEqual(results, expected) @mock.patch("wqflask.show_trait.export_trait_data.create_trait") @mock.patch("wqflask.show_trait.export_trait_data.data_set") def test_get_export_metadata_with_publish(self, data_mock, trait_mock): """test for exporting metadata with dataset.type=Publish""" - mock_instance = MockGeneral({"type": "Publish", "dataset_name": "Temp", - "name": "Temp", "description_display": "Description goes here"}) - - group_obj = MockChild() - group_obj.name = "name" - mock_instance.group = group_obj - data_mock.create_dataset.return_value = mock_instance - trait_instance = MockGeneral({"symbol": "", "description_display": "Description", - "title": "research1", "journal": "", "authors": ""}) + mock_dataset_attributes = AttributesSetterClass({"type": "Publish", "dataset_name": "Temp", + "name": "Temp", "description_display": "Description goes here"}) + + mock_nested_attributes = HelperClass() + mock_nested_attributes.name = "name" + mock_dataset_attributes.group = mock_nested_attributes + data_mock.create_dataset.return_value = mock_dataset_attributes + trait_instance = AttributesSetterClass({"symbol": "", "description_display": "Description", + "title": "research1", "journal": "", "authors": ""}) trait_mock.return_value = trait_instance results = get_export_metadata( -- cgit v1.2.3 From 544f24cb020136532689e3649be1902413f570c8 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Sat, 31 Oct 2020 15:17:12 +0300 Subject: use descriptive variable names --- wqflask/tests/wqflask/show_trait/test_export_trait_data.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/wqflask/tests/wqflask/show_trait/test_export_trait_data.py b/wqflask/tests/wqflask/show_trait/test_export_trait_data.py index 085c6a30..bd2f7dac 100644 --- a/wqflask/tests/wqflask/show_trait/test_export_trait_data.py +++ b/wqflask/tests/wqflask/show_trait/test_export_trait_data.py @@ -6,7 +6,7 @@ from wqflask.show_trait.export_trait_data import export_sample_table from wqflask.show_trait.export_trait_data import get_export_metadata -class AttributesSetterClass: +class AttributesSetter: def __init__(self, obj): for key, value in obj.items(): setattr(self, key, value) @@ -22,14 +22,14 @@ class TestExportTraits(unittest.TestCase): @mock.patch("wqflask.show_trait.export_trait_data.data_set") def test_get_export_metadata_no_publish(self, mock_dataset, mock_trait): """test for exporting metadata with no publish""" - mock_dataset_attributes = AttributesSetterClass( + mock_dataset_attributes = AttributesSetter( {"type": "no_publish", "dataset_name": "Temp", "name": "Temp"}) mock_nested_attributes = HelperClass() mock_nested_attributes.name = "name" mock_dataset_attributes.group = mock_nested_attributes mock_dataset.create_dataset.return_value = mock_dataset_attributes - mock_trait.return_value = AttributesSetterClass({"symbol": "", "description_display": "Description", + mock_trait.return_value = AttributesSetter({"symbol": "", "description_display": "Description", "title": "research1", "journal": "", "authors": ""}) results = get_export_metadata("random_id", "Temp") @@ -47,14 +47,14 @@ class TestExportTraits(unittest.TestCase): @mock.patch("wqflask.show_trait.export_trait_data.data_set") def test_get_export_metadata_with_publish(self, data_mock, trait_mock): """test for exporting metadata with dataset.type=Publish""" - mock_dataset_attributes = AttributesSetterClass({"type": "Publish", "dataset_name": "Temp", - "name": "Temp", "description_display": "Description goes here"}) + mock_dataset_attributes = AttributesSetter({"type": "Publish", "dataset_name": "Temp", + "name": "Temp", "description_display": "Description goes here"}) mock_nested_attributes = HelperClass() mock_nested_attributes.name = "name" mock_dataset_attributes.group = mock_nested_attributes data_mock.create_dataset.return_value = mock_dataset_attributes - trait_instance = AttributesSetterClass({"symbol": "", "description_display": "Description", + trait_instance = AttributesSetter({"symbol": "", "description_display": "Description", "title": "research1", "journal": "", "authors": ""}) trait_mock.return_value = trait_instance -- cgit v1.2.3 From 0b962eef391db6aae100a3283e89ee0ac0101f6b Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Sat, 31 Oct 2020 15:23:45 +0300 Subject: remove redundant classes --- .../tests/wqflask/show_trait/test_export_trait_data.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/wqflask/tests/wqflask/show_trait/test_export_trait_data.py b/wqflask/tests/wqflask/show_trait/test_export_trait_data.py index bd2f7dac..41761944 100644 --- a/wqflask/tests/wqflask/show_trait/test_export_trait_data.py +++ b/wqflask/tests/wqflask/show_trait/test_export_trait_data.py @@ -12,10 +12,6 @@ class AttributesSetter: setattr(self, key, value) -class HelperClass: - pass - - class TestExportTraits(unittest.TestCase): """Test methods related to converting dict to sortedlist""" @mock.patch("wqflask.show_trait.export_trait_data.create_trait") @@ -25,12 +21,11 @@ class TestExportTraits(unittest.TestCase): mock_dataset_attributes = AttributesSetter( {"type": "no_publish", "dataset_name": "Temp", "name": "Temp"}) - mock_nested_attributes = HelperClass() - mock_nested_attributes.name = "name" + mock_nested_attributes = AttributesSetter({"name": "name"}) mock_dataset_attributes.group = mock_nested_attributes mock_dataset.create_dataset.return_value = mock_dataset_attributes mock_trait.return_value = AttributesSetter({"symbol": "", "description_display": "Description", - "title": "research1", "journal": "", "authors": ""}) + "title": "research1", "journal": "", "authors": ""}) results = get_export_metadata("random_id", "Temp") expected = [["Record ID: random_id"], @@ -48,14 +43,13 @@ class TestExportTraits(unittest.TestCase): def test_get_export_metadata_with_publish(self, data_mock, trait_mock): """test for exporting metadata with dataset.type=Publish""" mock_dataset_attributes = AttributesSetter({"type": "Publish", "dataset_name": "Temp", - "name": "Temp", "description_display": "Description goes here"}) + "name": "Temp", "description_display": "Description goes here"}) - mock_nested_attributes = HelperClass() - mock_nested_attributes.name = "name" + mock_nested_attributes = AttributesSetter({"name": "name"}) mock_dataset_attributes.group = mock_nested_attributes data_mock.create_dataset.return_value = mock_dataset_attributes trait_instance = AttributesSetter({"symbol": "", "description_display": "Description", - "title": "research1", "journal": "", "authors": ""}) + "title": "research1", "journal": "", "authors": ""}) trait_mock.return_value = trait_instance results = get_export_metadata( -- cgit v1.2.3 From f049877408196d2d76299a49544a010d3ee1c7e0 Mon Sep 17 00:00:00 2001 From: zsloan Date: Fri, 30 Oct 2020 14:12:48 -0500 Subject: Removed a line adding the ceiling of the Max LRS to the Y axis, since it has the potential to cause an axis tick to appear above the figure * wqflask/wqflask/marker_regression/display_mapping_results.py - Removed a line adding the ceiling of the max LRS/LOD value to the Y axis --- wqflask/wqflask/marker_regression/display_mapping_results.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/wqflask/wqflask/marker_regression/display_mapping_results.py b/wqflask/wqflask/marker_regression/display_mapping_results.py index 7e43f6bd..04d47624 100644 --- a/wqflask/wqflask/marker_regression/display_mapping_results.py +++ b/wqflask/wqflask/marker_regression/display_mapping_results.py @@ -2146,9 +2146,6 @@ class DisplayMappingResults(object): LRSScale = 1.0 LRSAxisList = Plot.frange(LRSScale, LRS_LOD_Max, LRSScale) - #make sure the user's value appears on the y-axis - #update by NL 6-21-2011: round the LOD value to 100 when LRS_LOD_Max is equal to 460 - LRSAxisList.append(ceil(LRS_LOD_Max)) #ZS: Convert to int if all axis values are whole numbers all_int = True -- cgit v1.2.3