bedapub / bedapub/besca

bc.st.clr_normalize() fails

Open
#367 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
50
Forks
17
Avg merge
1d 4h
Merged PRs (30d)
3

Description

Running standard_workflow notebooks fails when running with CITEseq data

```
ValueError Traceback (most recent call last)
Cell In[38], line 30
28 #perform normalization (this normalization is specific to CITEseq data)
29 if adt_norm == 'CLR':
---> 30 bc.st.clr_normalize(adata_prot, os.path.join(results_folder_citeseq, 'citeseq'))
32 #perform batch correction if desired otherwise just perform clustering
33 if (batch_to_correct != 'None'):
34 #save a copy of uncorrected in case we need it for something later

File .../lib/python3.9/site-packages/besca/st/_wrapper_funcs.py:290, in clr_normalize(adata, results_folder)
285 start = time()
287 # normalize per cell
288 # this also already applies log! Is not taken seperately
289 # already normalize BEFORE saving "raw" - as recommended in the scanpy tutorial
--> 290 normalize_geometric(adata)
291 print("clr normalization applied to adata")
293 # keep raw copy

File .../lib/python3.9/site-packages/besca/pp/_normalization.py:188, in normalize_geometric(adata)
185 X = np.array(X)
187 # replacement of zero values with very small numbers without changing the overall sums
--> 188 X = multiplicative_replacement(X)
190 # centre log ratio transformation
191 X = clr(X)

File .../lib/python3.9/site-packages/besca/pp/_normalization.py:132, in multiplicative_replacement(mat, delta)
87 def multiplicative_replacement(mat, delta=None):
88 r"""Replace all zeros with small non-zero values
89 It uses the multiplicative replacement strategy [1]_ ,
90 replacing zeros with a small positive :math:`\delta`
(...)
129 [0.0625, 0.4375, 0.4375, 0.0625]])
130 """
--> 132 mat = closure(mat)
133 z_mat = mat == 0
135 num_feats = mat.shape[-1]

File .../lib/python3.9/site-packages/besca/pp/_normalization.py:37, in closure(mat)
6 """
7 Performs closure to ensure that all elements add up to 1.
8
(...)
34 [0.4, 0.4, 0.2]])
35 """
36 mat = np.atleast_2d(mat)
---> 37 if np.any(mat < 0):
38 raise ValueError("Cannot have negative proportions")
39 if mat.ndim > 2:

File .../lib/python3.9/site-packages/scipy/sparse/_base.py:396, in _spbase.__bool__(self)
394 return self.nnz != 0
395 else:
--> 396 raise ValueError("The truth value of an array with more than one "
397 "element is ambiguous. Use a.any() or a.all().")

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all().
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with besca/st/_wrapper_funcs.py at clr_normalize and follow normalize_geometric, multiplicative_replacement, and closure in besca/pp/_normalization.py. Reproduce the failure by running the standard_workflow notebooks with CITEseq data, then verify that CLR normalization completes without the reported ValueError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.