-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from ricoderks/dev
Dev
- Loading branch information
Showing
5 changed files
with
146 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Package: lipidomics | ||
Type: Package | ||
Title: Lipidomics workflow | ||
Version: 0.6.0 | ||
Version: 0.6.1 | ||
Author: Rico Derks | ||
Maintainer: Rico Derks <[email protected]> | ||
Description: Lipidomics workflow to proces the result files (export alignment) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#' @title Do a statitical test | ||
#' | ||
#' @description Do a statitical test, t-test or Mann-Whitney U test | ||
#' | ||
#' @param lipid_data tibble in tidy format | ||
#' @param group what column contains the group info | ||
#' @param group1_name is the name of group 1 | ||
#' @param group2_name is the name of group 2 | ||
#' @param normalization what normalization to use, none (raw data) or total area normalization | ||
#' @param transformation what transformation to use | ||
#' @param test do a t-test or Mann-Whitney U test | ||
#' | ||
#' @return a tibble ready for statistical testing | ||
#' | ||
#' @import tidyselect | ||
#' @importFrom dplyr select filter mutate rename group_by ungroup | ||
#' @importFrom tidyr pivot_wider everything nest | ||
#' @importFrom purrr map_dbl | ||
#' @importFrom magrittr %>% | ||
#' @importFrom rlang .data | ||
#' | ||
#' @author Rico Derks | ||
#' | ||
do_stat_test <- function(lipid_data, group, group1_name, group2_name, normalization = c("raw", "tot_area"), transformation = c("none", "log10"), | ||
test) { | ||
|
||
if(group1_name != "none" & | ||
group2_name != "none" & | ||
group1_name != group2_name) { | ||
prep_test_data <- lipid_data %>% | ||
filter(.data$keep == TRUE) %>% | ||
rename(my_group_info = !!sym(group)) %>% | ||
filter(.data$my_group_info == group1_name | | ||
.data$my_group_info == group2_name) %>% | ||
select(.data$my_id, .data$ShortLipidName, .data$LipidClass, .data$sample_name, .data$my_group_info, .data$area) %>% | ||
# total area normalisation | ||
group_by(.data$sample_name) %>% | ||
mutate(norm_area = .data$area / sum(.data$area)) %>% | ||
ungroup() %>% | ||
# select which normalization to use for PCA | ||
mutate(value = case_when( | ||
normalization == "raw" ~ .data$area, | ||
normalization == "tot_area" ~ .data$norm_area | ||
)) %>% | ||
# do transformations and select which transformation to keep | ||
mutate(value = case_when( | ||
transformation == "none" ~ .data$value, | ||
transformation == "log10" ~ log10(.data$value + 1) # the +1 is correct for any zero's | ||
)) %>% | ||
# remove the 2 area columns | ||
select(-.data$area, -.data$norm_area) %>% | ||
nest(test_data = c(.data$sample_name, .data$my_group_info, .data$value)) %>% | ||
mutate(fc = map_dbl(.x = .data$test_data, | ||
.f = ~ mean(.x$value[.x$my_group_info == group1_name]) / mean(.x$value[.x$my_group_info == group2_name])), | ||
fc_log2 = log2(.data$fc)) | ||
|
||
result <- switch(test, | ||
"ttest" = do_ttest(lipid_data = prep_test_data), | ||
"mwtest" = do_mwtest(lipid_data = prep_test_data)) | ||
} else { | ||
result <- NULL | ||
} | ||
|
||
return(result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.