Skip to content

Commit

Permalink
adding nr_children to LFQData and LFQDataAggregator
Browse files Browse the repository at this point in the history
  • Loading branch information
wolski committed Apr 5, 2024
1 parent 7a7dfb3 commit e0145fa
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 47 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: prolfqua
Type: Package
Title: Proteomics Label Free Quantification
Version: 1.2.1
Version: 1.2.2
Authors@R: c(person("Witold", "Wolski",
email = c("[email protected]", "[email protected]"),
role = c("aut", "cre"),
Expand Down
25 changes: 12 additions & 13 deletions R/ContrastsProDA.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@
#' @family modelling
#' @examples
#'
#' istar <- prolfqua_data('data_ionstar')$normalized()
#' istar$config <- old2new(istar$config )
#' istar_data <- dplyr::filter(istar$data ,protein_Id %in% sample(protein_Id, 10))
#' istar <- prolfqua::sim_lfq_data_peptide_config()
#' istar$config <- istar$config
#' istar_data <- istar$data
#' lfd <- LFQData$new(istar_data, istar$config)
#' #debug(prolfqua::LFQDataToSummarizedExperiment)
#' se <- prolfqua::LFQDataToSummarizedExperiment(lfd)
#'
#' fit <- proDA::proDA(se, design = ~ dilution. - 1,data_is_log_transformed = TRUE)
#' fit <- proDA::proDA(se, design = ~ group_ - 1, data_is_log_transformed = TRUE)
#' contr <- list()
#'
#' contrasts <- c("dilution_(9/7.5)_1.2" = "dilution.e - dilution.d",
#' "dilution_(7.5/6)_1.25" = "dilution.d - dilution.c")
#' contr[["dilution_(9/7.5)_1.2"]] <- data.frame(
#' contrast = "dilution_(9/7.5)_1.2",
#' proDA::test_diff(fit, contrast = "dilution.e - dilution.d"))
#' contr[["dilution_(7.5/6)_1.25"]] <- data.frame(
#' contrast = "dilution_(7.5/6)_1.25",
#' proDA::test_diff(fit, contrast = "dilution.d - dilution.c"))
#' contrasts <- c("group_AvsCtrl" = "group_A - group_Ctrl",
#' "group_BvsCtrl" = "group_B - group_Ctrl")
#' contr[["group_AvsCtrl"]] <- data.frame(
#' contrast = "group_AvsCtrl",
#' proDA::test_diff(fit, contrast = "group_A - group_Ctrl"))
#' contr[["group_BvsCtrl"]] <- data.frame(
#' contrast = "group_BvsCtrl",
#' proDA::test_diff(fit, contrast = "group_B - group_Ctrl"))
#'
#' bb <- dplyr::bind_rows(contr)
#' cproDA <- ContrastsProDA$new(bb, contrasts = contrasts, subject_Id = "name")
Expand Down
30 changes: 20 additions & 10 deletions R/LFQData.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,18 @@ LFQData <- R6::R6Class(
#' @description
#' converts the data to wide
#' @param as.matrix return as data.frame or matrix
#' @param value either response or nr chidren
#' @return list with data, annotation, and configuration
to_wide = function(as.matrix = FALSE){
wide <- prolfqua::tidy_to_wide_config(self$data, self$config, as.matrix = as.matrix)
to_wide = function(as.matrix = FALSE, value = c("response", "nr_children")){
value <- match.arg(value)
if (value == "response") {
wide <- prolfqua::tidy_to_wide_config(self$data, self$config, as.matrix = as.matrix)
} else {
wide <- prolfqua::tidy_to_wide_config(
self$data, self$config,
as.matrix = as.matrix,
value = self$config$table$nr_children)
}
wide$config <- self$config$clone(deep = TRUE)
return(wide)
},
Expand Down Expand Up @@ -275,9 +284,6 @@ LFQData <- R6::R6Class(
)





#' converts LFQData object to SummarizedExperiment
#'
#' For compatibility with Bioconductor
Expand All @@ -287,9 +293,9 @@ LFQData <- R6::R6Class(
#' @export
#' @examples
#'
#' istar <- prolfqua_data('data_ionstar')
#' istar$config <- old2new(istar$config)
#' data <- istar$data |> dplyr::filter(protein_Id %in% sample(protein_Id, 100))
#' istar <- prolfqua::sim_lfq_data_peptide_config()
#' istar$config <- (istar$config)
#' data <- istar$data
#' lfqdata <- LFQData$new(data, istar$config)
#' lfqdata$to_wide()
#' if(require("SummarizedExperiment")){
Expand All @@ -299,10 +305,14 @@ LFQData <- R6::R6Class(
LFQDataToSummarizedExperiment <- function(lfqdata){
if (requireNamespace("SummarizedExperiment")) {
wide <- lfqdata$to_wide(as.matrix = TRUE)
nr_children <- lfqdata$to_wide(as.matrix = TRUE, value = "nr_children")
ann <- data.frame(wide$annotation)
rownames(ann) <- wide$annotation[[lfqdata$config$table$sampleName]]
se <- SummarizedExperiment::SummarizedExperiment(S4Vectors::SimpleList(LFQ = wide$data), colData = ann,
rowData = wide$rowdata)
se <- SummarizedExperiment::SummarizedExperiment(S4Vectors::SimpleList(
LFQ = wide$data,
nr_children = nr_children$data),
colData = ann,
rowData = wide$rowdata)
return(se)
}
}
8 changes: 5 additions & 3 deletions R/tidyMS_R6_TransitionCorrelations.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ tidy_to_wide <- function(data,
#' testthat::expect_equal(nrow(res$rowdata), nrow(res$data))
#' testthat::expect_equal(ncol(res$data) - ncol(res$rowdata) , nrow(res$annotation))
#' res <- tidy_to_wide_config(data, config, as.matrix = TRUE)
#' dim(res$data) == c(28, 12)
#' dim(res$annotation) == c(12, 3)
#' dim(res$rowdata) == c(28, 3)
#' stopifnot(all(dim(res$data) == c(28, 12))
#' stopifnot(all(dim(res$annotation) == c(12, 4)))
#' stopifnot(all(dim(res$rowdata) == c(28, 3)))
#'
#' res <- scale(res$data)
#' tidy_to_wide_config(data, config, value = config$table$nr_children)
Expand All @@ -239,6 +239,8 @@ tidy_to_wide <- function(data,
#' #xt$config$table$is_response_transformed <- TRUE
#' res <- xt$get_Aggregator()
#' x <- res$medpolish()
#' towide <- tidy_to_wide_config(x$data, x$config, value = x$config$table$nr_children)
#'
#' dd <- prolfqua::sim_lfq_data_protein_config()
#' dd$config$table$nr_children
#' dd$data
Expand Down
25 changes: 12 additions & 13 deletions man/ContrastsProDA.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/LFQData.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/LFQDataToSummarizedExperiment.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions man/tidy_to_wide_config.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e0145fa

Please sign in to comment.