diff --git a/R/BuildClusterFilteredNetwork.R b/R/BuildClusterFilteredNetwork.R index 0b384c7a..ab4c4411 100644 --- a/R/BuildClusterFilteredNetwork.R +++ b/R/BuildClusterFilteredNetwork.R @@ -18,8 +18,8 @@ #' #' @export #' @examples -#' Example_Output <- BuildClusterFilteredNetwork(ex.gene.cccn, ex.stringdb.edges, ex.gm.edges) -#' utils::head(Example_Output) +#' Example_Output <- BuildClusterFilteredNetwork(ex_gene_cccn_edges, ex_stringdb_edges, ex_genemania_edges) +#' utils::head(Example_Output[[2]]) BuildClusterFilteredNetwork <- function(gene.cccn.edges, stringdb.edges = NULL, genemania.edges = NULL, kinsub.edges = NULL, db.filepaths = c(NULL)) { # Combine PPIs from different databases # First Normalize Weights diff --git a/R/CytoscapeGraphingFunctions.R b/R/CytoscapeGraphingFunctions.R index 10c22b3f..0630a731 100644 --- a/R/CytoscapeGraphingFunctions.R +++ b/R/CytoscapeGraphingFunctions.R @@ -1,184 +1,188 @@ -#' @title Graphing and Manipulating Cluster Filtered Network -#' -#' @description Creates a cytoscape graph of the cluster filtered network. Ensure that you have the Cytoscape app open and the RCy3 package downloaded. -#' The package RCy3 is required for many of the functions in this script. To download, run: -#' - if (!require("BiocManager", quietly = TRUE)) install.packages("BiocManager") -#' - BiocManager::install("RCy3") -#' It is also recommended (but not required) that users load RCy3 with library(RCy3) to access its functions directly. -#' -#' @details Graph Key -#' - Node Size -#' - Greater the node size, larger the absolute value of the score -#' - Blue Node -#' - Negative score -#' - Yellow Node -#' - Positive score -#' - Green Node -#' - Approximately zero score -#' Node Shapes: -#' - "ELLIPSE" -#' - unknown -#' - "ROUND_RECTANGLE" -#' - receptor tyrosine kinase -#' - "VEE" -#' - SH2 protein -#' or -#' - SH2-SH3 protein -#' - "TRIANGLE" -#' - SH3 protein -#' - "HEXAGON" -#' - tyrosine kinase -#' - "DIAMOND" -#' - SRC-family kinase -#' - "OCTAGON" -#' - kinase -#' or -#' - phosphatase -#' - "PARALLELOGRAM" -#' - transcription factor -#' - "RECTANGLE" -#' - RNA binding protein -#' Node Border Colors: -#' - Orange -#' - deacetylase -#' or -#' - acetyltransferase -#' - Blue -#' - demethylase -#' or -#' - methyltransferase -#' - Royal Purple -#' - membrane protein -#' - Red -#' - kinase -#' or -#' - tyrosine kinase -#' or -#' - SRC-family kinase -#' - Yellow -#' - phosphatase -#' or -#' - tyrosine phosphatase -#' - Lilac -#' - G protein-coupled receptor -#' or -#' - receptor tyrosine kinase -#' - Grey -#' - default -#' - Edge Thickness -#' - Stronger correlation -#'Edge Colors: -#' - Red -#' - Phosphorylation -#' or -#' - pp -#' or -#' - controls-phosphorylation-of -#' - Bright Magenta -#' - controls-expression-of -#' - Dull Magenta -#' - controls-transport-of -#' - Purple -#' - controls-state-change-of -#' - Blood Orange -#' - Acetylation -#' - Lime Green -#' - Phystical interactions -#' - Green -#' - BioPlex -#' - Dull Green -#' - in-complex-with -#' - Seafoam Green -#' - experiments -#' or -#' - experiments_transferred -#' - Cyan -#' - database -#' or -#' - database_transferred -#' - Teal -#' - Pathway -#' or -#' - Predicted -#' - Dark Turquoise -#' - Genetic interactions -#' - Yellow-Orange -#' - correlation -#' - Royal Blue -#' - negative correlation -#' - Bright Yellow -#' - positive correlation -#' - Grey -#' - combined_score -#' - Dark Grey -#' - merged -#' - Light Grey -#' - intersect -#' - Black -#' - peptide -#' - Orange -#' - homology -#' - Dull Orange -#' - Shared protein domains -#' - White -#' - Default -#' Arrow Types: -#' - Arrow -#' - Phosphorylation -#' or -#' - pp -#' or -#' - controls-phosphorylation-of -#' or -#' - controls-expression-of -#' or -#' - controls-transport-of -#' or -#' - controls-state-change-of -#' or -#' - Acetylation -#' - No Arrow -#' - Default -#' -#' @param cfn A version of ppi.network with only the edges that exist in cccn.matrix and have non-zero weights -#' @param ptmtable A dataset for post-translational modifications. Formatted with numbered rows, and the first column containing PTM names. The rest of the column names should be drugs. Values are numeric values that represent how much the PTM has reacted to the drug. -#' @param funckey A table graphing gene names to type of protein; defaults to the internal dataset `PTMsToPathways::function_key` -#' @param Network.title Desired title for the created Cytoscape Network; defaults to "cfn" -#' @param Network.collection Desired name for the collection created on Cytoscape in which the network will reside; defaults to "PTMsToPathways" -#' @param visual.style.name Desired name for the visual style created on Cytoscape; defaults to "PTMsToPathways.style" -#' -#' @param background.color Hex code of background color of graph; defaults to '#fcf3cf' -#' @param edge.label.color Hex code of edge label color of graph; defaults to '#17202a' -#' @param node.label.color Hex code of node label color of graph; defaults to '#145a32' -#' -#' @param default.font Font style of edge and node names; defaults to "Times New Roman" -#' @param node.font.size Font size of the node name; defaults to 12 -#' @param edge.font.size Font size of the edge name; defaults to 8 -#' -#' @param edge.line.style Type of edge style; defaults to "SOLID"; options include: "PARALLEL_LINES", "MARQUEE_EQUAL", "DOT", "EQUAL_DASH", "LONG_DASH", "CONTIGUOUS_ARROW", "MARQUEE_DASH", "DASH_DOT", "BACKWARD_SLASH", "FORWARD_SLASH", "VERTICAL_SLASH", "SOLID", "SEPARATE_ARROW", "MARQUEE_DASH_DOT", "ZIGZAG", "SINEWAVE" -#' -#' @param edge.opacity Opacity of the edge line on a scale of 0 - 255 with 0 being transparent; defaults to 175 -#' @param edge.label.opacity Opacity of the edge label on a scale of 0 - 255 with 0 being transparent; defaults to 255 -#' @param border.opacity Opacity of the node border on a scale of 0 - 255 with 0 being transparent; defaults to 255 -#' @param node.label.opacity Opacity of the node label on a scale of 0 - 255 with 0 being transparent; defaults to 255 -#' @param node.fill.opacity Opacity of the node fill on a scale of 0 - 255 with 0 being transparent; defaults to 255 -#' -#' @return A cytoscape graph of the cluster filtered network -#' @export -#' -#' @examples -#' # GraphCFN(ex.cfn) -#' # See vignette for default graph -#' +# @title Graphing and Manipulating Cluster Filtered Network +# +# @description Creates a cytoscape graph of the cluster filtered network. Ensure that you have the Cytoscape app open and the RCy3 package downloaded. +# The package RCy3 is required for many of the functions in this script. To download, run: +# - if (!require("BiocManager", quietly = TRUE)) install.packages("BiocManager") +# - BiocManager::install("RCy3") +# It is also recommended (but not required) that users load RCy3 with library(RCy3) to access its functions directly. +# +# @details Graph Key +# - Node Size +# - Greater the node size, larger the absolute value of the score +# - Blue Node +# - Negative score +# - Yellow Node +# - Positive score +# - Green Node +# - Approximately zero score +# Node Shapes: +# - "ELLIPSE" +# - unknown +# - "ROUND_RECTANGLE" +# - receptor tyrosine kinase +# - "VEE" +# - SH2 protein +# or +# - SH2-SH3 protein +# - "TRIANGLE" +# - SH3 protein +# - "HEXAGON" +# - tyrosine kinase +# - "DIAMOND" +# - SRC-family kinase +# - "OCTAGON" +# - kinase +# or +# - phosphatase +# - "PARALLELOGRAM" +# - transcription factor +# - "RECTANGLE" +# - RNA binding protein +# Node Border Colors: +# - Orange +# - deacetylase +# or +# - acetyltransferase +# - Blue +# - demethylase +# or +# - methyltransferase +# - Royal Purple +# - membrane protein +# - Red +# - kinase +# or +# - tyrosine kinase +# or +# - SRC-family kinase +# - Yellow +# - phosphatase +# or +# - tyrosine phosphatase +# - Lilac +# - G protein-coupled receptor +# or +# - receptor tyrosine kinase +# - Grey +# - default +# - Edge Thickness +# - Stronger correlation +#Edge Colors: +# - Red +# - Phosphorylation +# or +# - pp +# or +# - controls-phosphorylation-of +# - Bright Magenta +# - controls-expression-of +# - Dull Magenta +# - controls-transport-of +# - Purple +# - controls-state-change-of +# - Blood Orange +# - Acetylation +# - Lime Green +# - Phystical interactions +# - Green +# - BioPlex +# - Dull Green +# - in-complex-with +# - Seafoam Green +# - experiments +# or +# - experiments_transferred +# - Cyan +# - database +# or +# - database_transferred +# - Teal +# - Pathway +# or +# - Predicted +# - Dark Turquoise +# - Genetic interactions +# - Yellow-Orange +# - correlation +# - Royal Blue +# - negative correlation +# - Bright Yellow +# - positive correlation +# - Grey +# - combined_score +# - Dark Grey +# - merged +# - Light Grey +# - intersect +# - Black +# - peptide +# - Orange +# - homology +# - Dull Orange +# - Shared protein domains +# - White +# - Default +# Arrow Types: +# - Arrow +# - Phosphorylation +# or +# - pp +# or +# - controls-phosphorylation-of +# or +# - controls-expression-of +# or +# - controls-transport-of +# or +# - controls-state-change-of +# or +# - Acetylation +# - No Arrow +# - Default +# +# @param cfn A version of ppi.network with only the edges that exist in cccn.matrix and have non-zero weights +# @param ptmtable A dataset for post-translational modifications. Formatted with numbered rows, and the first column containing PTM names. The rest of the column names should be drugs. Values are numeric values that represent how much the PTM has reacted to the drug. +# @param funckey A table graphing gene names to type of protein; defaults to the internal dataset `PTMsToPathways::function_key` +# @param Network.title Desired title for the created Cytoscape Network; defaults to "cfn" +# @param Network.collection Desired name for the collection created on Cytoscape in which the network will reside; defaults to "PTMsToPathways" +# @param visual.style.name Desired name for the visual style created on Cytoscape; defaults to "PTMsToPathways.style" +# +# @param background.color Hex code of background color of graph; defaults to '#fcf3cf' +# @param edge.label.color Hex code of edge label color of graph; defaults to '#17202a' +# @param node.label.color Hex code of node label color of graph; defaults to '#145a32' +# +# @param default.font Font style of edge and node names; defaults to "Times New Roman" +# @param node.font.size Font size of the node name; defaults to 12 +# @param edge.font.size Font size of the edge name; defaults to 8 +# +# @param edge.line.style Type of edge style; defaults to "SOLID"; options include: "PARALLEL_LINES", "MARQUEE_EQUAL", "DOT", "EQUAL_DASH", "LONG_DASH", "CONTIGUOUS_ARROW", "MARQUEE_DASH", "DASH_DOT", "BACKWARD_SLASH", "FORWARD_SLASH", "VERTICAL_SLASH", "SOLID", "SEPARATE_ARROW", "MARQUEE_DASH_DOT", "ZIGZAG", "SINEWAVE" +# +# @param edge.opacity Opacity of the edge line on a scale of 0 - 255 with 0 being transparent; defaults to 175 +# @param edge.label.opacity Opacity of the edge label on a scale of 0 - 255 with 0 being transparent; defaults to 255 +# @param border.opacity Opacity of the node border on a scale of 0 - 255 with 0 being transparent; defaults to 255 +# @param node.label.opacity Opacity of the node label on a scale of 0 - 255 with 0 being transparent; defaults to 255 +# @param node.fill.opacity Opacity of the node fill on a scale of 0 - 255 with 0 being transparent; defaults to 255 +# +# @return A cytoscape graph of the cluster filtered network +# @export +# +# @examples +# # GraphCFN(ex.cfn) +# # See vignette for default graph +# # # helper functions for networks in R: # function to filter networks to include only selected nodes and those with edges to them -#' @param nodenames +#' Filter an edge file to edges between a specified set of nodes #' -#' @param edge.file +#' Returns only edges where both endpoints are in \code{nodenames}. #' +#' @param nodenames Character vector of node names to retain. +#' @param edge.file A data frame edge list with node names in columns 1 and 2. +#' +#' @return A data frame of filtered edges, or \code{NA} if no edges remain. #' @export filter.edges.0 <- function(nodenames, edge.file) { nodenames <-as.character(nodenames) @@ -190,10 +194,16 @@ filter.edges.0 <- function(nodenames, edge.file) { } # #function to filter networks and to get first order connected nodes -#' @param nodenames +#' Filter an edge file to include first-order neighbours of specified nodes +#' +#' Returns all edges where at least one endpoint is in \code{nodenames}, +#' effectively including the nodes themselves and all directly connected neighbours. #' -#' @param edge.file +#' @param nodenames Character vector of seed node names. +#' @param edge.file A data frame edge list with node names in columns 1 and 2. #' +#' @return A data frame of edges involving at least one node in \code{nodenames}, +#' or \code{NA} if no edges remain. #' @export filter.edges.1 <- function(nodenames, edge.file) { nodenames <-as.character(nodenames) @@ -208,12 +218,18 @@ filter.edges.1 <- function(nodenames, edge.file) { } # This function narrows the search only for edges between two sets of nodes -#' @param nodes1 +#' Filter an edge file to edges between two sets of nodes #' -#' @param nodes2 -#' @param edge.file -#' @param convert +#' Returns edges where one endpoint is in \code{nodes1} and the other is in +#' \code{nodes2}, in either direction. #' +#' @param nodes1 Character vector of the first set of node names. +#' @param nodes2 Character vector of the second set of node names. +#' @param edge.file A data frame edge list with node names in columns 1 and 2. +#' @param convert Logical; currently unused, reserved for future type conversion. +#' +#' @return A data frame of edges connecting \code{nodes1} to \code{nodes2}, +#' or \code{NA} if no such edges exist. #' @export filter.edges.between <- function(nodes1, nodes2, edge.file, convert=FALSE) { sel.edges1 <- edge.file[edge.file[,1] %in% nodes1 & edge.file[,2]%in% nodes2,] @@ -223,12 +239,20 @@ filter.edges.between <- function(nodes1, nodes2, edge.file, convert=FALSE) { } # connectNodes.all uses all_shortest_paths and returns just the edge file -#' @param nodepair +#' Connect a pair of nodes via all shortest paths +#' +#' Uses \code{igraph::all_shortest_paths} to find all shortest paths between +#' two nodes and returns the union of edges along those paths. #' -#' @param ig.graph -#' @param edgefile -#' @param newgraph +#' @param nodepair Character vector of length 2 giving the source and target node names. +#' @param ig.graph An \code{igraph} graph object. If \code{NULL} and +#' \code{newgraph = TRUE}, one is built from \code{edgefile}. +#' @param edgefile A data frame edge list used to construct the graph when +#' \code{newgraph = TRUE} and to extract edge attributes. +#' @param newgraph Logical; if \code{TRUE}, build a new \code{igraph} object +#' from \code{edgefile} before computing paths. #' +#' @return A data frame of edges along all shortest paths between the two nodes. #' @export connectNodes.all <- function(nodepair, ig.graph=NULL, edgefile, newgraph=FALSE) { if (newgraph==TRUE) { @@ -240,8 +264,16 @@ connectNodes.all <- function(nodepair, ig.graph=NULL, edgefile, newgraph=FALSE) return(path.edges) } # This function names the edges the way Cytoscape does so they can be selected: -#' @param edgefile +#' Get Cytoscape-formatted edge names #' +#' Constructs edge name strings in the format Cytoscape uses internally +#' (\code{source (interaction) target}), suitable for use with +#' \code{RCy3::selectEdges}. +#' +#' @param edgefile A data frame with columns \code{source}, \code{interaction}, +#' and \code{target}. +#' +#' @return A character vector of edge name strings. #' @export getCyEdgeNames <- function(edgefile) { cyedges <- mapply(paste, edgefile $source, " (", edgefile $interaction, ") ", edgefile $target, sep="") @@ -249,8 +281,14 @@ getCyEdgeNames <- function(edgefile) { } # Function to extract node names from, e.g.: # "ValidatedObjectAndEditString: validatedObject=ERBB3, editString=null" -#' @param test +#' Strip Cytoscape metadata strings to extract node names +#' +#' Parses verbose Cytoscape node identifier strings of the form +#' \code{"...Object=NODENAME, ..."} and returns just the node name portion. #' +#' @param test Character vector of raw Cytoscape node identifier strings. +#' +#' @return A character vector of extracted node names. #' @export strip.cy.goo <- function(test) { t1 <- unlist(strsplit(test, "Object=")) @@ -260,11 +298,19 @@ strip.cy.goo <- function(test) { # For graphing Pathway Crosstalk Networks (PCNs) in cytoscape -#' @param PCN +#' Graph a Pathway Crosstalk Network in Cytoscape +#' +#' Creates a Cytoscape network from a Pathway Crosstalk Network (PCN) data frame, +#' applying edge color and width mappings. Requires Cytoscape to be open and +#' \code{RCy3} to be installed. #' -#' @param net.name -#' @param Jaccard.edges +#' @param PCN A data frame representing the pathway crosstalk network with columns +#' \code{source}, \code{target}, \code{interaction}, and \code{Weight}. +#' @param net.name A character string used as the base network title in Cytoscape. +#' @param Jaccard.edges Logical; if \code{FALSE}, pathway Jaccard similarity edges +#' are removed before plotting. Defaults to \code{TRUE}. #' +#' @return Called for its side effects; creates a network in Cytoscape. #' @export cytoscape.graph.PCN.pathways <- function(PCN = pathway.crosstalk.network, net.name, Jaccard.edges=TRUE) { PCN.df <- data.frame(id=unique(c(PCN$source, PCN$target))) @@ -288,10 +334,16 @@ cytoscape.graph.PCN.pathways <- function(PCN = pathway.crosstalk.network, net.na } # Two linked functions to generate node file for Cytoscape: -#' @param genes +#' Summarise PTM table data to gene level #' -#' @param ptmtable +#' Subsets a PTM table to genes of interest and collapses PTM-level numeric +#' values to gene-level sums, suitable for loading into Cytoscape node attributes. #' +#' @param genes Character vector of gene names to retain. +#' @param ptmtable A PTM data frame with PTM identifiers (\code{"GENE site"}) as +#' row names and numeric drug/condition columns. +#' +#' @return A data frame with one row per gene and summed numeric columns. #' @export make.gene.data.from.ptmtable <- function(genes, ptmtable) { ptmtable.temp <- ptmtable @@ -306,13 +358,25 @@ make.gene.data.from.ptmtable <- function(genes, ptmtable) { return(as.data.frame(gene.data)) # Ensure base R class } -#' @param edge.file -#' -#' @param funckey -#' @param ptmtable -#' @param include.gene.data -#' @param include.coclustered.PTMs -#' +#' Build a Cytoscape node attribute table from an edge file +#' +#' Extracts unique gene nodes from an edge file, annotates them using the +#' function key, and optionally appends gene-level PTM data and co-clustered +#' PTM nodes. +#' +#' @param edge.file A data frame edge list with node names in columns 1 and 2 +#' and an \code{interaction} column. +#' @param funckey A data frame mapping gene names to protein annotations +#' (e.g., \code{PTMsToPathways::function_key}). +#' @param ptmtable A PTM data frame with PTM identifiers as row names and +#' numeric condition columns. +#' @param include.gene.data Logical; if \code{TRUE}, append gene-level +#' summarised PTM values to the node table. Defaults to \code{FALSE}. +#' @param include.coclustered.PTMs Logical; if \code{TRUE}, add co-clustered +#' PTM nodes and their edges to the output. Defaults to \code{FALSE}. +#' +#' @return A data frame of node attributes with an \code{id} column suitable +#' for \code{RCy3::createNetworkFromDataFrames}. #' @export make.cytoscape.node.file <- function(edge.file, funckey, ptmtable, include.gene.data = FALSE, include.coclustered.PTMs = FALSE) { # Step 1: get unique nodes from edge file @@ -361,14 +425,15 @@ make.cytoscape.node.file <- function(edge.file, funckey, ptmtable, include.gene. return(unique(node_file)) } # To remove self-loops -#' Title +#' Remove self-loop edges from an edge file #' -#' @param edgefile +#' Drops any rows where the source and target node are identical. #' -#' @returns -#' @export +#' @param edgefile A data frame edge list with \code{source} and \code{target} +#' columns. #' -#' @examples +#' @return The edge file with self-loop rows removed. +#' @export remove.autophos <- function(edgefile) { auto <- which (as.character(edgefile$source) == as.character(edgefile$target)) if (length(auto) > 0) { @@ -376,14 +441,17 @@ remove.autophos <- function(edgefile) { return (newedgefile) } # Helper functions for connecting PTMs (called "peptides" with their parent protein nodes (called Gene.Name)) -#' Title +#' Create gene-to-peptide edges from a PTM edge file #' -#' @param peptide.edgefile +#' Generates a new edge data frame linking each PTM node (\code{"GENE site"}) +#' to its parent gene node, for use in combined gene/PTM Cytoscape networks. #' -#' @returns -#' @export +#' @param peptide.edgefile A data frame edge list whose node names follow the +#' \code{"GENE site"} PTM naming convention. #' -#' @examples +#' @return A data frame with columns \code{source}, \code{target}, +#' \code{Weight}, and \code{interaction} (\code{"peptide"}). +#' @export make.genepep.edges <- function(peptide.edgefile) { peptides <- unique(c(peptide.edgefile$source, peptide.edgefile$target)) genenames <- sapply(peptides, function (x) unlist(strsplit(x, " ", fixed=TRUE))[1]) @@ -393,8 +461,18 @@ make.genepep.edges <- function(peptide.edgefile) { } # This function takes an edge file, retrieves only co-clustered PTM CCCN edges and links them to their gene nodes, returning an edge file -#' @param edge.file +#' Retrieve co-clustered PTM CCCN edges for genes in an edge file #' +#' Subsets the PTM CCCN to the PTMs belonging to genes present in +#' \code{edge.file}, then appends gene-to-peptide edges so the result +#' can be directly used as an extended edge list in Cytoscape. +#' +#' @param edge.file A data frame edge list whose nodes are gene names. +#' @param ptm.cccn.edges A data frame of PTM co-expression correlation network +#' edges with PTM identifiers as node names. +#' +#' @return An edge data frame combining the original gene edges, co-clustered +#' PTM edges, and gene-to-peptide linking edges. #' @export get.co.clustered.ptms <- function (edge.file, ptm.cccn.edges) { gene_nodes <- unique(c(as.character(edge.file[, 1]), as.character(edge.file[, 2]))) @@ -429,10 +507,15 @@ get.co.clustered.ptms <- function (edge.file, ptm.cccn.edges) { } -#' @param x +#' Symmetric set difference of two vectors +#' +#' Returns elements that are in either \code{x} or \code{y} but not in both +#' (i.e., the outer- or exclusive union). #' -#' @param y +#' @param x A vector. +#' @param y A vector. #' +#' @return A sorted vector of elements present in exactly one of \code{x} or \code{y}. #' @export outersect <- function(x, y) { sort(c(setdiff(x, y), @@ -441,11 +524,23 @@ outersect <- function(x, y) { # Function to harmonize gene and peptide data for networks # - for graphing combined CFN/CCCN graphs -# Enusres that for Cytoscape, "id" is used for node name columns#' @param edge.file.with.ptms -#' -#' @param genecf -#' @param ptmtable -#' +# Ensures that for Cytoscape, "id" is used for node name columns +#' Harmonize gene and PTM node tables for a combined CFN/CCCN network +#' +#' Merges a gene-level node attribute table with PTM-level rows derived from +#' the PTM table, ensuring the \code{id} column is present and used as the +#' Cytoscape node key. PTM nodes are annotated from the function key and +#' linked to their parent genes via a \code{parent} column. +#' +#' @param edge.file.with.ptms A data frame edge list containing both gene and +#' PTM (\code{interaction == "peptide"}) edges. +#' @param genecf A gene-level node attribute data frame, typically produced by +#' \code{make.cytoscape.node.file}. +#' @param ptmtable A PTM data frame with PTM identifiers as row names and +#' numeric condition columns. +#' +#' @return A merged data frame of gene and PTM node attributes with \code{id} +#' as the first column, suitable for \code{RCy3::createNetworkFromDataFrames}. #' @export harmonize_cfs <- function(edge.file.with.ptms, genecf, ptmtable) { if(!any(grepl("Gene.Name", names(genecf)))) { @@ -494,8 +589,17 @@ harmonize_cfs <- function(edge.file.with.ptms, genecf, ptmtable) { # Function to merge edges to declutter networks -#' @param edgefile +#' Merge duplicate edges in an edge file +#' +#' Consolidates an edge file by collapsing parallel edges (same source/target) +#' into a single row. For directed edge types, the highest-priority interaction +#' is kept; for undirected edges, all interaction types are concatenated with +#' \code{" | "}. Self-loops are removed from the result. #' +#' @param edgefile A data frame edge list with columns \code{source}, +#' \code{target}, \code{interaction}, and \code{Weight}. +#' +#' @return A deduplicated data frame edge list. #' @export mergeEdges <- function(edgefile) { # Define edge type priorities for directed edges @@ -568,8 +672,10 @@ mergeEdges <- function(edgefile) { #' cluster = c(1,1,2,1)) #' # Suppose filter.edges.0 and get.co.clustered.ptms are also defined and loaded #' # The following returns the gene/PTM subnetwork +#' \dontrun{ #' res <- ptms_to_cfn(ptms, cfn = cfn.merged, pepsep = ";") #' print(res) +#' } ptms_to_cfn <- function(ptms, cfn = cfn.merged, pepsep = ";") { ambig.ptms <- ptms[grep(";", ptms)] if (length(ambig.ptms) > 0) { @@ -599,8 +705,16 @@ ptms_to_cfn <- function(ptms, cfn = cfn.merged, pepsep = ";") { #_____________________________________________________________________________ # Vizprops helper functions: # Function to set shape and border color according to node type -#' @param cf +#' Apply node visual mappings in the active Cytoscape network #' +#' Sets default node appearance (shape, color, size, border) and applies +#' discrete visual mappings for node shape and border color based on the +#' \code{nodeType} column from the function key. +#' +#' @param cf A data frame of node attributes from the active Cytoscape network; +#' defaults to the full node table retrieved via \code{RCy3::getTableColumns}. +#' +#' @return Called for its side effects in Cytoscape. #' @export setNodeMapping <- function(cf=RCy3::getTableColumns('node')) { # require(RCy3) @@ -625,12 +739,14 @@ setNodeMapping <- function(cf=RCy3::getTableColumns('node')) { # Function to set edge appearance # # Use: setCorrEdgeAppearance() to change cytoscape front window #This is now modified to handle merged edges and match colors correctly -#' Title +#' Apply edge visual mappings in the active Cytoscape network #' -#' @returns -#' @export +#' Sets edge line widths (log-scaled from correlation weights), colors, and +#' arrow types based on the \code{interaction} column. Handles merged edge +#' labels by extracting the primary interaction type before applying mappings. #' -#' @examples +#' @return Called for its side effects in Cytoscape. +#' @export setCorrEdgeAppearance <- function() { # require(RCy3) RCy3::setEdgeLineWidthDefault(3) @@ -663,9 +779,17 @@ setCorrEdgeAppearance <- function() { RCy3::setEdgeColorMapping('main_interaction', edgeTypes, edgecolors, 'd', default.color="#FFFFFF") } -# Function to sent node size and color to match ratio data in the Cytoscape node table. -#' @param plotcol +# Function to set node size and color to match ratio data in the Cytoscape node table. +#' Map node size and color to ratio-scale data in Cytoscape +#' +#' Applies continuous node size and color mappings to the active Cytoscape +#' network using fixed log2-based control points suited for ratio or +#' fold-change data centered on zero. +#' +#' @param plotcol A character string naming the node table column to map to +#' both node size and node color. #' +#' @return Called for its side effects in Cytoscape. #' @export setNodeColorToRatios <- function(plotcol){ require(RCy3) @@ -698,8 +822,15 @@ setNodeColorToRatios <- function(plotcol){ } # This function works well with node data that are normalized by row z-scores -#' @param plotcol +#' Map node size and color to row z-score data in Cytoscape #' +#' Applies continuous node size and color mappings to the active Cytoscape +#' network using log2-based control points suited for row z-score normalised data. +#' +#' @param plotcol A character string naming the node table column to map to +#' both node size and node color. +#' +#' @return Called for its side effects in Cytoscape. #' @export setNodeColorToRowz <- function(plotcol){ cf <- getTableColumns('node') @@ -831,13 +962,23 @@ setNodeSizeColorIndependently <- function(sizeplotcol, colorplotcol, ratio=FALSE } # This function wraps RCy3 graphing in Cytoscape and sets node and edge visual properties -#' @param cfn.edges -#' -#' @param cfn.nodes -#' @param Network.title -#' @param Network.collection -#' @param visual.style.name -#' +#' Graph a Cluster Filtered Network in Cytoscape +#' +#' Creates a Cytoscape network from CFN edge and node tables, then applies the +#' PTMsToPathways node shape/color and edge color/width visual mappings. +#' Requires Cytoscape to be open and \code{RCy3} to be installed. +#' +#' @param cfn.edges A data frame of CFN edges (\code{source}, \code{target}, +#' \code{interaction}, \code{Weight}). +#' @param cfn.nodes A data frame of CFN node attributes with an \code{id} column. +#' @param Network.title Character string title for the new Cytoscape network; +#' defaults to \code{"CFN"}. +#' @param Network.collection Character string name for the Cytoscape collection; +#' defaults to \code{"PTMsToPathways"}. +#' @param visual.style.name Character string name for the visual style to create; +#' defaults to \code{"PTMsToPathways.style"}. +#' +#' @return Called for its side effects; creates a styled network in Cytoscape. #' @export GraphCfn <- function(cfn.edges, cfn.nodes, Network.title = "CFN", Network.collection = "PTMsToPathways", visual.style.name = "PTMsToPathways.style"){ if(!requireNamespace("RCy3", quietly = TRUE)){ @@ -855,11 +996,20 @@ GraphCfn <- function(cfn.edges, cfn.nodes, Network.title = "CFN", Network.colle # RCy3::setVisualStyle(visual.style.name) } -# # This helper function will make wider edges if they are two thin or narrow if to thick -#' @param ffactor +# # This helper function will make wider edges if they are too thin or too thick +#' Adjust edge line widths in the active Cytoscape network #' -#' @param log +#' Computes edge widths from the \code{Weight} column of the Cytoscape edge +#' table, optionally log-transforming the values, and loads them back as a +#' continuous edge width mapping. #' +#' @param ffactor Numeric offset applied to all computed widths; a negative value +#' shifts widths down (narrower). Defaults to \code{-1.2}. +#' @param log Logical; if \code{TRUE} (default), widths are computed as +#' \code{log(|Weight|) + ffactor - min(log(|Weight|))}. If \code{FALSE}, +#' widths are \code{ffactor * |Weight|}. +#' +#' @return Called for its side effects in Cytoscape. #' @export setEdgeWidths <- function (ffactor=-1.2, log=TRUE) { edgevalues <- RCy3::getTableColumns('edge',c('Weight')) @@ -913,8 +1063,16 @@ SetStandards <- function(visual.style.name, } # NodeEdgeKey function: Cytoscape legend for styles -#' @param visual.style.name +#' Create a node and edge legend network in Cytoscape +#' +#' Builds a demo network in Cytoscape that illustrates all node shapes, border +#' colors, and edge colors used by the PTMsToPathways visual style, serving as +#' an interactive legend. +#' +#' @param visual.style.name Character string name of the visual style to apply; +#' defaults to \code{"PTMsToPathways.style"}. #' +#' @return Called for its side effects; creates a legend network in Cytoscape. #' @export NodeEdgeKey <- function(visual.style.name = "PTMsToPathways.style") { # require(RCy3) diff --git a/R/EvaluateClusters.R b/R/EvaluateClusters.R index 2697e12d..da184706 100644 --- a/R/EvaluateClusters.R +++ b/R/EvaluateClusters.R @@ -112,14 +112,17 @@ #' head(eval_df) #' #' # Unordered cohort data (e.g. BRCA): disable slope filter +#' \dontrun{ #' eval_brca <- EvaluateClusters( #' brca_clusters, brca_tbl, #' data.type = "ratio", #' use.slope = FALSE, #' index.mode = "density" #' ) +#' } #' #' # LINCS data with ratio columns to strip, size-based index: +#'\dontrun{ #' eval_lincs <- EvaluateClusters( #' lincs_clusters, lincs_tbl, #' data.type = "ratio", @@ -127,6 +130,7 @@ #' use.slope = TRUE, #' ratio.col.pattern = "to" #' ) +#' } EvaluateClusters <- function( clusterlist, tbl.sc, diff --git a/R/GatherPPIData.R b/R/GatherPPIData.R index 3fcd8e0d..54d4f131 100644 --- a/R/GatherPPIData.R +++ b/R/GatherPPIData.R @@ -119,8 +119,9 @@ StandardizeGeneSymbols <- function(genes, #' @export #' #' @examples -#' # MakeDBInput(ex.nodenames) -#' cat(ex.nodenames[[1]], sep = "\n") +#' \dontrun{ +#' # MakeDBInput(ex_gene_cccn_nodes, file.path.name = "db_nodes.txt") +#' } MakeDBInput <- function(gene.cccn.nodes, file.path.name = "db_nodes.txt") { utils::write.table(unique(c(gene.cccn.nodes[[1]], gene.cccn.nodes[[2]])), file = file.path.name, row.names = FALSE, col.names = FALSE, quote = FALSE) } diff --git a/R/MakeCorrelationNetwork.R b/R/MakeCorrelationNetwork.R index 8760f33e..aade533e 100644 --- a/R/MakeCorrelationNetwork.R +++ b/R/MakeCorrelationNetwork.R @@ -15,9 +15,9 @@ #' @export #' #' @examples -#' Example_Output <- MakeCorrelationNetwork(ex_adj_consensus, ex.ptm.correlation.matrix) -#' Example_Output[[1]][1:5, 1:5] -#' Example_Output[[2]][1:5, 1:5] +#' Example_Output <- MakeCorrelationNetwork(ex_adj_consensus, ex_ptm_correlation_matrix) +#' head(Example_Output[[1]]) +#' head(Example_Output[[2]]) #' MakeCorrelationNetwork <- function(adj.consensus.matrix, ptm.correlation.matrix) { # Two nested functions for creating the PTM and gene CCCN, respectively diff --git a/R/PathwayCrosstalkNetwork.R b/R/PathwayCrosstalkNetwork.R index c9da47a2..e930faff 100644 --- a/R/PathwayCrosstalkNetwork.R +++ b/R/PathwayCrosstalkNetwork.R @@ -69,9 +69,7 @@ ReadBioplanetFile <- function(bioplanet.file = "bioplanet.csv") { #' #' @examples #' Example_Output <- BuildPathwayCrosstalkNetwork(ex_common_clusters, ex_pathways_list) -#' Example_Output[[1]][[3,]] -#' Example_Output[[3]][[1:3]] -#' Example_Output[[4]][1:3, 1:3] +#' head(Example_Output[[1]]) BuildPathwayCrosstalkNetwork <- function(common.clusters, bioplanet.file = "bioplanet.csv"){ message("Making PCN") start_time <- Sys.time() diff --git a/R/data_documentation.R b/R/data_documentation.R index 9b881aef..34b7366b 100644 --- a/R/data_documentation.R +++ b/R/data_documentation.R @@ -12,7 +12,7 @@ #' } #' @source "Sub-data frame of the small PTM table" #' @examples -#' head(ex_small_ptm_table) +#' head(ex_tiny_ptm_table) "ex_tiny_ptm_table" #' Small PTM Table Example diff --git a/man/BuildClusterFilteredNetwork.Rd b/man/BuildClusterFilteredNetwork.Rd index 1f51bc24..38e752e4 100644 --- a/man/BuildClusterFilteredNetwork.Rd +++ b/man/BuildClusterFilteredNetwork.Rd @@ -36,6 +36,6 @@ If either of these conditions are not met, then it will be removed from the list This new, cluster filtered network is then assigned to the global namespace. } \examples{ -Example_Output <- BuildClusterFilteredNetwork(ex.gene.cccn, ex.stringdb.edges, ex.gm.edges) -utils::head(Example_Output) +Example_Output <- BuildClusterFilteredNetwork(ex_gene_cccn_edges, ex_stringdb_edges, ex_genemania_edges) +utils::head(Example_Output[[2]]) } diff --git a/man/BuildPathwayCrosstalkNetwork.Rd b/man/BuildPathwayCrosstalkNetwork.Rd index d76c8e1e..b363f1db 100644 --- a/man/BuildPathwayCrosstalkNetwork.Rd +++ b/man/BuildPathwayCrosstalkNetwork.Rd @@ -24,7 +24,5 @@ Converts Bioplanet pathways from (\url{https://tripod.nih.gov/bioplanet/}) into } \examples{ Example_Output <- BuildPathwayCrosstalkNetwork(ex_common_clusters, ex_pathways_list) -Example_Output[[1]][[3,]] -Example_Output[[3]][[1:3]] -Example_Output[[4]][1:3, 1:3] +head(Example_Output[[1]]) } diff --git a/man/EvaluateClusters.Rd b/man/EvaluateClusters.Rd index 6b88f949..3c3e293e 100644 --- a/man/EvaluateClusters.Rd +++ b/man/EvaluateClusters.Rd @@ -135,14 +135,17 @@ eval_df <- EvaluateClusters(cl[[1]], ex_tiny_ptm_table, data.type = "ratio") head(eval_df) # Unordered cohort data (e.g. BRCA): disable slope filter +\dontrun{ eval_brca <- EvaluateClusters( brca_clusters, brca_tbl, data.type = "ratio", use.slope = FALSE, index.mode = "density" ) +} # LINCS data with ratio columns to strip, size-based index: +\dontrun{ eval_lincs <- EvaluateClusters( lincs_clusters, lincs_tbl, data.type = "ratio", @@ -151,6 +154,7 @@ eval_lincs <- EvaluateClusters( ratio.col.pattern = "to" ) } +} \seealso{ \code{\link[=MakeClusterList]{MakeClusterList()}} for generating the cluster list input. } diff --git a/man/GraphCfn.Rd b/man/GraphCfn.Rd new file mode 100644 index 00000000..c835933c --- /dev/null +++ b/man/GraphCfn.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CytoscapeGraphingFunctions.R +\name{GraphCfn} +\alias{GraphCfn} +\title{Graph a Cluster Filtered Network in Cytoscape} +\usage{ +GraphCfn( + cfn.edges, + cfn.nodes, + Network.title = "CFN", + Network.collection = "PTMsToPathways", + visual.style.name = "PTMsToPathways.style" +) +} +\arguments{ +\item{cfn.edges}{A data frame of CFN edges (\code{source}, \code{target}, +\code{interaction}, \code{Weight}).} + +\item{cfn.nodes}{A data frame of CFN node attributes with an \code{id} column.} + +\item{Network.title}{Character string title for the new Cytoscape network; +defaults to \code{"CFN"}.} + +\item{Network.collection}{Character string name for the Cytoscape collection; +defaults to \code{"PTMsToPathways"}.} + +\item{visual.style.name}{Character string name for the visual style to create; +defaults to \code{"PTMsToPathways.style"}.} +} +\value{ +Called for its side effects; creates a styled network in Cytoscape. +} +\description{ +Creates a Cytoscape network from CFN edge and node tables, then applies the +PTMsToPathways node shape/color and edge color/width visual mappings. +Requires Cytoscape to be open and \code{RCy3} to be installed. +} diff --git a/man/MakeCorrelationNetwork.Rd b/man/MakeCorrelationNetwork.Rd index 99a41a92..f3f0a1d5 100644 --- a/man/MakeCorrelationNetwork.Rd +++ b/man/MakeCorrelationNetwork.Rd @@ -25,8 +25,8 @@ It groups the PTM correlation matrix based on the Genes of PTMs. By summing these submatrices, it also produces a gene by gene cocluster correlation network shows strength of relationships between proteins using the common clusters between the three distance metrics. } \examples{ -Example_Output <- MakeCorrelationNetwork(ex_adj_consensus, ex.ptm.correlation.matrix) -Example_Output[[1]][1:5, 1:5] -Example_Output[[2]][1:5, 1:5] +Example_Output <- MakeCorrelationNetwork(ex_adj_consensus, ex_ptm_correlation_matrix) +head(Example_Output[[1]]) +head(Example_Output[[2]]) } diff --git a/man/MakeDBInput.Rd b/man/MakeDBInput.Rd index 7ac92dda..bd411ae7 100644 --- a/man/MakeDBInput.Rd +++ b/man/MakeDBInput.Rd @@ -19,6 +19,7 @@ This function outputs a file consisting entirely of gene names, each produced on a database input in order to get protein-protein interaction data. } \examples{ -# MakeDBInput(ex.nodenames) -cat(ex.nodenames[[1]], sep = "\n") +\dontrun{ +# MakeDBInput(ex_gene_cccn_nodes, file.path.name = "db_nodes.txt") +} } diff --git a/man/NodeEdgeKey.Rd b/man/NodeEdgeKey.Rd new file mode 100644 index 00000000..b0120b62 --- /dev/null +++ b/man/NodeEdgeKey.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CytoscapeGraphingFunctions.R +\name{NodeEdgeKey} +\alias{NodeEdgeKey} +\title{Create a node and edge legend network in Cytoscape} +\usage{ +NodeEdgeKey(visual.style.name = "PTMsToPathways.style") +} +\arguments{ +\item{visual.style.name}{Character string name of the visual style to apply; +defaults to \code{"PTMsToPathways.style"}.} +} +\value{ +Called for its side effects; creates a legend network in Cytoscape. +} +\description{ +Builds a demo network in Cytoscape that illustrates all node shapes, border +colors, and edge colors used by the PTMsToPathways visual style, serving as +an interactive legend. +} diff --git a/man/connectNodes.all.Rd b/man/connectNodes.all.Rd new file mode 100644 index 00000000..5171954e --- /dev/null +++ b/man/connectNodes.all.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CytoscapeGraphingFunctions.R +\name{connectNodes.all} +\alias{connectNodes.all} +\title{Connect a pair of nodes via all shortest paths} +\usage{ +connectNodes.all(nodepair, ig.graph = NULL, edgefile, newgraph = FALSE) +} +\arguments{ +\item{nodepair}{Character vector of length 2 giving the source and target node names.} + +\item{ig.graph}{An \code{igraph} graph object. If \code{NULL} and +\code{newgraph = TRUE}, one is built from \code{edgefile}.} + +\item{edgefile}{A data frame edge list used to construct the graph when +\code{newgraph = TRUE} and to extract edge attributes.} + +\item{newgraph}{Logical; if \code{TRUE}, build a new \code{igraph} object +from \code{edgefile} before computing paths.} +} +\value{ +A data frame of edges along all shortest paths between the two nodes. +} +\description{ +Uses \code{igraph::all_shortest_paths} to find all shortest paths between +two nodes and returns the union of edges along those paths. +} diff --git a/man/cytoscape.graph.PCN.pathways.Rd b/man/cytoscape.graph.PCN.pathways.Rd new file mode 100644 index 00000000..57a1c87a --- /dev/null +++ b/man/cytoscape.graph.PCN.pathways.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CytoscapeGraphingFunctions.R +\name{cytoscape.graph.PCN.pathways} +\alias{cytoscape.graph.PCN.pathways} +\title{Graph a Pathway Crosstalk Network in Cytoscape} +\usage{ +cytoscape.graph.PCN.pathways( + PCN = pathway.crosstalk.network, + net.name, + Jaccard.edges = TRUE +) +} +\arguments{ +\item{PCN}{A data frame representing the pathway crosstalk network with columns +\code{source}, \code{target}, \code{interaction}, and \code{Weight}.} + +\item{net.name}{A character string used as the base network title in Cytoscape.} + +\item{Jaccard.edges}{Logical; if \code{FALSE}, pathway Jaccard similarity edges +are removed before plotting. Defaults to \code{TRUE}.} +} +\value{ +Called for its side effects; creates a network in Cytoscape. +} +\description{ +Creates a Cytoscape network from a Pathway Crosstalk Network (PCN) data frame, +applying edge color and width mappings. Requires Cytoscape to be open and +\code{RCy3} to be installed. +} diff --git a/man/ex_tiny_ptm_table.Rd b/man/ex_tiny_ptm_table.Rd index 37472f6b..4613109a 100644 --- a/man/ex_tiny_ptm_table.Rd +++ b/man/ex_tiny_ptm_table.Rd @@ -22,6 +22,6 @@ ex_tiny_ptm_table Post-translational modification data under certain environmental conditions. } \examples{ -head(ex_small_ptm_table) +head(ex_tiny_ptm_table) } \keyword{internal} diff --git a/man/filter.edges.0.Rd b/man/filter.edges.0.Rd index 4f961d03..5f21fe2c 100644 --- a/man/filter.edges.0.Rd +++ b/man/filter.edges.0.Rd @@ -2,288 +2,18 @@ % Please edit documentation in R/CytoscapeGraphingFunctions.R \name{filter.edges.0} \alias{filter.edges.0} -\title{Graphing and Manipulating Cluster Filtered Network} +\title{Filter an edge file to edges between a specified set of nodes} \usage{ filter.edges.0(nodenames, edge.file) } \arguments{ -\item{cfn}{A version of ppi.network with only the edges that exist in cccn.matrix and have non-zero weights} +\item{nodenames}{Character vector of node names to retain.} -\item{ptmtable}{A dataset for post-translational modifications. Formatted with numbered rows, and the first column containing PTM names. The rest of the column names should be drugs. Values are numeric values that represent how much the PTM has reacted to the drug.} - -\item{funckey}{A table graphing gene names to type of protein; defaults to the internal dataset \code{PTMsToPathways::function_key}} - -\item{Network.title}{Desired title for the created Cytoscape Network; defaults to "cfn"} - -\item{Network.collection}{Desired name for the collection created on Cytoscape in which the network will reside; defaults to "PTMsToPathways"} - -\item{visual.style.name}{Desired name for the visual style created on Cytoscape; defaults to "PTMsToPathways.style"} - -\item{background.color}{Hex code of background color of graph; defaults to '#fcf3cf'} - -\item{edge.label.color}{Hex code of edge label color of graph; defaults to '#17202a'} - -\item{node.label.color}{Hex code of node label color of graph; defaults to '#145a32'} - -\item{default.font}{Font style of edge and node names; defaults to "Times New Roman"} - -\item{node.font.size}{Font size of the node name; defaults to 12} - -\item{edge.font.size}{Font size of the edge name; defaults to 8} - -\item{edge.line.style}{Type of edge style; defaults to "SOLID"; options include: "PARALLEL_LINES", "MARQUEE_EQUAL", "DOT", "EQUAL_DASH", "LONG_DASH", "CONTIGUOUS_ARROW", "MARQUEE_DASH", "DASH_DOT", "BACKWARD_SLASH", "FORWARD_SLASH", "VERTICAL_SLASH", "SOLID", "SEPARATE_ARROW", "MARQUEE_DASH_DOT", "ZIGZAG", "SINEWAVE"} - -\item{edge.opacity}{Opacity of the edge line on a scale of 0 - 255 with 0 being transparent; defaults to 175} - -\item{edge.label.opacity}{Opacity of the edge label on a scale of 0 - 255 with 0 being transparent; defaults to 255} - -\item{border.opacity}{Opacity of the node border on a scale of 0 - 255 with 0 being transparent; defaults to 255} - -\item{node.label.opacity}{Opacity of the node label on a scale of 0 - 255 with 0 being transparent; defaults to 255} - -\item{node.fill.opacity}{Opacity of the node fill on a scale of 0 - 255 with 0 being transparent; defaults to 255} +\item{edge.file}{A data frame edge list with node names in columns 1 and 2.} } \value{ -A cytoscape graph of the cluster filtered network +A data frame of filtered edges, or \code{NA} if no edges remain. } \description{ -Creates a cytoscape graph of the cluster filtered network. Ensure that you have the Cytoscape app open and the RCy3 package downloaded. -The package RCy3 is required for many of the functions in this script. To download, run: -\itemize{ -\item if (!require("BiocManager", quietly = TRUE)) install.packages("BiocManager") -\item BiocManager::install("RCy3") -It is also recommended (but not required) that users load RCy3 with library(RCy3) to access its functions directly. -} -} -\details{ -Graph Key -\itemize{ -\item Node Size -\itemize{ -\item Greater the node size, larger the absolute value of the score -} -\item Blue Node -\itemize{ -\item Negative score -} -\item Yellow Node -\itemize{ -\item Positive score -} -\item Green Node -\itemize{ -\item Approximately zero score -Node Shapes: -} -\item "ELLIPSE" -\itemize{ -\item unknown -} -\item "ROUND_RECTANGLE" -\itemize{ -\item receptor tyrosine kinase -} -\item "VEE" -\itemize{ -\item SH2 protein -or -\item SH2-SH3 protein -} -\item "TRIANGLE" -\itemize{ -\item SH3 protein -} -\item "HEXAGON" -\itemize{ -\item tyrosine kinase -} -\item "DIAMOND" -\itemize{ -\item SRC-family kinase -} -\item "OCTAGON" -\itemize{ -\item kinase -or -\item phosphatase -} -\item "PARALLELOGRAM" -\itemize{ -\item transcription factor -} -\item "RECTANGLE" -\itemize{ -\item RNA binding protein -Node Border Colors: -} -\item Orange -\itemize{ -\item deacetylase -or -\item acetyltransferase -} -\item Blue -\itemize{ -\item demethylase -or -\item methyltransferase -} -\item Royal Purple -\itemize{ -\item membrane protein -} -\item Red -\itemize{ -\item kinase -or -\item tyrosine kinase -or -\item SRC-family kinase -} -\item Yellow -\itemize{ -\item phosphatase -or -\item tyrosine phosphatase -} -\item Lilac -\itemize{ -\item G protein-coupled receptor -or -\item receptor tyrosine kinase -} -\item Grey -\itemize{ -\item default -} -\item Edge Thickness -\itemize{ -\item Stronger correlation -Edge Colors: -} -\item Red -\itemize{ -\item Phosphorylation -or -\item pp -or -\item controls-phosphorylation-of -} -\item Bright Magenta -\itemize{ -\item controls-expression-of -} -\item Dull Magenta -\itemize{ -\item controls-transport-of -} -\item Purple -\itemize{ -\item controls-state-change-of -} -\item Blood Orange -\itemize{ -\item Acetylation -} -\item Lime Green -\itemize{ -\item Phystical interactions -} -\item Green -\itemize{ -\item BioPlex -} -\item Dull Green -\itemize{ -\item in-complex-with -} -\item Seafoam Green -\itemize{ -\item experiments -or -\item experiments_transferred -} -\item Cyan -\itemize{ -\item database -or -\item database_transferred -} -\item Teal -\itemize{ -\item Pathway -or -\item Predicted -} -\item Dark Turquoise -\itemize{ -\item Genetic interactions -} -\item Yellow-Orange -\itemize{ -\item correlation -} -\item Royal Blue -\itemize{ -\item negative correlation -} -\item Bright Yellow -\itemize{ -\item positive correlation -} -\item Grey -\itemize{ -\item combined_score -} -\item Dark Grey -\itemize{ -\item merged -} -\item Light Grey -\itemize{ -\item intersect -} -\item Black -\itemize{ -\item peptide -} -\item Orange -\itemize{ -\item homology -} -\item Dull Orange -\itemize{ -\item Shared protein domains -} -\item White -\itemize{ -\item Default -Arrow Types: -} -\item Arrow -\itemize{ -\item Phosphorylation -or -\item pp -or -\item controls-phosphorylation-of -or -\item controls-expression-of -or -\item controls-transport-of -or -\item controls-state-change-of -or -\item Acetylation -} -\item No Arrow -\itemize{ -\item Default -} -} -} -\examples{ -# GraphCFN(ex.cfn) -# See vignette for default graph - +Returns only edges where both endpoints are in \code{nodenames}. } diff --git a/man/filter.edges.1.Rd b/man/filter.edges.1.Rd new file mode 100644 index 00000000..31799a46 --- /dev/null +++ b/man/filter.edges.1.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CytoscapeGraphingFunctions.R +\name{filter.edges.1} +\alias{filter.edges.1} +\title{Filter an edge file to include first-order neighbours of specified nodes} +\usage{ +filter.edges.1(nodenames, edge.file) +} +\arguments{ +\item{nodenames}{Character vector of seed node names.} + +\item{edge.file}{A data frame edge list with node names in columns 1 and 2.} +} +\value{ +A data frame of edges involving at least one node in \code{nodenames}, +or \code{NA} if no edges remain. +} +\description{ +Returns all edges where at least one endpoint is in \code{nodenames}, +effectively including the nodes themselves and all directly connected neighbours. +} diff --git a/man/filter.edges.between.Rd b/man/filter.edges.between.Rd new file mode 100644 index 00000000..341d5b4f --- /dev/null +++ b/man/filter.edges.between.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CytoscapeGraphingFunctions.R +\name{filter.edges.between} +\alias{filter.edges.between} +\title{Filter an edge file to edges between two sets of nodes} +\usage{ +filter.edges.between(nodes1, nodes2, edge.file, convert = FALSE) +} +\arguments{ +\item{nodes1}{Character vector of the first set of node names.} + +\item{nodes2}{Character vector of the second set of node names.} + +\item{edge.file}{A data frame edge list with node names in columns 1 and 2.} + +\item{convert}{Logical; currently unused, reserved for future type conversion.} +} +\value{ +A data frame of edges connecting \code{nodes1} to \code{nodes2}, +or \code{NA} if no such edges exist. +} +\description{ +Returns edges where one endpoint is in \code{nodes1} and the other is in +\code{nodes2}, in either direction. +} diff --git a/man/get.co.clustered.ptms.Rd b/man/get.co.clustered.ptms.Rd new file mode 100644 index 00000000..62794ae6 --- /dev/null +++ b/man/get.co.clustered.ptms.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CytoscapeGraphingFunctions.R +\name{get.co.clustered.ptms} +\alias{get.co.clustered.ptms} +\title{Retrieve co-clustered PTM CCCN edges for genes in an edge file} +\usage{ +get.co.clustered.ptms(edge.file, ptm.cccn.edges) +} +\arguments{ +\item{edge.file}{A data frame edge list whose nodes are gene names.} + +\item{ptm.cccn.edges}{A data frame of PTM co-expression correlation network +edges with PTM identifiers as node names.} +} +\value{ +An edge data frame combining the original gene edges, co-clustered +PTM edges, and gene-to-peptide linking edges. +} +\description{ +Subsets the PTM CCCN to the PTMs belonging to genes present in +\code{edge.file}, then appends gene-to-peptide edges so the result +can be directly used as an extended edge list in Cytoscape. +} diff --git a/man/getCyEdgeNames.Rd b/man/getCyEdgeNames.Rd new file mode 100644 index 00000000..524089d3 --- /dev/null +++ b/man/getCyEdgeNames.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CytoscapeGraphingFunctions.R +\name{getCyEdgeNames} +\alias{getCyEdgeNames} +\title{Get Cytoscape-formatted edge names} +\usage{ +getCyEdgeNames(edgefile) +} +\arguments{ +\item{edgefile}{A data frame with columns \code{source}, \code{interaction}, +and \code{target}.} +} +\value{ +A character vector of edge name strings. +} +\description{ +Constructs edge name strings in the format Cytoscape uses internally +(\code{source (interaction) target}), suitable for use with +\code{RCy3::selectEdges}. +} diff --git a/man/harmonize_cfs.Rd b/man/harmonize_cfs.Rd new file mode 100644 index 00000000..4a6c4a4a --- /dev/null +++ b/man/harmonize_cfs.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CytoscapeGraphingFunctions.R +\name{harmonize_cfs} +\alias{harmonize_cfs} +\title{Harmonize gene and PTM node tables for a combined CFN/CCCN network} +\usage{ +harmonize_cfs(edge.file.with.ptms, genecf, ptmtable) +} +\arguments{ +\item{edge.file.with.ptms}{A data frame edge list containing both gene and +PTM (\code{interaction == "peptide"}) edges.} + +\item{genecf}{A gene-level node attribute data frame, typically produced by +\code{make.cytoscape.node.file}.} + +\item{ptmtable}{A PTM data frame with PTM identifiers as row names and +numeric condition columns.} +} +\value{ +A merged data frame of gene and PTM node attributes with \code{id} +as the first column, suitable for \code{RCy3::createNetworkFromDataFrames}. +} +\description{ +Merges a gene-level node attribute table with PTM-level rows derived from +the PTM table, ensuring the \code{id} column is present and used as the +Cytoscape node key. PTM nodes are annotated from the function key and +linked to their parent genes via a \code{parent} column. +} diff --git a/man/make.cytoscape.node.file.Rd b/man/make.cytoscape.node.file.Rd new file mode 100644 index 00000000..ae498cb0 --- /dev/null +++ b/man/make.cytoscape.node.file.Rd @@ -0,0 +1,39 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CytoscapeGraphingFunctions.R +\name{make.cytoscape.node.file} +\alias{make.cytoscape.node.file} +\title{Build a Cytoscape node attribute table from an edge file} +\usage{ +make.cytoscape.node.file( + edge.file, + funckey, + ptmtable, + include.gene.data = FALSE, + include.coclustered.PTMs = FALSE +) +} +\arguments{ +\item{edge.file}{A data frame edge list with node names in columns 1 and 2 +and an \code{interaction} column.} + +\item{funckey}{A data frame mapping gene names to protein annotations +(e.g., \code{PTMsToPathways::function_key}).} + +\item{ptmtable}{A PTM data frame with PTM identifiers as row names and +numeric condition columns.} + +\item{include.gene.data}{Logical; if \code{TRUE}, append gene-level +summarised PTM values to the node table. Defaults to \code{FALSE}.} + +\item{include.coclustered.PTMs}{Logical; if \code{TRUE}, add co-clustered +PTM nodes and their edges to the output. Defaults to \code{FALSE}.} +} +\value{ +A data frame of node attributes with an \code{id} column suitable +for \code{RCy3::createNetworkFromDataFrames}. +} +\description{ +Extracts unique gene nodes from an edge file, annotates them using the +function key, and optionally appends gene-level PTM data and co-clustered +PTM nodes. +} diff --git a/man/make.gene.data.from.ptmtable.Rd b/man/make.gene.data.from.ptmtable.Rd new file mode 100644 index 00000000..ec3fa63a --- /dev/null +++ b/man/make.gene.data.from.ptmtable.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CytoscapeGraphingFunctions.R +\name{make.gene.data.from.ptmtable} +\alias{make.gene.data.from.ptmtable} +\title{Summarise PTM table data to gene level} +\usage{ +make.gene.data.from.ptmtable(genes, ptmtable) +} +\arguments{ +\item{genes}{Character vector of gene names to retain.} + +\item{ptmtable}{A PTM data frame with PTM identifiers (\code{"GENE site"}) as +row names and numeric drug/condition columns.} +} +\value{ +A data frame with one row per gene and summed numeric columns. +} +\description{ +Subsets a PTM table to genes of interest and collapses PTM-level numeric +values to gene-level sums, suitable for loading into Cytoscape node attributes. +} diff --git a/man/make.genepep.edges.Rd b/man/make.genepep.edges.Rd index f0bb0c3b..5b6811df 100644 --- a/man/make.genepep.edges.Rd +++ b/man/make.genepep.edges.Rd @@ -2,10 +2,19 @@ % Please edit documentation in R/CytoscapeGraphingFunctions.R \name{make.genepep.edges} \alias{make.genepep.edges} -\title{Title} +\title{Create gene-to-peptide edges from a PTM edge file} \usage{ make.genepep.edges(peptide.edgefile) } +\arguments{ +\item{peptide.edgefile}{A data frame edge list whose node names follow the +\code{"GENE site"} PTM naming convention.} +} +\value{ +A data frame with columns \code{source}, \code{target}, +\code{Weight}, and \code{interaction} (\code{"peptide"}). +} \description{ -Title +Generates a new edge data frame linking each PTM node (\code{"GENE site"}) +to its parent gene node, for use in combined gene/PTM Cytoscape networks. } diff --git a/man/mergeEdges.Rd b/man/mergeEdges.Rd new file mode 100644 index 00000000..78c26b74 --- /dev/null +++ b/man/mergeEdges.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CytoscapeGraphingFunctions.R +\name{mergeEdges} +\alias{mergeEdges} +\title{Merge duplicate edges in an edge file} +\usage{ +mergeEdges(edgefile) +} +\arguments{ +\item{edgefile}{A data frame edge list with columns \code{source}, +\code{target}, \code{interaction}, and \code{Weight}.} +} +\value{ +A deduplicated data frame edge list. +} +\description{ +Consolidates an edge file by collapsing parallel edges (same source/target) +into a single row. For directed edge types, the highest-priority interaction +is kept; for undirected edges, all interaction types are concatenated with +\code{" | "}. Self-loops are removed from the result. +} diff --git a/man/outersect.Rd b/man/outersect.Rd new file mode 100644 index 00000000..8458219a --- /dev/null +++ b/man/outersect.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CytoscapeGraphingFunctions.R +\name{outersect} +\alias{outersect} +\title{Symmetric set difference of two vectors} +\usage{ +outersect(x, y) +} +\arguments{ +\item{x}{A vector.} + +\item{y}{A vector.} +} +\value{ +A sorted vector of elements present in exactly one of \code{x} or \code{y}. +} +\description{ +Returns elements that are in either \code{x} or \code{y} but not in both +(i.e., the outer- or exclusive union). +} diff --git a/man/ptms_to_cfn.Rd b/man/ptms_to_cfn.Rd index c179d6e0..10c0eda8 100644 --- a/man/ptms_to_cfn.Rd +++ b/man/ptms_to_cfn.Rd @@ -30,6 +30,8 @@ cfn.merged <- data.frame(source = c("TP53", "BRCA1", "BRCA1", "MDM2"), cluster = c(1,1,2,1)) # Suppose filter.edges.0 and get.co.clustered.ptms are also defined and loaded # The following returns the gene/PTM subnetwork +\dontrun{ res <- ptms_to_cfn(ptms, cfn = cfn.merged, pepsep = ";") print(res) } +} diff --git a/man/remove.autophos.Rd b/man/remove.autophos.Rd index 7d8c3550..407cbaa2 100644 --- a/man/remove.autophos.Rd +++ b/man/remove.autophos.Rd @@ -2,10 +2,17 @@ % Please edit documentation in R/CytoscapeGraphingFunctions.R \name{remove.autophos} \alias{remove.autophos} -\title{Title} +\title{Remove self-loop edges from an edge file} \usage{ remove.autophos(edgefile) } +\arguments{ +\item{edgefile}{A data frame edge list with \code{source} and \code{target} +columns.} +} +\value{ +The edge file with self-loop rows removed. +} \description{ -Title +Drops any rows where the source and target node are identical. } diff --git a/man/setCorrEdgeAppearance.Rd b/man/setCorrEdgeAppearance.Rd index 8e6875a6..01e54131 100644 --- a/man/setCorrEdgeAppearance.Rd +++ b/man/setCorrEdgeAppearance.Rd @@ -2,10 +2,15 @@ % Please edit documentation in R/CytoscapeGraphingFunctions.R \name{setCorrEdgeAppearance} \alias{setCorrEdgeAppearance} -\title{Title} +\title{Apply edge visual mappings in the active Cytoscape network} \usage{ setCorrEdgeAppearance() } +\value{ +Called for its side effects in Cytoscape. +} \description{ -Title +Sets edge line widths (log-scaled from correlation weights), colors, and +arrow types based on the \code{interaction} column. Handles merged edge +labels by extracting the primary interaction type before applying mappings. } diff --git a/man/setEdgeWidths.Rd b/man/setEdgeWidths.Rd new file mode 100644 index 00000000..a3b36d8e --- /dev/null +++ b/man/setEdgeWidths.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CytoscapeGraphingFunctions.R +\name{setEdgeWidths} +\alias{setEdgeWidths} +\title{Adjust edge line widths in the active Cytoscape network} +\usage{ +setEdgeWidths(ffactor = -1.2, log = TRUE) +} +\arguments{ +\item{ffactor}{Numeric offset applied to all computed widths; a negative value +shifts widths down (narrower). Defaults to \code{-1.2}.} + +\item{log}{Logical; if \code{TRUE} (default), widths are computed as +\code{log(|Weight|) + ffactor - min(log(|Weight|))}. If \code{FALSE}, +widths are \code{ffactor * |Weight|}.} +} +\value{ +Called for its side effects in Cytoscape. +} +\description{ +Computes edge widths from the \code{Weight} column of the Cytoscape edge +table, optionally log-transforming the values, and loads them back as a +continuous edge width mapping. +} diff --git a/man/setNodeColorToRatios.Rd b/man/setNodeColorToRatios.Rd new file mode 100644 index 00000000..742ccb05 --- /dev/null +++ b/man/setNodeColorToRatios.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CytoscapeGraphingFunctions.R +\name{setNodeColorToRatios} +\alias{setNodeColorToRatios} +\title{Map node size and color to ratio-scale data in Cytoscape} +\usage{ +setNodeColorToRatios(plotcol) +} +\arguments{ +\item{plotcol}{A character string naming the node table column to map to +both node size and node color.} +} +\value{ +Called for its side effects in Cytoscape. +} +\description{ +Applies continuous node size and color mappings to the active Cytoscape +network using fixed log2-based control points suited for ratio or +fold-change data centered on zero. +} diff --git a/man/setNodeColorToRowz.Rd b/man/setNodeColorToRowz.Rd new file mode 100644 index 00000000..084bc149 --- /dev/null +++ b/man/setNodeColorToRowz.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CytoscapeGraphingFunctions.R +\name{setNodeColorToRowz} +\alias{setNodeColorToRowz} +\title{Map node size and color to row z-score data in Cytoscape} +\usage{ +setNodeColorToRowz(plotcol) +} +\arguments{ +\item{plotcol}{A character string naming the node table column to map to +both node size and node color.} +} +\value{ +Called for its side effects in Cytoscape. +} +\description{ +Applies continuous node size and color mappings to the active Cytoscape +network using log2-based control points suited for row z-score normalised data. +} diff --git a/man/setNodeMapping.Rd b/man/setNodeMapping.Rd new file mode 100644 index 00000000..e78d1651 --- /dev/null +++ b/man/setNodeMapping.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CytoscapeGraphingFunctions.R +\name{setNodeMapping} +\alias{setNodeMapping} +\title{Apply node visual mappings in the active Cytoscape network} +\usage{ +setNodeMapping(cf = RCy3::getTableColumns("node")) +} +\arguments{ +\item{cf}{A data frame of node attributes from the active Cytoscape network; +defaults to the full node table retrieved via \code{RCy3::getTableColumns}.} +} +\value{ +Called for its side effects in Cytoscape. +} +\description{ +Sets default node appearance (shape, color, size, border) and applies +discrete visual mappings for node shape and border color based on the +\code{nodeType} column from the function key. +} diff --git a/man/strip.cy.goo.Rd b/man/strip.cy.goo.Rd new file mode 100644 index 00000000..7c3c4e7a --- /dev/null +++ b/man/strip.cy.goo.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CytoscapeGraphingFunctions.R +\name{strip.cy.goo} +\alias{strip.cy.goo} +\title{Strip Cytoscape metadata strings to extract node names} +\usage{ +strip.cy.goo(test) +} +\arguments{ +\item{test}{Character vector of raw Cytoscape node identifier strings.} +} +\value{ +A character vector of extracted node names. +} +\description{ +Parses verbose Cytoscape node identifier strings of the form +\code{"...Object=NODENAME, ..."} and returns just the node name portion. +} diff --git a/vignettes/CreatingNetworks.Rmd b/vignettes/CreatingNetworks.Rmd index 40748bb6..ecf3487c 100644 --- a/vignettes/CreatingNetworks.Rmd +++ b/vignettes/CreatingNetworks.Rmd @@ -442,7 +442,7 @@ And we can see some of the pathway crosstalk network edges below: pathway.crosstalk.network[1:5,] ``` -```{r eval = TRUE, echo = TRUE} +```{r eval = TRUE, echo = FALSE} dat <- pathway.crosstalk.network[1:5,] knitr::kable(dat, align = 'l', digits = 2) ```