Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kr-swapnil committed Mar 14, 2024
1 parent a069b39 commit aab9499
Show file tree
Hide file tree
Showing 14 changed files with 251,431 additions and 106 deletions.
17 changes: 8 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ Maintainer: Swapnil Kumar <swapnil.kr@yahoo.com>
Depends: R (>= 3.0.0), igraph
Imports: parallel
Suggests: knitr, rmarkdown
Description: Performs network vulnerability analysis and help to identify vulnerable or critical proteins (VPs) and protein pairs (VPPs)
for a given protein-protein interaction (PPI) network. Hence, network vulnerability analysis is an approach to identify VPs and
VPPs by assessing networks based on its topological properties. The VPs and VPPs are identified based on fourteen different
topological properties calculated for networks as constructed by deleting all nodes/proteins using one node and two nodes
approaches, respectively, from the original network under investigation. Further, it helps to identify influential proteins in a
given network based on the escape velocity centrality (EVC) and extended EVC (EVC+). This package provides the capabilities to use
multiple cores on Linux/macOS to parallelize the process using parallel package. It also helps to identify hubs and bottlenecks
present in the network based on the well-known pareto-principle of 80:20 rule.
Description: Performs network vulnerability analysis and help to identify vulnerable or critical proteins (VPs), protein pairs (VPPs), and
protein triplets (VPTs) for a given protein-protein interaction (PPI) network. Hence, network vulnerability analysis is an approach
to identify VPs, VPPs, and VPTs by assessing networks based on its topological properties. The VPs, VPPs, and VPTs are identified
based on fourteen different topological properties calculated for networks as constructed by deleting all nodes/proteins using one,
two, and three nodes approaches, respectively, from the original network under investigation. Further, it helps to identify
influential proteins in a given network based on the escape velocity centrality (EVC) and extended EVC (EVC+). This package
provides the capabilities to use multiple cores on Linux/macOS to parallelize the process using parallel package. It also helps to
identify hubs and bottlenecks present in the network based on the well-known pareto-principle of 80:20 rule.
License: GPL (>= 3)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
Expand All @@ -28,4 +28,3 @@ Packaged: 2022-01-27 14:45:21 IST
NeedsCompilation: no
Repository: GitHub, CRAN
Date/Publication: 2022-01-29 00:34:42
LazyData: true
16 changes: 15 additions & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ NULL
#' Output of netva function for all VIPs in the breast cancer PPIN from two nodes approach
#'
#'
#' An dataframe with 25838 rows (proteins pairs) and 14 columns (topological properties).
#' An dataframe with 25838 rows (protein pairs) and 14 columns (topological properties).
#'
#'
#' @name netva_res_2n
Expand All @@ -39,3 +39,17 @@ NULL
#' @references netva_res_2n = netva(vl, bc.net, ncore = 30).
NULL

#' Output of netva function for all VIPs in the breast cancer PPIN from three nodes approach
#'
#'
#' An dataframe with 251270 rows (protein triplets) and 14 columns (topological properties).
#'
#'
#' @name netva_res_3n
#' @docType data
#' @title Output of netva function as dataframe for all VIPs in the breast cancer PPIN from three nodes approach.
#'
#' @keywords output-datasets
#' @references netva_res_3n = netva(vl, bc.net, ncore = 30).
NULL

