`use_raw=False` not working in bc.tl.sig.combined_signature_score( )
- Dominant language
- Python
- Stars
- 50
- Forks
- 17
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 3
Description
Hi,
When trying to calculate signature score without using the raw layer `use_raw=False` the function is still checking in raw and raising an error (in this case because I am using and adata without raw). Please correct the function so that the user can either use raw or not (as for scanpy `sc.tl.score_genes`, which works fine.
See code and error:
```
path = 'https://ross.science.roche.com/pred-bioinfo-bi-reference/scseq/h5ad/GSE144735_colorectalcLee20_Belgian/sw_besca25.h5ad'
file = 'sw_besca25.h5ad'
adata = sc.read(file, backup_url=path) # To read from ROSS
adata
```
AnnData object with n_obs × n_vars = 26280 × 16579
obs: 'CELL', 'individual_id', 'specimen_type', 'sample_id', 'Cell_type', 'Cell_subtype', 'percent_mito', 'n_counts', 'n_genes', 'leiden', 'dblabel', 'celltype1'
var: 'ENSEMBL', 'SYMBOL'
uns: 'log1p'
obsm: 'X_pca', 'X_umap'
```
#Calculate cDC signature scores (besca sigs)
sigs = {}
sigs['cDC1'] = {'UP': ['CLEC9A', 'XCR1', 'CLNK', 'ENPP1', 'PPM1J', 'ZNF366']}
bc.tl.sig.combined_signature_score(adata, GMT_file = None, signature_dict = sigs, overwrite = True, use_raw=False)
```
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In [39], line 4
2 sigs = {}
3 sigs['cDC1'] = {'UP': ['CLEC9A', 'XCR1', 'CLNK', 'ENPP1', 'PPM1J', 'ZNF366']}
----> 4 bc.tl.sig.combined_signature_score(adata, GMT_file = None, signature_dict = sigs, overwrite = True, use_raw=False)
File ~/scratch/conda/envs/besca25_LAS/lib/python3.8/site-packages/besca/tl/sig/_sig.py:267, in combined_signature_score(adata, GMT_file, signature_dict, UP_suffix, DN_suffix, method, overwrite, verbose, use_raw, conversion)
265 signature_dict = convert_siggenes(signature_dict, conversion)
266 # compute signed score
--> 267 compute_signed_score(
268 adata=adata,
269 signature_dict=signature_dict,
270 method=method,
271 overwrite=overwrite,
272 verbose=verbose,
273 use_raw=use_raw,
274 )
275 return None
File ~/scratch/conda/envs/besca25_LAS/lib/python3.8/site-packages/besca/tl/sig/_sig.py:308, in compute_signed_score(adata, signature_dict, method, overwrite, verbose, use_raw)
281 """Compute signed score combining UP and DN for all signatures in signature_dict
282 This function combines genesets (signatures) scores.
283 Results are stored in adata.obs with the key: "score_" + method + signature_name.
(...)
305
306 """
307 # Filter out signature genes not present in adata
--> 308 signature_dict_filtered=**filter_siggenes(adata, signature_dict)**
310 [
311 _handle_signature(
312 signature_dict_filtered, method, adata, signature_name, overwrite, verbose, use_raw
313 )
314 for signature_name in signature_dict.keys()
315 ]
316 return None
File ~/scratch/conda/envs/besca25_LAS/lib/python3.8/site-packages/besca/tl/sig/_sig.py:99, in filter_siggenes(adata, signature_dict)
55 """Filter all signatures in signature_dict to remove genes not present in adata
56
57 Parameters
(...)
95 {'GeneSet1': {'UP': ['Gene_0', 'Gene_2', 'Gene_3'], 'DN': ['Gene_5', 'Gene_6', 'Gene_8']}, 'GeneSet2': {'UP': ['Gene_10', 'Gene_11', 'Gene_13'], 'DN': ['Gene_14', 'Gene_16', 'Gene_18']}}
96 """
98 signature_dict_filtered = {}
---> 99 raw_index_set = set(**adata.raw.var**.index)
100 for geneset, dir_dict in signature_dict.items():
101 if type(dir_dict) is dict:
AttributeError: 'NoneType' object has no attribute 'var'
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in besca/tl/sig/_sig.py, especially combined_signature_score, compute_signed_score, and filter_siggenes, which are named in the traceback. Reproduce the call with an AnnData object without raw, then verify that both use_raw=False and use_raw=True complete correctly with appropriate gene filtering and regression tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100