-
Notifications
You must be signed in to change notification settings - Fork 16
Initial code for consense #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) | ||
| sNEdges <- vector(mode="list", length=numGraphs) | ||
| sNVerts <- vector(mode="list", length=numGraphs) | ||
| edgePairsList <- c() #vector(mode="list", length=numGraphs) | ||
| for (i in 1:numGraphs){ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks Boris. I was trying to create the pasted combined vertices in |
||
| 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) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outputGraphs undefined. sN?
There was a problem hiding this comment.
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.