-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.R
174 lines (96 loc) · 4.87 KB
/
global.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
#This is the global.R file for out CellTag Vizualtion Shiny App.
#In this file you should load all libraries, functions, or data required for use with the shiny app.
#This loads the shiny package required to run the app.
library(shiny)
#This packages allows multiple custom themes to be used with shiny webapps.
library(shinythemes)
#This loads useful "tidy" libraries for typically used for manipulating data.
library(tidyverse)
#This is a package that customizes ggplot2 plots. It creates a more minimal output and creates more appealing plots in my opinion.
library(cowplot)
#This is a package used to visualize graphs. Particularly the clonal graphs which visualizes clones as well as their related clones from subsequent rounds of CellTagging.
library(igraph)
#This package is used to construct the clonal CellTag networks.
library(networkD3)
library(viridis)
shinyjs::useShinyjs()
dataPath <- "data/celltag.viz.data.txt"
seuratPath <- "data/seurat.gene.expression.subset.Rds"
monoclePath <- "data/monocle.gene.expression.subset.Rds"
#Data required for Clone Network Visualiztions
#load(file = "links_and_Nodes.RData")
#load(file = "tag_metadata.RData")
load(file = "data/functions.RData")
load(file = "data/links_and_Nodes.HF1.RData")
load(file = "data/links_and_Nodes.HF2.RData")
load(file = "data/tag_metadata.HF1.RData")
load(file = "data/tag_metadata.HF2.RData")
netColorChoice <- colnames(hf1.Nodes)[c(6, 8, 10:15, 18)]
names(netColorChoice) <- netColorChoice
netColorChoice[9] <- "tag"
all_tags <- hf1.all_tags
hf1Names <- hf1.all_tags
hf1Names <- strsplit(hf1Names, split = "_")
hf1Names <- lapply(hf1Names, "[[", 2)
hf1Names <- unlist(hf1Names)
hf2Names <- hf2.all_tags
hf2Names <- strsplit(hf2Names, split = "_")
hf2Names <- lapply(hf2Names, "[[", 2)
hf2Names <- unlist(hf2Names)
names(hf1.all_tags) <- hf1Names
names(hf2.all_tags) <- hf2Names
#Functions for generating ggplots of tsne or pseudotime data. Functions for normal, contour, and clonal plots.
source(file = "R/tsne.plot.functions.R")
source(file = "R/plotBase.R")
source(file = "R/plotContour.R")
source(file = "R/subsetCloneData.R")
source(file = "R/generatePlot.R")
source(file = "R/plotCloneLayer.R")
source(file = "R/plotStackedBar.R")
source(file = "R/cloneVersion.R")
source(file = "R/addGeneExpr.R")
#This loads the data and meta data used for plotting.
celltagData <- read.table(file = dataPath, header = TRUE)
monocleExpr <- readRDS(file = monoclePath)
seuratExpr <- readRDS(file = seuratPath)
#monExpr <- read.table(file = monPath, header = TRUE)
colnames(celltagData)[c(21, 22)] <- c("tSNE_1", "tSNE_2")
selectChoices <- colnames(celltagData)[c(1:15)]
#geneChoiceMonocle <- rownames(monExpr)
celltagCols <- grep(pattern = "CellTag.D", x = colnames(celltagData), value = TRUE)
successfulD0 <- c(573, 2600, 2752, 2721, 3026)
successfulD3 <- c(329, 2024)
deadendD0 <- c(271, 487, 2352)
deadendD3 <- c(473, 488, 2388, 2396)
otherClonesD0 <- names(sort(table(celltagData$CellTag.D0), decreasing = TRUE))
otherClonesD0 <- otherClonesD0[!grepl(pattern = ".NA", x = otherClonesD0)]
otherClonesD0 <- otherClonesD0[!otherClonesD0 %in% successfulD0]
otherClonesD0 <- otherClonesD0[!otherClonesD0 %in% deadendD0]
cloneChoicesD0 <- list(Successful = successfulD0, DeadEnd = deadendD0, Others = otherClonesD0)
otherClonesD3 <- names(sort(table(celltagData$CellTag.D3), decreasing = TRUE))
otherClonesD3 <- otherClonesD3[!grepl(pattern = ".NA", x = otherClonesD3)]
otherClonesD3 <- otherClonesD3[!otherClonesD3 %in% successfulD3]
otherClonesD3 <- otherClonesD3[!otherClonesD3 %in% deadendD3]
cloneChoicesD3 <- list(Successful = successfulD3, DeadEnd = deadendD3, Others = otherClonesD3)
otherClonesD13 <- names(sort(table(celltagData$CellTag.D13), decreasing = TRUE))
otherClonesD13 <- otherClonesD13[!grepl(pattern = ".NA", x = otherClonesD13)]
cloneChoicesD13 <- list(Others = otherClonesD13)
celltagData$Cluster.Seurat <- as.factor(celltagData$Cluster.Seurat)
celltagData$State.Monocle <- as.factor(celltagData$State.Monocle)
celltagData$Timepoint <- factor(celltagData$Timepoint, levels = c("Day 0", "Day 3", "Day 6", "Day 9", "Day 12", "Day 15", "Day 21", "Day 28"))
celltagData$CellTag.Version <- as.character(celltagData$CellTag.Version)
cloneInput <- list()
geneChoice <- NULL
netTagD0 <- grep(x = all_tags, patter = "CellTag.D0", value = TRUE)
namesD0 <- strsplit(netTagD0, split = "_", fixed = TRUE)
namesD0 <- sapply(namesD0, "[[", 2)
names(netTagD0) <- namesD0
netTagD3 <- grep(x = all_tags, patter = "CellTag.D3", value = TRUE)
namesD3 <- strsplit(netTagD3, split = "_", fixed = TRUE)
namesD3 <- sapply(namesD3, "[[", 2)
names(netTagD3) <- namesD3
netTagD13 <- grep(x = all_tags, patter = "CellTag.D13", value = TRUE)
namesD13 <- strsplit(netTagD13, split = "_", fixed = TRUE)
namesD13 <- sapply(namesD13, "[[", 2)
names(netTagD13) <- namesD13
#networkVars <- colnames(Nodes)[c(1:2, 7, 9, 11, 12, 13, 14, 15, 16, 18, 19)]