Metadata-Version: 2.4
Name: sigProfilerPlotting
Version: 1.6.0
Summary: SigProfiler plotting tool
Home-page: https://github.com/SigProfilerSuite/SigProfilerPlotting
Author: SigProfilerSuite
Author-email: sislam6@albany.edu
Maintainer: S M Ashiqul Islam
Maintainer-email: sislam6@albany.edu
License: UCSD
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: matplotlib>=3.4.3
Requires-Dist: pandas>=2.0.0
Requires-Dist: scikit-learn>=1.1.3
Requires-Dist: pillow>=10.0.0
Requires-Dist: plotly>=6.1.1
Requires-Dist: kaleido>=1.0.0
Requires-Dist: pypdf>=5.0.0
Provides-Extra: tests
Requires-Dist: pytest; extra == "tests"
Requires-Dist: scikit-image>=0.21.0; extra == "tests"
Requires-Dist: numpy>=2.0.0; extra == "tests"
Requires-Dist: playwright; extra == "tests"
Dynamic: author
Dynamic: author-email
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: maintainer
Dynamic: maintainer-email
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

[![Docs](https://img.shields.io/badge/docs-latest-blue.svg)](https://sigprofilersuite.github.io/SigProfilerPlotting/) [![License](https://img.shields.io/badge/License-BSD\%202--Clause-orange.svg)](https://opensource.org/licenses/BSD-2-Clause) [![CI](https://github.com/sigprofilersuite/SigProfilerPlotting/actions/workflows/ci.yml/badge.svg)](https://github.com/sigprofilersuite/SigProfilerPlotting/actions/workflows/ci.yml)

# SigProfilerPlotting
SigProfilerPlotting provides a standard tool for displaying all types of mutational signatures as well as all types of mutational patterns in cancer genomes. The tool seamlessly integrates with other SigProfiler tools.

**INTRODUCTION**

The purpose of this document is to provide a guide for using the SigProfilerPlotting framework and associated functions/tools to visualize the output from SigProfilerExtraction and SigProfilerSimulator. The primary documentation is available at https://sigprofilersuite.github.io/SigProfilerPlotting/.

For users that prefer working in an R environment, a wrapper package is provided and can be found and installed from: https://github.com/SigProfilerSuite/SigProfilerPlottingR

![schematic](schematic.png)

**PREREQUISITES**

The framework is written in PYTHON, however, it also requires the following software with the given versions (or newer):

  * PYTHON          version 3.9 or newer
  * SigProfilerMatrixGenerator (recommended)

**QUICK START GUIDE**

This section will guide you through the minimum steps required to plot mutational matrices:
1. Install the python package using pip:
```
                          pip install SigProfilerPlotting
```

2. Plot mutational matrices from a Python session or using the Command Line Interface (CLI) as follows:

Using the Python session, the command is as follows:
 ```python
$ python3
>> import sigProfilerPlotting as sigPlt
>> sigPlt.plotSBS(matrix_path, output_path, project, plot_type, percentage=None)
 ```

The required parameters are:

    sigPlt.plotSBS(matrix_path, output_path, project, plot_type)

Using the CLI, the command is as follows:
```bash
SigProfilerPlotting plotSBS <matrix_path> <output_path> <project> <plot_type>
```

 3. The final plots are saved into the user-provided output folder.

## Single Base Substitution, Double Base Substitution, and Indel Plotting ##

**AVAILABLE FUNCTIONS**

```python
import sigProfilerPlotting as sigPlt

sigPlt.plotSBS(matrix_path, output_path, project, plot_type, percentage=None)
sigPlt.plotDBS(matrix_path, output_path, project, plot_type, percentage=False)
sigPlt.plotID(matrix_path, output_path, project, plot_type, percentage=False)

```

### Supported plots

| Mutation class | Function | Supported contexts |
| --- | --- | --- |
| Single-base substitutions | `plotSBS()` | SBS6, SBS24, SBS96, SBS192/384, SBS288, SBS1536, SBS4608 |
| Double-base substitutions | `plotDBS()` | DBS78 and DBS186/312 |
| Small insertions/deletions | `plotID()` | ID28, ID83, ID89, ID476, ID415 |
| Copy-number alterations | `plotCNV()` | CNV48 |
| Structural variants | `plotSV()` | SV32 |
| Combined sample summary | `samplePortrait()` | SBS, DBS, and ID matrices for one project |

The local interactive dashboard recognizes the complete matrix definitions
shipped in `sigProfilerPlotting/reference_formats`. It has dedicated layouts
for SBS96, SBS288, SBS1536, SBS4608, DBS78, ID83, ID89, ID476, CNV48, and
SV32, and a generic interactive layout for the remaining recognized
contexts. See [Interactive Dashboard](docs/Plotting-Dashboard.md).

## SBS4608 plotting

Strand-tagged pentanucleotide matrices can be rendered as a self-contained
interactive HTML report or as a multi-page static PDF via `plotSBS(...,
"4608", ...)`. The input must contain all 4,608 `MutationType` rows (`T`,
`U`, and `N` strands) for each selected sample or signature, for example
`T:AA[C>A]AA`.

When `percentage` is omitted, SBS4608 defaults to percentages because its
input is a signature/profile matrix. Other SBS contexts retain their existing
numerical default. Pass `percentage=False` for SBS4608 raw signature
contributions (these are not labeled as mutation counts).

```python
import sigProfilerPlotting as sigPlt

sigPlt.plotInteractive(
    "example.SBS4608.all",
    "example",
    output_path="plots",
)
sigPlt.plotSBS(
    "example.SBS4608.all", "plots", "example", "4608",
)
```

`plotInteractive()` embeds Plotly in the HTML file, so the report works
offline. The static `plotSBS(..., "4608", ...)` path renders each page as a
validated high-resolution raster before assembling the PDF, avoiding
renderer-dependent clipping. It uses Kaleido and requires a local Chrome or
Chromium installation; run `plotly_get_chrome` if Kaleido cannot find one.
There is no separate `plotStatic()` API. See
[Plotting SBS4608](docs/Plotting-SBS4608.md) for the full parameter list
(including `percentage`, `signatures`, and the
`custom_text_upper`/`middle`/`bottom` annotations).

## ID89 and ID476 (Koh et al.) indel plotting

`plotID()` and the interactive dashboard also support the Koh et al. ID89
(89-category) and ID476 (476-category) indel classification schemes,
alongside the existing ID83 scheme:

```python
sigPlt.plotID(matrix_path, output_path, project, "89", percentage=False)  # or "476"
```

See [Plotting ID89/ID476](docs/Plotting-ID89-ID476.md) for the input format,
supported output formats, and attribution.

## Copy Number and Structural Variant Plotting ##

```python
import sigProfilerPlotting as sigPlt

matrix_path = "./sigProfilerPlotting/examples/input/breast_cancer_samples_example.CNV48.all" #Output of CNVMatrixGenerator
output_path = "./sigProfilerPlotting/examples/output/"
project = "Breast"
```

**AVAILABLE FUNCTIONS**

*Multi-page pdf of CNV or SV signatures*

```python
sigPlt.plotCNV(matrix_path, output_path, project, percentage=True, aggregate=False) #plotting of CNV signatures
sigPlt.plotSV(matrix_path, output_path, project, percentage=True, aggregate=False) #plotting of SV signatures

```
*Multi-page pdf of CNV or SV counts*

```python
sigPlt.plotCNV(matrix_path, output_path, project, percentage=False, aggregate=False) #plotting of CNV counts
sigPlt.plotSV(matrix_path, output_path, project,percentage=False, aggregate=False) #plotting of SV counts
```

*Single pdf of CNV or SV counts per sample for a given cancer type/project*

```python
sigPlt.plotCNV(matrix_path, output_path, project, percentage=False, aggregate=True) #plotting of CNV counts
sigPlt.plotSV(matrix_path, output_path, project, percentage, aggregate=True) #plotting of SV counts
```

matrix_path -> path to the mutational matrix of interest

output_path -> desired output path

project -> name of unique sample set

plot_type -> context of the mutational matrix (96, 192, 78, 94, etc.)

percentage -> Boolean: plot the mutational matrix as percentages of the sample's total mutation count. Default is False

To create a sample portrait, ensure that you have a matrix for all required contexts (SBS-6, SBS-24, SBS-96, SBS-384, SBS-1536, DBS-78, DBS-312, ID-83, ID-28, ID-96)

```python
from sigProfilerPlotting import sample_portrait as sP
sP.samplePortrait(sample_matrices_path, output_path, project, percentage=False)
```

## Interactive Dashboard

A local, browser-based dashboard lets you upload any supported matrix and
explore it interactively (search/select samples, switch between
percentage/proportion/counts, hover/zoom/pan/export as SVG or PDF) without
writing any Python. Not ready with your own data yet? Its home screen offers
a handful of bundled example matrices to try with one click. It shares its
look with the other SigProfiler Suite workbenches, including a choice of
four themes. For `SBS96`, `SBS288`,
`SBS1536`, or `SBS4608` matrices, selecting a
single sample or signature also lets you compare it against COSMIC
reference signatures and see the 5 best cosine-similarity matches. This
needs your own authorized local copy of COSMIC's data -- SigProfilerPlotting
does not bundle or redistribute it (see
[the dashboard docs](docs/Plotting-Dashboard.md#comparing-against-cosmic-signatures)).
It runs entirely on your machine and never sends data anywhere else.

![The SigProfilerPlotting Workbench](https://raw.githubusercontent.com/SigProfilerSuite/SigProfilerPlotting/master/docs/assets/images/web-app/home.png)

**How to launch it:**

* **Already have the repo cloned?** Open a terminal in the repository root
  and run the launcher for your platform -- no setup needed, it creates its
  own isolated environment and installs everything the first time it runs:

  | Platform | Command |
  | --- | --- |
  | macOS | `./launch_dashboard.sh` (or double-click `launch_dashboard.command` in Finder) |
  | Linux | `./launch_dashboard.sh` |
  | Windows | Double-click `launch_dashboard.bat`, or run `launch_dashboard.bat` from a terminal |

* **Installed via `pip` instead?** Use the console command that comes with
  the package:

  ```console
  pip install SigProfilerPlotting
  sigprofilerplotting-web
  ```

Either way, your default browser opens to the dashboard automatically once
the server is ready. To stop it, press `Ctrl+C` in that terminal, click the
**Quit** button in the dashboard itself, or run the same command again with
`--stop` from another terminal.

See the [full dashboard documentation](https://sigprofilersuite.github.io/SigProfilerPlotting/Plotting-Dashboard.html)
for every command-line flag, supported mutation contexts, and troubleshooting.

## Release and publication

Package versions are derived from Git tags through `setuptools-scm`. A
maintainer can run the **Create version tag** GitHub Actions workflow with an
`x.y.z` version and target branch. The resulting `vX.Y.Z` tag builds and
checks the source/wheel distributions and publishes them to TestPyPI through
trusted publishing. Publishing the corresponding GitHub Release runs the
same verified build and publishes it to PyPI. See
[Release and publication](docs/Release-and-Publication.md) for the complete
checklist and required GitHub/PyPI environments.

**EXAMPLE**

This package comes with an example test for each plot type. Run the script plot_example.py from within the examples directory in the downloaded repo after installation:
```python
python3 sigProfilerPlotting/examples/plot_example.py
```

This example will create plots for each context for each of the included four samples. These plots will be saved within the `sigProfilerPlotting/examples/output/` folder.

**CITATION**

Bergstrom EN, Huang MN, Mahto U, Barnes M, Stratton MR, Rozen SG, Alexandrov LB: SigProfilerMatrixGenerator: a tool for visualizing and exploring patterns of small mutational events. BMC Genomics 2019, 20:685
https://bmcgenomics.biomedcentral.com/articles/10.1186/s12864-019-6041-2

**COPYRIGHT**

Copyright (c) 2020, Erik Bergstrom [Alexandrov Lab] All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

**CONTACT INFORMATION**

Please address any queries or bug reports to S M Ashiqul Islam at sislam6@albany.edu
