## ----setup, echo=FALSE, results="hide"----------------------------------------
knitr::opts_chunk$set(
    tidy = FALSE,
    cache = FALSE,
    dev = "png",
    message = FALSE, error = FALSE, warning = TRUE)

## ----install-pinpath, message = FALSE, warning = FALSE, eval=FALSE------------
# if (!requireNamespace("BiocManager", quietly=TRUE))
#     install.packages("BiocManager")
# 
# BiocManager::install("PinPath")

## ----install-others, message = FALSE, warning = FALSE, eval=FALSE-------------
# library(PinPath)
# library(org.Hs.eg.db)

## ----dataset, message = FALSE, warning = FALSE--------------------------------
lung_expr <- read.csv(
    system.file("extdata","data-lung-cancer.csv", package ="PinPath"), 
    stringsAsFactors = FALSE)

## ----significance, results = 'asis'-------------------------------------------
lung_expr$Significant <- ifelse(lung_expr$adj.P.Value < 0.05, "Yes", "No")

## ----default-color-values-----------------------------------------------------
colorList <- PinPath::defaultColorList(lung_expr[,c("log2FC", "Significant")])

## ----modify-significant-color-------------------------------------------------
colorList[["Significant"]]$Color <- c(
    "Yes" = "green",
    "No" = "white")

## ----modify-log2FC-color------------------------------------------------------
colorList[["log2FC"]]$ColorVal <- c(
    "MinVal" = -1.5,
    "MidVal" = 0,
    "MaxVal" = 1.5)

## ----plot-pathway, message = FALSE, warning = FALSE---------------------------
# Select pathway
pathway_id <- "hsa05207"
infile <- BiocFileCache::bfcrpath(
    BiocFileCache::BiocFileCache(),
    paste0("https://rest.kegg.jp/get/",pathway_id,"/kgml"))

# Plot pathway
pathVis <- PinPath::drawKGML(
    infile = infile,
    annGenes = "org.Hs.eg.db",
    inputDB = "ENSEMBL",
    featureIDs = lung_expr$GeneID,
    colorVar = lung_expr[,c("log2FC", "Significant")],
    colorList = colorList,
    nodeTable = TRUE,
    legend = TRUE,
    openFile = FALSE) # <-- set to TRUE to open the image automatically

## ----plot-network, message = FALSE, warning = FALSE---------------------------
pathVis <- PinPath::KGML2Network(
    infile = infile,
    annGenes = "org.Hs.eg.db",
    inputDB = "ENSEMBL",
    featureIDs = lung_expr$GeneID,
    colorVar = lung_expr[,c("log2FC", "Significant")],
    colorList = colorList,
    nodeTable = TRUE,
    legend = FALSE,
    openFile = FALSE) # <-- set to TRUE to open the image automatically

## ----sessionInfo--------------------------------------------------------------
sessionInfo()

