---
title: "Quick Start Guide"
author: "Zaoqu Liu"
date: "`r Sys.Date()`"
output: 
  rmarkdown::html_document:
    toc: true
    toc_depth: 3
    toc_float: true
    theme: flatly
    highlight: tango
    code_folding: show
vignette: >
  %\VignetteIndexEntry{Quick Start Guide}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(
  echo = TRUE,
  message = FALSE,
  warning = FALSE,
  fig.width = 8,
  fig.height = 6,
  fig.align = "center"
)
```

# Introduction

**tradeSeq** (TRAjectory Differential Expression analysis for SEQuencing data) provides a flexible statistical framework for identifying genes that are differentially expressed along cell trajectories in single-cell RNA sequencing data.

This quick start guide will walk you through a basic analysis workflow in just a few minutes.

# Installation

```{r install, eval=FALSE}
# From R-universe (recommended for latest version)
install.packages("tradeSeq", repos = "https://zaoqu-liu.r-universe.dev")

# From Bioconductor (stable release)
BiocManager::install("tradeSeq")

# From GitHub (development version)
remotes::install_github("Zaoqu-Liu/tradeSeq")
```

# Quick Workflow

## Step 1: Load Required Packages

```{r load-packages}
library(tradeSeq)
library(RColorBrewer)
library(SingleCellExperiment)
library(slingshot)
library(ggplot2)

# Set seed for reproducibility
set.seed(42)
```

## Step 2: Load Example Data

tradeSeq comes with example datasets from a study of bone marrow hematopoiesis.

```{r load-data}
# Load count matrix and trajectory
data(countMatrix, package = "tradeSeq")
data(crv, package = "tradeSeq")

# Convert to matrix
counts <- as.matrix(countMatrix)

# Check dimensions
cat("Genes:", nrow(counts), "\n")
cat("Cells:", ncol(counts), "\n")
```

## Step 3: Fit GAM Models

The core of tradeSeq is fitting generalized additive models (GAMs) for each gene.

```{r fit-gam}
# Fit GAM with 6 knots (default)
sce <- fitGAM(counts = counts, sds = crv, nknots = 6, verbose = FALSE)

# Check the fitted object
sce
```

## Step 4: Run Differential Expression Tests

### Association Test

Test whether gene expression is associated with pseudotime.

```{r association-test}
# Test for association with pseudotime
assocRes <- associationTest(sce)

# View top results
head(assocRes[order(assocRes$pvalue), ])
```
### Differential End Points Test

Compare expression at the endpoints of different lineages.

```{r diffend-test}
# Test for differential expression at lineage endpoints
endRes <- diffEndTest(sce)

# View top results
head(endRes[order(endRes$pvalue), ])
```

### Pattern Test

Test whether genes have different expression patterns between lineages.

```{r pattern-test}
# Test for differential patterns
patternRes <- patternTest(sce)

# View top results
head(patternRes[order(patternRes$pvalue), ])
```

## Step 5: Visualize Results

### Plot Gene Expression Smoothers

```{r plot-smoothers, fig.height=5}
# Get a significant gene
topGene <- rownames(assocRes[order(assocRes$pvalue), ])[1]

# Plot smoother
plotSmoothers(sce, counts, gene = topGene) +
  ggtitle(paste("Expression of", topGene, "along trajectory"))
```

### Plot Gene Count

```{r plot-genecount, fig.height=5}
# Plot gene counts on trajectory
plotGeneCount(crv, counts, gene = topGene) +
  ggtitle(paste(topGene, "expression"))
```

# Summary

In this quick start guide, you learned how to:

1. **Load data**: Import count matrix and trajectory information
2. **Fit models**: Use `fitGAM()` to fit GAMs for each gene
3. **Test DE**: Apply various statistical tests
4. **Visualize**: Create publication-ready plots

For more detailed tutorials, please see the other vignettes:

- [Main tradeSeq Workflow](tradeSeq.html)
- [Statistical Framework](statistical_framework.html)
- [Visualization Gallery](visualization.html)

# Session Info

```{r session-info}
sessionInfo()
```
