-
Notifications
You must be signed in to change notification settings - Fork 0
/
LiverIntegration.R
187 lines (153 loc) · 5.36 KB
/
LiverIntegration.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# Load packages
library(Seurat)
library(hdf5r)
library(ggplot2)
library(ggsci)
library(dplyr)
# Set working directory
setwd("~/Seurat")
# Load data
SeuObj <- readRDS("~/Seurat/SeuObj.rds")
# Isolate Liver tissue
Idents(SeuObj) <- "Tissue"
liverObj <- subset(x=SeuObj, idents = "LIVER")
# Perform analysis without integration
# Scaling
all.genes <- rownames(liverObj)
liverObj <- ScaleData(liverObj, features = all.genes)
#PCA
liverObj <- RunPCA(liverObj)
# Determine dimensionality of the data
ElbowPlot(liverObj, ndims = 50)
# Harmony integration
liverObj <- IntegrateLayers(
object = liverObj, method = HarmonyIntegration,
orig.reduction = "pca", new.reduction = "harmony",
verbose = FALSE
)
# Re-join layers after integration
liverObj[["RNA"]] <- JoinLayers(liverObj[["RNA"]])
# Checking clusters of harmony integration
liverObj <- FindNeighbors(liverObj, reduction = "harmony", dims = 1:30)
liverObj <- FindClusters(liverObj, resolution = 0.5)
liverObj <- RunUMAP(liverObj, dims = 1:30, reduction = "harmony")
# Identify markers of each clusters
liverObj@misc$markers <- FindAllMarkers(liverObj)
saveRDS(liverObj, file = "liverObjI.rds")
#### Add metadata ####
# Add stage in meta data
# Create lookup table with stage and sample
lookup <- data.frame(Patient_ID = c('10113-1','10113-2','10202','10203','10205','10291-2','10380','10634','10738','10742','9680','9932', '9961', '9991', '9999'),
Stage = c('F1_2','F0','F1_2','F1_2','F1_2','F1_2','F1_2','F1_2','F1_2','H','F1_2','F1_2', 'F0', 'F1_2', 'F0'))
# Extract meta data
meta <- [email protected]
# Create new column in meta data for Stage
meta$Stage <- NA
# Run for all samples in a for loop to populate the whole column
for (x in 1:length(lookup$Patient_ID)) {
meta$Stage[grep(lookup$Patient_ID[x], meta$Patient_ID)] <- lookup$Stage[x]
}
# Add meta data back to seurat object
liverObj <- AddMetaData(liverObj, metadata = meta)
# Add cluster.stage in metadata
liverObj$Cluster.Stage <- paste(liverObj$seurat_clusters , liverObj$Stage, sep = "_")
#### Plot UMAPs ####
# Ploting UMAP for clusters
ggp = DimPlot(liverObj, reduction = "umap", raster=FALSE, label = TRUE)+
theme_classic()+ labs(title = "LIVER clusters")
ggsave(
plot = ggp,
filename = ("~/plots/liver/clusters.tiff"),
height = 8,
width = 8,
dpi = 300,
units = 'in'
)
#Ploting UMAP for clusters by stage
ggp = DimPlot(liverObj, reduction = "umap", group.by = "Stage", raster=FALSE)+
theme_classic()+ labs(title = "LIVER clusters by Stage")
ggsave(
plot = ggp,
filename = ("~/plots/liver/clusters_by_stage.tiff"),
height = 8,
width = 8,
dpi = 300,
units = 'in'
)
# Ploting UMAP for clusters by Patient_ID
ggp = DimPlot(liverObj, reduction = "umap", group.by = "Patient_ID", raster=FALSE)+
theme_classic()+ labs(title = "LIVER clusters by Patient_ID")
ggsave(
plot = ggp,
filename = ("~/plots/liver/clusters_by_patients.tiff"),
height = 8,
width = 8,
dpi = 300,
units = 'in'
)
#### Generate count plots ####
# Create tissue summary data frame
summary <- [email protected] %>%
group_by(Stage) %>%
count(seurat_clusters) %>%
mutate(proportion = n / sum(n))
# Plot summary proportional bar chart
ggp <- ggplot(summary, aes(x = seurat_clusters, y = n, fill = Stage)) +
geom_bar(stat = "identity", position = "stack") +
guides(fill=guide_legend(title="Stage")) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
ggsave(
plot = ggp,
filename = ("~/plots/liver/cluster_count.tiff"),
height = 5,
width = 10,
dpi = 300,
units = 'in'
)
saveRDS(liverObj, file = "liverObjI.rds")
#### MHC expression ####
features <- c('HLA-A','HLA-B','HLA-C','HLA-DRA', 'HLA-DP', 'HLA-DM', 'HLA-DOA', 'HLA-DOB','HLA-DQ')
# Split by Stage
Idents(object = liverObj) <- "Stage"
ggp = DotPlot(liverObj, features = features)+ RotatedAxis()+
scale_fill_npg()+ labs(title = "Antigen presentation in Liver", x ='MHC genes', y = 'Stage')
ggsave(
plot = ggp,
filename = ("~/plots/liver/Antigen_presentation_markers_stage.tiff"),
height = 5,
width = 5,
dpi = 300,
units = 'in'
)
# Split by Patient_ID
Idents(object = liverObj) <- "Patient_ID"
# Arrange the patients according to stage
[email protected] <- factor ([email protected],
levels = c('10205','9991','9932', '9680','10113-1','10202','10203','10291-2','10380','10634','10738','10113-2','9999','9961','10742'))
ggp = DotPlot(liverObj, features = features)+ RotatedAxis()+
scale_fill_npg()+ labs(title = "Antigen presentation in Liver", x ='MHC genes', y = 'Patient_ID')
ggsave(
plot = ggp,
filename = ("~/plots/liver/Antigen_presentation_markers_patients.tiff"),
height = 5,
width = 5,
dpi = 300,
units = 'in'
)
# change cluster name
liverObj$cluster <- paste0("C", liverObj$seurat_clusters)
Idents(liverObj) <- "cluster"
# Arrange the cluster according to no
[email protected] <- factor ([email protected],
levels = c('C0','C1','C2', 'C3','C4','C5','C6','C7','C8','C9','C10','C11','C12','C13','C14', 'C15', 'C16', 'C17', 'C18', 'C19', 'C20', 'C21', 'C22'))
features <- c('CD3E','CD4','CD8B','ALB')
ggp = DotPlot(liverObj, features = features)+ RotatedAxis()+
scale_fill_npg()+ labs(title = "T cells and Hepatocytes in Liver tissue", x ='Genes', y = 'Cluster_ID')
ggsave(
plot = ggp,
filename = ("~/plots/liver/T cells and Hepatocytes in Liver tissue.tiff"),
height = 5,
width = 8,
dpi = 300,
units = 'in'
)