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
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: ariadne
Version: 0.2.6
Version: 0.2.7
Authors@R:
c(person(given = "Giulio", family = "Benedetti", role = c("aut", "cre"),
email = "giulio.benedetti@utu.fi",
Expand Down Expand Up @@ -37,7 +37,7 @@ Imports:
ggplot2,
ggraph,
httr2,
igraph,
igraph (>= 2.3.0),
KEGGREST,
Matrix,
methods,
Expand Down
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Changes in version 0.2.x
* Made major changes to workflow
* Switched to S4
* Switched back to S4

Changes in version 0.1.X
* Switched to S7
26 changes: 26 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,29 @@
#' @name butyrate
#' @importFrom utils data
NULL


#' Data frame for pathway from chebi to gmm
#'
#' \code{pathMeta} provides a minimal example of a data frame describing one
#' pathway in the ariadne graph from chebi to gmm. This kind of data frame is
#' typically the output of \code{\link{drawPath}} and works as input for
#' \code{\link{weavePath}} and \code{\link{weaveComplex}}.
#'
#' @returns
#' A pathway data frame with four rows (steps) and four columns (from, to,
#' source and version).
#'
#' @examples
#' # Import data frame for pathway from chebi to gmm
#' data("pathMeta", package = "ariadne")
#'
#' # Print pathway data frame
#' pathMeta
#'
#' # Recreate pathMeta using ariadne
#' # graph <- ariadne()
#' # pathMeta <- drawPath(graph, chebi ~ gmm, include = "rhea")
#' @name pathMeta
#' @importFrom utils data
NULL
2 changes: 1 addition & 1 deletion R/draw.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ setMethod("drawPath", signature = c(graph = "igraph"),
# Create path data.frame
path_df <- data.frame(
from = nodes[-length(nodes)],
to = nodes[-1],
to = nodes[-1L],
source = edges
)
return(path_df)
Expand Down
4 changes: 2 additions & 2 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ setMethod("plotPath", signature = c(graph = "igraph"),
function(graph, by = NULL, k = 1, include = NULL, exclude = NULL,
res.name = NULL, prune = FALSE, focus = FALSE){
# Check args
if( !is.logical(prune) || length(prune) != 1L ){
if( length(prune) != 1L || !is.logical(prune) || is.na(prune) ){
stop("'prune' must be TRUE or FALSE.", call. = FALSE)
}
if( !is.logical(focus) || length(focus) != 1L ){
if( length(focus) != 1L || !is.logical(focus) || is.na(focus) ){
stop("'focus' must be TRUE or FALSE.", call. = FALSE)
}

Expand Down
3 changes: 3 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ NULL
#' @export
#' @rdname listResourceVersions
listResourceVersions <- function(default = FALSE){
if( length(default) != 1L || !is.logical(default) || is.na(default) ){
stop("'default' must be TRUE or FALSE.", call. = FALSE)
}
# Retrieve metadata on resource versions
meta <- versionMetadata
# If default is turned on
Expand Down
90 changes: 75 additions & 15 deletions R/weave.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#' coverage threshold, which is useful for pathways or functional modules made
#' of several indispensable components.
#'
#' @param graph An igraph object.
#' @param graph An igraph or data.frame object, which can be obtained from
#' \code{\link{ariadne}} and \code{\link{drawPath}}, respectively.
#'
#' @param by A formula specifying the path to weave.
#'
Expand Down Expand Up @@ -65,15 +66,33 @@
#' column.
#'
#' @examples
#' # Load resource graph
#' graph <- ariadne()
#'
#' # Weave simple path from KEGG diseases to gut metabolic modules
#' dis2gmm <- weavePath(graph, kegg_disease ~ gmm)
#'
#' # Weave complex path from KEGG diseases to gut metabolic modules
#' dis2gmm <- weaveComplex(graph, kegg_disease ~ gmm)
#'
#' # Specify coverage threshold
#' dis2gmm <- weaveComplex(graph, kegg_disease ~ gmm, threshold = 0.8)
#'
#'
#' # Load example pathway dataframe
#' data("pathMeta", package = "ariadne")
#'
#' # Weave pathway from chebi to gmm with three initial chebi ids
#' chebi2gmm <- weavePath(pathMeta, init = c(15377, 30616, 4167))
#'
#'
#' # Import mia package
#' library(mia)
#'
#' # Import dataset
#' data("Tengeler2020", package = "mia")
#' tse <- Tengeler2020
#'
#' # Load resource graph
#' graph <- ariadne()
#'
#' # Retrieve taxon names
#' tax.labs <- getTaxonomyLabels(tse, make.unique = FALSE)
#' tax.labs <- sub("^.+:", "", tax.labs)
Expand All @@ -88,18 +107,59 @@
#' tax2bugsig <- weavePath(
#' graph, taxname ~ bugsig, include = "taxid", init = tax.labs
#' )
#'
#' # Weave simple path from KEGG diseases to gut metabolic modules
#' dis2gmm <- weavePath(graph, kegg_disease ~ gmm)
#'
#' # Weave complex path from KEGG diseases to gut metabolic modules
#' dis2gmm <- weaveComplex(graph, kegg_disease ~ gmm)
#'
#' # Specify coverage threshold
#' dis2gmm <- weaveComplex(graph, kegg_disease ~ gmm, threshold = 0.8)
NULL


#' @export
#' @rdname weavePath
#' @importFrom stats as.formula
setMethod("weavePath", signature = c(graph = "data.frame"),
function(graph, init = NULL, prune = TRUE, use.names = TRUE, verbose = TRUE,
timeout = 1e6, ...){
# Derive formula from pathway dataframe
by <- c(graph$from[1L], graph$to[nrow(graph)]) |>
paste(collapse = "~") |>
as.formula()
# Retrieve minimal graph for the pathway
graph <- .graph_from_path_df(graph)
# Weave linkmap from minimal graph
linkmap <- weavePath(
graph, by, init = init, prune = prune, use.names = use.names,
verbose = verbose, timeout = timeout, ...
)
return(linkmap)
})


#' @importFrom igraph as_data_frame subgraph_from_edges
.graph_from_path_df <- function(path_df){
# If versions are provided
if( "version" %in% names(path_df) ){
# Derive versions from pathway dataframe
res_df <- unique(path_df[ , c("source", "version")])
# Omit missing versions
res_df <- na.omit(res_df)
# Create versions list
versions <- as.list(res_df$version)
names(versions) <- res_df$source
}else{
# Use empty versions
versions <- NULL
}
# Import ariadne graph
graph <- ariadne(versions = versions)
# Get keys of graph edges
E(graph)$name <- graph |>
as_data_frame(what = "edges") |>
.get_edge_keys()
# Get keys of pathway steps
keep <- .get_edge_keys(path_df)
# Subset graph based on pathway steps
graph <- subgraph_from_edges(graph, keep)
return(graph)
}


#' @export
#' @rdname weavePath
#' @importFrom stats as.formula
Expand Down Expand Up @@ -132,10 +192,10 @@ setMethod("weavePath", signature = c(graph = "igraph"),
stop("'timeout' must be a positive number", call. = FALSE)
}
# Check shared logical args
if( !is.logical(prune) || length(prune) != 1L ){
if( length(prune) != 1L || !is.logical(prune) || is.na(prune) ){
stop("'prune' must be TRUE or FALSE.", call. = FALSE)
}
if( !is.logical(verbose) || length(verbose) != 1L ){
if( length(verbose) != 1L || !is.logical(verbose) || is.na(verbose) ){
stop("'verbose' must be TRUE or FALSE.", call. = FALSE)
}
# Set timeout for downloads
Expand Down
22 changes: 21 additions & 1 deletion R/weave_complex.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@

#' @export
#' @rdname weavePath
#' @importFrom stats as.formula
setMethod("weaveComplex", signature = c(graph = "data.frame"),
function(graph, init = NULL, prune = TRUE, use.names = TRUE,
threshold = NULL, verbose = TRUE, timeout = 1e6, ...){

by <- c(graph$from[1L], graph$to[nrow(graph)]) |>
paste(collapse = "~") |>
as.formula()

graph <- .graph_from_path_df(graph)

linkmap <- weaveComplex(
graph, by, init = init, prune = prune, use.names = use.names,
threshold = threshold, verbose = verbose, timeout = timeout, ...
)
return(linkmap)
})


#' @export
#' @rdname weavePath
#' @importFrom igraph as_data_frame
Expand Down Expand Up @@ -36,7 +57,6 @@ setMethod("weaveComplex", signature = c(graph = "igraph"),
}else{
inner_by <- by
}

# Build MultiFactor from path linkmaps
mf <- .build_path_mf(
graph, inner_by, k, include, exclude, res.name,
Expand Down
Binary file added data/pathMeta.rda
Binary file not shown.
26 changes: 26 additions & 0 deletions man/pathMeta.Rd

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

Loading
Loading