R/quickNet.R

Defines functions quickNet

Documented in quickNet

#' @title quickNet
#' @description Generates an igraph network representing the miR-mRNA
#' interactions filtered from the input data using pathway analysis and
#' database filtering. Pink nodes are miRs and light blue nodes are mRNAs.
#' Edges are coloured by the average correlations. Note, plot window size may
#' need to be adjusted to accommodate image.
#' @param net List generated by makeNet function. If you have fewer than two
#' interactions the plot will not work. Output from makeNet should be stored
#' as metadata within the MAE used in the makeNet function.
#' @param pathwayname Character which is the name of pathway of interest.
#' Default is "Pathway".
#' @return A network depicting filtered miR-mRNA interactions for a specific
#' wikipathway of interest.
#' @export
#' @importFrom igraph V V<- E E<-
#' @importFrom graphics legend par plot
#' @importFrom grDevices colorRampPalette
#' @importFrom stats median
#' @usage quickNet(net, pathwayname)
#' @examples
#' Filt_df <- data.frame(row.names = c("mmu-miR-320-3p:Acss1",
#'                                      "mmu-miR-27a-3p:Odc1"),
#'                       corr = c(-0.9191653, 0.7826041),
#'                       miR = c("mmu-miR-320-3p", "mmu-miR-27a-3p"),
#'                       mRNA = c("Acss1", "Acss1"),
#'                       miR_Entrez = c(NA, NA),
#'                       mRNA_Entrez = c(68738, 18263),
#'                       TargetScan = c(1, 0),
#'                       miRDB = c(0, 0),
#'                       Predicted_Interactions = c(1, 0),
#'                       miRTarBase = c(0, 1),
#'                       Pred_Fun = c(1, 1))
#'
#'MAE <- MultiAssayExperiment()
#'
#'MAE <- makeNet(MAE, Filt_df)
#'
#'quickNet(metadata(MAE)[[1]])
quickNet <- function(net, pathwayname = ""){

    if(missing(net)) stop('net is missing. Add igraph object. Please use the makeNet function. The output of makeNet should be stored as metadata within the MAE used in the makeNet function.')

    # Set network colours and features
    igraph::V(net)$color <- ifelse(igraph::V(net)$genetype == "mRNA",
                                                              "lightblue",
                                                              "pink")

    igraph::E(net)$width <- igraph::E(net)$Databases

    ii <- cut(igraph::E(net)$Correlation,
              breaks = seq(min(igraph::E(net)$Correlation),
                           max(igraph::E(net)$Correlation),
              len = length(igraph::E(net)$Correlation)), include.lowest = TRUE)

    # Legend colours
    colors <- grDevices::colorRampPalette(c("red", "grey","green"))(
                                         length(igraph::E(net)$Correlation))[ii]

    legcol <- grDevices::colorRampPalette(c("red", "grey", "green"))(3)

    igraph::E(net)$edge.color <- colors

    graphics::par(mar=c(1, 1, 1, 1))

    graphics::plot(net,
                   edge.arrow.size=.4,
                   vertex.label=igraph::V(net)$genes,
                   vertex.shape = "circle",
                   vertex.size = 20,
                   vertex.label.cex = 0.8,
                   vertex.label.dist = 0,
                   frame = TRUE,
                   main = paste0("miR-mRNA interactions", pathwayname),
                   edge.curved = 0.5,
                   vertex.frame.color = "white",
                   edge.color = colors)

    # Make legend
    graphics::legend(x = -2.4, y = -0.4,
                    legend = round(c(min(igraph::E(net)$Correlation),
                                   stats::median(E(net)$Correlation),
                                   max(igraph::E(net)$Correlation)), 2),
                    fill = legcol,
                    border = NA,
                    y.intersp = 0.7,
                    cex = 0.8,
                    text.font = 0.2,
                    title = "Corr")

    # Object specifics
    graphics::legend(x=-2.4,
                     y=-0.8,
                     c("microRNA","mRNA"),
                     pch=21,
                     col="#777777",
                     pt.bg= c("pink", "lightblue"),
                     pt.cex=2,
                     cex=1,
                     bty="n",
                     ncol=1)
}

Try the TimiRGeN package in your browser

Any scripts or data that you put into this service are public.

TimiRGeN documentation built on April 17, 2021, 6:03 p.m.