Skip to contents

The assignSampleExpression function calculates and assigns sample expression values to edges in an input graph using specified sample expression data. This function augments an input graph with additional edge attributes representing aggregated sample expression values based on gene information associated with the edges.

Usage

assignSampleExpression(
  igraph,
  sample_expr,
  gene_column = "symbol",
  attr_name = "edge_sum",
  output_graph = FALSE
)

Arguments

igraph

An igraph object representing the graph to which sample expression data should be assigned.

sample_expr

A named numeric vector containing sample expression values for individual genes. The names of the vector should correspond to gene identifiers used in the gene_column.

gene_column

A character string specifying the name of the edge attribute in the graph that contains gene identifiers. Defaults to "symbol".

attr_name

A character string specifying the name of the edge attribute to which the aggregated sample expression values should be assigned. Defaults to "edge_sum".

output_graph

A logical value indicating whether the function should return the graph with assigned edge attributes (TRUE) or just a vector of aggregated expression values (FALSE). Defaults to FALSE.

Value

If output_graph is TRUE, returns a modified igraph object with edge attributes assigned. If output_graph is FALSE, returns a numeric vector containing the aggregated sample expression values for each edge.

Note

The function assumes that the input graph has edge attributes containing gene identifiers (default column name: "symbol"), and the sample_expr vector contains numeric expression values for those genes. The function uses the igraph package for working with graphs and edge attributes.

Examples

# Create a sample igraph object
library(igraph)
g <- make_ring(10)
E(g)$symbol <- sample(letters, 10, replace = TRUE)

# Create a sample expression vector
sample_expr <- setNames(runif(26), letters)

# Assign sample expression values to graph edges
g_with_expr <- assignSampleExpression(g, sample_expr, output_graph = TRUE)

# Get the aggregated sample expression values as a vector
edge_expr_vec <- assignSampleExpression(g, sample_expr, output_graph = FALSE)