cnio-bu / beyondcell

Beyondcell is a computational methodology for identifying tumour cell subpopulations with distinct drug responses in single-cell RNA-seq and Spatial Transcriptomics data.
Other
42 stars 4 forks source link

NA values in mean of ranked table #147

Open mpaya opened 9 months ago

mpaya commented 9 months ago

When computing the step of bcRanks() to obtain the ranked table, all mean values were NA. In script Ranks.R, line 148, the mean() function uses na.omit = TRUE instead of na.rm = TRUE as in following statistical functions. With this modification, the issue is solved.

katimbach commented 4 months ago

It seems like something similar is happening with NaN values breaking bc4Squares:

> bc4Squares(bc, idents = "bc_clusters_res.0.2", lvl = "4")
Error in quantile.default(as.numeric(res$residuals.mean), prob = seq(from = 0,  : 
  missing values and NaN's not allowed if 'na.rm' is FALSE

In line 950 of Visualization.R, na.rm =TRUE, so not sure how to fix this one. Manually plugging this line seems to work fine:

> ranks<- as.data.frame(bc@ranks)
> quantile(as.numeric(ranks$bc_clusters_res.0.2.residuals.mean.0), na.rm = TRUE,
                            prob = seq(from = 0, to = 1, length = 11))
    0%    10%    20%    30%    40%    50%    60%    70%    80%    90%   100% 
-5.000 -1.151 -0.660 -0.383 -0.210 -0.095  0.050  0.233  0.452  0.904  9.850 
> quantile(as.numeric(ranks$bc_clusters_res.0.2.residuals.mean.1), na.rm = TRUE,
                            prob = seq(from = 0, to = 1, length = 11))
    0%    10%    20%    30%    40%    50%    60%    70%    80%    90%   100% 
-4.390 -1.886 -1.176 -0.750 -0.432 -0.070  0.310  0.620  1.102  1.720  4.590 
> quantile(as.numeric(ranks$bc_clusters_res.0.2.residuals.mean.2), na.rm = TRUE,
                            prob = seq(from = 0, to = 1, length = 11))
    0%    10%    20%    30%    40%    50%    60%    70%    80%    90%   100% 
-6.390 -2.576 -1.940 -1.352 -0.874 -0.390  0.080  0.640  1.740  2.302  6.460 
> quantile(as.numeric(ranks$bc_clusters_res.0.2.residuals.mean.3), na.rm = TRUE,
                            prob = seq(from = 0, to = 1, length = 11))
    0%    10%    20%    30%    40%    50%    60%    70%    80%    90%   100% 
-2.230 -0.901 -0.632 -0.410 -0.230 -0.050  0.090  0.263  0.492  0.790  2.500 
> quantile(as.numeric(ranks$bc_clusters_res.0.2.residuals.mean.4), na.rm = TRUE,
                            prob = seq(from = 0, to = 1, length = 11))
     0%     10%     20%     30%     40%     50%     60%     70%     80%     90% 
-24.890  -3.524  -2.100  -0.956   0.044   0.890   1.600   2.420   3.394   5.110 
   100% 
 13.380