├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ └── check-bioc.yml ├── .gitignore ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── NEWS.md ├── R ├── HMDB_mapper_vec.R ├── binarize_with_sign.R ├── check_COSMOS_inputs.R ├── check_gene_names.R ├── check_inputs_CARNIVAL.R ├── check_network_data_coverage.R ├── compress_same_children.R ├── cosmos_data.R ├── decoupleRnival.R ├── default_CARNIVAL_options.R ├── discretize_vector.R ├── display_node_neighboorhood.R ├── filter_input_nodes_not_in_pkn.R ├── filter_pkn_expressed_genes.R ├── filter_transcriptional_regulations.R ├── format_COSMOS_results.R ├── get_TF_activity_from_CARNIVAL.R ├── keep_downstream_neighbours.R ├── limit_string_vec.R ├── load_tf_regulon_dorothea.R ├── meta_network.R ├── prepare_metab_inputs.R ├── preprocess_COSMOS.R ├── preprocess_COSMOS_metabolism_to_signaling.R ├── preprocess_COSMOS_signaling_to_metabolism.R ├── process_CARNIVAL_results.R ├── runCARNIVAL_wrapper.R ├── run_COSMOS_metabolism_to_signaling.R ├── run_COSMOS_signaling_to_metabolism.R ├── support_ORA.R ├── support_decoupleR.R ├── support_pheatmap.R ├── sysdata.rda ├── toy_RNA.R ├── toy_metabolic_input.R ├── toy_network.R └── toy_signaling_input.R ├── README.md ├── data ├── HMDB_mapper_vec.RData ├── meta_network.RData ├── toy_RNA.RData ├── toy_metabolic_input.RData ├── toy_network.RData └── toy_signaling_input.RData ├── inst └── CITATION ├── man ├── HMDB_mapper_vec.Rd ├── compress_same_children.Rd ├── cosmos_data.Rd ├── createLinearColors.Rd ├── decompress_moon_result.Rd ├── decompress_solution_network.Rd ├── decoupleRnival.Rd ├── default_CARNIVAL_options.Rd ├── display_node_neighboorhood.Rd ├── extract_nodes_for_ORA.Rd ├── figures │ ├── graphical_abstract.png │ ├── intro_data.png │ ├── logo.png │ └── summary.png ├── filter_incohrent_TF_target.Rd ├── format_COSMOS_res.Rd ├── format_LR_ressource.Rd ├── get_moon_scoring_network.Rd ├── gmt_to_dataframe.Rd ├── load_tf_regulon_dorothea.Rd ├── make_heatmap_color_palette.Rd ├── meta_network.Rd ├── meta_network_cleanup.Rd ├── moon.Rd ├── prepare_metab_inputs.Rd ├── preprocess_COSMOS_metabolism_to_signaling.Rd ├── preprocess_COSMOS_signaling_to_metabolism.Rd ├── print.cosmos_data.Rd ├── reduce_solution_network.Rd ├── run_COSMOS_metabolism_to_signaling.Rd ├── run_COSMOS_signaling_to_metabolism.Rd ├── toy_RNA.Rd ├── toy_metabolic_input.Rd ├── toy_network.Rd ├── toy_signaling_input.Rd ├── translate_column_HMDB.Rd ├── translate_res.Rd └── wide_ulm_res.Rd ├── pkgdown ├── _pkgdown.yml ├── extra.css └── favicon │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ ├── apple-touch-icon-180x180.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ └── favicon.ico ├── tests ├── testthat.R └── testthat │ ├── test-check_COSMOS_inputs.R │ ├── test-cosmos_data.R │ ├── test-load_tf_regulon_dorothea.R │ ├── test-preprocess_COSMOS.R │ ├── test-run_COSMOS_metabolism_to_signaling.R │ └── test-run_COSMOS_signaling_to_metabolism.R └── vignettes ├── M2Cf └── figs │ ├── Activity_estimations_for_factor_4_1.png │ ├── Activity_estimations_for_factor_4_2.png │ ├── Chekc_cross_correlation_of_omics_compared_to_variance_epxlained_1.png │ ├── Chekc_cross_correlation_of_omics_compared_to_variance_epxlained_2.png │ ├── Chekc_cross_correlation_of_omics_compared_to_variance_epxlained_3.png │ ├── Compare_MOFA_models_1.png │ ├── Factor_weights_per_view_1.png │ ├── Plot_Ligand_receptor_activity_estimates_1.png │ ├── Plot_Metabolite_factor_weights_1.png │ ├── Plot_RNA_weights_and_protein_weights_1.png │ ├── Plot_RNA_weights_and_protein_weights_2.png │ ├── Plot_TF_activity_estimates_1.png │ ├── Preparing_MOFA_input_1.png │ ├── Preparing_MOFA_input_2.png │ ├── Preparing_MOFA_input_3.png │ ├── Preparing_MOFA_input_4.png │ ├── Preparing_MOFA_input_5.png │ ├── Run_moon_rec_to_TFmetab_1.png │ ├── Supp_figure_condition_prot_RNA_correlation_1.png │ ├── Supp_figure_single_prot_RNA_correlation_1.png │ ├── Total_variance_per_factor_1.png │ ├── Variance_per_view_per_factor_1.png │ ├── correlation_RNA │ └── prot-1.png │ └── run_moon_TF_to_lig_1.png ├── MOFA_to_COSMOS.Rmd ├── MOFA_to_COSMOS.md ├── NCI60_tutorial.Rmd ├── net_compr_MOON.md ├── net_compr_MOON_files └── figure-markdown_strict │ └── extract_subnetwork_from_scored_MOON_network_1.png └── tutorial.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^.git$ 4 | ^pkgdown$ 5 | cosmos_cache 6 | docs 7 | ^\.github$ 8 | ^devel$ 9 | ^doc$ 10 | ^Meta$ 11 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | *.Rproj 3 | .Rhistory 4 | .Rprofile 5 | vignettes/.Rhistory 6 | vignettes/.Rhistory 7 | vignettes/Tutorial.pdf 8 | vignettes/Tutorial.html 9 | .DS_Store 10 | 11 | docs/ 12 | /doc/ 13 | /Meta/ 14 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: cosmosR 2 | Type: Package 3 | Title: COSMOS (Causal Oriented Search of Multi-Omic Space) 4 | Version: 1.9.1 5 | Description: COSMOS (Causal Oriented Search of Multi-Omic Space) is a method 6 | that integrates phosphoproteomics, transcriptomics, and metabolomics data sets 7 | based on prior knowledge of signaling, metabolic, and gene regulatory 8 | networks. It estimated the activities of transcrption factors and kinases 9 | and finds a network-level causal reasoning. Thereby, COSMOS provides 10 | mechanistic hypotheses for experimental observations across mulit-omics datasets. 11 | Authors@R: c( 12 | person(given = "Aurélien", 13 | family = "Dugourd", 14 | role = c("aut"), 15 | email = "dugourdaurelien@gmail.com", 16 | comment = c(ORCID = "0000-0002-0714-028X")), 17 | person(given = "Attila", 18 | family = "Gabor", 19 | role = c("cre"), 20 | email = "attila.gabor@uni-heidelberg.de", 21 | comment = c(ORCID = "0000-0002-0776-1182")), 22 | person(given = "Katharina", 23 | family = "Zirngibl", 24 | role = c("aut"), 25 | email = "katharina.zirngibl@uni-heidelberg.de", 26 | comment = c(ORCID = "0000-0002-7518-0339"))) 27 | URL: https://github.com/saezlab/COSMOSR 28 | BugReports: https://github.com/saezlab/COSMOSR/issues 29 | Depends: R (>= 4.1) 30 | License: GPL-3 31 | Encoding: UTF-8 32 | LazyData: false 33 | RoxygenNote: 7.2.3 34 | VignetteBuilder: knitr 35 | Imports: 36 | CARNIVAL, 37 | dorothea, 38 | dplyr, 39 | GSEABase, 40 | igraph, 41 | progress, 42 | purrr, 43 | rlang, 44 | stringr, 45 | utils, 46 | visNetwork, 47 | decoupleR 48 | Suggests: 49 | testthat, 50 | knitr, 51 | rmarkdown, 52 | htmltools, 53 | markdown, 54 | piano, 55 | ggplot2, 56 | stringi, 57 | reshape2 58 | biocViews: CellBiology, Pathways, Network, Proteomics, Metabolomics, Transcriptomics, 59 | GeneSignaling 60 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(print,cosmos_data) 4 | export(compress_same_children) 5 | export(createLinearColors) 6 | export(decompress_moon_result) 7 | export(decompress_solution_network) 8 | export(decoupleRnival) 9 | export(default_CARNIVAL_options) 10 | export(display_node_neighboorhood) 11 | export(extract_nodes_for_ORA) 12 | export(filter_incohrent_TF_target) 13 | export(format_COSMOS_res) 14 | export(format_LR_ressource) 15 | export(get_moon_scoring_network) 16 | export(load_tf_regulon_dorothea) 17 | export(make_heatmap_color_palette) 18 | export(meta_network_cleanup) 19 | export(moon) 20 | export(prepare_metab_inputs) 21 | export(preprocess_COSMOS_metabolism_to_signaling) 22 | export(preprocess_COSMOS_signaling_to_metabolism) 23 | export(reduce_solution_network) 24 | export(run_COSMOS_metabolism_to_signaling) 25 | export(run_COSMOS_signaling_to_metabolism) 26 | export(translate_column_HMDB) 27 | export(translate_res) 28 | export(wide_ulm_res) 29 | import(decoupleR) 30 | import(dplyr) 31 | importFrom(dplyr,"%>%") 32 | importFrom(dplyr,as_tibble) 33 | importFrom(dplyr,bind_rows) 34 | importFrom(dplyr,filter) 35 | importFrom(dplyr,mutate) 36 | importFrom(dplyr,rename) 37 | importFrom(dplyr,select) 38 | importFrom(progress,progress_bar) 39 | importFrom(purrr,map) 40 | importFrom(rlang,.data) 41 | importFrom(stringr,str_extract) 42 | importFrom(utils,data) 43 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | ## Changes in version 0.99.2 (2020-05-12) 2 | 3 | --- 4 | 5 | - Submitted to bioRxiv 6 | - Release of github page 7 | - Submitted to Bioconductor -------------------------------------------------------------------------------- /R/HMDB_mapper_vec.R: -------------------------------------------------------------------------------- 1 | #' Toy Input Transcription Data Set 2 | #' 3 | #' This exemplary transcription data are the specific deregulated gene expression of the 786-O cell line from the NCI60 dataset. 4 | #' 5 | #' @docType data 6 | #' 7 | #' @usage data(HMDB_mapper_vec) 8 | #' 9 | #' @format An object of class \dQuote{\code{character}} containing the marching between HMDB metabolite IDs and there coresponding metabolite names. 10 | #' 11 | #' @source 12 | #' \url{https://bioconductor.org/packages/release/data/annotation/html/metaboliteIDmapping.html} 13 | #' 14 | #' 15 | #' @examples 16 | #' data(HMDB_mapper_vec) 17 | #' 18 | #' @keywords datasets 19 | "HMDB_mapper_vec" -------------------------------------------------------------------------------- /R/binarize_with_sign.R: -------------------------------------------------------------------------------- 1 | #' binarize_with_sign 2 | #' 3 | #' binarizes the data based on the threshold using the absolute value of the data. 4 | #' Gives a sign based on the sign of the input data. 5 | #' @param data numerical vector 6 | #' @param threshold threshold used to binarise the data 7 | #' @noRd 8 | binarize_with_sign <- function(data,threshold){ 9 | 10 | out = sign(data) * as.numeric(abs(data) >= threshold) 11 | return(out) 12 | } 13 | -------------------------------------------------------------------------------- /R/check_COSMOS_inputs.R: -------------------------------------------------------------------------------- 1 | #' check_COSMOS_inputs 2 | #' 3 | #' checks the format of the main data inputs. Checks only the data that was 4 | #' passed (not NULL). 5 | #' @param meta_network prior knowledge network 6 | #' @param tf_regulon transcription factor regulon 7 | #' @param signaling_data named numerical vector 8 | #' @param metabolic_data named numerical vector 9 | #' @param expression_data named numerical vector 10 | #' @noRd 11 | check_COSMOS_inputs <- function(meta_network = NULL, 12 | tf_regulon = NULL, 13 | signaling_data = NULL, 14 | metabolic_data = NULL, 15 | expression_data = NULL){ 16 | # checking the data 17 | if(!is.null(signaling_data)) stopifnot(is.vector(signaling_data)) 18 | if(!is.null(metabolic_data)) stopifnot(is.vector(metabolic_data)) 19 | if(!is.null(expression_data)) stopifnot(is.vector(expression_data)) 20 | 21 | # check duplicated names 22 | if(!is.null(signaling_data) & anyDuplicated(names(signaling_data))) { 23 | stop("duplicated gene names in signaling data detected. ") 24 | } 25 | if(!is.null(expression_data) & anyDuplicated(names(expression_data))) { 26 | stop("duplicated gene names in expression_data detected. ") 27 | } 28 | if(!is.null(metabolic_data) & anyDuplicated(names(metabolic_data))) { 29 | stop("duplicated gene names in metabolic_data detected. ") 30 | } 31 | 32 | 33 | # checking the networks 34 | if(!is.null(meta_network)){ 35 | stopifnot(is.data.frame(meta_network)) 36 | stopifnot(all(c("source","interaction","target" ) %in% names(meta_network))) 37 | stopifnot(ncol(meta_network)==3) 38 | } 39 | 40 | if(!is.null(tf_regulon)){ 41 | stopifnot(is.data.frame(tf_regulon)) 42 | stopifnot(all(c("tf","sign","target" ) %in% names(tf_regulon))) 43 | stopifnot(ncol(meta_network)==3) 44 | } 45 | return(TRUE) 46 | } 47 | 48 | 49 | -------------------------------------------------------------------------------- /R/check_gene_names.R: -------------------------------------------------------------------------------- 1 | #' check_gene_names 2 | #' 3 | #' checks if gene names looks like an EntrezID with a prefix of X. 4 | #' @param ... takes named vectors 5 | #' @noRd 6 | check_gene_names <- function(...){ 7 | 8 | res = lapply(list(...),function(x){ 9 | if(any(duplicated(names(x)))){ 10 | stop("Duplicated gene names detected. Gene names in inputs should be unique.") 11 | } 12 | TRUE 13 | } 14 | ) 15 | 16 | return(unlist(res)) 17 | 18 | } 19 | -------------------------------------------------------------------------------- /R/check_inputs_CARNIVAL.R: -------------------------------------------------------------------------------- 1 | #' Check Inputs For CARNIVAL 2 | #' 3 | #' Checks the format of the main data inputs for CARNIVL. Checks the data format 4 | #' and coverage of nodes in the PKN and data. Ensures that all nodes in 5 | #' input_data and measured_data appear in the PKN. 6 | #' 7 | #' @param meta_network Prior knowledge network (PKN). \dQuote{\code{data.frame}} 8 | #' object with source, sign and target columns. By default COSMOS uses a PKN 9 | #' derived from Omnipath, STITCHdb and Recon3D. See details on the data 10 | #' \code{\link{meta_network}}. 11 | #' 12 | #' @param input_data Numerical vector, where names are input nodes in the PKN 13 | #' and values are from \{1, 0, -1\}. 14 | #' 15 | #' @param measured_data Numerical vector, where names are measured nodes in the 16 | #' PKN and values are continuous values. These values are compared to with 17 | #' the simulation. 18 | #' 19 | #' @seealso \code{\link{default_CARNIVAL_options}} 20 | #' @noRd 21 | check_inputs_for_CARNIVAL <- function(meta_network, 22 | input_data, 23 | measured_data){ 24 | # checking the data 25 | stopifnot(is.vector(input_data)) 26 | stopifnot(is.vector(measured_data)) 27 | 28 | # checking the networks 29 | 30 | stopifnot(is.data.frame(meta_network)) 31 | stopifnot(all(c("source","interaction","target" ) %in% names(meta_network))) 32 | stopifnot(ncol(meta_network)==3) 33 | 34 | # check inputs and measurements are in the network 35 | stopifnot(all(names(input_data) %in% c(meta_network$source, meta_network$target))) 36 | stopifnot(all(names(measured_data) %in% c(meta_network$source, meta_network$target))) 37 | 38 | return(TRUE) 39 | } -------------------------------------------------------------------------------- /R/check_network_data_coverage.R: -------------------------------------------------------------------------------- 1 | 2 | #' checks coverage between data and prior knowledge 3 | #' 4 | #' checks the following 5 | #' - signaling data nodes are in PKN 6 | #' - metabolic data nodes are in PKN 7 | #' - expression data genes overlap with TF targets 8 | #' Stops if a check fails 9 | #' 10 | #' @param meta_network contains the PKN 11 | #' @param tf_regulon (optional) tf-target network with EntrezID 12 | #' @param signaling_data numerical vector, where names are signaling nodes 13 | #' in the PKN and values are from \{1,-1\} 14 | #' @param metabolic_data numerical vector, where names are metabolic nodes 15 | #' in the PKN and values are continuous values. These values are compared to 16 | #' with the the simulation [? range of values] 17 | #' @param expression_data (optional) numerical vector, where names are gene names 18 | #' and values are from \{1,-1\} 19 | #' @param verbose (default: TRUE) reports coverage 20 | #' @noRd 21 | 22 | 23 | # expand_metabolic_data format metabolic data to match meta_network nodes? 24 | # It will add "XMetab__" before the pubchem IDs and all the possible compartments 25 | # after it. (e.g, "1150" will become "Xmetab__1150___c____" and "Xmetab__1150___e____") 26 | 27 | check_network_data_coverage <- function(meta_network, 28 | tf_regulon = NULL, 29 | signaling_data, 30 | metabolic_data, 31 | expression_data = NULL, 32 | verbose = TRUE){ 33 | 34 | # signaling should be in PKN 35 | signaling_nodes = names(signaling_data) 36 | missing_nodes <- signaling_nodes[!signaling_nodes %in% c(meta_network$source, 37 | meta_network$target)] 38 | 39 | if(length(missing_nodes)>0){ 40 | 41 | message_missing_nodes <- paste("The following signaling nodes are not found in the PKN:", 42 | limit_string_vec(missing_nodes)) 43 | stop(message_missing_nodes) 44 | 45 | 46 | }else{ 47 | if(verbose) print(paste("COSMOS: all", length(signaling_nodes), 48 | "signaling nodes from data were found in the meta PKN")) 49 | } 50 | 51 | # metabolic nodes should be in PKN 52 | metabolic_nodes = names(metabolic_data) 53 | missing_nodes <- metabolic_nodes[!metabolic_nodes %in% c(meta_network$source, 54 | meta_network$target)] 55 | if(length(missing_nodes)>0){ 56 | 57 | message_missing_nodes <- paste("The following signaling nodes are not found in the PKN:", 58 | limit_string_vec(missing_nodes)) 59 | stop(message_missing_nodes) 60 | 61 | 62 | 63 | 64 | }else{ 65 | if(verbose) print(paste("COSMOS: all",length(metabolic_nodes) , 66 | "metabolic nodes from data were found in the meta PKN")) 67 | 68 | } 69 | 70 | # the expression data should overlap with the TF targets 71 | if(!is.null(tf_regulon) & !is.null(expression_data)){ 72 | genes = names(expression_data) 73 | genes_as_tf_target <- sum(genes %in% tf_regulon$target) 74 | 75 | if(verbose) print(paste0("COSMOS: ", genes_as_tf_target, 76 | " of the ",length(genes), 77 | " genes in expression data were found as transcription factor target")) 78 | if(verbose) print(paste0("COSMOS: ", sum( unique(tf_regulon$target) %in% genes), 79 | " of the ",length(unique(tf_regulon$target)), 80 | " transcription factor targets were found in expression data")) 81 | if(genes_as_tf_target==0){ 82 | print(genes, tf_regulon$target) 83 | stop("Expression data contains no gene that appear as transcription factor target. 84 | The expression_data must be a named vector using gene symboles.") 85 | } 86 | } 87 | 88 | 89 | } 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /R/compress_same_children.R: -------------------------------------------------------------------------------- 1 | #' Compress Network by Merging Nodes with Identical Children 2 | #' 3 | #' This function compresses a network by merging nodes that have the same children. 4 | #' The input network is represented as a data frame with three columns: source, target, and sign of interaction. 5 | #' The function returns a list containing the compressed network, node signatures, and duplicated signatures. 6 | #' 7 | #' @param df A data frame representing the network with three columns: source, target, and sign of interaction. 8 | #' @param sig_input A list of input node signatures to be considered for the merging process. 9 | #' @param metab_input A list of input metabolic signatures to be considered for the merging process. 10 | #' 11 | #' @return A list containing the following elements: 12 | #' \item{compressed_network}{A data frame representing the compressed network.} 13 | #' \item{node_signatures}{A list of signatures of nodes in the network after the merging process.} 14 | #' \item{duplicated_signatures}{A list of duplicated signatures in the network after the merging process.} 15 | #' 16 | #' @examples 17 | #' # Create a sample network 18 | #' df <- data.frame(source = c("A", "A", "B", "B"), 19 | #' target = c("C", "D", "C", "D"), 20 | #' sign_of_interaction = c(1, 1, 1, 1)) 21 | #' 22 | #' # Define input node and metabolic signatures 23 | #' sig_input <- list() 24 | #' metab_input <- list() 25 | #' 26 | #' # Compress the network 27 | #' result <- compress_same_children(df, sig_input, metab_input) 28 | #' compressed_network <- result$compressed_network 29 | #' 30 | #' @export 31 | compress_same_children <- function(df, sig_input, metab_input) 32 | { 33 | nodes <- unique(c(df$source,df$target)) 34 | 35 | parents <- nodes[which(nodes %in% df$source)] 36 | 37 | df_signature <- df 38 | df_signature[,2] <- paste(df_signature[,2],df_signature[,3],sep = "") 39 | 40 | node_signatures <- sapply(parents, function(parent,df_signature){ 41 | 42 | return(paste("parent_of_",paste0(unlist(df_signature[which(df_signature[,1] == parent),2]), collapse = "_____"), sep = "")) 43 | },df_signature = df_signature, USE.NAMES = T, simplify = F) 44 | 45 | dubs <- node_signatures[duplicated(node_signatures) & 46 | !(names(node_signatures) %in% names(metab_input) | 47 | names(node_signatures) %in% names(sig_input))] 48 | 49 | duplicated_parents <- unlist(node_signatures[which(node_signatures %in% dubs)]) 50 | 51 | df[,1] <- sapply(df[,1], function(node,duplicated_parents){ 52 | if(node %in% names(duplicated_parents)) 53 | { 54 | node <- duplicated_parents[node] 55 | } 56 | return(node) 57 | },duplicated_parents = duplicated_parents, simplify = T) 58 | 59 | df[,2] <- sapply(df[,2], function(node,duplicated_parents){ 60 | if(node %in% names(duplicated_parents)) 61 | { 62 | node <- duplicated_parents[node] 63 | } 64 | return(node) 65 | },duplicated_parents = duplicated_parents, simplify = T) 66 | 67 | df <- unique(df) 68 | 69 | return(list("compressed_network" = df, "node_signatures" = node_signatures, "duplicated_signatures" = duplicated_parents)) 70 | } 71 | 72 | #' Decompress Solution Network 73 | #' 74 | #' This function decompresses a solution network by mapping node signatures back to their original identifiers. 75 | #' The input is a formatted solution network, a meta network, node signatures, and duplicated parents. 76 | #' The function returns a list containing the decompressed solution network and attribute table. 77 | #' 78 | #' @param formatted_res A list containing the solution network and attribute table. 79 | #' @param meta_network A data frame representing the meta network. 80 | #' @param node_signatures A list of node signatures. 81 | #' @param duplicated_parents A list of duplicated parents from the compression process. 82 | #' 83 | #' @return A list containing the following elements: 84 | #' \item{SIF}{A data frame representing the decompressed solution network.} 85 | #' \item{ATT}{A data frame containing the attributes of the decompressed solution network.} 86 | #' 87 | #' @examples 88 | #' # Create a sample formatted_res 89 | #' formatted_res <- list( 90 | #' SIF = data.frame(source = c("parent_of_D1", "D"), 91 | #' target = c("D", "F"), 92 | #' interaction = c(1, 1), 93 | #' Weight = c(1, 1)), 94 | #' ATT = data.frame(Nodes = c("parent_of_D1", "D", "F"), 95 | #' NodeType = c("","",""), 96 | #' ZeroAct = c(0,0,0), 97 | #' UpAct = c(1,1,1), 98 | #' DownAct = c(0,0,0), 99 | #' AvgAct = c(1,1,1), 100 | #' measured = c(0,0,0), 101 | #' Activity = c(1,1,1)) 102 | #' ) 103 | #' 104 | #' # Create a sample meta_network 105 | #' meta_network <- data.frame(source = c("A", "B", "D"), 106 | #' target = c("D", "D", "F"), 107 | #' interaction_type = c(1, 1, 1)) 108 | #' 109 | #' # Define node_signatures and duplicated_parents 110 | #' node_signatures <- list("A" = "parent_of_D1","B" = "parent_of_D1","D" = "parent_F1") 111 | #' duplicated_parents <- c("A" = "parent_of_D1","B" = "parent_of_D1") 112 | #' 113 | #' # Decompress the solution network 114 | #' result <- decompress_solution_network(formatted_res, meta_network, node_signatures, duplicated_parents) 115 | #' decompressed_network <- result[[1]] 116 | #' attribute_table <- result[[2]] 117 | #' 118 | #' @export 119 | decompress_solution_network <- function(formatted_res, meta_network, node_signatures, duplicated_parents) 120 | { 121 | SIF <- formatted_res[[1]] 122 | ATT <- formatted_res[[2]] 123 | 124 | duplicated_parents_df <- data.frame(duplicated_parents) 125 | duplicated_parents_df$source_original <- row.names(duplicated_parents_df) 126 | names(duplicated_parents_df)[1] <- "Nodes" 127 | 128 | 129 | addons <- data.frame(names(node_signatures)[-which(names(node_signatures) %in% duplicated_parents_df$source_original)]) 130 | names(addons)[1] <- "Nodes" 131 | addons$source_original <- addons$Nodes 132 | 133 | mapping_table <- as.data.frame(rbind(duplicated_parents_df,addons)) 134 | 135 | data("HMDB_mapper_vec") 136 | 137 | mapping_table[, 1] <- sapply(mapping_table[, 1], function(x, HMDB_mapper_vec) { 138 | x <- gsub("Metab__", "", x) 139 | x <- gsub("^Gene", "Enzyme", x) 140 | suffixe <- stringr::str_extract(x, "_[a-z]$") 141 | x <- gsub("_[a-z]$", "", x) 142 | if (x %in% names(HMDB_mapper_vec)) { 143 | x <- HMDB_mapper_vec[x] 144 | x <- paste("Metab__", x, sep = "") 145 | } 146 | if (!is.na(suffixe)) { 147 | x <- paste(x, suffixe, sep = "") 148 | } 149 | return(x) 150 | }, HMDB_mapper_vec = HMDB_mapper_vec) 151 | 152 | mapping_table[, 2] <- sapply(mapping_table[, 2], function(x, HMDB_mapper_vec) { 153 | x <- gsub("Metab__", "", x) 154 | x <- gsub("^Gene", "Enzyme", x) 155 | suffixe <- stringr::str_extract(x, "_[a-z]$") 156 | x <- gsub("_[a-z]$", "", x) 157 | if (x %in% names(HMDB_mapper_vec)) { 158 | x <- HMDB_mapper_vec[x] 159 | x <- paste("Metab__", x, sep = "") 160 | } 161 | if (!is.na(suffixe)) { 162 | x <- paste(x, suffixe, sep = "") 163 | } 164 | return(x) 165 | }, HMDB_mapper_vec = HMDB_mapper_vec) 166 | 167 | # View(ATT[!(ATT$Nodes %in% mapping_table$Nodes),]) 168 | 169 | 170 | 171 | ATT <- merge(ATT, mapping_table, by = "Nodes") 172 | ATT <- ATT[,c(9,2:8)] 173 | names(ATT)[1] <- "Nodes" 174 | 175 | SIF <- meta_network 176 | 177 | SIF[, 1] <- sapply(SIF[, 1], function(x, HMDB_mapper_vec) { 178 | x <- gsub("Metab__", "", x) 179 | x <- gsub("^Gene", "Enzyme", x) 180 | suffixe <- stringr::str_extract(x, "_[a-z]$") 181 | x <- gsub("_[a-z]$", "", x) 182 | if (x %in% names(HMDB_mapper_vec)) { 183 | x <- HMDB_mapper_vec[x] 184 | x <- paste("Metab__", x, sep = "") 185 | } 186 | if (!is.na(suffixe)) { 187 | x <- paste(x, suffixe, sep = "") 188 | } 189 | return(x) 190 | }, HMDB_mapper_vec = HMDB_mapper_vec) 191 | 192 | SIF[, 2] <- sapply(SIF[, 2], function(x, HMDB_mapper_vec) { 193 | x <- gsub("Metab__", "", x) 194 | x <- gsub("^Gene", "Enzyme", x) 195 | suffixe <- stringr::str_extract(x, "_[a-z]$") 196 | x <- gsub("_[a-z]$", "", x) 197 | if (x %in% names(HMDB_mapper_vec)) { 198 | x <- HMDB_mapper_vec[x] 199 | x <- paste("Metab__", x, sep = "") 200 | } 201 | if (!is.na(suffixe)) { 202 | x <- paste(x, suffixe, sep = "") 203 | } 204 | return(x) 205 | }, HMDB_mapper_vec = HMDB_mapper_vec) 206 | 207 | SIF <- SIF[SIF$source %in% ATT$Nodes & 208 | SIF$target %in% ATT$Nodes,] 209 | 210 | SIF$Weight <- apply(SIF, 1, function(x, ATT){ 211 | source_act <- ATT[ATT$Nodes == x[1],"Activity"] 212 | target_act <- ATT[ATT$Nodes == x[2],"Activity"] 213 | coherence <- source_act * target_act 214 | weight <- ifelse(sign(coherence) == sign(as.numeric(x[3])), min(abs(c(source_act, target_act))), 0) 215 | return(weight) 216 | }, ATT = ATT) 217 | 218 | SIF <- SIF[which(SIF$Weight != 0),] 219 | ATT <- ATT[ATT$AvgAct != 0,] 220 | 221 | seeds <- SIF[!(SIF[,1] %in% SIF[,2]),1] 222 | bad_seeds <- seeds[!(seeds %in% ATT[ATT$NodeType == "P","Nodes"])] 223 | 224 | if(length(bad_seeds) > 0) 225 | { 226 | ATT <- ATT[!(ATT$Nodes %in% bad_seeds),] 227 | SIF <- SIF[SIF$source %in% ATT$Nodes & 228 | SIF$target %in% ATT$Nodes,] 229 | } 230 | 231 | formatted_res <- list(SIF,ATT) 232 | 233 | return(formatted_res) 234 | } -------------------------------------------------------------------------------- /R/cosmos_data.R: -------------------------------------------------------------------------------- 1 | 2 | # Constructor ------------------------------------------------------------------ 3 | # for internal use 4 | #' Create New Cosmos Data 5 | #' 6 | #' Constructor. Should not be exported. The object is not validated. 7 | #' @param meta_network Prior knowledge network (PKN). By default COSMOS use a 8 | #' PKN derived from Omnipath, STITCHdb and Recon3D. See details on the data 9 | #' \code{\link{meta_network}}. 10 | #' @param tf_regulon Collection of transcription factor - target interactions. 11 | #' A default collection from dorothea can be obtained by the 12 | #' \code{\link{load_tf_regulon_dorothea}} function. 13 | #' @param signaling_data Numerical vector, where names are signaling nodes 14 | #' in the PKN and values are from \{1, 0, -1\}. Continuous data will be 15 | #' discretized using the \code{\link{sign}} function. 16 | #' @param metabolic_data Numerical vector, where names are metabolic nodes 17 | #' in the PKN and values are continuous values that represents log2 fold change 18 | #' or t-values from a differential analysis. These values are compared to 19 | #' the simulation results (simulated nodes can take value -1, 0 or 1). 20 | #' @param expression_data Numerical vector that represents the results of a 21 | #' differential gene expression analysis. Names are gene names using EntrezID 22 | #' starting with an X and values are log fold change or t-values. Genes with 23 | #' NA values are considered none expressed and they will be removed from the 24 | #' TF-gene expression interactions. 25 | #' @noRd 26 | new_cosmos_data <- function(meta_network = data.frame(), 27 | tf_regulon = data.frame(), 28 | signaling_data = double(), 29 | metabolic_data = double(), 30 | expression_data = double()){ 31 | 32 | stopifnot(is.data.frame(meta_network)) 33 | stopifnot(is.data.frame(tf_regulon)) 34 | stopifnot(is.double(signaling_data)) 35 | stopifnot(is.double(metabolic_data)) 36 | stopifnot(is.double(expression_data) | is.null(expression_data)) 37 | 38 | 39 | structure(list( 40 | meta_network = meta_network, 41 | tf_regulon = tf_regulon, 42 | signaling_data = signaling_data, 43 | metabolic_data = metabolic_data, 44 | expression_data = expression_data, 45 | history = c() 46 | ), class = "cosmos_data") 47 | 48 | } 49 | 50 | # validator ------------------------------------------------------------------- 51 | #' Validate cosmos data 52 | #' 53 | #' Checks the cosmos object. 54 | #' 55 | #' @param x \code{\link{cosmos_data}} object. Use the 56 | #' \code{\link{preprocess_COSMOS_metabolism_to_signaling}} function to create 57 | #' one. 58 | #' @noRd 59 | validate_cosmos_data <- function(x){ 60 | 61 | if(!all(c("meta_network", "tf_regulon", "signaling_data", "metabolic_data") %in% names(x))){ 62 | stop( 63 | "All fields should present in the cosmos object: meta_network, tf_regulon, signaling_data, metabolic_data", 64 | call. = FALSE 65 | ) 66 | } 67 | 68 | meta_network = x$meta_network 69 | tf_regulon = x$tf_regulon 70 | signaling_data = x$signaling_data 71 | metabolic_data = x$metabolic_data 72 | expression_data = x$expression_data 73 | 74 | 75 | check_COSMOS_inputs(meta_network = meta_network, 76 | tf_regulon = tf_regulon, 77 | expression_data = expression_data, 78 | signaling_data = signaling_data, 79 | metabolic_data = metabolic_data) 80 | 81 | check_gene_names(signaling_data) 82 | 83 | # Check overlap among node names in the inputs 84 | check_network_data_coverage(meta_network = meta_network, 85 | signaling_data = signaling_data, 86 | metabolic_data = metabolic_data, 87 | verbose = FALSE) 88 | 89 | 90 | } 91 | 92 | 93 | 94 | 95 | 96 | # helper ----------------------------------------------------------------------- 97 | #' Create Cosmos Data 98 | #' 99 | #' An S3 class that combines the required data into a comprehensive list. Use 100 | #' the \code{\link{preprocess_COSMOS_signaling_to_metabolism}} or 101 | #' \code{\link{preprocess_COSMOS_metabolism_to_signaling}} to create an instance. 102 | #' 103 | #' @param meta_network Prior knowledge network (PKN). By default COSMOS use a 104 | #' PKN derived from Omnipath, STITCHdb and Recon3D. See details on the data 105 | #' \code{\link{meta_network}}. 106 | #' @param tf_regulon Collection of transcription factor - target interactions. 107 | #' A default collection from dorothea can be obtained by the 108 | #' \code{\link{load_tf_regulon_dorothea}} function. 109 | #' @param signaling_data Numerical vector, where names are signaling nodes 110 | #' in the PKN and values are from \{1, 0, -1\}. Continuous data will be 111 | #' discretized using the \code{\link{sign}} function. 112 | #' @param metabolic_data Numerical vector, where names are metabolic nodes 113 | #' in the PKN and values are continuous values that represents log2 fold change 114 | #' or t-values from a differential analysis. These values are compared to 115 | #' the simulation results (simulated nodes can take value -1, 0 or 1). 116 | #' @param expression_data Numerical vector that represents the results of a 117 | #' differential gene expression analysis. Names are gene names using EntrezID 118 | #' starting with an X and values are log fold change or t-values. Genes with 119 | #' NA values are considered none expressed and they will be removed from the 120 | #' TF-gene expression interactions. 121 | #' @param verbose (default: TRUE) Reports details about the 122 | #' \code{\link{cosmos_data}} object. 123 | #' @return \code{cosmos data} class instance. 124 | #' 125 | 126 | cosmos_data <- function(meta_network, 127 | tf_regulon = NULL, 128 | signaling_data, 129 | metabolic_data, 130 | expression_data, 131 | verbose = TRUE){ 132 | 133 | check_gene_names(signaling_data) 134 | 135 | # signaling should be in PKN 136 | signaling_nodes = names(signaling_data) 137 | missing_nodes <- signaling_nodes[!signaling_nodes %in% c(meta_network$source, 138 | meta_network$target)] 139 | if(length(missing_nodes)>0){ 140 | message_missing_nodes <- paste("The following signaling nodes are not found in the PKN and will be removed from input:", 141 | limit_string_vec(missing_nodes)) 142 | message("COSMOS: ", message_missing_nodes) 143 | signaling_data <- signaling_data[signaling_nodes != missing_nodes] 144 | 145 | 146 | }else{ 147 | if(verbose) print(paste("COSMOS: all", length(signaling_nodes), 148 | "signaling nodes from data were found in the meta PKN")) 149 | } 150 | 151 | # metabolic nodes should be in PKN 152 | metabolic_nodes = names(metabolic_data) 153 | missing_nodes <- metabolic_nodes[!metabolic_nodes %in% c(meta_network$source, 154 | meta_network$target)] 155 | if(length(missing_nodes)>0){ 156 | 157 | message_missing_nodes <- paste("The following metabolic nodes are not found in the PKN and will be removed from input:", 158 | limit_string_vec(missing_nodes)) 159 | message("COSMOS: ", message_missing_nodes) 160 | # remove metabolic inputs not matching into the meta_network 161 | metabolic_data <- metabolic_data[metabolic_nodes != missing_nodes] 162 | 163 | }else{ 164 | if(verbose) print(paste("COSMOS: all",length(metabolic_nodes) , 165 | "metabolic nodes from data were found in the meta PKN")) 166 | } 167 | 168 | # the expression data should overlap with the TF targets 169 | if(!is.null(tf_regulon) & !is.null(expression_data)){ 170 | genes = names(expression_data) 171 | genes_as_tf_target <- sum(genes %in% tf_regulon$target) 172 | 173 | if(verbose) print(paste0("COSMOS: ", genes_as_tf_target, 174 | " of the ",length(genes), 175 | " genes in expression data were found as transcription factor target")) 176 | if(verbose) print(paste0("COSMOS: ", sum( unique(tf_regulon$target) %in% genes), 177 | " of the ",length(unique(tf_regulon$target)), 178 | " transcription factor targets were found in expression data")) 179 | if(genes_as_tf_target==0){ 180 | stop("Expression data contains no gene that appear as transcription factor target. 181 | The expression_data must be a named vector using EntrezIDs.") 182 | } 183 | } 184 | 185 | new_cosmos_data(meta_network = meta_network, 186 | tf_regulon = tf_regulon, 187 | signaling_data = signaling_data, 188 | metabolic_data = metabolic_data, 189 | expression_data = expression_data) 190 | 191 | 192 | 193 | } 194 | 195 | 196 | ### Generic functions ------------------------------------------------------------------ 197 | #' Print Cosmos Data Summary 198 | 199 | #' Print a summary of cosmos data. 200 | 201 | #' @param x \code{\link{cosmos_data}} object. Use the 202 | #' \code{\link{preprocess_COSMOS_signaling_to_metabolism}} or 203 | #' \code{\link{preprocess_COSMOS_metabolism_to_signaling}} functions to 204 | #' create one. 205 | #' @param ... Further print arguments passed to or from other methods. 206 | #' 207 | #' @seealso \code{\link[base]{print}}, \code{\link{cosmos_data}} 208 | #' 209 | #' 210 | #' @return input (invisible) 211 | #' @export 212 | print.cosmos_data <- function(x, ...) { 213 | cat("cosmos_data contains the following data: \n") 214 | cat("Meta network: ", nrow(x$meta_network), "interactions and", length(unique(c(x$meta_network$source,x$meta_network$target))), "unique nodes\n") 215 | cat("TF regulon: ", nrow(x$tf_regulon), "interactions,", length(unique(c(x$tf_regulon$tf))),"TFs and", length(unique(c(x$tf_regulon$target))), "targets\n") 216 | cat("Signaling data: ", length(x$signaling_data), "measured nodes\n") 217 | cat("Metabolic data: ", length(x$metabolic_data), "measured nodes\n") 218 | cat("Expression data:", length(x$expression_data), "measured nodes\n") 219 | if(!is.null(x$history)) print(x$history) 220 | 221 | invisible(x) 222 | } 223 | -------------------------------------------------------------------------------- /R/default_CARNIVAL_options.R: -------------------------------------------------------------------------------- 1 | #' Setting Default CARNIVAL Options 2 | #' 3 | #' Returns the default CARNIVAL options as a list. You can modify the elements 4 | #' of the list and then use it as an argument in \code{\link{run_COSMOS_metabolism_to_signaling}} or 5 | #' \code{\link{run_COSMOS_signaling_to_metabolism}}. 6 | #' If you choose CPLEX or CBC, you must modify then the solverPath field and point to 7 | #' the CPLEX/CBC executable (See Details). 8 | #' 9 | #' @details COSMOS is dependent on CARNIVAL for exhibiting the signalling pathway optimisation. 10 | #' CARNIVAL requires the interactive version of IBM Cplex, Gurobi or CBC-COIN solver 11 | #' as the network optimiser. The IBM ILOG Cplex is freely available through 12 | #' Academic Initiative \href{https://www.ibm.com/products/ilog-cplex-optimization-studio}{here}. 13 | #' Gurobi license is also free for academics, request a license following instructions 14 | #' \href{https://www.gurobi.com/downloads/end-user-license-agreement-academic/}{here}. 15 | #' The \href{https://projects.coin-or.org/Cbc}{CBC} solver is open source and freely 16 | #' available for any user, but has a significantly lower performance than CPLEX or 17 | #' Gurobi. Obtain CBC executable directly usable for cosmos 18 | #'\href{https://ampl.com/products/solvers/open-source/#cbc}{here}. Alternatively for 19 | #' small networks, users can rely on the freely available 20 | #' \href{https://cran.r-project.org/web/packages/lpSolve/index.html}{lpSolve R-package}, 21 | #' which is automatically installed with the package. 22 | #' 23 | #' @param solver one of `cplex` (recommended, but require 3rd party tool), `cbc` (also require 3rd party tool) or `lpSolve` (only for small networks) 24 | #' @return returns a list with all possible options implemented in CARNIVAL. 25 | #' see the documentation on \code{\link[CARNIVAL]{runCARNIVAL}}. 26 | #' @examples 27 | #' # load and change default options: 28 | #' my_options = default_CARNIVAL_options(solver = "cplex") 29 | #' 30 | #' my_options$solverPath = "/Applications/CPLEX_Studio128/cplex/bin/x86-64_osx/cplex" 31 | #' my_options$threads = 2 32 | #' my_options$timelimit = 3600*15 33 | #' @export 34 | #' 35 | default_CARNIVAL_options = function(solver = NULL){ 36 | 37 | if(is.null(solver)){ 38 | stop("please call default_CARNIVAL_options(solver = 'cplex') with a 39 | specific solver argument. Valid solvers are: 'lpSolve','cplex' or 'cbc'.") 40 | } 41 | solver_options = c("lpSolve","cplex","cbc") 42 | solver <- match.arg(solver,choices = solver_options) 43 | 44 | if(solver == "lpSolve"){ 45 | opts = CARNIVAL::defaultLpSolveCarnivalOptions() 46 | }else if(solver == "cplex"){ 47 | opts = CARNIVAL::defaultCplexCarnivalOptions() 48 | }else if(solver == "cbc"){ 49 | opts = CARNIVAL::defaultCbcSolveCarnivalOptions() 50 | } 51 | opts$keepLPFiles = FALSE 52 | 53 | return(opts) 54 | } 55 | 56 | 57 | 58 | #' Check CARNIVAL Options 59 | #' 60 | #' Checks the list of input options for CARNIVAL for completeness. 61 | #' 62 | #' @param opts An object of type \dQuote{\code{list}} defining the run parameters 63 | #' for CARNIVAL. Use the \code{\link{default_CARNIVAL_options}} function to 64 | #' create a list with default parameter settings. If cplex or cbc are chosen 65 | #' as the solver, the parameter solverPath needs to be supplied (not 66 | #' automatically added by \code{default_CARNIVAL_options()}). 67 | #' 68 | #' @seealso \code{\link{default_CARNIVAL_options}}, 69 | #' \code{\link[CARNIVAL]{runCARNIVAL}} 70 | #' @noRd 71 | check_CARNIVAL_options <- function(opts){ 72 | 73 | 74 | if(!is.list(opts)) stop("CARNIVAL options should be a list") 75 | req_names <- c("solver") 76 | 77 | 78 | if(!all(req_names %in% names(opts))){ 79 | stop("CARNIVAL options should contain all options. 80 | Start by calling CARNIVAL::defaultCbcCarnivalOptions() for CPLEX or 81 | CARNIVAL::defaultCplexCarnivalOptions() for CBC solver, or 82 | CARNIVAL::defaultLpSolveCarnivalOptions() for LpSolve and replace entries. ") 83 | } 84 | 85 | 86 | if(!(opts$solver %in% c("cplex","cbc","lpSolve"))) stop("current version supports only the CPLEX or cbc solver. lpSolve is also available for test runs.") 87 | if(opts$solver == "cbc") print("We recommend the users to use CPLEX if possible.") 88 | if(opts$solver == "lpSolve") print("lpSolve does not scale well with large PKNs. This solver is mainly for testing purposes. To run COSMSO, we recommend using cplex, or cbc solvers.") 89 | if(is.null(opts$solverPath) & opts$solver != "lpSolve") stop("path to CPLEX or cbc solver must be provided") 90 | 91 | return('List of CARNIVAL options is complete.') 92 | 93 | 94 | } 95 | -------------------------------------------------------------------------------- /R/discretize_vector.R: -------------------------------------------------------------------------------- 1 | #' discretize input vector 2 | #' 3 | #' convert a vector of continuous values to discrete {-1, 0, 1} 4 | #' 5 | #' @param input_vec numerical value 6 | #' @noRd 7 | 8 | 9 | discretize_input <- function(input_vec){ 10 | 11 | 12 | if(!all(input_vec %in% c(-1,0,1))){ 13 | message("Input nodes should have values from {-1, 0, 1}. We discretize your input with sign().") 14 | res = sign(input_vec) 15 | }else{ 16 | res = input_vec 17 | } 18 | 19 | return(res) 20 | } -------------------------------------------------------------------------------- /R/display_node_neighboorhood.R: -------------------------------------------------------------------------------- 1 | #' display_node_neighboorhood 2 | #' 3 | #' display input and measurements within n steps of a given set of nodes 4 | #' @param central_node character or character vector; node ID(s) around which a 5 | #' network will be branched out untill meansurments and input are reached 6 | #' @param sif df; COSMOS network solution in sif format like the first list 7 | #' element returned by the format_cosmos_res function 8 | #' @param att df; attributes of the nodes of the COMSOS network solution like 9 | #' the second list element returned by the format_cosmos_res function 10 | #' @param n numeric; maximum number of steps in the network to look for inputs 11 | #' and measurments 12 | #' @return a visnetwork object 13 | #' @importFrom dplyr %>% 14 | #' @examples 15 | #' CARNIVAL_options <- cosmosR::default_CARNIVAL_options("lpSolve") 16 | #' data(toy_network) 17 | #' data(toy_signaling_input) 18 | #' data(toy_metabolic_input) 19 | #' data(toy_RNA) 20 | #' test_for <- preprocess_COSMOS_signaling_to_metabolism(meta_network = toy_network, 21 | #' signaling_data = toy_signaling_input, 22 | #' metabolic_data = toy_metabolic_input, 23 | #' diff_expression_data = toy_RNA, 24 | #' maximum_network_depth = 15, 25 | #' remove_unexpressed_nodes = TRUE, 26 | #' CARNIVAL_options = CARNIVAL_options 27 | #' ) 28 | #' test_result_for <- run_COSMOS_signaling_to_metabolism(data = test_for, 29 | #' CARNIVAL_options = CARNIVAL_options) 30 | #' test_result_for <- format_COSMOS_res(test_result_for) 31 | #' network_plot <- display_node_neighboorhood(central_node = 'MYC', 32 | #' sif = test_result_for[[1]], 33 | #' att = test_result_for[[2]], 34 | #' n = 7) 35 | #' network_plot 36 | #' @export 37 | display_node_neighboorhood <- function(central_node,sif, att, n = 100) 38 | { 39 | # require(igraph) 40 | full_sif <- sif 41 | if(sum(names(full_sif) %in% c("Node1", "Node2", "Sign", "Weight")) != 4) 42 | { 43 | print('sif should be a dataframe with 4 column named "Node1", "Node2", "Sign" and "Weight"') 44 | return('Error:bad sif') 45 | } 46 | full_sif <- full_sif[,c("Node1", "Node2", "Sign", "Weight")] 47 | full_att <- att 48 | 49 | ig_net <- igraph::graph_from_data_frame(full_sif) 50 | 51 | ig_net <- igraph::make_ego_graph(ig_net, nodes = central_node, order = n, mode = "all") 52 | 53 | to_keep <- unlist(sapply(ig_net,function(x){igraph::V(x)$name})) 54 | 55 | full_sif <- full_sif[full_sif$Node1 %in% to_keep & full_sif$Node2 %in% to_keep,] 56 | full_att <- full_att[full_att$Nodes %in% to_keep,] 57 | 58 | ig_net <- igraph::graph_from_data_frame(full_sif) 59 | 60 | center_node <- sapply(central_node, function(x, ig_net, full_att) { 61 | names(unlist(igraph::get.shortest.paths(ig_net, from = x, to = full_att[full_att$measured == 1,1])$vpath)) 62 | }, ig_net= ig_net, full_att = full_att, simplify = FALSE, USE.NAMES = TRUE) 63 | 64 | center_node <- unlist(center_node) 65 | 66 | center_node_out <- full_sif[full_sif$Node1 %in% center_node & full_sif$Node2 %in% center_node,] 67 | 68 | center_node <- sapply(central_node, function(x, ig_net, full_att) { 69 | names(unlist(igraph::get.shortest.paths(ig_net, from = x, to = full_att[full_att$measured == 1,1], mode = "in")$vpath)) 70 | }, ig_net= ig_net, full_att = full_att, simplify = FALSE, USE.NAMES = TRUE) 71 | 72 | center_node <- unlist(center_node) 73 | 74 | center_node_in <- full_sif[full_sif$Node1 %in% center_node & full_sif$Node2 %in% center_node,] 75 | 76 | center_node_net <- as.data.frame(rbind(center_node_in,center_node_out)) 77 | 78 | nodes <- full_att[full_att$Nodes %in% center_node_net$Node1 | full_att$Nodes %in% center_node_net$Node2,] 79 | edges <- center_node_net 80 | 81 | names(edges) <- c("from","to","sign","weigth") 82 | edges$color <- ifelse(edges$sign == 1, "grey","grey") 83 | 84 | # edges$arrows <- "to" 85 | 86 | edges$arrows.to.type <- ifelse(edges$sign == 1, "arrow","circle") 87 | edges$enabled <- TRUE 88 | edges$scaleFactor <- 1 89 | 90 | edges <- unique(edges) 91 | 92 | names(nodes)[1] <- "id" 93 | nodes$label <- nodes$id 94 | nodes$color <- ifelse(nodes$Activity > 0, "green","red") 95 | nodes <- nodes[!duplicated(nodes$id),] 96 | nodes$shape <- "dot" 97 | nodes[nodes$type == "metab_enzyme","shape"] <- "square" 98 | nodes[nodes$type == "protein","shape"] <- "square" 99 | nodes[nodes$type == "Kinase","shape"] <- "triangle" 100 | nodes[nodes$type == "TF","shape"] <- "diamond" 101 | nodes <- nodes[order(nodes$id),] 102 | nodes$shadow <- (nodes$measured == 1) 103 | 104 | return(visNetwork::visNetwork(nodes, edges, width = 1600, height = 1600) %>% 105 | visNetwork::visOptions(highlightNearest = TRUE, 106 | nodesIdSelection = list(enabled = TRUE, 107 | style = 'width: 200px; height: 26px; 108 | background: #f8f8f8; 109 | color: darkblue; 110 | border:none; 111 | outline:none;'))) 112 | 113 | } -------------------------------------------------------------------------------- /R/filter_input_nodes_not_in_pkn.R: -------------------------------------------------------------------------------- 1 | 2 | filter_input_nodes_not_in_pkn <- function(data,pkn){ 3 | 4 | new_data = data[names(data) %in% c(pkn$source,pkn$target)] 5 | 6 | if(length(data) != length(new_data)){ 7 | removed_nodes <- names(data)[!names(data) %in% names(new_data)] 8 | 9 | print(paste("COSMOS:",length(removed_nodes), 10 | "input/measured nodes are not in PKN any more:", 11 | limit_string_vec(removed_nodes))) 12 | } 13 | return(new_data) 14 | } 15 | -------------------------------------------------------------------------------- /R/filter_pkn_expressed_genes.R: -------------------------------------------------------------------------------- 1 | #' filter_pkn_expressed_genes 2 | #' 3 | #' filters the non-expressed genes from the prior knowledge network 4 | #' 5 | #' @param expressed_genes_entrez Gene_symboles of expressed genes (mut be same ID as used in meta_PKN) 6 | #' @param meta_pkn COSMOS prior knowledge network 7 | #' @noRd 8 | filter_pkn_expressed_genes <- function(expressed_genes_entrez,meta_pkn){ 9 | 10 | print(paste("COSMOS: removing unexpressed nodes from PKN...")) 11 | 12 | is_expressed <- function(x) 13 | { 14 | if(!grepl("Metab",x) & !grepl("orphanReac",x)) 15 | { 16 | if(x %in% expressed_genes_entrez) 17 | { 18 | return(x) 19 | } else 20 | { 21 | if(grepl("Gene[0-9]+__[A-Z0-9_]+$",x)) 22 | { 23 | genes <- gsub("Gene[0-9]+__","",x) 24 | genes <- strsplit(genes,"_")[[1]] 25 | if(sum(genes %in% expressed_genes_entrez) != length(genes)) 26 | { 27 | return(NA) 28 | } else 29 | { 30 | return(x) 31 | } 32 | } else 33 | { 34 | if(grepl("Gene[0-9]+__[^_][a-z]",x)) 35 | { 36 | print(x) 37 | return(x) 38 | } else 39 | { 40 | if(grepl("Gene[0-9]+__[A-Z0-9_]+reverse",x)) 41 | { 42 | genes <- gsub("Gene[0-9]+__","",x) 43 | genes <- gsub("_reverse","",genes) 44 | genes <- strsplit(genes,"_")[[1]] 45 | if(sum(genes %in% expressed_genes_entrez) != length(genes)) 46 | { 47 | return(NA) 48 | } else 49 | { 50 | return(x) 51 | } 52 | } else 53 | { 54 | return(NA) 55 | } 56 | } 57 | } 58 | } 59 | } else 60 | { 61 | return(x) 62 | } 63 | } 64 | 65 | # is_expressed("XGene3004__124975_91227") 66 | 67 | meta_pkn$source <- sapply(meta_pkn$source,is_expressed) 68 | n_removed = sum(!stats::complete.cases(meta_pkn)) 69 | meta_pkn <- meta_pkn[stats::complete.cases(meta_pkn),] 70 | meta_pkn$target <- sapply(meta_pkn$target,is_expressed) 71 | meta_pkn <- meta_pkn[stats::complete.cases(meta_pkn),] 72 | n_removed = n_removed + sum(!stats::complete.cases(meta_pkn)) 73 | print(paste("COSMOS:", n_removed, "interactions removed")) 74 | return(meta_pkn) 75 | } 76 | 77 | #' filter_pkn_expressed_genes_fast 78 | #' 79 | #' filters the non-expressed genes from the prior knowledge network 80 | #' USING A FASTER OPTIMISED ALGORITHM 81 | #' 82 | #' @param expressed_genes_entrez Gene_symboles of expressed genes (mut be same ID as used in meta_PKN) 83 | #' @param meta_pkn COSMOS prior knowledge network 84 | #' @noRd 85 | filter_pkn_expressed_genes_fast <- function(expressed_genes_entrez, meta_pkn) { 86 | message("COSMOS: removing unexpressed nodes from PKN...") 87 | 88 | # Create an environment to act as a hash table for fast membership checks. 89 | expressed_env <- new.env(hash = TRUE, parent = emptyenv()) 90 | for (gene in expressed_genes_entrez) { 91 | expressed_env[[gene]] <- TRUE 92 | } 93 | 94 | vectorized_is_expressed <- function(x, env) { 95 | out <- rep(NA_character_, length(x)) 96 | 97 | # 1. Nodes that contain "Metab" or "orphanReac" are kept as is. 98 | keep_idx <- grepl("Metab|orphanReac", x, perl = TRUE) 99 | out[keep_idx] <- x[keep_idx] 100 | 101 | # 2. Direct membership check: if the node exists in the environment. 102 | not_checked <- which(is.na(out)) 103 | if (length(not_checked) > 0) { 104 | direct <- sapply(x[not_checked], function(s) exists(s, envir = env, inherits = FALSE)) 105 | out[not_checked[direct]] <- x[not_checked[direct]] 106 | } 107 | 108 | # 3. For nodes that follow the pattern "Gene...": 109 | not_checked <- which(is.na(out)) 110 | if (length(not_checked) > 0) { 111 | # Pattern for concatenated genes (e.g. "Gene1234__ID1_ID2") 112 | pattern_concat <- grepl("^Gene[0-9]+__[A-Z0-9_]+$", x[not_checked], perl = TRUE) 113 | if (any(pattern_concat)) { 114 | idx <- not_checked[pattern_concat] 115 | out[idx] <- sapply(x[idx], function(s) { 116 | genes_str <- sub("^Gene[0-9]+__", "", s) 117 | genes <- unlist(strsplit(genes_str, "_")) 118 | if (all(sapply(genes, exists, envir = env, inherits = FALSE))) s else NA_character_ 119 | }) 120 | } 121 | 122 | # Pattern for reverse-tagged genes (e.g. "Gene1234__ID1_ID2_reverse") 123 | not_checked <- which(is.na(out)) 124 | pattern_reverse <- grepl("^Gene[0-9]+__[A-Z0-9_]+_reverse$", x[not_checked], perl = TRUE) 125 | if (any(pattern_reverse)) { 126 | idx <- not_checked[pattern_reverse] 127 | out[idx] <- sapply(x[idx], function(s) { 128 | genes_str <- sub("^Gene[0-9]+__", "", s) 129 | genes_str <- sub("_reverse$", "", genes_str) 130 | genes <- unlist(strsplit(genes_str, "_")) 131 | if (all(sapply(genes, exists, envir = env, inherits = FALSE))) s else NA_character_ 132 | }) 133 | } 134 | 135 | # Special pattern with a lower-case letter in the tag: 136 | not_checked <- which(is.na(out)) 137 | pattern_lower <- grepl("^Gene[0-9]+__[^_][a-z]", x[not_checked], perl = TRUE) 138 | if (any(pattern_lower)) { 139 | idx <- not_checked[pattern_lower] 140 | # Optionally, print messages for these cases. 141 | for (s in x[idx]) message("Note: ", s) 142 | out[idx] <- x[idx] 143 | } 144 | } 145 | 146 | return(out) 147 | } 148 | 149 | meta_pkn$source <- vectorized_is_expressed(meta_pkn$source, expressed_env) 150 | meta_pkn$target <- vectorized_is_expressed(meta_pkn$target, expressed_env) 151 | 152 | initial_n <- nrow(meta_pkn) 153 | meta_pkn <- meta_pkn[stats::complete.cases(meta_pkn), ] 154 | removed <- initial_n - nrow(meta_pkn) 155 | message("COSMOS: ", removed, " interactions removed") 156 | 157 | return(meta_pkn) 158 | } 159 | 160 | -------------------------------------------------------------------------------- /R/filter_transcriptional_regulations.R: -------------------------------------------------------------------------------- 1 | #' Filter Based On Transcriptional Regulations 2 | #' 3 | #' Filters interactions between TFs and genes in the PKN by the following points: 4 | #' - finds the TF target genes that change strongly (threshold) 5 | #' - finds TFs from the inputs (known TF activity) 6 | #' - remove interactions if the target gene expression doesn't change (regulation 7 | #' should not go through this node ) 8 | #' - remove interactions if the TF activity is not in agreement with the change 9 | #' in the target gene expression (other factors influence these genes) 10 | #' 11 | #' @param network Prior knowledge network (PKN). By default COSMOS use a PKN 12 | #' derived from Omnipath, STITCHdb and Recon3D. See details on the data 13 | #' \code{\link{meta_network}}. 14 | #' @param gene_expression_binarized Named vector of {-1,0,1} difnining which 15 | #' genes changed. 16 | #' @param signaling_data Named vector containing known activity of signaling 17 | #' nodes (kinases, TFs). 18 | #' @param tf_regulon Collection of transcription factor - target interactions. 19 | #' A default collection from dorothea can be obtained by the 20 | #' \code{\link{load_tf_regulon_dorothea}} function. 21 | #' @return A filtered version of the network. 22 | #' @importFrom rlang .data 23 | #' @importFrom dplyr %>% 24 | #' @noRd 25 | filter_transcriptional_regulations <- function(network, 26 | gene_expression_binarized, 27 | signaling_data, 28 | tf_regulon) 29 | { 30 | check_COSMOS_inputs(meta_network = network, 31 | tf_regulon = tf_regulon, 32 | signaling_data = signaling_data, 33 | expression_data = gene_expression_binarized) 34 | 35 | # map the TF values and gene expression levels on the PKN 36 | 37 | gene_exp_df = data.frame(gene =names(gene_expression_binarized), 38 | target_sign = gene_expression_binarized) 39 | 40 | signaling_df = data.frame(TF =names(signaling_data), 41 | TF_sign = signaling_data) %>% 42 | dplyr::filter(.data$TF %in% tf_regulon$tf) 43 | 44 | annotated_network <- network %>% 45 | # add the gene expression data: (non-genes will be filled with NA) 46 | dplyr::left_join(gene_exp_df, by=c(target="gene")) %>% 47 | # add the TF data (non-TFs will be filled with NAs) 48 | dplyr::left_join( signaling_df, by=c(source="TF")) %>% 49 | dplyr::mutate(source_is_TF = .data$source %in% tf_regulon$tf) 50 | 51 | # find interactions where TF regulates a gene, but target 52 | # - does not change 53 | # - target gene is not measured 54 | # - target changes inconsistently 55 | annotated_network <- annotated_network %>% 56 | # genes didn't change 57 | dplyr::mutate(target_gene_unchanged = .data$target_sign==0) %>% 58 | # gene didnt change and the source is a TF (it is a transcriptional regulation) 59 | dplyr::mutate(TF_target_unchanged = .data$source_is_TF & 60 | (.data$target_gene_unchanged | is.na(.data$target_gene_unchanged))) %>% 61 | # gene changed, but not consistently with TF activity 62 | dplyr::mutate(inconsistent_TF_gene_sign = 63 | sign(.data$TF_sign) != interaction * sign(.data$target_sign) ) 64 | 65 | # TODO: option to return these interactions 66 | removed_interactions <- annotated_network %>% 67 | dplyr::filter(.data$TF_target_unchanged | .data$inconsistent_TF_gene_sign) 68 | 69 | print(paste("COSMOS: ", nrow(removed_interactions), 70 | "interactions are removed from the PKN based on", 71 | "consistency check between TF activity and gene expression")) 72 | 73 | 74 | kept_interactions <- annotated_network %>% 75 | dplyr::filter(!.data$TF_target_unchanged | is.na(.data$TF_target_unchanged)) %>% 76 | dplyr::filter(!.data$inconsistent_TF_gene_sign | is.na(.data$inconsistent_TF_gene_sign)) 77 | 78 | out_pkn <- kept_interactions %>% dplyr::select(.data$source,.data$interaction,.data$target) 79 | return(out_pkn) 80 | } 81 | 82 | 83 | -------------------------------------------------------------------------------- /R/format_COSMOS_results.R: -------------------------------------------------------------------------------- 1 | #' format_COSMOS_res 2 | #' 3 | #' formats the network with readable names 4 | #' 5 | #' @param cosmos_res results of COSMOS run 6 | #' @param metab_mapping a named vector with HMDB Ids as names and desired metabolite names as values. 7 | #' @return list with network and attribute tables. 8 | #' @importFrom stringr str_extract 9 | #' @export 10 | format_COSMOS_res <- function(cosmos_res, 11 | metab_mapping = NULL) 12 | { 13 | 14 | if(is.null(metab_mapping)) 15 | { 16 | data("HMDB_mapper_vec",package = "cosmosR",envir = environment()) 17 | } 18 | SIF <- as.data.frame(cosmos_res$weightedSIF) 19 | ATT <- as.data.frame(cosmos_res$nodesAttributes) 20 | colnames(ATT)[1] <- "Nodes" 21 | ATT$measured <- ifelse(ATT$NodeType %in% c("M","T","S","P"),1,0) 22 | ATT$Activity <- ATT$AvgAct 23 | 24 | for(i in c(1,3)) 25 | { 26 | SIF[,i] <- sapply(SIF[,i], function(x, HMDB_mapper_vec){ 27 | x <- gsub("Metab__","",x) 28 | x <- gsub("^Gene","Enzyme",x) 29 | suffixe <- stringr::str_extract(x,"_[a-z]$") 30 | x <- gsub("_[a-z]$","",x) 31 | if(x %in% names(HMDB_mapper_vec)) 32 | { 33 | x <- HMDB_mapper_vec[x] 34 | x <- paste("Metab__",paste(x,suffixe,sep = ""),sep = "") 35 | } 36 | return(x) 37 | },HMDB_mapper_vec = HMDB_mapper_vec) 38 | } 39 | 40 | ATT[,1] <- sapply(ATT[,1], function(x, HMDB_mapper_vec){ 41 | x <- gsub("Metab__","",x) 42 | x <- gsub("^Gene","Enzyme",x) 43 | suffixe <- stringr::str_extract(x,"_[a-z]$") 44 | x <- gsub("_[a-z]$","",x) 45 | if(x %in% names(HMDB_mapper_vec)) 46 | { 47 | x <- HMDB_mapper_vec[x] 48 | x <- paste("Metab__",x,sep = "") 49 | } 50 | if(!is.na(suffixe)) 51 | { 52 | x <- paste(x,suffixe,sep = "") 53 | } 54 | return(x) 55 | },HMDB_mapper_vec = HMDB_mapper_vec) 56 | 57 | return(list(SIF,ATT)) 58 | } -------------------------------------------------------------------------------- /R/get_TF_activity_from_CARNIVAL.R: -------------------------------------------------------------------------------- 1 | #' get_TF_activity_from_CARNIVAL 2 | #' 3 | #' screens the CARNIVAL results and obtains the activity of transcription factors 4 | #' 5 | #' @param carnival_result list obtained from runCARNIVAL 6 | #' @param TFs character vector of transcription factors using EntrezIDs 7 | #' @return named numerical vector with TF activity found in CARNIVAL results. 8 | #' @importFrom rlang .data 9 | #' @importFrom dplyr %>% filter select as_tibble 10 | #' @noRd 11 | get_TF_activity_from_CARNIVAL <- function(carnival_result, TFs) 12 | { 13 | 14 | if(!validate_CARNIVAL_results(carnival_result)) warning("we failed to validate CARNIVAL results.") 15 | 16 | estimated_activity <- dplyr::as_tibble(carnival_result$nodesAttributes) %>% 17 | dplyr::select(.data$Node,.data$AvgAct) %>% 18 | dplyr::filter(.data$AvgAct!=0) %>% 19 | dplyr::filter(.data$Node %in% TFs) 20 | 21 | activity = as.numeric(estimated_activity$AvgAct)/100 22 | names(activity) = estimated_activity$Node 23 | 24 | return(activity) 25 | } 26 | 27 | #' Validate CARNIVAL Results 28 | #' 29 | #' Implement here basic checks to see if we got back from CARNIVAL what we 30 | #' expected. Subject to change if CARNIVAL results changes. 31 | #' 32 | #' @param CR CARNIVAL result object 33 | #' @noRd 34 | validate_CARNIVAL_results <- function(CR){ 35 | 36 | list_names = c("weightedSIF","nodesAttributes","sifAll","attributesAll" ) %in% names(CR) 37 | if(!all(list_names)) return(FALSE) 38 | 39 | if(is.null(CR$weightedSIF)) return(FALSE) 40 | if(is.null(CR$nodesAttributes)) return(FALSE) 41 | if(is.null(CR$sifAll)) return(FALSE) 42 | if(is.null(CR$attributesAll)) return(FALSE) 43 | 44 | return(TRUE) 45 | } 46 | -------------------------------------------------------------------------------- /R/keep_downstream_neighbours.R: -------------------------------------------------------------------------------- 1 | #' keep controllable neighbors 2 | #' 3 | #' keeps the nodes in network that are no more then n_steps away from the starting nodes. 4 | #' @param network network in 3 column data.frame format 5 | #' (source, interaction, target) 6 | #' @param n_steps largest distance t consider 7 | #' @param input_nodes names of the input nodes in the network 8 | #' @noRd 9 | keep_controllable_neighbours <- function(network, n_steps, input_nodes) 10 | { 11 | stopifnot(all(c("source","target","interaction") %in% colnames(network))) 12 | stopifnot(all(input_nodes %in% c(network$source,network$target))) 13 | 14 | print(paste("COSMOS: removing nodes that are not reachable from inputs within",n_steps,"steps")) 15 | meta_g <- igraph::graph_from_data_frame(network[,c("source",'target',"interaction")],directed = TRUE) 16 | dn_nbours <- igraph::ego(graph = meta_g, order = n_steps,nodes = input_nodes, mode = "out") 17 | 18 | sub_nodes <- c(unique(names(unlist(dn_nbours))), input_nodes) 19 | 20 | to_keep = network$source %in% sub_nodes & network$target %in% sub_nodes 21 | 22 | print(paste("COSMOS:", sum(!to_keep), "from ", length(to_keep), 23 | "interactions are removed from the PKN")) 24 | 25 | network <- network[to_keep,] 26 | 27 | 28 | return(network) 29 | } 30 | 31 | #' keep observable neighbors 32 | #' 33 | #' keeps the nodes in network that are no more then n_steps upstreams from the 34 | #' measured nodes 35 | #' @param network network in 3 column data.frame format 36 | #' (source, interaction, target) 37 | #' @param n_steps largest distance t consider 38 | #' @param observed_nodes names of the measured nodes in the network 39 | #' @noRd 40 | keep_observable_neighbours <- function(network, n_steps, observed_nodes) 41 | { 42 | stopifnot(all(c("source","target","interaction") %in% colnames(network))) 43 | stopifnot(all(observed_nodes %in% c(network$source,network$target))) 44 | 45 | print(paste("COSMOS: removing nodes that are not observable by measurements within",n_steps,"steps")) 46 | meta_g <- igraph::graph_from_data_frame(network[,c("source",'target',"interaction")],directed = TRUE) 47 | up_nbours <- igraph::ego(graph = meta_g, order = n_steps, nodes = observed_nodes, mode = "in") 48 | 49 | sub_nodes <- c(unique(names(unlist(up_nbours))), observed_nodes) 50 | 51 | to_keep = network$source %in% sub_nodes & network$target %in% sub_nodes 52 | 53 | print(paste("COSMOS:", sum(!to_keep), "from ", length(to_keep), 54 | "interactions are removed from the PKN")) 55 | 56 | network <- network[to_keep,] 57 | 58 | 59 | return(network) 60 | } -------------------------------------------------------------------------------- /R/limit_string_vec.R: -------------------------------------------------------------------------------- 1 | #' Limit String Vec 2 | #' 3 | #' Writes the first 6 elements and the number of other elements in a string. 4 | #' 5 | #' @param str_vec A string vector to be transformed. 6 | #' 7 | #' @noRd 8 | limit_string_vec <- function(str_vec){ 9 | paste(paste(utils::head(str_vec),collapse = ", "), "and", 10 | length(str_vec) - length(utils::head(str_vec)), "more.") 11 | } 12 | -------------------------------------------------------------------------------- /R/load_tf_regulon_dorothea.R: -------------------------------------------------------------------------------- 1 | #' load transcription factor regulon 2 | #' 3 | #' load the transcription factors from \code{DOROTHEA} package and converts 4 | #' gene symbols to EntrezID using org.Hs.eg.db 5 | #' 6 | #' @param confidence strong vector (by default: c("A","B","C")). Subset of \{A, B, 7 | #' C, D, E\}. See the `dorothea` for the meaning of confidence levels. 8 | #' package for further details. 9 | #' @return returns a PKN of a form of a data table. Each row is an interaction. 10 | #' Columns names are: 11 | #' 12 | #' - `tf` transcription factor 13 | #' - `confidence` class of confidence 14 | #' - `target` target gene 15 | #' - `sign` indicates if interaction is up (1) or down-regulation (-1). 16 | #' 17 | #' @importFrom dplyr %>% 18 | #' @export 19 | #' @examples 20 | #' load_tf_regulon_dorothea() 21 | load_tf_regulon_dorothea <- function(confidence = c("A","B","C")){ 22 | . <- NULL 23 | 24 | # load regulon from dorothea: 25 | regulon = dorothea::dorothea_hs 26 | regulon <- regulon %>% dplyr::rename(sign = "mor") 27 | 28 | conf = confidence 29 | regulon <- regulon %>% dplyr::filter(.data$confidence %in% conf) 30 | regulon <- regulon[,-which(names(regulon) == "confidence")] 31 | 32 | return(regulon) 33 | } 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /R/meta_network.R: -------------------------------------------------------------------------------- 1 | #' Meta Prior Knowledge Network 2 | #' 3 | #' Comprehensive Prior Knowledge Network (PKN), which combines signaling and 4 | #' metabolic interaction networks. The network was constructed using the Recon3D 5 | #' and STITCH metabolic networks as well as the signaling network from 6 | #' OmniPath. 7 | #' 8 | #' @docType data 9 | #' 10 | #' @usage data(meta_network) 11 | #' 12 | #' @format An object of class \dQuote{\code{tibble}} with 117065 rows 13 | #' (interactions) and three variables: 14 | #' \describe{ 15 | #' \item{\code{source}}{Source node, either metabolite or protein} 16 | #' \item{\code{interaction}}{Type of interaction, 1 = Activation, -1 = Inhibition} 17 | #' \item{\code{target}}{Target node, either metabolite or protein} 18 | #' A detailed description of the identifier formatting can be found under 19 | #' \url{https://metapkn.omnipathdb.org/00__README.txt}. 20 | #' } 21 | #' 22 | #' @source The network is available in Omnipath: 23 | #' \url{https://metapkn.omnipathdb.org/metapkn__20200122.txt}, the scripts 24 | #' used for the build of the network are available under 25 | #' \url{https://github.com/saezlab/Meta_PKN}. 26 | #' 27 | #' @references { 28 | #' Dugourd, A., Kuppe, C. and Sciacovelli, M. et. al. (2021) \emph{Molecular 29 | #' Systems Biology}. \bold{17}, e9730. 30 | #' } 31 | #' 32 | #' @examples 33 | #' data(meta_network) 34 | #' 35 | #' @keywords datasets 36 | "meta_network" -------------------------------------------------------------------------------- /R/prepare_metab_inputs.R: -------------------------------------------------------------------------------- 1 | #' add metabolic compartment and metab__ prefix to metabolite IDs 2 | #' 3 | #' This function adds metabolic compartments to the metabolic identifiers provided by the user. 4 | #' 5 | #' @param metab_input a named vector with matebolic statistics as inputs and metabolite identifiers as names 6 | #' @param compartment_codes a character vector, the desired compartment codes to be added. Possible values are "r", "c", "e", "x", "m", "l", "n" and "g" 7 | #' @export 8 | #' @return a named vector with the compartment code and prefixed added to the names 9 | prepare_metab_inputs <- function(metab_input, compartment_codes) 10 | { 11 | comps <- c("r", "c", "e", "x", "m", "l", "n", "g") 12 | 13 | if(length(compartment_codes[which(!(compartment_codes %in% comps))]) > 0) 14 | { 15 | ignored <- compartment_codes[which(!(compartment_codes %in% comps))] 16 | print("The following compartment codes are not found in the PKN and will be ignored") 17 | print(ignored) 18 | } 19 | 20 | compartment_codes <- compartment_codes[which(compartment_codes %in% comps)] 21 | 22 | if(length(compartment_codes) == 0) 23 | { 24 | print("There are no valid compartment left. No compartiment codes will be added.") 25 | names(metab_input) <- paste("Metab__",names(metab_input),sep = "") 26 | return(metab_input) 27 | } else 28 | { 29 | print("Adding compartment codes.") 30 | metab_input_list <- lapply(compartment_codes, function(compartment_code, curr_metab_input){ 31 | names(curr_metab_input) <- paste(names(curr_metab_input),compartment_code, sep = "_") 32 | names(curr_metab_input) <- paste("Metab__",names(curr_metab_input),sep = "") 33 | return(curr_metab_input) 34 | }, curr_metab_input = metab_input) 35 | metab_input <- unlist(metab_input_list) 36 | return(metab_input) 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /R/preprocess_COSMOS_metabolism_to_signaling.R: -------------------------------------------------------------------------------- 1 | #' Preprocess COSMOS Inputs For Metabolism to Signaling 2 | #' 3 | #' Runs checks on the input data and simplifies the prior knowledge network. 4 | #' Simplification includes the removal of (1) nodes that are not reachable from 5 | #' signaling nodes and (2) interactions between transcription factors and target 6 | #' genes if the target gene does not respond or the response is contradictory 7 | #' with the change in the transcription factor activity. 8 | #' Optionally, further TF activities are estimated via network optimization via 9 | #' CARNIVAL and the interactions between TF and genes are filtered again. 10 | #' 11 | #' @param meta_network prior knowledge network (PKN). A PKN released with COSMOS 12 | #' and derived from Omnipath, STITCHdb and Recon3D can be used. See details on 13 | #' the data \code{\link{meta_network}}. 14 | #' @param tf_regulon collection of transcription factor - target interactions. 15 | #' A default collection from dorothea can be obtained by the 16 | #' \code{\link{load_tf_regulon_dorothea}} function. 17 | #' @param signaling_data numerical vector, where names are signaling nodes 18 | #' in the PKN and values are from \{1, 0, -1\}. Continuous data will be 19 | #' discretized using the \code{\link{sign}} function. 20 | #' @param metabolic_data numerical vector, where names are metabolic nodes 21 | #' in the PKN and values are continuous values that represents log2 fold change 22 | #' or t-values from a differential analysis. These values are compared to 23 | #' the simulation results (simulated nodes can take value -1, 0 or 1) 24 | #' @param diff_expression_data (optional) numerical vector that represents the 25 | #' results of a differential gene expression analysis. Names are gene 26 | #' names using gene symbole and values are log fold change or 27 | #' t-values. We use the \dQuote{\code{diff_exp_threshold}} parameter to decide 28 | #' which genes changed significantly. Genes with NA values are considered none 29 | #' expressed and they will be removed from the TF-gene expression interactions. 30 | #' @param diff_exp_threshold threshold parameter (default 1) used to binarize 31 | #' the values of \dQuote{\code{diff_expression_data}}. 32 | #' @param maximum_network_depth integer > 0 (default: 8). Nodes that are further 33 | #' than \dQuote{\code{maximum_network_depth}} steps from the signaling nodes on 34 | #' the directed graph of the PKN are considered non-reachable and are removed. 35 | #' @param remove_unexpressed_nodes if TRUE (default) removes nodes from the PKN 36 | #' that are not expressed, see input \dQuote{\code{expressed_genes}}. 37 | #' @param expressed_genes character vector. Names of nodes that are expressed. By 38 | #' default we consider all the nodes that appear in \code{diff_expression_data} with 39 | #' a numeric value (i.e. nodes with NA are removed) 40 | #' @param filter_tf_gene_interaction_by_optimization (default:TRUE), if TRUE then runs 41 | #' a network optimization that estimates TF activity not included in the inputs 42 | #' and checks the consistency between the estimated activity and change in gene 43 | #' expression. Removes interactions where TF and gene expression are inconsistent 44 | #' @param CARNIVAL_options list that controls the options of CARNIVAL. See details 45 | #' in \code{\link{default_CARNIVAL_options}}. 46 | #' @importFrom utils data 47 | #' @export 48 | #' @return cosmos_data object with the following fields: 49 | #' \describe{ 50 | #' \item{\code{meta_network}}{Filtered PKN} 51 | #' \item{\code{tf_regulon}}{TF - target regulatory network} 52 | #' \item{\code{signaling_data_bin}}{Binarised signaling data} 53 | #' \item{\code{metabolic_data}}{Metabolomics data} 54 | #' \item{\code{diff_expression_data_bin}}{Binarized gene expression data} 55 | #' \item{\code{optimized_network}}{Initial optimized network if 56 | #' \code{filter_tf_gene_interaction_by_optimization is TRUE}} 57 | #' } 58 | #' @seealso \code{\link{meta_network}} for meta PKN, 59 | #' \code{\link{load_tf_regulon_dorothea}} for tf regulon, 60 | #' \code{\link[CARNIVAL]{runCARNIVAL}}. 61 | #' 62 | #' @examples 63 | #' data(toy_network) 64 | #' data(toy_signaling_input) 65 | #' data(toy_metabolic_input) 66 | #' data(toy_RNA) 67 | #' test_back <- preprocess_COSMOS_metabolism_to_signaling( 68 | #' meta_network = toy_network, 69 | #' signaling_data = toy_signaling_input, 70 | #' metabolic_data = toy_metabolic_input, 71 | #' diff_expression_data = toy_RNA, 72 | #' maximum_network_depth = 15, 73 | #' remove_unexpressed_nodes = TRUE, 74 | #' CARNIVAL_options = default_CARNIVAL_options("lpSolve") 75 | #' ) 76 | preprocess_COSMOS_metabolism_to_signaling <- function(meta_network = meta_network, 77 | tf_regulon = load_tf_regulon_dorothea(), 78 | signaling_data, 79 | metabolic_data, 80 | diff_expression_data = NULL, 81 | diff_exp_threshold = 1, 82 | maximum_network_depth = 8, 83 | expressed_genes = NULL, 84 | remove_unexpressed_nodes = TRUE, 85 | filter_tf_gene_interaction_by_optimization = TRUE, 86 | CARNIVAL_options = default_CARNIVAL_options("lpSolve")){ 87 | 88 | if(!is.null(diff_expression_data)) 89 | { 90 | expressed_genes <- names(diff_expression_data)[!is.na(diff_expression_data)] 91 | } else 92 | { 93 | expressed_genes <- NULL 94 | remove_unexpressed_nodes <- FALSE 95 | } 96 | out_data <- preprocess_COSMOS_core(meta_network = meta_network, 97 | tf_regulon = tf_regulon, 98 | signaling_data=signaling_data, 99 | metabolic_data=metabolic_data, 100 | input_layer = "metabolic_data", 101 | output_layer = "signaling_data", 102 | diff_expression_data=diff_expression_data, 103 | diff_exp_threshold = diff_exp_threshold, 104 | maximum_network_depth = maximum_network_depth, 105 | expressed_genes = expressed_genes, 106 | remove_unexpressed_nodes = remove_unexpressed_nodes, 107 | filter_tf_gene_interaction_by_optimization = filter_tf_gene_interaction_by_optimization, 108 | CARNIVAL_options = CARNIVAL_options) 109 | 110 | out_data$history = c(out_data$history,"created by preprocess_COSMOS_metabolism_to_signaling\n") 111 | 112 | return(out_data) 113 | } 114 | -------------------------------------------------------------------------------- /R/preprocess_COSMOS_signaling_to_metabolism.R: -------------------------------------------------------------------------------- 1 | #' Preprocess COSMOS Inputs For Signaling to Metabolism 2 | #' 3 | #' Runs checks on the input data and simplifies the prior knowledge network. 4 | #' Simplification includes the removal of (1) nodes that are not reachable from 5 | #' signaling nodes and (2) interactions between transcription factors and target 6 | #' genes if the target gene does not respond or the response is contradictory 7 | #' with the change in the transcription factor activity. 8 | #' Optionally, further TF activities are estimated via network optimization via 9 | #' CARNIVAL and the interactions between TF and genes are filtered again. 10 | #' 11 | #' @param meta_network prior knowledge network (PKN). A PKN released with COSMOS 12 | #' and derived from Omnipath, STITCHdb and Recon3D can be used. See details on 13 | #' the data \code{\link{meta_network}}. 14 | #' @param tf_regulon collection of transcription factor - target interactions. 15 | #' A default collection from dorothea can be obtained by the 16 | #' \code{\link{load_tf_regulon_dorothea}} function. 17 | #' @param signaling_data numerical vector, where names are signaling nodes 18 | #' in the PKN and values are from \{1, 0, -1\}. Continuous data will be 19 | #' discretized using the \code{\link{sign}} function. 20 | #' @param metabolic_data numerical vector, where names are metabolic nodes 21 | #' in the PKN and values are continuous values that represents log2 fold change 22 | #' or t-values from a differential analysis. These values are compared to 23 | #' the simulation results (simulated nodes can take value -1, 0 or 1) 24 | #' @param diff_expression_data (optional) numerical vector that represents the 25 | #' results of a differential gene expression analysis. Names are gene 26 | #' names using gene symbole and values are log fold change or 27 | #' t-values. We use the \dQuote{\code{diff_exp_threshold}} parameter to decide 28 | #' which genes changed significantly. Genes with NA values are considered none 29 | #' expressed and they will be removed from the TF-gene expression interactions. 30 | #' @param diff_exp_threshold threshold parameter (default 1) used to binarize 31 | #' the values of \dQuote{\code{diff_expression_data}}. 32 | #' @param maximum_network_depth integer > 0 (default: 8). Nodes that are further 33 | #' than \dQuote{\code{maximum_network_depth}} steps from the signaling nodes on 34 | #' the directed graph of the PKN are considered non-reachable and are removed. 35 | #' @param remove_unexpressed_nodes if TRUE (default) removes nodes from the PKN 36 | #' that are not expressed, see input \dQuote{\code{expressed_genes}}. 37 | #' @param expressed_genes character vector. Names of nodes that are expressed. By 38 | #' default we consider all the nodes that appear in \code{diff_expression_data} with 39 | #' a numeric value (i.e. nodes with NA are removed) 40 | #' @param filter_tf_gene_interaction_by_optimization (default:TRUE), if TRUE then runs 41 | #' a network optimization that estimates TF activity not included in the inputs 42 | #' and checks the consistency between the estimated activity and change in gene 43 | #' expression. Removes interactions where TF and gene expression are inconsistent 44 | #' @param CARNIVAL_options list that controls the options of CARNIVAL. See details 45 | #' in \code{\link{default_CARNIVAL_options}}. 46 | #' @importFrom utils data 47 | #' @export 48 | #' @return cosmos_data object with the following fields: 49 | #' \describe{ 50 | #' \item{\code{meta_network}}{Filtered PKN} 51 | #' \item{\code{tf_regulon}}{TF - target regulatory network} 52 | #' \item{\code{signaling_data_bin}}{Binarised signaling data} 53 | #' \item{\code{metabolic_data}}{Metabolomics data} 54 | #' \item{\code{diff_expression_data_bin}}{Binarized gene expression data} 55 | #' \item{\code{optimized_network}}{Initial optimized network if 56 | #' \code{filter_tf_gene_interaction_by_optimization is TRUE}} 57 | #' } 58 | #' @seealso \code{\link{meta_network}} for meta PKN, 59 | #' \code{\link{load_tf_regulon_dorothea}} for tf regulon, 60 | #' \code{\link[CARNIVAL]{runCARNIVAL}}. 61 | #' 62 | #' @examples 63 | #' data(toy_network) 64 | #' data(toy_signaling_input) 65 | #' data(toy_metabolic_input) 66 | #' data(toy_RNA) 67 | #' test_for <- preprocess_COSMOS_signaling_to_metabolism(meta_network = toy_network, 68 | #' signaling_data = toy_signaling_input, 69 | #' metabolic_data = toy_metabolic_input, 70 | #' diff_expression_data = toy_RNA, 71 | #' maximum_network_depth = 15, 72 | #' remove_unexpressed_nodes = TRUE, 73 | #' CARNIVAL_options = default_CARNIVAL_options("lpSolve")) 74 | 75 | preprocess_COSMOS_signaling_to_metabolism <- function(meta_network = meta_network, 76 | tf_regulon = load_tf_regulon_dorothea(), 77 | signaling_data, 78 | metabolic_data, 79 | diff_expression_data = NULL, 80 | diff_exp_threshold = 1, 81 | maximum_network_depth = 8, 82 | expressed_genes = NULL, 83 | remove_unexpressed_nodes = TRUE, 84 | filter_tf_gene_interaction_by_optimization = TRUE, 85 | CARNIVAL_options = default_CARNIVAL_options("lpSolve")){ 86 | 87 | if(!is.null(diff_expression_data)) 88 | { 89 | expressed_genes <- names(diff_expression_data)[!is.na(diff_expression_data)] 90 | } else 91 | { 92 | expressed_genes <- NULL 93 | remove_unexpressed_nodes <- FALSE 94 | } 95 | 96 | out_data <- preprocess_COSMOS_core(meta_network = meta_network, 97 | tf_regulon = tf_regulon, 98 | signaling_data=signaling_data, 99 | metabolic_data=metabolic_data, 100 | input_layer = "signaling_data", 101 | output_layer = "metabolic_data", 102 | diff_expression_data=diff_expression_data, 103 | diff_exp_threshold = diff_exp_threshold, 104 | maximum_network_depth = maximum_network_depth, 105 | expressed_genes = expressed_genes, 106 | remove_unexpressed_nodes = remove_unexpressed_nodes, 107 | filter_tf_gene_interaction_by_optimization = filter_tf_gene_interaction_by_optimization, 108 | CARNIVAL_options = CARNIVAL_options) 109 | 110 | out_data$history = c(out_data$history,"created by preprocess_COSMOS_signaling_to_metaboism\n") 111 | 112 | return(out_data) 113 | } 114 | -------------------------------------------------------------------------------- /R/process_CARNIVAL_results.R: -------------------------------------------------------------------------------- 1 | 2 | #' process_CARNIVAL_results 3 | #' 4 | #' formats the raw CARNIVAL results to a more appealing list of networks. 5 | #' @param CARNIVAL_results list of matrices received from 6 | #' CRANIVAL::run_CARNIVAL() 7 | #' @return list with the following elements: 8 | #' \describe{ 9 | #' \item{\code{aggregated_network}}{The averaged networks found by 10 | #' optimization in a format of a Simple Interaction network, i.e. each row 11 | #' codes an edge} 12 | #' \item{\code{N_networks}}{Number of solutions found by the 13 | #' optimization} 14 | #' \item{\code{aggregated_network_node_attributes}}{Estimated node properties} 15 | #' \item{\code{individual_networks}}{List of optimial networks found} 16 | #' \item{\code{individual_networks_node_attributes}}{Node activity in each 17 | #' network} 18 | #' } 19 | #' @importFrom rlang .data 20 | #' @importFrom dplyr %>% mutate rename as_tibble 21 | #' @importFrom purrr map 22 | #' @noRd 23 | process_CARNIVAL_results <- function(CARNIVAL_results){ 24 | 25 | network_output = list() 26 | 27 | network_output$weightedSIF <- dplyr::as_tibble(CARNIVAL_results$weightedSIF) %>% 28 | dplyr::rename(Node1 = "Node1", 29 | Node2 = "Node2", 30 | Sign = "Sign", 31 | Weight = "Weight") %>% 32 | dplyr::mutate(Sign = as.numeric(.data$Sign), 33 | Weight = as.numeric(.data$Weight)/100) 34 | 35 | network_output$N_networks = length(CARNIVAL_results$sifAll) 36 | 37 | network_output$nodesAttributes = 38 | dplyr::as_tibble(CARNIVAL_results$nodesAttributes) %>% 39 | dplyr::mutate(ZeroAct = as.numeric(.data$ZeroAct)/100, 40 | UpAct = as.numeric(.data$UpAct)/100, 41 | DownAct = as.numeric(.data$DownAct)/100, 42 | AvgAct = as.numeric(.data$AvgAct)/100, 43 | ) 44 | 45 | network_output$individual_networks = 46 | purrr::map(CARNIVAL_results$sifAll,function(Net){ 47 | dplyr::as_tibble(Net) %>% 48 | dplyr::rename(source = "Node1", 49 | target = "Node2", 50 | interaction = "Sign") %>% 51 | dplyr::mutate(interaction = as.numeric(.data$interaction)) 52 | 53 | } ) 54 | 55 | 56 | network_output$individual_networks_node_attributes = 57 | purrr::map(CARNIVAL_results$attributesAll,function(Net){ 58 | dplyr::as_tibble(Net) %>% 59 | dplyr::rename(node = "Nodes", 60 | activity = "Activity") %>% 61 | dplyr::mutate(activity = as.numeric(.data$activity)) 62 | 63 | } ) 64 | 65 | return(network_output) 66 | 67 | } -------------------------------------------------------------------------------- /R/runCARNIVAL_wrapper.R: -------------------------------------------------------------------------------- 1 | #' Run CARNIVAL Wrapper 2 | #' 3 | #' Checks and formats the COSMOS data to CARNIVAL inputs and runs CARNIVAL. 4 | #' 5 | #' @param network Prior knowledge network (PKN). \dQuote{\code{data.frame}} 6 | #' object with source, sign and target columns. By default COSMOS uses a PKN 7 | #' derived from Omnipath, STITCHdb and Recon3D. See details on the data 8 | #' \code{\link{meta_network}}. 9 | #' 10 | #' @param input_data Numerical vector, where names are input nodes in the PKN 11 | #' and values are from \{1, 0, -1\}. 12 | #' 13 | #' @param measured_data Numerical vector, where names are measured nodes in the 14 | #' PKN and values are continuous values. These values are compared to with 15 | #' the simulation. 16 | #' 17 | #' @param options An object of type \dQuote{\code{list}} defining the run 18 | #' parameters for CARNIVAL. Use the \code{\link{default_CARNIVAL_options}} 19 | #' function to create a list with default parameter settings. If cplex or cbc 20 | #' are chosen as the solver, the parameter solverPath needs to be supplied 21 | #' (not automatically added by \code{default_CARNIVAL_options()}). 22 | #' @noRd 23 | runCARNIVAL_wrapper <- function(network, 24 | input_data, 25 | measured_data, 26 | options 27 | ){ 28 | 29 | check_CARNIVAL_options(options) 30 | check_inputs_for_CARNIVAL(meta_network = network, 31 | input_data = input_data, 32 | measured_data = measured_data) 33 | 34 | 35 | CARNIVAL_Result <- CARNIVAL::runVanillaCarnival(perturbations = input_data, 36 | measurements = measured_data, 37 | priorKnowledgeNetwork = network, 38 | carnivalOptions = options) 39 | 40 | 41 | if(!validate_CARNIVAL_results(CARNIVAL_Result)) warning("We failed to validate CARNIVAL results.") 42 | 43 | return(CARNIVAL_Result) 44 | } -------------------------------------------------------------------------------- /R/run_COSMOS_metabolism_to_signaling.R: -------------------------------------------------------------------------------- 1 | #' run COSMOS metabolism to signaling 2 | #' 3 | #' Runs COSMOS from metabolism to signaling. This function uses CARNIVAL to find 4 | #' a subset of the prior knowledge network based on optimization that (1) 5 | #' includes the most measured and input nodes and (2) which is in agreement with 6 | #' the data. Use \code{\link{preprocess_COSMOS_metabolism_to_signaling}} to 7 | #' prepare the the inputs, measurements and the prior knowledge network. 8 | #' 9 | #' @param data \code{\link{cosmos_data}} object. Use the 10 | #' \code{\link{preprocess_COSMOS_metabolism_to_signaling}} function to create 11 | #' an instance. 12 | #' @param CARNIVAL_options List that controls the options of CARNIVAL. See details 13 | #' in \code{\link{default_CARNIVAL_options}}. 14 | #' @export 15 | #' @return List with the following elements: 16 | #' \describe{ 17 | #' \item{\code{weightedSIF}}{The averaged networks found by 18 | #' optimization in a format of a Simple Interaction network, i.e. each row 19 | #' codes an edge} 20 | #' \item{\code{N_networks}}{Number of solutions found by the 21 | #' optimization} 22 | #' \item{\code{nodesAttributes}}{Estimated node properties} 23 | #' \item{\code{individual_networks}}{List of optimial networks found} 24 | #' \item{\code{individual_networks_node_attributes}}{Node activity in each 25 | #' network} 26 | #' } 27 | #' @seealso \code{\link{preprocess_COSMOS_metabolism_to_signaling}}, 28 | #' \code{\link[CARNIVAL]{runCARNIVAL}}, \code{\link{cosmos_data}} 29 | #' @examples 30 | #' data(toy_network) 31 | #' data(toy_signaling_input) 32 | #' data(toy_metabolic_input) 33 | #' data(toy_RNA) 34 | #' test_back <- preprocess_COSMOS_metabolism_to_signaling(meta_network = toy_network, 35 | #' signaling_data = toy_signaling_input, 36 | #' metabolic_data = toy_metabolic_input, 37 | #' diff_expression_data = toy_RNA, 38 | #' maximum_network_depth = 15, 39 | #' remove_unexpressed_nodes = TRUE, 40 | #' CARNIVAL_options = default_CARNIVAL_options("lpSolve")) 41 | #' 42 | #' test_result_back <- run_COSMOS_metabolism_to_signaling(data = test_back, 43 | #' CARNIVAL_options = default_CARNIVAL_options("lpSolve")) 44 | run_COSMOS_metabolism_to_signaling <- function(data, 45 | CARNIVAL_options = default_CARNIVAL_options("lpSolve")){ 46 | 47 | ## Checking COSMOS input format 48 | validate_cosmos_data_metabolism_to_signaling(data) 49 | 50 | check_CARNIVAL_options(CARNIVAL_options) 51 | 52 | disc_metabolic_data <- discretize_input(data$metabolic_data) 53 | 54 | CARNIVAL_results = runCARNIVAL_wrapper(network = data$meta_network, 55 | input_data = disc_metabolic_data, 56 | measured_data = data$signaling_data, 57 | options = CARNIVAL_options) 58 | 59 | network_results <- process_CARNIVAL_results(CARNIVAL_results) 60 | 61 | } 62 | 63 | 64 | validate_cosmos_data_metabolism_to_signaling <- function(data){ 65 | 66 | validate_cosmos_data(data) 67 | 68 | if(!all(c("signaling_data_bin") %in% names(data))) 69 | stop("missing inputs detected. Input data should be obtained by running preprocess_cosmos_metabolism_to_signaling.") 70 | 71 | } 72 | -------------------------------------------------------------------------------- /R/run_COSMOS_signaling_to_metabolism.R: -------------------------------------------------------------------------------- 1 | #' run COSMOS signaling to metabolism 2 | #' 3 | #' Runs COSMOS from signaling to metabolism. This function uses CARNIVAL to find 4 | #' a subset of the prior knowledge network based on optimisation that (1) 5 | #' includes the most measured and input nodes and (2) which is in agreement with 6 | #' the data. Use \code{\link{preprocess_COSMOS_signaling_to_metabolism}} to 7 | #' prepare inputs, measurements and prior knowledge network. 8 | #' 9 | #' @param data \code{\link{cosmos_data}} object. Use the 10 | #' \code{\link{preprocess_COSMOS_signaling_to_metabolism}} function to create 11 | #' an instance. 12 | #' @param CARNIVAL_options List that controls the options of CARNIVAL. See 13 | #' details in \code{\link{default_CARNIVAL_options}}. 14 | #' @export 15 | #' @return List with the following elements: 16 | #' \describe{ 17 | #' \item{\code{weightedSIF}}{The averaged networks found by 18 | #' optimization in a format of a Simple Interaction network, i.e. each row 19 | #' codes an edge} 20 | #' \item{\code{N_networks}}{Number of solutions found by the 21 | #' optimization} 22 | #' \item{\code{nodesAttributes}}{Estimated node properties} 23 | #' \item{\code{individual_networks}}{List of optimial networks found} 24 | #' \item{\code{individual_networks_node_attributes}}{Node activity in each 25 | #' network} 26 | #' } 27 | #' @seealso \code{\link{preprocess_COSMOS_metabolism_to_signaling}}, 28 | #' \code{\link[CARNIVAL]{runCARNIVAL}}, \code{\link{cosmos_data}} 29 | #' @examples 30 | #' data(toy_network) 31 | #' data(toy_signaling_input) 32 | #' data(toy_metabolic_input) 33 | #' data(toy_RNA) 34 | #' test_for <- preprocess_COSMOS_signaling_to_metabolism(meta_network = toy_network, 35 | #' signaling_data = toy_signaling_input, 36 | #' metabolic_data = toy_metabolic_input, 37 | #' diff_expression_data = toy_RNA, 38 | #' maximum_network_depth = 15, 39 | #' remove_unexpressed_nodes = TRUE, 40 | #' CARNIVAL_options = default_CARNIVAL_options("lpSolve")) 41 | #' 42 | #' test_result_for <- run_COSMOS_signaling_to_metabolism(data = test_for, 43 | #' CARNIVAL_options = default_CARNIVAL_options("lpSolve")) 44 | run_COSMOS_signaling_to_metabolism <- function(data, 45 | CARNIVAL_options = default_CARNIVAL_options("lpSolve")){ 46 | 47 | ## Checking COSMOS input format 48 | validate_cosmos_data_signaling_to_metabolism(data) 49 | 50 | check_CARNIVAL_options(CARNIVAL_options) 51 | 52 | disc_signaling_data <- discretize_input(data$signaling_data) 53 | 54 | CARNIVAL_results = runCARNIVAL_wrapper(network = data$meta_network, 55 | input_data = disc_signaling_data, 56 | measured_data = data$metabolic_data, 57 | options = CARNIVAL_options) 58 | 59 | network_results <- process_CARNIVAL_results(CARNIVAL_results) 60 | 61 | } 62 | 63 | 64 | validate_cosmos_data_signaling_to_metabolism <- function(data){ 65 | 66 | validate_cosmos_data(data) 67 | 68 | if(!all(c("signaling_data_bin") %in% names(data))) 69 | stop("missing inputs detected. Input data should be obtained by running preprocess_cosmos_signaling_to_metabolism.") 70 | 71 | } 72 | 73 | -------------------------------------------------------------------------------- /R/support_ORA.R: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 Caroline Lohoff, Aurelien Dugourd 2 | 3 | # based on "support_enrichment.R" from 4 | # https://github.com/saezlab/transcriptutorial/blob/master/scripts/06_analysis_CARNIVAL_results.md 5 | # Copyright (C) 2020 Aurelien Dugourd, Alberto Valdeolivas, Rosa Hernansaiz-Ballesteros 6 | # Contact : aurelien.dugourd@bioquant.uni-heidelberg.de 7 | 8 | # This program is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program. If not, see . 20 | 21 | 22 | #' Convert gmt file to data frame 23 | #' 24 | #' This function is designed to convert a gmt file (gene set file from MSigDB) 25 | #' into a two column data frame where the first column corresponds to omic 26 | #' features (genes) and the second column to associated terms (pathway the gene 27 | #' belongs to). One gene can belong to several pathways. 28 | #' 29 | #' @param gmtfile a full path name of the gmt file to be converted 30 | #' @return a two column data frame where the first column corresponds to omic 31 | #' features and the second column to associated terms (pathways). 32 | #' @importFrom dplyr bind_rows 33 | #' @importFrom progress progress_bar 34 | 35 | gmt_to_dataframe <- function(gmtfile) 36 | { 37 | genesets = GSEABase::getGmt(con = gmtfile) 38 | genesets = unlist(genesets) 39 | 40 | pb <- progress::progress_bar$new(total=length(genesets), 41 | format = "[:bar] :percent eta: :eta") 42 | 43 | gene_to_term <- lapply(genesets,function(geneset){ 44 | pb$tick() 45 | temp <- GSEABase::geneIds(geneset) 46 | temp2 <- GSEABase::setName(geneset) 47 | temp3 <- as.data.frame(cbind(temp,rep(temp2,length(temp)))) 48 | 49 | }) %>% 50 | dplyr::bind_rows() 51 | 52 | names(gene_to_term) <- c("gene","term") 53 | return(gene_to_term[stats::complete.cases(gene_to_term),]) 54 | } 55 | 56 | 57 | #' Extract COSMOS nodes for ORA analysis 58 | #' 59 | #' Function to extract the nodes that appear in the COSMOS output network and 60 | #' the background genes (all genes present in the prior knowledge network) 61 | #' 62 | #' @param sif df; COSMOS network solution in sif format like the first list 63 | #' element returned by the format_cosmos_res function 64 | #' @param att df; attributes of the nodes of the COMSOS network solution like 65 | #' the second list element returned by the format_cosmos_res function 66 | #' @return List with 2 objects: the success and the background genes 67 | #' @export 68 | #' @examples 69 | #' CARNIVAL_options <- cosmosR::default_CARNIVAL_options("lpSolve") 70 | #' data(toy_network) 71 | #' data(toy_signaling_input) 72 | #' data(toy_metabolic_input) 73 | #' data(toy_RNA) 74 | #' test_for <- preprocess_COSMOS_signaling_to_metabolism(meta_network = toy_network, 75 | #' signaling_data = toy_signaling_input, 76 | #' metabolic_data = toy_metabolic_input, 77 | #' diff_expression_data = toy_RNA, 78 | #' maximum_network_depth = 15, 79 | #' remove_unexpressed_nodes = TRUE, 80 | #' CARNIVAL_options = CARNIVAL_options 81 | #' ) 82 | #' test_result_for <- run_COSMOS_signaling_to_metabolism(data = test_for, 83 | #' CARNIVAL_options = CARNIVAL_options) 84 | #' test_result_for <- format_COSMOS_res(test_result_for) 85 | #' extreacted_nodes <- extract_nodes_for_ORA( 86 | #' sif = test_result_for[[1]], 87 | #' att = test_result_for[[2]] 88 | #' ) 89 | 90 | extract_nodes_for_ORA <- function(sif, att){ 91 | 92 | # Extract all nodes from COSMOS's solution network 93 | CosmosNetwork <- 94 | as.data.frame(sif, stringsAsFactors = FALSE) 95 | colnames(CosmosNetwork) <- c("source", "sign", "target", "weight") 96 | 97 | # Remove all metabolites 98 | CosmosNetwork <- CosmosNetwork[!grepl("Metab", CosmosNetwork$source), ] 99 | CosmosNetwork <- CosmosNetwork[!grepl("Metab", CosmosNetwork$target), ] 100 | 101 | ## We define the set of unique nodes (genes) in the solution network 102 | sucesses <- unique(c(gsub("_.*","",CosmosNetwork$source), 103 | gsub("_.*","",CosmosNetwork$target))) 104 | 105 | # Extract all unique genes from PKN as background nodes 106 | Cosmos_attributes <- as.data.frame(att, 107 | stringsAsFactors = FALSE) 108 | Cosmos_attributes <- Cosmos_attributes[!grepl("Metab", Cosmos_attributes$Nodes), ] 109 | bg <- unique(gsub("_.*","",Cosmos_attributes$Nodes)) 110 | 111 | return(list(sucesses = sucesses, bg = bg)) 112 | } 113 | -------------------------------------------------------------------------------- /R/support_decoupleR.R: -------------------------------------------------------------------------------- 1 | #' Format Ligand-Receptor Resource 2 | #' 3 | #' This function formats a ligand-receptor resource by creating a gene set 4 | #' with source-target pairs, converting it to a long format, and adding 5 | #' default values for 'mor' and 'likelihood'. 6 | #' 7 | #' @param ligrec_ressource A data frame representing the ligand-receptor resource with columns for source and target gene symbols. 8 | #' 9 | #' @return A data frame containing the formatted ligand-receptor gene set with columns: 10 | #' \item{gene}{The gene symbol from the ligand-receptor pairs.} 11 | #' \item{set}{The set identifier combining source and target gene symbols.} 12 | #' \item{mor}{Default value set to 1 for all entries.} 13 | #' \item{likelihood}{Default value set to 1 for all entries.} 14 | #' 15 | #' @examples 16 | #' # Create a sample ligand-receptor resource 17 | #' ligrec_ressource <- data.frame(source_genesymbol = c("L1", "L2"), 18 | #' target_genesymbol = c("R1", "R2")) 19 | #' 20 | #' # Format the ligand-receptor resource 21 | #' formatted_geneset <- format_LR_ressource(ligrec_ressource) 22 | #' 23 | #' @export 24 | format_LR_ressource <- function(ligrec_ressource) 25 | { 26 | ligrec_geneset <- ligrec_ressource[,c("source_genesymbol","target_genesymbol")] 27 | ligrec_geneset$set <- paste(ligrec_geneset$source_genesymbol, ligrec_geneset$target_genesymbol, sep = "___") 28 | ligrec_geneset <- reshape2::melt(ligrec_geneset, id.vars = "set")[,c(3,1)] 29 | names(ligrec_geneset)[1] <- "gene" 30 | ligrec_geneset$mor <- 1 31 | ligrec_geneset$likelihood <- 1 32 | ligrec_geneset <- distinct(ligrec_geneset) 33 | 34 | return(ligrec_geneset) 35 | } 36 | 37 | #' Convert ULM Results to Wide Format 38 | #' 39 | #' This function converts the results from a ULM analysis to a wide format data frame. 40 | #' The input is a data frame with columns for source, condition, and score. The output 41 | #' is a data frame where each row represents a source and each column represents a condition, 42 | #' with the corresponding scores as values. 43 | #' 44 | #' @param ulm_result A data frame representing the ULM results with columns: source, condition, and score. 45 | #' 46 | #' @return A data frame in wide format where each row is a source and each column is a condition. 47 | #' 48 | #' @examples 49 | #' # Create a sample ULM result 50 | #' ulm_result <- data.frame(source = c("A", "A", "B", "B"), 51 | #' condition = c("cond1", "cond2", "cond1", "cond2"), 52 | #' score = c(0.5, 0.8, 0.3, 0.7)) 53 | #' 54 | #' # Convert to wide format 55 | #' wide_ulm_result <- wide_ulm_res(ulm_result) 56 | #' 57 | #' @export 58 | wide_ulm_res <- function(ulm_result) 59 | { 60 | ulm_result_df <- reshape2::dcast(ulm_result, formula = source~condition, value.var = "score") 61 | row.names(ulm_result_df) <- ulm_result_df$source 62 | ulm_result_df <- ulm_result_df[,-1] 63 | 64 | return(ulm_result_df) 65 | } 66 | 67 | #' Translate Column Using HMDB Mapper 68 | #' 69 | #' This function translates the values in a column using a provided Human Metabolome Database (HMDB) mapper vector. 70 | #' It modifies the input values by replacing certain prefixes and suffixes according to specific rules. 71 | #' 72 | #' @param my_column A vector of values to be translated. 73 | #' @param HMDB_mapper_vec A named vector where the names are the original identifiers and the values are the corresponding HMDB identifiers. 74 | #' 75 | #' @return A vector with the translated values. 76 | #' 77 | #' @examples 78 | #' # Create a sample column and HMDB mapper vector 79 | #' my_column <- c("Metab__1234_a", "Gene5678_b", "Metab__91011_c") 80 | #' HMDB_mapper_vec <- c("1234" = "HMDB00001", "5678" = "HMDB00002", "91011" = "HMDB00003") 81 | #' 82 | #' # Translate the column 83 | #' translated_column <- translate_column_HMDB(my_column, HMDB_mapper_vec) 84 | #' 85 | #' @export 86 | translate_column_HMDB <- function(my_column, HMDB_mapper_vec) 87 | { 88 | return(sapply(my_column, function(x, HMDB_mapper_vec) { 89 | x <- gsub("Metab__", "", x) 90 | x <- gsub("^Gene", "Enzyme", x) 91 | suffixe <- stringr::str_extract(x, "_[a-z]$") 92 | x <- gsub("_[a-z]$", "", x) 93 | if (x %in% names(HMDB_mapper_vec)) { 94 | x <- HMDB_mapper_vec[x] 95 | x <- paste("Metab__", x, sep = "") 96 | } 97 | if (!is.na(suffixe)) { 98 | x <- paste(x, suffixe, sep = "") 99 | } 100 | return(x) 101 | }, HMDB_mapper_vec = HMDB_mapper_vec)) 102 | } -------------------------------------------------------------------------------- /R/support_pheatmap.R: -------------------------------------------------------------------------------- 1 | #' Create Heatmap Color Palette 2 | #' 3 | #' This function generates a color palette suitable for heatmaps based on the values in a matrix. It uses the `createLinearColors` function to generate separate color gradients for positive and negative values. 4 | #' 5 | #' @param my_matrix A numeric matrix for which the heatmap color palette is to be generated. 6 | #' 7 | #' @return A character vector of colors representing the heatmap color palette based on the input matrix values. 8 | #' 9 | #' @examples 10 | #' # Create a sample matrix 11 | #' my_matrix <- matrix(c(-3, -1, 0, 1, 3), nrow = 1) 12 | #' 13 | #' # Generate heatmap color palette 14 | #' heatmap_palette <- make_heatmap_color_palette(my_matrix) 15 | #' 16 | #' @export 17 | make_heatmap_color_palette <- function(my_matrix) 18 | { 19 | t <- as.vector(t(my_matrix)) 20 | palette1 <- createLinearColors(t[t < 0],withZero = F , maximum = abs(min(t,na.rm = T)) * 10) 21 | palette2 <- createLinearColors(t[t > 0],withZero = F , maximum = abs(max(t,na.rm = T)) * 10) 22 | palette <- c(palette1, palette2) 23 | } 24 | 25 | #' Create Linear Colors Based on Numeric Input 26 | #' 27 | #' This function generates a gradient of colors based on the provided numeric values. The colors can be adjusted to include zero and are configurable with a specified maximum and custom color palette. 28 | #' 29 | #' @param numbers A numeric vector for which the color gradient is to be generated. 30 | #' @param withZero A logical value indicating whether zero should be included in the color gradient. Default is TRUE. 31 | #' @param maximum An integer specifying the maximum number of colors to be generated in the gradient. Default is 100. 32 | #' @param my_colors A character vector of length three specifying the colors to be used in the gradient. Default is c("royalblue3", "white", "red"). 33 | #' 34 | #' @return A character vector of colors representing the gradient based on the input numeric values. 35 | #' 36 | #' @examples 37 | #' # Generate colors for a set of numbers including zero 38 | #' numbers <- c(-50, -20, 0, 20, 50) 39 | #' colors <- createLinearColors(numbers, withZero = TRUE, maximum = 100) 40 | #' 41 | #' @export 42 | createLinearColors <- function(numbers, withZero = T, maximum = 100, my_colors = c("royalblue3","white","red")) 43 | { 44 | if (min(numbers, na.rm = T) > 0) 45 | { 46 | if(withZero) 47 | { 48 | numbers <- c(0,numbers) 49 | } 50 | myPalette <- colorRampPalette(my_colors[c(2,3)]) 51 | myColors <- myPalette(maximum) 52 | } 53 | else 54 | { 55 | if (max(numbers, na.rm = T) < 0) 56 | { 57 | if(withZero) 58 | { 59 | numbers <- c(0,numbers) 60 | } 61 | myPalette <- colorRampPalette(my_colors[c(1,2)]) 62 | myColors <- myPalette(maximum) 63 | } 64 | else 65 | { 66 | myPalette_pos <- colorRampPalette(c("white","red")) 67 | myPalette_neg <- colorRampPalette(c("royalblue3","white")) 68 | npos <- length(numbers[numbers >= 0]) + 1 69 | nneg <- length(numbers[numbers <= 0]) + 1 70 | 71 | myColors_pos <- myPalette_pos(npos) 72 | myColors_neg <- myPalette_neg(nneg) 73 | 74 | #print(myColors_neg) 75 | #print(myColors_pos) 76 | 77 | myColors <- c(myColors_neg[-(nneg)], myColors_pos[-1]) 78 | } 79 | } 80 | return(myColors) 81 | } 82 | -------------------------------------------------------------------------------- /R/sysdata.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/R/sysdata.rda -------------------------------------------------------------------------------- /R/toy_RNA.R: -------------------------------------------------------------------------------- 1 | #' Toy Input Transcription Data Set 2 | #' 3 | #' This exemplary transcription data are the specific deregulated gene expression of the 786-O cell line from the NCI60 dataset. 4 | #' 5 | #' @docType data 6 | #' 7 | #' @usage data(toy_RNA) 8 | #' 9 | #' @format An object of class \dQuote{\code{numeric}} containing the t-values of 10 | #' 9300 genes, which are named with gene symboles matching the toy network. 11 | #' 12 | #' @source 13 | #' \url{https://github.com/saezlab/COSMOS_MSB/blob/main/data/RNA_ttop_tumorvshealthy.csv} 14 | #' 15 | #' @references { 16 | #' Dugourd, A., Kuppe, C. and Sciacovelli, M. et. al. (2021) \emph{Molecular 17 | #' Systems Biology}. \bold{17}, e9730. 18 | #' } 19 | #' 20 | #' @examples 21 | #' data(toy_RNA) 22 | #' 23 | #' @keywords datasets 24 | "toy_RNA" -------------------------------------------------------------------------------- /R/toy_metabolic_input.R: -------------------------------------------------------------------------------- 1 | #' Toy Metabolic Input Data 2 | #' 3 | #' This metabolic data are a subset from the metabolic measurements of the 786-O cell line from the NCI60 dataset. 4 | #' 5 | #' @docType data 6 | #' 7 | #' @usage data(toy_metabolic_input) 8 | #' 9 | #' @format An object of class \dQuote{\code{numeric}} containing the t-values of 10 | #' 2 metabolites, which are named with metabolite HMDB Ids matching the 11 | #' toy network. 12 | #' 13 | #' @source Subset of: 14 | #' \url{https://github.com/saezlab/COSMOS_MSB/blob/main/data/metab_input_COSMOS.csv} 15 | #' 16 | #' @references { 17 | #' Dugourd, A., Kuppe, C. and Sciacovelli, M. et. al. (2021) \emph{Molecular 18 | #' Systems Biology}. \bold{17}, e9730. 19 | #' } 20 | #' 21 | #' @examples 22 | #' data(toy_metabolic_input) 23 | #' 24 | #' @keywords datasets 25 | "toy_metabolic_input" -------------------------------------------------------------------------------- /R/toy_network.R: -------------------------------------------------------------------------------- 1 | #' Toy Input Network 2 | #' 3 | #' This signaling network is the reduced COSMOS network solution obtained in the 4 | #' cosmos test on 786-O NCI60 data. Here, this network solution is reused as an 5 | #' exemplary input prior knowledge network (PKN). 6 | #' 7 | #' @docType data 8 | #' 9 | #' @usage data(toy_network) 10 | #' 11 | #' @format An object of class \dQuote{\code{data.frame}} with 19 rows 12 | #' (interactions) and three variables: 13 | #' \describe{ 14 | #' \item{\code{source}}{Source node, either metabolite or protein} 15 | #' \item{\code{interaction}}{Type of interaction, 1 = Activation, -1 = Inhibition} 16 | #' \item{\code{target}}{Target node, either metabolite or protein} 17 | #' A detailed description of the identifier formatting can be found under 18 | #' \url{https://metapkn.omnipathdb.org/00__README.txt}. 19 | #' } 20 | #' 21 | #' @source The network data are available on github: 22 | #' \url{https://github.com/saezlab/COSMOS_MSB/tree/main/results/COSMOS_result/COSMOS_res_session.RData}. 23 | #' The toy_network is the combined network of the COSMOS network solutions 24 | #' CARNIVAL_Result2 and CARNIVAL_Result_rerun subsequently reduced to 19 25 | #' exemplary nodes. 26 | #' 27 | #' @references { 28 | #' Dugourd, A., Kuppe, C. and Sciacovelli, M. et. al. (2021) \emph{Molecular 29 | #' Systems Biology}. \bold{17}, e9730. 30 | #' } 31 | #' 32 | #' @examples 33 | #' data(toy_network) 34 | #' 35 | #' @keywords datasets 36 | "toy_network" -------------------------------------------------------------------------------- /R/toy_signaling_input.R: -------------------------------------------------------------------------------- 1 | #' Toy Signaling Input 2 | #' 3 | #' This signaling data are a subset of the footprint-based signaling activity 4 | #' estimates of transcription factors of the 786-O cell line from the NCI60 dataset. 5 | #' 6 | #' @docType data 7 | #' 8 | #' @usage data(toy_signaling_input) 9 | #' 10 | #' @format An object of class \dQuote{\code{data.frame}} containing the normalised 11 | #' enrichment scores (NES) of 2 signaling proteins, which are named with their 12 | #' respective gene Entrez ID matching the toy network. 13 | #' 14 | #' @source Subset of: 15 | #' \url{https://github.com/saezlab/COSMOS_MSB/blob/main/data/signaling_input_COSMOS.csv} 16 | #' 17 | #' @references { 18 | #' Dugourd, A., Kuppe, C. and Sciacovelli, M. et. al. (2021) \emph{Molecular 19 | #' Systems Biology}. \bold{17}, e9730. 20 | #' } 21 | #' 22 | #' @examples 23 | #' data(toy_signaling_input) 24 | #' 25 | #' @keywords datasets 26 | "toy_signaling_input" -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cosmosR 2 | 3 | 4 | [![R-CMD-check](https://github.com/saezlab/cosmosr/workflows/R-CMD-check-bioc/badge.svg)](https://github.com/saezlab/cosmosr/actions) 5 | 6 | 7 | ## Overview 8 | 9 | COSMOS (Causal Oriented Search of Multi-Omic Space) is a method that integrates phosphoproteomics, transcriptomics, and metabolomics data sets. COSMOS leverages extensive prior knowledge of signaling pathways, metabolic networks, and gene regulation with computational methods to estimate activities of transcription factors and kinases as well as network-level causal reasoning. This pipeline can provide mechanistic explanations for experimental observations across multiple omic data sets. 10 | 11 | 12 | 13 | 14 | COSMOS finds coherent subnetwork causally connecting as many deregulated TFs, kinases/phosphatases and metabolites as possible. The subnetwork is extracted from a novel integrated PKN (available [here](http://metapkn.omnipathdb.org/)) spanning signaling, transcriptional regulation and metabolism. Transcription factors activities are inferred from gene expression with [decoupleR](https://saezlab.github.io/decoupleR/). Kinase activities are inferred from phosphoproteomic with a kinase/substrate network of [Omnipath](http://omnipathdb.org/), a meta resource of protein-protein. The scripts to generate the current network can be found here: https://github.com/saezlab/meta_PKN_BIGG. 15 | 16 | 17 | You can also use COSMOS if you don't have metabolomic data, to connect TF activities (from transcriptomic) with kinase activities (from phosphoproteomic) for exmaple ! 18 | 19 | 20 | 21 | 22 | ## Installation 23 | 24 | R >= 4.1 is required 25 | ```r 26 | # install from bioconductor 27 | if (!requireNamespace("BiocManager", quietly = TRUE)) 28 | install.packages("BiocManager") 29 | 30 | BiocManager::install("cosmosR") 31 | 32 | # We advise to instal from github to get the latest version of the tool. 33 | if (!requireNamespace("devtools", quietly = TRUE)) 34 | install.packages("devtools") 35 | 36 | devtools::install_github("saezlab/cosmosR") 37 | ``` 38 | 39 | If you don't have R 4.1, you can also clone the github repository on your machine, create a new R project with R studio from the cosmosR folder, change the R version to your own R version in the DESCRIPTION file and then install it with devtools:install() 40 | 41 | But 4.1 is advised in any case. 42 | 43 | ## tutorial to use MOFA and COSMOS 44 | 45 | [Here](https://github.com/saezlab/Factor_COSMOS/) you can find an extensive tutorial showing how to use MOFA and COSMOS with the NCI60 dataset. This is an extensive tutorial, if you wish to get a quicker plug and play introduction to COSMOS, see below. 46 | 47 | !!! THIS is were you can find the input data and the pre-processing scripts that corespond to the featured vignette !!! 48 | 49 | ## Tutorial (NCI60 playground) 50 | 51 | We made a repository that contains pre-processed inputs and an example script to use cosmos with the NCI60 RNA+metabolomic datasets. 52 | You can find the repository [here](https://github.com/saezlab/COSMOS_basic). 53 | 54 | !!! THIS is were you can find the input data and the pre-processing scripts that corespond to the featured vignette !!! 55 | 56 | ## Access 57 | 58 | The meta PKN used with the older biorXiv version of COSMOS (2021) is available [here](http://metapkn.omnipathdb.org/). 59 | 60 | An updated meta PKN is available with the package (using data(meta_network) in R) 61 | 62 | ## Citation 63 | If you use cosmosR for your research please cite [COSMOS+ preprint](https://www.biorxiv.org/content/10.1101/2024.07.15.603538v2) 64 | Dugourd A, Lafrenz P, Mañanes D, Fallegger R, Kroger AC, Turei D, Shtylla B, Saez-Rodriguez J; Modeling causal signal propagation in multi-omic factor space with COSMOS; BioRxiv. 2024 Jul 17 65 | DOI: 10.1101/2024.07.15.603538 66 | 67 | The first publication of COSMOS is MSB can be found [here](https://www.embopress.org/doi/full/10.15252/msb.20209730): 68 | 69 | ## License 70 | 71 | The code is distributed under the GNU General Public License v3.0. The meta PKN is distributed under the Attribution-NonCommercial 4.0 International (CC-BY-NC 4.0) License. 72 | -------------------------------------------------------------------------------- /data/HMDB_mapper_vec.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/data/HMDB_mapper_vec.RData -------------------------------------------------------------------------------- /data/meta_network.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/data/meta_network.RData -------------------------------------------------------------------------------- /data/toy_RNA.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/data/toy_RNA.RData -------------------------------------------------------------------------------- /data/toy_metabolic_input.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/data/toy_metabolic_input.RData -------------------------------------------------------------------------------- /data/toy_network.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/data/toy_network.RData -------------------------------------------------------------------------------- /data/toy_signaling_input.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/data/toy_signaling_input.RData -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | citEntry( 2 | entry="article", 3 | author = c(person("Aurelien", "Dugourd"), 4 | person("Christoph", "Kuppe"), 5 | person("Marco", "Sciacovelli"), 6 | person("Enio", "Gjerga"), 7 | person("Attila", "Gabor"), 8 | person("Kristina B.", "Embdal"), 9 | person("Vitor", "Vieira"), 10 | person("Dorte B.", "Bekker-Jensen"), 11 | person("Jennifer", "Kranz"), 12 | person("Eric M. J.", "Bindels"), 13 | person("Ana S. H.", "Costa"), 14 | person("Abel", "Sousa"), 15 | person("Pedro", "Beltrao"), 16 | person("Jesper V", "Olsen"), 17 | person("Christian", "Frezza"), 18 | person("Rafael", "Kramann"), 19 | person("Julio", "Saez-Rodriguez")), 20 | title = "Causal integration of multi-omics data with prior knowledge to generate mechanistic hypotheses", 21 | journal = "Molecular Systems Biology", 22 | year = 2021, 23 | 24 | textVersion = "Aurelien Dugourd, Christoph Kuppe, Marco Sciacovelli, Enio Gjerga, Attila Gabor, Kristina B. Emdal, Vitor Vieira, Dorte B. Bekker-Jensen, Jennifer Kranz, Eric. M. J. Bindels, Ana S. H. Costa, Abel sousa, Pedro Beltrao, Jesper V. Olsen, Christian Frezza, Rafael Kramann, Julio Saez-Rodriguez. 'Causal integration of multi-omics data with prior knowledge to generate mechanistic hypotheses.' Molecular Systems Biology. 2021." 25 | ) 26 | -------------------------------------------------------------------------------- /man/HMDB_mapper_vec.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/HMDB_mapper_vec.R 3 | \docType{data} 4 | \name{HMDB_mapper_vec} 5 | \alias{HMDB_mapper_vec} 6 | \title{Toy Input Transcription Data Set} 7 | \format{ 8 | An object of class \dQuote{\code{character}} containing the marching between HMDB metabolite IDs and there coresponding metabolite names. 9 | } 10 | \source{ 11 | \url{https://bioconductor.org/packages/release/data/annotation/html/metaboliteIDmapping.html} 12 | } 13 | \usage{ 14 | data(HMDB_mapper_vec) 15 | } 16 | \description{ 17 | This exemplary transcription data are the specific deregulated gene expression of the 786-O cell line from the NCI60 dataset. 18 | } 19 | \examples{ 20 | data(HMDB_mapper_vec) 21 | 22 | } 23 | \keyword{datasets} 24 | -------------------------------------------------------------------------------- /man/compress_same_children.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/compress_same_children.R 3 | \name{compress_same_children} 4 | \alias{compress_same_children} 5 | \title{Compress Network by Merging Nodes with Identical Children} 6 | \usage{ 7 | compress_same_children(df, sig_input, metab_input) 8 | } 9 | \arguments{ 10 | \item{df}{A data frame representing the network with three columns: source, target, and sign of interaction.} 11 | 12 | \item{sig_input}{A list of input node signatures to be considered for the merging process.} 13 | 14 | \item{metab_input}{A list of input metabolic signatures to be considered for the merging process.} 15 | } 16 | \value{ 17 | A list containing the following elements: 18 | \item{compressed_network}{A data frame representing the compressed network.} 19 | \item{node_signatures}{A list of signatures of nodes in the network after the merging process.} 20 | \item{duplicated_signatures}{A list of duplicated signatures in the network after the merging process.} 21 | } 22 | \description{ 23 | This function compresses a network by merging nodes that have the same children. 24 | The input network is represented as a data frame with three columns: source, target, and sign of interaction. 25 | The function returns a list containing the compressed network, node signatures, and duplicated signatures. 26 | } 27 | \examples{ 28 | # Create a sample network 29 | df <- data.frame(source = c("A", "A", "B", "B"), 30 | target = c("C", "D", "C", "D"), 31 | sign_of_interaction = c(1, 1, 1, 1)) 32 | 33 | # Define input node and metabolic signatures 34 | sig_input <- list() 35 | metab_input <- list() 36 | 37 | # Compress the network 38 | result <- compress_same_children(df, sig_input, metab_input) 39 | compressed_network <- result$compressed_network 40 | 41 | } 42 | -------------------------------------------------------------------------------- /man/cosmos_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cosmos_data.R 3 | \name{cosmos_data} 4 | \alias{cosmos_data} 5 | \title{Create Cosmos Data} 6 | \usage{ 7 | cosmos_data( 8 | meta_network, 9 | tf_regulon = NULL, 10 | signaling_data, 11 | metabolic_data, 12 | expression_data, 13 | verbose = TRUE 14 | ) 15 | } 16 | \arguments{ 17 | \item{meta_network}{Prior knowledge network (PKN). By default COSMOS use a 18 | PKN derived from Omnipath, STITCHdb and Recon3D. See details on the data 19 | \code{\link{meta_network}}.} 20 | 21 | \item{tf_regulon}{Collection of transcription factor - target interactions. 22 | A default collection from dorothea can be obtained by the 23 | \code{\link{load_tf_regulon_dorothea}} function.} 24 | 25 | \item{signaling_data}{Numerical vector, where names are signaling nodes 26 | in the PKN and values are from \{1, 0, -1\}. Continuous data will be 27 | discretized using the \code{\link{sign}} function.} 28 | 29 | \item{metabolic_data}{Numerical vector, where names are metabolic nodes 30 | in the PKN and values are continuous values that represents log2 fold change 31 | or t-values from a differential analysis. These values are compared to 32 | the simulation results (simulated nodes can take value -1, 0 or 1).} 33 | 34 | \item{expression_data}{Numerical vector that represents the results of a 35 | differential gene expression analysis. Names are gene names using EntrezID 36 | starting with an X and values are log fold change or t-values. Genes with 37 | NA values are considered none expressed and they will be removed from the 38 | TF-gene expression interactions.} 39 | 40 | \item{verbose}{(default: TRUE) Reports details about the 41 | \code{\link{cosmos_data}} object.} 42 | } 43 | \value{ 44 | \code{cosmos data} class instance. 45 | } 46 | \description{ 47 | An S3 class that combines the required data into a comprehensive list. Use 48 | the \code{\link{preprocess_COSMOS_signaling_to_metabolism}} or 49 | \code{\link{preprocess_COSMOS_metabolism_to_signaling}} to create an instance. 50 | } 51 | -------------------------------------------------------------------------------- /man/createLinearColors.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/support_pheatmap.R 3 | \name{createLinearColors} 4 | \alias{createLinearColors} 5 | \title{Create Linear Colors Based on Numeric Input} 6 | \usage{ 7 | createLinearColors( 8 | numbers, 9 | withZero = T, 10 | maximum = 100, 11 | my_colors = c("royalblue3", "white", "red") 12 | ) 13 | } 14 | \arguments{ 15 | \item{numbers}{A numeric vector for which the color gradient is to be generated.} 16 | 17 | \item{withZero}{A logical value indicating whether zero should be included in the color gradient. Default is TRUE.} 18 | 19 | \item{maximum}{An integer specifying the maximum number of colors to be generated in the gradient. Default is 100.} 20 | 21 | \item{my_colors}{A character vector of length three specifying the colors to be used in the gradient. Default is c("royalblue3", "white", "red").} 22 | } 23 | \value{ 24 | A character vector of colors representing the gradient based on the input numeric values. 25 | } 26 | \description{ 27 | This function generates a gradient of colors based on the provided numeric values. The colors can be adjusted to include zero and are configurable with a specified maximum and custom color palette. 28 | } 29 | \examples{ 30 | # Generate colors for a set of numbers including zero 31 | numbers <- c(-50, -20, 0, 20, 50) 32 | colors <- createLinearColors(numbers, withZero = TRUE, maximum = 100) 33 | 34 | } 35 | -------------------------------------------------------------------------------- /man/decompress_moon_result.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/decoupleRnival.R 3 | \name{decompress_moon_result} 4 | \alias{decompress_moon_result} 5 | \title{Decompress Moon Result} 6 | \usage{ 7 | decompress_moon_result(moon_res, meta_network_compressed_list, meta_network) 8 | } 9 | \arguments{ 10 | \item{moon_res}{A data frame containing the results of a moon analysis.} 11 | 12 | \item{meta_network_compressed_list}{A list containing compressed meta network details, 13 | including node signatures and duplicated parents.} 14 | 15 | \item{meta_network}{A data frame representing the original meta network.} 16 | } 17 | \value{ 18 | A data frame which merges the moon analysis results with the meta network data, 19 | including additional details about node signatures and handling of duplicated parents. 20 | } 21 | \description{ 22 | This function decompresses the results obtained from moon analysis by incorporating 23 | node signatures and handling duplicated parents. It merges these details with the 24 | provided meta network data and returns a comprehensive data frame. 25 | } 26 | \examples{ 27 | # Example usage (requires appropriate data structures for moon_res, 28 | # meta_network_compressed_list, and meta_network) 29 | # decompressed_result <- decompress_moon_result(moon_res, meta_network_compressed_list, meta_network) 30 | 31 | } 32 | -------------------------------------------------------------------------------- /man/decompress_solution_network.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/compress_same_children.R 3 | \name{decompress_solution_network} 4 | \alias{decompress_solution_network} 5 | \title{Decompress Solution Network} 6 | \usage{ 7 | decompress_solution_network( 8 | formatted_res, 9 | meta_network, 10 | node_signatures, 11 | duplicated_parents 12 | ) 13 | } 14 | \arguments{ 15 | \item{formatted_res}{A list containing the solution network and attribute table.} 16 | 17 | \item{meta_network}{A data frame representing the meta network.} 18 | 19 | \item{node_signatures}{A list of node signatures.} 20 | 21 | \item{duplicated_parents}{A list of duplicated parents from the compression process.} 22 | } 23 | \value{ 24 | A list containing the following elements: 25 | \item{SIF}{A data frame representing the decompressed solution network.} 26 | \item{ATT}{A data frame containing the attributes of the decompressed solution network.} 27 | } 28 | \description{ 29 | This function decompresses a solution network by mapping node signatures back to their original identifiers. 30 | The input is a formatted solution network, a meta network, node signatures, and duplicated parents. 31 | The function returns a list containing the decompressed solution network and attribute table. 32 | } 33 | \examples{ 34 | # Create a sample formatted_res 35 | formatted_res <- list( 36 | SIF = data.frame(source = c("parent_of_D1", "D"), 37 | target = c("D", "F"), 38 | interaction = c(1, 1), 39 | Weight = c(1, 1)), 40 | ATT = data.frame(Nodes = c("parent_of_D1", "D", "F"), 41 | NodeType = c("","",""), 42 | ZeroAct = c(0,0,0), 43 | UpAct = c(1,1,1), 44 | DownAct = c(0,0,0), 45 | AvgAct = c(1,1,1), 46 | measured = c(0,0,0), 47 | Activity = c(1,1,1)) 48 | ) 49 | 50 | # Create a sample meta_network 51 | meta_network <- data.frame(source = c("A", "B", "D"), 52 | target = c("D", "D", "F"), 53 | interaction_type = c(1, 1, 1)) 54 | 55 | # Define node_signatures and duplicated_parents 56 | node_signatures <- list("A" = "parent_of_D1","B" = "parent_of_D1","D" = "parent_F1") 57 | duplicated_parents <- c("A" = "parent_of_D1","B" = "parent_of_D1") 58 | 59 | # Decompress the solution network 60 | result <- decompress_solution_network(formatted_res, meta_network, node_signatures, duplicated_parents) 61 | decompressed_network <- result[[1]] 62 | attribute_table <- result[[2]] 63 | 64 | } 65 | -------------------------------------------------------------------------------- /man/decoupleRnival.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/decoupleRnival.R 3 | \name{decoupleRnival} 4 | \alias{decoupleRnival} 5 | \title{DecoupleRnival} 6 | \usage{ 7 | decoupleRnival( 8 | upstream_input = NULL, 9 | downstream_input, 10 | meta_network, 11 | n_layers, 12 | n_perm = 1000, 13 | downstream_cutoff = 0, 14 | statistic = "norm_wmean" 15 | ) 16 | } 17 | \arguments{ 18 | \item{upstream_input}{A named vector with up_stream nodes and their corresponding activity.} 19 | 20 | \item{downstream_input}{A named vector with down_stream nodes and their corresponding activity.} 21 | 22 | \item{meta_network}{A network data frame containing signed directed prior knowledge of molecular interactions.} 23 | 24 | \item{n_layers}{The number of layers that will be propagated upstream.} 25 | 26 | \item{n_perm}{The number of permutations to use in decoupleR's algorithm.} 27 | 28 | \item{downstream_cutoff}{If downstream measurments should be included above a given threshold} 29 | 30 | \item{statistic}{the decoupleR stat to consider: "wmean", "norm_wmean", or "ulm"} 31 | } 32 | \value{ 33 | A data frame containing the score of the nodes upstream of the 34 | downstream input based on the iterative propagation 35 | } 36 | \description{ 37 | Iteratively propagate downstream input activity through a signed directed network 38 | using the weighted mean enrichment score from decoupleR package 39 | } 40 | \examples{ 41 | # Example input data 42 | upstream_input <- c("A" = 1, "B" = -1, "C" = 0.5) 43 | downstream_input <- c("D" = 2, "E" = -1.5) 44 | meta_network <- data.frame( 45 | source = c("A", "A", "B", "C", "C", "D", "E"), 46 | target = c("B", "C", "D", "E", "D", "B", "A"), 47 | sign = c(1, -1, -1, 1, -1, -1, 1) 48 | ) 49 | 50 | # Run the function with the example input data 51 | result <- decoupleRnival(upstream_input, downstream_input, meta_network, n_layers = 2, n_perm = 100) 52 | 53 | # View the results 54 | print(result) 55 | } 56 | -------------------------------------------------------------------------------- /man/default_CARNIVAL_options.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/default_CARNIVAL_options.R 3 | \name{default_CARNIVAL_options} 4 | \alias{default_CARNIVAL_options} 5 | \title{Setting Default CARNIVAL Options} 6 | \usage{ 7 | default_CARNIVAL_options(solver = NULL) 8 | } 9 | \arguments{ 10 | \item{solver}{one of `cplex` (recommended, but require 3rd party tool), `cbc` (also require 3rd party tool) or `lpSolve` (only for small networks)} 11 | } 12 | \value{ 13 | returns a list with all possible options implemented in CARNIVAL. 14 | see the documentation on \code{\link[CARNIVAL]{runCARNIVAL}}. 15 | } 16 | \description{ 17 | Returns the default CARNIVAL options as a list. You can modify the elements 18 | of the list and then use it as an argument in \code{\link{run_COSMOS_metabolism_to_signaling}} or 19 | \code{\link{run_COSMOS_signaling_to_metabolism}}. 20 | If you choose CPLEX or CBC, you must modify then the solverPath field and point to 21 | the CPLEX/CBC executable (See Details). 22 | } 23 | \details{ 24 | COSMOS is dependent on CARNIVAL for exhibiting the signalling pathway optimisation. 25 | CARNIVAL requires the interactive version of IBM Cplex, Gurobi or CBC-COIN solver 26 | as the network optimiser. The IBM ILOG Cplex is freely available through 27 | Academic Initiative \href{https://www.ibm.com/products/ilog-cplex-optimization-studio}{here}. 28 | Gurobi license is also free for academics, request a license following instructions 29 | \href{https://www.gurobi.com/downloads/end-user-license-agreement-academic/}{here}. 30 | The \href{https://projects.coin-or.org/Cbc}{CBC} solver is open source and freely 31 | available for any user, but has a significantly lower performance than CPLEX or 32 | Gurobi. Obtain CBC executable directly usable for cosmos 33 | \href{https://ampl.com/products/solvers/open-source/#cbc}{here}. Alternatively for 34 | small networks, users can rely on the freely available 35 | \href{https://cran.r-project.org/web/packages/lpSolve/index.html}{lpSolve R-package}, 36 | which is automatically installed with the package. 37 | } 38 | \examples{ 39 | # load and change default options: 40 | my_options = default_CARNIVAL_options(solver = "cplex") 41 | 42 | my_options$solverPath = "/Applications/CPLEX_Studio128/cplex/bin/x86-64_osx/cplex" 43 | my_options$threads = 2 44 | my_options$timelimit = 3600*15 45 | } 46 | -------------------------------------------------------------------------------- /man/display_node_neighboorhood.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/display_node_neighboorhood.R 3 | \name{display_node_neighboorhood} 4 | \alias{display_node_neighboorhood} 5 | \title{display_node_neighboorhood} 6 | \usage{ 7 | display_node_neighboorhood(central_node, sif, att, n = 100) 8 | } 9 | \arguments{ 10 | \item{central_node}{character or character vector; node ID(s) around which a 11 | network will be branched out untill meansurments and input are reached} 12 | 13 | \item{sif}{df; COSMOS network solution in sif format like the first list 14 | element returned by the format_cosmos_res function} 15 | 16 | \item{att}{df; attributes of the nodes of the COMSOS network solution like 17 | the second list element returned by the format_cosmos_res function} 18 | 19 | \item{n}{numeric; maximum number of steps in the network to look for inputs 20 | and measurments} 21 | } 22 | \value{ 23 | a visnetwork object 24 | } 25 | \description{ 26 | display input and measurements within n steps of a given set of nodes 27 | } 28 | \examples{ 29 | CARNIVAL_options <- cosmosR::default_CARNIVAL_options("lpSolve") 30 | data(toy_network) 31 | data(toy_signaling_input) 32 | data(toy_metabolic_input) 33 | data(toy_RNA) 34 | test_for <- preprocess_COSMOS_signaling_to_metabolism(meta_network = toy_network, 35 | signaling_data = toy_signaling_input, 36 | metabolic_data = toy_metabolic_input, 37 | diff_expression_data = toy_RNA, 38 | maximum_network_depth = 15, 39 | remove_unexpressed_nodes = TRUE, 40 | CARNIVAL_options = CARNIVAL_options 41 | ) 42 | test_result_for <- run_COSMOS_signaling_to_metabolism(data = test_for, 43 | CARNIVAL_options = CARNIVAL_options) 44 | test_result_for <- format_COSMOS_res(test_result_for) 45 | network_plot <- display_node_neighboorhood(central_node = 'MYC', 46 | sif = test_result_for[[1]], 47 | att = test_result_for[[2]], 48 | n = 7) 49 | network_plot 50 | } 51 | -------------------------------------------------------------------------------- /man/extract_nodes_for_ORA.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/support_ORA.R 3 | \name{extract_nodes_for_ORA} 4 | \alias{extract_nodes_for_ORA} 5 | \title{Extract COSMOS nodes for ORA analysis} 6 | \usage{ 7 | extract_nodes_for_ORA(sif, att) 8 | } 9 | \arguments{ 10 | \item{sif}{df; COSMOS network solution in sif format like the first list 11 | element returned by the format_cosmos_res function} 12 | 13 | \item{att}{df; attributes of the nodes of the COMSOS network solution like 14 | the second list element returned by the format_cosmos_res function} 15 | } 16 | \value{ 17 | List with 2 objects: the success and the background genes 18 | } 19 | \description{ 20 | Function to extract the nodes that appear in the COSMOS output network and 21 | the background genes (all genes present in the prior knowledge network) 22 | } 23 | \examples{ 24 | CARNIVAL_options <- cosmosR::default_CARNIVAL_options("lpSolve") 25 | data(toy_network) 26 | data(toy_signaling_input) 27 | data(toy_metabolic_input) 28 | data(toy_RNA) 29 | test_for <- preprocess_COSMOS_signaling_to_metabolism(meta_network = toy_network, 30 | signaling_data = toy_signaling_input, 31 | metabolic_data = toy_metabolic_input, 32 | diff_expression_data = toy_RNA, 33 | maximum_network_depth = 15, 34 | remove_unexpressed_nodes = TRUE, 35 | CARNIVAL_options = CARNIVAL_options 36 | ) 37 | test_result_for <- run_COSMOS_signaling_to_metabolism(data = test_for, 38 | CARNIVAL_options = CARNIVAL_options) 39 | test_result_for <- format_COSMOS_res(test_result_for) 40 | extreacted_nodes <- extract_nodes_for_ORA( 41 | sif = test_result_for[[1]], 42 | att = test_result_for[[2]] 43 | ) 44 | } 45 | -------------------------------------------------------------------------------- /man/figures/graphical_abstract.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/man/figures/graphical_abstract.png -------------------------------------------------------------------------------- /man/figures/intro_data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/man/figures/intro_data.png -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/man/figures/logo.png -------------------------------------------------------------------------------- /man/figures/summary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/man/figures/summary.png -------------------------------------------------------------------------------- /man/filter_incohrent_TF_target.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/decoupleRnival.R 3 | \name{filter_incohrent_TF_target} 4 | \alias{filter_incohrent_TF_target} 5 | \title{filter_incohrent_TF_target} 6 | \usage{ 7 | filter_incohrent_TF_target( 8 | decouplRnival_res, 9 | TF_reg_net, 10 | meta_network, 11 | RNA_input 12 | ) 13 | } 14 | \arguments{ 15 | \item{decouplRnival_res}{A data frame resulting from the decoupleRnival function.} 16 | 17 | \item{TF_reg_net}{A data frame containing prior knowledge of transcription factor (TF) regulatory interactions.} 18 | 19 | \item{meta_network}{A network data frame containing signed directed prior knowledge of molecular interactions.} 20 | 21 | \item{RNA_input}{A named vector containing differential gene expression data.} 22 | } 23 | \value{ 24 | A network data frame containing the genes that are not incoherently regulated by TFs. 25 | } 26 | \description{ 27 | Filters incoherent target genes from a regulatory network based on a decoupling analysis 28 | of upstream and downstream gene expression. 29 | } 30 | \examples{ 31 | # Example input data 32 | upstream_input <- c("A" = 1, "B" = -1, "C" = 0.5) 33 | downstream_input <- c("D" = 2, "E" = -1.5) 34 | meta_network <- data.frame( 35 | source = c("A", "A", "B", "C", "C", "D", "E"), 36 | target = c("B", "D", "D", "E", "D", "B", "A"), 37 | interaction = c(-1, 1, -1, 1, -1, -1, 1) 38 | ) 39 | RNA_input <- c("A" = 1, "B" = -1, "C" = 5, "D" = -0.7, "E" = -0.3) 40 | 41 | TF_reg_net <- data.frame( 42 | source = c("B"), 43 | target = c("D"), 44 | mor = c(-1) 45 | ) 46 | 47 | # Run the decoupleRnival function to get the upstream influence scores 48 | upstream_scores <- decoupleRnival(upstream_input, downstream_input, meta_network, n_layers = 2, n_perm = 100) 49 | 50 | filtered_network <- filter_incohrent_TF_target(upstream_scores, TF_reg_net, meta_network, RNA_input) 51 | 52 | print(filtered_network) 53 | } 54 | -------------------------------------------------------------------------------- /man/format_COSMOS_res.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/format_COSMOS_results.R 3 | \name{format_COSMOS_res} 4 | \alias{format_COSMOS_res} 5 | \title{format_COSMOS_res} 6 | \usage{ 7 | format_COSMOS_res(cosmos_res, metab_mapping = NULL) 8 | } 9 | \arguments{ 10 | \item{cosmos_res}{results of COSMOS run} 11 | 12 | \item{metab_mapping}{a named vector with HMDB Ids as names and desired metabolite names as values.} 13 | } 14 | \value{ 15 | list with network and attribute tables. 16 | } 17 | \description{ 18 | formats the network with readable names 19 | } 20 | -------------------------------------------------------------------------------- /man/format_LR_ressource.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/support_decoupleR.R 3 | \name{format_LR_ressource} 4 | \alias{format_LR_ressource} 5 | \title{Format Ligand-Receptor Resource} 6 | \usage{ 7 | format_LR_ressource(ligrec_ressource) 8 | } 9 | \arguments{ 10 | \item{ligrec_ressource}{A data frame representing the ligand-receptor resource with columns for source and target gene symbols.} 11 | } 12 | \value{ 13 | A data frame containing the formatted ligand-receptor gene set with columns: 14 | \item{gene}{The gene symbol from the ligand-receptor pairs.} 15 | \item{set}{The set identifier combining source and target gene symbols.} 16 | \item{mor}{Default value set to 1 for all entries.} 17 | \item{likelihood}{Default value set to 1 for all entries.} 18 | } 19 | \description{ 20 | This function formats a ligand-receptor resource by creating a gene set 21 | with source-target pairs, converting it to a long format, and adding 22 | default values for 'mor' and 'likelihood'. 23 | } 24 | \examples{ 25 | # Create a sample ligand-receptor resource 26 | ligrec_ressource <- data.frame(source_genesymbol = c("L1", "L2"), 27 | target_genesymbol = c("R1", "R2")) 28 | 29 | # Format the ligand-receptor resource 30 | formatted_geneset <- format_LR_ressource(ligrec_ressource) 31 | 32 | } 33 | -------------------------------------------------------------------------------- /man/get_moon_scoring_network.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/decoupleRnival.R 3 | \name{get_moon_scoring_network} 4 | \alias{get_moon_scoring_network} 5 | \title{Get Moon Scoring Network} 6 | \usage{ 7 | get_moon_scoring_network( 8 | upstream_node, 9 | meta_network, 10 | moon_scores, 11 | keep_upstream_node_peers = F 12 | ) 13 | } 14 | \arguments{ 15 | \item{upstream_node}{The node from which the network analysis starts.} 16 | 17 | \item{meta_network}{The complete network data.} 18 | 19 | \item{moon_scores}{Scores associated with each node in the network.} 20 | 21 | \item{keep_upstream_node_peers}{Logical; whether to keep peers of the upstream node. Default is FALSE.} 22 | } 23 | \value{ 24 | A list with two elements: 25 | - `SIF`: A data frame representing the filtered meta network. 26 | - `ATT`: A data frame representing the updated moon scores. 27 | } 28 | \description{ 29 | This function analyzes a given meta network based on moon scores and an upstream node. 30 | It filters and processes the network by controlling and observing neighbours 31 | according to specified parameters. The function returns a list containing a filtered 32 | network and updated moon scores. 33 | } 34 | \examples{ 35 | # Example usage (requires appropriate data structures for meta_network and moon_scores) 36 | # result <- get_moon_scoring_network(upstream_node, meta_network, moon_scores) 37 | 38 | } 39 | -------------------------------------------------------------------------------- /man/gmt_to_dataframe.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/support_ORA.R 3 | \name{gmt_to_dataframe} 4 | \alias{gmt_to_dataframe} 5 | \title{Convert gmt file to data frame} 6 | \usage{ 7 | gmt_to_dataframe(gmtfile) 8 | } 9 | \arguments{ 10 | \item{gmtfile}{a full path name of the gmt file to be converted} 11 | } 12 | \value{ 13 | a two column data frame where the first column corresponds to omic 14 | features and the second column to associated terms (pathways). 15 | } 16 | \description{ 17 | This function is designed to convert a gmt file (gene set file from MSigDB) 18 | into a two column data frame where the first column corresponds to omic 19 | features (genes) and the second column to associated terms (pathway the gene 20 | belongs to). One gene can belong to several pathways. 21 | } 22 | -------------------------------------------------------------------------------- /man/load_tf_regulon_dorothea.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/load_tf_regulon_dorothea.R 3 | \name{load_tf_regulon_dorothea} 4 | \alias{load_tf_regulon_dorothea} 5 | \title{load transcription factor regulon} 6 | \usage{ 7 | load_tf_regulon_dorothea(confidence = c("A", "B", "C")) 8 | } 9 | \arguments{ 10 | \item{confidence}{strong vector (by default: c("A","B","C")). Subset of \{A, B, 11 | C, D, E\}. See the `dorothea` for the meaning of confidence levels. 12 | package for further details.} 13 | } 14 | \value{ 15 | returns a PKN of a form of a data table. Each row is an interaction. 16 | Columns names are: 17 | 18 | - `tf` transcription factor 19 | - `confidence` class of confidence 20 | - `target` target gene 21 | - `sign` indicates if interaction is up (1) or down-regulation (-1). 22 | } 23 | \description{ 24 | load the transcription factors from \code{DOROTHEA} package and converts 25 | gene symbols to EntrezID using org.Hs.eg.db 26 | } 27 | \examples{ 28 | load_tf_regulon_dorothea() 29 | } 30 | -------------------------------------------------------------------------------- /man/make_heatmap_color_palette.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/support_pheatmap.R 3 | \name{make_heatmap_color_palette} 4 | \alias{make_heatmap_color_palette} 5 | \title{Create Heatmap Color Palette} 6 | \usage{ 7 | make_heatmap_color_palette(my_matrix) 8 | } 9 | \arguments{ 10 | \item{my_matrix}{A numeric matrix for which the heatmap color palette is to be generated.} 11 | } 12 | \value{ 13 | A character vector of colors representing the heatmap color palette based on the input matrix values. 14 | } 15 | \description{ 16 | This function generates a color palette suitable for heatmaps based on the values in a matrix. It uses the `createLinearColors` function to generate separate color gradients for positive and negative values. 17 | } 18 | \examples{ 19 | # Create a sample matrix 20 | my_matrix <- matrix(c(-3, -1, 0, 1, 3), nrow = 1) 21 | 22 | # Generate heatmap color palette 23 | heatmap_palette <- make_heatmap_color_palette(my_matrix) 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/meta_network.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/meta_network.R 3 | \docType{data} 4 | \name{meta_network} 5 | \alias{meta_network} 6 | \title{Meta Prior Knowledge Network} 7 | \format{ 8 | An object of class \dQuote{\code{tibble}} with 117065 rows 9 | (interactions) and three variables: 10 | \describe{ 11 | \item{\code{source}}{Source node, either metabolite or protein} 12 | \item{\code{interaction}}{Type of interaction, 1 = Activation, -1 = Inhibition} 13 | \item{\code{target}}{Target node, either metabolite or protein} 14 | A detailed description of the identifier formatting can be found under 15 | \url{https://metapkn.omnipathdb.org/00__README.txt}. 16 | } 17 | } 18 | \source{ 19 | The network is available in Omnipath: 20 | \url{https://metapkn.omnipathdb.org/metapkn__20200122.txt}, the scripts 21 | used for the build of the network are available under 22 | \url{https://github.com/saezlab/Meta_PKN}. 23 | } 24 | \usage{ 25 | data(meta_network) 26 | } 27 | \description{ 28 | Comprehensive Prior Knowledge Network (PKN), which combines signaling and 29 | metabolic interaction networks. The network was constructed using the Recon3D 30 | and STITCH metabolic networks as well as the signaling network from 31 | OmniPath. 32 | } 33 | \examples{ 34 | data(meta_network) 35 | 36 | } 37 | \references{ 38 | { 39 | Dugourd, A., Kuppe, C. and Sciacovelli, M. et. al. (2021) \emph{Molecular 40 | Systems Biology}. \bold{17}, e9730. 41 | } 42 | } 43 | \keyword{datasets} 44 | -------------------------------------------------------------------------------- /man/meta_network_cleanup.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/decoupleRnival.R 3 | \name{meta_network_cleanup} 4 | \alias{meta_network_cleanup} 5 | \title{meta_network_cleanup} 6 | \usage{ 7 | meta_network_cleanup(meta_network) 8 | } 9 | \arguments{ 10 | \item{meta_network}{A data frame with columns 'source', 'interaction', and 'target'.} 11 | } 12 | \value{ 13 | A cleaned up meta network data frame. 14 | } 15 | \description{ 16 | This function cleans up a meta network data frame by removing self-interactions, 17 | calculating the mean interaction values for duplicated source-target pairs, and 18 | keeping only interactions with values of 1 or -1. 19 | } 20 | \examples{ 21 | # Create a meta network data frame 22 | example_meta_network <- data.frame( 23 | source = c("A", "B", "C", "D", "A", "B", "C", "D", "A"), 24 | interaction = c(1, 1, 1, -1, 1, -1, 1, -1, 1), 25 | target = c("B", "C", "D", "A", "C", "D", "A", "B", "B") 26 | ) 27 | 28 | # Clean up the example meta network 29 | cleaned_meta_network <- meta_network_cleanup(example_meta_network) 30 | print(cleaned_meta_network) 31 | 32 | } 33 | -------------------------------------------------------------------------------- /man/moon.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/decoupleRnival.R 3 | \name{moon} 4 | \alias{moon} 5 | \title{moon} 6 | \usage{ 7 | moon( 8 | upstream_input = NULL, 9 | downstream_input, 10 | meta_network, 11 | n_layers, 12 | n_perm = 1000, 13 | downstream_cutoff = 0, 14 | statistic = "ulm", 15 | return_levels = F 16 | ) 17 | } 18 | \arguments{ 19 | \item{upstream_input}{A named vector with up_stream nodes and their corresponding activity.} 20 | 21 | \item{downstream_input}{A named vector with down_stream nodes and their corresponding activity.} 22 | 23 | \item{meta_network}{A network data frame containing signed directed prior knowledge of molecular interactions.} 24 | 25 | \item{n_layers}{The number of layers that will be propagated upstream.} 26 | 27 | \item{n_perm}{The number of permutations to use in decoupleR's algorithm.} 28 | 29 | \item{downstream_cutoff}{If downstream measurments should be included above a given threshold} 30 | 31 | \item{statistic}{the decoupleR stat to consider: "wmean", "norm_wmean", or "ulm"} 32 | 33 | \item{return_levels}{true or false, if true the layers that the protein belongs to will be returned alongside the scores} 34 | } 35 | \value{ 36 | A data frame containing the score of the nodes upstream of the 37 | downstream input based on the iterative propagation 38 | } 39 | \description{ 40 | Iteratively propagate downstream input activity through a signed directed network 41 | using the weighted mean enrichment score from decoupleR package 42 | } 43 | \examples{ 44 | # Example input data 45 | upstream_input <- c("A" = 1, "B" = -1, "C" = 0.5) 46 | downstream_input <- c("D" = 2, "E" = -1.5) 47 | meta_network <- data.frame( 48 | source = c("A", "A", "B", "C", "C", "D", "E"), 49 | target = c("B", "C", "D", "E", "D", "B", "A"), 50 | sign = c(1, -1, -1, 1, -1, -1, 1) 51 | ) 52 | 53 | # Run the function with the example input data 54 | result <- moon(upstream_input, downstream_input, meta_network, n_layers = 2, statistic = "wmean") 55 | 56 | # View the results 57 | print(result) 58 | } 59 | -------------------------------------------------------------------------------- /man/prepare_metab_inputs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/prepare_metab_inputs.R 3 | \name{prepare_metab_inputs} 4 | \alias{prepare_metab_inputs} 5 | \title{add metabolic compartment and metab__ prefix to metabolite IDs} 6 | \usage{ 7 | prepare_metab_inputs(metab_input, compartment_codes) 8 | } 9 | \arguments{ 10 | \item{metab_input}{a named vector with matebolic statistics as inputs and metabolite identifiers as names} 11 | 12 | \item{compartment_codes}{a character vector, the desired compartment codes to be added. Possible values are "r", "c", "e", "x", "m", "l", "n" and "g"} 13 | } 14 | \value{ 15 | a named vector with the compartment code and prefixed added to the names 16 | } 17 | \description{ 18 | This function adds metabolic compartments to the metabolic identifiers provided by the user. 19 | } 20 | -------------------------------------------------------------------------------- /man/preprocess_COSMOS_metabolism_to_signaling.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/preprocess_COSMOS_metabolism_to_signaling.R 3 | \name{preprocess_COSMOS_metabolism_to_signaling} 4 | \alias{preprocess_COSMOS_metabolism_to_signaling} 5 | \title{Preprocess COSMOS Inputs For Metabolism to Signaling} 6 | \usage{ 7 | preprocess_COSMOS_metabolism_to_signaling( 8 | meta_network = meta_network, 9 | tf_regulon = load_tf_regulon_dorothea(), 10 | signaling_data, 11 | metabolic_data, 12 | diff_expression_data = NULL, 13 | diff_exp_threshold = 1, 14 | maximum_network_depth = 8, 15 | expressed_genes = NULL, 16 | remove_unexpressed_nodes = TRUE, 17 | filter_tf_gene_interaction_by_optimization = TRUE, 18 | CARNIVAL_options = default_CARNIVAL_options("lpSolve") 19 | ) 20 | } 21 | \arguments{ 22 | \item{meta_network}{prior knowledge network (PKN). A PKN released with COSMOS 23 | and derived from Omnipath, STITCHdb and Recon3D can be used. See details on 24 | the data \code{\link{meta_network}}.} 25 | 26 | \item{tf_regulon}{collection of transcription factor - target interactions. 27 | A default collection from dorothea can be obtained by the 28 | \code{\link{load_tf_regulon_dorothea}} function.} 29 | 30 | \item{signaling_data}{numerical vector, where names are signaling nodes 31 | in the PKN and values are from \{1, 0, -1\}. Continuous data will be 32 | discretized using the \code{\link{sign}} function.} 33 | 34 | \item{metabolic_data}{numerical vector, where names are metabolic nodes 35 | in the PKN and values are continuous values that represents log2 fold change 36 | or t-values from a differential analysis. These values are compared to 37 | the simulation results (simulated nodes can take value -1, 0 or 1)} 38 | 39 | \item{diff_expression_data}{(optional) numerical vector that represents the 40 | results of a differential gene expression analysis. Names are gene 41 | names using gene symbole and values are log fold change or 42 | t-values. We use the \dQuote{\code{diff_exp_threshold}} parameter to decide 43 | which genes changed significantly. Genes with NA values are considered none 44 | expressed and they will be removed from the TF-gene expression interactions.} 45 | 46 | \item{diff_exp_threshold}{threshold parameter (default 1) used to binarize 47 | the values of \dQuote{\code{diff_expression_data}}.} 48 | 49 | \item{maximum_network_depth}{integer > 0 (default: 8). Nodes that are further 50 | than \dQuote{\code{maximum_network_depth}} steps from the signaling nodes on 51 | the directed graph of the PKN are considered non-reachable and are removed.} 52 | 53 | \item{expressed_genes}{character vector. Names of nodes that are expressed. By 54 | default we consider all the nodes that appear in \code{diff_expression_data} with 55 | a numeric value (i.e. nodes with NA are removed)} 56 | 57 | \item{remove_unexpressed_nodes}{if TRUE (default) removes nodes from the PKN 58 | that are not expressed, see input \dQuote{\code{expressed_genes}}.} 59 | 60 | \item{filter_tf_gene_interaction_by_optimization}{(default:TRUE), if TRUE then runs 61 | a network optimization that estimates TF activity not included in the inputs 62 | and checks the consistency between the estimated activity and change in gene 63 | expression. Removes interactions where TF and gene expression are inconsistent} 64 | 65 | \item{CARNIVAL_options}{list that controls the options of CARNIVAL. See details 66 | in \code{\link{default_CARNIVAL_options}}.} 67 | } 68 | \value{ 69 | cosmos_data object with the following fields: 70 | \describe{ 71 | \item{\code{meta_network}}{Filtered PKN} 72 | \item{\code{tf_regulon}}{TF - target regulatory network} 73 | \item{\code{signaling_data_bin}}{Binarised signaling data} 74 | \item{\code{metabolic_data}}{Metabolomics data} 75 | \item{\code{diff_expression_data_bin}}{Binarized gene expression data} 76 | \item{\code{optimized_network}}{Initial optimized network if 77 | \code{filter_tf_gene_interaction_by_optimization is TRUE}} 78 | } 79 | } 80 | \description{ 81 | Runs checks on the input data and simplifies the prior knowledge network. 82 | Simplification includes the removal of (1) nodes that are not reachable from 83 | signaling nodes and (2) interactions between transcription factors and target 84 | genes if the target gene does not respond or the response is contradictory 85 | with the change in the transcription factor activity. 86 | Optionally, further TF activities are estimated via network optimization via 87 | CARNIVAL and the interactions between TF and genes are filtered again. 88 | } 89 | \examples{ 90 | data(toy_network) 91 | data(toy_signaling_input) 92 | data(toy_metabolic_input) 93 | data(toy_RNA) 94 | test_back <- preprocess_COSMOS_metabolism_to_signaling( 95 | meta_network = toy_network, 96 | signaling_data = toy_signaling_input, 97 | metabolic_data = toy_metabolic_input, 98 | diff_expression_data = toy_RNA, 99 | maximum_network_depth = 15, 100 | remove_unexpressed_nodes = TRUE, 101 | CARNIVAL_options = default_CARNIVAL_options("lpSolve") 102 | ) 103 | } 104 | \seealso{ 105 | \code{\link{meta_network}} for meta PKN, 106 | \code{\link{load_tf_regulon_dorothea}} for tf regulon, 107 | \code{\link[CARNIVAL]{runCARNIVAL}}. 108 | } 109 | -------------------------------------------------------------------------------- /man/preprocess_COSMOS_signaling_to_metabolism.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/preprocess_COSMOS_signaling_to_metabolism.R 3 | \name{preprocess_COSMOS_signaling_to_metabolism} 4 | \alias{preprocess_COSMOS_signaling_to_metabolism} 5 | \title{Preprocess COSMOS Inputs For Signaling to Metabolism} 6 | \usage{ 7 | preprocess_COSMOS_signaling_to_metabolism( 8 | meta_network = meta_network, 9 | tf_regulon = load_tf_regulon_dorothea(), 10 | signaling_data, 11 | metabolic_data, 12 | diff_expression_data = NULL, 13 | diff_exp_threshold = 1, 14 | maximum_network_depth = 8, 15 | expressed_genes = NULL, 16 | remove_unexpressed_nodes = TRUE, 17 | filter_tf_gene_interaction_by_optimization = TRUE, 18 | CARNIVAL_options = default_CARNIVAL_options("lpSolve") 19 | ) 20 | } 21 | \arguments{ 22 | \item{meta_network}{prior knowledge network (PKN). A PKN released with COSMOS 23 | and derived from Omnipath, STITCHdb and Recon3D can be used. See details on 24 | the data \code{\link{meta_network}}.} 25 | 26 | \item{tf_regulon}{collection of transcription factor - target interactions. 27 | A default collection from dorothea can be obtained by the 28 | \code{\link{load_tf_regulon_dorothea}} function.} 29 | 30 | \item{signaling_data}{numerical vector, where names are signaling nodes 31 | in the PKN and values are from \{1, 0, -1\}. Continuous data will be 32 | discretized using the \code{\link{sign}} function.} 33 | 34 | \item{metabolic_data}{numerical vector, where names are metabolic nodes 35 | in the PKN and values are continuous values that represents log2 fold change 36 | or t-values from a differential analysis. These values are compared to 37 | the simulation results (simulated nodes can take value -1, 0 or 1)} 38 | 39 | \item{diff_expression_data}{(optional) numerical vector that represents the 40 | results of a differential gene expression analysis. Names are gene 41 | names using gene symbole and values are log fold change or 42 | t-values. We use the \dQuote{\code{diff_exp_threshold}} parameter to decide 43 | which genes changed significantly. Genes with NA values are considered none 44 | expressed and they will be removed from the TF-gene expression interactions.} 45 | 46 | \item{diff_exp_threshold}{threshold parameter (default 1) used to binarize 47 | the values of \dQuote{\code{diff_expression_data}}.} 48 | 49 | \item{maximum_network_depth}{integer > 0 (default: 8). Nodes that are further 50 | than \dQuote{\code{maximum_network_depth}} steps from the signaling nodes on 51 | the directed graph of the PKN are considered non-reachable and are removed.} 52 | 53 | \item{expressed_genes}{character vector. Names of nodes that are expressed. By 54 | default we consider all the nodes that appear in \code{diff_expression_data} with 55 | a numeric value (i.e. nodes with NA are removed)} 56 | 57 | \item{remove_unexpressed_nodes}{if TRUE (default) removes nodes from the PKN 58 | that are not expressed, see input \dQuote{\code{expressed_genes}}.} 59 | 60 | \item{filter_tf_gene_interaction_by_optimization}{(default:TRUE), if TRUE then runs 61 | a network optimization that estimates TF activity not included in the inputs 62 | and checks the consistency between the estimated activity and change in gene 63 | expression. Removes interactions where TF and gene expression are inconsistent} 64 | 65 | \item{CARNIVAL_options}{list that controls the options of CARNIVAL. See details 66 | in \code{\link{default_CARNIVAL_options}}.} 67 | } 68 | \value{ 69 | cosmos_data object with the following fields: 70 | \describe{ 71 | \item{\code{meta_network}}{Filtered PKN} 72 | \item{\code{tf_regulon}}{TF - target regulatory network} 73 | \item{\code{signaling_data_bin}}{Binarised signaling data} 74 | \item{\code{metabolic_data}}{Metabolomics data} 75 | \item{\code{diff_expression_data_bin}}{Binarized gene expression data} 76 | \item{\code{optimized_network}}{Initial optimized network if 77 | \code{filter_tf_gene_interaction_by_optimization is TRUE}} 78 | } 79 | } 80 | \description{ 81 | Runs checks on the input data and simplifies the prior knowledge network. 82 | Simplification includes the removal of (1) nodes that are not reachable from 83 | signaling nodes and (2) interactions between transcription factors and target 84 | genes if the target gene does not respond or the response is contradictory 85 | with the change in the transcription factor activity. 86 | Optionally, further TF activities are estimated via network optimization via 87 | CARNIVAL and the interactions between TF and genes are filtered again. 88 | } 89 | \examples{ 90 | data(toy_network) 91 | data(toy_signaling_input) 92 | data(toy_metabolic_input) 93 | data(toy_RNA) 94 | test_for <- preprocess_COSMOS_signaling_to_metabolism(meta_network = toy_network, 95 | signaling_data = toy_signaling_input, 96 | metabolic_data = toy_metabolic_input, 97 | diff_expression_data = toy_RNA, 98 | maximum_network_depth = 15, 99 | remove_unexpressed_nodes = TRUE, 100 | CARNIVAL_options = default_CARNIVAL_options("lpSolve")) 101 | } 102 | \seealso{ 103 | \code{\link{meta_network}} for meta PKN, 104 | \code{\link{load_tf_regulon_dorothea}} for tf regulon, 105 | \code{\link[CARNIVAL]{runCARNIVAL}}. 106 | } 107 | -------------------------------------------------------------------------------- /man/print.cosmos_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cosmos_data.R 3 | \name{print.cosmos_data} 4 | \alias{print.cosmos_data} 5 | \title{Print Cosmos Data Summary 6 | Print a summary of cosmos data.} 7 | \usage{ 8 | \method{print}{cosmos_data}(x, ...) 9 | } 10 | \arguments{ 11 | \item{x}{\code{\link{cosmos_data}} object. Use the 12 | \code{\link{preprocess_COSMOS_signaling_to_metabolism}} or 13 | \code{\link{preprocess_COSMOS_metabolism_to_signaling}} functions to 14 | create one.} 15 | 16 | \item{...}{Further print arguments passed to or from other methods.} 17 | } 18 | \value{ 19 | input (invisible) 20 | } 21 | \description{ 22 | Print Cosmos Data Summary 23 | Print a summary of cosmos data. 24 | } 25 | \seealso{ 26 | \code{\link[base]{print}}, \code{\link{cosmos_data}} 27 | } 28 | -------------------------------------------------------------------------------- /man/reduce_solution_network.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/decoupleRnival.R 3 | \name{reduce_solution_network} 4 | \alias{reduce_solution_network} 5 | \title{reduce_solution_network} 6 | \usage{ 7 | reduce_solution_network( 8 | decoupleRnival_res, 9 | meta_network, 10 | cutoff, 11 | upstream_input, 12 | RNA_input = NULL, 13 | n_steps = 10 14 | ) 15 | } 16 | \arguments{ 17 | \item{decoupleRnival_res}{A data frame resulting from the decoupleRnival function.} 18 | 19 | \item{meta_network}{A network data frame containing signed directed prior knowledge of molecular interactions.} 20 | 21 | \item{cutoff}{The consistency threshold for filtering edges from the solution network.} 22 | 23 | \item{upstream_input}{A named vector with up_stream nodes and their corresponding activity.} 24 | 25 | \item{RNA_input}{A named vector containing differential gene expression data.} 26 | 27 | \item{n_steps}{The maximum number of steps from upstream input nodes to include in the solution network.} 28 | } 29 | \value{ 30 | A list containing the solution network (SIF) and an attribute table (ATT) with gene expression data. 31 | } 32 | \description{ 33 | Reduces a solution network based on a decoupling analysis of upstream and downstream gene expression, 34 | by filtering out edges that do not meet a consistency threshold, and limiting the network to a 35 | certain number of steps from upstream input nodes. 36 | } 37 | \examples{ 38 | # Example input data 39 | upstream_input <- c("A" = 1, "B" = -1, "C" = 0.5) 40 | downstream_input <- c("D" = 2, "E" = -1.5) 41 | meta_network <- data.frame( 42 | source = c("A", "A", "B", "C", "C", "D", "E"), 43 | target = c("B", "D", "D", "E", "D", "B", "A"), 44 | interaction = c(-1, 1, -1, 1, -1, -1, 1) 45 | ) 46 | RNA_input <- c("A" = 1, "B" = -1, "C" = 5, "D" = 0.7, "E" = -0.3) 47 | 48 | # Run the decoupleRnival function to get the upstream influence scores 49 | upstream_scores <- decoupleRnival(upstream_input, downstream_input, meta_network, n_layers = 2, n_perm = 100) 50 | 51 | # Reduce the solution network based on the upstream influence scores 52 | reduced_network <- reduce_solution_network(upstream_scores, meta_network, 0.4, upstream_input, RNA_input, 3) 53 | 54 | # View the resulting solution network and attribute table 55 | print(reduced_network$SIF) 56 | print(reduced_network$ATT) 57 | } 58 | -------------------------------------------------------------------------------- /man/run_COSMOS_metabolism_to_signaling.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/run_COSMOS_metabolism_to_signaling.R 3 | \name{run_COSMOS_metabolism_to_signaling} 4 | \alias{run_COSMOS_metabolism_to_signaling} 5 | \title{run COSMOS metabolism to signaling} 6 | \usage{ 7 | run_COSMOS_metabolism_to_signaling( 8 | data, 9 | CARNIVAL_options = default_CARNIVAL_options("lpSolve") 10 | ) 11 | } 12 | \arguments{ 13 | \item{data}{\code{\link{cosmos_data}} object. Use the 14 | \code{\link{preprocess_COSMOS_metabolism_to_signaling}} function to create 15 | an instance.} 16 | 17 | \item{CARNIVAL_options}{List that controls the options of CARNIVAL. See details 18 | in \code{\link{default_CARNIVAL_options}}.} 19 | } 20 | \value{ 21 | List with the following elements: 22 | \describe{ 23 | \item{\code{weightedSIF}}{The averaged networks found by 24 | optimization in a format of a Simple Interaction network, i.e. each row 25 | codes an edge} 26 | \item{\code{N_networks}}{Number of solutions found by the 27 | optimization} 28 | \item{\code{nodesAttributes}}{Estimated node properties} 29 | \item{\code{individual_networks}}{List of optimial networks found} 30 | \item{\code{individual_networks_node_attributes}}{Node activity in each 31 | network} 32 | } 33 | } 34 | \description{ 35 | Runs COSMOS from metabolism to signaling. This function uses CARNIVAL to find 36 | a subset of the prior knowledge network based on optimization that (1) 37 | includes the most measured and input nodes and (2) which is in agreement with 38 | the data. Use \code{\link{preprocess_COSMOS_metabolism_to_signaling}} to 39 | prepare the the inputs, measurements and the prior knowledge network. 40 | } 41 | \examples{ 42 | data(toy_network) 43 | data(toy_signaling_input) 44 | data(toy_metabolic_input) 45 | data(toy_RNA) 46 | test_back <- preprocess_COSMOS_metabolism_to_signaling(meta_network = toy_network, 47 | signaling_data = toy_signaling_input, 48 | metabolic_data = toy_metabolic_input, 49 | diff_expression_data = toy_RNA, 50 | maximum_network_depth = 15, 51 | remove_unexpressed_nodes = TRUE, 52 | CARNIVAL_options = default_CARNIVAL_options("lpSolve")) 53 | 54 | test_result_back <- run_COSMOS_metabolism_to_signaling(data = test_back, 55 | CARNIVAL_options = default_CARNIVAL_options("lpSolve")) 56 | } 57 | \seealso{ 58 | \code{\link{preprocess_COSMOS_metabolism_to_signaling}}, 59 | \code{\link[CARNIVAL]{runCARNIVAL}}, \code{\link{cosmos_data}} 60 | } 61 | -------------------------------------------------------------------------------- /man/run_COSMOS_signaling_to_metabolism.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/run_COSMOS_signaling_to_metabolism.R 3 | \name{run_COSMOS_signaling_to_metabolism} 4 | \alias{run_COSMOS_signaling_to_metabolism} 5 | \title{run COSMOS signaling to metabolism} 6 | \usage{ 7 | run_COSMOS_signaling_to_metabolism( 8 | data, 9 | CARNIVAL_options = default_CARNIVAL_options("lpSolve") 10 | ) 11 | } 12 | \arguments{ 13 | \item{data}{\code{\link{cosmos_data}} object. Use the 14 | \code{\link{preprocess_COSMOS_signaling_to_metabolism}} function to create 15 | an instance.} 16 | 17 | \item{CARNIVAL_options}{List that controls the options of CARNIVAL. See 18 | details in \code{\link{default_CARNIVAL_options}}.} 19 | } 20 | \value{ 21 | List with the following elements: 22 | \describe{ 23 | \item{\code{weightedSIF}}{The averaged networks found by 24 | optimization in a format of a Simple Interaction network, i.e. each row 25 | codes an edge} 26 | \item{\code{N_networks}}{Number of solutions found by the 27 | optimization} 28 | \item{\code{nodesAttributes}}{Estimated node properties} 29 | \item{\code{individual_networks}}{List of optimial networks found} 30 | \item{\code{individual_networks_node_attributes}}{Node activity in each 31 | network} 32 | } 33 | } 34 | \description{ 35 | Runs COSMOS from signaling to metabolism. This function uses CARNIVAL to find 36 | a subset of the prior knowledge network based on optimisation that (1) 37 | includes the most measured and input nodes and (2) which is in agreement with 38 | the data. Use \code{\link{preprocess_COSMOS_signaling_to_metabolism}} to 39 | prepare inputs, measurements and prior knowledge network. 40 | } 41 | \examples{ 42 | data(toy_network) 43 | data(toy_signaling_input) 44 | data(toy_metabolic_input) 45 | data(toy_RNA) 46 | test_for <- preprocess_COSMOS_signaling_to_metabolism(meta_network = toy_network, 47 | signaling_data = toy_signaling_input, 48 | metabolic_data = toy_metabolic_input, 49 | diff_expression_data = toy_RNA, 50 | maximum_network_depth = 15, 51 | remove_unexpressed_nodes = TRUE, 52 | CARNIVAL_options = default_CARNIVAL_options("lpSolve")) 53 | 54 | test_result_for <- run_COSMOS_signaling_to_metabolism(data = test_for, 55 | CARNIVAL_options = default_CARNIVAL_options("lpSolve")) 56 | } 57 | \seealso{ 58 | \code{\link{preprocess_COSMOS_metabolism_to_signaling}}, 59 | \code{\link[CARNIVAL]{runCARNIVAL}}, \code{\link{cosmos_data}} 60 | } 61 | -------------------------------------------------------------------------------- /man/toy_RNA.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/toy_RNA.R 3 | \docType{data} 4 | \name{toy_RNA} 5 | \alias{toy_RNA} 6 | \title{Toy Input Transcription Data Set} 7 | \format{ 8 | An object of class \dQuote{\code{numeric}} containing the t-values of 9 | 9300 genes, which are named with gene symboles matching the toy network. 10 | } 11 | \source{ 12 | \url{https://github.com/saezlab/COSMOS_MSB/blob/main/data/RNA_ttop_tumorvshealthy.csv} 13 | } 14 | \usage{ 15 | data(toy_RNA) 16 | } 17 | \description{ 18 | This exemplary transcription data are the specific deregulated gene expression of the 786-O cell line from the NCI60 dataset. 19 | } 20 | \examples{ 21 | data(toy_RNA) 22 | 23 | } 24 | \references{ 25 | { 26 | Dugourd, A., Kuppe, C. and Sciacovelli, M. et. al. (2021) \emph{Molecular 27 | Systems Biology}. \bold{17}, e9730. 28 | } 29 | } 30 | \keyword{datasets} 31 | -------------------------------------------------------------------------------- /man/toy_metabolic_input.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/toy_metabolic_input.R 3 | \docType{data} 4 | \name{toy_metabolic_input} 5 | \alias{toy_metabolic_input} 6 | \title{Toy Metabolic Input Data} 7 | \format{ 8 | An object of class \dQuote{\code{numeric}} containing the t-values of 9 | 2 metabolites, which are named with metabolite HMDB Ids matching the 10 | toy network. 11 | } 12 | \source{ 13 | Subset of: 14 | \url{https://github.com/saezlab/COSMOS_MSB/blob/main/data/metab_input_COSMOS.csv} 15 | } 16 | \usage{ 17 | data(toy_metabolic_input) 18 | } 19 | \description{ 20 | This metabolic data are a subset from the metabolic measurements of the 786-O cell line from the NCI60 dataset. 21 | } 22 | \examples{ 23 | data(toy_metabolic_input) 24 | 25 | } 26 | \references{ 27 | { 28 | Dugourd, A., Kuppe, C. and Sciacovelli, M. et. al. (2021) \emph{Molecular 29 | Systems Biology}. \bold{17}, e9730. 30 | } 31 | } 32 | \keyword{datasets} 33 | -------------------------------------------------------------------------------- /man/toy_network.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/toy_network.R 3 | \docType{data} 4 | \name{toy_network} 5 | \alias{toy_network} 6 | \title{Toy Input Network} 7 | \format{ 8 | An object of class \dQuote{\code{data.frame}} with 19 rows 9 | (interactions) and three variables: 10 | \describe{ 11 | \item{\code{source}}{Source node, either metabolite or protein} 12 | \item{\code{interaction}}{Type of interaction, 1 = Activation, -1 = Inhibition} 13 | \item{\code{target}}{Target node, either metabolite or protein} 14 | A detailed description of the identifier formatting can be found under 15 | \url{https://metapkn.omnipathdb.org/00__README.txt}. 16 | } 17 | } 18 | \source{ 19 | The network data are available on github: 20 | \url{https://github.com/saezlab/COSMOS_MSB/tree/main/results/COSMOS_result/COSMOS_res_session.RData}. 21 | The toy_network is the combined network of the COSMOS network solutions 22 | CARNIVAL_Result2 and CARNIVAL_Result_rerun subsequently reduced to 19 23 | exemplary nodes. 24 | } 25 | \usage{ 26 | data(toy_network) 27 | } 28 | \description{ 29 | This signaling network is the reduced COSMOS network solution obtained in the 30 | cosmos test on 786-O NCI60 data. Here, this network solution is reused as an 31 | exemplary input prior knowledge network (PKN). 32 | } 33 | \examples{ 34 | data(toy_network) 35 | 36 | } 37 | \references{ 38 | { 39 | Dugourd, A., Kuppe, C. and Sciacovelli, M. et. al. (2021) \emph{Molecular 40 | Systems Biology}. \bold{17}, e9730. 41 | } 42 | } 43 | \keyword{datasets} 44 | -------------------------------------------------------------------------------- /man/toy_signaling_input.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/toy_signaling_input.R 3 | \docType{data} 4 | \name{toy_signaling_input} 5 | \alias{toy_signaling_input} 6 | \title{Toy Signaling Input} 7 | \format{ 8 | An object of class \dQuote{\code{data.frame}} containing the normalised 9 | enrichment scores (NES) of 2 signaling proteins, which are named with their 10 | respective gene Entrez ID matching the toy network. 11 | } 12 | \source{ 13 | Subset of: 14 | \url{https://github.com/saezlab/COSMOS_MSB/blob/main/data/signaling_input_COSMOS.csv} 15 | } 16 | \usage{ 17 | data(toy_signaling_input) 18 | } 19 | \description{ 20 | This signaling data are a subset of the footprint-based signaling activity 21 | estimates of transcription factors of the 786-O cell line from the NCI60 dataset. 22 | } 23 | \examples{ 24 | data(toy_signaling_input) 25 | 26 | } 27 | \references{ 28 | { 29 | Dugourd, A., Kuppe, C. and Sciacovelli, M. et. al. (2021) \emph{Molecular 30 | Systems Biology}. \bold{17}, e9730. 31 | } 32 | } 33 | \keyword{datasets} 34 | -------------------------------------------------------------------------------- /man/translate_column_HMDB.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/support_decoupleR.R 3 | \name{translate_column_HMDB} 4 | \alias{translate_column_HMDB} 5 | \title{Translate Column Using HMDB Mapper} 6 | \usage{ 7 | translate_column_HMDB(my_column, HMDB_mapper_vec) 8 | } 9 | \arguments{ 10 | \item{my_column}{A vector of values to be translated.} 11 | 12 | \item{HMDB_mapper_vec}{A named vector where the names are the original identifiers and the values are the corresponding HMDB identifiers.} 13 | } 14 | \value{ 15 | A vector with the translated values. 16 | } 17 | \description{ 18 | This function translates the values in a column using a provided Human Metabolome Database (HMDB) mapper vector. 19 | It modifies the input values by replacing certain prefixes and suffixes according to specific rules. 20 | } 21 | \examples{ 22 | # Create a sample column and HMDB mapper vector 23 | my_column <- c("Metab__1234_a", "Gene5678_b", "Metab__91011_c") 24 | HMDB_mapper_vec <- c("1234" = "HMDB00001", "5678" = "HMDB00002", "91011" = "HMDB00003") 25 | 26 | # Translate the column 27 | translated_column <- translate_column_HMDB(my_column, HMDB_mapper_vec) 28 | 29 | } 30 | -------------------------------------------------------------------------------- /man/translate_res.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/decoupleRnival.R 3 | \name{translate_res} 4 | \alias{translate_res} 5 | \title{translate_res} 6 | \usage{ 7 | translate_res(SIF, ATT, HMDB_mapper_vec = NULL) 8 | } 9 | \arguments{ 10 | \item{SIF}{result SIF of decoupleRnival pipeline} 11 | 12 | \item{ATT}{result ATT of decoupleRnival pipeline} 13 | 14 | \item{HMDB_mapper_vec}{a named vector with HMDB Ids as names and desired metabolite names as values.} 15 | } 16 | \value{ 17 | list with network and attribute tables. 18 | } 19 | \description{ 20 | formats the network with readable names 21 | } 22 | \examples{ 23 | # Create a meta network data frame 24 | example_SIF <- data.frame( 25 | source = c("GPX1", "Gene863__GPX1"), 26 | target = c("Gene863__GPX1", "Metab__HMDB0003337_c"), 27 | sign = c(1, 1) 28 | ) 29 | 30 | example_ATT <- data.frame( 31 | Nodes = c("GPX1", "Gene863__GPX1","Metab__HMDB0003337_c"), 32 | sign = c(1, 1, 1) 33 | ) 34 | 35 | example_SIF 36 | 37 | data("HMDB_mapper_vec") 38 | 39 | translated_res <- translate_res(example_SIF,example_ATT,HMDB_mapper_vec) 40 | 41 | translated_res$SIF 42 | } 43 | -------------------------------------------------------------------------------- /man/wide_ulm_res.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/support_decoupleR.R 3 | \name{wide_ulm_res} 4 | \alias{wide_ulm_res} 5 | \title{Convert ULM Results to Wide Format} 6 | \usage{ 7 | wide_ulm_res(ulm_result) 8 | } 9 | \arguments{ 10 | \item{ulm_result}{A data frame representing the ULM results with columns: source, condition, and score.} 11 | } 12 | \value{ 13 | A data frame in wide format where each row is a source and each column is a condition. 14 | } 15 | \description{ 16 | This function converts the results from a ULM analysis to a wide format data frame. 17 | The input is a data frame with columns for source, condition, and score. The output 18 | is a data frame where each row represents a source and each column represents a condition, 19 | with the corresponding scores as values. 20 | } 21 | \examples{ 22 | # Create a sample ULM result 23 | ulm_result <- data.frame(source = c("A", "A", "B", "B"), 24 | condition = c("cond1", "cond2", "cond1", "cond2"), 25 | score = c(0.5, 0.8, 0.3, 0.7)) 26 | 27 | # Convert to wide format 28 | wide_ulm_result <- wide_ulm_res(ulm_result) 29 | 30 | } 31 | -------------------------------------------------------------------------------- /pkgdown/_pkgdown.yml: -------------------------------------------------------------------------------- 1 | destination: docs 2 | navbar: 3 | structure: 4 | left: [home, intro, reference, articles, tutorials, news] 5 | right: [github, twitter, homepage] 6 | components: 7 | twitter: 8 | icon: "fab fa-twitter fa-lg" 9 | href: https://twitter.com/saezlab 10 | homepage: 11 | icon: "fas fa-university" 12 | href: https://saezlab.org 13 | type: dark 14 | bg: primary 15 | template: 16 | params: 17 | ganalytics: G-PV71G2Q3SF 18 | highlightcss: false 19 | bootstrap: 5 20 | bootswatch: cosmo 21 | bslib: 22 | primary: "#285FA9" 23 | assets: vignettes/MOFA_to_COSMOS_files, vignettes/net_compr_MOON_files 24 | -------------------------------------------------------------------------------- /pkgdown/extra.css: -------------------------------------------------------------------------------- 1 | .contents p:first-of-type img { 2 | background-color: white; 3 | padding: 10px; 4 | margin-top: 15px; 5 | scale: 1.1; 6 | position: relative; 7 | left: 10%; 8 | } 9 | 10 | body { 11 | font-size: 117%!important; 12 | } 13 | 14 | .bg-primary { 15 | background-color: #285FA9!important; 16 | } 17 | 18 | nav[data-toggle="toc"] .nav > li > a { 19 | border-radius: 0px!important; 20 | padding-left: 1rem!important; 21 | } 22 | 23 | pre { 24 | border-radius: 0px!important; 25 | background-color: white!important; 26 | } 27 | 28 | code span, code a:any-link { 29 | color: #1f1c1b!important; 30 | }/* Normal */ 31 | code span.al, code span.al a:any-link { 32 | color: #bf0303!important; 33 | background-color: #f7e6e6!important; 34 | font-weight: bold; 35 | } /* Alert */ 36 | code span.an, code span.an a:any-link { 37 | color: #ca60ca!important; 38 | } /* Annotation */ 39 | code span.at, code span.at a:any-link { 40 | color: #0057ae!important; 41 | } /* Attribute */ 42 | code span.bn, code span.bn a:any-link { 43 | color: #b08000!important; 44 | } /* BaseN */ 45 | code span.bu, code span.bu a:any-link { 46 | color: #644a9b!important; 47 | font-weight: bold; 48 | } /* BuiltIn */ 49 | code span.cf, code span.cf a:any-link { 50 | color: #1f1c1b!important; 51 | font-weight: bold; 52 | } /* ControlFlow */ 53 | code span.ch, code span.ch a:any-link { 54 | color: #924c9d!important; 55 | } /* Char */ 56 | code span.cn, code span.cn a:any-link { 57 | color: #aa5500!important; 58 | }/* Constant */ 59 | code span.co, code span.co a:any-link { 60 | color: #898887!important; 61 | }/* Comment */ 62 | code span.cv, code span.cv a:any-link { 63 | color: #0095ff!important; 64 | }/* CommentVar */ 65 | code span.do, code span.do a:any-link { 66 | color: #607880!important; 67 | }/* Documentation */ 68 | code span.dt, code span.dt a:any-link { 69 | color: #0057ae!important; 70 | }/* DataType */ 71 | code span.dv, code span.dv a:any-link { 72 | color: #b08000!important; 73 | }/* DecVal */ 74 | code span.er, code span.er a:any-link { 75 | color: #bf0303!important; 76 | text-decoration: underline; 77 | } /* Error */ 78 | code span.ex, code span.ex a:any-link { 79 | color: #0095ff!important; 80 | font-weight: bold; 81 | } /* Extension */ 82 | code span.fl, code span.fl a:any-link { 83 | color: #b08000!important; 84 | }/* Float */ 85 | code span.fu, 86 | code span.fu a:any-link { 87 | color: #644a9b!important; 88 | } /* Function */ 89 | code span.im, code span.im a:any-link { 90 | color: #ff5500!important; 91 | }/* Import */ 92 | code span.in, code span.in a:any-link { 93 | color: #b08000!important; 94 | }/* Information */ 95 | code span.kw, code span.kw a:any-link { 96 | /*color: #1f1c1b!important;*/ 97 | color: #007BA5!important; 98 | font-weight: bold; 99 | } /* Keyword */ 100 | code span.op, code span.op a:any-link { 101 | /* color: #1f1c1b!important; */ 102 | color: #5E5E5E!important; 103 | }/* Operator */ 104 | code span.ot, code span.ot a:any-link { 105 | color: #006e28!important; 106 | }/* Other */ 107 | code span.pp, code span.pp a:any-link { 108 | color: #006e28!important; 109 | }/* Preprocessor */ 110 | code span.re, code span.re a:any-link { 111 | color: #0057ae!important; 112 | background-color: #e0e9f8!important; 113 | } /* RegionMarker */ 114 | code span.sc, code span.sc a:any-link { 115 | color: #3daee9!important; 116 | }/* SpecialChar */ 117 | code span.ss, code span.ss a:any-link { 118 | color: #ff5500!important; 119 | }/* SpecialString */ 120 | /* code span.st, code span.st a:any-link { 121 | color: #bf0303!important; 122 | }/* String */ 123 | code span.st, code span.st a:any-link { 124 | color: #20794d!important; 125 | }/* String */ 126 | code span.va, code span.va a:any-link { 127 | color: #0057ae!important; 128 | }/* Variable */ 129 | code span.vs, code span.vs a:any-link { 130 | color: #bf0303!important; 131 | }/* VerbatimString */ 132 | code span.wa, code span.wa a:any-link { 133 | color: #bf0303!important; 134 | }/* Warning */ 135 | 136 | .nav-text.text-muted { 137 | color: #ffffff!important; 138 | } 139 | 140 | .nav-item.active > .nav-link { 141 | background-color: #e9ecef!important; 142 | color: #285FA9!important; 143 | } 144 | 145 | .navbar-dark input[type="search"] { 146 | background-color: #e9ecef!important; 147 | color: #212529!important; 148 | } 149 | 150 | .template-home > .row > #main > p > img { 151 | background-color: #ffffff!important; 152 | padding-top: 20px; 153 | } 154 | 155 | .template-home > .row > #main > .section > .page-header > img { 156 | display: none!important; 157 | } 158 | 159 | .template-home h1, .template-home h2, .template-home h3, .template-home h4, 160 | .template-home h5, .template-home h6, .template-article .page-header h1 { 161 | font-weight: 700!important; 162 | } 163 | 164 | h1#omnipathr { 165 | font-size: 4.125rem!important; 166 | } 167 | 168 | img.logo { 169 | background-color: #ffffff!important; 170 | } 171 | 172 | p.abstract { 173 | font-size: calc(1.375rem + 1.5vw)!important; 174 | } 175 | 176 | h4.author { 177 | font-size: 1.25rem!important; 178 | margin-top: 1rem!important; 179 | } 180 | 181 | @media (min-width: 1200px){ 182 | p.abstract { 183 | font-size: 2.5rem!important; 184 | } 185 | } 186 | 187 | .author_afil { 188 | font-size: small!important; 189 | } 190 | 191 | .nav-item { 192 | margin-left: 10px!important; 193 | } 194 | -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(cosmosR) 3 | 4 | test_check("cosmosR") 5 | -------------------------------------------------------------------------------- /tests/testthat/test-check_COSMOS_inputs.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("test data", { 3 | 4 | # should not work with dataframe 5 | test_data = dplyr::tibble(ID = c("A","B"),activity = c(0.1,5)) 6 | expect_error(check_COSMOS_inputs(signaling_data = test_data)) 7 | 8 | # should pass with named vector 9 | test_data = c(X0125=4,X123684=-4) 10 | expect_true(check_COSMOS_inputs(signaling_data = test_data)) 11 | 12 | }) 13 | 14 | test_that("test meta network", { 15 | 16 | test_data = dplyr::tibble(source = c("A","B"),interaction = c(-1,1), target = c("C","D")) 17 | expect_true(check_COSMOS_inputs(meta_network = test_data)) 18 | 19 | }) 20 | 21 | 22 | test_that("test regulon network", { 23 | 24 | test_data = dplyr::tibble(tf = c("A","B"),sign = c(-1,1), target = c("C","D")) 25 | expect_true(check_COSMOS_inputs(tf_regulon = test_data)) 26 | 27 | }) 28 | -------------------------------------------------------------------------------- /tests/testthat/test-cosmos_data.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | test_that("construct cosmos_data", { 5 | 6 | meta_network_test <- cosmosR:::meta_network_test 7 | signaling_input_test <- cosmosR:::signaling_input_test 8 | expression_data_test <- cosmosR:::expression_data_test 9 | metabolic_data_test <- cosmosR:::metabolic_data_test 10 | 11 | cos <- new_cosmos_data(meta_network = meta_network_test, 12 | tf_regulon = load_tf_regulon_dorothea(), 13 | signaling_data = signaling_input_test, 14 | expression_data = expression_data_test, 15 | metabolic_data = metabolic_data_test) 16 | expect_true(is(cos,"cosmos_data")) 17 | }) 18 | 19 | 20 | 21 | test_that("validate cosmos_data", { 22 | 23 | cos <- new_cosmos_data(meta_network = meta_network_test, 24 | tf_regulon = load_tf_regulon_dorothea(), 25 | signaling_data = signaling_input_test, 26 | expression_data = expression_data_test, 27 | metabolic_data = metabolic_data_test) 28 | expect_true({ 29 | validate_cosmos_data(cos) 30 | TRUE 31 | }) 32 | }) 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /tests/testthat/test-load_tf_regulon_dorothea.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | test_that("tf conversion", { 5 | 6 | reg = load_tf_regulon_dorothea(confidence = c("A","B","C")) 7 | # make sure A,B,C still contains a lot of interactions 8 | expect_true(nrow(reg) > 1) 9 | # should return 3 columns, correct names 10 | expect_true(ncol(reg) == 3) 11 | expect_true(all(c("tf","sign","target") %in% colnames(reg))) 12 | # should not contain missing values 13 | expect_true(all(complete.cases(reg))) 14 | 15 | }) 16 | -------------------------------------------------------------------------------- /tests/testthat/test-preprocess_COSMOS.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("test cosmos preprocessing (signaling to metabolism)", { 3 | 4 | meta_network_test <- cosmosR:::meta_network_test 5 | signaling_input_test <- cosmosR:::signaling_input_test 6 | expression_data_test <- cosmosR:::expression_data_test 7 | metabolic_data_test <- cosmosR:::metabolic_data_test 8 | 9 | res <- preprocess_COSMOS_signaling_to_metabolism(meta_network = meta_network_test, 10 | signaling_data = signaling_input_test, 11 | metabolic_data = metabolic_data_test, 12 | diff_expression_data = expression_data_test, 13 | filter_tf_gene_interaction_by_optimization = FALSE) 14 | # check list: 15 | expect_length(res, 10) 16 | expect_true(all(c("meta_network", 17 | "tf_regulon", 18 | "signaling_data", 19 | "signaling_data_bin", 20 | "metabolic_data", 21 | "metabolic_data_bin", 22 | "expression_data", 23 | "diff_expression_data_bin", 24 | "optimized_network") %in% names(res))) 25 | 26 | 27 | # checking network 28 | expect_equal(ncol(res$meta_network), 3) 29 | # expect_equal(nrow(res$meta_network), 44005) 30 | expect_true(all(colnames(res$meta_network) %in% c("source","interaction","target"))) 31 | 32 | # checking tf_regulon 33 | expect_true(all(c("tf","target","sign") %in% colnames(res$tf_regulon))) 34 | 35 | # checking signaling 36 | expect_true(is.vector(res$signaling_data_bin)) 37 | #expect_equal(length(res$signaling_data_bin),103) 38 | #expect_equal(sum(grepl("^X",names(res$signaling_data_bin))),103) 39 | expect_true(all(res$signaling_data_bin %in% c(-1,0,1))) 40 | 41 | # checking metabolic 42 | expect_true(is.vector(res$metabolic_data)) 43 | #expect_equal(length(res$metabolic_data),35) 44 | #expect_equal(sum(grepl("^XMetab",names(res$metabolic_data))),35) 45 | 46 | # check diff_expression_data_bin 47 | expect_true(is.vector(res$diff_expression_data_bin)) 48 | #expect_equal(length(res$diff_expression_data_bin),15919) 49 | #expect_equal(sum(grepl("^X",names(res$diff_expression_data_bin))),15919) 50 | expect_true(all(res$diff_expression_data_bin %in% c(-1,0,1))) 51 | }) 52 | 53 | 54 | test_that("test cosmos preprocessing (signaling to metabolism)", { 55 | 56 | 57 | meta_network_test <- cosmosR:::meta_network_test 58 | signaling_input_test <- cosmosR:::signaling_input_test 59 | expression_data_test <- cosmosR:::expression_data_test 60 | metabolic_data_test <- cosmosR:::metabolic_data_test 61 | 62 | res <- preprocess_COSMOS_metabolism_to_signaling(meta_network = meta_network_test, 63 | signaling_data = signaling_input_test, 64 | metabolic_data = metabolic_data_test, 65 | diff_expression_data = expression_data_test, 66 | filter_tf_gene_interaction_by_optimization = FALSE) 67 | # check list: 68 | expect_length(res, 10) 69 | expect_true(all(c("meta_network", 70 | "tf_regulon", 71 | "signaling_data", 72 | "signaling_data_bin", 73 | "metabolic_data", 74 | "metabolic_data_bin", 75 | "expression_data", 76 | "diff_expression_data_bin", 77 | "optimized_network") %in% names(res))) 78 | 79 | 80 | # checking network 81 | expect_equal(ncol(res$meta_network), 3) 82 | #expect_equal(nrow(res$meta_network), 42103) 83 | expect_true(all(colnames(res$meta_network) %in% c("source","interaction","target"))) 84 | 85 | # checking tf_regulon 86 | expect_true(all(c("tf","target","sign") %in% colnames(res$tf_regulon))) 87 | 88 | # checking signaling 89 | expect_true(is.vector(res$signaling_data_bin)) 90 | #expect_equal(length(res$signaling_data_bin),107) 91 | #expect_equal(sum(grepl("^X",names(res$signaling_data_bin))),107) 92 | expect_true(all(res$signaling_data_bin %in% c(-1,0,1))) 93 | 94 | # checking metabolic 95 | expect_true(is.vector(res$metabolic_data)) 96 | #expect_equal(length(res$metabolic_data),29) 97 | #expect_equal(sum(grepl("^XMetab",names(res$metabolic_data))),29) 98 | 99 | # check diff_expression_data_bin 100 | expect_true(is.vector(res$diff_expression_data_bin)) 101 | #expect_equal(length(res$diff_expression_data_bin),15919) 102 | #expect_equal(sum(grepl("^X",names(res$diff_expression_data_bin))),15919) 103 | expect_true(all(res$diff_expression_data_bin %in% c(-1,0,1))) 104 | }) 105 | -------------------------------------------------------------------------------- /tests/testthat/test-run_COSMOS_metabolism_to_signaling.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | test_that("test run COSMOS signaling to metabolism", { 5 | 6 | meta_network <- cosmosR:::meta_network_test 7 | signaling_data <- cosmosR:::signaling_input_test 8 | expression_data <- cosmosR:::expression_data_test 9 | metabolic_data <- cosmosR:::metabolic_data_test 10 | 11 | 12 | res <- preprocess_COSMOS_metabolism_to_signaling(signaling_data = signaling_data, 13 | meta_network = meta_network, 14 | metabolic_data = metabolic_data, 15 | diff_expression_data = expression_data, 16 | remove_unexpressed_nodes = FALSE, 17 | maximum_network_depth = 15, 18 | filter_tf_gene_interaction_by_optimization = FALSE) 19 | 20 | CARNIVAL_options = CARNIVAL::defaultLpSolveCarnivalOptions() 21 | 22 | res_network = run_COSMOS_metabolism_to_signaling(data = res, 23 | CARNIVAL_options = CARNIVAL_options) 24 | 25 | expect_length(res_network, 5) 26 | expect_true(all(c("weightedSIF", 27 | "N_networks", 28 | "nodesAttributes", 29 | "individual_networks", 30 | "individual_networks_node_attributes") %in% names(res_network))) 31 | 32 | }) 33 | -------------------------------------------------------------------------------- /tests/testthat/test-run_COSMOS_signaling_to_metabolism.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | test_that("test run COSMOS signaling to metabolism", { 5 | 6 | 7 | meta_network <- cosmosR:::meta_network_test 8 | signaling_data <- cosmosR:::signaling_input_test 9 | expression_data <- cosmosR:::expression_data_test 10 | metabolic_data <- cosmosR:::metabolic_data_test 11 | 12 | 13 | res <- preprocess_COSMOS_signaling_to_metabolism(signaling_data = signaling_data, 14 | meta_network = meta_network, 15 | metabolic_data = metabolic_data, 16 | diff_expression_data = expression_data, 17 | remove_unexpressed_nodes = FALSE, 18 | maximum_network_depth = 15, 19 | filter_tf_gene_interaction_by_optimization = FALSE) 20 | 21 | CARNIVAL_options = CARNIVAL::defaultLpSolveCarnivalOptions() 22 | 23 | 24 | #cplex_file <- "/Applications/CPLEX_Studio128/cplex/bin/x86-64_osx/cplex" 25 | #skip_if(!file.exists(cplex_file),"CPLEX optimization based test skipped.") 26 | 27 | #CARNIVAL_options$solverPath = cplex_file 28 | res_network = run_COSMOS_signaling_to_metabolism(data = res, 29 | CARNIVAL_options = CARNIVAL_options) 30 | 31 | 32 | expect_length(res_network, 5) 33 | expect_true(all(c("weightedSIF", 34 | "N_networks", 35 | "nodesAttributes", 36 | "individual_networks", 37 | "individual_networks_node_attributes") %in% names(res_network))) 38 | 39 | }) 40 | -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Activity_estimations_for_factor_4_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Activity_estimations_for_factor_4_1.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Activity_estimations_for_factor_4_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Activity_estimations_for_factor_4_2.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Chekc_cross_correlation_of_omics_compared_to_variance_epxlained_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Chekc_cross_correlation_of_omics_compared_to_variance_epxlained_1.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Chekc_cross_correlation_of_omics_compared_to_variance_epxlained_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Chekc_cross_correlation_of_omics_compared_to_variance_epxlained_2.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Chekc_cross_correlation_of_omics_compared_to_variance_epxlained_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Chekc_cross_correlation_of_omics_compared_to_variance_epxlained_3.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Compare_MOFA_models_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Compare_MOFA_models_1.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Factor_weights_per_view_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Factor_weights_per_view_1.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Plot_Ligand_receptor_activity_estimates_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Plot_Ligand_receptor_activity_estimates_1.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Plot_Metabolite_factor_weights_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Plot_Metabolite_factor_weights_1.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Plot_RNA_weights_and_protein_weights_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Plot_RNA_weights_and_protein_weights_1.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Plot_RNA_weights_and_protein_weights_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Plot_RNA_weights_and_protein_weights_2.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Plot_TF_activity_estimates_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Plot_TF_activity_estimates_1.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Preparing_MOFA_input_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Preparing_MOFA_input_1.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Preparing_MOFA_input_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Preparing_MOFA_input_2.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Preparing_MOFA_input_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Preparing_MOFA_input_3.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Preparing_MOFA_input_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Preparing_MOFA_input_4.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Preparing_MOFA_input_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Preparing_MOFA_input_5.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Run_moon_rec_to_TFmetab_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Run_moon_rec_to_TFmetab_1.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Supp_figure_condition_prot_RNA_correlation_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Supp_figure_condition_prot_RNA_correlation_1.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Supp_figure_single_prot_RNA_correlation_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Supp_figure_single_prot_RNA_correlation_1.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Total_variance_per_factor_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Total_variance_per_factor_1.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/Variance_per_view_per_factor_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/Variance_per_view_per_factor_1.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/correlation_RNA/prot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/correlation_RNA/prot-1.png -------------------------------------------------------------------------------- /vignettes/M2Cf/figs/run_moon_TF_to_lig_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/M2Cf/figs/run_moon_TF_to_lig_1.png -------------------------------------------------------------------------------- /vignettes/MOFA_to_COSMOS.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "MOFA to COSMOS tutorial" 3 | output: rmarkdown::html_vignette 4 | resource_files: 5 | - MOFA_to_COSMOS_files 6 | vignette: > 7 | %\VignetteIndexEntry{MOFA to COSMOS tutorial} 8 | %\VignetteEngine{knitr::rmarkdown} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r, include = FALSE} 13 | knitr::opts_chunk$set( 14 | collapse = TRUE, 15 | comment = "#>" 16 | ) 17 | ``` 18 | 19 | ```{r, results='asis',echo=FALSE} 20 | #install.packages("htmltools") 21 | #install.packages("markdown") 22 | # Include the external HTML file 23 | htmltools::includeMarkdown("MOFA_to_COSMOS.md") 24 | ``` 25 | 26 | -------------------------------------------------------------------------------- /vignettes/NCI60_tutorial.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "NCI60 tutorial" 3 | output: rmarkdown::html_vignette 4 | resource_files: 5 | - net_compr_MOON_files 6 | vignette: > 7 | %\VignetteIndexEntry{NCI60 tutorial} 8 | %\VignetteEngine{knitr::rmarkdown} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r, include = FALSE} 13 | knitr::opts_chunk$set( 14 | collapse = TRUE, 15 | comment = "#>" 16 | ) 17 | ``` 18 | 19 | ```{r, results='asis',echo=FALSE} 20 | # htmltools::tags$iframe( 21 | # src = base64enc::dataURI(file="../pkgdown/assets/NCI.html", mime="text/html; charset=UTF-8"), 22 | # style="border:0; position:relative; top:0; left:0; right:0; bottom:0; width:100%; height:100vh" 23 | # ) 24 | # 25 | htmltools::includeMarkdown("net_compr_MOON.md") 26 | ``` 27 | -------------------------------------------------------------------------------- /vignettes/net_compr_MOON.md: -------------------------------------------------------------------------------- 1 | 2 | ## libraries, data loading and feature selection 3 | 4 | # We advise to instal from github to get the latest version of the tool. 5 | # if (!requireNamespace("devtools", quietly = TRUE)) 6 | # install.packages("devtools") 7 | # 8 | # devtools::install_github("saezlab/cosmosR") 9 | 10 | library(cosmosR) 11 | library(reshape2) 12 | library(readr) 13 | 14 | data("meta_network") 15 | 16 | meta_network <- meta_network_cleanup(meta_network) 17 | 18 | ## Warning: `summarise_each()` was deprecated in dplyr 0.7.0. 19 | ## ℹ Please use `across()` instead. 20 | ## ℹ The deprecated feature was likely used in the cosmosR package. 21 | ## Please report the issue at . 22 | ## This warning is displayed once every 8 hours. 23 | ## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was 24 | ## generated. 25 | 26 | ## Warning: `funs()` was deprecated in dplyr 0.8.0. 27 | ## ℹ Please use a list of either functions or lambdas: 28 | ## 29 | ## # Simple named list: list(mean = mean, median = median) 30 | ## 31 | ## # Auto named with `tibble::lst()`: tibble::lst(mean, median) 32 | ## 33 | ## # Using lambdas list(~ mean(., trim = .2), ~ median(., na.rm = TRUE)) 34 | ## ℹ The deprecated feature was likely used in the cosmosR package. 35 | ## Please report the issue at . 36 | ## This warning is displayed once every 8 hours. 37 | ## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was 38 | ## generated. 39 | 40 | load("data/cosmos/cosmos_inputs.RData") 41 | 42 | names(cosmos_inputs) 43 | 44 | ## [1] "786-0" "A498" "A549/ATCC" "ACHN" "BT-549" 45 | ## [6] "CAKI-1" "CCRF-CEM" "COLO 205" "DU-145" "EKVX" 46 | ## [11] "HCC-2998" "HCT-116" "HCT-15" "HL-60(TB)" "HOP-62" 47 | ## [16] "HOP-92" "HS 578T" "HT29" "IGROV1" "K-562" 48 | ## [21] "KM12" "LOX IMVI" "M14" "MALME-3M" "MCF7" 49 | ## [26] "MDA-MB-435" "MOLT-4" "NCI-H226" "NCI-H23" "NCI-H322M" 50 | ## [31] "NCI-H460" "NCI-H522" "NCI/ADR-RES" "OVCAR-3" "OVCAR-4" 51 | ## [36] "OVCAR-5" "OVCAR-8" "PC-3" "RPMI-8226" "SF-268" 52 | ## [41] "SF-295" "SF-539" "SK-MEL-28" "SK-MEL-5" "SK-OV-3" 53 | ## [46] "SN12C" "SNB-19" "SNB-75" "SR" "SW-620" 54 | ## [51] "T-47D" "TK-10" "U251" "UACC-257" "UACC-62" 55 | ## [56] "UO-31" 56 | 57 | cell_line <- "786-0" 58 | 59 | #see scripts/prepare_cosmos_inputs.R 60 | sig_input <- cosmos_inputs[[cell_line]]$TF_scores 61 | metab_input <- cosmos_inputs[[cell_line]]$metabolomic 62 | RNA_input <- cosmos_inputs[[cell_line]]$RNA 63 | 64 | #Choose which compartment to assign to the metabolic measurments 65 | metab_input <- prepare_metab_inputs(metab_input, c("c","m")) 66 | 67 | ## [1] "Adding compartment codes." 68 | 69 | ##Filter significant inputs 70 | sig_input <- sig_input[abs(sig_input) > 2] 71 | # metab_input <- metab_input[abs(metab_input) > 2] 72 | 73 | ## Filter inputs and prior knowledge network 74 | 75 | #Remove genes that are not expressed from the meta_network 76 | meta_network <- cosmosR:::filter_pkn_expressed_genes(names(RNA_input), meta_pkn = meta_network) 77 | 78 | ## [1] "COSMOS: removing unexpressed nodes from PKN..." 79 | ## [1] "COSMOS: 20357 interactions removed" 80 | 81 | #Filter inputs and prune the meta_network to only keep nodes that can be found downstream of the inputs 82 | #The number of step is quite flexible, 7 steps already covers most of the network 83 | 84 | n_steps <- 6 85 | 86 | # in this step we prune the network to keep only the relevant part between upstream and downstream nodes 87 | sig_input <- cosmosR:::filter_input_nodes_not_in_pkn(sig_input, meta_network) 88 | 89 | ## [1] "COSMOS: 12 input/measured nodes are not in PKN any more: CEBPA, ESR1, FOS, FOXA1, GATA3, HNF4A and 6 more." 90 | 91 | meta_network <- cosmosR:::keep_controllable_neighbours(meta_network, n_steps, names(sig_input)) 92 | 93 | ## [1] "COSMOS: removing nodes that are not reachable from inputs within 6 steps" 94 | ## [1] "COSMOS: 26540 from 37740 interactions are removed from the PKN" 95 | 96 | metab_input <- cosmosR:::filter_input_nodes_not_in_pkn(metab_input, meta_network) 97 | 98 | ## [1] "COSMOS: 195 input/measured nodes are not in PKN any more: Metab__HMDB0011747_c, Metab__HMDB0000755_c, Metab__HMDB0000905_c, Metab__HMDB0001191_c, Metab__HMDB0000355_c, Metab__HMDB0000479_c and 189 more." 99 | 100 | meta_network <- cosmosR:::keep_observable_neighbours(meta_network, n_steps, names(metab_input)) 101 | 102 | ## [1] "COSMOS: removing nodes that are not observable by measurements within 6 steps" 103 | ## [1] "COSMOS: 3657 from 11200 interactions are removed from the PKN" 104 | 105 | sig_input <- cosmosR:::filter_input_nodes_not_in_pkn(sig_input, meta_network) 106 | 107 | ## [1] "COSMOS: 4 input/measured nodes are not in PKN any more: CTCF, EPAS1, ETS1, USF1 and 0 more." 108 | 109 | #compress the network 110 | meta_network_compressed_list <- compress_same_children(meta_network, sig_input = sig_input, metab_input = metab_input) 111 | 112 | meta_network_compressed <- meta_network_compressed_list$compressed_network 113 | 114 | node_signatures <- meta_network_compressed_list$node_signatures 115 | 116 | duplicated_parents <- meta_network_compressed_list$duplicated_signatures 117 | 118 | meta_network_compressed <- meta_network_cleanup(meta_network_compressed) 119 | 120 | ## run MOON ot score the and contextualise the PKN 121 | 122 | load("support/dorothea_reg.RData") 123 | 124 | meta_network_TF_to_metab <- meta_network_compressed 125 | 126 | before <- 1 127 | after <- 0 128 | i <- 1 129 | while (before != after & i < 10) { 130 | before <- length(meta_network_TF_to_metab[,1]) 131 | moon_res <- moon(upstream_input = sig_input, 132 | downstream_input = metab_input, 133 | meta_network = meta_network_TF_to_metab, 134 | n_layers = n_steps, 135 | statistic = "ulm") 136 | 137 | meta_network_TF_to_metab <- filter_incohrent_TF_target(moon_res, dorothea_reg, meta_network_TF_to_metab, RNA_input) 138 | after <- length(meta_network_TF_to_metab[,1]) 139 | i <- i + 1 140 | } 141 | 142 | ## [1] 2 143 | ## [1] 3 144 | ## [1] 4 145 | ## [1] 5 146 | ## [1] 6 147 | ## [1] 2 148 | ## [1] 3 149 | ## [1] 4 150 | ## [1] 5 151 | ## [1] 6 152 | ## [1] 2 153 | ## [1] 3 154 | ## [1] 4 155 | ## [1] 5 156 | ## [1] 6 157 | 158 | if(i < 10) 159 | { 160 | print(paste("Converged after ",paste(i-1," iterations", sep = ""),sep = "")) 161 | } else 162 | { 163 | print(paste("Interupted after ",paste(i," iterations. Convergence uncertain.", sep = ""),sep = "")) 164 | } 165 | 166 | ## [1] "Converged after 3 iterations" 167 | 168 | ##### 169 | write_csv(moon_res, file = paste("results/moon/",paste(cell_line, "_ATT_decouplerino_full.csv",sep = ""), sep = "")) 170 | 171 | source("scripts/support_decompression.R") 172 | moon_res <- decompress_moon_result(moon_res, meta_network_compressed_list, meta_network_TF_to_metab) 173 | 174 | plot(density(moon_res$score)) 175 | abline(v = 1) 176 | abline(v = -1) 177 | 178 | ![](net_compr_MOON_files/figure-markdown_strict/extract_subnetwork_from_scored_MOON_network_1.png) 179 | 180 | solution_network <- reduce_solution_network(decoupleRnival_res = moon_res, 181 | meta_network = meta_network, 182 | cutoff = 0.5, 183 | upstream_input = sig_input, 184 | RNA_input = RNA_input, 185 | n_steps = n_steps) 186 | 187 | ## [1] "COSMOS: removing nodes that are not reachable from inputs within 6 steps" 188 | ## [1] "COSMOS: 458 from 1747 interactions are removed from the PKN" 189 | 190 | SIF <- solution_network$SIF 191 | names(SIF)[3] <- "sign" 192 | ATT <- solution_network$ATT 193 | 194 | data("HMDB_mapper_vec") 195 | 196 | translated_res <- translate_res(SIF,ATT,HMDB_mapper_vec) 197 | 198 | SIF <- translated_res[[1]] 199 | ATT <- translated_res[[2]] 200 | 201 | write_csv(SIF, file = paste("results/",paste(cell_line, "_dec_compressed_SIF.csv",sep = ""), sep = "")) 202 | write_csv(ATT, file = paste("results/",paste(cell_line, "_dec_compressed_ATT.csv",sep = ""), sep = "")) 203 | 204 | sessionInfo() 205 | 206 | ## R version 4.2.0 (2022-04-22) 207 | ## Platform: aarch64-apple-darwin20 (64-bit) 208 | ## Running under: macOS Monterey 12.6 209 | ## 210 | ## Matrix products: default 211 | ## BLAS: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib 212 | ## LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib 213 | ## 214 | ## locale: 215 | ## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 216 | ## 217 | ## attached base packages: 218 | ## [1] stats graphics grDevices utils datasets methods base 219 | ## 220 | ## other attached packages: 221 | ## [1] readr_2.1.4 reshape2_1.4.4 cosmosR_1.5.2 222 | ## 223 | ## loaded via a namespace (and not attached): 224 | ## [1] Rcpp_1.0.10 highr_0.10 plyr_1.8.8 pillar_1.9.0 225 | ## [5] compiler_4.2.0 prettyunits_1.1.1 tools_4.2.0 progress_1.2.2 226 | ## [9] bit_4.0.5 digest_0.6.31 evaluate_0.20 lifecycle_1.0.3 227 | ## [13] tibble_3.2.1 lattice_0.20-45 pkgconfig_2.0.3 rlang_1.1.0 228 | ## [17] igraph_1.4.2 Matrix_1.5-3 cli_3.6.1 rstudioapi_0.14 229 | ## [21] yaml_2.3.7 parallel_4.2.0 xfun_0.42 fastmap_1.1.1 230 | ## [25] withr_2.5.0 dplyr_1.1.3 stringr_1.5.0 knitr_1.42 231 | ## [29] generics_0.1.3 vctrs_0.6.1 hms_1.1.3 bit64_4.0.5 232 | ## [33] grid_4.2.0 tidyselect_1.2.0 glue_1.6.2 R6_2.5.1 233 | ## [37] fansi_1.0.4 parallelly_1.34.0 vroom_1.6.1 rmarkdown_2.21 234 | ## [41] tzdb_0.3.0 tidyr_1.3.0 purrr_1.0.1 decoupleR_2.9.1 235 | ## [45] magrittr_2.0.3 htmltools_0.5.5 utf8_1.2.3 stringi_1.7.12 236 | ## [49] crayon_1.5.2 237 | -------------------------------------------------------------------------------- /vignettes/net_compr_MOON_files/figure-markdown_strict/extract_subnetwork_from_scored_MOON_network_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saezlab/cosmosR/ef9d5aacc056c79c730382974a98b7d04e62c69d/vignettes/net_compr_MOON_files/figure-markdown_strict/extract_subnetwork_from_scored_MOON_network_1.png --------------------------------------------------------------------------------