carmonalab / ProjecTILs

Interpretation of cell states using reference single-cell maps
GNU General Public License v3.0
252 stars 29 forks source link

Uninformative error if one sample contains no cells to project onto reference map #46

Closed halterc closed 1 year ago

halterc commented 1 year ago

If there are e.g. zero (or too little?) CD8TILs to project onto the CD8TIL reference map the error it throws is not very obvious:

`object.CD8T.projected <- Run.ProjecTILs(query = object.CD8T, ref = ref, filter.cell = TRUE, skip.normalize = T, split.by = "Sample", ncores = 4)

[1] "Using assay RNA for SampleXYZ" Pre-filtering cells with scGate... Error: BiocParallel errors 1 remote errors, element index: 25 45 unevaluated and other errors first remote error: Error in run_scGate_singlemodel(data, model = model[[m]], k.param = k.param, : object 'pure.cells' not found`

-> Skip sample and through informative warning if it has zero (or too little) cells to project onto map

jmodlis commented 1 year ago

I have encountered a similar issue (but with different error code, see below). I believe it is due to the fact that this particular sample has only 1 cell left after filtering.

Pre-filtering cells with scGate...

### Detected a total of 1 pure 'Target' cells (2.13% of total)
[1] "46 out of 47 ( 98% ) non-pure cells removed. Use filter.cells=FALSE to avoid pre-filtering"
Performing log-normalization
0%   10   20   30   40   50   60   70   80   90   100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
  |======================                                           |  33%
Error: BiocParallel errors
  1 remote errors, element index: 4
  8 unevaluated and other errors
  first remote error:
Error: All cells in the object being added must match the cells in this object

My initial thought is that handling these samples by assigning the cells to a NULL functional.cluster without running the projection or classification seems like the best way to handle this, although I'm currently just splitting by group, as there are large group effects in this dataset with some samples with few cells (and this solution is quick for exploratory purposes).

ProjecTILs version

> packageVersion("ProjecTILs")
[1] ‘3.1.0’
mass-a commented 1 year ago

I agree, this is not desirable behavior. We will try to address it in the next update, will post here when it's solved.

Best -m

mass-a commented 1 year ago

Hello! we pushed an update to the latest version (v3.1.1), to better handle cases with zero or 1 cells. I have tested several scenarios, and it appears to play nice in all cases. But if you still experience similar problems please report here again.

Best -m

jmodlis commented 1 year ago

Thank you, that was quick! I will test it out with my data as well.

Thanks, Jen

halterc commented 1 year ago

Fixed with commit https://github.com/carmonalab/ProjecTILs/commit/c59eba42ec61e35c68b85afd96d1f9adfc83d00d