network_data: Creates Nodes and Edge-List For An OTU Table

Description Usage Arguments Value Author(s) Examples

Description

This function creates nodes and edge-list for an otu table, which can be used for network plotting

Usage

1
network_data(data, is.OTU=TRUE, metadata)

Arguments

data

an otu table of a species abundance matrix

is.OTU

whether or not data is an otu table

metadata

associated metadta of the otu table, should have same sampleIDs

Value

Return a list of network nodes and edges based on an otu table and the associated metadata

Author(s)

Wen Chen

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
data(ITS1, meta)
## Not run: 
ITS1.01<-filter.OTU(data=list(ITS1=ITS1), percent=0.01)[[1]]

# create nodes and edges lists
b<-network_data(ITS1.01, is.OTU=TRUE, meta)
b_node<-b[[1]]
b_edge<-b[[2]]
head(b_node)
head(b_edge)

library(igraph)
b1<-graph.data.frame(b_edge, directed=FALSE)
lev <- levels(factor(E(b1)$Crop))

# vertices size
V(b1)$size<-degree(b1)

# vertices color
Crop1<-rownames(meta)[meta$Crop=="Crop1"]
Crop2<-rownames(meta)[meta$Crop=="Crop2"]

## vertices representing samples from crop1 will be in red,
## vertices representing samples from crop2 will be in blue;
## vertices representing taxa will be in pink
V(b1)$color[which(is.element(V(b1)$name, Crop1))]<-"red"
V(b1)$color[which(is.element(V(b1)$name, Crop2))]<-"blue"
V(b1)$color[-which(is.element(V(b1)$name, c(Crop1, Crop2)))]<-"pink"
V(b1)$color

# edges color
col<-c("red", "blue")
for (i in 1:length(lev) ) { 
  E(b1)$color[E(b1)$Crop==lev[i]] <- col[i]
}

# plot
plot(b1, vertex.label.font=2,
         vertex.label.cex=0.5,
         layout=layout.kamada.kawai)

## End(Not run)

Example output

Loading required package: vegan
Loading required package: permute
Loading required package: lattice
This is vegan 2.4-4
Loading required package: ggplot2
sh: 1: cannot create /dev/null: Permission denied
sh: 1: cannot create /dev/null: Permission denied
[1] "26 otus in ITS1 met the filter requirment."
Using id as id variables
  node_name     ntype degree weighted_degree  Sample  City  Crop Plots
1 P1001.1M1 user_node     22           13458 Sample1 City1 Crop1     2
2 P1001.1M2 user_node     21            8485 Sample2 City1 Crop1     2
3 P1001.1M3 user_node     20           17396 Sample3 City1 Crop1     2
4 P1001.1M4 user_node     21            2065 Sample4 City1 Crop1     2
5 P1001.1M5 user_node     21           12867 Sample5 City2 Crop1     2
6 P1001.1M6 user_node     22            7596 Sample6 City2 Crop1     2
  Harvestmethod Harvestdate Ergosterol_ppm Province Latitude Longitude
1       Method1  2014-08-13            9.1       ON  45.4214  -75.6919
2       Method2  2014-08-13           9.16       ON  45.4214  -75.6919
3       Method1  2014-07-15          10.36       ON  45.4214  -75.6919
4       Method2  2014-07-15           11.6       ON  45.4214  -75.6919
5       Method1  2014-08-13           7.78       QC     45.5  -73.5667
6       Method2  2014-08-13           6.63       QC     45.5  -73.5667
       from                     to eweight  Sample  City  Crop Plots
1 P1001.1M1    101090_g__Epicoccum      90 Sample1 City1 Crop1     2
2 P1001.1M1         73303_k__Fungi      94 Sample1 City1 Crop1     2
3 P1001.1M1  17718_g__Cryptococcus    1114 Sample1 City1 Crop1     2
4 P1001.1M1   104295_g__Alternaria    1100 Sample1 City1 Crop1     2
5 P1001.1M1  45347_g__Cryptococcus       9 Sample1 City1 Crop1     2
6 P1001.1M1 132126_g__Cryptococcus     219 Sample1 City1 Crop1     2
  Harvestmethod Harvestdate Ergosterol_ppm Province Latitude Longitude
1       Method1  2014-08-13            9.1       ON  45.4214  -75.6919
2       Method1  2014-08-13            9.1       ON  45.4214  -75.6919
3       Method1  2014-08-13            9.1       ON  45.4214  -75.6919
4       Method1  2014-08-13            9.1       ON  45.4214  -75.6919
5       Method1  2014-08-13            9.1       ON  45.4214  -75.6919
6       Method1  2014-08-13            9.1       ON  45.4214  -75.6919

Attaching package: 'igraph'

The following object is masked from 'package:vegan':

    diversity

The following object is masked from 'package:permute':

    permute

The following objects are masked from 'package:stats':

    decompose, spectrum

The following object is masked from 'package:base':

    union

Warning message:
In vattrs[[name]][index] <- value :
  number of items to replace is not a multiple of replacement length
 [1] "red"  "blue" "blue" "blue" "blue" "blue" "blue" "blue" "red"  "red" 
[11] "red"  "red"  "red"  "red"  "red"  "blue" "pink" "pink" "pink" "pink"
[21] "pink" "pink" "pink" "pink" "pink" "pink" "pink" "pink" "pink" "pink"
[31] "pink" "pink" "pink" "pink" "pink" "pink" "pink" "pink" "pink" "pink"
[41] "pink" "pink"

RAM documentation built on May 2, 2019, 3:04 p.m.