TL;DR

This code block is not evaluated. Need a breakdown? Look at the following sections.

suppressWarnings(suppressMessages(require(netDx)))
suppressWarnings(suppressMessages(library(curatedTCGAData)))

# fetch data remotely
brca <- suppressMessages(curatedTCGAData("BRCA",c("mRNAArray"),FALSE))

# process input variables
staget <- sub("[abcd]","",sub("t","",colData(brca)$pathology_T_stage))
staget <- suppressWarnings(as.integer(staget))
colData(brca)$STAGE <- staget

pam50 <- colData(brca)$PAM50.mRNA
pam50[which(!pam50 %in% "Luminal A")] <- "notLumA"
pam50[which(pam50 %in% "Luminal A")] <- "LumA"
colData(brca)$pam_mod <- pam50

tmp <- colData(brca)$PAM50.mRNA
idx <- union(which(tmp %in% c("Normal-like","Luminal B","HER2-enriched")),
                    which(is.na(staget)))
pID <- colData(brca)$patientID
tokeep <- setdiff(pID, pID[idx])
brca <- brca[,tokeep,]

smp <- sampleMap(brca)
samps <- smp[which(smp$assay=="BRCA_mRNAArray-20160128"),]
# remove duplicate assays mapped to the same sample
notdup <- samps[which(!duplicated(samps$primary)),"colname"]
brca[[1]] <- suppressMessages(brca[[1]][,notdup])

# colData must have ID and STATUS columns
pID <- colData(brca)$patientID
colData(brca)$ID <- pID
colData(brca)$STATUS <- colData(brca)$pam_mod

# create grouping rules
groupList <- list()
# genes in mRNA data are grouped by pathways
pathList <- readPathways(fetchPathwayDefinitions("January",2018))
groupList[["BRCA_mRNAArray-20160128"]] <- pathList[1:3]
# clinical data is not grouped; each variable is its own feature
groupList[["clinical"]] <- list(
      age="patient.age_at_initial_pathologic_diagnosis",
       stage="STAGE"
)

# create function to tell netDx how to build features (PSN) from your data
makeNets <- function(dataList, groupList, netDir,...) {
    netList <- c() # initialize before is.null() check
    # make RNA nets (NOTE: the check for is.null() is important!)
    # (Pearson correlation)
    if (!is.null(groupList[["BRCA_mRNAArray-20160128"]])) { 
    netList <- makePSN_NamedMatrix(dataList[["BRCA_mRNAArray-20160128"]],
                rownames(dataList[["BRCA_mRNAArray-20160128"]]),
                groupList[["BRCA_mRNAArray-20160128"]],
                netDir,verbose=FALSE, 
                writeProfiles=TRUE,...) 
    }

    # make clinical nets (normalized difference)
    netList2 <- c()
    if (!is.null(groupList[["clinical"]])) {
    netList2 <- makePSN_NamedMatrix(dataList$clinical, 
        rownames(dataList$clinical),
        groupList[["clinical"]],netDir,
        simMetric="custom",customFunc=normDiff, # custom function
        writeProfiles=FALSE,
        sparsify=TRUE,verbose=TRUE,...)
    }
    netList <- c(unlist(netList),unlist(netList2))
    return(netList)
}

# run predictor 
set.seed(42) # make results reproducible
outDir <- paste(tempdir(),randAlphanumString(),
    "pred_output",sep=getFileSep())
# To see all messages, remove suppressMessages() and set logging="default".
# To keep all intermediate data, set keepAllData=TRUE
out <- buildPredictor(
      dataList=brca,groupList=groupList,
      makeNetFunc=makeNets,
      outDir=outDir, ## netDx requires absolute path
      numSplits=2L,featScoreMax=2L, featSelCutoff=1L,
      numCores=1L,logging="none",
      keepAllData=FALSE,debugMode=TRUE
   )

# collect results
numSplits <- 2
st <- unique(colData(brca)$STATUS)
acc <- c()         # accuracy
predList <- list() # prediction tables
featScores <- list() # feature scores per class
for (cur in unique(st)) featScores[[cur]] <- list()

for (k in 1:numSplits) { 
    pred <- out[[sprintf("Split%i",k)]][["predictions"]];
    # predictions table
    tmp <- pred[,c("ID","STATUS","TT_STATUS","PRED_CLASS",
                     sprintf("%s_SCORE",st))]
    predList[[k]] <- tmp 
    # accuracy
    acc <- c(acc, sum(tmp$PRED==tmp$STATUS)/nrow(tmp))
    # feature scores
    for (cur in unique(st)) {
       tmp <- out[[sprintf("Split%i",k)]][["featureScores"]][[cur]]
       colnames(tmp) <- c("PATHWAY_NAME","SCORE")
       featScores[[cur]][[sprintf("Split%i",k)]] <- tmp
    }
}

# plot ROC and PR curve, compute AUROC, AUPR
predPerf <- plotPerf(predList, predClasses=st)
# get table of feature scores for each split and patient label
featScores2 <- lapply(featScores, getNetConsensus)
# identify features that consistently perform well
featSelNet <- lapply(featScores2, function(x) {
    callFeatSel(x, fsCutoff=1, fsPctPass=0)
})

# prepare data for EnrichmentMap plotting of top-scoring features
Emap_res <- getEMapInput_many(featScores2,pathList,
    minScore=1,maxScore=2,pctPass=0,out$inputNets,verbose=FALSE)
gmtFiles <- list()
nodeAttrFiles <- list()

for (g in names(Emap_res)) {
    outFile <- paste(outDir,sprintf("%s_nodeAttrs.txt",g),sep=getFileSep())
    write.table(Emap_res[[g]][["nodeAttrs"]],file=outFile,
        sep="\t",col=TRUE,row=FALSE,quote=FALSE)
    nodeAttrFiles[[g]] <- outFile

    outFile <- paste(outDir,sprintf("%s.gmt",g),sep=getFileSep())
    conn <- suppressWarnings(
         suppressMessages(base::file(outFile,"w")))
    tmp <- Emap_res[[g]][["featureSets"]]
    gmtFiles[[g]] <- outFile

    for (cur in names(tmp)) {
        curr <- sprintf("%s\t%s\t%s", cur,cur,
            paste(tmp[[cur]],collapse="\t"))
        writeLines(curr,con=conn)
    }
close(conn)
}

