|
a |
|
b/R/NetAnalysis.R |
|
|
1 |
#' @title Networking analysis. |
|
|
2 |
#' @description This function checks the connectivity degree and the betweenness |
|
|
3 |
#' centrality, which reflect the communication flow in the defined PPI |
|
|
4 |
#' networks |
|
|
5 |
#' @export |
|
|
6 |
#' @param data Protein-protein interaction data frame resulted from running the |
|
|
7 |
#' PPI function. |
|
|
8 |
#' @param export if `TRUE`, exports the analysis table as a csv file |
|
|
9 |
#' @param FileName suffix for the file name (if export = TRUE) |
|
|
10 |
#' @importFrom igraph graph.data.frame as_adjacency_matrix distance_table |
|
|
11 |
#' average.path.length get.adjacency V E mean_distance betweenness |
|
|
12 |
#' @importFrom NetIndices GenInd |
|
|
13 |
#' @return A network analysis table |
|
|
14 |
NetAnalysis <- function( |
|
|
15 |
data, export = FALSE, FileName = "NetworkAnalysisTable-1") { |
|
|
16 |
if (length(data[, 1]) < 1) { |
|
|
17 |
stop("No Protein-Protein Interactions") |
|
|
18 |
} |
|
|
19 |
df <- data[, -c(1, 2)] |
|
|
20 |
gg <- graph.data.frame(df) |
|
|
21 |
betweenness <- betweenness(gg) |
|
|
22 |
betweenness.table <- data.frame(betweenness) |
|
|
23 |
names <- rownames(betweenness.table) |
|
|
24 |
rownames(betweenness.table) <- NULL |
|
|
25 |
degree <- degree(gg) |
|
|
26 |
|
|
|
27 |
Duplicated <- data[duplicated(data), ] |
|
|
28 |
if (length(Duplicated[, 1]) > 0) { |
|
|
29 |
degree <- degree / 2 |
|
|
30 |
} |
|
|
31 |
|
|
|
32 |
degree.table <- data.frame(degree) |
|
|
33 |
names <- rownames(degree.table) |
|
|
34 |
rownames(degree.table) <- NULL |
|
|
35 |
AnalysisTable <- cbind(names, degree.table, betweenness.table) |
|
|
36 |
|
|
|
37 |
if (export) { |
|
|
38 |
write.csv(AnalysisTable, file = paste0(FileName, ".csv")) |
|
|
39 |
} |
|
|
40 |
|
|
|
41 |
test.graph.adj <- get.adjacency(gg, sparse = FALSE) |
|
|
42 |
test.graph.properties <- GenInd(test.graph.adj) |
|
|
43 |
message("Number of nodes: ", test.graph.properties$N) |
|
|
44 |
message("Number of links: ", test.graph.properties$Ltot) |
|
|
45 |
message("Link Density: ", test.graph.properties$LD) |
|
|
46 |
message("The connectance of the graph: ", test.graph.properties$C) |
|
|
47 |
message("Mean Distences", mean_distance(gg)) |
|
|
48 |
message("Average Path Length", average.path.length(gg), "\n") |
|
|
49 |
AnalysisTable <- |
|
|
50 |
AnalysisTable[order(AnalysisTable[, 2], decreasing = TRUE), ] |
|
|
51 |
return(AnalysisTable) |
|
|
52 |
} |