Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/nilsmechtel/MetAlyzer into …
Browse files Browse the repository at this point in the history
…new_changes
  • Loading branch information
luisherfurth committed Jan 23, 2024
2 parents 279cc32 + e3fea0d commit c556c76
Show file tree
Hide file tree
Showing 37 changed files with 1,758 additions and 511 deletions.
11 changes: 2 additions & 9 deletions .Rbuildignore
Expand Up @@ -7,17 +7,10 @@
^\.\.Rcheck.*
^LICENSE$
^cran-comments\.md$
.*_cache$

^tests/.*

^vignettes/.*

^R/calculate_anova\.R$
^R/calculate_cv\.R$

^R/add_filter\.R$
^R/do_anova_2w\.R$
^R/filter_groupwise\.R$
^R/perform_anova\.R$
^R/plot_2w_anvova\.R$
^R/two_way_anova\.R$
^R/two_way_anova\.R$
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,3 +6,4 @@
*.code-workspace
.Rproj.user
..Rcheck
*_cache
18 changes: 10 additions & 8 deletions DESCRIPTION
Expand Up @@ -23,21 +23,23 @@ Authors@R:
comment = c(ORCID = "0000-0002-6041-7049")))
Depends:
R (>= 4.0.0)
biocViews:
Imports:
SummarizedExperiment,
openxlsx,
stringr,
dplyr,
tidyr,
stringr,
utils,
rlang,
tibble,
agricolae,
ggplot2,
ggrepel,
SummarizedExperiment,
S4Vectors,
BiocManager,
qvalue,
utils,
rlang,
methods,
data.table
data.table,
S4Vectors,
qvalue
Description: The 'MetAlyzer' S4 object provides methods to read and reformat metabolomics data for convenient data handling, statistics and downstream analysis. The resulting format corresponds to input data of the Shiny app 'MetaboExtract' (<https://www.metaboextract.shiny.dkfz.de/MetaboExtract/>).
License: GPL-3
Encoding: UTF-8
Expand Down
10 changes: 6 additions & 4 deletions NAMESPACE
Expand Up @@ -2,14 +2,16 @@

export(MetAlyzer_dataset)
export(aggregatedData)
export(calculate_anova)
export(calculate_cv)
export(calculate_log2FC)
export(example_extraction_data)
export(example_meta_data)
export(example_mutation_data_xl)
export(example_treatment_data)
export(exportConcValues)
export(filterMetaData)
export(filterMetabolites)
export(log2FC)
export(metalyzer_colors)
export(pathway)
export(plot_log2FC)
Expand All @@ -24,8 +26,8 @@ import(dplyr)
import(ggplot2)
import(ggrepel)
importFrom(data.table,":=")
importFrom(methods,is)
importFrom(rlang,.data)
importFrom(stats,aov)
importFrom(stats,lm)
importFrom(utils,install.packages)
importFrom(utils,installed.packages)
importFrom(tibble,deframe)
importFrom(tibble,rownames_to_column)
43 changes: 22 additions & 21 deletions R/MetAlyzer_dataset.R
Expand Up @@ -101,9 +101,9 @@ MetAlyzer_dataset <- function(
return(se)
}

#' MetAlyzer logo
#' @title MetAlyzer logo
#'
#' This function prints "MetAlyzer" as an ASCII logo
#' @description This function prints "MetAlyzer" as an ASCII logo
#'
#' @keywords internal
metalyzer_ascii_logo <- function() {
Expand Down Expand Up @@ -144,9 +144,9 @@ metalyzer_ascii_logo <- function() {
}


#' Open Excel file
#' @title Open Excel file
#'
#' This function opens the given MetIDQ output Excel file and reads the full
#' @description This function opens the given MetIDQ output Excel file and reads the full
#' given sheet.
#'
#' @param starter_list contains the file path and the sheet index
Expand All @@ -165,9 +165,9 @@ open_file <- function(starter_list) {
}


#' Get data range
#' @title Get data range
#'
#' This function extracts rows and column indices to slice the .full_sheet into
#' @description This function extracts rows and column indices to slice the .full_sheet into
#' metabolites, conc_values and meta_data.
#'
#' @param full_sheet full_sheet
Expand Down Expand Up @@ -208,10 +208,10 @@ get_data_range <- function(full_sheet) {
}


#' Slice metabolites
#' @title Slice metabolites
#'
#' This function extracts metabolites with their corresponding metabolite class
#' from .full_sheet into metabolites.
#' @description This function extracts metabolites with their corresponding
#' metabolite class from .full_sheet into metabolites.
#'
#' @param full_sheet full_sheet
#' @param data_ranges data_ranges
Expand All @@ -232,9 +232,10 @@ slice_metabolites <- function(full_sheet, data_ranges) {
}


#' Slice concentration values
#' @title Slice concentration values
#'
#' This function slices measurements from .full_sheet into conc_values.
#' @description This function slices measurements from .full_sheet into
#' conc_values.
#'
#' @param full_sheet full_sheet
#' @param data_ranges data_ranges
Expand All @@ -253,9 +254,9 @@ slice_conc_values <- function(full_sheet, data_ranges, metabolites) {
}


#' Slice meta data
#' @title Slice meta data
#'
#' This function slices meta data from .full_sheet into meta_data.
#' @description This function slices meta data from .full_sheet into meta_data.
#'
#' @param full_sheet full_sheet
#' @param data_ranges data_ranges
Expand All @@ -282,10 +283,10 @@ slice_meta_data <- function(full_sheet, data_ranges) {
}


#' Unify hex codes
#' @title Unify hex codes
#'
#' This function gets hex codes of different length and returns them in a
#' unified format.
#' @description This function gets hex codes of different length and returns
#' them in a unified format.
#'
#' @param hex A 3, 4, 6 or 8 digit hex code
#'
Expand Down Expand Up @@ -317,10 +318,10 @@ unify_hex <- function(hex) {
}


#' Read quantification status
#' @title Read quantification status
#'
#' This function gets the background color of each cell in .full_sheet and
#' assigns it to the corresponding quantification status.
#' @description This function gets the background color of each cell in
#' full_sheet and assigns it to the corresponding quantification status.
#'
#' @param starter_list starter_list
#' @param sheet_dim sheet_dim
Expand Down Expand Up @@ -378,9 +379,9 @@ read_quant_status <- function(
return(quant_status)
}

#' Aggregate data
#' @title Aggregate data
#'
#' This function reshapes conc_values, quant_status,
#' @description This function reshapes conc_values, quant_status,
#' metatabolites and sample IDs and combines them into a tibble data frame
#' for filtering with dplyr and plotting with 'ggplot2'. "aggregated_data"
#' is grouped by metabolites.
Expand Down
14 changes: 0 additions & 14 deletions R/MetAlyzer_fpaths.R
Expand Up @@ -12,20 +12,6 @@ example_extraction_data <- function() {
}


#' @title Get example treatment data
#'
#' @description This function returns the treatment_data_MxP_Quant_500.xlsx file path.
#'
#' @return treatment_data_MxP_Quant_500.xlsx file path
#' @export
#'
#' @examples
#' fpath <- example_treatment_data()
example_treatment_data <- function() {
system.file("extdata", "treatment_data_MxP_Quant_500.xlsx", package = "MetAlyzer")
}


#' @title Get example mutation data
#'
#' @description This function returns the mutation_data_MxP_Quant_500_XL.xlsx file path.
Expand Down
53 changes: 42 additions & 11 deletions R/MetAlyzer_handler.R
Expand Up @@ -127,11 +127,11 @@ filterMetaData <- function(metalyzer_se, ..., inplace = FALSE) {
# Print how many samples were removed
diff <- nrow(meta_data) - length(true_samples)
if (diff == 1) {
cat("1 sample was removed!\n")
cat("Info: 1 sample was removed!\n")
} else if (diff > 1) {
cat(paste(diff, "samples were removed!\n"))
cat("Info:", paste(diff, "samples were removed!\n"))
} else {
cat("No samples were removed!\n")
cat("Info: No samples were removed!\n")
}

if (inplace) {
Expand Down Expand Up @@ -369,7 +369,7 @@ filterMetabolites <- function(metalyzer_se,
)
}
cat(
"A group counts as valid, if at least ",
"Info: A group counts as valid, if at least ",
round(min_percent_valid * 100, 2),
"% of samples are considered as valid.\n",
"Group-wise calculation: (",
Expand All @@ -379,7 +379,7 @@ filterMetabolites <- function(metalyzer_se,
)
} else {
cat(
"A metabolite counts as valid, if at least ",
"Info: A metabolite counts as valid, if at least ",
round(min_percent_valid * 100, 2),
"% of samples are considered as valid.\n",
sep = ""
Expand Down Expand Up @@ -438,11 +438,11 @@ filterMetabolites <- function(metalyzer_se,

diff <- length(rm_metabolites)
if (diff == 1) {
cat("1 metabolite was removed!\n")
cat("Info: 1 metabolite was removed!\n")
} else if (diff > 1) {
cat(paste(diff, "metabolites were removed!\n"))
cat("Info:", paste(diff, "metabolites were removed!\n"))
} else {
cat("No metabolites were removed!\n")
cat("Info: No metabolites were removed!\n")
}

if (inplace) {
Expand All @@ -456,7 +456,7 @@ filterMetabolites <- function(metalyzer_se,
# === Handle Aggregated Data ===
#' @title Get Aggregated Data
#'
#' @description This function returns the tibble data frame "aggregated_data".
#' @description This function returns the tibble "aggregated_data".
#'
#' @param metalyzer_se SummarizedExperiment
#' @export
Expand All @@ -469,6 +469,37 @@ aggregatedData <- function(metalyzer_se) {
return(metalyzer_se@metadata$aggregated_data)
}

# === Handle log2FC Data ===
#' @title Get log2FC Data
#'
#' @description This function returns the tibble "log2FC".
#'
#' @param metalyzer_se SummarizedExperiment
#' @export
#'
#' @examples
#' metalyzer_se <- MetAlyzer_dataset(file_path = example_mutation_data_xl())
#' metalyzer_se <- filterMetabolites(
#' metalyzer_se,
#' drop_metabolites = "Metabolism Indicators"
#' )
#' metalyzer_se <- renameMetaData(
#' metalyzer_se,
#' Mutant_Control = "Sample Description"
#' )
#'
#' metalyzer_se <- calculate_log2FC(
#' metalyzer_se,
#' categorical = "Mutant_Control",
#' impute_perc_of_min = 0.2,
#' impute_NA = TRUE
#' )
#'
#' log2FC(metalyzer_se)
log2FC <- function(metalyzer_se) {
return(metalyzer_se@metadata$log2FC)
}

# === Export data ===

#' @title Export filtered raw data as csv
Expand Down Expand Up @@ -497,8 +528,8 @@ exportConcValues <- function(metalyzer_se,
dplyr::select(meta_data, ...),
t(conc_values)
)
cat("Number of samples:", nrow(meta_data), "\n")
cat("Number of Metabolites:", nrow(conc_values), "\n")
cat("Info: Number of samples:", nrow(meta_data), "\n")
cat("Info: Number of Metabolites:", nrow(conc_values), "\n")
utils::write.csv(
x = df,
file = file_path,
Expand Down
28 changes: 0 additions & 28 deletions R/add_filter.R

This file was deleted.

0 comments on commit c556c76

Please sign in to comment.