graphBAM-class {graph} | R Documentation

## EXPERIMENTAL class "graphBAM"

### Description

The graphBAM class represents a graph as an adjacency matrix. The adjacency matrix is stored as a bit array using a `raw` vector to reduce the memory footprint and speed operations like `graphIntersection`. This class is EXPERIMENTAL and its API is subject to change.

### Usage

    graphBAM(df, nodes=NULL, edgemode="undirected", ignore_dup_edges = FALSE)

### Arguments

`df` | A `data.frame` with three columns: "from", "to" and "weight". Columns "from" and "to" can be either factors or character vectors. Each row of `df` describes an edge in the resulting graph. The "weight" column must be numeric.
`nodes` | A character vector of node labels. Use this to add degree zero nodes to the graph. If `NULL`, the set of nodes found in `from` and `to` will be used.
`edgemode` | A string, one of "directed" or "undirected".
`ignore_dup_edges` | If `FALSE` (default), specifying duplicate edges in the input is an error. When set to `TRUE` duplicate edges are ignored. Edge weight values are ignored when determining duplicates. This is most useful for graph import and conversion.

### Constructors

The `GraphBAM` function is used to create new `graphBAM` instances. Edges are specified in a `data.frame`. For undirected graphs, reciprical edges should not be includes unless `ignoe_dup_edges` is `TRUE`.

### Extends

Class `"graph"`, directly.

### Methods for graphBAM objects

`addEdge(from, to, graph, weights)`

  Return a new `graphBAM` object with the specified edge(s) added. The `from` and `to` arguments must either be the same length or one of them must be of length one. Each time an edge is added, the entire graph is copied. For the purpose of building a graph it will often be more efficient to build up the list of edges and call `GraphBAM`.

`addNode(node, object)`

  Return a new `graphBAM` object with the specified node(s) added.

`clearNode(node, object)`

  This operation is not currently supported.

`edges(object, which)`

  Returns an adjacency list representation of the graph. The list will have an entry for each node with a vector of adjacent node labels or `character(0)`. For undirected graphs, `edges` returns the reciprocal edges. The optional argument `which` can be a character vector of node labels. When present, only entries for the specified nodes will be returned.

`inEdges(node, object)`

  (Not yet supported) Similar to the `edges` function, but the adjacency list maps nodes that have an edge to the given node instead of from the given node.

`isAdjacent(object, from, to)`

  Returns a logical vector indicating whether there is an edge corresponding to the elements in `from` and `to`. These vectors must have the same length, unless one has length one.

`nodes(object)`

  Return the node labels for the graph

`numEdges(object)`

  Returns the number of edges in the graph.

`numNodes(object)`

  Returns the number of nodes in the graph

`removeEdge(from, to, graph)`

  Return a new `graphBAM` object with the specified edges removed. The `from` and `to` arguments must be the same length unless one of them has length one.

`removeNode(node, object)`

  Returns a new `graphBAM` object with the specified node removed. Node and edge attributes corresponding to that node are also removed.

`edgeData(self, from, to, attr)`

  Access edge attributes. See help for `edgeData`.

`edgeDataDefaults(self, attr)`

  Access edge data default attributes .

`nodeDataDefaults(self, attr)`

  Access node data default attributes .

`edgeWeights(object, index)`

  Return the edge weights for the graph in adjacency list format. The optional argument `index` specified a character vector of nodes. In this case, only the weights for the specified nodes will be returned.

`extractFromTo(g)`

  Returns a data frame with column names "from", "to", and "weight" corresponding to the connected nodes in the graphBAM object.

`graphIntersect(x, y, nodeFun, edgeFun)`

  When given two `graphBAM` objects, `graphIntersect` returns a new `graphBAM` containing the nodes and edges in common between the two graphs. Both x and y should either be directed or undirected. The intersection is computed by first finding the intersection of the node sets, obtaining the resulting subgraphs, and finding the intersection of the resulting edge sets. Node/Edge attributes that are equal are carried over to the result. Non equal edge/node attributes will result in the corresponding attribute being set to NA. The user has the option of providing a named list of functions correspoding to the names of the edge attributes for resolving conflicting edge attributes. For resolving any of the conflicting node attributes the user has the option of providing a named `list` of functions corresponding to the node attribute names.

`graphUnion(x, y, nodeFun, edgeFun)`

  When given two `graphBAM` objects, `graphUnion` returns a new `graphBAM` containing the union of nodes and edges between the two graphs. The union is compted by first finding the union of the nodesets. Both x and y should be either directed or undirected. Node/Edge attributes that are equal are carried over to the result. Non equal edge/node attributes will result in the corresponding attribute being set to NA. The user has the option of providing a named list of functions correspoding to the names of the edge attributes for resolving conflicting edge attributes. For resolving any of the conflicting node attributes the user has the option of providing a named `list` of functions corresponding to the node attribute names.

`edgemode(object) <- value`

  Set the edgemode for the graph ("directed" or "undirected"). If the specified edgemode is the same, the object is returned without changes. Otherwise, a directed graph is converted to an undirected graph via `ugraph` and an undirected graph is returned such that each edge is interpreted as two edges, one in each direction.

`ugraph(graph)`

  Return an undirected version of the current graph. Conceptually, the arrows of a graph's directed edges are removed.

`nodes(object) <- value`

  Replacement of a `graphBAM` object's node labels is currently not supported. An error is raised if this method is called.

### Coercion

`graphBAM` objects can be coerced to `graphAM`, `graphNEL`, and `matrix` instances via `as(g, CLASS)`.

### Author(s)

N. Gopalakrishnan, S. Falcon

### Examples

        f <- c("a", "a", "b", "c", "d")
        t <- c("b", "c", "c", "d", "a")
        weight <- c(2.3, 2.3, 4.3, 1.0, 3.0)
        df <- data.frame(from=f, to=t, weight= weight)
        g <- graphBAM(df)
        nd <- nodes(g)
        nodeDataDefaults(g, attr ="color") <- "green"
        nodeData(g,n=c("b", "c"), attr ="color") <- "red"
        w1 <- edgeWeights(g)
        w2 <- edgeWeights(g,"a")
        w3 <- edgeWeights(g,1)
        d1 <- edges(g)
        d2 <- edges(g,c("a", "b"))
        e1 <- edgeData(g)
        e2 <- edgeData(g, "a", "c",attr="weight")
        em <- edgeMatrix(g)
        id <- isDirected(g)
        sg <- subGraph(c("a","c","d"), g)
        ft <- extractFromTo(g)
        am <- as(g,"graphAM")
        nl <- as(g,"graphNEL")
        mt <- as(g,"matrix")
        k  <- graphIntersect(g,g)
        k <- graphUnion(g,g)
        e <- removeEdgesByWeight(g,lessThan= 3.0)
        f <- removeNode("a", g)
        g

[Package graph version 1.62.0 Index]