Skip to content

Commit

Permalink
fixes related to nr_children column
Browse files Browse the repository at this point in the history
  • Loading branch information
wolski committed Apr 12, 2024
1 parent b43c6ef commit bd9a4cb
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 37 deletions.
15 changes: 2 additions & 13 deletions R/AnalysisConfiguration.R
Original file line number Diff line number Diff line change
Expand Up @@ -397,35 +397,24 @@ hierarchy_counts <- function(pdata, config){
#' config <- bb$config
#' data <- bb$data
#' res <- hierarchy_counts_sample(data, config, nr_children = 1)
#' res()
#' x <- res("long")
#' res("plot")
#' # filters on peptide level
#' res <- hierarchy_counts_sample(data, config, nr_children = 2)
#' res()
#' x2 <- res("long")
#' res("plot")
#' # filters on protein level based on peptide count
#' bb <- prolfqua::sim_lfq_data_protein_config()
#' res <- hierarchy_counts_sample(bb$data, bb$config, nr_children = 2)
#' x1 <- res()
#' res("long")
#' res("plot")
#' res <- hierarchy_counts_sample(bb$data, bb$config, nr_children = 1)
#' x2 <- res()
#' res("long")
#' res("plot")
#' x1$nr_children <- 2
#' x2$nr_children <- 1
#' xl <- dplyr::bind_rows(x1, x2)
#'
#'
#'
#'
#' xl$nr_children |> table()
#' nudgeval <- -mean(xl$protein_Id) * 0.05
#' ggplot(xl, aes(x = sampleName, y = protein_Id, fill = as.character(nr_children)) ) +
#' geom_bar(stat = "identity", position = position_dodge())
#' ggplot2::ggplot(xl, ggplot2::aes(x = sampleName, y = protein_Id, fill = as.character(nr_children)) ) +
#' ggplot2::geom_bar(stat = "identity", position = ggplot2::position_dodge())
#'
hierarchy_counts_sample <- function(
pdata,
Expand Down
3 changes: 2 additions & 1 deletion R/ContrastsPlotter.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ContrastsPlotter <- R6::R6Class(
fcthresh = 1,
#' @field avg.abundance name of column containing avg abundance values.
avg.abundance = character(),
#' @field avg.abundance name of column containing avg abundance values.
#' @field protein_annot protein annotation
protein_annot = NULL,
#' @description
#' create Crontrast_Plotter
Expand All @@ -90,6 +90,7 @@ ContrastsPlotter <- R6::R6Class(
#' @param diff fold change (difference) diff column
#' @param contrast contrast column
#' @param avg.abundance name of column with average abundance
#' @param protein_annot add protein annotation (optional)
initialize = function(contrastDF,
subject_Id,
volcano = list(list(score = "FDR", thresh = 0.1)),
Expand Down
16 changes: 12 additions & 4 deletions R/ProteinAnnotation.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,39 @@ ProteinAnnotation <-
pID = character(),
#' @field description name of column containing descriptions
description = "description",
#' @field ids vector with columns containing addition IDs
ids = character(),
#' @field cleaned_ids vector with columns containing addition IDs
cleaned_ids = character(),
#' @field nr_children name of columns with the number of peptides
nr_children = character(),
#' @description initialize
#' @param lfqdata data frame from \code{\link{setup_analysis}}
#' @param row_annot data frame with row annotation. Must have columns matching \code{config$table$hierarchy_keys_depth()}
#' @param description name of column with description
#' @param ids names of columns with additional ID's
#' @param ids names of columns with cleaned Ids
#' @param nr_peptides additional peptides
#' @param nr_children column with the number of children
initialize = function(lfqdata,
row_annot,
description = NULL,
ids = NULL,
nr_children = "nr_peptides"){
self$pID = lfqdata$config$table$hierarchy_keys_depth()[1]
self$nr_children = nr_children
if (!missing(row_annot)) {
if ( !is.null(ids)) {self$cleaned_ids = ids} else {self$cleaned_ids = self$pID}
if ( !is.null(description)) {self$description = description} else {self$description = self$pID}
if ( !missing(row_annot)) {
stopifnot(self$pID %in% colnames(row_annot))
row_annot <- dplyr::filter(row_annot, !!sym(self$pID) %in% lfqdata$data[[self$pID]] )
self$row_annot <- row_annot
} else {
self$row_annot <- distinct(select(lfqdata$data, self$pID))
}

stopifnot(self$cleaned_ids %in% colnames(self$row_annot))
stopifnot(self$description %in% colnames(self$row_annot))

if (!self$nr_children %in% colnames(row_annot) ) {
warning("no nr_children column specified, computing using nr_obs_experiment function")
self$row_annot <- inner_join(
self$row_annot,
nr_obs_experiment(lfqdata$data, lfqdata$config, name_nr_child = self$nr_children),
Expand Down
2 changes: 1 addition & 1 deletion R/tidyMS_R6_TransitionCorrelations.R
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ nr_B_in_A <- function(pdata, config , merge = TRUE){
#' @keywords internal
#' @family summary
#' @examples
#' debug(nr_B_in_A_per_sample)
#'
#' bb <- prolfqua::sim_lfq_data_peptide_config()
#' nr_B_in_A_per_sample(bb$data, bb$config, nested =FALSE)
#' bb <- prolfqua::sim_lfq_data_protein_config()
Expand Down
2 changes: 1 addition & 1 deletion R/tidyMS_aggregation.R
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ aggregate_intensity_topN <- function(pdata , config, .func, N = 3){
workIntensity = newcol,
hierarchy = config$table$hierarchy[seq_len(config$table$hierarchyDepth)])

new_child_name <- paste0("nr_", config$table$hierarchy_keys_depth() )
new_child_name <- paste(c("nr", config$table$hierarchy_keys_depth()), collapse = "_" )
res_nr_children <- nr_obs_sample(pdata, config, new_child = new_child_name)
sumTopInt <- inner_join(
sumTopInt, res_nr_children,
Expand Down
4 changes: 3 additions & 1 deletion man/ContrastsPlotter.Rd

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

6 changes: 4 additions & 2 deletions man/ProteinAnnotation.Rd

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

15 changes: 2 additions & 13 deletions man/hierarchy_counts_sample.Rd

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

2 changes: 1 addition & 1 deletion man/nr_B_in_A_per_sample.Rd

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

0 comments on commit bd9a4cb

Please sign in to comment.