-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyse_data.R
130 lines (102 loc) · 4.29 KB
/
analyse_data.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
library(tidyverse)
library(reshape2)
drugs_signatures <- unlist(strsplit(read_file("drugs_signature_ids"), split = "\n"))
prefix <- paste("results", "drugs", sep = "/")
filenames <- paste(paste(drugs_signatures, "Concordant", sep = "-"), "tsv", sep = ".")
files <- paste(prefix, filenames, sep = "/")
metadata <- read_csv("signature_data/id-name-cellline_mapping.csv",
col_types = cols(
SignatureId = col_character(),
Perturbagen = col_character(),
CellLine = col_character()
))
col_spec <- cols(
similarity = col_double(),
pValue = col_double(),
nGenes = col_double(),
treatment = col_character(),
perturbagenID = col_character(),
time = col_character(),
signatureid = col_character(),
cellline = col_character(),
Source_Signature = col_character()
)
dfs <- list()
for (i in 1:length(files)) {
df <- read_tsv(files[i], col_types = col_spec)
dfs[[i]] <- df
}
df <- reduce(dfs, bind_rows)
drugs <- c("Carbetocin", "Desmopressin", "Hydroxychloroquine", "Chloroquine",
"Bupropion", "Ritonavit", "Lopinavir", "Benazepril", "Captopril", "Enalapril",
"Fosinopril", "Lisinopril", "Moexipril", "Olmesartan", "Perindopril", "Quinapril",
"Ramipril", "Telmisartan", "Valsartan")
complete <- inner_join(df, metadata, by = c("Source_Signature" = "SignatureId")) %>%
mutate(perturbagen = str_to_title(Perturbagen),
perturbagen = if_else(perturbagen == "Enalaprilat", "Enalapril", perturbagen),
perturbagen = if_else(perturbagen == "ENT-Benazepril", "Benazepril", perturbagen),
perturbagen = if_else(perturbagen == "Olmesartan Medoxomil", "Olmesartan", perturbagen)) %>%
filter(perturbagen %in% drugs)
filter_data <- function(data) {
dataframe <- data
output <- dataframe %>%
group_by(treatment, perturbagen) %>%
filter(abs(similarity) == max(abs(similarity))) %>%
ungroup() %>%
select(signatureid, treatment, perturbagen, similarity, pValue, cellline)
return(output)
}
write_csv(complete,
paste("results", paste(paste("complete", "result", sep = "-"), "csv", sep = "."), sep = "/"))
analysed <- filter_data(complete)
#cell_lines <- c("A375", "HA1E", "MCF7", "PC3")
for (cell in unique(analysed$cellline)) {
outfile <- paste("results", paste(paste(cell, "result", sep = "-"), "csv", sep = "."), sep = "/")
analysed %>%
filter(cellline == cell) %>%
select(perturbagen, treatment, cellline, similarity) %>%
write_csv(outfile)
}
result_files <- list.files("results/", pattern = "result")
all_results <- analysed %>%
select(perturbagen, treatment, cellline, similarity)
write_csv(all_results, "results/all_results.csv")
all_averaged <- all_results %>%
group_by(perturbagen, treatment) %>%
summarise(mean_similarity = mean(similarity))
write_csv(all_averaged, "results/all_averaged.csv")
process_gene <- function(dataset, gene) {
g <- dataset %>%
filter(treatment == gene) %>%
ungroup() %>%
select(-treatment) %>%
arrange(cellline, similarity)
gcross <- g %>%
dcast(cellline ~ perturbagen)
prefix <- "results/"
file <- paste(gene, "csv", sep = ".")
crossfile <- paste(paste(gene, "crosstab", sep = "-"), "csv", sep = ".")
write_csv(g, paste(prefix, file, sep = "/"))
write_csv(gcross, paste(prefix, crossfile, sep = "/"))
invisible(list(g, gcross))
}
process_gene(all_results, "TNF") # Selected and subset to HA1E
process_gene(all_results, "TLR7") # Selecting HA1E
process_gene(all_results, "TLR9") # Selecting HA1E
process_gene(all_results, "ARG1") # Selecting HA1E
process_gene(all_results, "CD40") # Does not have Carbetocin in result
process_gene(all_results, "CD46") # Does not have a direct comparison with Carbetocin
process_gene(all_results, "CD83") # Selecting HA1E
process_gene(all_results, "CD44") # Does not have a direct comparison with Carbetocin
process_gene(all_results, "AGT")
process_gene(all_results, "AGTR1")
process_gene(all_results, "CTLA4")
process_gene(all_results, "IL6R")
process_gene(all_results, "NFKB1")
#process_gene(all_results, "ACE")
carbetocin <- all_results %>%
filter(perturbagen == "Carbetocin") %>%
ungroup() %>%
select(-perturbagen, -cellline) %>%
arrange(similarity)
write_csv(carbetocin, "results/carbetocin.csv")