AnansiWeb S4 container class
Source:R/AllClasses.R
, R/AnansiWeb-constructors.R
, R/AnansiWeb-methods.R
, and 1 more
AnansiWeb.Rd
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 class 'AnansiWeb'
dimnames(x)
# S4 method for class 'AnansiWeb'
dim(x)
# S4 method for class 'AnansiWeb'
names(x)
# S4 method for class 'AnansiWeb'
tableY(x, ...)
# S4 method for class 'AnansiWeb'
tableY(x, ...) <- value
# S4 method for class 'AnansiWeb'
tableX(x, ...)
# S4 method for class 'AnansiWeb'
tableX(x, ...) <- value
# S4 method for class 'AnansiWeb'
dictionary(x, ...)
# S4 method for class 'AnansiWeb'
dictionary(x, ...) <- value
# S4 method for class 'AnansiWeb'
metadata(x, simplify = TRUE, ...)
# S4 method for class 'AnansiWeb'
metadata(x, simplify = TRUE, ...) <- value
## Coercion
asMAE(x)
# S4 method for class 'AnansiWeb'
as.list(x, ...)
# S4 method for class 'AnansiWeb'
as.data.frame(
x, row.names = NULL, optional = FALSE, ...
)
## Utilities on feature pairs
# S4 method for class 'AnansiWeb'
which(x, arr.ind = TRUE, useNames = FALSE)
# S4 method for class 'AnansiWeb'
getFeaturePairs(
x, which = NULL, with.metadata = FALSE, ...
)
# S4 method for class 'AnansiWeb'
mapply(
FUN, ..., MoreArgs = NULL, SIMPLIFY = TRUE, USE.NAMES = TRUE
)
# S4 method for class '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 toMatrix
- metadata
list
of metadata. Optional.- ...
additional arguments (currently not used).
- x, object
an
AnansiWeb
object on which a method will be applied.- simplify
boolean
. IfTRUE
(Default), handles single data.frame arguments while ensuring compatibility withS4Vectors
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
andy
, in order, refer to the corresponding values of feature pairs intableX
andtableY
.- MoreArgs, SIMPLIFY, USE.NAMES
see ?base::mapply
- which
integer matrix
, indicating pair positions intableY(x)
andtableX(x)
, respectively. IfNULL
(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 withtableY()
andtableX()
.dictionary
Matrix
, binary adjacency matrix. Optionally sparse. Typically generated using theweaveWeb()
function. Access withdictionary()
.metadata
Optional
data.frame
of sample metadata. Access withmetadata()
.
See also
kegg_link()
: For examples of input for link argument.getWeb()
: ForMultiAssayExperiment::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)
#> $y_names
#> [1] "A" "B" "C"
#>
#> $x_names
#> [1] "a" "b" "c" "d" "e"
#>
dim(web)
#> [1] 3 5
names(web)
#> [1] "y_names" "x_names"
tableX(web)
#> a b c d e
#> 1 -1.400043517 -1.91008747 1.33732041 0.22712713 0.97995670
#> 2 0.255317055 -0.27923724 0.23669628 0.97845492 1.32178099
#> 3 -2.437263611 -0.31344598 1.31829338 -0.20888265 -1.11971083
#> 4 -0.005571287 1.06730788 0.52390979 -1.39941046 0.51459982
#> 5 0.621552721 0.07003485 0.60674805 0.25853729 -1.50909984
#> 6 1.148411606 -0.63912332 -0.10993567 -0.44179945 1.53274148
#> 7 -1.821817661 -0.04996490 0.17218172 0.56859986 0.42914737
#> 8 -0.247325302 -0.25148344 -0.09032729 2.12685046 0.12210341
#> 9 -0.244199607 0.44479712 1.92434334 0.42485844 -1.13801240
#> 10 -0.282705449 2.75541758 1.29839276 -1.68428153 -0.55801513
#> 11 -0.553699384 0.04653138 0.74879127 0.24940178 1.05253854
#> 12 0.628982042 0.57770907 0.55622433 1.07283825 0.67768364
#> 13 2.065024895 0.11819487 -0.54825726 2.03936926 0.03849955
#> 14 -1.630989402 -1.91172049 1.11053489 0.44945378 -0.35638119
#> 15 0.512426950 0.86208648 -2.61233433 1.39181405 0.78284410
#> 16 -1.863011492 -0.24323674 -0.15569378 0.42656655 0.80441162
#> 17 -0.522012515 -0.20608719 0.43388979 0.10758399 -1.90006082
#> 18 -0.052601910 0.01917759 -0.38195111 0.02229473 0.93578429
#> 19 0.542996343 0.02956075 0.42418757 0.60361101 -0.30905150
#> 20 -0.914074827 0.54982754 1.06310200 -0.26265057 0.26306668
#> 21 0.468154420 -2.27411486 1.04871262 -0.52826408 -1.79059186
#> 22 0.362951256 2.68255718 -0.03810289 0.19214942 -0.78825884
#> 23 -1.304543545 -0.36122126 0.48614892 -1.14619967 -1.13302167
#> 24 0.737776321 0.21335575 1.67288261 0.84618466 0.36365257
#> 25 1.888504929 1.07434588 -0.35436116 0.08171963 -0.28588791
#> 26 -0.097445104 -0.66508825 0.94634789 -1.30511701 0.51766913
#> 27 -0.935847354 1.11395242 1.31682636 -0.94491206 -0.10290867
#> 28 -0.015950311 -0.24589641 -0.29664002 0.45434159 -0.97406959
#> 29 -0.826788954 -1.17756331 -0.38721358 -0.85520250 1.27067230
#> 30 -1.512399651 -0.97585062 -0.78543266 -0.28689522 0.96086479
#> 31 0.935363190 1.06505732 -1.05673687 0.89496163 0.76872137
#> 32 0.176488611 0.13167063 -0.79554143 0.06730444 1.03593077
#> 33 0.243685465 0.48862881 -1.75627543 -0.16267634 -0.47388707
#> 34 1.623548883 -1.69945057 -0.69053790 -0.82731017 -1.27533487
#> 35 0.112038083 -1.47073631 -0.55854199 1.87650562 -0.30562067
#> 36 -0.133997013 0.28415034 -0.53666333 0.76644020 2.21176949
tableY(web)
#> A B C
#> 1 -1.04166838 0.55851442 -1.193641182
#> 2 -1.14652385 0.41540640 -0.751723323
#> 3 -1.67532730 -1.45229977 1.455841403
#> 4 1.52593866 0.94120612 -0.828603533
#> 5 0.55418551 -0.33893587 0.289774460
#> 6 1.99311026 -0.07557425 -0.480053484
#> 7 -0.15412074 0.04020439 -0.604829354
#> 8 2.56440834 0.12430107 1.460110180
#> 9 1.06199914 -0.99843255 0.149679354
#> 10 1.14269488 1.23339006 -1.433321100
#> 11 1.12383884 0.34042449 -0.010303319
#> 12 -0.39700149 -0.47270248 -0.212236035
#> 13 -0.82326115 0.70875306 -0.906340179
#> 14 -0.57888462 -1.52895871 -2.102152479
#> 15 1.76378938 0.23742535 1.893360464
#> 16 0.13299215 -1.31281425 -0.968125837
#> 17 0.37649933 0.74702859 -0.102603036
#> 18 1.13870765 -1.56251843 0.239959572
#> 19 1.24126308 0.07105336 0.060898893
#> 20 0.61209094 -0.63953477 -2.177576028
#> 21 -0.42938009 -0.84519574 -0.117860143
#> 22 1.36046133 0.67524470 0.112294787
#> 23 -0.07085743 1.15337579 0.007886198
#> 24 -0.27215368 -1.68650474 1.877743872
#> 25 -2.44668003 -0.90281495 2.158756554
#> 26 0.06548664 1.31763370 0.709714522
#> 27 -1.09850890 1.10018974 0.766983379
#> 28 -0.63317818 1.20376784 -0.308211421
#> 29 -2.06365445 -1.43127078 1.012001849
#> 30 2.64893203 1.38291086 -0.919051597
#> 31 -1.15339839 0.00312594 0.563380077
#> 32 -0.34063788 -0.07788682 0.322482749
#> 33 0.78636258 0.44142823 0.366674363
#> 34 -1.27051311 0.12892290 1.129835153
#> 35 0.54214155 -0.83021426 -0.941498076
#> 36 0.07510590 -0.50359291 0.217837643
dictionary(web)
#> 3 x 5 sparse Matrix of class "lgCMatrix"
#> x_names
#> y_names a b c d e
#> A | | | | |
#> B | | | | |
#> C | | | | |
# 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)
#> a b
#> 1 1.41541229 b
#> 2 -0.38373305 a
#> 3 -0.17408637 b
#> 4 -0.22174452 b
#> 5 -1.00952872 b
#> 6 0.48072527 b
#> 7 1.60440733 a
#> 8 -1.51502453 b
#> 9 -1.41602391 b
#> 10 0.87677733 a
#> 11 0.62413241 b
#> 12 2.11227729 a
#> 13 -0.35612442 b
#> 14 -1.06446421 a
#> 15 1.07711654 a
#> 16 1.18157557 b
#> 17 0.19839209 a
#> 18 -0.40040525 a
#> 19 0.61615428 b
#> 20 1.97415675 b
#> 21 1.88466232 b
#> 22 -1.58862055 b
#> 23 -0.53992316 b
#> 24 -1.16946146 a
#> 25 0.55910599 a
#> 26 -1.81934725 b
#> 27 0.39334397 b
#> 28 0.04213411 a
#> 29 1.17966418 b
#> 30 -0.25692118 b
#> 31 -1.05633610 a
#> 32 0.19877721 a
#> 33 0.65053355 a
#> 34 0.34391334 a
#> 35 1.47753231 a
#> 36 0.07202570 b
# coerce To list
weblist <- as.list(web)
# Coerce to MultiAssayExperiment
asMAE(web)
#> A MultiAssayExperiment object of 2 listed
#> experiments with user-defined names and respective classes.
#> Containing an ExperimentList class object of length 2:
#> [1] y_names: SummarizedExperiment with 3 rows and 36 columns
#> [2] x_names: SummarizedExperiment with 5 rows and 36 columns
#> Functionality:
#> experiments() - obtain the ExperimentList instance
#> colData() - the primary/phenotype DataFrame
#> sampleMap() - the sample coordination DataFrame
#> `$`, `[`, `[[` - extract colData columns, subset, or experiment
#> *Format() - convert into a long or wide DataFrame
#> assays() - convert ExperimentList to a SimpleList of matrices
#> exportClass() - save data to flat files
# Extract data.frames in pairs (only show first)
getFeaturePairs(web)[1L]
#> [[1]]
#> A a
#> 1 -1.04166838 -1.400043517
#> 2 -1.14652385 0.255317055
#> 3 -1.67532730 -2.437263611
#> 4 1.52593866 -0.005571287
#> 5 0.55418551 0.621552721
#> 6 1.99311026 1.148411606
#> 7 -0.15412074 -1.821817661
#> 8 2.56440834 -0.247325302
#> 9 1.06199914 -0.244199607
#> 10 1.14269488 -0.282705449
#> 11 1.12383884 -0.553699384
#> 12 -0.39700149 0.628982042
#> 13 -0.82326115 2.065024895
#> 14 -0.57888462 -1.630989402
#> 15 1.76378938 0.512426950
#> 16 0.13299215 -1.863011492
#> 17 0.37649933 -0.522012515
#> 18 1.13870765 -0.052601910
#> 19 1.24126308 0.542996343
#> 20 0.61209094 -0.914074827
#> 21 -0.42938009 0.468154420
#> 22 1.36046133 0.362951256
#> 23 -0.07085743 -1.304543545
#> 24 -0.27215368 0.737776321
#> 25 -2.44668003 1.888504929
#> 26 0.06548664 -0.097445104
#> 27 -1.09850890 -0.935847354
#> 28 -0.63317818 -0.015950311
#> 29 -2.06365445 -0.826788954
#> 30 2.64893203 -1.512399651
#> 31 -1.15339839 0.935363190
#> 32 -0.34063788 0.176488611
#> 33 0.78636258 0.243685465
#> 34 -1.27051311 1.623548883
#> 35 0.54214155 0.112038083
#> 36 0.07510590 -0.133997013
#>
mapply(
FUN = function(x, y) cor(x, y),
web
)
#> aA aB aC bA bB bC
#> -0.04798083 0.06035449 0.32607170 0.21244171 0.26101305 0.13758072
#> cA cB cC dA dB dC
#> -0.13706694 -0.13116275 -0.24363013 0.07428211 -0.26138248 0.07189662
#> eA eB eC
#> 0.09469575 -0.06728680 -0.07338832