-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSimpleNetworkPlotter.R
37 lines (32 loc) · 1.69 KB
/
SimpleNetworkPlotter.R
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
require(plyr)
require(dplyr)
require(ape)
require(vegan)
require(data.table)
require(igraph)
require(network)
require(stringr)
#Plot co-occurrence networks generated by https://github.com/levisimons/SCCWRP/blob/master/StreamNetworkGeneratorVcluster.R
setwd("~/Desktop/SCCWRP")
#Set network file input.
#networkFile <- "LUSweepCAWatershedPerm100SantaClaraYears9Reps6MeanLU21.29332588708nTaxa148Network.txt"
networkFile <- "LUSweepCAWatershedPerm100WestWalkerYears9Reps8MeanLU0nTaxa152Network.txt"
#Read in network file.
networkdata <- read.delim(networkFile,header=TRUE, sep="\t",as.is=T,check.names=FALSE)
#Filter out association network data based on P and Q scores, for the local similarity
#between two factors, with values less than a particuar threshold.
networkdata <- filter(networkdata, P <= 1e-4)
networkdata <- filter(networkdata, Q <= 1e-4)
names(networkdata)[names(networkdata)=="LS"]<-"weight"
#Create network graph object.
networkgraph=graph.data.frame(networkdata,directed=FALSE)
#Plot graph
V(networkgraph)$size <- 3
E(networkgraph)$color <- ifelse(E(networkgraph)$weight > 0, "blue","red")
plot(networkgraph,vertex.label=NA,edge.width=1*abs(E(networkgraph)$weight),layout=layout_with_dh(networkgraph))
#Read in analyzed network data to pull relevant network measures.
networkAnalysis <- read.table("LUSweepCAWatershedPerm100Networks.txt",header=TRUE, sep="\t",as.is=T,skip=0,fill=TRUE,check.names=FALSE)
#Calculate network connectance.
networkAnalysis$C <- (2*networkAnalysis$networkEdgecount)/(networkAnalysis$N*(networkAnalysis$N-1))
#Pull the calculated network parameters for a given network.
networkAnalysis[which(networkAnalysis$filename==networkFile),c("M","zeta","lambda_network_m","C","meanStrength")]