-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathExtend_data_5.Rmd
executable file
·164 lines (134 loc) · 5.15 KB
/
Extend_data_5.Rmd
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
---
title: "EEC_UMIcounts"
author: "yejg"
date: "2017/12/25"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,message = FALSE,warning = FALSE,tidy = TRUE)
```
### Library necessary packages
```{r,message=FALSE,message=FALSE}
library(NMF)
library(rsvd)
library(Rtsne)
library(ggplot2)
library(cowplot)
library(sva)
library(igraph)
library(cccd)
library(KernSmooth)
library(beeswarm)
library(stringr)
library(reshape2)
library(formatR)
library(destiny)
source('Fxns.R')
```
### Load data
```{r}
EEC_UMIs<-load_data('./Extend_data/GSE92332_EEC_UMIcounts.txt.gz')
### whether need this step??
gene_expr<-as.numeric(apply(EEC_UMIs,1,sum))
EEC_UMIs<-EEC_UMIs[which(gene_expr>0),]
EEC_tpm=data.frame(log2(1+tpm(EEC_UMIs)))
```
### Select variables
```{r}
v=get.variable.genes(EEC_UMIs,min.cv2=100)
var.genes=as.character(rownames(v)[v$p.adj<0.05])
```
### Extract messages from samples
```{r}
gene.names<-rownames(EEC_tpm)
sample.names<-colnames(EEC_tpm)
region.names<-unlist(lapply(sample.names,function(x)return(str_split(x,'_')[[1]][3])))
mices<-unlist(lapply(sample.names,function(x)return(str_split(x,'_')[[1]][2])))
cell.types<-unlist(lapply(sample.names,function(x)return(str_split(x,'_')[[1]][4])))
```
### TSNE,PCA
```{r}
# do not known whether it has batch effect. Ignore here. If need to be checked,and will do it
tsne.rot<-PCA_TSNE.scores(data.tpm = EEC_tpm,data.umis=EEC_UMIs,var_genes = var.genes,data_name = './Extend_data/EEC',is.var.genes = TRUE)
tsne.rot<-as.data.frame(tsne.rot)
colnames(tsne.rot)<-c('tSNE_1','tSNE_2')
pca<-read.table('./Extend_data/EEC_pca_scores.txt')
```
### Figure a
```{r}
ggplot(data = tsne.rot,aes(x=tSNE_1,y=tSNE_2,color=region.names))+geom_point()+
scale_color_manual(values=brewer16)+scale_fill_discrete()+theme(legend.title=element_blank())+ggtitle('Regions')
```
### Figure b
### do not how to plot???
### Figure c
#### Figure c.1
```{r}
ggplot(data = tsne.rot,aes(x=tSNE_1,y=tSNE_2,color=cell.types))+geom_point()+
scale_color_manual(values=brewer16)+scale_fill_discrete()+theme(legend.title=element_blank())+ggtitle('Cells Type')
```
```{r}
genes.1<-c('Neurog3','Sct','Tac1')
All.Facet.tsne.1<-data.frame()
for(gene in genes.1){
All.Facet.tsne.1<-rbind(All.Facet.tsne.1,
Facet_wrap_fun(gene=gene,tpm.data = EEC_tpm,tsne.data = tsne.rot,condition = unique(cell.types),all.condition = cell.types))
}
ggplot(data=All.Facet.tsne.1,aes(x=tSNE_1,y=tSNE_2,colour=Gene.Mp))+geom_point()+
facet_wrap(~ Gene, nrow = 5,ncol = 2)+
theme(legend.title = element_text(size=10,color='blue',face='bold'),legend.position = 'right')+
scale_color_gradient2(low='lightblue',mid='green',high='red',name='Log2\nTPM+1')
```
```{r}
genes.2<-c('Sst','Cck','Gcg','Ghrl')
All.Facet.tsne.2<-data.frame()
for(gene in genes.2){
All.Facet.tsne.2<-rbind(All.Facet.tsne.2,
Facet_wrap_fun(gene=gene,tpm.data = EEC_tpm,tsne.data = tsne.rot,condition = unique(cell.types),all.condition = cell.types))
}
ggplot(data=All.Facet.tsne.2,aes(x=tSNE_1,y=tSNE_2,colour=Gene.Mp))+geom_point()+
facet_wrap(~ Gene, nrow = 5,ncol = 2)+
theme(legend.title = element_text(size=10,color='blue',face='bold'),legend.position = 'right')+
scale_color_gradient2(low='lightblue',mid='green',high='red',name='Log2\nTPM+1')
```
```{r}
genes.3<-c('Glp','Nts','Reg4','Pyy')
All.Facet.tsne.3<-data.frame()
for(gene in genes.3){
All.Facet.tsne.3<-rbind(All.Facet.tsne.3,
Facet_wrap_fun(gene=gene,tpm.data = EEC_tpm,tsne.data = tsne.rot,condition = unique(cell.types),all.condition = cell.types))
}
ggplot(data=All.Facet.tsne.3,aes(x=tSNE_1,y=tSNE_2,colour=Gene.Mp))+geom_point()+
facet_wrap(~ Gene, nrow = 5,ncol = 2)+
theme(legend.title = element_text(size=10,color='blue',face='bold'),legend.position = 'right')+
scale_color_gradient2(low='lightblue',mid='green',high='red',name='Log2\nTPM+1')
```
### Figure d
#### Figure d left
heatmap shows the expression of canonical gut hormone genes (rows) in each of 533 individual EEC cells (columns), coloured on the basis of their assignment to the clusters
```{r}
genes.p<-c('Neurog3','Sct','Tac1','Sst','Cck','Gcg','Ghrl','Gip','Nts','Reg4','Pyy')
# check whether genes in sample
# for(gene in genes.p){
# if(!gene%in%gene.names){
# cat(sprintf('%s is not exist',gene))
# }
# }
EEC.heatmap.d.tpm<-Heatmap_fun(genes=genes.p,tpm.data = EEC_tpm,condition = unique(cell.types),all.condition = cell.types)
aheatmap(x=EEC.heatmap.d.tpm[[2]],Colv = NA,Rowv = NA,annCol = EEC.heatmap.d.tpm[[1]])
```
#### Figure d right
heatmap shows for each cluster (columns) the percentage of cells (inset text) in which the
transcript for each hormone (rows) is detected.
```{r}
EEC_UMIs_1<-as.data.frame(t(EEC_UMIs[gene.names%in%genes.p,]))
Count<-lapply(unique(cell.types),function(x){
x.1<-EEC_UMIs_1[cell.types%in%x,]
x.2<-unlist(apply(x.1,2,sum))
return(data.frame(x=round(x.2/sum(x.2),3)))
})
EEC_UMIs_prop<-as.data.frame(Count)*100
colnames(EEC_UMIs_prop)<-unique(cell.types)
#EEC_UMIs_prop<-data.frame(t(EEC_UMIs_prop)*100)
aheatmap(EEC_UMIs_prop, color = cubehelix1.16, border_color = list("cell"="white"), txt=EEC_UMIs_prop, Colv = NA, Rowv = NA )
```