---
title: "stPipe Report"
output: 
  html_document:
    toc: true             
    toc_depth: 3          
    toc_float: true     
---

# Summary of Results

This HTML report provides an overview of the outputs generated by **stPipe** package and serves as a guide to help understand the filtering approaches and their impact on data quality, providing a foundation for confident downstream analysis. Below you can find each visualization results with corresponding explanation for your data in different sections.

## Barcode demultiplexing Plot

The barcode demultiplexing plot shows the percentage of reads that uniquely match to the cell barcodes, as well as the unmatched proportion of reads and their alignment rates to introns and exons. 

### Importance

If a large proportion of unmatched reads is observed that map to exons, a failure of the spatial barcode demultiplexing is possible.

```{r, echo=FALSE, fig.align="center", fig.cap="Fig 1. Barcode demultiplexing Plot"}
knitr::include_graphics('<<Barcode_demultiplexing_plot>>')

```

## UMI duplication Plot

The UMI duplication plot is used to evaluate read depth. In this plot, X axis and Y axis stands for log UMI duplication number and frequency respectively.

### Importance

UMIs are routinely used to mark individual molecules and after PCR amplification, the same molecule with have multiple copys, which can be identified and removed if they are observed to have the same UMI sequence. UMI copy number is an indication of the PCR amplification rate.

```{r, echo=FALSE, fig.align="center"}
knitr::include_graphics('<<UMI_duplication_plot>>')

```

## Mapping Statistics Plot

The mapping statistics plot  X axis presents the position across all spots/bins/beads/nanoballs and Y axis presents the percentage of reads corresponding to 6 categories, including "unaligned", "aligned_unmapped", "ambiguous_mapping", "mapped_to_ERCC", "mapped_to_intron", and "mapped_to_exon."

### Importance

This alignment statistics is often used as an important indictor for mapping quality.

```{r, echo=FALSE, fig.align="center"}
knitr::include_graphics(normalizePath('<<Mapping_statistics_plot>>'), error = FALSE)
```

## Threshold for **'Run_QC'** step

This threshold plot quantile raw UMI count as 100 percentiles in the X axis, raw UMI count showing in the Y axis. Detailed description can be found in **'Run_QC'** help page.

#### Visual Representation:
The QC process generates a plot showing UMI count percentiles, with annotations for the threshold values used to filter low-count cells. This visualization aids in understanding the filtering process.

### Impoatance
This plot is necessary to check for QC, as it would directly show you the raw UMI count quality and provides the thresholds used within **stPipe**. You could further adjust and personalize your **qc_per** in the config file according to this plot.

```{r, echo=FALSE, fig.align="center"}
knitr::include_graphics(normalizePath('<<Threshold>>'), error = FALSE)
```

## UMI Count Spatial Heatmap

This section shows two spatial heatmap with the left one showing raw UMI count and right one showing log UMI count. Both of them present the spatial distribution of UMI count, you may wish to visualize them before and after **'Run_QC'** step.

### Importance

This spatial heatmap provides direct visualization in the perspective of raw and log UMI count. For 10X Visium, this suggests the tissue appearance. For other technologies such as Slideseq, this shows the density of UMI distribution in spatial dimension. 

```{r, echo=FALSE, fig.show='hold', out.width="50%", out.height="400px", dpi=400}
knitr::include_graphics('<<Spatial_Heatmap_of_UMI_Count_raw>>')
knitr::include_graphics('<<Spatial_Heatmap_of_UMI_Count_log>>')
```

## Spatial location number before and after **'Run_QC'** step

The number of spots/bins/beads/nanoballs before and after the **'Run_QC'** step is critical. For 10X Visium, **'Run_QC'** step aims to remove the background noise outside the captured tissue. For other technologies such as Slideseq, **'Run_QC'** step aims to remove low quality spatial location which would not impact further downstream analysis.

### Importance

It is important to get information from the spatial locations removed by **'Run_QC'**, since doing quality control is a kind of "fine tuning" process - you don't want to remove too much information but do want to get rid of nosiy data.

# Clustering: T-SNE and UMAP

### Importance
T-SNE visually reveals the clustering patterns in the data, helping you to determine whether distinct groups or clusters exist. It is especially useful for identifying dense regions of the data and showing their relationships in spatial distribution, providing insights that can be used for further biological interpretation.

```{r, echo=FALSE, fig.align="center"}
knitr::include_url('<<tsne_interactive>>')
```

### Importance

UMAP complements T-SNE by displaying global trends in the data, allowing you to observe the relative positioning of different groups or clusters and identify potential transitions between them. Additionally, UMAP is often used in large-scale datasets to reduce dimensionality and visualize characteristic patterns across spatial or single-cell data.

```{r, echo=FALSE, fig.align="center"}
knitr::include_url('<<umap_interactive>>')
```

<details>
<summary>Session Info</summary>
```{r}
sessionInfo()
```

