-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathvalidation.R
executable file
·85 lines (70 loc) · 2.23 KB
/
validation.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
check_columns_exist = function(.data, columns){
if((!columns %in% (.data %>% colnames)) %>% any)
stop(
sprintf(
"The columns %s are not present in your tibble",
paste(columns[(!columns %in% (.data %>% colnames))], collapse=" ")
)
)
}
check_if_count_integer = function(.data, .count){
.count = enquo(.count)
# Check if the counts column is an integer
if (!.data %>% pull(!!.count) %>% is("integer"))
stop(
sprintf(
"The column %s must be of class integer. You can do as mutate(`%s` = as.integer(`%s`))",
quo_name(.count),
quo_name(.count),
quo_name(.count)
)
)
}
#' Check if NA
#'
#' @importFrom tidyr drop_na
#' @importFrom dplyr enquo
#'
#' @param .data A tibble including a gene name column | sample name column | read counts column | factors column
#' @param columns Columns to check
#'
#' @keywords internal
#' @noRd
check_if_any_NA = function(.data, columns){
if(
.data %>%
drop_na(all_of(columns)) %>%
nrow %>% st( .data %>% nrow )
)
stop(sprintf("There are NA values in you tibble for any of the column %s", paste(columns, collapse=", ")))
}
check_if_within_posterior = function(.data, my_df, .do_check, .count){
# Define the variables as NULL to avoid CRAN NOTES
.lower <- NULL
.upper <- NULL
ppc <- NULL
writeLines(sprintf("executing %s", "check_if_within_posterior"))
.data %>%
left_join(my_df, by = c("S", "G")) %>%
filter((!!.do_check)) %>% # Filter only DE genes
rowwise() %>%
mutate(`ppc` = !!.count %>% between(`.lower`, `.upper`)) %>%
mutate(`is higher than mean` = (!`ppc`) &
(!!.count > mean)) %>%
ungroup
}
check_if_columns_right_class = function(.data, .sample, .cell_group){
.sample = enquo(.sample)
.cell_group = enquo(.cell_group)
# Check that sample and cell_type is chr of factor
if(
!(
.data %>% pull(!!.sample) %>% is("character") |
.data %>% pull(!!.sample) %>% is("factor")
) |
!(
.data %>% pull(!!.cell_group) %>% is("character") |
.data %>% pull(!!.cell_group) %>% is("factor")
)
) stop(sprintf("sccomp says: the columns %s and %s must be of class character or factor", quo_name(.sample), quo_name(.cell_group)))
}