GreenleafLab / ArchR

ArchR : Analysis of Regulatory Chromatin in R (www.ArchRProject.com)
MIT License
387 stars 138 forks source link

mapLabels function #2081

Open A-legac45 opened 10 months ago

A-legac45 commented 10 months ago

I want to subset a cluster from archr project by running clustree. on this specific cluster and put it back to the archproject.

subset cluster9

idxSample <- BiocGenerics::which(project_Peaks_MACS2_RES0.9$Clusters.res_RNA0.9 %in% "C9") cellsSample <- project_Peaks_MACS2_RES0.9$cellNames[idxSample] CLUSTER9 <- project_Peaks_MACS2_RES0.9[cellsSample, ]

CLUSTER9 <- addIterativeLSI(

ArchRProj = CLUSTER9,

#useMatrix = "GeneExpressionMatrix", 
#depthCol = "Gex_nUMI",
#varFeatures = 2500,
#firstSelection = "variable",
#binarize = FALSE,
#name = "LSI_RNA_C9", force = TRUE

)

CLUSTER9 <- addUMAP(ArchRProj = CLUSTER9, reducedDims = "LSI_RNA", name = "UMAP_RNA", force = TRUE)

CLUSTERING

for(i in seq(0,0.9,0.1)){ CLUSTER9 <- addClusters(input = CLUSTER9, reducedDims = "LSI_RNA",method = "Seurat", force = TRUE, name = paste("Clusters.res_RNA_C9",i,sep=""),resolution = i, verbose = FALSE) }

CLUSTER9 <- addUMAP(ArchRProj = CLUSTER9, reducedDims = "LSI_RNA", name = "UMAP_RNA_C9", force = TRUE)

tmp.clustree.datatable<-as.data.frame(CLUSTER9@cellColData) clustree(tmp.clustree.datatable, prefix="Clusters.res_RNA_C9")

nb of cluster found with the new clustering of this subset

I can not use properly mapLabels labelNew <- c(CLUSTER9$Clusters.res_RNA_C90.4) labelNew

remapClust <- c( "C1" = "C9a", "C2" = "C9b", "C3" = "C9c")

remapClust <- remapClust[names(remapClust) %in% labelNew]

labelNew2 <- mapLabels(labelNew, oldLabels = names(remapClust), newLabels = remapClust) labelNew2

CLUSTER9$newclust_9 <- labelNew2 CLUSTER9df <- getCellColData(CLUSTER9, select = c("newclust_9", "Clusters.res_RNA_C90.4")) CLUSTER9df$cellNames <- rownames(CLUSTER9df)

df <- getCellColData(project_Peaks_MACS2_RES0.9, select = "Clusters.res_RNA0.9") df$cellNames <- rownames(df)

all <- merge(df, CLUSTER9df, by = "cellNames", all = TRUE)

all$cluster <- ifelse(all$Clusters.res_RNA0.9 == "C9", all$newclust_9, all$Clusters.res_RNA0.9) table(all$cluster, all$Clusters.res_RNA0.9)

length(project_Peaks_MACS2_RES0.9$cellNames)

project_Peaks_MACS2_RES0.9$new_cluster_sub <-all$cluster

project_Peaks_MACS2_RES0.9$new_cluster_sub <- all$cluster

table(project_Peaks_MACS2_RES0.9$new_cluster_sub, project_Peaks_MACS2_RES0.9$Clusters.res_RNA0.9)

before subdivision

image

after subdivision

image

rcorces commented 10 months ago

Hi @A-legac45! Thanks for using ArchR! Please make sure that your post belongs in the Issues section. Only bugs and error reports belong in the Issues section. Usage questions and feature requests should be posted in the Discussions section, not in Issues.
It is worth noting that there are very few actual bugs in ArchR. If you are getting an error, it is probably something specific to your dataset, usage, or computational environment, all of which are extremely challenging to troubleshoot. As such, we require reproducible examples (preferably using the tutorial dataset) from users who want assistance. If you cannot reproduce your error, we will not be able to help. Before going through the work of making a reproducible example, search the previous Issues, Discussions, function definitions, or the ArchR manual and you will likely find the answers you are looking for. If your post does not contain a reproducible example, it is unlikely to receive a response.
In addition to a reproducible example, you must do the following things before we help you, unless your original post already contained this information: 1. If you've encountered an error, have you already searched previous Issues to make sure that this hasn't already been solved? 2. Did you post your log file? If not, add it now. 3.__ Remove any screenshots that contain text and instead copy and paste the text using markdown's codeblock syntax (three consecutive backticks). You can do this by editing your original post.