AnansiWeb: AnansiWeb S4 container class

View source: R/AnansiWeb-constructors.R

AnansiWebR Documentation

AnansiWeb S4 container class

Description

AnansiWeb is an S4 class containing two feature tables as well as a dictionary to link them. AnansiWeb is the main container that will hold your input data throughout the anansi pipeline.

Typical use of the anansi package will involve generating an AnansiWeb object using the weaveWeb() function.

The function AnansiWeb() constructs an AnansiWeb object from two feature tables and an adjacency matrix.

Usage

## Constructor for `AnansiWeb` objects
AnansiWeb(tableX, tableY, dictionary, metadata = list(), ...)

## Accessors
## S4 method for signature 'AnansiWeb'
dimnames(x)
## S4 method for signature 'AnansiWeb'
dim(x)
## S4 method for signature 'AnansiWeb'
names(x)

## S4 method for signature 'AnansiWeb'
tableY(x, ...)
## S4 replacement method for signature 'AnansiWeb'
tableY(x, ...) <- value
## S4 method for signature 'AnansiWeb'
tableX(x, ...)
## S4 replacement method for signature 'AnansiWeb'
tableX(x, ...) <- value
## S4 method for signature 'AnansiWeb'
dictionary(x, ...)
## S4 replacement method for signature 'AnansiWeb'
dictionary(x, ...) <- value
## S4 method for signature 'AnansiWeb'
metadata(x, simplify = TRUE, ...)
## S4 replacement method for signature 'AnansiWeb'
metadata(x, simplify = TRUE, ...) <- value

## Coercion
asMAE(x)
## S4 method for signature 'AnansiWeb'
as.list(x, ...)
## S4 method for signature 'AnansiWeb'
as.data.frame(
    x, row.names = NULL, optional = FALSE, ...
    )

## Utilities on feature pairs
## S4 method for signature 'AnansiWeb'
which(x, arr.ind = TRUE, useNames = FALSE)
## S4 method for signature 'AnansiWeb'
getFeaturePairs(
    x, which = NULL, with.metadata = FALSE, ...
)
## S4 method for signature 'AnansiWeb'
mapply(
    FUN, ..., MoreArgs = NULL, SIMPLIFY = TRUE, USE.NAMES = TRUE
    )

## S4 method for signature 'AnansiWeb'
show(object)

Arguments

tableY, tableX

A table containing features of interest. Rows should be samples and columns should be features. Y and X refer to the position of the features in a formula: Y ~ X.

dictionary

A binary adjacency matrix of class Matrix, or coercible to Matrix

metadata

list of metadata. Optional.

...

additional arguments (currently not used).

x, object

an AnansiWeb object on which a method will be applied.

simplify

boolean. If TRUE (Default), handles single data.frame arguments while ensuring compatibility with S4Vectors method.

value

replacement matrix with same number of rows target.

arr.ind, useNames

See ?base::which. AnansiWeb default returns a two-column array index.

FUN

a function with at least two arguments. The variables x and y, in order, refer to the corresponding values of feature pairs in tableX and tableY.

MoreArgs, SIMPLIFY, USE.NAMES

see ?base::mapply

which

⁠integer matrix⁠, indicating pair positions in tableY(x) and tableX(x), respectively. If NULL (default): Matrix::which(dictionary(x), TRUE).

with.metadata

⁠Logical scalar⁠ whether to append metadata to output

row.names, optional

Ignored, for S4 generic. See ?base::as.data.frame.

Value

an AnansiWeb object, with sparse binary biadjacency matrix with features from y as rows and features from x as columns in dictionary slot.

A list of data.frames with the paired data

Slots

tableY,tableX

Two matrix objects of measurements, data. Rows are samples and columns are features. Access with tableY() and tableX().

dictionary

Matrix, binary adjacency matrix. Optionally sparse. Typically generated using the weaveWeb() function. Access with dictionary().

metadata

Optional data.frame of sample metadata. Access with metadata().

See Also

  • kegg_link(): For examples of input for link argument.

  • getWeb(): For MultiAssayExperiment::MultiAssayExperiment() methods.

  • weaveWeb(): for general use.

Examples


# Use AnansiWeb() to consrtuct an AnansiWeb object from components:
tX <- `dimnames<-`(replicate(5, (rnorm(36))),
    value = list(
        as.character(seq_len(36)),
        letters[1:5]
    )
)
tY <- `dimnames<-`(replicate(3, (rnorm(36))),
    value = list(
        as.character(seq_len(36)),
        LETTERS[1:3]
    )
)

d <- matrix(TRUE,
    nrow = NCOL(tY), ncol = NCOL(tX),

    # Note: Dictionary should have named dimensions
    dimnames = list(
        y_names = colnames(tY),
        x_names = colnames(tX)
    )
)
web <- AnansiWeb(tableX = tX, tableY = tY, dictionary = d)

# Methods for AnansiWeb
dimnames(web)
dim(web)
names(web)

tableX(web)
tableY(web)
dictionary(web)

# Assign some random metadata
metadata(web) <- data.frame(
    id = row.names(tableY(web)),
    a = rnorm(36),
    b = sample(c("a", "b"), 36, TRUE),
    row.names = "id"
)
metadata(web)

# coerce To list
weblist <- as.list(web)

# Coerce to MultiAssayExperiment
asMAE(web)

# Extract data.frames in pairs (only show first)
getFeaturePairs(web)[1L]

mapply(
    FUN = function(x, y) cor(x, y),
    web
)


thomazbastiaanssen/anansi documentation built on June 9, 2025, 3:59 p.m.