From 21fbbfd599c841f082d88ddfc5f4cb362e1eb869 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 18 Nov 2021 10:58:34 +0300 Subject: Replace code migrated from R with pingouin functions Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi * Replace the code that was in the process of being migrated from R in GeneNetwork1 with calls to pingouin functions that achieve the same thing. Since the functions in this case are computing correlations and partial correlations, rather than having home-rolled functions to do that, this commit makes use of the tried and tested pingouin functions. This avoids complicating our code with edge-case checks, and leverages the performance optimisations done in pingouin. --- .../unit/computations/test_partial_correlations.py | 41 +--------------------- 1 file changed, 1 insertion(+), 40 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/computations/test_partial_correlations.py b/tests/unit/computations/test_partial_correlations.py index 39e6e8e..138155d 100644 --- a/tests/unit/computations/test_partial_correlations.py +++ b/tests/unit/computations/test_partial_correlations.py @@ -16,9 +16,7 @@ from gn3.computations.partial_correlations import ( dictify_by_samples, tissue_correlation, find_identical_traits, - partial_correlation_matrix, - good_dataset_samples_indexes, - partial_correlation_recursive) + good_dataset_samples_indexes) sampleslist = ["B6cC3-1", "BXD1", "BXD12", "BXD16", "BXD19", "BXD2"] control_traits = ( @@ -397,40 +395,3 @@ class TestPartialCorrelations(TestCase): with self.subTest(xdata=xdata, ydata=ydata, zdata=zdata): self.assertTrue( build_data_frame(xdata, ydata, zdata).equals(expected)) - - def test_partial_correlation_matrix(self): - """ - Test that `partial_correlation_matrix` computes the appropriate - correlation value. - """ - for sample in parse_test_data_csv( - ("tests/unit/computations/partial_correlations_test_data/" - "pcor_mat_blackbox_test.csv")): - with self.subTest( - xdata=sample["x"], ydata=sample["y"], zdata=sample["z"], - method=sample["method"], omit_nones=sample["rm"]): - self.assertEqual( - partial_correlation_matrix( - sample["x"], sample["y"], sample["z"], - method=sample["method"], omit_nones=sample["rm"]), - sample["result"]) - - def test_partial_correlation_recursive(self): - """ - Test that `partial_correlation_recursive` computes the appropriate - correlation value. - """ - for sample in parse_test_data( - ("tests/unit/computations/partial_correlations_test_data/" - "pcor_rec_blackbox_test.txt"), - parse_for_rec): - with self.subTest( - xdata=sample["x"], ydata=sample["y"], zdata=sample["z"], - method=sample["method"], omit_nones=sample["rm"]): - self.assertEqual( - round( - partial_correlation_recursive( - sample["x"], sample["y"], sample["z"], - method=sample["method"], omit_nones=sample["rm"]), - ROUND_TO), - round(sample["result"], ROUND_TO)) -- cgit v1.2.3