Skip to contents

Coercion functions for anansi

Usage

# S3 method for class '`anansi::AnansiWeb`'
as.list(x, ...)

# S3 method for class '`anansi::MultiFactor`'
as.list(x, ..., use.names = TRUE)

# S3 method for class '`anansi::AnansiWeb`'
as.data.frame(x, row.names, optional, ...)

asMAE(x)

asTSE(x)

Arguments

x

input object

...

additional arguments (currently not used).

use.names

Logical scalar, whether output list should contain character (Default) or integer data frame. If FALSE, returns unfactor(x).

row.names, optional

Not used. See ?base::data.frame

Value

An object of the desired class.

See also

Examples

# AnansiWeb
x <- randomWeb(
    n_samples = 5,
    n_features_x = 4,
    n_features_y = 6
)

as.list(x)
#> $y
#>                       y
#> sample_id                      y_1        y_2        y_3        y_4         y_5
#>   anansi_ID_sample_1_1  0.26665271  2.0107346  0.9549602  0.7342024 -0.02531491
#>   anansi_ID_sample_2_1 -0.21468618  1.1576628 -0.7614755 -0.3614332 -1.20992250
#>   anansi_ID_sample_3_1  0.54418631 -1.1437424 -1.8017583 -0.5588636 -0.07770139
#>   anansi_ID_sample_4_1 -0.73160010 -1.5832660 -1.3847598 -0.2774683 -0.60569915
#>   anansi_ID_sample_5_1 -0.07715187  0.7374131 -0.2976818  0.5900611 -0.43986955
#>                       y
#> sample_id                       y_6
#>   anansi_ID_sample_1_1  0.540867642
#>   anansi_ID_sample_2_1 -0.899922143
#>   anansi_ID_sample_3_1 -1.566842379
#>   anansi_ID_sample_4_1 -0.001528403
#>   anansi_ID_sample_5_1 -0.381552421
#> 
#> $x
#>                       x
#> sample_id                     x_1         x_2        x_3        x_4
#>   anansi_ID_sample_1_1  1.8975577  0.06014704  0.6663198 -0.7946773
#>   anansi_ID_sample_2_1  0.3981683  0.26975570  0.4333921 -0.9398198
#>   anansi_ID_sample_3_1  0.6794073 -0.82569929  0.9145914  0.1648717
#>   anansi_ID_sample_4_1 -0.1673151  0.37878777 -1.3723373  1.2251926
#>   anansi_ID_sample_5_1 -0.3377048  0.38632382 -0.9835608 -1.0493841
#> 
#> $dictionary
#> 6 x 4 sparse Matrix of class "ngCMatrix"
#>      x
#> y     x_1 x_2 x_3 x_4
#>   y_1   |   .   |   .
#>   y_2   .   .   .   |
#>   y_3   |   .   |   |
#>   y_4   .   .   .   .
#>   y_5   |   |   .   .
#>   y_6   |   |   |   |
#> 
#> $metadata
#>                      sample_id repeated group_ab subtype    score_a
#> anansi_ID_sample_1_1  sample_1    rep_1        b       x  0.4372142
#> anansi_ID_sample_2_1  sample_2    rep_1        a       y  0.3158621
#> anansi_ID_sample_3_1  sample_3    rep_1        a       y  0.1946105
#> anansi_ID_sample_4_1  sample_4    rep_1        a       x -0.4557621
#> anansi_ID_sample_5_1  sample_5    rep_1        a       y  0.8125350
#>                           score_b    score_c
#> anansi_ID_sample_1_1  0.275042593 -0.1346410
#> anansi_ID_sample_2_1  0.006009411  1.4708322
#> anansi_ID_sample_3_1  2.010186412 -1.4751257
#> anansi_ID_sample_4_1  0.313808823  0.2044997
#> anansi_ID_sample_5_1 -0.846162712 -0.3417684
#> 
as.data.frame(x)
#>                              y_1        y_2        y_3        y_4         y_5
#> anansi_ID_sample_1_1  0.26665271  2.0107346  0.9549602  0.7342024 -0.02531491
#> anansi_ID_sample_2_1 -0.21468618  1.1576628 -0.7614755 -0.3614332 -1.20992250
#> anansi_ID_sample_3_1  0.54418631 -1.1437424 -1.8017583 -0.5588636 -0.07770139
#> anansi_ID_sample_4_1 -0.73160010 -1.5832660 -1.3847598 -0.2774683 -0.60569915
#> anansi_ID_sample_5_1 -0.07715187  0.7374131 -0.2976818  0.5900611 -0.43986955
#>                               y_6        x_1         x_2        x_3        x_4
#> anansi_ID_sample_1_1  0.540867642  1.8975577  0.06014704  0.6663198 -0.7946773
#> anansi_ID_sample_2_1 -0.899922143  0.3981683  0.26975570  0.4333921 -0.9398198
#> anansi_ID_sample_3_1 -1.566842379  0.6794073 -0.82569929  0.9145914  0.1648717
#> anansi_ID_sample_4_1 -0.001528403 -0.1673151  0.37878777 -1.3723373  1.2251926
#> anansi_ID_sample_5_1 -0.381552421 -0.3377048  0.38632382 -0.9835608 -1.0493841
#>                      sample_id repeated group_ab subtype    score_a
#> anansi_ID_sample_1_1  sample_1    rep_1        b       x  0.4372142
#> anansi_ID_sample_2_1  sample_2    rep_1        a       y  0.3158621
#> anansi_ID_sample_3_1  sample_3    rep_1        a       y  0.1946105
#> anansi_ID_sample_4_1  sample_4    rep_1        a       x -0.4557621
#> anansi_ID_sample_5_1  sample_5    rep_1        a       y  0.8125350
#>                           score_b    score_c
#> anansi_ID_sample_1_1  0.275042593 -0.1346410
#> anansi_ID_sample_2_1  0.006009411  1.4708322
#> anansi_ID_sample_3_1  2.010186412 -1.4751257
#> anansi_ID_sample_4_1  0.313808823  0.2044997
#> anansi_ID_sample_5_1 -0.846162712 -0.3417684

# AnansiWeb to MultiAssayExperiment
asMAE(x)
#> A MultiAssayExperiment object of 2 listed
#>  experiments with user-defined names and respective classes.
#>  Containing an ExperimentList class object of length 2:
#>  [1] y: SummarizedExperiment with 6 rows and 5 columns
#>  [2] x: SummarizedExperiment with 4 rows and 5 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
asTSE(x)
#> class: TreeSummarizedExperiment 
#> dim: 6 5 
#> metadata(1): dictionary
#> assays(1): y
#> rownames(6): y_1 y_2 ... y_5 y_6
#> rowData names(0):
#> colnames(5): anansi_ID_sample_1_1 anansi_ID_sample_2_1
#>   anansi_ID_sample_3_1 anansi_ID_sample_4_1 anansi_ID_sample_5_1
#> colData names(7): sample_id repeated ... score_b score_c
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(1): x
#> rowLinks: NULL
#> rowTree: NULL
#> colLinks: NULL
#> colTree: NULL

# MultiFactor
x <- randomMultiFactor(n_types = 3, n_features = 3)
as.list(x, use.names = TRUE)
#> $a2b
#>       a     b
#> 1 a_001 b_001
#> 2 a_001 b_002
#> 3 a_001 b_003
#> 4 a_002 b_003
#> 5 a_003 b_003
#> 
#> $b2c
#>       b     c
#> 1 b_001 c_001
#> 2 b_002 c_001
#> 3 b_002 c_002
#> 4 b_001 c_003
#> 5 b_003 c_003
#>