-
Notifications
You must be signed in to change notification settings - Fork 3
/
Extended-Data-Figure_10.R
executable file
·223 lines (162 loc) · 9.14 KB
/
Extended-Data-Figure_10.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
library(KernSmooth)
library(NMF)
library(rsvd)
library(Rtsne)
library(ggplot2)
library(cowplot)
library(sva)
library(igraph)
library(cccd)
library(destiny)
library(stringr)
library(reshape2)
library(vioplot)
source('Fxns.R')
SalmHelm_UMIs<-load_data("./data/GSE92332_SalmHelm_UMIcounts.txt.gz")
SalmHelm_UMIs<-SalmHelm_UMIs[which(unlist(apply(SalmHelm_UMIs,1,sum))>0),]
v = get.variable.genes(SalmHelm_UMIs, min.cv2 = 100)
var.genes = as.character(rownames(v)[v$p.adj<0.05]) # select genes
SalmHelm_tpm<-data.frame(log2(1+tpm(SalmHelm_UMIs)))
SalmHelm.all.cells<-colnames(SalmHelm_UMIs)
SalmHelm.all.genes<-rownames(SalmHelm_UMIs)
SalmHelm.condition<-unlist(lapply(SalmHelm.all.cells,function(x)return(str_split(x,'_')[[1]][3]))) # cell by conditon
SalmHelm.cell.groups<-unlist(lapply(SalmHelm.all.cells,function(x)return(str_split(x,'_')[[1]][4]))) # cell groups
SalmHelm.batches<-unlist(lapply(SalmHelm.all.cells,function(x)return(str_split(x,'_')[[1]][1]))) # batches
# check batch effect
table(SalmHelm.batches)
batch_mean_tpm = group.means(counts = SalmHelm_tpm, groups = SalmHelm.batches)
x = batch_mean_tpm[, 1]
y = batch_mean_tpm[,2]
expr.cor = round(cor(x,y),2)
smoothScatter(x, y, nrpoints=Inf, pch=16, cex=0.25, main=sprintf("Before batch correction, correlation between \ntwo illustrative batches is %s", expr.cor), xlab="All genes Batch 2, mean log2(TPM+1)", ylab="All genes Batch 1, mean log2(TPM+1)")
# remove the batch effect
SalmHelm_tpm_norm = batch.normalise.comBat(counts = as.matrix(SalmHelm_tpm), batch.groups = SalmHelm.batches)
batch_mean_tpm_norm = group.means(counts =SalmHelm_tpm_norm, groups = SalmHelm.batches)
x = batch_mean_tpm_norm[, 1]
y = batch_mean_tpm_norm[,2]
expr.cor = round(cor(x,y),2)
smoothScatter(x, y, nrpoints=Inf, pch=16, cex=0.25, main=sprintf("After batch correction, correlation between \ntwo illustrative batches is %s", expr.cor), xlab="All genes Batch 2, mean log2(TPM+1)", ylab="All genes Batch 1, mean log2(TPM+1)")
# Dimensionality reduction
SalmHelm.tsne.rot<-PCA_TSNE.scores(data.tpm = SalmHelm_tpm_norm,data.umis = SalmHelm_UMIs,var_genes = var.genes,
data_name = './data/SalmHelm',sig.pcs = TRUE,is.var.genes = TRUE)
SalmHelm.tsne.rot<-data.frame(SalmHelm.tsne.rot)
colnames(SalmHelm.tsne.rot)<-c('tSNE_1','tSNE_2')
ggplot(data =SalmHelm.tsne.rot,aes(x=tSNE_1,y=tSNE_2))+geom_point(aes(colour=SalmHelm.cell.groups))+
scale_color_manual(values=brewer16)+scale_fill_discrete()+theme(legend.title=element_blank())+ggtitle('SalmHelm')
ggplot(data =SalmHelm.tsne.rot,aes(x=tSNE_1,y=tSNE_2))+geom_point(aes(colour=SalmHelm.condition))+
scale_color_manual(values=brewer16)+scale_fill_discrete()+theme(legend.title=element_blank())+ggtitle('SalmHelm')
# Figure a
genes<-c('Cd74','Gpx2','Hsph1') # gene Hsph5 can not be found in all genes
for(gene in genes){
Genes_mean_tpm(genes =gene ,tpm_data = SalmHelm_tpm_norm[,SalmHelm.condition%in%'Control'],
tsne_data = SalmHelm.tsne.rot[SalmHelm.condition%in%'Control',],title = 'Control')
}
for(gene in genes){
Genes_mean_tpm(genes =gene ,tpm_data = SalmHelm_tpm_norm[,SalmHelm.condition%in%"Hpoly.Day3"],
tsne_data = SalmHelm.tsne.rot[SalmHelm.condition%in%"Hpoly.Day3",],title = "Hpoly.Day3")
}
for(gene in genes){
Genes_mean_tpm(genes =gene ,tpm_data = SalmHelm_tpm_norm[,SalmHelm.condition%in%"Hpoly.Day10"],
tsne_data = SalmHelm.tsne.rot[SalmHelm.condition%in%"Hpoly.Day10",],title = "Hpoly.Day10")
}
for(gene in genes){
Genes_mean_tpm(genes =gene ,tpm_data = SalmHelm_tpm_norm[,SalmHelm.condition%in%"Salmonella"],
tsne_data = SalmHelm.tsne.rot[SalmHelm.condition%in%"Salmonella",],title = "Salmonella")
}
# Figure b
SalmHelm.Tuft.tpm<-SalmHelm_tpm_norm[,SalmHelm.cell.groups%in%'Tuft']
SalmHelm.Tuft.tsne<-SalmHelm.tsne.rot[SalmHelm.cell.groups%in%'Tuft',]
SalmHelm.Tuft.pca<-read.table('SalmHelm_pca_scores.txt')[SalmHelm.cell.groups%in%'Tuft',]
### Find the k to make 3 cluster
### k-nearest method
Find_K<-function(K,pca.data,n=3){
dm<-as.matrix(dist(pca.data))
for(k in K){
knn<-build_knn_graph(dm,k=k)
clustering<-cluster_graph(knn)$partition
if(length(unique(clustering))==n){
cat(sprintf('Find the K:%d\n',k))
return(k)
break
}
}
}
K<-seq(2,200,by = 2)
k<-Find_K(K = K,pca.data = SalmHelm.Tuft.pca[,1:15])
dm<-as.matrix(dist(SalmHelm.Tuft.pca[,1:15]))
# build nearest neighbor graph
knn = build_knn_graph(dm, k =74)
Tuft.clustering = cluster_graph(knn)$partition
### Kmeans method
# SalmHelm.Tuft.kmeans<-kmeans(SalmHelm.Tuft.tsne,3)
# Tuft.clustering<-as.character(SalmHelm.Tuft.kmeans$cluster)
Tuft.clustering<-paste('Tuft-',Tuft.clustering,sep='')
Tuft.clustering<-ifelse(Tuft.clustering=='Tuft-1','Tuft-1',ifelse(Tuft.clustering=='Tuft-2','Tuft-2','Progenitor'))
score_1<-unlist(apply(SalmHelm.Tuft.tpm[Tuft_1_marker_genes,],2,mean,na.rm=TRUE))
score_2<-unlist(apply(SalmHelm.Tuft.tpm[Tuft_2_marker_genes,],2,mean,na.rm=TRUE))
Dklk1<-as.numeric(SalmHelm.Tuft.tpm['Dclk1',])
Violin.data1<-cbind(data.frame(Value=score_1),data.frame(Group=Tuft.clustering))
Violin.data2<-cbind(data.frame(Value=score_2),data.frame(Group=Tuft.clustering))
Dklk1.data<-cbind(data.frame(Value=Dklk1),data.frame(Group=Tuft.clustering))
## Figure b.1
ggplot(data=Violin.data1,aes(x=Group,y=Value,colour=Group))+
geom_violin(aes(fill=Group))+geom_boxplot(width=0.1,fill="white")+
geom_jitter(shape=16, position=position_jitter(0.2),color='black')+
theme(legend.title = element_blank())+ggtitle(label = 'Tuft-1 score')+
xlab(NULL)+ylab('Expression Level\nLog2(TPM+1)')
#stat_summary(fun.data=mean_sdl,geom="pointrange", color="red")
## Figure b.2
ggplot(data=Violin.data2,aes(x=Group,y=Value,colour=Group))+
geom_violin(aes(fill=Group))+geom_boxplot(width=0.1,fill="white")+
geom_jitter(shape=16, position=position_jitter(0.2),color='black')+
theme(legend.title = element_blank())+ggtitle(label = 'Tuft-2 score')+
xlab(NULL)+ylab('Expression Level\nLog2(TPM+1)')
## Figure b.3
ggplot(data=Dklk1.data,aes(x=Group,y=Value,colour=Group))+
geom_violin(aes(fill=Group))+geom_boxplot(width=0.1,fill="white")+
geom_jitter(shape=16, position=position_jitter(0.2),color='black')+
theme(legend.title = element_blank())+ggtitle(label = 'Dckl1')+
xlab(NULL)+ylab('Expression Level\nLog2(TPM+1)')
# Figure c
Tuft_1_marker_genes<-as.character(read.table('./data/Tuft_1_marker_genes.txt',header = FALSE)$V1)
Tuft_2_marker_genes<-as.character(read.table('./data/Tuft_2_marker_genes.txt',header = FALSE)$V1)
## Figure c.1
ggplot(SalmHelm.Tuft.tsne, aes(x=tSNE_1, y=tSNE_2))+geom_point(aes(color=score_1))+
theme(legend.title = element_text(size=8,color='blue',face='bold'),
legend.position = 'right') +ggtitle('Tuft-1 Score')+scale_color_gradient2(low='lightblue',mid='green',high='red',name='Log2\nTPM+1')
## Figure c.2
ggplot(SalmHelm.Tuft.tsne, aes(x=tSNE_1, y=tSNE_2))+geom_point(aes(color=score_2))+
theme(legend.title = element_text(size=8,color='blue',face='bold'),
legend.position = 'right') +ggtitle('Tuft-2 Score')+scale_color_gradient2(low='lightblue',mid='green',high='red',name='Log2\nTPM+1')
## Figure c.3
ggplot(data =SalmHelm.Tuft.tsne,aes(x=tSNE_1,y=tSNE_2))+geom_point(aes(colour=Tuft.clustering))+
scale_color_manual(values=brewer16)+scale_fill_discrete()+theme(legend.title=element_blank())+ggtitle('Tuft')
# Figure d
SalmHelm.Goblet.tpm<-SalmHelm_tpm_norm[,SalmHelm.cell.groups%in%'Goblet']
SalmHelm.Goblet.condiion<-SalmHelm.condition[SalmHelm.cell.groups%in%'Goblet']
SalmHelm.Goblet.condition.tpm<-SalmHelm.Goblet.tpm[,SalmHelm.Goblet.condiion%in%c('Control',"Hpoly.Day3","Hpoly.Day10")]
SalmHelm.Goblet.condiion3<-SalmHelm.Goblet.condiion[SalmHelm.Goblet.condiion%in%c('Control',"Hpoly.Day3","Hpoly.Day10")]
Retnlb<-as.numeric(SalmHelm.Goblet.condition.tpm['Retnlb',])
Wars<-as.numeric(SalmHelm.Goblet.condition.tpm['Wars',])
Pnliprp2<-as.numeric(SalmHelm.Goblet.condition.tpm['Pnliprp2',])
Violin.Retnlb<-cbind(data.frame(Value=Retnlb),data.frame(Group=SalmHelm.Goblet.condiion3))
Violin.Wars<-cbind(data.frame(Value=Wars),data.frame(Group=SalmHelm.Goblet.condiion3))
Violin.Pnliprp2<-cbind(data.frame(Value=Pnliprp2),data.frame(Group=SalmHelm.Goblet.condiion3))
## Figure d.1
ggplot(data=Violin.Retblb,aes(x=Group,y=Value,colour=Group))+
geom_violin(aes(fill=Group))+geom_boxplot(width=0.1,fill="white")+
geom_jitter(shape=16, position=position_jitter(0.2),color='black')+
theme(legend.title = element_blank())+ggtitle(label = 'Retnlb')+
xlab(NULL)+ylab('Expression Level\nLog2(TPM+1)')
## Figure d.2
ggplot(data=Violin.Wars,aes(x=Group,y=Value,colour=Group))+
geom_violin(aes(fill=Group))+geom_boxplot(width=0.1,fill="white")+
geom_jitter(shape=16, position=position_jitter(0.2),color='black')+
theme(legend.title = element_blank())+ggtitle(label = 'Wars')+
xlab(NULL)+ylab('Expression Level\nLog2(TPM+1)')
## Figure d.3
ggplot(data=Violin.Pnliprp2,aes(x=Group,y=Value,colour=Group))+
geom_violin(aes(fill=Group))+geom_boxplot(width=0.1,fill="white")+
geom_jitter(shape=16, position=position_jitter(0.2),color='black')+
theme(legend.title = element_blank())+ggtitle(label = 'Pnliprp2')+
xlab(NULL)+ylab('Expression Level\nLog2(TPM+1)')