aertslab/SCopeLoomR

Bug on cluster annotation from Seurat object

Opened this issue · 0 comments

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:

  • add_seurat_clustering (lines 697-704)
#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)
  • add_annotated_clustering (lines 842-852)
# 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)
  #}
  • add_global_md_clustering (lines 229-236)
if(!is.null(annotation)) {
      # Force to have the same order
      #annotation<-annotation[names(clusters)]
      # If annotation for the current cluster not empty then add
      d<-as.vector(unlist(annotation[annotation[,1] == cluster.id, 2]))
      # ASSUMING CLUSTER NUMBER IN FIRST COLUMN AND ANNOT IN SECOND
      # Convert from factor to character vector to be used with nchar
      #d<-as.character(unique(annotation[clusters == cluster.id])) 

Cheers,

C