Skip to content

add_seurat_clustering is not working #31

@saeedfc

Description

@saeedfc
exp_mtx1 <- GetAssayData(SO, assay = "RNA", slot = "data")
exp_mtx1 <- as.matrix(exp_mtx1)

umap_mtx <- as.data.frame(Embeddings(SO, reduction = "umap"))

file.name <- "expanded.loom"
build_loom(
  file.name=file.name,
  dgem=exp_mtx1,
  title="Data 2020", # A name for your data
  genome="Human", # Just for user information, not used internally
  default.embedding=umap_mtx,
  default.embedding.name="Seurat_UMAP"
)


loom <- open_loom("expanded.loom", mode = 'r+')

#Load the DEG markers file as a data frame
wilcoxon_test_markers_csv <- read.csv("/mnt/DATA1/Markers_Fib_Jan27.csv", row.names = 1)
#Save it as an RDS file
saveRDS(wilcoxon_test_markers_csv, "/mnt/DATA1/Fibrosis/Full Scale Analysis/FibroBlasts/Markers_Fib_Jan27.rds")
#Make a named list of path to the markers file
#Name should be the resolution mentioned on the column name of corresponding seurat clustering for which you calculated the markers Eg: here 'res.0.25'
wilcoxon_test_markers <- list(res.0.25 = "/mnt/DATA1/Markers_Fib_Jan27.rds")


#Also for the corresponding resolution , if you have already annotated names for each cluster number, you can add it as a #data.frame
seurat.annotation <- data.frame(integrated_snn_res.0.25 = unique(as.numeric(as.character(SO$integrated_snn_res.0.25))), annotation = unique(as.character(SO$subtype)))
head(seurat.annotation)
#  integrated_snn_res.0.25        annotation
#1                      1                 F3A
#2                      2               Act_F
#3                      0               Res_I
#4                      4              Res_II
#5                      3                 SC3
#6                      6               mixed
#7                      5                 TFR


#Add the clustering here
add_seurat_clustering(loom = loom
                      , seurat = SO
                      , seurat.markers.file.path.list = wilcoxon_test_markers
                      ,seurat.clustering.prefix = 'integrated_snn_res.'
                      ,annotation = seurat.annotation #the DF of annotation; if not annotated, use NULL
                      ,annotation.cluster.id.cn = 'integrated_snn_res.0.25' #Column name for seurat cluster numbers of the annotation dataframe
                      ,annotation.cluster.description.cn = 'annotation' #Column name for the cell types of the annotation dataframe
                      , seurat.marker.metric.accessors = c("avg_logFC", "p_val_adj")
                      , seurat.marker.metric.names = c("Avg. logFC", "Adj. p-value")
                      , seurat.marker.metric.description = c("Average log fold change from Wilcox differential test", "Adjusted p-value using Bonferroni correction based on the total number of genes in the dataset"))

I get this error. Can you kindly let me know, what could be going wrong here?

Error in if (nchar(x = d) > 0) { : argument is of length zero
> traceback()
5: FUN(X[[i]], ...)
4: lapply(X = seq_along(along.with = unique.clusters), FUN = function(cluster.idx) {
       cluster.id <- unique.clusters[[cluster.idx]]
       if (is.numeric(x = cluster.id)) {
           description <- paste("NDA - Cluster", cluster.id)
       }
       else if (is.character(x = cluster.id)) {
           cluster.id <- cluster.idx - 1
           description <- cluster.id
       }
       else {
           stop("Cluster labels are required to be of class character or numeric.")
       }
       if (!is.null(x = annotation)) {
           annotation <- annotation[names(x = clusters)]
           d <- as.character(x = unique(x = annotation[clusters == 
               cluster.id]))
           if (length(x = d) > 1) {
               stop("Annotation is not unique: multiple annotation correspond to a cluster ID.")
           }
           if (nchar(x = d) > 0) {
               description <- paste0(d, " (", cluster.id, ")")
           }
       }
       return(list(id = cluster.id, description = description))
   })
3: add_global_md_clustering(loom = loom, id = id, group = group, 
       name = name, clusters = clusters_as_factor_ids, annotation = annotation)
2: add_annotated_clustering(loom = loom, group = "Seurat", name = paste("Seurat,", 
       paste0(seurat.clustering.prefix, res)), clusters = cluster_ids, 
       annotation = cluster_annotation, is.default = is_default_clustering, 
       overwrite.default = default.clustering.overwrite)
1: add_seurat_clustering(loom = loom, seurat = SO, seurat.markers.file.path.list = wilcoxon_test_markers, 
       seurat.clustering.prefix = "integrated_snn_res.", annotation = seurat.annotation, 
       annotation.cluster.id.cn = "integrated_snn_res.0.25", annotation.cluster.description.cn = "annotation", 
       seurat.marker.metric.accessors = c("avg_logFC", "p_val_adj"), 
       seurat.marker.metric.names = c("Avg. logFC", "Adj. p-value"), 
       seurat.marker.metric.description = c("Average log fold change from Wilcox differential test", 
           "Adjusted p-value using Bonferroni correction based on the total number of genes in the dataset"))

Thanks,
Saeed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions