Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ Imports:
readr
Suggests:
MetaCycData,
datadr,
knitr,
rmarkdown,
foreach,
doParallel,
testthat,
purrr,
viridis,
DT
DT,
hexbin
Remotes:
github::delta-rho/datadr,
github::EMSL-Computing/MetaCycData
VignetteBuilder: knitr
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
4 changes: 0 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export(compound_calcs)
export(concat)
export(conf_filter)
export(coreMSDataToFtmsData)
export(densityCognostics)
export(densityPlot)
export(divideByGroup)
export(divideByGroupComparisons)
Expand Down Expand Up @@ -95,7 +94,6 @@ export(getSulfurColName)
export(getVanKrevelenCategoryBounds)
export(group_designation)
export(heatmap)
export(kendrickCognostics)
export(kendrickPlot)
export(mapCompoundsToModules)
export(mapCompoundsToReactions)
Expand All @@ -104,7 +102,6 @@ export(mass_error_plot)
export(mass_filter)
export(molecule_filter)
export(numPeaksPlot)
export(panelFunctionGenerator)
export(parseModuleReaction)
export(plotPrincipalCoordinates)
export(plotlyHeatmap)
Expand All @@ -114,7 +111,6 @@ export(summarizeGroupComparisons)
export(summarizeGroups)
export(transformation_counts)
export(unique_mf_assignment)
export(vanKrevelenCognostics)
export(vanKrevelenPlot)
importFrom(dplyr,"%>%")
importFrom(magrittr,"%>%")
37 changes: 16 additions & 21 deletions R/concat.R
Original file line number Diff line number Diff line change
@@ -1,47 +1,42 @@
#' Combine multiple distributed data objects of ftmsData
#' Combine multiple ftmsData objects
#'
#' Combine multiple distributed data objects (ddo) into a single ddo
#' Combine multiple ftmsData objects into a single ftmsData object
#' for further analysis or visualizations. The inputs to this function are
#' the ddo objects created by \code{\link{divideByGroup}} or
#' \code{\link{divideByGroupComparisons}}. The output is a new ddo
#' the ftmsData objects created by \code{\link{divideByGroup}} or
#' \code{\link{divideByGroupComparisons}}. The output is a new ftmsData
#' with all the data of the supplied inputs, in a form that can be
#' summarized with \code{\link{summarizeGroups}} or \code{\link{summarizeGroupComparisons}}
#' respectively, or visualized with \code{trelliscope}.
#' respectively.
#'
#' @param ... two or more ddo objects that are the output of \code{\link{summarizeGroups}} or \code{\link{summarizeGroupComparisons}}
#' @param ... two or more ftmsData objects that are the output of \code{\link{summarizeGroups}} or \code{\link{summarizeGroupComparisons}}
#'
#' @seealso \link[datadr:ddo]{ddo}
#' @author Amanda White
#'
#' @export
#'
#' @examples
#' data("exampleProcessedPeakData")
#' exampleProcessedPeakData <- group_designation(exampleProcessedPeakData, main_effects = "Location")
#' grpDdo1 <- divideByGroup(exampleProcessedPeakData)
#' grp1 <- divideByGroup(exampleProcessedPeakData)
#'
#' exampleProcessedPeakData <- group_designation(exampleProcessedPeakData, main_effects = "Crop.Flora")
#' grpDdo2 <- divideByGroup(exampleProcessedPeakData)
#' grp2 <- divideByGroup(exampleProcessedPeakData)
#'
#' allGrpDdo <-concat(grpDdo1, grpDdo2)
#' grpSummaries <- summarizeGroups(allGrpDdo, c("n_present", "prop_present"))
#' allGrps <-concat(grp1, grp2)
#' grpSummaries <- summarizeGroups(allGrps, c("n_present", "prop_present"))
concat <- function(...) {
require(datadr)

parms <- list(...)
# test inputs
if (length(parms) == 0) return(NULL)
if (!all(unlist(lapply(parms, function(x) inherits(x, "ddo")))))
stop("input values must be ddo objects")
if (!all(unlist(lapply(parms, function(x) inherits(x[[1]]$value, "ftmsData") | inherits(x[[1]]$value, "groupComparison")))))
stop("input values must be distributed data objects of ftmsData or groupComparison objects")
if (!all(unlist(lapply(parms, function(x) inherits(x, "list")))))
stop("input values must be list objects")
if (!all(unlist(lapply(parms, function(x) inherits(x[[1]], "ftmsData") | inherits(x[[1]], "groupComparison")))))
stop("input values must be lists of ftmsData or groupComparison objects")

if (length(parms) == 1) return(parms[[1]])

# combine multiple DDOs
tmp <- unlist(lapply(parms, as.list), recursive = FALSE)
res <- ddo(tmp)
# combine multiple lists of ftmsData Objects
res <- c(unlist(parms, recursive=FALSE))

return(res)
}

