From beccacde5c9c7317bfe795e5c8c4ebe033f39f89 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Wed, 12 May 2021 19:40:27 +0300 Subject: rename p_val ro tissue_p_value for tissue_results --- tests/unit/computations/test_correlation.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/unit/computations/test_correlation.py b/tests/unit/computations/test_correlation.py index 6414c3b..42ab796 100644 --- a/tests/unit/computations/test_correlation.py +++ b/tests/unit/computations/test_correlation.py @@ -236,7 +236,7 @@ class TestCorrelation(TestCase): target_tissues_values = [1, 2, 3] mock_compute_corr_coeff.side_effect = [(0.4, 0.9), (-0.2, 0.91)] expected_tissue_results = {"1456_at": {"tissue_corr": 0.4, - "p_value": 0.9, "tissue_number": 3}} + "tissue_p_val": 0.9, "tissue_number": 3}} tissue_results = tissue_correlation_for_trait_list( primary_tissue_values, target_tissues_values, corr_method="pearson", trait_id="1456_at", @@ -417,13 +417,15 @@ class TestCorrelation(TestCase): target_tissue_data = {"trait_symbol_dict": target_trait_symbol, "symbol_tissue_vals_dict": target_symbol_tissue_vals} - mock_tissue_corr.side_effect = [{"tissue_corr": -0.5, "p_value": 0.9, "tissue_number": 3}, - {"tissue_corr": 1.11, "p_value": 0.2, "tissue_number": 3}] + mock_tissue_corr.side_effect = [{"tissue_corr": -0.5, "tissue_p_val": 0.9, + "tissue_number": 3}, + {"tissue_corr": 1.11, "tissue_p_val": 0.2, + "tissue_number": 3}] expected_results = [{"1412_at": - {"tissue_corr": 1.11, "p_value": 0.2, "tissue_number": 3}}, + {"tissue_corr": 1.11, "tissue_p_val": 0.2, "tissue_number": 3}}, {"1418702_a_at": - {"tissue_corr": -0.5, "p_value": 0.9, "tissue_number": 3}}] + {"tissue_corr": -0.5, "tissue_p_val": 0.9, "tissue_number": 3}}] results = compute_all_tissue_correlation( primary_tissue_dict=primary_tissue_dict, -- cgit v1.2.3 From f88a2c3161c71d58c91c3030bd303a86846c5a73 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Wed, 12 May 2021 19:49:55 +0300 Subject: rename tissue_correlation_for_trait_list with tissue_correlation_for_trait --- gn3/computations/correlations.py | 8 ++++---- tests/unit/computations/test_correlation.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/gn3/computations/correlations.py b/gn3/computations/correlations.py index 3cea69d..21bc82e 100644 --- a/gn3/computations/correlations.py +++ b/gn3/computations/correlations.py @@ -222,7 +222,7 @@ probet return corr_results -def tissue_correlation_for_trait_list( +def tissue_correlation_for_trait( primary_tissue_vals: List, target_tissues_values: List, corr_method: str, @@ -378,7 +378,7 @@ def compute_all_lit_correlation(conn, trait_lists: List, def compute_all_tissue_correlation(primary_tissue_dict: dict, target_tissues_data: dict, corr_method: str): - """Function acts as an abstraction for tissue_correlation_for_trait_list\ + """Function acts as an abstraction for tissue_correlation_for_trait\ required input are target tissue object and primary tissue trait\ target tissues data contains the trait_symbol_dict and symbol_tissue_vals @@ -398,7 +398,7 @@ def compute_all_tissue_correlation(primary_tissue_dict: dict, target_tissue_vals = target_tissue_obj.get("tissue_values") - tissue_result = tissue_correlation_for_trait_list( + tissue_result = tissue_correlation_for_trait( primary_tissue_vals=primary_tissue_vals, target_tissues_values=target_tissue_vals, trait_id=trait_id, @@ -459,7 +459,7 @@ def compute_tissue_correlation(primary_tissue_dict: dict, with multiprocessing.Pool(4) as pool: results = pool.starmap( - tissue_correlation_for_trait_list, processed_values) + tissue_correlation_for_trait, processed_values) for result in results: tissues_results.append(result) diff --git a/tests/unit/computations/test_correlation.py b/tests/unit/computations/test_correlation.py index 42ab796..e6bc280 100644 --- a/tests/unit/computations/test_correlation.py +++ b/tests/unit/computations/test_correlation.py @@ -11,7 +11,7 @@ from gn3.computations.correlations import compute_sample_r_correlation from gn3.computations.correlations import compute_all_sample_correlation from gn3.computations.correlations import filter_shared_sample_keys from gn3.computations.correlations import tissue_lit_corr_for_probe_type -from gn3.computations.correlations import tissue_correlation_for_trait_list +from gn3.computations.correlations import tissue_correlation_for_trait from gn3.computations.correlations import lit_correlation_for_trait_list from gn3.computations.correlations import fetch_lit_correlation_data from gn3.computations.correlations import query_formatter @@ -227,7 +227,7 @@ class TestCorrelation(TestCase): self.assertEqual(results, (None, None)) @mock.patch("gn3.computations.correlations.compute_corr_coeff_p_value") - def test_tissue_correlation_for_trait_list(self, mock_compute_corr_coeff): + def test_tissue_correlation_for_trait(self, mock_compute_corr_coeff): """Test given a primary tissue values for a trait and and a list of\ target tissues for traits do the tissue correlation for them """ @@ -237,7 +237,7 @@ class TestCorrelation(TestCase): mock_compute_corr_coeff.side_effect = [(0.4, 0.9), (-0.2, 0.91)] expected_tissue_results = {"1456_at": {"tissue_corr": 0.4, "tissue_p_val": 0.9, "tissue_number": 3}} - tissue_results = tissue_correlation_for_trait_list( + tissue_results = tissue_correlation_for_trait( primary_tissue_values, target_tissues_values, corr_method="pearson", trait_id="1456_at", compute_corr_p_value=mock_compute_corr_coeff) @@ -395,7 +395,7 @@ class TestCorrelation(TestCase): self.assertEqual(lit_correlation_results, expected_mocked_lit_results) - @mock.patch("gn3.computations.correlations.tissue_correlation_for_trait_list") + @mock.patch("gn3.computations.correlations.tissue_correlation_for_trait") @mock.patch("gn3.computations.correlations.process_trait_symbol_dict") def test_compute_all_tissue_correlation(self, process_trait_symbol, mock_tissue_corr): """Test for compute all tissue corelation which abstracts -- cgit v1.2.3 From 9215c0d412bd885db3c3bbcb5635c22ac932b6f4 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Wed, 12 May 2021 19:52:21 +0300 Subject: rename lit_correlation_for_trait_list to lit_correlation_for_trait --- gn3/computations/correlations.py | 6 +++--- tests/unit/computations/test_correlation.py | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/gn3/computations/correlations.py b/gn3/computations/correlations.py index 21bc82e..2a4854b 100644 --- a/gn3/computations/correlations.py +++ b/gn3/computations/correlations.py @@ -287,7 +287,7 @@ def fetch_lit_correlation_data( return (gene_id, 0) -def lit_correlation_for_trait_list( +def lit_correlation_for_trait( conn, target_trait_lists: List, species: Optional[str] = None, @@ -361,9 +361,9 @@ def map_to_mouse_gene_id(conn, species: Optional[str], def compute_all_lit_correlation(conn, trait_lists: List, species: str, gene_id): """Function that acts as an abstraction for - lit_correlation_for_trait_list""" + lit_correlation_for_trait""" - lit_results = lit_correlation_for_trait_list( + lit_results = lit_correlation_for_trait( conn=conn, target_trait_lists=trait_lists, species=species, diff --git a/tests/unit/computations/test_correlation.py b/tests/unit/computations/test_correlation.py index e6bc280..8bf5b37 100644 --- a/tests/unit/computations/test_correlation.py +++ b/tests/unit/computations/test_correlation.py @@ -12,7 +12,7 @@ from gn3.computations.correlations import compute_all_sample_correlation from gn3.computations.correlations import filter_shared_sample_keys from gn3.computations.correlations import tissue_lit_corr_for_probe_type from gn3.computations.correlations import tissue_correlation_for_trait -from gn3.computations.correlations import lit_correlation_for_trait_list +from gn3.computations.correlations import lit_correlation_for_trait from gn3.computations.correlations import fetch_lit_correlation_data from gn3.computations.correlations import query_formatter from gn3.computations.correlations import map_to_mouse_gene_id @@ -246,7 +246,7 @@ class TestCorrelation(TestCase): @mock.patch("gn3.computations.correlations.fetch_lit_correlation_data") @mock.patch("gn3.computations.correlations.map_to_mouse_gene_id") - def test_lit_correlation_for_trait_list(self, mock_mouse_gene_id, fetch_lit_data): + def test_lit_correlation_for_trait(self, mock_mouse_gene_id, fetch_lit_data): """Fetch results from db call for lit correlation given a trait list\ after doing correlation """ @@ -260,7 +260,7 @@ class TestCorrelation(TestCase): fetch_lit_data.side_effect = [(15, 9), (17, 8), (11, 12)] - lit_results = lit_correlation_for_trait_list( + lit_results = lit_correlation_for_trait( conn=conn, target_trait_lists=target_trait_lists, species="rat", trait_gene_id="12") @@ -375,10 +375,10 @@ class TestCorrelation(TestCase): self.assertEqual(results, expected_results) - @mock.patch("gn3.computations.correlations.lit_correlation_for_trait_list") + @mock.patch("gn3.computations.correlations.lit_correlation_for_trait") def test_compute_all_lit_correlation(self, mock_lit_corr): """Test for compute all lit correlation which acts\ - as an abstraction for lit_correlation_for_trait_list + as an abstraction for lit_correlation_for_trait and is used in the api/correlation/lit """ -- cgit v1.2.3 From 0f2b3be58b8265858d17581b85cab5ac4f13e097 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Wed, 12 May 2021 19:57:01 +0300 Subject: delete unused functions --- gn3/computations/correlations.py | 23 ----------------------- tests/unit/computations/test_correlation.py | 13 ------------- 2 files changed, 36 deletions(-) (limited to 'tests') diff --git a/gn3/computations/correlations.py b/gn3/computations/correlations.py index 2a4854b..d496cec 100644 --- a/gn3/computations/correlations.py +++ b/gn3/computations/correlations.py @@ -199,29 +199,6 @@ def benchmark_compute_all_sample(this_trait, return corr_results -def tissue_lit_corr_for_probe_type(corr_type: str, top_corr_results): - """Function that does either lit_corr_for_trait_list or tissue_corr _for_trait -list depending on whether both dataset and target_dataset are both set to -probet - - """ - - corr_results = {"lit": 1} - - if corr_type not in ("lit", "literature"): - - corr_results["top_corr_results"] = top_corr_results - # run lit_correlation for the given top_corr_results - if corr_type == "tissue": - # run lit correlation the given top corr results - pass - if corr_type == "sample": - pass - # run sample r correlation for the given top results - - return corr_results - - def tissue_correlation_for_trait( primary_tissue_vals: List, target_tissues_values: List, diff --git a/tests/unit/computations/test_correlation.py b/tests/unit/computations/test_correlation.py index 8bf5b37..52c1f85 100644 --- a/tests/unit/computations/test_correlation.py +++ b/tests/unit/computations/test_correlation.py @@ -10,7 +10,6 @@ from gn3.computations.correlations import do_bicor from gn3.computations.correlations import compute_sample_r_correlation from gn3.computations.correlations import compute_all_sample_correlation from gn3.computations.correlations import filter_shared_sample_keys -from gn3.computations.correlations import tissue_lit_corr_for_probe_type from gn3.computations.correlations import tissue_correlation_for_trait from gn3.computations.correlations import lit_correlation_for_trait from gn3.computations.correlations import fetch_lit_correlation_data @@ -214,18 +213,6 @@ class TestCorrelation(TestCase): filter_shared_samples.assert_called_once_with( this_trait_data.get("trait_sample_data"), traits_dataset[0].get("trait_sample_data")) - @unittest.skip("not implemented") - def test_tissue_lit_corr_for_probe_type(self): - """Tests for doing tissue and lit correlation for trait list\ - if both the dataset and target dataset are probeset runs\ - on after initial correlation has been done - """ - - results = tissue_lit_corr_for_probe_type( - corr_type="tissue", top_corr_results={}) - - self.assertEqual(results, (None, None)) - @mock.patch("gn3.computations.correlations.compute_corr_coeff_p_value") def test_tissue_correlation_for_trait(self, mock_compute_corr_coeff): """Test given a primary tissue values for a trait and and a list of\ -- cgit v1.2.3 From bcba700bd2835f0a36042d781860b3407519f6d8 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Sat, 15 May 2021 01:05:48 +0300 Subject: index lit tuple result --- gn3/computations/correlations.py | 2 +- tests/unit/computations/test_correlation.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/gn3/computations/correlations.py b/gn3/computations/correlations.py index d496cec..4fdf8cf 100644 --- a/gn3/computations/correlations.py +++ b/gn3/computations/correlations.py @@ -257,7 +257,7 @@ def fetch_lit_correlation_data( cursor.execute(query_formatter(query, *tuple(reversed(query_values)))) lit_corr_results = cursor.fetchone() - lit_results = (gene_id, lit_corr_results.val)\ + lit_results = (gene_id, lit_corr_results[1])\ if lit_corr_results else (gene_id, 0) return lit_results diff --git a/tests/unit/computations/test_correlation.py b/tests/unit/computations/test_correlation.py index 52c1f85..d264738 100644 --- a/tests/unit/computations/test_correlation.py +++ b/tests/unit/computations/test_correlation.py @@ -276,7 +276,7 @@ class TestCorrelation(TestCase): input trait mouse gene id and mouse gene id """ - expected_db_results = [namedtuple("lit_coeff", "val")(x*0.1) + expected_db_results = [("val", x*0.1) for x in range(1, 4)] conn = DataBase(expected_results=expected_db_results) expected_results = ("1", 0.1) -- cgit v1.2.3