jn-goe / gruffi

Granular Functional Filtering (Gruffi) to isolate stressed cells
GNU General Public License v3.0
11 stars 6 forks source link

Granule average score should be stored as numeric, not factor (AssignGranuleAverageScoresFromGOterm). #20

Closed vertesy closed 8 months ago

vertesy commented 8 months ago

Currently granule average scores are stored as not factor:

> is.factor(combined.obj$RNA_snn_res.6_cl.av_GO.0042063)
[1] TRUE
> is.numeric(combined.obj$RNA_snn_res.6_cl.av_GO.0042063)
[1] FALSE

Describe the solution you'd like Keep them as numeric, since we compute with them and code could be much simpler

vertesy commented 8 months ago

The conversion from numeric to factor happens (v1.3.0) inside AssignGranuleAverageScoresFromGOterm() after cl.av <- CalcClusterAverages_Gruffi(), bc cl.av is still numeric.

It is bc of Seurat::RenameIdents, bc it inherits from a previous factor, cluster ident and keeps as is.

This should solve it:

# Store cluster average scores in the metadata under a new column
  ColNameAverageScore <- paste0(clustering, "_cl.av_", make.names(GO_term))
  obj <- Seurat::RenameIdents(obj, cl.av)

Before

  obj@meta.data[ColNameAverageScore] <- Seurat::Idents(obj)

After

  obj@meta.data[ColNameAverageScore] <- as.numeric(as.character(Seurat::Idents(obj)))