caravagnalab / rcongas

rcongas
GNU General Public License v3.0
7 stars 1 forks source link

Bug remove_small_clusters #8

Closed caravagn closed 1 year ago

caravagn commented 3 years ago

In https://github.com/Militeee/rcongas/blob/master/R/filter_clusters.R (function remove_small_clusters) get_best_model cannot be called as

bm <- Rcongas::get_best_model(x)

since it is not exported in https://github.com/Militeee/rcongas/blob/master/NAMESPACE.

Maybe this should be exported no?

caravagn commented 3 years ago

Fixed myself.

caravagn commented 3 years ago

I fixed that but still it does not work.

It works with the default template fit released with the package

y = Rcongas::congas_example
y %>% Rcongas:::filter_clusters(ncells = 10, abundance = .5)

since

! Filtering 1 cluster due to low cell counts or abudance
ℹ No posterior probabilities, using euclidean distance to merge clusters
── [ Rcongas ] My CONGAS model n = 504 cells with k = 70 segments, grouped in k = 1 clusters. ───────────────
● Cluster 1, n = 504 [100% of total cells].
ℹ Model scored with BIC = 272839
● Differential Expression analysis for 1 vs 2 with the DESeq2 method: 212 DE genes at level alpha 0.01, with
|lfc| > 0.25.

But it does not work with a fit object @riccardobergamin which used

x <- Rcongas:::best_cluster(
  x, 
  model = "MixtureGaussian", 
  clusters = 2:3, 
  steps = 500, 
  lr = 0.05, 
  param_list = list(theta_shape=5,theta_rate=1), 
  method = "BIC",  
  MAP = TRUE, 
  posteriors = FALSE, 
  step_post = 100)

> x
── [ Rcongas ] My CONGAS model n = 460 cells with k = 52 segments, grouped in k = 2 clusters. ───────────────
● Cluster c1, n = 348 [75.65% of total cells].
● Cluster c2, n = 112 [24.35% of total cells].
ℹ Model scored with BIC = 28574492.27

> x %>% Rcongas:::filter_clusters(ncells = 10, abundance = .5)
! Filtering 1 cluster due to low cell counts or abudance
ℹ No posterior probabilities, using euclidean distance to merge clusters
! Filtering 1 cluster due to low cell counts or abudance
ℹ No posterior probabilities, using euclidean distance to merge clusters
── [ Rcongas ] My CONGAS model n = 460 cells with k = 52 segments, grouped in k = 2 clusters. ───────────────
● Cluster c1, n = 348 [75.65% of total cells].
● Cluster c2, n = 112 [24.35% of total cells].
ℹ Model scored with BIC = 28574492.27
caravagn commented 3 years ago

Besides, we should recompute the BIC score for the model etc after we remove some clusters.

caravagn commented 3 years ago

Note that the default fit crashes with

y %>% Rcongas:::filter_clusters(ncells = 150, remove = TRUE)

with

Error in cm$parameters$assignment_probs[i, ] : 
  incorrect number of dimensions
caravagn commented 1 year ago

Is this a thing? @Militeee