---
title: "Quick Start Guide"
author: "Zaoqu Liu"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Quick Start Guide}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 7,
  fig.height = 5,
  message = FALSE,
  warning = FALSE
)
```

## Introduction

**SCENT** (Single Cell ENTropy) estimates differentiation potency of single cells 
from scRNA-Seq data using signaling entropy on protein interaction networks.

This package implements:

- **SR (Signaling Entropy Rate)**: The gold-standard method for accurate potency estimation
- **CCAT (Correlation of Connectome And Transcriptome)**: A fast approximation (~100x faster)

## Installation

```{r install, eval=FALSE}
# Install from GitHub
devtools::install_github("Zaoqu-Liu/SCENT")
```

## Quick Example

```{r load}
library(SCENT)
library(ggplot2)

# Load the built-in PPI network
data(net13Jun12.m)
cat("PPI network:", nrow(net13Jun12.m), "genes,", 
    sum(net13Jun12.m)/2, "interactions\n")
```

### Simulate Single-Cell Data

```{r simulate}
set.seed(42)

# Simulate expression matrix (genes x cells)
n_genes <- 5500
n_cells <- 100

exp_matrix <- matrix(
  rpois(n_genes * n_cells, lambda = 5),
  nrow = n_genes,
  ncol = n_cells
)
rownames(exp_matrix) <- head(rownames(net13Jun12.m), n_genes)
colnames(exp_matrix) <- paste0("Cell_", 1:n_cells)

cat("Expression matrix:", nrow(exp_matrix), "genes x", 
    ncol(exp_matrix), "cells\n")
```

### Method 1: CCAT (Fast)
 
```{r ccat}
# CCAT: ~0.1 seconds for 100 cells
ccat_scores <- CompCCAT(exp_matrix, net13Jun12.m)

cat("CCAT scores range:", round(range(ccat_scores), 4), "\n")
```

### Method 2: SR (Accurate)

```{r sr}
# Step 1: Integrate expression with PPI network
integ <- DoIntegPPI(exp_matrix, net13Jun12.m)
cat("Integrated:", nrow(integ$expMC), "genes in maximal component\n")

# Step 2: Compute Signaling Entropy Rate
sr_result <- CompSRana(integ, local = FALSE)

cat("SR scores range:", round(range(sr_result$SR), 4), "\n")
```

### Compare Methods

```{r compare, fig.height=4}
# Correlation between SR and CCAT
cor_value <- cor(sr_result$SR, ccat_scores)
cat("SR-CCAT correlation: r =", round(cor_value, 3), "\n")

# Visualization
df <- data.frame(
  SR = sr_result$SR,
  CCAT = ccat_scores,
  Cell = colnames(exp_matrix)
)

ggplot(df, aes(x = CCAT, y = SR)) +
  geom_point(alpha = 0.6, color = "#3498db", size = 2) +
  geom_smooth(method = "lm", color = "#e74c3c", se = FALSE) +
  labs(
    title = "SR vs CCAT Correlation",
    subtitle = paste("Pearson r =", round(cor_value, 3)),
    x = "CCAT Score",
    y = "Signaling Entropy Rate (SR)"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(face = "bold", size = 14),
    plot.subtitle = element_text(color = "gray40")
  )
```

## Interpretation

- **Higher SR/CCAT scores** indicate higher differentiation potency (more stem-like)
- **Lower scores** indicate more differentiated states

## When to Use Each Method

| Scenario | Recommended Method |
|----------|-------------------|
| Quick screening | CCAT |
| Publication-quality results | SR |
| Large datasets (>10,000 cells) | CCAT first, then SR on subset |
| Time-sensitive analysis | CCAT |

## Session Info

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