Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
DPM/R/get_link.R
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
50 lines (46 sloc)
1.88 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Converts the score matrix (obtained from DPM or reg-DPM) to a sorted list of non-directed links (links with higher score first). | |
#' | |
#' @param score_matrix score matrix obtained from DPM or regDPM. | |
#' @param top_ranked number of top links with higher score to report. The default value is NULL, i.e. all the links are reported. | |
#' @param threshold only links with a score above the threshold are reported. The default value is 0, i.e. all the links are reported. | |
#' | |
#' @return List of links in a data frame. Each line of the data frame corresponds to a link. The first and second columns are the corresponding nodes of the link and the third column is the score of the link. | |
#' | |
#' @examples | |
#'##load DREAM4 data (insilico_size10_1_knockouts) | |
#' data(dream4) | |
#' | |
#'## Run regularized DPM | |
#' score_mat <- reg.dpm(dream4) | |
#' | |
#' ## Get ranking of links | |
#' links <- get_link(score_mat) | |
#' head(linkList) | |
#' | |
#' ## Get only the top ranked links | |
#' links <- get_link(score_mat,top_ranked=10) | |
#' head(linkList) | |
#' | |
#' ## Get only the links with a score higher than a threshold | |
#' links <- get_link(score_mat,threshold = 0.2) | |
#' head(linkList) | |
#' | |
#' @export | |
#' | |
#' | |
#################################################################################### | |
### Function to converts the score matrix to a sorted list of non-directed links#### | |
#################################################################################### | |
get_link <- function(score_matrix, top_ranked=NULL, threshold=0) { | |
diag(score_matrix) <- NA | |
score_matrix[upper.tri(score_matrix)] <- NA | |
linkList <- reshape2::melt(abs(score_matrix), na.rm=TRUE) | |
colnames(linkList) <- c("Node1", "Node2", "score") | |
linkList <- linkList[linkList$score>=threshold,] | |
linkList <- linkList[order(linkList$score, decreasing=TRUE),] | |
if(!is.null(top_ranked)) { | |
linkList <- linkList[1:min(nrow(linkList), top_ranked),] | |
} | |
rownames(linkList) <- NULL | |
return(linkList) | |
} |