diff --git a/ci.yml b/.github/workflows/ci.yml similarity index 93% rename from ci.yml rename to .github/workflows/ci.yml index f1ce0ec..38168d6 100644 --- a/ci.yml +++ b/.github/workflows/ci.yml @@ -21,10 +21,10 @@ jobs: python-version: ['3.9', '3.14'] steps: - - uses: actions/checkout@v4 - + - uses: actions/checkout@v6 + - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 + uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} @@ -38,7 +38,7 @@ jobs: python -m pip install --upgrade pip setuptools packaging - name: Cache src directory - uses: actions/cache@v4 + uses: actions/cache@v5 with: path: ${{ github.workspace }}/src/ key: ${{ runner.os }}-src-grch37 diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..4a4a4e9 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,53 @@ +name: Docs + +on: + push: + branches: + - master + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: github-pages + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + + - uses: actions/setup-python@v6 + with: + python-version: "3.x" + + - name: Configure Pages + uses: actions/configure-pages@v6 + + - name: Install docs dependencies + run: | + python -m pip install --upgrade pip + python -m pip install mkdocs mkdocs-material pymdown-extensions + + - name: Build site + run: | + mkdocs build --clean + + - name: Upload Pages artifact + uses: actions/upload-pages-artifact@v5 + with: + path: site + + deploy: + runs-on: ubuntu-latest + needs: build + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - id: deployment + uses: actions/deploy-pages@v5 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f6109e7..b507a48 100755 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,10 +17,12 @@ jobs: steps: - name: Checkout repo - uses: actions/checkout@v4 + uses: actions/checkout@v6 + with: + fetch-depth: 0 - name: Set up Python - uses: actions/setup-python@v5 + uses: actions/setup-python@v6 with: python-version: "3.14" @@ -64,14 +66,21 @@ jobs: raise SystemExit(f"Error: New version ({new_version}) is not higher than latest release ({latest_version})") EOF - - name: Generate CHANGELOG.md with git-cliff + - name: Generate release notes and update CHANGELOG.md run: | - git-cliff --unreleased --strip all --tag "v${{ steps.get_version.outputs.VERSION }}" > CHANGELOG.md + git-cliff --unreleased --strip all --tag "v${{ steps.get_version.outputs.VERSION }}" > RELEASE_NOTES.md + git-cliff --unreleased --tag "v${{ steps.get_version.outputs.VERSION }}" --prepend CHANGELOG.md - - name: Create Git tag + - name: Commit and push CHANGELOG.md run: | git config user.name "github-actions" git config user.email "github-actions@github.com" + git add CHANGELOG.md + git commit -m "chore: update CHANGELOG.md for v${{ steps.get_version.outputs.VERSION }}" + git push origin HEAD:master + + - name: Create Git tag + run: | git tag v${{ steps.get_version.outputs.VERSION }} git push origin v${{ steps.get_version.outputs.VERSION }} @@ -79,7 +88,7 @@ jobs: uses: softprops/action-gh-release@v2 with: tag_name: v${{ steps.get_version.outputs.VERSION }} - body_path: CHANGELOG.md + body_path: RELEASE_NOTES.md env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 962b1bb..7bc932e 100755 --- a/README.md +++ b/README.md @@ -1,151 +1,53 @@ -[![Docs](https://img.shields.io/badge/docs-latest-blue.svg)](https://osf.io/qpmzw/wiki/home/) [![License](https://img.shields.io/badge/License-BSD\%202--Clause-orange.svg)](https://opensource.org/licenses/BSD-2-Clause) [![Build Status](https://app.travis-ci.com/AlexandrovLab/SigProfilerClusters.svg?token=Fyqun3zxxDr3YzDRaKKm&branch=master)](https://app.travis-ci.com/AlexandrovLab/SigProfilerClusters) +[![Docs](https://img.shields.io/badge/docs-latest-blue.svg)](https://sigprofilersuite.github.io/SigProfilerClusters/) +[![License](https://img.shields.io/badge/License-BSD\%202--Clause-orange.svg)](https://opensource.org/licenses/BSD-2-Clause) +[![CI](https://github.com/SigProfilerSuite/SigProfilerClusters/actions/workflows/ci.yml/badge.svg)](https://github.com/SigProfilerSuite/SigProfilerClusters/actions/workflows/ci.yml) +SigProfilerClusters # SigProfilerClusters -Tool for analyzing the inter-mutational distances between SNV-SNV and INDEL-INDEL mutations. Tool separates mutations into clustered and non-clustered groups on a sample-dependent basis and subclassifies all SNVs into a set category of clustered event: i) DBS; ii) MBS; iii) omikli; and iv) kataegis. Indels are not subclassifed. +SigProfilerClusters analyzes inter-mutational distances (IMD) between SNV-SNV and INDEL-INDEL mutations, separating them into clustered and non-clustered groups on a sample-dependent basis. Clustered SNVs are further subclassified into doublet base substitutions (DBS), multi-base substitutions (MBS), omikli, and kataegis events. The tool uses [SigProfilerSimulator](https://github.com/SigProfilerSuite/SigProfilerSimulator) to build a per-sample background model and applies a regionally corrected IMD threshold to identify mutations unlikely to have co-occurred by chance. -This tool was previously under the project name of SigProfilerHotSpots, but has been renamed to SigProfilerClusters. For all instructions below, SigProfilerClusters may be interchanged with SigProfilerHotSpots if the older version of the tools is being used. +## Documentation +Detailed documentation can be found at https://sigprofilersuite.github.io/SigProfilerClusters. -**INTRODUCTION** +## Quick Start Guide -The purpose of this document is to provide a guide for using the SigProfilerClusters framework. An extensive Wiki page detailing the usage of this tool can be found at https://osf.io/qpmzw/wiki/home/. +### Installation - -**PREREQUISITES** - -The framework is written in PYTHON, and uses additional SigProfiler packages: - - * PYTHON version 3.8 or newer - * SigProfilerMatrixGenerator (https://github.com/AlexandrovLab/SigProfilerMatrixGenerator) - * SigProfilerSimulator (https://github.com/AlexandrovLab/SigProfilerSimulator) - -Please visit their respective GitHub pages for detailed installation and usage instructions. - -**QUICK START GUIDE** - -This section will guide you through the minimum steps required to perform clustered analysis: - -1a. Install the python package using pip (current package): - pip install SigProfilerClusters - -1b. Install the python package using pip (deprecated version): - pip install SigProfilerHotSpots - - -Install your desired reference genome from the command line/terminal as follows (available reference genomes are: GRCh37, GRCh38, mm9, and mm10): +Install the current stable PyPI version of SigProfilerClusters: ``` -$ python ->> from SigProfilerMatrixGenerator import install as genInstall ->> genInstall.install('GRCh37', rsync=False, bash=True) +$ pip install SigProfilerClusters ``` -This will install the human 37 assembly as a reference genome. You may install as many genomes as you wish. If you have a firewall on your server, you may need to install rsync and use the rsync=True parameter. Similarly, if you do not have bash, -use bash=False. -2. Place your vcf files in your desired output folder. It is recommended that you name this folder based on your project's name. Before you can analyze clustered mutations, you need to generate a background model for each of your samples. To do this, generate a minimum of 100 simulations for your project (see SigProfilerSimulator for a detailed list of parameters): -``` ->>from SigProfilerSimulator import SigProfilerSimulator as sigSim ->>sigSim.SigProfilerSimulator(project, project_path, genome, contexts=["96"], simulations=100, chrom_based=True) -``` -3. Now the original mutations can be partitioned into clustered and non-clustered sets using the required parameters below: -``` ->> from SigProfilerClusters import SigProfilerClusters as hp ->> hp.analysis(project, genome, contexts, simContext, input_path) +Install your desired reference genome (available genomes: GRCh37, GRCh38, mm9, mm10): +```python +$ python +from SigProfilerMatrixGenerator import install as genInstall +genInstall.install('GRCh37') ``` -See below for a detailed list of available parameters - -4. The partitioned vcf files are placed under [project_path]/ouput/clustered/ and [project_path]/ouput/nonClustered/. You can visualize the results by looking at the IMD plots available under [project_path]/ouput/plots/. - - -**AVAILABLE PARAMETERS** - -### Required Parameters - -| Parameter | Variable Type | Description | -|--------------|--------------------|-------------| -| `project` | String | Unique name for the given project. | -| `genome` | String | Reference genome to use. Must be installed using SigProfilerMatrixGenerator. | -| `contexts` | String | Contexts needs to be one of the following: `"96"`, `"ID"`. | -| `simContext` | List of Strings | Mutation context used for generating the background model (e.g., `["6144"]` or `["96"]`). | -| `input_path` | String | Path to the input files. Must end with a `/`, e.g., `"path/to/the/input_file/"`. | - ---- - -### Optional Parameters - -| Parameter | Variable Type | Description | -|----------------|----------------|-------------| -| `analysis` | String | Desired analysis pipeline. Options include `"all"` (default), `"subClassify"`, and `"hotspot"`. | -| `sortSims` | Boolean | Option to sort simulated files. Ensures accuracy. Default: `True`. | -| `interdistance` | String | Mutation types to calculate IMDs between. Use only for indel analysis. Default: `"ID"`. | -| `calculateIMD` | Boolean | Whether to calculate IMDs. Useful for rerunning subclassification only. Default: `True`. | -| `max_cpu` | Integer | Number of CPUs to use. Default: all available CPUs. | -| `subClassify` | Boolean | Subclassify clustered mutations (requires VAF scores in TCGA/Sanger format). Default: `False`. | -| `plotIMDfigure` | Boolean | Generate IMD and mutational spectra plots for each sample. Default: `True`. | -| `plotRainfall` | Boolean | Generate rainfall plots using subclassified clustered events. Default: `True`. | - ---- - -### Parameters Used if `subClassify=True` -| Parameter | Variable Type | Description | -|------------------|---------------|-------------| -| `includedVAFs` | Boolean | Indicates VAFs are included in the dataset. Default: `True`. | -| `includedCCFs` | Boolean | Indicates CCFs are included. If `True`, set `includedVAFs=False`. Default: `True`. | -| `variant_caller` | String | Format of VAF scores (e.g., `"standard"`). Default: `"standard"`. | -| `windowSize` | Integer | Window size for calculating mutation density in rainfall plots. Default: `10000000`. | -| `correction` | Boolean | Perform genome-wide mutational density correction. Default: `False`. | -| `probability` | Boolean | Calculate the probability of observing each clustered event in its local region. Output saved in `[project_path]/output/clustered/`. Default: `False`. | +### Running +First, generate a background model using [SigProfilerSimulator](https://github.com/SigProfilerSuite/SigProfilerSimulator) (minimum 100 simulations recommended): +```python +from SigProfilerSimulator import SigProfilerSimulator as sigSim +sigSim.SigProfilerSimulator(project, project_path, genome, contexts=["288"], chrom_based=True, simulations=100) +``` -**VAF Format** - -SigProfilerClusters uses the VAF recorded in the input files to subclassify clustered mutations when subclassify=True and includedVAFs=True. However, depending on the VCF file, the VAF may be recorded in a different format. Below are the accepted formats corresponding to the correct settings to use for this tool. - -If you are not using VCFs as input files, VAFs cannot be used in the subclassification step. Therefore, to subclassify clusters using other input file types set subclassify=True and includedVAFs=False. - -If your VAF is recorded in the 11th column of your VCF as the last number of the colon delimited values, set variant_caller="caveman". - -If your VAF is recorded in the 8th or 10th column of your VCF as VAF=xx or AF=xx, set variant_caller="standard". - -If your VAF is recorded in the 10th or 11th column of your VCF as AF=xx, set variant_caller="mutect2". - -If your VCFs have no recorded VAFs set includedVAFs=False. This will run SigProfilerClusters, subclassify clusters based on just the calculated IMD (provided that you set subclassify=True). - - -**CCF Format** -Alternatively, SigProfilerClusters accepts cancer cell fraction (CCF) estimates in place of VAFs, when includedCCFs=True and includedVAFs=False to correct for copy number amplifications. To use CCFs, one must add the CCF values in the last column of each row within each VCF file (tab separated columns). - - -**Output Format** -All mutations are categorized into either clustered or non-clustered mutations. Each are saved under their respective directories within VCF files ([project_path]/output/clustered/ or [project_path]/output/nonClustered/; respectively). The clustered folder contains the partition of clustered mutations, which have been subclassified into one of four categories (five if using VAFs/CCFs). Within each subclass subfolder, a single VCF file is saved for each sample. All visualizations including rainfall plots are found within the output directory ([project_oath]/output/plots/). -Please refer to the Output page on the OSF wiki page for more details on all available output including available plots (https://osf.io/qpmzw/wiki/4.%20Output/). - -**LOG FILES** - -All errors and progress checkpoints are saved into SigProfilerClusters_[project]_[genome].err and SigProfilerClusters_[project]_[genome].out, respectively. For all errors, please email the error and progress log files to the primary contact under CONTACT INFORMATION. - - - -**Example Files** -Two examples are provided under examples/. These directories include all expected output except for the simulations folder to reduce memory size (please see the OSF page for more details: https://osf.io/qpmzw/wiki/4.%20Output/). - - -CITATIONS - -Erik N Bergstrom, Mousumy Kundu, Noura Tbeileh, Ludmil B Alexandrov. bioRxiv 2022.02.11.480117; doi: https://doi.org/10.1101/2022.02.11.480117 - -COPYRIGHT - -Copyright (c) 2023, Erik Bergstrom [Alexandrov Lab] All rights reserved. +Then, partition mutations into clustered and non-clustered sets: +```python +from SigProfilerClusters import SigProfilerClusters as hp +hp.analysis(project, genome, contexts, simContext, input_path) +``` -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +Results are placed under `[project_path]/output/clustered/` and `[project_path]/output/nonClustered/`. Visualizations are found under `[project_path]/output/plots/`. -Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +## Reference -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. +Bergstrom EN, Kundu M, Tbeileh N, Alexandrov LB. Examining clustered somatic mutations with SigProfilerClusters. *Bioinformatics*. 2022;38(13):3470–3473. [https://doi.org/10.1093/bioinformatics/btac335](https://doi.org/10.1093/bioinformatics/btac335) -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. +Bergstrom EN, Luebeck J, Petljak M, et al. Mapping clustered mutations in cancer reveals APOBEC3 mutagenesis of ecDNA. *Nature*. 2022;602:510–517. [https://doi.org/10.1038/s41586-022-04398-6](https://doi.org/10.1038/s41586-022-04398-6) -CONTACT INFORMATION +## Contact -Please address any queries or bug reports to Erik Bergstrom at ebergstr@health.ucsd.edu or Mousumy Kundu at mkundu@health.ucsd.edu +For questions, support requests, or bug reports, please contact the SigProfilerSuite team via GitHub [issues](https://github.com/SigProfilerSuite/SigProfilerClusters/issues) or by email at [contact@sigprofilersuite.org](mailto:contact@sigprofilersuite.org). diff --git a/docs/1_installation.md b/docs/1_installation.md new file mode 100644 index 0000000..05c4fd2 --- /dev/null +++ b/docs/1_installation.md @@ -0,0 +1,82 @@ +# Installation + + +---------- + + +This section will help you set up the necessary software and packages required to run SigProfilerClusters. + +---------- + + +## Prerequisites ## + +- [Python][1] version >= 3.9 +- [SigProfilerMatrixGenerator][2] with a downloaded reference genome (required to generate mutational matrices and simulations) +- [SigProfilerSimulator][3] (required to generate the background model used for IMD threshold calculation) +- Other dependencies are installed automatically during package installation + +## Installation ## + +SigProfilerClusters can be executed on any Windows/macOS/Unix system. First follow the [SigProfilerMatrixGenerator][2] guide for installing `Python` and `pip`. Next, follow the instructions below for the latest stable release or the current GitHub version. + +### Installation with `pip` ### + +Install the latest `SigProfilerClusters` PyPI version using `pip`: +``` +$ pip install SigProfilerClusters +``` + +To upgrade an existing installation to the most recent version: +``` +$ pip install SigProfilerClusters --upgrade +``` + +### Install specific GitHub Release ### + +First, download the [zip file][4] or clone the GitHub repository: +``` +$ git clone https://github.com/SigProfilerSuite/SigProfilerClusters.git +``` + +Next, enter the downloaded directory and install the package: +``` +$ cd SigProfilerClusters +$ pip install . +``` + +## Download Reference Genome ## + +SigProfilerClusters requires a reference genome to generate simulations and mutational matrices. Current reference genomes supported include GRCh37, GRCh38, mm9, and mm10. To install the reference genome/s, you need to use [SigProfilerMatrixGenerator][2]. + +The last PyPI [SigProfilerMatrixGenerator][2] version is installed with SigProfilerClusters by default. You can also install a specific version following the instructions in the [SigProfilerMatrixGenerator Wiki][2]. + +Once [SigProfilerMatrixGenerator][2] is installed, install your desired reference genome from the command line/terminal as follows. + +### Installation from command line ### + +``` +$ SigProfilerMatrixGenerator install GRCh37 +``` + +### Installation from Python terminal ### + +``` python +$ python +>>> from SigProfilerMatrixGenerator import install as genInstall +>>> genInstall.install('GRCh37', rsync=False, bash=True) +``` + +If you have a firewall on your server, you may need to install `rsync` and use the `rsync=True` parameter. Similarly, if you do not have bash available, use `bash=False`. + +In case you prefer to install a reference genome from a local copy: +``` python +$ python +>>> from SigProfilerMatrixGenerator import install as genInstall +>>> genInstall.install('GRCh37', offline_files_path='path/to/directory/containing/GRCh37.tar.gz') +``` + + [1]: https://www.python.org/downloads + [2]: https://sigprofilersuite.github.io/SigProfilerMatrixGenerator/ + [3]: https://osf.io/usxjz/wiki/home/ + [4]: https://github.com/SigProfilerSuite/SigProfilerClusters/releases diff --git a/docs/2_quick_start_example.md b/docs/2_quick_start_example.md new file mode 100644 index 0000000..0e5151b --- /dev/null +++ b/docs/2_quick_start_example.md @@ -0,0 +1,75 @@ +# Quick Start Example + + +---------- + + +This section provides a minimal example to get started with SigProfilerClusters. The following example uses a breast cancer sample (`BRCA`) or a melanoma sample (`MELA`) and demonstrates the complete workflow: generating simulations with [SigProfilerSimulator][2] and detecting clustered mutations with SigProfilerClusters. + +---------- + +## Prerequisites ## + +This tutorial requires that you have completed all steps in the [installation guide][1], specifically: + +- Installed SigProfilerClusters +- Installed [SigProfilerSimulator][2] +- Downloaded the **GRCh37** reference genome using [SigProfilerMatrixGenerator][3] + +## Downloading input example data ## + +Download one of the example VCF files below and place it in a new project directory (e.g., `path/to/data/`): + +- [BRCA_example_subs.vcf][5] — breast cancer substitutions +- [BRCA_example_indels.vcf][7] — breast cancer indels +- [MELA_example.vcf][6] — melanoma substitutions + +These samples and their expected outputs are also available under the `examples/` directory within the [GitHub repository](https://github.com/SigProfilerSuite/SigProfilerClusters). + +!!! note + The `simulations/` folder is not included in the GitHub repository to reduce its memory footprint. + +## Running SigProfilerClusters ## + +First, start a Python interactive shell and import [SigProfilerMatrixGenerator][3], [SigProfilerSimulator][2], and SigProfilerClusters. + +``` python +$ python +>>> from SigProfilerMatrixGenerator import install as genInstall +>>> from SigProfilerSimulator import SigProfilerSimulator as sigSim +>>> from SigProfilerClusters import SigProfilerClusters as hp +``` + +### Step 1: Run SigProfilerSimulator ### + +Generate a background model by running at least 100 simulations of inter-mutational distances for your data. **Note**: Update `"path/to/data"` with the actual path to the directory containing the VCF file. + +``` python +>>> sigSim.SigProfilerSimulator("BRCA", "path/to/data", "GRCh37", contexts=["288"], chrom_based=True, simulations=100) +``` + +### Step 2: Run SigProfilerClusters ### + +Cluster mutations based on the simulated background distribution. **Note**: Update `"path/to/data"` with the actual path to your project directory. + +``` python +>>> hp.analysis("BRCA", "GRCh37", "96", ["288"], "path/to/data", + analysis="all", sortSims=True, subClassify=True, + correction=True, calculateIMD=True, max_cpu=4, + variant_caller="standard") +``` + +After SigProfilerClusters has finished running, the output will be organized under `path/to/data/output/`. Partitioned mutations are placed under `output/clustered/` and `output/nonClustered/`, and visualizations are found under `output/plots/`. To learn more about all output files, please refer to the [Using the Tool - Output][4] section. + +## Additional Information ## + +In the above example, unspecified parameters use their default values. All function arguments and their types are described in detail in the [Using the Tool - Input][8] section. To learn more about the generated output files, refer to [Using the Tool - Output][4]. + + [1]: https://sigprofilersuite.github.io/SigProfilerClusters/1_installation.html + [2]: https://osf.io/usxjz/wiki/home/ + [3]: https://sigprofilersuite.github.io/SigProfilerMatrixGenerator/ + [4]: https://sigprofilersuite.github.io/SigProfilerClusters/5_using_the_tool_output.html + [5]: https://osf.io/gy2bh/ + [6]: https://osf.io/a8bq5/ + [7]: https://osf.io/tyw3u/ + [8]: https://sigprofilersuite.github.io/SigProfilerClusters/4_using_the_tool_input.html diff --git a/docs/3_workflow.md b/docs/3_workflow.md new file mode 100644 index 0000000..af26901 --- /dev/null +++ b/docs/3_workflow.md @@ -0,0 +1,49 @@ +# Workflow + + +---------- + + +This section describes the methodology used by SigProfilerClusters to identify and classify clustered mutations. The tool follows a four-stage process that distinguishes genuinely clustered mutations from those distributed randomly across the genome. + +!!! note "Minimum mutational burden" + Reliable analysis requires a mutational burden greater than **0.005 mutations per megabase**. Samples below this threshold may not produce meaningful IMD-based clustering results. + +---------- + +## Stage 1: Background Model Generation ## + +A per-sample background model is created using [SigProfilerSimulator][1]. This tool randomizes each mutation across the genome while preserving: + +- The desired trinucleotide sequence context +- Transcriptional strand bias ratios +- The mutational burden on each chromosome + +A minimum of **100 simulations** is recommended to ensure a robust background distribution. + +## Stage 2: IMD Threshold Calculation ## + +SigProfilerClusters compares the distribution of real inter-mutational distances (IMD) with the simulated background to compute a **sample-specific IMD threshold**. The threshold is set at the point where at least **90% of mutations falling within it are unlikely to have occurred by chance**, i.e., their spacing cannot be explained by the background model. + +This approach ensures that the clustering criterion adapts to the mutation burden and genomic context of each individual sample. + +## Stage 3: Regional Correction ## + +The global IMD threshold is further refined by applying a **localized correction across 1-megabase genomic windows**. This step accounts for the uneven distribution of mutations throughout the genome — regions with higher mutation density will have a proportionally adjusted threshold — preventing over- or under-calling of clustered events in heterogeneous mutational landscapes. + +## Stage 4: Mutation Classification ## + +After thresholding and correction, mutations are assigned to one of the following categories based on their inter-mutational spacing and, when available, variant allele frequencies (VAF): + +| Class | Category | Description | +|-------|----------|-------------| +| Non-clustered | — | Mutations whose spacing is consistent with random expectation | +| Clustered | **DBS** (Doublet Base Substitution) | Exactly 2 adjacent SNVs on the same chromosomal position | +| Clustered | **MBS** (Multi-Base Substitution) | 3 or more adjacent SNVs on consecutive chromosomal positions | +| Clustered | **Omikli** | 2–3 clustered SNVs with IMD pattern consistent with a localized event | +| Clustered | **Kataegis** | 4 or more clustered SNVs with IMD pattern consistent with a regional hypermutation event | +| Clustered | **Other** | Clustered mutations with inconsistent allele frequencies; only identified when VAF/CCF data is available | + +Indels are classified as clustered or non-clustered but are not further subclassified into the categories above. + + [1]: https://osf.io/usxjz/wiki/home/ diff --git a/docs/4_using_the_tool_input.md b/docs/4_using_the_tool_input.md new file mode 100644 index 0000000..fa43e46 --- /dev/null +++ b/docs/4_using_the_tool_input.md @@ -0,0 +1,105 @@ +# Using SigProfilerClusters + + +---------- + + +This section describes SigProfilerClusters' main function for clustered mutation analysis, the accepted input file formats, and all available parameters. + +---------- + +## Function ## + +The main function in SigProfilerClusters is `analysis`. It partitions somatic mutations into clustered and non-clustered groups and, optionally, subclassifies clustered SNVs into DBS, MBS, Omikli, and Kataegis events. + +### Input files ### + +SigProfilerClusters accepts four input file types. All input files for a given project must be placed in the same directory (`input_path`): + +- **VCF** — one file per sample, with the sample ID as the filename. +- **MAF** — standard Mutation Annotation Format file. +- **Simple text file** — tab-delimited plain text format, as described in [SigProfilerMatrixGenerator][1]. +- **ICGC Format** — ICGC simple somatic mutation format. + +Additionally, a background model generated by [SigProfilerSimulator][2] must be present in the same project directory before running the `analysis` function. + +### Running the function ### + +First, start a Python interactive shell and import SigProfilerClusters: + +``` python +$ python +>>> from SigProfilerClusters import SigProfilerClusters as hp +``` + +Then call the `analysis` function with the required parameters: + +``` python +>>> hp.analysis(project, genome, contexts, simContext, input_path) +``` + +You can also run SigProfilerClusters from the command line: + +``` bash +$ SigProfilerClusters analysis project genome contexts simContext input_path +``` + +### Required parameters ### + +| Parameter | Variable Type | Parameter Description | +|-----------|---------------|-----------------------| +| `project` | String | Unique name for the given project | +| `genome` | String | Reference genome to use. Must be installed using [SigProfilerMatrixGenerator][1]. Supported genomes: GRCh37, GRCh38, mm9, mm10 | +| `contexts` | String | Mutational context for SNV analysis. Accepted values: `"96"` (substitutions) or `"ID"` (indels) | +| `simContext` | List of Strings | Mutation context used when generating the background model with [SigProfilerSimulator][2]. For example: `["288"]`, `["6144"]`, or `["96"]` | +| `input_path` | String | Path to the directory containing the input files. Must end with `/` (e.g., `"path/to/the/input_file/"`) | + +### Optional parameters ### + +| Parameter | Variable Type | Parameter Description | +|-----------|---------------|-----------------------| +| `analysis` | String | Analysis pipeline to run. Options: `"all"` (default), `"subClassify"`, `"hotspot"` | +| `sortSims` | Boolean | Sort simulated files to ensure accuracy. Default: `True` | +| `interdistance` | String | Mutation types for which to calculate IMDs. Use only for indel analysis. Default: `"ID"` | +| `calculateIMD` | Boolean | Whether to calculate IMDs. Set to `False` to rerun subclassification only. Default: `True` | +| `max_cpu` | Integer | Number of CPUs to use for parallel processing. Default: all available CPUs | +| `subClassify` | Boolean | Subclassify clustered mutations into DBS, MBS, Omikli, and Kataegis (requires VAF scores in TCGA/Sanger format if `includedVAFs=True`). Default: `False` | +| `plotIMDfigure` | Boolean | Generate IMD and mutational spectra plots for each sample. Default: `True` | +| `plotRainfall` | Boolean | Generate rainfall plots using subclassified clustered events. Default: `True` | + +### Parameters used when `subClassify=True` ### + +| Parameter | Variable Type | Parameter Description | +|-----------|---------------|-----------------------| +| `includedVAFs` | Boolean | Indicates that VAF scores are present in the input files and should be used for subclassification. Default: `True` | +| `includedCCFs` | Boolean | Indicates that Cancer Cell Fraction (CCF) estimates are used instead of VAFs. When `True`, set `includedVAFs=False`. Default: `True` | +| `variant_caller` | String | Format of the VAF column in the input VCF. Accepted values: `"standard"` (default), `"caveman"`, `"mutect2"` | +| `windowSize` | Integer | Window size (in bp) for calculating mutation density in rainfall plots. Default: `10000000` | +| `correction` | Boolean | Apply genome-wide mutational density correction to the IMD threshold. Default: `False` | +| `probability` | Boolean | Calculate the probability of observing each clustered event within its local genomic region. Results are appended as an extra column in the output VCF files under `[project_path]/output/clustered/`. Default: `False` | + +## VAF Formats ## + +SigProfilerClusters uses variant allele frequencies (VAF) to subclassify clustered mutations when `subClassify=True` and `includedVAFs=True`. The VAF may be recorded in different formats depending on the variant caller used. Select the appropriate `variant_caller` value using the table below: + +| `variant_caller` value | VAF column location | +|------------------------|---------------------| +| `"caveman"` | 11th column; last colon-delimited value (e.g., `0:0:0.25`) | +| `"standard"` | 8th or 10th column as `VAF=xx` or `AF=xx` | +| `"mutect2"` | 10th or 11th column as `AF=xx` | + +!!! tip "No VAF available" + If your input files contain no VAF information, set `includedVAFs=False`. SigProfilerClusters will still subclassify clusters based solely on the calculated IMD values (when `subClassify=True`). + +!!! note "Non-VCF input" + If you are using a non-VCF input format (MAF, simple text, ICGC), VAFs cannot be extracted from the file. In this case, set `subClassify=True` and `includedVAFs=False`. + +## CCF Format ## + +As an alternative to VAFs, SigProfilerClusters accepts **cancer cell fraction (CCF)** estimates to correct for copy number amplifications. To use CCFs: + +- Set `includedCCFs=True` and `includedVAFs=False`. +- Add the CCF value as a tab-separated extra column at the end of each variant row in the input VCF file. + + [1]: https://sigprofilersuite.github.io/SigProfilerMatrixGenerator/ + [2]: https://osf.io/usxjz/wiki/home/ diff --git a/docs/5_using_the_tool_output.md b/docs/5_using_the_tool_output.md new file mode 100644 index 0000000..7d22807 --- /dev/null +++ b/docs/5_using_the_tool_output.md @@ -0,0 +1,83 @@ +# Using SigProfilerClusters - Output + + +---------- + + +This section describes the output files and directories produced by SigProfilerClusters. All results are written under `[project_path]/output/`, organized into several subdirectories. + +---------- + +## Output Overview ## + +After a successful run, the output directory contains the following subdirectories: + +``` +[project_path]/output/ +├── clustered/ +├── nonClustered/ +├── plots/ +├── simulations/ +└── vcf_files_corrected/ +``` + +All errors and progress checkpoints are also saved as log files in the project directory: + +- `SigProfilerClusters_[project]_[genome].err` — error log +- `SigProfilerClusters_[project]_[genome].out` — progress log + +## `clustered/` Directory ## + +Contains the partitioned clustered mutations, organized into subclass subdirectories. Within each subclass folder, one VCF file is saved per sample. The subclasses correspond to the categories described in the [Workflow][1] section: + +| Subclass | Description | +|----------|-------------| +| `DBS/` | Doublet base substitutions (2 adjacent SNVs) | +| `MBS/` | Multi-base substitutions (3+ adjacent SNVs) | +| `omikli/` | Localized clustered events (2–3 SNVs) | +| `kataegis/` | Regional hypermutation events (4+ SNVs) | +| `other/` | Clustered events with inconsistent allele frequencies (only present when VAF/CCF data is available) | + +When `probability=True`, an extra column is appended to each VCF file containing the probability of observing that clustered event within its local genomic region. + +## `nonClustered/` Directory ## + +Contains VCF files with the non-clustered mutations for each sample. Substitution and indel mutations are stored in separate files, one per sample. + +## `plots/` Directory ## + +Contains two types of visualizations generated per sample: + +### IMD plots ### +Show the mutational spectra alongside the distribution of inter-mutational distances (IMD) for both the real data and the simulated background. These plots allow visual inspection of the clustering signal relative to the background model. + +### Rainfall plots ### +Display the IMD distribution across genomic coordinates for each sample, with the sample-dependent IMD threshold overlaid. Clustered events are color-coded by subclass, providing a genome-wide view of mutational clustering patterns. + +## `simulations/` Directory ## + +Contains three subdirectories with intermediate simulation data used for threshold calculation: + +| Subdirectory | Contents | +|--------------|----------| +| `imd_data/` | IMD values across all simulations | +| `original_imds/` | IMD values for the original (real) mutations | +| `sorted_sims/` | Simulation files sorted alphanumerically, used during threshold computation | + +## `vcf_files_corrected/` Directory ## + +Contains VCF files for both clustered and non-clustered mutations after the **localized IMD correction** step (Stage 3 of the [workflow][1]). These files reflect the final mutation assignments incorporating regional mutation density adjustments. + +## Mutation Class Summary ## + +Output files use the following class labels to describe the nature of each clustered event: + +| Class | Categories included | Description | +|-------|---------------------|-------------| +| Class 1 | DBS, MBS, Omikli | Small-scale clustered events involving 2–3 mutations | +| Class 2 | Kataegis | Larger hypermutation events; further subdivided by processivity | +| Class 3 | Other clustered | Remaining clustered mutations not fitting Class 1 or Class 2 criteria | + +Each output VCF row includes the mutation coordinates, alleles, IMD value, and allele frequency, enabling detailed downstream analysis of individual clustered events. + + [1]: https://sigprofilersuite.github.io/SigProfilerClusters/3_workflow.html diff --git a/docs/assets/images/SigProfilerClusters.png b/docs/assets/images/SigProfilerClusters.png new file mode 100755 index 0000000..50c35b0 Binary files /dev/null and b/docs/assets/images/SigProfilerClusters.png differ diff --git a/docs/assets/stylesheets/extra.css b/docs/assets/stylesheets/extra.css new file mode 100644 index 0000000..8b3e941 --- /dev/null +++ b/docs/assets/stylesheets/extra.css @@ -0,0 +1,29 @@ +:root { + --md-text-font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, + Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji"; +} + +.md-main__inner { + max-width: 80%; +} + +.md-grid { + max-width: 80%; +} + + +/* Improve readability of long tables from OSF wiki. */ +.md-typeset table:not([class]) { + display: block; + overflow-x: auto; + white-space: nowrap; +} + +/* Make big OSF screenshots feel less cramped. */ +.md-typeset img { + border-radius: 8px; +} + +p { + text-align: justify +} diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..b318028 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,38 @@ +# SigProfilerClusters + +![Logo](assets/images/SigProfilerClusters.png) + +---------- + +**SigProfilerClusters** is a Python framework for analyzing the inter-mutational distances (IMD) between SNV-SNV and INDEL-INDEL mutations. The tool separates mutations into clustered and non-clustered groups on a sample-dependent basis, and subclassifies all SNVs into one of four categories of clustered event: i) doublet base substitutions (DBS); ii) multi-base substitutions (MBS); iii) omikli; and iv) kataegis. Indels are identified as clustered or non-clustered but are not further subclassified. + +SigProfilerClusters builds a sample-specific background model using [SigProfilerSimulator][1] and applies an IMD-based threshold — corrected for regional mutation density — to distinguish mutations that are unlikely to have co-occurred by chance. This approach allows reliable detection of clustered mutational events across a wide range of tumor types and mutation burdens. + +**SigProfilerClusters** makes use of [SigProfilerSimulator][1] and [SigProfilerMatrixGenerator][2], enabling seamless integration with other tools in the SigProfiler suite. + +The SigProfilerClusters library is available on [GitHub](https://github.com/SigProfilerSuite/SigProfilerClusters) and [PyPI](https://pypi.org/project/SigProfilerClusters). + +!!! note "Previously known as SigProfilerHotSpots" + This tool was previously distributed under the name **SigProfilerHotSpots**. For all usage instructions, `SigProfilerClusters` and `SigProfilerHotSpots` may be used interchangeably when working with the older version of the tool. + +---------- + +### Citation + +Bergstrom EN, Kundu M, Tbeileh N, Alexandrov LB. Examining clustered somatic mutations with SigProfilerClusters. *Bioinformatics*. 2022;38(13):3470–3473. [https://doi.org/10.1093/bioinformatics/btac335](https://doi.org/10.1093/bioinformatics/btac335) + +Bergstrom EN, Luebeck J, Petljak M, et al. Mapping clustered mutations in cancer reveals APOBEC3 mutagenesis of ecDNA. *Nature*. 2022;602:510–517. [https://doi.org/10.1038/s41586-022-04398-6](https://doi.org/10.1038/s41586-022-04398-6) + +### License + +This software is copyrighted © 2022 by Erik Bergstrom, Alexandrov Lab. SigProfilerClusters is distributed under a BSD 2-Clause License. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the copyright notice and disclaimer are retained. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED. + +### Contact + +For questions, support requests, or bug reports, please contact the development team via GitHub [issues](https://github.com/SigProfilerSuite/SigProfilerClusters/issues) or by email: + +- Erik Bergstrom: [ebergstr@health.ucsd.edu](mailto:ebergstr@health.ucsd.edu) +- Mousumy Kundu: [mkundu@health.ucsd.edu](mailto:mkundu@health.ucsd.edu) + + [1]: https://osf.io/usxjz/wiki/home/ + [2]: https://osf.io/s93d5/wiki/home/ diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..1028b77 --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,60 @@ +site_name: SigProfilerClusters +repo_name: SigProfilerSuite/SigProfilerClusters +repo_url: https://github.com/SigProfilerSuite/SigProfilerClusters + +docs_dir: docs +site_url: https://sigprofilersuite.github.io/SigProfilerClusters/ + +use_directory_urls: false + +theme: + name: material + features: + - navigation.instant + - navigation.tracking + - navigation.tabs + - navigation.sections + - navigation.top + - toc.follow + - content.code.copy + palette: + - scheme: default + primary: indigo + accent: indigo + - scheme: slate + primary: indigo + accent: indigo + toggle: + icon: material/weather-night + name: Switch to dark mode + +nav: + - Home: index.md + - Getting Started: + - '1. Installation': '1_installation.md' + - '2. Quick Start Example': '2_quick_start_example.md' + - How It Works: + - '3. Workflow': '3_workflow.md' + - Using The Tool: + - '4. Using the Tool - Input': '4_using_the_tool_input.md' + - '5. Using the Tool - Output': '5_using_the_tool_output.md' + +plugins: + - search + +markdown_extensions: + - toc: + permalink: true + - attr_list + - md_in_html + - admonition + - pymdownx.superfences + - pymdownx.details + - pymdownx.tabbed: + alternate_style: true + +extra_css: + - assets/stylesheets/extra.css + +hooks: + - mkdocs_hooks.py diff --git a/mkdocs_hooks.py b/mkdocs_hooks.py new file mode 100644 index 0000000..9c8e57b --- /dev/null +++ b/mkdocs_hooks.py @@ -0,0 +1,13 @@ +import re + + +_OSF_TOC_RE = re.compile(r"^\s*@\[toc\]\([^)]+\)\s*$", re.IGNORECASE) + + +def on_page_markdown(markdown: str, /, *, page, config, files): + # OSF wiki pages contain a non-standard marker like `@[toc](Sections)` which MkDocs + # otherwise renders as a broken relative link. We keep the source files unchanged + # (to match OSF) and strip the marker at build time. + lines = markdown.splitlines() + filtered = [line for line in lines if not _OSF_TOC_RE.match(line)] + return "\n".join(filtered) + ("\n" if markdown.endswith("\n") else "")