aertslab / SCopeLoomR

R package (compatible with SCope) to create generic .loom files and extend them with other data e.g.: SCENIC regulons, Seurat clusters and markers, ...
MIT License
38 stars 15 forks source link

Bug on cluster annotation from Seurat object #13

Open cbravo93 opened 4 years ago

cbravo93 commented 4 years ago

Hi @dweemx !

I had some issues to annotate Seurat clusters with the add_seurat_clustering function; even when providing an annotation clusters would be only annotated numerically, and read into SCope as NDA - Cluster X (X). By changing some parts of the code it works now, and at least for the way I am creating looms doesn't seem to give issues:

#cluster.annotation<-create_cluster_annotation(clusters = cluster.ids, cluster.meta.data.df = a, cluster.id.cn = ac.id.cn,  cluster.description.cn = ac.description.cn) 
# NOT NEEDED!
clid<-add_annotated_clustering(loom = loom
                                     , group = "Seurat"
                                     , name = paste("Seurat,", paste0(seurat.clustering.prefix, res))
                                     , clusters = cluster.ids
                                     , annotation = annotation 
                                     #Pass directly annotation, not cluster.annotation
                                     , is.default = is.default.clustering
                                     , overwrite.default = default.clustering.overwrite)
# DON'T DO THIS, KEEP ANNOTATION AS IT IS
 #if(length(unique(clusters)) == length(unique(annotation))) {
    # Make sure the order are the same
   # annotation<-annotation[names(clusters)]
  #} else {
    # Does not seem that cluster IDs and cluster annotation correspond
    # Remap to have the same number of unique IDs as the number of unique annotation
   # library(plyr)
    #clusters<-factor(x = as.integer(mapvalues(annotation, from = unique(x = annotation), to = seq_along(along.with = unique(x = annotation))-1)))
    #names(clusters)<-names(annotation)
  #}

Cheers,

C