-
Notifications
You must be signed in to change notification settings - Fork 0
/
doEquitabilityAnalysis.R
175 lines (140 loc) · 4.95 KB
/
doEquitabilityAnalysis.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
#!/usr/bin/Rscript --vanilla
# Aim:
# Add equitability calculations, plot data.
# Usage:
# Rscript doEquitabilityAnalysis.R
library(tidyverse)
source("./R/functions.R")
# inputs
meta_path <- "./zebrafish/meta/samples_zf_RNAseq_Mariana.xlsx"
sheet_name <- "main_editCP_missing_sample"
results_path <- "./zebrafish/results/"
sample_name_column_in_meta <- "sample_name"
sample_name_column_in_data <- "sample"
arrangement_type <- "productive"
receptor_type <- "TRB"
file <- paste0(results_path, "/clonotypes_raw_wMeta_wRatios.TRB.productive.tsv")
outfilename <- "clonotypes_raw_wMeta_wRatios.TRB.productive."
clonotypes <- data.table::fread(file)
# Optional: add extra column with custum names to metadata
metadata <- readxl::read_xlsx(path = meta_path, sheet = sheet_name) %>%
distinct()
# =================================================================================================
# Add equitability for a particular receptor:
# =================================================================================================
clonotypes_w_equitability <- clonotypes %>%
addEquitabilityPerSample(
receptor_column = "allVHitsWithScore",
receptor_type = "TRB",
sample_column = "sample",
outdir = results_path
)
#clonotypes_w_equitability %>% View()
# Equitability per sample per receptor type
receptorType_equitability <- clonotypes_w_equitability %>%
select(equitability_per_sample, sample) %>%
distinct()
# export TR dataframe w/ equitability
clonotypes_w_equitability %>% #View()
write_delim(
paste0(results_path, "/", outfilename, "w_equitability.tsv"),
delim = "\t"
)
# =================================================================================================
# Plot the clonotypes and the equitability, independently:
# =================================================================================================
arrangement_type <- "productive"
# 1.1 plot number of unique clonotypes
# 1.1.2 Filter (in) the MYC samples:
# 1.1.2.1 vertical
receptorType_equitability %>%
filter(str_detect(`sample`, "Myc")) %>%
plotBoxplotDotJitter(
y_max_lim = 1,
grouping = "Manuscript notation",
ymeasurement = "equitability_per_sample",
ylab = paste0("Equitability(",receptor_type,")"),
outname = "TransientLines",
# receptor_type = receptor_type#,
#subDir = arrangement_type,
#outdir = results_path,
#meta_path = meta_path,
#sheet_name = sheet_name
)
# 1.1.2.2 horizontal
receptorType_equitability %>%
filter(str_detect(`sample`, "Myc")) %>%
plotBoxplotDotJitterHz(
y_max_lim = 1,
grouping = "Manuscript notation",
ymeasurement = "equitability_per_sample",
ylab = paste0("Equitability(",receptor_type,")"),
outname = "TransientLines",
subDir = arrangement_type,
outdir = results_path,
meta_path = meta_path,
sheet_name = sheet_name
)
# 1.1.3 Filter (in) the WKM_vs_stable
receptorType_equitability %>%
filter(!str_detect(`sample`, "Myc")) %>%
filter(!str_detect(`sample`, "Thy")) %>%
filter(!str_detect(`sample`, "WKM-CG1-P2mut")) %>%
plotBoxplotDotJitter(
y_max_lim = 1,
grouping = "Manuscript notation",
ymeasurement = "equitability_per_sample",
outname = "WKM_vs_stable",
ylab = paste0("Equitability(",receptor_type,")"),
subDir = "productive",
outdir = results_path,
meta_path = meta_path,
sheet_name = sheet_name
)
receptorType_equitability %>%
filter(!str_detect(`sample`, "Myc")) %>%
filter(!str_detect(`sample`, "Thy")) %>%
filter(!str_detect(`sample`, "WKM-CG1-P2mut")) %>%
plotBoxplotDotJitterHz(
y_max_lim = 1,
grouping = "Manuscript notation",
ymeasurement = "equitability_per_sample",
outname = "WKM_vs_stable",
ylab = paste0("Equitability(",receptor_type,")"),
subDir = "productive",
outdir = results_path,
meta_path = meta_path,
sheet_name = sheet_name
)
# 1.1.4 Filter (in) the Thy_vs_mut
receptorType_equitability %>%
filter(!str_detect(`sample`, "Myc")) %>%
filter(!str_detect(`sample`, "WKM-CG1")) %>%
filter(!str_detect(`sample`, "WKM-CG1-P2mut")) %>% #View()
plotBoxplotDotJitter(
y_max_lim = 1,
grouping = "Manuscript notation",
ymeasurement = "equitability_per_sample",
outname = "Thy_vs_mut",
ylab = paste0("Equitability(",receptor_type,")"),
subDir = "productive",
outdir = results_path,
meta_path = meta_path,
sheet_name = sheet_name
)
receptorType_equitability %>%
filter(!str_detect(`sample`, "Myc")) %>%
filter(!str_detect(`sample`, "WKM-CG1")) %>%
filter(!str_detect(`sample`, "WKM-CG1-P2mut")) %>% #View()
plotBoxplotDotJitterHz(
y_max_lim = 1,
grouping = "Manuscript notation",
ymeasurement = "equitability_per_sample",
outname = "Thy_vs_mut",
ylab = paste0("Equitability(",receptor_type,")"),
subDir = "productive",
outdir = results_path,
meta_path = meta_path,
sheet_name = sheet_name
)
# Add productive / non-productive ratio