Skip to contents

Utilities for extracting and adding node-associated features stored in the fdata container of a GraphSpace object.

Usage

# S4 method for class 'GraphSpaceInterface'
gs_fdata(x)

# S4 method for class 'GraphSpace'
gs_fdata(x) <- value

# S4 method for class 'GraphSpaceInterface'
gs_nfeatures(x)

# S4 method for class 'GraphSpaceInterface'
gs_features(x)

# S4 method for class 'GraphSpaceInterface'
gs_fdata(x) <- value

# S4 method for class 'GraphSpaceInterface'
gs_fdata_type(x)

# S4 method for class 'GraphSpaceInterface'
gs_fdata_type(x) <- value

gs_fetch_features(x, vars = NULL, as_df = FALSE)

gs_add_features(x, data)

Arguments

x

A GraphSpace object.

value

Replacement value for the selected slot or attribute.

vars

Character vector specifying feature names to extract. If NULL, all features are returned.

as_df

Logical. If TRUE, returns a data.frame. Otherwise returns the original backend representation.

data

A matrix-like or data.frame object containing node features, with node identifiers in columns (features x nodes) or in rows (nodes x features); it is stored as features x nodes.

Value

  • gs_fetch_features() returns a matrix-like object or data.frame containing the selected node features.

  • gs_add_features() returns a modified GraphSpace object.

Details

gs_fdata() returns the stored matrix, features x nodes. gs_fetch_features() returns nodes x features, for the selected features.

gs_fdata<- replaces the whole feature matrix, while gs_add_features() adds features to it, replacing those with the same names.

gs_fdata_type() gives what the feature data hold (e.g. "logcounts"), as recorded by as.GraphSpace, or NULL; the reverse coercions (e.g. gs_to_sce) use it by default. gs_fdata_type<- sets it.

Examples

library(RGraphSpace)

# Load a demo igraph and create a GraphSpace object
data('gtoy1', package = 'RGraphSpace')
gs <- GraphSpace(gtoy1)
#> Validating the 'igraph' object...
#> Ignoring graph-level attributes: 'name', 'mode', 'center'
#> Creating a 'GraphSpace' object...

# Add a sparse Matrix aligned to nodes
library(Matrix)
mtx <- Matrix(0, gs_vcount(gs), 2)
rownames(mtx) <- rownames(gs)
colnames(mtx) <- c("feature1","feature2")
gs_fdata(gs) <- mtx

# Feature names
gs_features(gs)
#> [1] "feature1" "feature2"

# Feature count
gs_nfeatures(gs)
#> [1] 2

# A feature matrix with node identifiers as row names
feats <- matrix(as.numeric(seq_len(gs_vcount(gs) * 3)), ncol = 3,
  dimnames = list(rownames(gs), c("geneA", "geneB", "geneC")))

# Add features (rows are matched and reordered to the nodes)
gs <- gs_add_features(gs, feats)
gs_features(gs)
#> [1] "feature1" "feature2" "geneA"    "geneB"    "geneC"   

# Fetch all features, or a subset as a data.frame
gs_fetch_features(gs)
#> 5 x 5 Matrix of class "dgeMatrix"
#>    feature1 feature2 geneA geneB geneC
#> n1        0        0     1     6    11
#> n2        0        0     2     7    12
#> n3        0        0     3     8    13
#> n4        0        0     4     9    14
#> n5        0        0     5    10    15
gs_fetch_features(gs, vars = c("geneA", "geneC"), as_df = TRUE)
#>    geneA geneC
#> n1     1    11
#> n2     2    12
#> n3     3    13
#> n4     4    14
#> n5     5    15