Example script demonstrating execution of the OncoSig Random Forest (OncoSig-RF) algorithm (https://pubmed.ncbi.nlm.nih.gov/32929263/), to generate an oncoprotein-specific molecular interaction map (SigMap) for the KRAS protein.

Load required libraries

if(!require("randomForest", quietly = TRUE)) {
  install.packages("randomForest")
  require(randomForest, quietly = TRUE)
}
## randomForest 4.7-1.1
## Type rfNews() to see new features/changes/bug fixes.
if(!require("ROCR", quietly = TRUE)) {
  install.packages("ROCR")
  require(ROCR, quietly = TRUE)
}

Set the working directory, where the example code and data files are located.

setwd("/usr/local/RF/")

Source necessary code

source("./R/listToMatrix.R")
source("./R/OncoSigRF.R")

Set the network file path. In this example script, we are using a reduced-size version of a network file generated by processing lung adenocarcinoma (luad) samples, from the Genome Cancer Atlas project (TCGA). The companion Docker container includes the full version of the network, as well as a network generated from the TCGA colon adenocarcinoma (coad) sample collection. Details about how the networks are generated can be found in the OncoSig publication cited above (PMID: 32929263).

Network_location <- "./Data_files/luad_network_sample.txt"

Read in the network file and convert to matrix

Network <- read.delim(Network_location, header = F)

Convert network to matrix. listToMatrix is a Josh function

Network$V1 <- as.character(Network$V1)
Network$V2 <- as.character(Network$V2)
Network$V3 <- as.numeric(Network$V3)
Network <- as.matrix(Network)
Network[, 3] <- as.numeric(Network[, 3])
Network_matrix <- listToMatrix(Network)

Load the gold standard set. Here, we are using canonical KRAS signaling proteins. In additional to KRAS, gold standard sets for 9 more oncoproteins are available and can be selected by modifying the file path below, changing KRAS to the gene symbol of one of the other 9 proteins.

Gold_Standard_location <- "./Data_files/10_oncogene_pathways/KRAS/gold_standard.txt"
Gold_Standard <- read.delim(Gold_Standard_location, header = F)
Gold_Standard$V1 <- as.character(Gold_Standard$V1)

The feature matrix is compiled by combining Network_matrix and Gold_Standard

Network_matrix_df <- as.data.frame(Network_matrix)
Gold_Standard_in_Network_names <- intersect(rownames(Network_matrix_df), Gold_Standard$V1)
Negative_Set_names <- setdiff(rownames(Network_matrix_df), Gold_Standard_in_Network_names)
remove(Network_matrix)

Run the classifier. For this sample calculation, 10 trees and 10 iterations are sufficient.

Query_output_results <- OncoSigRF(Network_matrix_df, Gold_Standard_in_Network_names, Fraction_Gold_sample = 0.5, ntrees = 10, max_iterations = 10, balance = 1, to_save = 1)
## Running OncoSig
## Fraction of Gold Standard to train on for each Random Forest: 0.5
## Number of Trees per Iteration: 10
## Number of Iterations: 10
## Balance: 1
## Number of positive results to sample: 115
## Number of negative results to sample: 115
## Performing Random Forest
## mtry equals 167
## ntree      OOB      1      2
##     1:  44.44%  8.82% 70.21%
##     2:  47.10%  3.17% 84.00%
##     3:  46.55%  4.76% 85.56%
##     4:  46.32%  5.38% 85.57%
##     5:  44.61%  3.92% 85.29%
##     6:  44.44%  5.77% 83.50%
##     7:  48.15%  6.54% 88.99%
##     8:  44.04%  3.70% 83.64%
##     9:  46.15%  8.26% 83.04%
##    10:  45.98%  6.31% 84.96%
## Performing Random Forest
## mtry equals 167
## ntree      OOB      1      2
##     1:  42.70% 12.20% 68.75%
##     2:  43.07% 10.45% 74.29%
##     3:  43.45%  3.70% 80.46%
##     4:  45.60% 22.45% 69.47%
##     5:  46.41% 17.92% 75.73%
##     6:  45.87% 16.36% 75.93%
##     7:  42.99%  9.01% 77.27%
##     8:  45.54% 13.51% 76.99%
##     9:  42.41%  8.11% 76.11%
##    10:  42.67%  6.25% 78.76%
## Performing Random Forest
## mtry equals 167
## ntree      OOB      1      2
##     1:  44.79%  8.70% 78.00%
##     2:  39.87%  2.63% 76.62%
##     3:  39.68%  3.16% 76.60%
##     4:  40.59%  1.98% 79.21%
##     5:  41.20%  1.87% 79.82%
##     6:  40.91%  1.82% 80.00%
##     7:  41.07%  1.80% 79.65%
##     8:  41.85%  0.89% 81.74%
##     9:  42.79%  2.63% 82.61%
##    10:  40.87%  1.74% 80.00%
## At iteration 3
## Performing Random Forest
## mtry equals 167
## ntree      OOB      1      2
##     1:  36.26%  2.17% 71.11%
##     2:  42.75%  7.46% 76.06%
##     3:  40.46%  4.82% 73.33%
##     4:  41.18%  8.51% 74.19%
##     5:  39.90%  5.83% 73.33%
##     6:  42.79%  4.76% 79.09%
##     7:  41.26%  3.57% 79.28%
##     8:  43.75%  4.42% 83.78%
##     9:  43.11%  4.39% 82.88%
##    10:  41.15%  4.39% 78.57%
## At iteration 4
## Performing Random Forest
## mtry equals 167
## ntree      OOB      1      2
##     1:  41.86%  2.38% 79.55%
##     2:  44.44%  6.06% 81.16%
##     3:  43.86%  4.65% 83.53%
##     4:  43.46%  4.21% 82.29%
##     5:  41.67%  3.85% 81.00%
##     6:  42.18%  4.72% 80.00%
##     7:  42.20%  3.64% 81.48%
##     8:  41.89%  2.65% 82.57%
##     9:  40.54%  3.54% 78.90%
##    10:  41.15%  2.63% 80.36%
## At iteration 5
## Performing Random Forest
## mtry equals 167
## ntree      OOB      1      2
##     1:  50.56%  2.50% 89.80%
##     2:  42.55%  1.41% 84.29%
##     3:  46.07% 29.21% 62.92%
##     4:  46.27% 23.76% 69.00%
##     5:  44.86% 16.51% 74.29%
##     6:  41.28%  9.82% 74.53%
##     7:  39.29%  7.08% 72.07%
##     8:  40.97%  4.39% 77.88%
##     9:  41.48%  6.14% 76.52%
##    10:  40.17%  0.88% 79.13%
## At iteration 6
## Performing Random Forest
## mtry equals 167
## ntree      OOB      1      2
##     1:  50.00% 17.07% 80.00%
##     2:  45.86%  9.23% 80.88%
##     3:  42.26%  6.98% 79.27%
##     4:  43.09%  6.32% 80.65%
##     5:  43.56%  5.83% 82.83%
##     6:  42.45%  4.63% 81.73%
##     7:  42.66%  3.60% 83.18%
##     8:  42.86%  4.42% 81.98%
##     9:  42.73%  3.51% 82.30%
##    10:  43.17%  4.39% 82.30%
## At iteration 7
## Performing Random Forest
## mtry equals 167
## ntree      OOB      1      2
##     1:  38.67%  2.78% 71.79%
##     2:  38.97%  6.25% 68.06%
##     3:  38.73%  5.81% 71.26%
##     4:  41.18%  4.35% 76.84%
##     5:  42.79%  6.06% 78.43%
##     6:  42.06%  4.67% 79.44%
##     7:  41.01%  2.73% 80.37%
##     8:  42.60%  4.42% 81.82%
##     9:  43.17%  6.09% 81.25%
##    10:  43.61%  4.35% 83.93%
## At iteration 8
## Performing Random Forest
## mtry equals 167
## ntree      OOB      1      2
##     1:  41.76% 12.20% 66.00%
##     2:  44.59% 12.68% 74.03%
##     3:  44.26%  8.99% 77.66%
##     4:  41.67%  8.82% 74.51%
##     5:  42.59%  5.45% 81.13%
##     6:  41.26%  3.54% 80.00%
##     7:  40.89%  4.39% 78.38%
##     8:  40.53%  3.48% 78.57%
##     9:  40.61%  2.61% 78.95%
##    10:  41.30%  2.61% 80.00%
## At iteration 9
## Performing Random Forest
## mtry equals 167
## ntree      OOB      1      2
##     1:  37.50%  6.82% 68.18%
##     2:  40.28% 10.39% 74.63%
##     3:  44.00%  9.09% 79.31%
##     4:  43.00%  7.77% 80.41%
##     5:  42.38%  8.41% 77.67%
##     6:  42.66%  9.09% 76.85%
##     7:  41.70%  9.73% 74.55%
##     8:  42.04% 10.53% 74.11%
##     9:  44.05% 11.40% 76.99%
##    10:  42.79% 10.43% 75.44%
## At iteration 10

After run, save the results

result_dir <- "../result/"
if (!dir.exists(result_dir)) dir.create(result_dir, recursive = TRUE)
Query_output_results_scores <- as.data.frame(Query_output_results[[1]])

Change Oncoprotein directory and output file name for other maps

write.csv(Query_output_results_scores, paste0(result_dir, "results.csv"))

Create ROC curves (or save them to a PDF file, if preferred)

save_to_file = FALSE
if (save_to_file)
  pdf(file = paste0(result_dir, "KRAS_ROC.pdf"))
Query_output_results_scores <- Query_output_results[[1]]
Query_output_results_scores$label <- 0
Query_output_results_scores[Gold_Standard_in_Network_names, 2] <- 1
Query_output_results_scores <- na.omit(Query_output_results_scores)
pred <- prediction(Query_output_results_scores$Score, Query_output_results_scores$label)
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf, col = "black", xlim = c(0, 1), lwd = 6)

if (save_to_file)
  dev.off()

Create ROC curve to FPR < 0.05

if (save_to_file)
  pdf(file = paste0(result_dir, "KRAS_ROC_frp05.pdf"), height = 5, width = 5)
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf, col = "black", xlim = c(0, 0.05), lwd = 6)

if (save_to_file)
  dev.off()