---
title: "Intratumoral Heterogeneity in Glioblastoma"
author: "Zaoqu Liu"
date: "`r Sys.Date()`"
output: 
  rmarkdown::html_vignette:
    toc: true
    toc_depth: 3
vignette: >
  %\VignetteIndexEntry{Intratumoral Heterogeneity in Glioblastoma}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(
  echo = TRUE, 
  eval = FALSE,
  message = FALSE, 
  warning = FALSE
)
```

## Introduction

This vignette demonstrates SCEVAN's ability to detect intratumoral heterogeneity in a glioblastoma sample. We analyze the MGH106 sample from the public dataset GSE131928.

## Load Data

```{r load-data}
# Load scRNA data of MGH106 sample from GSE131928
load(url("https://www.dropbox.com/s/b9udpvhnc2ez9pc/MGH106_data.RData?raw=1"))

# Check dimensions
dim(count_mtx)
```

## Run Pipeline

Run the complete SCEVAN pipeline with subclone detection enabled:

```{r run-pipeline}
library(SCEVAN)

results <- pipelineCNA(
  count_mtx, 
  sample = "MGH106", 
  par_cores = 20, 
  SUBCLONES = TRUE, 
  plotTree = TRUE
)
```

## Results

The pipeline returns a data frame containing:
- Cell classification (tumor/normal)
- Confident normal cell status
- Subclone assignment

```{r results}
head(results)
```

Output files are saved to `./output/`:

```{r list-files}
list.files(path = "./output", pattern = "MGH106")
```

## Output Visualizations

### 1. Classification Heatmap

Heatmap showing CNA matrix with malignant/non-malignant classification:

**File:** `MGH106heatmap.png`

### 2. Subclone Heatmap

CNA matrix colored by clonal subpopulations:

**File:** `MGH106heatmap_subclones.png`

### 3. Phylogenetic Tree

Clonal tree inferred from subclone profiles:

**File:** `MGH106CloneTree.png`

### 4. Consensus Plot

Compact visualization of alterations per subpopulation:

**File:** `MGH106consensus.png`

### 5. OncoPrint Plot

Shows specific, shared, and clonal alterations:

**File:** `MGH106OncoHeat2.png`

### 6. Differential Expression

Volcano plots from DE analysis of genes in specific alterations:

**Files:** `MGH106-DEchr*_subclones.png`

### 7. Pathway Analysis

REACTOME pathway activity via GSEA for each subclone:

**Files:** `MGH106pathwayAnalysis_subclones*.png`

## Summary

SCEVAN successfully:

1. Classified cells into tumor and normal populations
2. Identified multiple tumor subclones
3. Characterized subclone-specific copy number alterations
4. Performed differential expression analysis
5. Generated pathway enrichment results

## Session Info

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