Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions pytometry/preprocessing/_process_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ def compensate(
# the compensation matrix may have different index names than the adata.X matrix
ref_col = adata.var.index
idx_in = np.intersect1d(compens.columns, ref_col)
if idx_in is None:
if not idx_in.any():
# try the adata.var['channel'] as reference
ref_col = adata.var["channel"]
idx_in = np.intersect1d(compens.columns, ref_col)
if idx_in is None:
if not idx_in.any():
raise ValueError(
"Could not match the column names of the compensation matrix"
'with neither `adata.var.index` nor `adata.var["channel"].'
Expand All @@ -172,7 +172,17 @@ def compensate(
# sort compensation matrix by adata.var_names
compens = compens.iloc[idx_sort, idx_sort]
X_comp = np.linalg.solve(compens.T, adata.X[:, ref_idx].T).T

X = adata.X.copy()
adata.X[:, ref_idx] = X_comp

if np.array_equal(X, adata.X):
print(
"Compensation failed - matrices before and after are equivalent. Please"
" check your compensation matrix."
)
del X

# check for nan values
nan_val = np.isnan(adata.X[:, ref_idx]).sum()
if nan_val > 0:
Expand Down