162 changes: 0 additions & 162 deletions R/densityCognostics.R

This file was deleted.

26 changes: 12 additions & 14 deletions R/divideByGroup.R
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
#' Divide an ftmsData object by group to form a ddo
#' Divide an ftmsData object by group to form a list of ftmsData objects
#'
#' Construct a \code{\link[datadr:ddo]{ddo}} from an \code{ftmsData} object by dividing
#' by group. The resulting object may be used with Trelliscope to make
#' plots for each group. The input data must have a \code{group_DF} attribute
#' defining the groups.
#' Construct a list of subsetted ftmsData objects from an \code{ftmsData} object by dividing
#' by group.
#'
#' @param ftmsObj ftmsData object
#' @return a ddo where each division is a subset of \code{ftmsObj} corresponding
#' @return a list where each element is a subset of \code{ftmsObj} corresponding
#' to a single group
#' @seealso \code{\link[datadr:ddo]{ddo}}
#' @export
divideByGroup <- function(ftmsObj) {
require(datadr)
sample.colname <- getFDataColName(ftmsObj)
samples <- as.character(ftmsObj$f_data[, sample.colname])
groupDF <- getGroupDF(ftmsObj)
if (is.null(groupDF)) stop("This object does not have group designation information")

edata_nonsample_cols <- setdiff(colnames(ftmsObj$e_data), samples)

result <- lapply(unique(groupDF$Group), function(group_name) {

val <- subset(ftmsObj, groups=group_name)

# datadr attributes:
attr(val, "split") <- data.frame(Group=group_name, stringsAsFactors = FALSE)
colnames(attr(val, "split")) <- "Group"

key <- paste0("Group=", group_name)
return(kvPair(key, val))
return(val)
})

result_names <- lapply(unique(groupDF$Group), function(group_name) {
paste0("Group=", group_name)
})
names(result) <- result_names

result <- ddo(result)
return(result)
}
23 changes: 16 additions & 7 deletions R/divideByGroupComparisons.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
#' Construct a ddo of group comparisons
#' Construct a list of group comparisons
#'
#' Construct a \code{\link[datadr:ddo]{ddo}} where each subset consists of data for
#' Construct a list where each element is a subset consisting of data for
#' a pair of groups. This is used to facilitate analysis and visualizations
#' of group comparisons.
#'
#' @param ftmsObj ftmsData object
#' @param comparisons dictates which pairwise comparisons to make. 'all' will create a matrix for all pairwise comparisons, 'control' will create a matrix for all comparisons against a specified control group, 'one-factor' will create a matrix of pairwise comparisons to be made where only one 'main_effect' changes between the two groups, or a list of specific comparisons to be made (e.g., list(c("Group1","Group2"),c("Group3","Group4"))) can be given.
#' @param control if wanting to only compare against a control, must specify which group or sample is the control
#' @return a distributed data object where each division consists of a subset of \code{ftmsObj} with
#' @return a named list where each element consists of a subset of \code{ftmsObj} with
#' data from just two groups.
#' @export
divideByGroupComparisons <- function(ftmsObj, comparisons, control=NULL) {

if (missing(ftmsObj)) stop("ftmsObj is missing")
if (missing(comparisons)) stop("comparisons is missing")
if (!inherits(ftmsObj, "ftmsData")) stop("ftmsObj must be of type ftmsData")
# if (!is.matrix(comparisons) & !is.data.frame(comparisons)) stop("comparisons must be either a matrix or a data frame")
if (missing(comparisons)) stop("comparisons is missing")

require(datadr)

fdata.colname <- getFDataColName(ftmsObj)

groupDF <- ftmsRanalysis:::getGroupDF(ftmsObj)
Expand All @@ -35,6 +34,7 @@ divideByGroupComparisons <- function(ftmsObj, comparisons, control=NULL) {
samples <- unique(as.character(ftmsObj$f_data[, fdata.colname]))
edata_nonsample_cols <- setdiff(colnames(ftmsObj$e_data), groups)

# lapply over each col in matrix and return list of subset data
result <- lapply(1:ncol(compMatrix), function(i) {
grp.names <- compMatrix[,i]

Expand All @@ -45,10 +45,19 @@ divideByGroupComparisons <- function(ftmsObj, comparisons, control=NULL) {
attr(val, "split") <- data.frame(Group_Comparison=comp_name, stringsAsFactors = FALSE)
colnames(attr(val, "split")) <- "Group_Comparison"

return(val)
})

# Loop over cols of matrix and create vector of names for results above
result_names <- lapply(1:ncol(compMatrix), function(i) {
grp.names <- compMatrix[,i]
comp_name <- paste(grp.names, collapse=" vs ")
key <- paste0("Group_Comparison=", comp_name)
return(kvPair(key, val))
return(key)
})
result <- ddo(result)

names(result) <- result_names

attr(result, "e_meta") <- ftmsObj$e_meta
return(result)
}
Loading
Loading