64 changes: 36 additions & 28 deletions R/detectHB.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @param perturb Percentage value to rewire edges.
#' @param iter Number of iterations to perform rewiring and construction of new rewired networks. The default value is round(100/perturb).
#' @param ng Number of new graphs/networks to be constructed. The default value is the value of iter.
#' @return A numeric vector containing all possible hubs with hub proteins' names and corresponding degree values as identified in the given network.
#' @return If validate = TRUE, a list with two (named) numeric vectors, first containing all possible hubs with their degree values before edge perturbation and second containing all possible hubs with their degree values (from the original network) after the edge perturbation. Otherwise, a (named) numeric vector with all possible hubs with their corresponding degree values as identified in the given network.
#' @export
detectHubs <- function(net, method = "ETP", p = 20, validate = TRUE, perturb = 5, iter = round(100/perturb), ng = iter){
d <- igraph::degree(net)
Expand All @@ -23,13 +23,17 @@ detectHubs <- function(net, method = "ETP", p = 20, validate = TRUE, perturb = 5
pg <- perturbNet(g = net, p = perturb, iter)
for(i in 1:length(pg)){
kn <- detectkn(g = pg[[i]], t = degree(pg[[i]]), p)
kn.vec = c(kn.vec, names(kn))
kn.vec <- c(kn.vec, names(kn))
}
kn.pg = kn.vec[which(table(kn.vec) == ng)]
kn.pg <- kn.vec[which(table(kn.vec) == ng)]
hubs2 <- intersect(names(hubs), kn.pg)
hub.list <- list(hubs.bp = hubs, hubs.ap = hubs[hubs2])
return(hub.list)
}else{
hub.list <- hubs
return(hub.list)
}
hubs2 <- intersect(names(hubs), kn.pg)
hub.list <- list(hubs.bp = hubs, hubs.ap = hubs[hubs2])
return(hub.list)

}