# This step requires Cytoscape to be installed and running.
###plotEmap(gmtFiles[[1]],nodeAttrFiles[[1]],
###         groupClusters=TRUE, hideNodeLabels=TRUE)

# collect data for integrated PSN
featScores2 <- lapply(featScores, getNetConsensus)
featSelNet <- lapply(featScores2, function(x) {
    callFeatSel(x, fsCutoff=2, fsPctPass=1)
})
topPath <- gsub(".profile","",
        unique(unlist(featSelNet)))
topPath <- gsub("_cont.txt","",topPath)
# create groupList limited to top features
g2 <- list();
for (nm in names(groupList)) {
    cur <- groupList[[nm]]
    idx <- which(names(cur) %in% topPath)
    message(sprintf("%s: %i pathways", nm, length(idx)))
    if (length(idx)>0) g2[[nm]] <- cur[idx]
}

# calculates integrated PSN, calculates grouping statistics,
# and plots integrates PSN. Set plotCytoscape=TRUE if Cytoscape is running.
psn <- suppressMessages(
   plotIntegratedPatientNetwork(brca,
  groupList=g2, makeNetFunc=makeNets,
  aggFun="MEAN",prune_X=0.30,prune_useTop=TRUE,
  numCores=1L,calcShortestPath=TRUE,
  showStats=FALSE,
  verbose=FALSE, plotCytoscape=FALSE)
)

# Visualize integrated patient similarity network as a tSNE plot
tsne <- plot_tSNE(psn$patientSimNetwork_unpruned,colData(brca))

Introduction

In this example, we will build a binary breast tumour classifier from clinical data and gene expression data. We will use different rules to create features for each data layer. Specifically:

Feature scoring is performed over multiple random splits of the data into train and blind test partitions. Feature selected networks are those that consistently score highly across the multiple splits (e.g. those that score 9 out of 10 in >=70% of splits).

Conceptually, this is what the higher-level logic looks like for a cross-validation design. In the pseudocode example below, the predictor runs for 100 train/test splits. Within a split, features are scored from 0 to 10. Features scoring >=9 are used to predict labels on the held-out test set (20%).

