forked from anna-alemany/VASAseq
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLantent_time.Rmd
164 lines (84 loc) · 4.62 KB
/
Lantent_time.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: "R Notebook"
output: html_notebook
---
Lanten time
####
```{r}
library(biomaRt)
```
```{r}
cardio_time_pseudo.membership <- fread("/lustre/scratch117/cellgen/team218/gp7/Joe/MicroExonator/")
cardio_time_pseudo <- fread("/lustre/scratch117/cellgen/team218/gp7/Joe/MicroExonator/Whippet/Quant/Single_Cell/Pseudo_bulks/pseudo_bulks.psi.tsv.gz")
cardio_time_pseudo.metadata <- fread("/lustre/scratch117/cellgen/team218/gp7/Joe/MicroExonator/heart_specif_Cardio_E85_latent_time.grep.txt")
cardio_time_pseudo[, pool_ID:=basename(Sample) ]
cardio_time_pseudo[, cluster:=gsub("\\_.*","", pool_ID)]
cardio_time_pseudo
cardio_time_pseudo.membership[, cluster:=gsub("\\_.*","", pseudo_bulk_ID)]
cardio_time_pseudo.membership[ cluster %in% c(1,2,3,4), ]
cardio_time_pseudo.membership.expand <- cardio_time_pseudo.membership[, .(barcode=strsplit(samples, ',')[[1]]), pseudo_bulk_ID]
cardio_time_pseudo.membership.expand.metadata <- merge(cardio_time_pseudo.membership.expand, cardio_time_pseudo.metadata , by="barcode")
```
```{r}
old_table <- data.table(id=1:4,
values=c('A,B,C',
'D,E',
'F',
'G,H,I,J'))
new_table <- old_table[, .(value=strsplit(values, ',')[[1]]), id]
```
```{r}
heart.total.sig <- fread('/lustre/scratch117/cellgen/team218/gp7/Joe/MicroExonator/Whippet.old/Cardiomyocytes_Precursors_vs_Cardiomyocytes_e85.txt')
heart.sig
cardio_time_pseudo.node
node_vector <-gsub('chr', '', heart.total.sig[ Gene=="ENSMUSG00000026305.15", Coord ])
node_vector
```
```{r}
visualise_latent_time <- function(time_pseudo, time_pseudo.membership.expand.metadata, node_vector, gene_vector) {
time_pseudo.node <- time_pseudo[ Coord %in% node_vector & cluster %in% c(1,2,3,4), ][order(cluster)]
gene_vector[time_pseudo.node$Gene]
time_pseudo.node[ , c("CI_low", "CI_high") := tstrsplit(`CI_Lo,Hi`, ",", fixed=TRUE)]
time_pseudo.node.LT <- merge(time_pseudo.node, time_pseudo.membership.expand.metadata[, .(latent_time=mean(latent_time)) , by=pseudo_bulk_ID], by.x="pool_ID", by.y="pseudo_bulk_ID")
time_pseudo.node.LT$Coord <- factor(time_pseudo.node.LT$Coord, levels = node_vector)
ggplot(data = time_pseudo.node.LT, aes(latent_time, as.numeric(Psi))) +
geom_pointrange(aes(ymin = as.numeric(CI_low), ymax = as.numeric(CI_high), colour=cluster),
linetype='solid') +
geom_smooth(method = "gam", linetype='dashed', colour="black") +
xlab("Mean latent time") +
ylab("Mean pseudo-pool splice node PSI") +
facet_grid(. ~ Coord, labeller = labeller(Coord = gene_vector) ) +
theme_bw() +
theme(axis.text.x = element_text(angle = 90, hjust=0.95,vjust=0.2), legend.position="none") +
guides(colour = guide_legend(nrow = 3)) +
ylim(c(0,1))
}
```
```{r, fig.width=15, fig.height=3 }
node_vector <- gsub('chr', '', heart.total.sig[ Gene=="ENSMUSG00000026305.15", Coord ])
visualise_latent_time( cardio_time_pseudo, cardio_time_pseudo.membership.expand.metadata, node_vector)
```
```{r, fig.width=15, fig.height=3 }
node_vector <- gsub('chr', '', head(heart.total.sig[order(-abs(DeltaPsi.mean) )]$Coord, n=10))
visualise_latent_time( cardio_time_pseudo, cardio_time_pseudo.membership.expand.metadata, node_vector)
```
```{r, fig.width=12, fig.height=3 }
ensembl_mm = useEnsembl(biomart="ensembl", dataset="mmusculus_gene_ensembl")
str_split( as.character(heart.total.sig$Gene), sep=".")
heart.total.sig[, ensembl_gene_id:= gsub("\\..*","", Gene)]
gene_table <- data.table(getBM(attributes=c('ensembl_gene_id', "mgi_symbol"),filters = 'ensembl_gene_id', values = heart.total.sig$ensembl_gene_id , mart = ensembl_mm))
heart.total.sig.genes <- merge(heart.total.sig, gene_table, by="ensembl_gene_id")
gene_table
gene_vector <- heart.total.sig.genes$mgi_symbol
names(gene_vector) <- gsub('chr', '', heart.total.sig.genes$Coord)
heart.total.sig[ Gene=="ENSMUSG00000026305.15", Coord ]
total_gene_table <- data.table(getBM(attributes=c("ensembl_transcript_id_version", "ensembl_transcript_id", "mgi_symbol"), filters = 'ensembl_transcript_id_version', values = ME_final$transcript , mart = ensembl_mm))
node_vector <- gsub('chr', '', heart.total.sig[order(cdf.beta), ][1:10, ][order(DeltaPsi.mean)]$Coord)
visualise_latent_time( cardio_time_pseudo, cardio_time_pseudo.membership.expand.metadata, node_vector, gene_vector)
```
```{r}
node_vector <- "X:140542511-140542668"
time_pseudo <- cardio_time_pseudo
time_pseudo.membership.expand.metadata <- cardio_time_pseudo.membership.expand.metadata
visualise_latent_time( cardio_time_pseudo, cardio_time_pseudo.membership.expand.metadata, node_vector)
```