-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.R
127 lines (115 loc) · 5.83 KB
/
helpers.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
# Define functions
create_summary_calculations_table <- function(sample, save_path) {
summary_calculations <- data.table::fread(paste0(save_path, "/", sample, "/summary-calculations_", sample, ".txt"), header = TRUE, sep = "\t", stringsAsFactors = FALSE)
return(summary_calculations)
}
create_extra_mutations_calculations_table <- function(sample, save_path) {
if(file.exists(paste0(save_path, "/", sample, "/extra_mutations_calculations_", sample, ".txt"))){
extra_mutations_calculations <- data.table::fread(paste0(save_path, "/", sample, "/extra_mutations_calculations_", sample, ".txt"), header = TRUE, sep = "\t", stringsAsFactors = FALSE)
return(extra_mutations_calculations)
}else{
return()
}
}
create_less_mutations_calculations_table <- function(sample, save_path) {
if(file.exists(paste0(save_path, "/", sample, "/less_muts_calculations_", sample, ".txt"))){
less_mutations_calculations <- data.table::fread(paste0(save_path, "/", sample, "/less_muts_calculations_", sample, ".txt"), header = TRUE, sep = "\t", stringsAsFactors = FALSE)
return(less_mutations_calculations)
}else{
return()
}
}
create_mutations_table <- function(sample, min_reads, save_path) {
if(file.exists(paste0(save_path, "/", sample, "/evolution-file-", sample, "_threshold", min_reads, ".txt"))){
mutations <- data.table::fread(paste0(save_path, "/", sample, "/evolution-file-", sample, "_threshold", min_reads, ".txt"), header = TRUE, sep = "\t", stringsAsFactors = FALSE)
return(mutations)
}else{
return()
}
}
create_aa_mutations_main_var_table <- function(sample, save_path) {
if(file.exists(paste0(save_path, "/", sample, "/aa_muts_weight_main_variant_", sample, ".txt"))){
aa_mutations_main_var <- data.table::fread(paste0(save_path, "/", sample, "/aa_muts_weight_main_variant_", sample, ".txt"), header = TRUE, sep = "\t", stringsAsFactors = FALSE)
return(aa_mutations_main_var)
}else{
return()
}
}
create_aa_mutations_table <- function(sample, save_path) {
if(file.exists(paste0(save_path, "/", sample, "/aa_muts_weight_", sample, ".txt"))){
aa_mutations <- data.table::fread(paste0(save_path, "/", sample, "/aa_muts_weight_", sample, ".txt"), header = TRUE, sep = "\t", stringsAsFactors = FALSE)
return(aa_mutations)
}else{
return()
}
}
create_graph_metrics_table <- function(sample, include_metrics, save_path) {
if(file.exists(paste0(save_path, "/", sample, "/graph_info_", sample, ".txt"))){
graph_metrics <- data.table::fread(paste0(save_path, "/", sample, "/graph_info_", sample, ".txt"), header = TRUE, sep = "\t", stringsAsFactors = FALSE)
metrics <- unlist(strsplit(include_metrics, ","))
if (!("Main variant identity" %in% metrics)) {
graph_metrics <- graph_metrics %>% select(-main_nt_var_identity)
}
if (!("Relative convergence (reads)" %in% metrics)) {
graph_metrics <- graph_metrics %>% select(-convergence_score, -nb_reads_most_relevant_pathway, -nb_reads_main_nt_var)
}
if (!("Most relevant pathway score" %in% metrics)) {
graph_metrics <- graph_metrics %>% select(-most_relevant_pathway_score)
}
if (!("Most relevant pathway (nodes)" %in% metrics)) {
graph_metrics <- graph_metrics %>% select(-nb_nodes_most_relevant_pathway)
}
if (!("End nodes density" %in% metrics)) {
graph_metrics <- graph_metrics %>% select(-end_nodes_density, -nb_end_nodes, -nb_extra_nodes)
}
if (!("Max path length" %in% metrics)) {
graph_metrics <- graph_metrics %>% select(-max_path_length)
}
if (!("Max mutations path length" %in% metrics)) {
graph_metrics <- graph_metrics %>% select(-max_muts_length)
}
if (!("Total reads" %in% metrics)) {
graph_metrics <- graph_metrics %>% select(-nb_reads_tot)
}
if (!("Average degree" %in% metrics)) {
graph_metrics <- graph_metrics %>% select(-avg_degree)
}
if (!("Average distance" %in% metrics)) {
graph_metrics <- graph_metrics %>% select(-avg_distance)
}
return(graph_metrics)
}else{
return()
}
}
create_graph_network <- function(sample, save_path) {
if(file.exists(paste0(save_path, "/", sample, "/", sample, "_ID.pdf"))){
pdf_convert(paste0(save_path, "/", sample, "/", sample, "_ID.pdf"), format = "png", filenames = paste0(save_path, "/", sample, "/", sample, "_ID.png"), dpi = 300)
list(src = paste0(save_path, "/", sample, "/", sample, "_ID.png"), width = 800, height = 800)
}else{
return()
}
}
choose_comparison_metrics <- function(compare_metrics) {
comparison_metrics <- c("convergence_score", "end_nodes_density", "max_path_length", "max_muts_length", "avg_degree", "avg_distance")
metrics <- unlist(strsplit(compare_metrics, ","))
if (!("Convergence score" %in% metrics)) {
comparison_metrics <- comparison_metrics[!comparison_metrics %in% "convergence_score"]
}
if (!("End nodes density" %in% metrics)) {
comparison_metrics <- comparison_metrics[!comparison_metrics %in% "end_nodes_density"]
}
if (!("Max path length" %in% metrics)) {
comparison_metrics <- comparison_metrics[!comparison_metrics %in% "max_path_length"]
}
if (!("Max mutations length" %in% metrics)) {
comparison_metrics <- comparison_metrics[!comparison_metrics %in% "max_muts_length"]
}
if (!("Average degree" %in% metrics)) {
comparison_metrics <- comparison_metrics[!comparison_metrics %in% "avg_degree"]
}
if (!("Average distance" %in% metrics)) {
comparison_metrics <- comparison_metrics[!comparison_metrics %in% "avg_distance"]
}
return(comparison_metrics)
}