Closed Yale73 closed 4 years ago
What is your cluster.plot
command.
cluster.plot(my.obj, plot.type = "tsne", col.by = "clusters", interactive = FALSE)
Is it the converted object from previous post? If you converted your Seurat object to iCellR here is an example of how to do it. The example includes how the Seurat object was made too. Let me know if it helps.
library(Seurat)
library(SeuratData)
InstallData("panc8")
options(future.globals.maxSize = 4000 * 1024^2)
data("panc8")
pancreas.list <- SplitObject(panc8, split.by = "tech")
pancreas.list <- pancreas.list[c("celseq", "celseq2", "fluidigmc1", "smartseq2")]
for (i in 1:length(pancreas.list)) {
pancreas.list[[i]] <- SCTransform(pancreas.list[[i]], verbose = FALSE)
}
pancreas.features <- SelectIntegrationFeatures(object.list = pancreas.list, nfeatures = 3000)
pancreas.list <- PrepSCTIntegration(object.list = pancreas.list, anchor.features = pancreas.features,
verbose = FALSE)
pancreas.anchors <- FindIntegrationAnchors(object.list = pancreas.list, normalization.method = "SCT",
anchor.features = pancreas.features, verbose = FALSE)
pancreas.integrated <- IntegrateData(anchorset = pancreas.anchors, normalization.method = "SCT",
verbose = FALSE)
pancreas.integrated <- RunPCA(pancreas.integrated, verbose = FALSE)
pancreas.integrated <- RunUMAP(pancreas.integrated, dims = 1:30)
plots <- DimPlot(pancreas.integrated, group.by = c("tech", "celltype"), combine = FALSE)
plots <- lapply(X = plots, FUN = function(x) x + theme(legend.position = "top")
+ guides(color = guide_legend(nrow = 3, byrow = TRUE, override.aes = list(size = 3))))
png('pancreas_Plots.png', width = 12, height = 8, units = 'in', res = 300)
CombinePlots(plots)
dev.off()
save(pancreas.integrated, file = "pancreas.integrated.Robj")
############### plots
plots <- DimPlot(pancreas.integrated, group.by = c("tech", "celltype"), combine = FALSE)
plots <- lapply(X = plots, FUN = function(x) x + theme(legend.position = "top")
+ guides(color = guide_legend(nrow = 3, byrow = TRUE, override.aes = list(size = 3))))
CombinePlots(plots)
############################ how to convert to iCellR
library(Seurat)
load("pancreas.integrated.Robj")
objectName=pancreas.integrated
my.data <- as.data.frame(as.matrix(objectName@assays$RNA@data))
myUMAP <- as.data.frame(objectName@reductions$umap@cell.embeddings)
myPCA <- as.data.frame(objectName@reductions$pca@cell.embeddings)
dim(my.data)
dim(myUMAP)
head(my.data)[1:5]
head(myUMAP)
MyCols <- row.names(myUMAP)
MyCols <- gsub("-",".",MyCols)
MyCols <- gsub("_",".",MyCols)
MyCols <- paste0(objectName@meta.data$tech,"_",MyCols,sep="")
colnames(my.data) <- MyCols
rownames(myPCA) <- MyCols
rownames(myUMAP) <- MyCols
my.obj <- make.obj(my.data)
my.obj@main.data <- my.obj@raw.data
my.obj
my.obj@umap.data <- myUMAP
my.obj@pca.data <- myPCA
my.obj <- run.pc.tsne(my.obj, dims = 1:10)
### get the clusters
MyClust <- objectName@meta.data$celltype
### rename them to numbers
MyClust <- gsub("gamma","1",MyClust)
MyClust <- gsub("acinar","2",MyClust)
MyClust <- gsub("alpha","3",MyClust)
MyClust <- gsub("delta","4",MyClust)
MyClust <- gsub("beta","5",MyClust)
MyClust <- gsub("ductal","6",MyClust)
MyClust <- gsub("endothelial","7",MyClust)
MyClust <- gsub("activated_stellate","8",MyClust)
MyClust <- gsub("schwann","9",MyClust)
MyClust <- gsub("mast","10",MyClust)
MyClust <- gsub("macrophage","11",MyClust)
MyClust <- gsub("epsilon","12",MyClust)
MyClust <- gsub("quiescent_stellate","13",MyClust)
MyClust <- as.numeric(MyClust)
MyClust <- as.data.frame(MyClust)
colnames(MyClust) <- "clusters"
rownames(MyClust) <- rownames(myPCA)
my.obj@best.clust <- MyClust
save(my.obj, file = "my.obj.Robj")
Thanks Reza, this one is a different object, therefore I created a new issue. This one is made from 3 csv files, one is raw count, one is logcounts, and one is sample info. I will try the upper code on the other object and let you know.
Thanks, Yale
Thanks Reza, the code works perfectly for me! Thanks again, Yale
Hello Reza,
I am using a datamatrix to make a iCellR and run the workflow. But when I run the cluster.plot and run.diff.exp, I got error again and again.
The cluster.plot error is:
I tested this one and find the following code works:
But I don't know how to change it.
The run.diff.exp error is:
As my clsuters are 1 to 11, I changed my cluster to 0 (-1) or Cluster0 (paste0("Cluster", Info$cluster-1))), it still doesn't work.
I found I always run the cluster issue, when I transfer the data from seurat, the cluster is 0-10, then I will run issue at findMarkers step because of the unmatched clusters, then if the cluster starts from 1, the findMarkers works, but the run.diff.exp doesn't work.
The print(my.obj) ################################### An object of class iCellR version: 1.4.5 Raw/original data dimentions (rows,columns): 19831,92889 Data conditions: no conditions/single sample Row names: RP11-34P13.7,FO538757.2,AP006222.2 ... Columns names: AAACCTGAGACTGTAA.1,AAACCTGCAAGGTTTC.1,AAACCTGCATCTGGTA.1 ... ################################### QC stats performed:FALSE, PCA performed:FALSE Clustering performed:TRUE, Number of clusters:11 tSNE performed:TRUE, UMAP performed:FALSE, DiffMap performed:FALSE Main data dimensions (rows,columns): 2468,92889 Normalization factors:,... Imputed data dimensions (rows,columns):0,0 ############## scVDJ-seq ########### VDJ data dimentions (rows,columns):0,0 ############## CITE-seq ############ ADT raw data dimensions (rows,columns):0,0 ADT main data dimensions (rows,columns):0,0 ADT columns names:... ADT row names:... ############## scATAC-seq ############ ATAC raw data dimensions (rows,columns):0,0 ATAC main data dimensions (rows,columns):0,0 ATAC columns names:... ATAC row names:... ############## Spatial ########### Spatial data dimentions (rows,columns):0,0 ########### iCellR object ##########
My sessionInfo() R version 3.6.1 (2019-07-05) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 16299)
Matrix products: default
locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages: [1] grid stats graphics grDevices utils datasets methods base
other attached packages: [1] iCellR_1.4.5 plotly_4.9.1 hdf5r_1.3.0 gtable_0.3.0 RColorBrewer_1.1-2 [6] pheatmap_1.0.12 forcats_0.4.0 stringr_1.4.0 purrr_0.3.3 readr_1.3.1
[11] tidyr_1.0.0 tibble_2.1.3 ggplot2_3.2.1 tidyverse_1.3.0 pryr_0.1.4
[16] magrittr_1.5 data.table_1.12.6 xlsx_0.6.1 cowplot_1.0.0 Matrix_1.2-17
[21] dplyr_0.8.3 Seurat_3.1.1 formattable_0.2.0.1 classInt_0.4-2
loaded via a namespace (and not attached): [1] rappdirs_0.3.1 R.methodsS3_1.7.1 acepack_1.4.1 bit64_0.9-7 knitr_1.26
[6] irlba_2.3.3 multcomp_1.4-11 R.utils_2.9.2 rpart_4.1-15 generics_0.0.2
[11] metap_1.2 BiocGenerics_0.30.0 TH.data_1.0-10 RSQLite_2.1.4 RANN_2.6.1
[16] europepmc_0.3 future_1.15.1 bit_1.1-14 enrichplot_1.4.0 mutoss_0.1-12
[21] xml2_1.2.2 lubridate_1.7.4 httpuv_1.5.2 assertthat_0.2.1 viridis_0.5.1
[26] xfun_0.11 hms_0.5.2 rJava_0.9-11 evaluate_0.14 promises_1.1.0
[31] fansi_0.4.0 progress_1.2.2 caTools_1.17.1.2 dbplyr_1.4.2 readxl_1.3.1
[36] igraph_1.2.4.1 DBI_1.1.0 htmlwidgets_1.5.1 reshape_0.8.8 stats4_3.6.1
[41] ggpubr_0.2.5 backports_1.1.5 gbRd_0.4-11 RcppParallel_4.4.4 vctrs_0.2.0
[46] Biobase_2.44.0 Cairo_1.5-10 ROCR_1.0-7 withr_2.1.2 ggforce_0.3.1
[51] triebeard_0.3.0 checkmate_1.9.4 sctransform_0.2.0 prettyunits_1.0.2 mnormt_1.5-5
[56] cluster_2.1.0 DOSE_3.10.2 ape_5.3 lazyeval_0.2.2 crayon_1.3.4
[61] labeling_0.3 pkgconfig_2.0.3 tweenr_1.0.1 nlme_3.1-140 nnet_7.3-12
[66] rlang_0.4.1 globals_0.12.5 lifecycle_0.1.0 sandwich_2.5-1 modelr_0.1.5
[71] rsvd_1.0.2 cellranger_1.1.0 polyclip_1.10-0 lmtest_0.9-37 graph_1.62.0
[76] urltools_1.7.3 zoo_1.8-6 reprex_0.3.0 base64enc_0.1-3 ggridges_0.5.1
[81] png_0.1-7 viridisLite_0.3.0 bitops_1.0-6 R.oo_1.23.0 KernSmooth_2.23-15
[86] blob_1.2.0 qvalue_2.16.0 jpeg_0.1-8.1 NbClust_3.0 gridGraphics_0.4-1
[91] ggsignif_0.6.0 S4Vectors_0.22.1 reactome.db_1.68.0 scales_1.1.0 memoise_1.1.0
[96] graphite_1.30.0 plyr_1.8.4 ica_1.0-2 gplots_3.0.1.1 bibtex_0.4.2
[101] gdata_2.18.0 compiler_3.6.1 lsei_1.2-0 plotrix_3.7-7 fitdistrplus_1.0-14 [106] cli_2.0.0 listenv_0.8.0 pbapply_1.4-2 htmlTable_1.13.3 Formula_1.2-3
[111] MASS_7.3-51.4 tidyselect_0.2.5 stringi_1.4.3 GOSemSim_2.10.0 latticeExtra_0.6-29 [116] ggrepel_0.8.1 fastmatch_1.1-0 tools_3.6.1 future.apply_1.3.0 parallel_3.6.1
[121] rstudioapi_0.10 foreign_0.8-71 gridExtra_2.3 scatterplot3d_0.3-41 farver_2.0.1
[126] Rtsne_0.15 ggraph_2.0.0 digest_0.6.22 rvcheck_0.1.7 BiocManager_1.30.10 [131] shiny_1.4.0 Rcpp_1.0.2 broom_0.5.3 SDMTools_1.1-221.1 later_1.0.0
[136] RcppAnnoy_0.0.13 httr_1.4.1 ggdendro_0.1-20 AnnotationDbi_1.46.1 npsurv_0.4-0
[141] Rdpack_0.11-1 colorspace_1.4-1 rvest_0.3.5 fs_1.3.1 reticulate_1.13
[146] IRanges_2.18.3 splines_3.6.1 uwot_0.1.4 sn_1.5-4 graphlayouts_0.5.0
[151] xlsxjars_0.6.1 multtest_2.40.0 ggplotify_0.0.4 xtable_1.8-4 jsonlite_1.6
[156] tidygraph_1.1.2 UpSetR_1.4.0 zeallot_0.1.0 R6_2.4.1 TFisher_0.2.0
[161] Hmisc_4.3-0 pillar_1.4.3 htmltools_0.4.0 mime_0.8 glue_1.3.1
[166] fastmap_1.0.1 BiocParallel_1.18.1 class_7.3-15 codetools_0.2-16 fgsea_1.10.1
[171] tsne_0.1-3 mvtnorm_1.0-11 lattice_0.20-38 numDeriv_2016.8-1.1 leiden_0.3.1
[176] gtools_3.8.1 ReactomePA_1.28.0 zip_2.0.4 GO.db_3.8.2 survival_2.44-1.1
[181] rmarkdown_2.0 munsell_0.5.0 e1071_1.7-3 DO.db_2.9 haven_2.2.0
[186] reshape2_1.4.3
Thanks, Yale