From e9289a13e392f9b6283af9f716e3caee97d3d78a Mon Sep 17 00:00:00 2001 From: marouenbg Date: Tue, 24 Mar 2026 19:04:52 -0400 Subject: [PATCH 1/2] Remove pkg_resources dependency from sambar.py Replace pkg_resources.resource_filename() with os.path.join() relative to __file__ for locating package data files. This removes the dependency on setuptools/pkg_resources which is deprecated and scheduled for removal. Fixes #363 --- netZooPy/sambar/sambar.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/netZooPy/sambar/sambar.py b/netZooPy/sambar/sambar.py index 69f6d8b4..401b4e08 100644 --- a/netZooPy/sambar/sambar.py +++ b/netZooPy/sambar/sambar.py @@ -5,7 +5,6 @@ import networkx as nx from scipy.spatial.distance import pdist,cosine,squareform from scipy.cluster.hierarchy import linkage,cut_tree -import pkg_resources """ Description: Python implementation of the Subtyping Agglomerated Mutations By Annotation Relations (SAMBAR) method as implemented in R https://github.com/mararie/SAMBAR. @@ -40,10 +39,11 @@ This package includes the functions ```sambar```,```desparsify```,```corgenelength```,```convertgmt```,```clustering``` as well as an implementation of the binomial distance (Millar dissimilarity from the package vegdist from R. To see the full description of each of this functions use ```help(pysambar.function)```. """ ## Default toydata files -esize = pkg_resources.resource_filename(__name__, 'esizef.csv') -genes = pkg_resources.resource_filename(__name__, 'genes.txt') -sign = pkg_resources.resource_filename(__name__, 'h.all.v6.1.symbols.gmt') -mut = pkg_resources.resource_filename(__name__, 'mut.ucec.csv') +_DATA_DIR = os.path.dirname(__file__) +esize = os.path.join(_DATA_DIR, 'esizef.csv') +genes = os.path.join(_DATA_DIR, 'genes.txt') +sign = os.path.join(_DATA_DIR, 'h.all.v6.1.symbols.gmt') +mut = os.path.join(_DATA_DIR, 'mut.ucec.csv') def corgenelength(mut,cangenes,esize,normbysample=True,subcangenes=True): """ From 1c35c6745b7e4a80487d28381b59c10716038c3e Mon Sep 17 00:00:00 2001 From: marouenbg Date: Tue, 24 Mar 2026 19:32:25 -0400 Subject: [PATCH 2/2] Fix pandas 4.x compatibility in cobra test and condor - test_cobra: use numpy array for mean computation instead of pandas Series integer access (KeyError: 0 with string column index) - condor: use .iloc for positional access on iterrows() Series (KeyError: 2 with string column labels) - condor: use ki.sum() instead of float(sum(ki)) to avoid TypeError with np.matrix column vectors in newer numpy --- netZooPy/condor/condor.py | 5 +++-- tests/test_cobra.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/netZooPy/condor/condor.py b/netZooPy/condor/condor.py index 0e755bd9..bc5e95c5 100644 --- a/netZooPy/condor/condor.py +++ b/netZooPy/condor/condor.py @@ -305,13 +305,14 @@ def matrices(self, c,resolution): # Computes weighted biadjacency matrix. A = np.matrix(np.zeros((p, q))) for edge in self.net.iterrows(): - A[gn[edge[1][1]], rg[edge[1][0]]] = edge[1][2] + row = edge[1] + A[gn[row.iloc[1]], rg[row.iloc[0]]] = row.iloc[2] # Computes node degrees for the nodesets. ki = A.sum(1) dj = A.sum(0) # Computes sum of edges and bimodularity matrix. - m = float(sum(ki)) + m = float(ki.sum()) B = A - resolution*((ki @ dj) / m) # d = self.index_dict diff --git a/tests/test_cobra.py b/tests/test_cobra.py index 2fe940fc..00e59e55 100644 --- a/tests/test_cobra.py +++ b/tests/test_cobra.py @@ -37,7 +37,8 @@ def test_cobra(): pd.testing.assert_frame_equal(G, G_gt, rtol=1e-10, check_exact=False) q = psi.shape[0] + X_mean = np.mean(X.to_numpy(), axis=0) for i in range(q): - C = Q.to_numpy().dot(np.mean(X, axis=0)[i] * np.diag(psi.to_numpy()[i, :])).dot(Q.to_numpy().T) - C_gt = Q_gt.to_numpy().dot(np.mean(X, axis=0)[i] * np.diag(psi_gt.to_numpy()[i, :])).dot(Q_gt.to_numpy().T) + C = Q.to_numpy().dot(X_mean[i] * np.diag(psi.to_numpy()[i, :])).dot(Q.to_numpy().T) + C_gt = Q_gt.to_numpy().dot(X_mean[i] * np.diag(psi_gt.to_numpy()[i, :])).dot(Q_gt.to_numpy().T) pd.testing.assert_frame_equal(pd.DataFrame(C), pd.DataFrame(C_gt), rtol=1e-10, check_exact=False)