---
title: "A Quick Start of sigminer Package"
author: "Shixiang Wang ( wangshx@shanghaitech.edu.cn )"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{A Quick Start of sigminer Package}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, echo = FALSE, message = FALSE}
library(markdown)
library(knitr)
knitr::opts_chunk$set(
    error = FALSE,
    tidy  = TRUE,
    message = FALSE,
    fig.align = "center",
    collapse = TRUE,
    comment = "#>")
options(width = 100)
options(rmarkdown.html_vignette.check_title = FALSE)
```

Assume you have already gotten a catalog matrix (sample-by-component) like below:

```{r message=TRUE}
library(sigminer)
data("simulated_catalogs")
mat <- t(simulated_catalogs$set1)

mat[1:5, 1:5]
```

Extract signatures with:

```{r eval=FALSE}
# Here I reduce the values for n_bootstrap and n_nmf_run
# for reducing the run time.
# In practice, you should keep default or increase the values
# for better estimation.
#
# The input data here is simulated from 10 mutational signatures
e1 <- bp_extract_signatures(
  mat,
  range = 8:12,
  n_bootstrap = 5,
  n_nmf_run = 10
)
```

```{r include=FALSE}
e1 <- readRDS("e1.rds")
```

Check which signature number is proper:

```{r message=TRUE, fig.width=4, fig.height=3}
bp_show_survey2(e1, highlight = 10)
```

Get the `10` signatures:

```{r}
obj <- bp_get_sig_obj(e1, 10)
```

Show signature profile:

```{r fig.width=10, fig.height=8}
show_sig_profile(obj, mode = "SBS", style = "cosmic")
```
Show signature activity (a.k.a. exposure) profile:

```{r fig.width=8, fig.height=5}
show_sig_exposure(obj, rm_space = TRUE)
```

Calculate the similarity to COSMIC reference signatures:

```{r message=TRUE}
sim <- get_sig_similarity(obj, sig_db = "SBS")
```

```{r fig.width=10, fig.height=6}
if (require(pheatmap)) {
  pheatmap::pheatmap(sim$similarity)
}
```

## QA

If you encounter warnings about `future` package, please set the following options before running code:

```r
options(future.rng.onMisuse = "ignore", future.globals.maxSize = Inf)
```

## More

Please go to [*reference* list](https://shixiangwang.github.io/sigminer/reference/index.html) for well organized functions and documentation.

For more about mutational signature and **sigminer** usage, you can read [*sigminer-book*](https://shixiangwang.github.io/sigminer-book/).