(Note: these aren't real function calls; this block just serves to illustrate the concept of the design for our purposes)

numSplits <- 100     # num times to split data into train/blind test samples
featScoreMax <- 10   # num folds for cross-validation, also max score for a network
featSelCutoff <- 9
netScores <- list()  # collect <numSplits> set of netScores
perf <- list()       # collect <numSplits> set of test evaluations

for k in 1:numSplits
 [train, test] <- splitData(80:20) # split data using RNG seed
  featScores[[k]] <- scoreFeatures(train, featScoreMax)
 topFeat[[k]] <- applyFeatCutoff(featScores[[k]])
 perf[[k]] <- collectPerformance(topFeat[[k]], test)
end

Setup

suppressWarnings(suppressMessages(require(netDx)))

Data

In this example, we use curated data from The Cancer Genome Atlas, through the BioConductor curatedTCGAData package. The goal is to classify a breast tumour into either a Luminal A subtype or otherwise. The predictor will integrate clinical variables selected by the user, along with gene expression data.

Here we load the required packages and download clinical and gene expression data.

suppressMessages(library(curatedTCGAData))

Take a look at the available data without downloading any:

curatedTCGAData(diseaseCode="BRCA", assays="*",dry.run=TRUE)
## snapshotDate(): 2020-10-02
## See '?curatedTCGAData' for 'diseaseCode' and 'assays' inputs
##     ah_id                                      title file_size
## 1   EH584                       BRCA_CNASeq-20160128      0 Mb
## 2   EH585                       BRCA_CNASNP-20160128    9.8 Mb
## 3   EH586                       BRCA_CNVSNP-20160128    2.8 Mb
## 4   EH588             BRCA_GISTIC_AllByGene-20160128    1.3 Mb
## 5  EH2121                 BRCA_GISTIC_Peaks-20160128      0 Mb
## 6   EH589     BRCA_GISTIC_ThresholdedByGene-20160128    0.4 Mb
## 7  EH2122  BRCA_Methylation_methyl27-20160128_assays   63.2 Mb
## 8  EH2123      BRCA_Methylation_methyl27-20160128_se    0.4 Mb
## 9  EH2124 BRCA_Methylation_methyl450-20160128_assays 2613.2 Mb
## 10 EH2125     BRCA_Methylation_methyl450-20160128_se    6.1 Mb
## 11  EH593                 BRCA_miRNASeqGene-20160128    0.6 Mb
## 12  EH594                    BRCA_mRNAArray-20160128   27.3 Mb
## 13  EH595                     BRCA_Mutation-20160128    4.5 Mb
## 14  EH596              BRCA_RNASeq2GeneNorm-20160128   64.5 Mb
## 15  EH597                   BRCA_RNASeqGene-20160128     30 Mb
## 16  EH598                    BRCA_RPPAArray-20160128    1.6 Mb
##                    rdataclass rdatadateadded rdatadateremoved
## 1            RaggedExperiment     2017-10-10             <NA>
## 2            RaggedExperiment     2017-10-10             <NA>
## 3            RaggedExperiment     2017-10-10             <NA>
## 4        SummarizedExperiment     2017-10-10             <NA>
## 5  RangedSummarizedExperiment     2019-01-09             <NA>
## 6        SummarizedExperiment     2017-10-10             <NA>
## 7        SummarizedExperiment     2019-01-09             <NA>
## 8        SummarizedExperiment     2019-01-09             <NA>
## 9            RaggedExperiment     2019-01-09             <NA>
## 10       SummarizedExperiment     2019-01-09             <NA>
## 11       SummarizedExperiment     2017-10-10             <NA>
## 12       SummarizedExperiment     2017-10-10             <NA>
## 13           RaggedExperiment     2017-10-10             <NA>
## 14       SummarizedExperiment     2017-10-10             <NA>
## 15       SummarizedExperiment     2017-10-10             <NA>
## 16       SummarizedExperiment     2017-10-10             <NA>

We will work only with the mRNA data in this example:

brca <- suppressMessages(curatedTCGAData("BRCA",c("mRNAArray"),FALSE))

This next code block prepares the TCGA data. In practice you would do this once, and save the data before running netDx, but we run it here to see an end-to-end example.

staget <- sub("[abcd]","",sub("t","",colData(brca)$pathology_T_stage))
staget <- suppressWarnings(as.integer(staget))
colData(brca)$STAGE <- staget

pam50 <- colData(brca)$PAM50.mRNA
pam50[which(!pam50 %in% "Luminal A")] <- "notLumA"
pam50[which(pam50 %in% "Luminal A")] <- "LumA"
colData(brca)$pam_mod <- pam50

tmp <- colData(brca)$PAM50.mRNA
idx <- union(which(tmp %in% c("Normal-like","Luminal B","HER2-enriched")),
                    which(is.na(staget)))
pID <- colData(brca)$patientID
tokeep <- setdiff(pID, pID[idx])
brca <- brca[,tokeep,]

# remove duplicate assays mapped to the same sample
smp <- sampleMap(brca)
samps <- smp[which(smp$assay=="BRCA_mRNAArray-20160128"),]
notdup <- samps[which(!duplicated(samps$primary)),"colname"]
brca[[1]] <- suppressMessages(brca[[1]][,notdup])
## harmonizing input:
##   removing 44 sampleMap rows with 'colname' not in colnames of experiments

The important thing is to create ID and STATUS columns in the sample metadata table. netDx uses these to get the patient identifiers and labels, respectively.

pID <- colData(brca)$patientID
colData(brca)$ID <- pID
colData(brca)$STATUS <- colData(brca)$pam_mod

Design custom patient similarity networks (features)

netDx allows the user to define a custom function that takes patient data and variable groupings as input, and returns a set of patient similarity networks (PSN) as output. The user can customize what datatypes are used, how they are grouped, and what defines patient similarity for a given datatype.

When running the predictor (next section), the user simply passes this custom function as an input variable; i.e. the makeNetFunc parameter when calling buildPredictor().

Note: While netDx provides a high degree of flexibility in achieving your design of choice, it is up to the user to ensure that the design, i.e. the similarity metric and variable groupings, is appropriate for your application. Domain knowledge is almost likely required for good design.

netDx requires that this function take some generic parameters as input. These include:

dataList

Here the BRCA data is already provided to us as a MultiAssayExperiment object:

summary(brca)
##               Length                Class                 Mode 
##                    1 MultiAssayExperiment                   S4

groupList

This object tells the predictor how to group units when constructing a network. For examples, genes may be grouped into a network representing a pathway. This object is a list; the names match those of dataList while each value is itself a list and reflects a potential network.

groupList <- list()

# genes in mRNA data are grouped by pathways
pathList <- readPathways(fetchPathwayDefinitions("January",2018))
## ---------------------------------------
## Fetching http://download.baderlab.org/EM_Genesets/January_01_2018/Human/symbol/Human_AllPathways_January_01_2018_symbol.gmt
## File: 12bc4b4f1937_Human_AllPathways_January_01_2018_symbol.gmt
## Read 3028 pathways in total, internal list has 3009 entries
##  FILTER: sets with num genes in [10, 200]
##    => 971 pathways excluded
##    => 2038 left
groupList[["BRCA_mRNAArray-20160128"]] <- pathList[1:3]
# clinical data is not grouped; each variable is its own feature
groupList[["clinical"]] <- list(
      age="patient.age_at_initial_pathologic_diagnosis",
       stage="STAGE"
)

So the groupList variable has one entry per data layer:

summary(groupList)
##                         Length Class  Mode
## BRCA_mRNAArray-20160128 3      -none- list
## clinical                2      -none- list

Each entry contains a list, with one entry per feature. Here we have 3 pathway-level features for mRNA and two variable-level features for clinical data.

For example, here are the networks to be created with RNA data. Genes corresponding to pathways are to be grouped into individual network. Such a groupList would create pathway-level networks:

groupList[["BRCA_mRNAArray-20160128"]][1:3]
## $UREA_CYCLE
##  [1] "SLC25A15" "CPS1"     "ASL"      "ARG2"     "SLC25A2"  "OTC"     
##  [7] "NMRAL1"   "NAGS"     "ASS1"     "ARG1"    
## 
## $`CDP-DIACYLGLYCEROL_BIOSYNTHESIS_I`
##  [1] "AGPAT1" "GPD2"   "ABHD5"  "GPAT2"  "CDS1"   "LPCAT3" "LPCAT4" "CDS2"  
##  [9] "AGPAT6" "AGPAT5" "MBOAT7" "AGPAT9" "LCLAT1" "MBOAT2" "AGPAT4" "GPAM"  
## [17] "AGPAT3" "AGPAT2"
## 
## $`SUPERPATHWAY_OF_D-_I_MYO__I_-INOSITOL__1,4,5_-TRISPHOSPHATE_METABOLISM`
##  [1] "IPMK"   "INPP5B" "INPP5F" "INPP5D" "MINPP1" "INPP5A" "ITPKA"  "OCRL"  
##  [9] "ITPKC"  "ITPKB"  "SYNJ2"  "INPP5J" "INPP5K" "PTEN"   "IMPA2"  "INPP1" 
## [17] "SYNJ1"  "INPPL1" "IMPA1"  "IMPAD1"

For clinical data, we want to keep each variable as its own network:

head(groupList[["clinical"]])
## $age
## [1] "patient.age_at_initial_pathologic_diagnosis"
## 
## $stage
## [1] "STAGE"

Define patient similarity for each network

This function is defined by the user and tells the predictor how to create networks from the provided input data.

This function requires dataList,groupList, and netDir as input variables. The residual ... parameter is to pass additional variables to makePSN_NamedMatrix(), notably numCores (number of parallel jobs).

In this particular example, the custom similarity function does the following:

  1. Creates pathway-level networks from RNA data using the default Pearson correlation measure makePSN_NamedMatrix(writeProfiles=TRUE,...)
  2. Creates variable-level networks from clinical data using a custom similarity function of normalized difference: makePSN_NamedMatrix(writeProfiles=FALSE,simMetric="custom",customFunc=normDiff).
makeNets <- function(dataList, groupList, netDir,...) {
    netList <- c() # initialize before is.null() check
    # make RNA nets (NOTE: the check for is.null() is important!)
    # (Pearson correlation)
    if (!is.null(groupList[["BRCA_mRNAArray-20160128"]])) { 
    netList <- makePSN_NamedMatrix(dataList[["BRCA_mRNAArray-20160128"]],
                rownames(dataList[["BRCA_mRNAArray-20160128"]]),
                groupList[["BRCA_mRNAArray-20160128"]],
                netDir,verbose=FALSE, 
                writeProfiles=TRUE,...) 
    }

    # make clinical nets (normalized difference)
    netList2 <- c()
    if (!is.null(groupList[["clinical"]])) {
    netList2 <- makePSN_NamedMatrix(dataList$clinical, 
        rownames(dataList$clinical),
        groupList[["clinical"]],netDir,
        simMetric="custom",customFunc=normDiff, # custom function
        writeProfiles=FALSE,
        sparsify=TRUE,verbose=TRUE,...)
    }
    netList <- c(unlist(netList),unlist(netList2))
    return(netList)
}

Note: dataList and groupList are generic containers that can contain whatever object the user requires to create PSN. The custom function gives the user complete flexibility in feature design.

Build predictor

Finally we call the function that runs the netDx predictor. We provide:

Change numCores to match the number of cores available on your machine for parallel processing.

The call below runs 2 train/test splits. Within each split, it:

These are unrealistically low values set so the example will run fast. In practice a good starting point is featScoreMax=10, featSelCutoff=9 and numSplits=100, but these parameters depend on the sample sizes in the dataset and heterogeneity of the samples.

set.seed(42) # make results reproducible
outDir <- paste(tempdir(),randAlphanumString(),
    "pred_output",sep=getFileSep())
# set keepAllData=TRUE to not delete at the end of the predictor run.
# This can be useful for debugging.
out <- buildPredictor(
      dataList=brca,groupList=groupList,
      makeNetFunc=makeNets,
      outDir=outDir, ## netDx requires absolute path
      numSplits=2L,featScoreMax=2L,
      featSelCutoff=1L,
      numCores=1L,debugMode=TRUE,
      logging="none")
## Predictor started at:
## 2020-12-09 21:02:26
## Pearson similarity chosen - enforcing min. 5 patients per net.
## Making Java call
## java -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.core.evaluation.ProfileToNetworkDriver -proftype continuous -cor PEARSON -threshold off -maxmissing 100.0 -in /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/tmp/profiles/1.1.profile -out /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/tmp/INTERACTIONS/1.1.txt -syn /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/tmp/1.synonyms -keepAllTies -limitTies
## Making Java call
## java -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.core.evaluation.ProfileToNetworkDriver -proftype continuous -cor PEARSON -threshold off -maxmissing 100.0 -in /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/tmp/profiles/1.2.profile -out /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/tmp/INTERACTIONS/1.2.txt -syn /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/tmp/1.synonyms -keepAllTies -limitTies
## Making Java call
## java -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.core.evaluation.ProfileToNetworkDriver -proftype continuous -cor PEARSON -threshold off -maxmissing 100.0 -in /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/tmp/profiles/1.3.profile -out /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/tmp/INTERACTIONS/1.3.txt -syn /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/tmp/1.synonyms -keepAllTies -limitTies
## java -Xmx10G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.mediator.lucene.exporter.Generic2LuceneExporter /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/tmp/db.cfg /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/tmp /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/tmp/colours.txt
## java -Xmx10G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.apps.CacheBuilder -cachedir cache -indexDir . -networkDir /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/tmp/INTERACTIONS -log /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/tmp/test.log
##  Scoring features
## Java 8 detected
## java -d64 -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.plugin.apps.QueryRunner --data /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/dataset --in flat --out flat --threads 1 --results /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/LumA/GM_results /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/LumA/GM_results/CV_1.query /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/LumA/GM_results/CV_2.query --netdx-flag true
## QueryRunner time taken: 2.1 s
##  Scoring features
## Java 8 detected
## java -d64 -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.plugin.apps.QueryRunner --data /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/dataset --in flat --out flat --threads 1 --results /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/notLumA/GM_results /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/notLumA/GM_results/CV_1.query /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/notLumA/GM_results/CV_2.query --netdx-flag true
## QueryRunner time taken: 2.0 s
## Pearson similarity chosen - enforcing min. 5 patients per net.
## Making Java call
## java -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.core.evaluation.ProfileToNetworkDriver -proftype continuous -cor PEARSON -threshold off -maxmissing 100.0 -in /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/LumA/tmp/profiles/1.1.profile -out /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/LumA/tmp/INTERACTIONS/1.1.txt -syn /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/LumA/tmp/1.synonyms -keepAllTies -limitTies
## Making Java call
## java -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.core.evaluation.ProfileToNetworkDriver -proftype continuous -cor PEARSON -threshold off -maxmissing 100.0 -in /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/LumA/tmp/profiles/1.2.profile -out /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/LumA/tmp/INTERACTIONS/1.2.txt -syn /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/LumA/tmp/1.synonyms -keepAllTies -limitTies
## java -Xmx10G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.mediator.lucene.exporter.Generic2LuceneExporter /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/LumA/tmp/db.cfg /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/LumA/tmp /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/LumA/tmp/colours.txt
## java -Xmx10G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.apps.CacheBuilder -cachedir cache -indexDir . -networkDir /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/LumA/tmp/INTERACTIONS -log /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/LumA/tmp/test.log
## java -d64 -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.plugin.apps.QueryRunner --data /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/LumA/dataset --in flat --out flat --threads 1 --results /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/LumA /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/LumA/LumA_query --netdx-flag true
## Pearson similarity chosen - enforcing min. 5 patients per net.
## Making Java call
## java -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.core.evaluation.ProfileToNetworkDriver -proftype continuous -cor PEARSON -threshold off -maxmissing 100.0 -in /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/notLumA/tmp/profiles/1.1.profile -out /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/notLumA/tmp/INTERACTIONS/1.1.txt -syn /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/notLumA/tmp/1.synonyms -keepAllTies -limitTies
## Making Java call
## java -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.core.evaluation.ProfileToNetworkDriver -proftype continuous -cor PEARSON -threshold off -maxmissing 100.0 -in /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/notLumA/tmp/profiles/1.2.profile -out /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/notLumA/tmp/INTERACTIONS/1.2.txt -syn /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/notLumA/tmp/1.synonyms -keepAllTies -limitTies
## java -Xmx10G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.mediator.lucene.exporter.Generic2LuceneExporter /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/notLumA/tmp/db.cfg /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/notLumA/tmp /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/notLumA/tmp/colours.txt
## java -Xmx10G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.apps.CacheBuilder -cachedir cache -indexDir . -networkDir /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/notLumA/tmp/INTERACTIONS -log /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/notLumA/tmp/test.log
## java -d64 -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.plugin.apps.QueryRunner --data /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/notLumA/dataset --in flat --out flat --threads 1 --results /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/notLumA /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng1/notLumA/notLumA_query --netdx-flag true
## Pearson similarity chosen - enforcing min. 5 patients per net.
## Making Java call
## java -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.core.evaluation.ProfileToNetworkDriver -proftype continuous -cor PEARSON -threshold off -maxmissing 100.0 -in /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/tmp/profiles/1.1.profile -out /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/tmp/INTERACTIONS/1.1.txt -syn /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/tmp/1.synonyms -keepAllTies -limitTies
## Making Java call
## java -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.core.evaluation.ProfileToNetworkDriver -proftype continuous -cor PEARSON -threshold off -maxmissing 100.0 -in /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/tmp/profiles/1.2.profile -out /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/tmp/INTERACTIONS/1.2.txt -syn /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/tmp/1.synonyms -keepAllTies -limitTies
## Making Java call
## java -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.core.evaluation.ProfileToNetworkDriver -proftype continuous -cor PEARSON -threshold off -maxmissing 100.0 -in /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/tmp/profiles/1.3.profile -out /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/tmp/INTERACTIONS/1.3.txt -syn /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/tmp/1.synonyms -keepAllTies -limitTies
## java -Xmx10G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.mediator.lucene.exporter.Generic2LuceneExporter /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/tmp/db.cfg /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/tmp /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/tmp/colours.txt
## java -Xmx10G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.apps.CacheBuilder -cachedir cache -indexDir . -networkDir /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/tmp/INTERACTIONS -log /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/tmp/test.log
##  Scoring features
## Java 8 detected
## java -d64 -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.plugin.apps.QueryRunner --data /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/dataset --in flat --out flat --threads 1 --results /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/LumA/GM_results /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/LumA/GM_results/CV_1.query /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/LumA/GM_results/CV_2.query --netdx-flag true
## QueryRunner time taken: 1.9 s
##  Scoring features
## Java 8 detected
## java -d64 -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.plugin.apps.QueryRunner --data /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/dataset --in flat --out flat --threads 1 --results /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/notLumA/GM_results /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/notLumA/GM_results/CV_1.query /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/notLumA/GM_results/CV_2.query --netdx-flag true
## QueryRunner time taken: 1.4 s
## Pearson similarity chosen - enforcing min. 5 patients per net.
## Making Java call
## java -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.core.evaluation.ProfileToNetworkDriver -proftype continuous -cor PEARSON -threshold off -maxmissing 100.0 -in /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/LumA/tmp/profiles/1.1.profile -out /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/LumA/tmp/INTERACTIONS/1.1.txt -syn /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/LumA/tmp/1.synonyms -keepAllTies -limitTies
## Making Java call
## java -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.core.evaluation.ProfileToNetworkDriver -proftype continuous -cor PEARSON -threshold off -maxmissing 100.0 -in /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/LumA/tmp/profiles/1.2.profile -out /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/LumA/tmp/INTERACTIONS/1.2.txt -syn /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/LumA/tmp/1.synonyms -keepAllTies -limitTies
## java -Xmx10G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.mediator.lucene.exporter.Generic2LuceneExporter /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/LumA/tmp/db.cfg /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/LumA/tmp /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/LumA/tmp/colours.txt
## java -Xmx10G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.apps.CacheBuilder -cachedir cache -indexDir . -networkDir /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/LumA/tmp/INTERACTIONS -log /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/LumA/tmp/test.log
## java -d64 -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.plugin.apps.QueryRunner --data /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/LumA/dataset --in flat --out flat --threads 1 --results /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/LumA /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/LumA/LumA_query --netdx-flag true
## Pearson similarity chosen - enforcing min. 5 patients per net.
## Making Java call
## java -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.core.evaluation.ProfileToNetworkDriver -proftype continuous -cor PEARSON -threshold off -maxmissing 100.0 -in /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/notLumA/tmp/profiles/1.1.profile -out /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/notLumA/tmp/INTERACTIONS/1.1.txt -syn /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/notLumA/tmp/1.synonyms -keepAllTies -limitTies
## Making Java call
## java -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.core.evaluation.ProfileToNetworkDriver -proftype continuous -cor PEARSON -threshold off -maxmissing 100.0 -in /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/notLumA/tmp/profiles/1.2.profile -out /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/notLumA/tmp/INTERACTIONS/1.2.txt -syn /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/notLumA/tmp/1.synonyms -keepAllTies -limitTies
## java -Xmx10G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.mediator.lucene.exporter.Generic2LuceneExporter /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/notLumA/tmp/db.cfg /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/notLumA/tmp /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/notLumA/tmp/colours.txt
## java -Xmx10G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.engine.apps.CacheBuilder -cachedir cache -indexDir . -networkDir /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/notLumA/tmp/INTERACTIONS -log /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/notLumA/tmp/test.log
## java -d64 -Xmx4G -cp /home/biocbuild/.cache/netDx/12bc3d62d151_genemania-netdx.jar org.genemania.plugin.apps.QueryRunner --data /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/notLumA/dataset --in flat --out flat --threads 1 --results /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/notLumA /tmp/Rtmpltd2HL/QEAYJ1252R/pred_output/rng2/notLumA/notLumA_query --netdx-flag true
## Predictor completed at:
## 2020-12-09 21:06:57

Examine output

The results are stored in the list object returned by the buildPredictor() call. This list contains:

summary(out)
##           Length Class  Mode     
## inputNets 10     -none- character
## Split1     4     -none- list     
## Split2     4     -none- list
summary(out$Split1)
##                 Length Class      Mode   
## featureScores      2   -none-     list   
## featureSelected    2   -none-     list   
## predictions     2692   data.frame list   
## accuracy           1   -none-     numeric

Reformat results for further analysis

This code collects different components of model output to examine the results.

numSplits <- 2
st <- unique(colData(brca)$STATUS)
acc <- c()         # accuracy
predList <- list() # prediction tables

featScores <- list() # feature scores per class
for (cur in unique(st)) featScores[[cur]] <- list()

for (k in 1:numSplits) { 
    pred <- out[[sprintf("Split%i",k)]][["predictions"]];
    # predictions table
    tmp <- pred[,c("ID","STATUS","TT_STATUS","PRED_CLASS",
                     sprintf("%s_SCORE",st))]
    predList[[k]] <- tmp 
    # accuracy
    acc <- c(acc, sum(tmp$PRED==tmp$STATUS)/nrow(tmp))
    # feature scores
    for (cur in unique(st)) {
       tmp <- out[[sprintf("Split%i",k)]][["featureScores"]][[cur]]
       colnames(tmp) <- c("PATHWAY_NAME","SCORE")
       featScores[[cur]][[sprintf("Split%i",k)]] <- tmp
    }
}

Compute model performance

After compiling the data above, plot accuracy for each train/test split:

print(acc)
## [1] 0.7462687 0.7761194

Create a ROC curve, a precision-recall curve, and plot average AUROC and AUPR:

predPerf <- plotPerf(predList, predClasses=st)

plot of chunk unnamed-chunk-19

Examine feature scores and consistently high-scoring features

Use getNetConsensus() to convert the list data structure into a single table, one per patient label. The rows show train/test splits and the columns show features that consistently perform well.

We then use callFeatSel() to identify features that consistently perform well across the various train/test splits. Because this is a toy example, we set the bar very low to get some features. Here we accept a feature if it scores 1 or higher (fsCutoff=1) in even one split (fsPctPass=0.05), setting the latter to a low positive fraction.

featScores2 <- lapply(featScores, getNetConsensus)
summary(featScores2)
##         Length Class      Mode
## LumA    3      data.frame list
## notLumA 3      data.frame list
head(featScores2[["LumA"]])
##                                                                     PATHWAY_NAME
## 1                                      CDP-DIACYLGLYCEROL_BIOSYNTHESIS_I.profile
## 2 SUPERPATHWAY_OF_D-_I_MYO__I_-INOSITOL__1.4.5_-TRISPHOSPHATE_METABOLISM.profile
## 3                                                             UREA_CYCLE.profile
## 4                                                                   age_cont.txt
## 5                                                                 stage_cont.txt
##   Split1 Split2
## 1      2      2
## 2      2      2
## 3      2      2
## 4      1      1
## 5     NA      1

In practice, a recommended setting is fsCutoff=9 and fsPctPass=0.7 to get features that score at least 9 (out of 10) in at least 70% of the train/test splits.

featSelNet <- lapply(featScores2, function(x) {
    callFeatSel(x, fsCutoff=1, fsPctPass=0)
})
print(head(featScores2[["LumA"]]))
##                                                                     PATHWAY_NAME
## 1                                      CDP-DIACYLGLYCEROL_BIOSYNTHESIS_I.profile
## 2 SUPERPATHWAY_OF_D-_I_MYO__I_-INOSITOL__1.4.5_-TRISPHOSPHATE_METABOLISM.profile
## 3                                                             UREA_CYCLE.profile
## 4                                                                   age_cont.txt
## 5                                                                 stage_cont.txt
##   Split1 Split2
## 1      2      2
## 2      2      2
## 3      2      2
## 4      1      1
## 5     NA      1

Visualize EnrichmentMap

An EnrichmentMap is a network-based visualization of pathway connectivity and is used in netDx to visualize themes in predictive pathway-based features. It is used in conjunction with AutoAnnotate to identify clusters, and apply auto-generated labels to these. For more information, see the EnrichmentMap website at baderlab.org.

Use getEMapInput_many() to create the input that helps generate the EnrichmentMap in Cytoscape.

Emap_res <- getEMapInput_many(featScores2,pathList,
    minScore=1,maxScore=2,pctPass=0,out$inputNets,verbose=FALSE)

Write the results to files that Cytoscape can read in:

gmtFiles <- list()
nodeAttrFiles <- list()

for (g in names(Emap_res)) {
    outFile <- paste(outDir,sprintf("%s_nodeAttrs.txt",g),sep=getFileSep())
    write.table(Emap_res[[g]][["nodeAttrs"]],file=outFile,
        sep="\t",col=TRUE,row=FALSE,quote=FALSE)
    nodeAttrFiles[[g]] <- outFile

    outFile <- paste(outDir,sprintf("%s.gmt",g),sep=getFileSep())
    conn <- suppressWarnings(
         suppressMessages(base::file(outFile,"w")))
    tmp <- Emap_res[[g]][["featureSets"]]
    gmtFiles[[g]] <- outFile

    for (cur in names(tmp)) {
        curr <- sprintf("%s\t%s\t%s", cur,cur,
            paste(tmp[[cur]],collapse="\t"))
        writeLines(curr,con=conn)
    }
close(conn)
}

Finally, plot the EnrichmentMap. This step requires Cytoscape to be installed, along with the EnrichmentMap and AutoAnnotate apps. It also requires the Cytoscape application to be open and running on the machine running the code. This block is commented out for automatic builds on BioConductor, but a screenshot of the intended result is shown below.

###plotEmap(gmtFiles[[1]],nodeAttrFiles[[1]],
###         groupClusters=TRUE, hideNodeLabels=TRUE)

This example EnrichmentMap isn't terribly exciting because of the low number of pathway features permitted, the upper bound on feature selection scores and low number of train/test splits. But hopefully it serves its purpose to be illustrative.

EnrichmentMap generated from example in this vignette. The small number of nodes reflects the limited number of pathways provided to the model, and also reduced parameter values for model building.

Here is an example of an EnrichmentMap generated by running the above predictor with more real-world parameter values, and all available pathways:

EnrichmentMap from the same data but using all pathways, more train/test splits and higher range of feature scores.

Visualize integrated patient similarity network based on top features

We can apply a threshold to define predictive features, and integrate these into a single patient similarity network. Such a network is useful for downstream operations such as ascertaining whether or not classes are significantly separated and visualization.

Here we define predictive features as those scoring 3 out of 3 in all train/test splits.

featScores2 <- lapply(featScores, getNetConsensus)
featSelNet <- lapply(featScores2, function(x) {
    callFeatSel(x, fsCutoff=2, fsPctPass=1)
})

We can examine the features:

print(featSelNet)
## $LumA
## [1] "CDP-DIACYLGLYCEROL_BIOSYNTHESIS_I.profile"                                     
## [2] "SUPERPATHWAY_OF_D-_I_MYO__I_-INOSITOL__1.4.5_-TRISPHOSPHATE_METABOLISM.profile"
## [3] "UREA_CYCLE.profile"                                                            
## 
## $notLumA
## [1] "SUPERPATHWAY_OF_D-_I_MYO__I_-INOSITOL__1.4.5_-TRISPHOSPHATE_METABOLISM.profile"
## [2] "UREA_CYCLE.profile"

Create a new groupList limited to top features:

topPath <- gsub(".profile","",
        unique(unlist(featSelNet)))
topPath <- gsub("_cont.txt","",topPath)
# create groupList limited to top features
g2 <- list();
for (nm in names(groupList)) {
    cur <- groupList[[nm]]
    idx <- which(names(cur) %in% topPath)
    message(sprintf("%s: %i pathways", nm, length(idx)))
    if (length(idx)>0) g2[[nm]] <- cur[idx]
}
## BRCA_mRNAArray-20160128: 2 pathways
## clinical: 0 pathways

Plot the integrated patient network based on the features selected above. Note that at this stage, the similarity measure is inverted into a dissimilarity measure so that nodes with greater similarity are closer (have smaller distance or dissimilarity) in the final network.

In the example below, the networks are integrated by taking the mean of the edge weights (aggFun="MEAN"). For the plotting we retain only the top 5% of the strongest edges (topX=0.05).

By setting calcShortestPath=TRUE, the function will also compute the pairwise shortest path for within- and across-group nodes. The result is shown as a set of violin plots and a one-sided Wilcoxon-Mann-Whitney test is used to assign significance.

As with plotEMap(), this method must be run on a computer with Cytoscape installed and running. For the purposes of this example, plotCytoscape is set to FALSE and a screenshot of the resulting network is provided below. To plot in Cytoscape, set plotCytoscape=TRUE.

psn <- suppressMessages(
   plotIntegratedPatientNetwork(brca,
  groupList=g2, makeNetFunc=makeNets,
  aggFun="MEAN",prune_pctX=0.30,prune_useTop=TRUE,
  numCores=1L,calcShortestPath=TRUE,
  showStats=FALSE,
  verbose=FALSE, plotCytoscape=FALSE)
)
## Warning in dir.create(paste(netDir, "profiles", sep = fsep)): '/tmp/Rtmpltd2HL/
## profiles' already exists

plot of chunk unnamed-chunk-28

Patient network after integrating features that scored 2 out of 2 in all train-test splits. For visualization only the top 10% strongest edges are shown. Nodes are patients, and edges are average distance across all features passing feature selection. Green indicates "LumA" status and orange indicates "nonLumA" status.

The integrated PSN can also be visualized as a tSNE plot:

tsne <- plot_tSNE(psn$patientSimNetwork_unpruned,colData(brca))
## * Making symmetric matrix
## * Running tSNE
## * Plotting

plot of chunk unnamed-chunk-29

summary(tsne)
##                     Length Class  Mode   
## N                     1    -none- numeric
## Y                   662    -none- numeric
## costs               331    -none- numeric
## itercosts            20    -none- numeric
## origD                 1    -none- numeric
## perplexity            1    -none- numeric
## theta                 1    -none- numeric
## max_iter              1    -none- numeric
## stop_lying_iter       1    -none- numeric
## mom_switch_iter       1    -none- numeric
## momentum              1    -none- numeric
## final_momentum        1    -none- numeric
## eta                   1    -none- numeric
## exaggeration_factor   1    -none- numeric
class(tsne)
## [1] "list"

sessionInfo

sessionInfo()
## R version 4.0.3 (2020-10-10)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 18.04.5 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.12-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.12-bioc/R/lib/libRlapack.so
## 
## locale:
##  [1] LC_CTYPE=C                 LC_NUMERIC=C              
##  [3] LC_TIME=C                  LC_COLLATE=C              
##  [5] LC_MONETARY=C              LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats4    parallel  stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] curatedTCGAData_1.12.0      MultiAssayExperiment_1.16.0
##  [3] SummarizedExperiment_1.20.0 GenomicRanges_1.42.0       
##  [5] GenomeInfoDb_1.26.2         IRanges_2.24.0             
##  [7] S4Vectors_0.28.1            MatrixGenerics_1.2.0       
##  [9] matrixStats_0.57.0          netDx_1.2.2                
## [11] bigmemory_4.5.36            Biobase_2.50.0             
## [13] BiocGenerics_0.36.0        
## 
## loaded via a namespace (and not attached):
##   [1] uuid_0.1-4                    AnnotationHub_2.22.0         
##   [3] BiocFileCache_1.14.0          NMF_0.23.0                   
##   [5] plyr_1.8.6                    igraph_1.2.6                 
##   [7] RCy3_2.10.2                   lazyeval_0.2.2               
##   [9] splines_4.0.3                 entropy_1.2.1                
##  [11] BiocParallel_1.24.1           rncl_0.8.4                   
##  [13] ggplot2_3.3.2                 gridBase_0.4-7               
##  [15] scater_1.18.3                 digest_0.6.27                
##  [17] htmltools_0.5.0               foreach_1.5.1                
##  [19] viridis_0.5.1                 magrittr_2.0.1               
##  [21] memoise_1.1.0                 cluster_2.1.0                
##  [23] doParallel_1.0.16             ROCR_1.0-11                  
##  [25] limma_3.46.0                  annotate_1.68.0              
##  [27] R.utils_2.10.1                prettyunits_1.1.1            
##  [29] colorspace_2.0-0              blob_1.2.1                   
##  [31] rappdirs_0.3.1                xfun_0.19                    
##  [33] dplyr_1.0.2                   crayon_1.3.4                 
##  [35] RCurl_1.98-1.2                bigmemory.sri_0.1.3          
##  [37] graph_1.68.0                  genefilter_1.72.0            
##  [39] phylobase_0.8.10              survival_3.2-7               
##  [41] iterators_1.0.13              ape_5.4-1                    
##  [43] glue_1.4.2                    registry_0.5-1               
##  [45] gtable_0.3.0                  zlibbioc_1.36.0              
##  [47] XVector_0.30.0                DelayedArray_0.16.0          
##  [49] BiocSingular_1.6.0            kernlab_0.9-29               
##  [51] Rhdf5lib_1.12.0               shape_1.4.5                  
##  [53] SingleCellExperiment_1.12.0   HDF5Array_1.18.0             
##  [55] scales_1.1.1                  DBI_1.1.0                    
##  [57] edgeR_3.32.0                  rngtools_1.5                 
##  [59] Rcpp_1.0.5                    viridisLite_0.3.0            
##  [61] xtable_1.8-4                  progress_1.2.2               
##  [63] bit_4.0.4                     rsvd_1.0.3                   
##  [65] glmnet_4.0-2                  netSmooth_1.10.0             
##  [67] httr_1.4.2                    RColorBrewer_1.1-2           
##  [69] ellipsis_0.3.1                farver_2.0.3                 
##  [71] pkgconfig_2.0.3               XML_3.99-0.5                 
##  [73] R.methodsS3_1.8.1             scuttle_1.0.3                
##  [75] dbplyr_2.0.0                  locfit_1.5-9.4               
##  [77] RJSONIO_1.3-1.4               labeling_0.4.2               
##  [79] later_1.1.0.1                 howmany_0.3-1                
##  [81] tidyselect_1.1.0              rlang_0.4.9                  
##  [83] softImpute_1.4                reshape2_1.4.4               
##  [85] AnnotationDbi_1.52.0          BiocVersion_3.12.0           
##  [87] munsell_0.5.0                 tools_4.0.3                  
##  [89] ExperimentHub_1.16.0          generics_0.1.0               
##  [91] RSQLite_2.2.1                 ade4_1.7-16                  
##  [93] fastmap_1.0.1                 evaluate_0.14                
##  [95] stringr_1.4.0                 yaml_2.2.1                   
##  [97] knitr_1.30                    bit64_4.0.5                  
##  [99] purrr_0.3.4                   nlme_3.1-150                 
## [101] sparseMatrixStats_1.2.0       mime_0.9                     
## [103] R.oo_1.24.0                   pracma_2.2.9                 
## [105] xml2_1.3.2                    compiler_4.0.3               
## [107] interactiveDisplayBase_1.28.0 beeswarm_0.2.3               
## [109] curl_4.3                      tibble_3.0.4                 
## [111] RNeXML_2.4.5                  stringi_1.5.3                
## [113] highr_0.8                     RSpectra_0.16-0              
## [115] lattice_0.20-41               Matrix_1.2-18                
## [117] vctrs_0.3.5                   pillar_1.4.7                 
## [119] lifecycle_0.2.0               rhdf5filters_1.2.0           
## [121] BiocManager_1.30.10           combinat_0.0-8               
## [123] zinbwave_1.12.0               BiocNeighbors_1.8.2          
## [125] data.table_1.13.4             bitops_1.0-6                 
## [127] irlba_2.3.3                   httpuv_1.5.4                 
## [129] R6_2.5.0                      promises_1.1.1               
## [131] gridExtra_2.3                 vipor_0.4.5                  
## [133] codetools_0.2-18              MASS_7.3-53                  
## [135] assertthat_0.2.1              rhdf5_2.34.0                 
## [137] pkgmaker_0.32.2               withr_2.3.0                  
## [139] GenomeInfoDbData_1.2.4        locfdr_1.1-8                 
## [141] hms_0.5.3                     grid_4.0.3                   
## [143] beachmat_2.6.2                tidyr_1.1.2                  
## [145] DelayedMatrixStats_1.12.1     Rtsne_0.15                   
## [147] shiny_1.5.0                   clusterExperiment_2.10.0     
## [149] ggbeeswarm_0.6.0