CCA
需要很大的内存,我开到了64+512仍然卒,可能我的数据量比较大,但理解过后,还是奉上代码,还有友情提示,多看看seraut官网,https://satijalab.org/seurat/v3.2/integration.html。
library(Seurat)
library(ggplot2)
library(cowplot)
library(Matrix)
library(dplyr)
library(ggsci)
library(tidyverse)
library(SingleR)
library(harmony)
library(patchwork)
exp1 <- data.table::fread('GSE132465_GEO_processed_CRC_10X_raw_UMI_count_matrix.txt',data.table = F)
test <- exp1[1:10,1:10]
rownames(exp1) <- exp1$Index
exp1 <-exp1[,-1]
experiment.aggregate <- CreateSeuratObject(
exp1,
project = "multi",
min.cells = 10,
min.features = 200,
names.field = 1,
names.delim = "-")
View(experiment.aggregate@meta.data)
experiment.aggregate[["percent.mt"]] <- PercentageFeatureSet(experiment.aggregate,
pattern = "^MT-")
options(future.globals.maxSize = 800 * 1024^3) #将全局变量上限调至20G
library(future)
plan(multiprocess, workers = 100) #允许并行计算函数使用20个线程
dir.create("SCTransform")
setwd("./SCTransform")
experiment.aggregate.list <- SplitObject(experiment.aggregate, split.by = "orig.ident")
for (i in 1:length(experiment.aggregate.list)) {
experiment.aggregate.list[[i]] <- SCTransform(experiment.aggregate.list[[i]], verbose = FALSE)
}
experiment.aggregate.features <- SelectIntegrationFeatures(object.list = experiment.aggregate.list, nfeatures = 3000)
experiment.aggregate.list <- PrepSCTIntegration(object.list = experiment.aggregate.list, anchor.features = experiment.aggregate.features, verbose = FALSE)
experiment.aggregate.anchors <- FindIntegrationAnchors(object.list = experiment.aggregate.list, normalization.method = "SCT",
anchor.features = experiment.aggregate.features, verbose = FALSE)
experiment.aggregate.integrated <- IntegrateData(anchorset = experiment.aggregate.anchors, normalization.method = "SCT",
verbose = FALSE)
View(experiment.aggregate.integrated@meta.data)
experiment.aggregate.integrated<- RunPCA(experiment.aggregate.integrated, verbose = F)
ElbowPlot(experiment.aggregate.integrated, ndims = 50)
pc.num=1:30
experiment.aggregate.integrated <- experiment.aggregate.integrated %>% RunTSNE(dims=pc.num) %>% RunUMAP(dims=pc.num) %>%
FindNeighbors(dims = pc.num) %>% FindClusters(resolution=0.8)
没有支持他跑下去的电脑,所以卒。
PCA
听说电脑的配置小一点
library(Seurat)
library(ggplot2)
library(cowplot)
library(Matrix)
library(dplyr)
library(ggsci)
library(tidyverse)
library(SingleR)
library(harmony)
library(patchwork)
exp1 <- data.table::fread('GSE132465_GEO_processed_CRC_10X_raw_UMI_count_matrix.txt',data.table = F)
test <- exp1[1:10,1:10]
rownames(exp1) <- exp1$Index
exp1 <-exp1[,-1]
experiment.aggregate <- CreateSeuratObject(
exp1,
project = "multi",
min.cells = 10,
min.features = 200,
names.field = 1,
names.delim = "_")
View(experiment.aggregate@meta.data)
experiment.aggregate[["percent.mt"]] <- PercentageFeatureSet(experiment.aggregate,
pattern = "^MT-")
options(future.globals.maxSize = 256 * 1024^3) #将全局变量上限调至20G
library(future)
plan(multiprocess, workers = 32)
bm40k.list <- SplitObject(experiment.aggregate, split.by = "orig.ident")
bm40k.list <- lapply(X = bm40k.list, FUN = function(x) {
x <- NormalizeData(x, verbose = FALSE)
x <- FindVariableFeatures(x, verbose = FALSE)
})
features <- SelectIntegrationFeatures(object.list = bm40k.list)
bm40k.list <- lapply(X = bm40k.list, FUN = function(x) {
x <- ScaleData(x, features = features, verbose = FALSE)
x <- RunPCA(x, features = features, verbose = FALSE)
})
anchors <- FindIntegrationAnchors(object.list = bm40k.list, reference = c(1, 2), reduction = "rpca",
dims = 1:30)
bm40k.integrated <- IntegrateData(anchorset = anchors, dims = 1:30)
bm40k.integrated <- ScaleData(bm40k.integrated, verbose = FALSE)
bm40k.integrated <- RunPCA(bm40k.integrated, verbose = FALSE)
ElbowPlot(scRNA, ndims = 50)
pc.num=1:30
scRNA <- scRNA %>% RunTSNE(dims=pc.num) %>% RunUMAP(dims=pc.num) %>%
FindNeighbors(dims = pc.num) %>% FindClusters(resolution=0.8)
最终结果 卒 哈哈哈 那种同一平台测同一部位的多样本数据,建议harmony把
网友评论