#' Identify all possible bottlenecks based on the pareto principle of Eighty-twenty rule (by default) for a given network
Expand All @@ -41,7 +45,7 @@ detectHubs <- function(net, method = "ETP", p = 20, validate = TRUE, perturb = 5
#' @param perturb Percentage value to rewire edges.
#' @param iter Number of iterations to perform rewiring and construction of new rewired networks. The default value is round(100/perturb).
#' @param ng Number of new graphs/networks to be constructed. The default value is the value of iter.
#' @return A numeric vector containing all possible bottlenecks with bottleneck proteins' names and corresponding betweenness values as identified in the given network.
#' @return If validate = TRUE, a list with two (named) numeric vectors, first containing all possible bottlenecks with their betweenness values before edge perturbation and second containing all possible bottlenecks with their betweenness values (from the original network) after the edge perturbation. Otherwise, a (named) numeric vector with all possible bottlenecks with their corresponding betweenness values as identified in the given network.
#' @export
detectBottlenecks <- function(net, method = "ETP", p = 20, validate = TRUE, perturb = 5, iter = round(100/perturb), ng = iter){
b <- igraph::betweenness(net)
Expand All @@ -52,17 +56,21 @@ detectBottlenecks <- function(net, method = "ETP", p = 20, validate = TRUE, pert
}

if(validate == TRUE){
kn.vec = c()
kn.vec <- c()
pg <- perturbNet(g = net, p = perturb, iter)
for(i in 1:length(pg)){
kn <- detectkn(g = pg[[i]], t = betweenness(pg[[i]]), p)
kn.vec = c(kn.vec, names(kn))
kn <- detectkn(g = pg[[i]], t = igraph::betweenness(pg[[i]]), p)
kn.vec <- c(kn.vec, names(kn))
}
kn.pg = kn.vec[which(table(kn.vec) == ng)]
kn.pg <- kn.vec[which(table(kn.vec) == ng)]
bottlenecks2 <- intersect(names(bottlenecks), kn.pg)
bot.list <- list(bottlenecks.bp = bottlenecks, bottlenecks.ap = bottlenecks[bottlenecks2])
return(bot.list)
}else{
bot.list <- bottlenecks
return(bot.list)
}
bottlenecks2 <- intersect(names(bottlenecks), kn.pg)
bot.list <- list(bottlenecks.bp = bottlenecks, bottlenecks.ap = bottlenecks[bottlenecks2])
return(bot.list)

}

#' Identify key nodes for a given network based on either degree or betweenness values
Expand Down Expand Up @@ -94,24 +102,24 @@ detectkn <- function(g, t, p){
#' @return A list of newly constructed graphs and there will be n graphs in this list, where n is equal to the value of iter.
#' @noRd
perturbNet <- function(g, p, iter){
n = round(ecount(g)*(p/100))
on.el = as_edgelist(g)
temp.el = on.el
on.el = as.data.frame(on.el)
gl = vector("list", iter)
n <- round(igraph::ecount(g)*(p/100))
on.el <- igraph::as_edgelist(g)
temp.el <- on.el
on.el <- as.data.frame(on.el)
gl <- vector("list", iter)
for(i in 1:iter){
if(n <= nrow(temp.el)){
j = sample(nrow(temp.el), n)
j <- sample(nrow(temp.el), n)
}else{
j = sample(nrow(temp.el))
j <- sample(nrow(temp.el))
}
br.el = as.data.frame(temp.el[j,])
ar.el = transform(br.el, V1 = sample(V1))
rem.el = setdiff(on.el, br.el)
mut.el = rbind(rem.el, ar.el)
mut.net = graph.data.frame(mut.el, directed=F)
gl[[i]] = mut.net
temp.el = temp.el[-j,]
br.el <- as.data.frame(temp.el[j,])
ar.el <- transform(br.el, V1 = sample(V1))
rem.el <- setdiff(on.el, br.el)
mut.el <- rbind(rem.el, ar.el)
mut.net <- igraph::graph.data.frame(mut.el, directed=F)
gl[[i]] <- mut.net
temp.el <- temp.el[-j,]
}
return(gl)
}
Expand Down
54 changes: 27 additions & 27 deletions R/evc.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#========================================================================================================================================
#' Calculates escape velocity centrality (normal and extended version)
#'
#' Calculates escape velocity centrality (EVC, evc) and extended escape velocity centrality (EVC+, evc.plus)
#' of all vertices in the network under study [Ullah et al., 2022].
#' Calculates escape velocity centrality (EVC/evc) and extended escape velocity centrality (EVC+/evc.plus)
#' of all vertices in the network under study.
#'
#' @param g An igraph graph object.
#' @param alpha A tunable factor with value between 0.1 to 1. The default value of alpha is 1.
Expand All @@ -14,46 +14,46 @@
#' @references Ullah A. et al. (2022). Escape velocity centrality: escape influence-based key nodes identification in complex networks, Applied Intelligence, 1-19.
#'
#' @export
evc = function(g, alpha = 1, mode = "all"){
a = alpha
evc.vec = c()
evc.vec2 = c()
n = c()
dv = igraph::degree(g)
evc <- function(g, alpha = 1, mode = "all"){
a <- alpha
evc.vec <- c()
evc.vec2 <- c()
n <- c()
dv <- igraph::degree(g)
s.paths <- igraph::shortest.paths(g, algorithm = "dijkstra")
nv = igraph::vcount(g)
ks = igraph::coreness(g, mode)
v = igraph::vertex_attr(g)$name
nv <- igraph::vcount(g)
ks <- igraph::coreness(g, mode)
v <- igraph::vertex_attr(g)$name

pb <- txtProgressBar(min = 0, max = nv, style = 3, width = 50, char = "=")

for(i in 1:nv){
r1 = 0
r2 = 0
r1 <- 0
r2 <- 0
for(j in 1:nv){
if(i != j){
sp = s.paths[v[i],v[j]]
dvi = dv[[v[i]]]
ksi = ks[[v[i]]]
ksj = ks[[v[j]]]
evc = sqrt((2*a*dvi)/sp)
r1 = sum(r1, evc)
sp <- s.paths[v[i],v[j]]
dvi <- dv[[v[i]]]
ksi <- ks[[v[i]]]
ksj <- ks[[v[j]]]
evc <- sqrt((2*a*dvi)/sp)
r1 <- sum(r1, evc)

evc.p = sqrt((2*a*dvi*(ksi + ksj))/sp)
r2 = sum(r2, evc.p)
evc.p <- sqrt((2*a*dvi*(ksi + ksj))/sp)
r2 <- sum(r2, evc.p)
}
}
evc.vec = c(evc.vec, r1)
evc.vec2 = c(evc.vec2, r2)
n = c(n, v[i])
evc.vec <- c(evc.vec, r1)
evc.vec2 <- c(evc.vec2, r2)
n <- c(n, v[i])

setTxtProgressBar(pb, i)
}
close(pb)

names(evc.vec) = n
names(evc.vec2) = n
evc.list = list(evc = evc.vec, evc.plus = evc.vec2)
names(evc.vec) <- n
names(evc.vec2) <- n
evc.list <- list(evc = evc.vec, evc.plus = evc.vec2)
return(evc.list)
}

58 changes: 29 additions & 29 deletions R/netva.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ nva <- function(v, net){

g <- igraph::delete.vertices(net, v)

nva.res[2] <- mean(igraph::betweenness(g))
nva.res[3] <- mean(igraph::closeness(g), na.rm=T)
nva.res[5] <- mean(igraph::eccentricity(g))
nva.res[1] <- mean(igraph::betweenness(g))
nva.res[2] <- mean(igraph::closeness(g), na.rm=T)
nva.res[3] <- mean(igraph::eccentricity(g))
nva.res[4] <- mean(igraph::degree(g))
nva.res[6] <- igraph::average.path.length(g)
nva.res[1] <- igraph::clusters(g)$no
nva.res[5] <- igraph::average.path.length(g)
nva.res[6] <- igraph::components(g)$no
nva.res[7] <- igraph::transitivity(g)
nva.res[8] <- cohesiveness(v, net)
nva.res[9] <- compactness(v, net)
nva.res[10] <- igraph::global_efficiency(g)
nva.res[14] <- heterogeneity(g)
nva.res[11] <- igraph::centr_degree(g)$centralization
nva.res[12] <- igraph::graph.density(g)
nva.res[13] <- igraph::diameter(g)
nva.res[11] <- heterogeneity(g)
nva.res[12] <- igraph::centr_degree(g)$centralization
nva.res[13] <- igraph::graph.density(g)
nva.res[14] <- igraph::diameter(g)

return(nva.res)
}
Expand Down Expand Up @@ -65,14 +65,14 @@ netva <- function(vl, net, ncore = 1){
}
nva.df <- data.frame(matrix(unlist(res), byrow=T, nrow=length(res), ncol=14))

vl2 = c()
vl2 <- c()
for(i in 1:length(vl)){
if(class(vl[[i]]) == "igraph.vs"){
j = paste(igraph::as_ids(vl[[i]]), sep = "", collapse = " ")
j <- paste(igraph::as_ids(vl[[i]]), sep = "", collapse = " ")
}else{
j = paste(vl[[i]], sep = "", collapse = " ")
j <- paste(vl[[i]], sep = "", collapse = " ")
}
vl2 = c(vl2, j)
vl2 <- c(vl2, j)
}

rownames(nva.df) <- vl2
Expand Down Expand Up @@ -108,22 +108,22 @@ cohesiveness <- function(v = NULL, net, p = 0.1){
if(length(v) == 0){
#Calculating cohesiveness of complete network (default)
subnet <- net
twe.wisubnet <- sum(strength(subnet))
twe.wosubnet <- sum(strength(net, vids = vertex_attr(subnet)$name))
twe.wisubnet <- sum(igraph::strength(subnet))
twe.wosubnet <- sum(igraph::strength(net, vids = igraph::vertex_attr(subnet)$name))
}else{
#Calculating cohesiveness of subnetwork after removal of v
cl <- clusters(net)
cl <- igraph::components(net)
if(class(v) == "igraph.vs"){
v = as_ids(v)
v <- igraph::as_ids(v)
i <- which(names(cl$membership) %in% v)
}else{
i <- which(names(cl$membership) %in% v)
}
#i <- which(names(cl$membership) %in% v)
subnet <- subgraph(net, which(cl$membership == cl$membership[[i]]))
subnet <- delete.vertices(subnet, v)
twe.wisubnet <- sum(strength(subnet))
twe.wosubnet <- sum(strength(delete.vertices(net, v), vids = vertex_attr(subnet)$name))
subnet <- igraph::subgraph(net, which(cl$membership %in% cl$membership[i]))
subnet <- igraph::delete.vertices(subnet, v)
twe.wisubnet <- sum(igraph::strength(subnet))
twe.wosubnet <- sum(igraph::strength(igraph::delete.vertices(net, v), vids = igraph::vertex_attr(subnet)$name))
}
cohe.cent <- twe.wisubnet/(twe.wosubnet + p)
return(cohe.cent)
Expand All @@ -142,23 +142,23 @@ compactness <- function(v = NULL, net, p = 0.1){
if(length(v) == 0){
#Calculating compactness of complete network (default)
subnet <- net
tnc.wisubnet <- length(max_cliques(subnet, 3, 3))
tnc.wosubnet <- length(max_cliques(net, 3, 3, vertex_attr(subnet)$name))
tnc.wisubnet <- length(igraph::max_cliques(subnet, 3, 3))
tnc.wosubnet <- length(igraph::max_cliques(net, 3, 3, igraph::vertex_attr(subnet)$name))
}else{
#Calculating compactness of subnetwork after removal of v
cl <- clusters(net)
cl <- igraph::components(net)
if(class(v) == "igraph.vs"){
v = as_ids(v)
v <- igraph::as_ids(v)
i <- which(names(cl$membership) %in% v)
}else{
i <- which(names(cl$membership) %in% v)
}
#i <- which(names(cl$membership) %in% v)
subnet <- subgraph(net, which(cl$membership == cl$membership[[i]]))
subnet <- delete.vertices(subnet, v)
tnc.wisubnet <- length(max_cliques(subnet, 3, 3))
subnet <- igraph::subgraph(net, which(cl$membership %in% cl$membership[i]))
subnet <- igraph::delete.vertices(subnet, v)
tnc.wisubnet <- length(igraph::max_cliques(subnet, 3, 3))
#vnc.subnet <- length(max_cliques(subnet, 3, 3, v))
tnc.wosubnet <- length(max_cliques(delete.vertices(net, v), 3, 3, vertex_attr(subnet)$name))
tnc.wosubnet <- length(igraph::max_cliques(igraph::delete.vertices(net, v), 3, 3, igraph::vertex_attr(subnet)$name))
}
comp.cent <- tnc.wisubnet/(tnc.wosubnet + p)
return(comp.cent)
Expand Down
2 changes: 1 addition & 1 deletion data-raw/netva_res_2n.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Output of netva function for all VIPs in the breast cancer PPIN from two nodes approach
#'
#'
#' An dataframe with 25838 rows (proteins pairs) and 14 columns (topological properties).
#' An dataframe with 25838 rows (protein pairs) and 14 columns (topological properties).
#'
#'
#' @name netva_res_2n
Expand Down
17 changes: 17 additions & 0 deletions data-raw/netva_res_3n.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#' Output of netva function for all VIPs in the breast cancer PPIN from three nodes approach
#'
#'
#' An dataframe with 251270 rows (protein triplets) and 14 columns (topological properties).
#'
#'
#' @name netva_res_3n
#' @docType data
#' @title Output of netva function as dataframe for all VIPs in the breast cancer PPIN from three nodes approach.
#'
#' @keywords datasets
#' @references netva_res_3n = netva(vl, bc.net, ncore = 30).

#Making binary data available for the demonstration of NetVA
netva_res_3n = read.table("data-raw/netva_result_3node_approach.txt", head = TRUE, row.names = 1, sep = "\t")
usethis::use_data(netva_res_3n)

Loading

0 comments on commit aab9499

Please sign in to comment.