-
Notifications
You must be signed in to change notification settings - Fork 0
/
Brain.R
65 lines (46 loc) · 1.94 KB
/
Brain.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
library(dplyr)
library(Seurat)
library(Matrix)
library(cowplot)
library(ggplot2)
# Specify data path
data_path <- "dataset/"
# Load datasets
countdata <- read.csv(paste0(data_path, "GSE89567_normalized.csv.gz"), header = TRUE,
row.names = 1, as.is = TRUE, stringsAsFactors = FALSE)
metadata <- read.csv(paste0(data_path, "metadata.csv"), header = TRUE,
row.names = 1, as.is = TRUE)
countdata <- Matrix(as.matrix(countdata), sparse = TRUE)
Brain <- CreateSeuratObject(counts = countdata, project ="Brain",
min.cells = 5, min.features = 100, meta.data = metadata)
Brain <- FindVariableFeatures(Brain, selection.method = "vst", nfeatures = 2000)
top10 <- head(VariableFeatures(Brain), 10)
top10
plot1 <- VariableFeaturePlot(Brain)
plot2 <- LabelPoints(plot = plot1, points = top10, repel = TRUE)
CombinePlots(plots = list(plot1, plot2))
all.genes <- rownames(Brain)
Brain <- ScaleData(Brain, features = all.genes)
# Clustering the cell using PCA & UMAP
Brain <- RunPCA(Brain, features = VariableFeatures(object = Brain))
ElbowPlot(Brain)
Brain <- FindNeighbors(Brain, dims = 1:15)
Brain <- FindClusters(Brain, resolution = 0.5)
DimPlot(Brain, reduction = "pca")
Brain <- RunUMAP(Brain, dims = 1:15)
DimPlot(Brain, reduction = "umap")
# Changing the identity with metadata
Idents(Brain) <- [email protected]$leiden
head(Idents(Brain))
p1 <- DimPlot(Brain, reduction = "umap")
Idents(Brain) <- [email protected]$Major_type
head(Idents(Brain))
p2 <- DimPlot(Brain, reduction = "umap")
plot_grid(p1, p2)
Tumor.markers <- FindMarkers(Brain, ident.1 = "Tumor", min.pct = 0.25)
Macrophage.markers <- FindMarkers(Brain, ident.1 = "Macrophage", min.pct = 0.25)
head(Tumor.markers, n = 10)
head(Macrophage.markers, n = 10)
write.table(Tumor.markers, file="Tumor.markers.txt", sep='\t')
write.table(Macrophage.markers, file="Macrophage.markers.txt", sep='\t')
FeaturePlot(Brain, features = c("'EGFR'", "'CD14'"))