---
title: "Pipeline DAG"
format:
  html:
    toc: true
    toc-expand: 2
    toc-location: left
    code-fold: true
    code-summary: "Show code"
vignette: >
  %\VignetteIndexEntry{Pipeline DAG}
  %\VignetteEngine{quarto::html}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include=FALSE}
#| echo: false
#| results: asis
in_pkgdown <- nzchar(Sys.getenv("IN_PKGDOWN"))
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  eval = TRUE,
  message = FALSE,
  warning = FALSE,
  fig.width = 8,
  fig.height = 6
)
if (!in_pkgdown) library(targets)

# Shared vignette utilities (safe_tar_read, show_target, render helpers)
utils_path <- system.file("vignette_utils.R", package = "coMMpass")
if (utils_path == "") {
  utils_path <- if (file.exists("../inst/vignette_utils.R")) "../inst/vignette_utils.R"
  else if (file.exists("inst/vignette_utils.R")) "inst/vignette_utils.R"
  else stop("Cannot find vignette_utils.R")
}
source(utils_path, local = TRUE)
```

```{r pkgdown-banner}
#| results: asis
#| eval: !expr in_pkgdown
#| echo: false
cat("::: {.callout-note}\n## Online documentation\nThis vignette shows pre-computed results from the targets pipeline.\n:::\n")
```

## Pipeline Overview

The CoMMpass analysis pipeline is organized into isolated layers.
Each layer corresponds to a functional area of the analysis, with
explicit allowed dependencies between layers.

| Layer | Description |
|---|---|
| data-acquisition | Download RNA-seq and clinical data from GDC |
| data-cleaning | Standardize and integrate datasets |
| cytogenetics | Extract FISH markers and classify risk |
| quality-control | Sample QC, filtering, normalization |
| differential-expression | DESeq2, edgeR, limma-voom analysis |
| survival | Kaplan-Meier, Cox PH regression |
| pathway | GSEA, ORA, gene annotation |
| eda | Exploratory summaries |
| storage | DuckDB/parquet querying |
| api | Plumber API for programmatic access |
| documentation | Vignette pre-computed outputs |
| infrastructure | Nix sync, pkgctx, DAG validation |

## DAG Validation

Validation checks on the targets pipeline DAG: no orphaned targets, no circular dependencies, and all vignette targets are reachable from raw data inputs. A passing validation confirms the pipeline is structurally sound.

```{r dag-validation}
#| echo: false
#| results: asis
show_target("dag_layer_validation")
```

## Target Network

Interactive DAG showing the targets pipeline network with layer-based coloring. Nodes are colored by functional layer. Hover for target details, use the dropdown to search by name.

```{r pipeline-visnetwork}
#| echo: false
#| results: asis
# visNetwork widget can't render in CI (glue/htmltools conflicts)
# Show the node/edge summary instead
val <- safe_tar_read("vig_pipeline_dag")
if (inherits(val, c("shiny.tag.list", "htmlwidget"))) {
  cat("*Interactive DAG available in local builds only.*\n\n")
  cat("Run `targets::tar_visnetwork(targets_only = TRUE)` locally.\n")
} else if (!is.null(val)) {
  val
}
```

## Pipeline by Layer

To explore the full interactive DAG locally, run:

```r
targets::tar_visnetwork(targets_only = TRUE, label = "time")
```

## Recent Changes

Recent project commits with lines added, files changed, and change categories.

```{r changelog}
#| echo: false
#| results: asis
show_target("vig_git_changelog")
```

## Reproducibility

<details>
<summary>Session Info (click to expand)</summary>

```{r session-info, eval=TRUE}
sessionInfo()
```

</details>
