Learn R Programming

MPSEM (version 0.4-4)

graph-functions: MPSEM graph Manipulation Functions

Description

A set of primitive functions for creating and munipulating MPSEM graphs.

Usage

pop.graph(n, vertex = list(), label = NULL)

add.vertex(x, n, vertex = list(), label = NULL)

add.edge(x, from, to, edge = list(), label = NULL)

rm.edge(x, id)

rm.vertex(x, id)

collapse.vertex(x, id)

Phylo2DirectedGraph(tp)

Value

The function returns a graph-class object. Objects returned by Phylo2DirectedGraph have a numeric

edge property called ‘distance’ featuring branch lengths, and a link{logical} vertex property called ‘species’ specifying whether a vertex is a tree tip or an internal node.

Arguments

n

The number of vertices to populate a new graph (pop.graph) or to add to an existing graph (add.vertex).

vertex

A list of vertex properties.

label

Labels to be given to edges or vertices.

x

A graph-class object.

from

The origins of the edges to be added (vertex labels or indices).

to

The destinations of the edges to be added (vertex labels or indices).

edge

A list of edge properties.

id

Indentity (label or index) of vertex or edge to be removed.

tp

Phylogenetic tree object of class ‘phylo’, as defined in ape-package.

Functions

  • pop.graph(): Create Graph

    Create a graph and populates it with vertices.

  • add.vertex(): Add Vertices

    Add vertices to an existing graph.

  • add.edge(): Add Edges

    Add edges to a graph.

  • rm.edge(): Remove Edges

    Remove edges from a graph.

  • rm.vertex(): Remove Vertices

    Remove vertices from a graph.

  • collapse.vertex(): Collapse Vertices

    Remove vertices from a graph: remove vertices together with their associated edges.

  • Phylo2DirectedGraph(): Phylogenetic Tree Conversion

    Create a new graph-class object from a phylo-class object (phylogenetic tree).

Author

tools:::Rd_package_author("MPSEM") Maintainer: tools:::Rd_package_maintainer("MPSEM")

Details

A new graph can be populated with n vertices using function pop.graph. Additional vertices can be added later with function add.vertex. The graphs so created contain no edges; the latter are added using function add.edge. Vertices and edges are removed using functions rm.vertex and rm.edge, respectively.

Function collapse.vertex allows one to remove a vertex while reestablishing the connections between the vertices located above and below that vertex using a new set of edges.

Function Phylo2DirectedGraph uses the MPSEM graph functions to convert a rooted phylogenetic tree of class ‘phylo’ (see ape-package) to a graph-class object. It recycles tip labels. It also creates default node labels if they were absent from the ‘phylo’ object, and uses them as vertex labels. The resulting acyclic graph can then be edited to represent cases that do not have a tree topology.

References

Guénard, G., Legendre, P., and Peres-Neto, P. 2013. Phylogenetic eigenvector maps: a framework to model and predict species traits. Methods in Ecology and Evolution 4: 1120-1131

Makarenkov, V., Legendre, L. & Desdevise, Y. 2004. Modelling phylogenetic relationships using reticulated networks. Zoologica Scripta 33: 89-96

Blanchet, F. G., Legendre, P. & Borcard, D. 2008. Modelling directional spatial processes in ecological data. Ecological Modelling 215: 325-336

See Also

graph-class.

Examples

Run this code
## Populate a graph with 7 vertices labeled A-G having properties x and y:
gr <- pop.graph(n=7,
                vertex=list(x=rnorm(7,0,1),y=rnorm(7,0,1)),
                label=c("A","B","C","D","E","F","G"))
gr

## Adding 3 vertices H, I, and J with property x (y is absent) and a new
## property z (type character), which is unknown for A-G:
gr <- add.vertex(x=gr,
                 n=3,
                 label=c("H","I","J"),
                 vertex=list(x=rnorm(3,0,1),z=c("A","B","C")))
gr
gr$vertex

## Adding 10 edges, labeled E1-E10 and with properties a and b, to the graph:
gr <- add.edge(x=gr,
               from=c("A","B","B","C","C","D","D","E","E","F"),
               to=c("A","C","D","E","F","F","G","H","I","J"),
               edge=list(a=rnorm(10,0,1),b=rnorm(10,0,1)),
               label=paste("E",1:10,sep=""))
gr
gr$edge

## Removing edges 2, 4, and 7 from the graph:
print(rm.edge(gr,id=c(2,4,7)))

## Removing vertices 1, 3, 7, and 10 from the graph:
print(rm.vertex(gr,id=c(1,3,7,10)))
# Notice that the edges that had one of the removed vertex as their
# origin or destination are also removed:
print.default(rm.vertex(gr,id=c(1,3,7,10)))

## Vertex collapsing.
x <- pop.graph(n=9,label=c("A","B","C","D","E","F","G","H","I"))
x <- add.edge(x,from=c("A","A","B","B","C","C","D","D","E","E"),
              to=c("B","C","D","E","E","I","F","G","G","H"),
              label=paste("E",1:10,sep=""),
              edge=list(length=c(1,2,3,2,1,3,2,2,1,3)))
print.default(x)
for(i in c("A","B","C","D","E","F","G","H","I"))
  print(collapse.vertex(x,id=i))

if(require(ape)) {
  tree1 <- read.tree(
    text=paste(
      "(((A:0.15,B:0.2)N4:0.15,C:0.35)N2:0.25,((D:0.25,E:0.1)N5:0.3,",
      "(F:0.15,G:0.2)N6:0.3)N3:0.1)N1;",sep=""))
  x <- Phylo2DirectedGraph(tree1)
  print(x)
}

Run the code above in your browser using DataLab