Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions R/consense.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

consense <- function(sN,minEdgeCC=length(sN),noLog = FALSE,silent = FALSE) {

#'Find consensus subnetworks
#'
# sN: List of subnetworks resulting after edge removal and
#'@param sN List of subnetworks
#'@param minEdgeCC minimum number of subnetworks an edge appears in to be kept
#'@param noLog if FALSE, save process to an .Rdata log file
#'@param silent if FALSE, print process to console in real time
#'@return A list of consensus subnetworks as igraph objects

#INPUTS:
# sN: List of subnetworks
# minEdgeCC: minimum number of subnetworks an edge appears in to be kept# method: method of edge removal
# noLog: if FALSE, save process to an .Rdata log file# delta: threshold for edge removal for given method
# silent: if FALSE, print process to console in real time# EGG: 'Heat Diffusion' annotated AGG, iGraph object.

#OUTPUT:
# cSN: List of subnetworks resulting after edge removal and
# subnetwork construction


#minEdgeCC = 0 #length(outputGraphs)
numGraphs <- length(outputGraphs)
Copy link
Owner

@hyginn hyginn Apr 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outputGraphs undefined. sN?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that should have been sN.

sNEdges <- vector(mode="list", length=numGraphs)
sNVerts <- vector(mode="list", length=numGraphs)
edgePairsList <- c() #vector(mode="list", length=numGraphs)
for (i in 1:numGraphs){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make a hash with keys paste()'ed from incident vertices, and just count occurrences. Our input graphs are simple, so any observation must stem from a different subnetwork. They are also directed, so you don't even have to worry about whether a-b is also b-a (Nb. this problem is usually resolved in undirected graphs by lexically sorting the incident vertices). Just dump the incident edges into a data frame for each input graph, then iterate over the rows, make keys and create a hash entry (if new) or increment its value (if it exists).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Boris. I was trying to create the pasted combined vertices in edgePairs on line 40. I was using a list, and tried to create the count table from that list, but I agree that your strategy makes more sense.

print(i)
sNEdges <- igraph::as_data_frame(outputGraphs[[i]], what = "edges")
sNVerts <- igraph::as_data_frame(outputGraphs[[i]], what = "vertices")
# Find edgepairs
numEdges <- nrow(sNEdges)
print(sNEdges)
edgePairs <- character(length=numEdges) # * 2)
for (j in 1:numEdges){
print(edgePairs)
edgePairs[j] <- paste(sNEdges[j, 'from'], sNEdges[j, 'to'], sep='-')
}
edgePairsList <- c(edgePairsList, edgePairs)
}

# Weigh edges based on how many subnetworks they occur in
boolIndex <- as.vector(table(edgePairsList) >= minEdgeCC)
edgesToKeep <- edgePairsList[boolIndex]

# Keep only edges with weight > minEdgeCC

# Extract connected components

return(cSN)
}