-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs.R
48 lines (31 loc) · 991 Bytes
/
funcs.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
plot_distribution <- function(cur_stat) {
ggplot(df, aes(x = eval(parse(text = cur_stat)))) +
geom_histogram(bins = 40) +
labs(x = cur_stat,
y = "Count") +
theme_bw()
}
snv_dist <- function(arg1, arg2) {
return(sum(abs(arg1 - arg2)) / length(arg1))
}
freq_mapper <- function(cur_pos) {
freq_array <- cur_pos %>%
select(contains(paste0("Freq", cur_pos$con_base))) %>%
as.vector() %>%
as.numeric()
return(freq_array)
}
max_mapper <- function(cur_pos, pattern) {
max_val <- cur_pos %>%
select(contains(paste(pattern, cur_pos$AbundMaxIdx, sep = "_"))) %>%
as.vector() %>%
as.numeric()
return(max_val)
}
sample_loader <- function(sample_name, gen_list = "", method = read_csv) {
sample_df <- method(sample_name) %>%
mutate(sample = as.numeric(gsub(".tsv", "", gsub("data/gene_info", "", sample_name)))) %>%
left_join(mapping) %>%
filter(AbundMaxIdx == sample)
return(sample_df)
}