Metadata-Version: 2.4
Name: somaticseq
Version: 3.12.0
Summary: SomaticSeq: An ensemble approach to accurately detect somatic mutations using SomaticSeq
Author: Li Tai Fang, Pegah Tootoonchi Afshar, Aparna Chhibber, Marghoob Mohiyuddin, John C. Mu, Greg Gibeling, Sharon Barr, Narges Bani Asadi, Hugo Y.K. Lam
Maintainer-email: Li Tai Fang <ltfang@gmail.com>
License: BSD-2-Clause
Project-URL: Homepage, https://github.com/bioinform/somaticseq
Keywords: somatic mutations,bioinformatics,genomics,ngs
Classifier: Development Status :: 5 - Production/Stable
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Healthcare Industry
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.11.0
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: pysam
Requires-Dist: numpy
Requires-Dist: scipy
Requires-Dist: pandas
Requires-Dist: pybedtools>=0.12.0
Requires-Dist: xgboost>=1.4
Requires-Dist: pydantic<3.0,>=2.0.0
Provides-Extra: dev
Requires-Dist: black; extra == "dev"
Requires-Dist: flake8; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-mock; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: description
Dynamic: description-content-type
Dynamic: license-file

# SomaticSeq

SomaticSeq is an ensemble somatic SNV/indel caller that has the ability to use
machine learning to filter out false positives from other callers. It also comes
with a suite of [genomic utilities](https://github.com/bioinform/somaticseq/blob/v3.12.0/somaticseq/utilities/README.md). The
detailed documentation is located in
[docs/Manual.pdf](https://github.com/bioinform/somaticseq/blob/v3.12.0/docs/Manual.pdf "User Manual").

- It was published in
  [Fang, L.T., Afshar, P.T., Chhibber, A. _et al_. An ensemble approach to accurately detect somatic mutations using SomaticSeq. _Genome Biol_ **16**, 197 (2015)](http://dx.doi.org/10.1186/s13059-015-0758-2 "Fang LT, et al. Genome Biol (2015)").
- Feel free to report issues and/or ask questions at the
  [Issues](https://github.com/bioinform/somaticseq/blob/v3.12.0/../../issues "Issues") page.

## Training data for benchmarking and/or model building

In 2021, the
[FDA-led MAQC-IV/SEQC2 Consortium](https://www.fda.gov/science-research/bioinformatics-tools/microarraysequencing-quality-control-maqcseqc#MAQC_IV)
has produced multi-center multi-platform whole-genome and whole-exome
[sequencing data sets](https://identifiers.org/ncbi/insdc.sra:SRP162370) for a
pair of tumor-normal reference samples (HCC1395 and HCC1395BL), along with the
high-confidence
[somatic mutation call set](https://ftp-trace.ncbi.nlm.nih.gov/ReferenceSamples/seqc/Somatic_Mutation_WG/release/latest/).
This work was published in
[Fang, L.T., Zhu, B., Zhao, Y. _et al_. Establishing community reference samples, data and call sets for benchmarking cancer mutation detection using whole-genome sequencing. _Nat Biotechnol_ **39**, 1151-1160 (2021)](https://doi.org/10.1038/s41587-021-00993-6 "Fang LT, et al. Nat Biotechnol (2021)")
/
[PMID:34504347](http://identifiers.org/pubmed:34504347 "Fang LT, et al. Nat Biotechnol (2021)")
/
[Free Read-Only Link](https://bit.ly/2021nbt "Fang LT, et al. Nat Biotechnol (2021)").
The following are some of the use cases for these resources:

- Use high-confidence call set as the "ground truth" to investigate how
  different sample preparations, sequencing library kits, and bioinformatic
  algorithms affect the accuracy of the somatic mutation pipelines, and develop
  best practices, e.g.,
  [Xiao W. _et al_. Nat Biotechnol 2021](https://doi.org/10.1038/s41587-021-00994-5).
- Use high-confidence call set as the "ground truth" to build accurate and
  robust machine learning models for somatic mutation detections, e.g.,
  [NeuSomatic by Sahraeian S.M.E. _et al_. Genome Biol 2022](https://doi.org/10.1186/s13059-021-02592-9),
  [DeepSomatic by Park J. _et al_. 2024](https://doi.org/10.1101/2024.08.16.608331).
- Use the bam files and high-confidence call set to benchmark a workflow, e.g.,
  [Benchmarking NVIDIA Clara Parabricks Somatic Variant Calling Pipeline on AWS](https://aws.amazon.com/blogs/hpc/benchmarking-nvidia-clara-parabricks-somatic-variant-calling-pipeline-on-aws/),
  [NVIDIA Docs Hub](https://docs.nvidia.com/clara/parabricks/how-tos/somaticcalling.html),
  [nf-core/sarek](https://doi.org/10.1093/nargab/lqae031), etc.

#### Click for [more details of the SEQC2's somatic mutation project](https://github.com/bioinform/somaticseq/blob/v3.12.0/docs/seqc2.md).

#### [Recommendation](https://github.com/bioinform/somaticseq/blob/v3.12.0/docs/train_for_classifiers.md) of how to use SEQC2 data to create SomaticSeq classifiers.

<hr>
<table style="width: 100%;">

  <tr>
    <td>Briefly explaining SomaticSeq v1.0</td>
    <td>SEQC2 somatic mutation reference data and call sets</td>
    <td>How to run <a href="https://precision.fda.gov/home/apps/app-G7XVKQQ02v051q5PK3yQYJKJ-1">SomaticSeq v3.6.3</a> on precisionFDA</td>

  </tr>

  <tr>
    <td><a href="https://youtu.be/MnJdTQWWN6w"><img src="https://github.com/bioinform/somaticseq/raw/v3.12.0/docs/SomaticSeqYoutube.png" width="400" /></a></td>
    <td><a href="https://youtu.be/nn0BOAONRe8"><img src="https://github.com/bioinform/somaticseq/raw/v3.12.0/docs/workflow400.png" width="400" /></a></td>
    <td><a href="https://youtu.be/fLKokuMGTvk"><img src="https://github.com/bioinform/somaticseq/raw/v3.12.0/docs/precisionfda.png" width="400" /></a></td>

  </tr>

  <tr>
    <td></td>
    <td></td>
    <td>Run in <a href="https://youtu.be/F6TSdg0OffM">train or prediction mode</a></td>

  </tr>

</table>
<hr>

# Installation

## Dependencies

This [dockerfile](https://github.com/bioinform/somaticseq/blob/v3.12.0/Dockerfiles/somaticseq.base-1.8.dockerfile) reveals the
dependencies

- Python 3, plus pysam, numpy, scipy, pandas, and xgboost libraries.
- [BEDTools](https://bedtools.readthedocs.io/en/latest/): required when parallel
  processing is invoked, and/or when any bed files are used as input files.
- Optional: dbSNP VCF file (if you want to use dbSNP membership as a feature).
- Optional: R and [ada](https://cran.r-project.org/package=ada) are required for
  AdaBoost, whereas XGBoost (default) is implemented in python.
- To install SomaticSeq, clone this repo, `cd somaticseq`, and then run
  `pip install .` (To install extra packages for development:
  `pip install '.[dev]'`). A number of commands prefixed with `somaticseq_` will
  be placed into the PATH.

## To install using pip

Make sure to install `bedtools` separately.

```
pip install somaticseq
```

## To install the bioconda version

SomaticSeq can also be found on
[![Anaconda-Server Badge](https://anaconda.org/bioconda/somaticseq/badges/version.svg)](https://anaconda.org/bioconda/somaticseq),
which has
[![Anaconda-Server Badge](https://anaconda.org/bioconda/somaticseq/badges/downloads.svg)](https://anaconda.org/bioconda/somaticseq)
so far. To
[![install with bioconda](https://img.shields.io/badge/install%20with-bioconda-brightgreen.svg?style=flat)](http://bioconda.github.io/recipes/somaticseq/README.html),
which also automatically installs a bunch of 3rd-party somatic mutation callers:

```
conda install -c bioconda somaticseq
```

## To install from github source with conda

```
conda create --name venv -c bioconda python bedtools
conda activate venv
git clone git@github.com:bioinform/somaticseq.git
cd somaticseq
pip install -e .
```

### Test your installation

If installed successfully, you will be able to run `somaticseq --help` in the
terminal. Also make sure `bedtools` is executable. There are some toy data sets
and test scripts in [**example**](tests/example) that should finish in <1 minute
if installed properly.

## Run SomaticSeq with an example command

- At minimum, given the results of the individual mutation caller(s), SomaticSeq
  will extract sequencing features for the combined call set. Required inputs
  for command `somaticseq` are:
    - `--output-directory` and `--genome-reference`, then
    - Either `paired` or `single` to invoke paired or single sample mode,
        - if `paired`: `--tumor-bam-file`, and `--normal-bam-file` are both
          required.
        - if `single`: `--bam-file` is required.

    Everything else is optional (though without a single VCF file from at least
    one caller, SomaticSeq does nothing).

- The following four files will be created into the output directory:
    - `Consensus.sSNV.vcf`, `Consensus.sINDEL.vcf`, `Ensemble.sSNV.tsv`, and
      `Ensemble.sINDEL.tsv`.

- If you're searching for pipelines to run those individual somatic mutation
  callers, feel free to take advantage of our
  [**Dockerized Somatic Mutation Workflow**](https://github.com/bioinform/somaticseq/blob/v3.12.0/somaticseq/utilities/dockered_pipelines)
  as a start.
    - Important note: multi-argument options (e.g., `--extra-hyperparameters` or
      `--features-excluded`) cannot be placed immediately before `paired` or
      `single`, because those options would try to "grab" `paired` or `single`
      as an additional argument.

```
# Merge caller results and extract SomaticSeq features
somaticseq \
  --output-directory  $OUTPUT_DIR \
  --genome-reference  GRCh38.fa \
  --inclusion-region  genome.bed \
  --exclusion-region  blacklist.bed \
  --threads           24 \
paired \
  --tumor-bam-file    tumor.bam \
  --normal-bam-file   matched_normal.bam \
  --mutect2-vcf       MuTect2/variants.vcf \
  --varscan-snv       VarScan2/variants.snp.vcf \
  --varscan-indel     VarScan2/variants.indel.vcf \
  --jsm-vcf           JointSNVMix2/variants.snp.vcf \
  --somaticsniper-vcf SomaticSniper/variants.snp.vcf \
  --vardict-vcf       VarDict/variants.vcf \
  --muse-vcf          MuSE/variants.snp.vcf \
  --lofreq-snv        LoFreq/variants.snp.vcf \
  --lofreq-indel      LoFreq/variants.indel.vcf \
  --scalpel-vcf       Scalpel/variants.indel.vcf \
  --strelka-snv       Strelka/variants.snv.vcf \
  --strelka-indel     Strelka/variants.indel.vcf \
  --arbitrary-snvs    additional_snv_calls_1.vcf.gz additional_snv_calls_2.vcf.gz ... \
  --arbitrary-indels  additional_indel_calls_1.vcf.gz additional_indel_calls_2.vcf.gz ...
```

- For all of those input VCF files, both `.vcf` and `.vcf.gz` are acceptable.
  SomaticSeq also accepts `.cram`, but some callers may only take `.bam`.

- `--arbitrary-snvs` and `--arbitrary-indels` are added since v3.7.0. It allows
  users to input **any** arbitrary VCF file(s) from caller(s) that we did not
  explicitly incorporate. SNVs and indels have to be separated.
    - If your caller puts SNVs and indels in the same output VCF file, you may
      split it using a SomaticSeq utility script, e.g.,
      `somaticseq_split_vcf -infile small_variants.vcf -snv snvs.vcf -indel indels.vcf`.
      As usual, input can be either `.vcf` or `.vcf.gz`, but output will be
      `.vcf`.
    - For those VCF file(s), any calls **not** labeled REJECT or LowQual will be
      considered a bona fide somatic mutation call. REJECT calls will be
      skipped. LowQual calls will be considered, but will not have a value of
      `1` in `if_Caller` machine learning feature.

- `--inclusion-region` or `--exclusion-region` will require `bedtools` in your
  path.

- `--algorithm` defaults to `xgboost` as v3.6.0, but can also be `ada` (AdaBoost
  in R). XGBoost supports multi-threading and can be orders of magnitude faster
  than AdaBoost, and seems to be about the same in terms of accuracy, so we
  changed the default from `ada` to `xgboost` as v3.6.0 and that's what we
  recommend now.

- To split the job into multiple threads, place `--threads X` before the
  `paired` option to indicate X threads. It simply creates multiple BED file
  (each consisting of 1/X of total base pairs) for SomaticSeq to run on each of
  those sub-BED files in parallel. It then merges the results. This requires
  `bedtools` in your path.

Additional parameters to be specified **before** `paired` option to invoke
training mode. In addition to the four files specified above, two classifiers
(SNV and indel) will be created..

- `--somaticseq-train`: FLAG to invoke training mode with no argument, which
  also requires ground truth VCF files.
    - `--extra-hyperparameters`: add hyperparameters for xgboost, e.g.,
      `--extra-hyperparameters scale_pos_weight:0.1 grow_policy:lossguide max_leaves:12`.
- `--truth-snv`: if you have a ground truth VCF file for SNV
- `--truth-indel`: if you have a ground truth VCF file for INDEL

Additional input files to be specified **before** `paired` option invoke
prediction mode (to use classifiers to score variants). Four additional files
will be created, i.e., `SSeq.Classified.sSNV.vcf`, `SSeq.Classified.sSNV.tsv`,
`SSeq.Classified.sINDEL.vcf`, and `SSeq.Classified.sINDEL.tsv`.

- `--classifier-snv`: classifier previously built for SNV
- `--classifier-indel`: classifier previously built for INDEL

Without those paramters above to invoking training or prediction mode,
SomaticSeq will default to majority-vote consensus mode.

## To train for SomaticSeq classifiers with multiple data sets combined

Run `somaticseq_xgboost train --help` to see the options. It is recommended that
SNV and INDEL models be trained separately, but it is up to you to experiment,
e.g.,

```
somaticseq_xgboost train \
  -tsvs SAMPLE_1/Ensemble.sSNV.tsv SAMPLE_2/Ensemble.sSNV.tsv ... SAMPLE_N/Ensemble.sSNV.tsv \
  -out multiSample.SNV.classifier \
  -threads 8 -depth 12 -seed 42 -method hist -iter 250 \
  --extra-params scale_pos_weight:0.1 grow_policy:lossguide max_leaves:12
```

## Run SomaticSeq modules seperately

Most SomaticSeq modules can be run on their own. They may be useful in debugging
context, or be run for your own purposes. See [this page](https://github.com/bioinform/somaticseq/blob/v3.12.0/MODULES.md) for your
options.

## Dockerized workflows and pipelines

### To run somatic mutation callers and then SomaticSeq

We have created a module (i.e., `somaticseq_make_somatic_scripts`) that can run
all the dockerized somatic mutation callers and then SomaticSeq, described at
[**somaticseq/utilities/dockered_pipelines**](https://github.com/bioinform/somaticseq/blob/v3.12.0/somaticseq/utilities/dockered_pipelines).
There is also an alignment workflow described there. You need
[docker](https://www.docker.com/) to run these workflows. Singularity is also
supported, but is not optimized. Let me know if you find bugs.

### To create training data to create SomaticSeq classifiers

- I recommend [SEQC2 Somatic Mutation Working Group](https://github.com/bioinform/somaticseq/blob/v3.12.0/docs/seqc2.md)'s
  [reference sequencing data](https://identifiers.org/ncbi/insdc.sra:SRP162370)
  and
  [high-confidence somatic mutation call sets](https://ftp-trace.ncbi.nlm.nih.gov/ReferenceSamples/seqc/Somatic_Mutation_WG/release/latest/).

- Before well characterized real data was available, we have dockerized
  pipelines for _in silico_ mutation spike in at
  [**somaticseq/utilities/dockered_pipelines/bamSimulator**](https://github.com/bioinform/somaticseq/blob/v3.12.0/somaticseq/utilities/dockered_pipelines/bamSimulator).
  These pipelines are based on
  [BAMSurgeon](https://github.com/adamewing/bamsurgeon). We have used it to
  create training set to build SomaticSeq classifiers, though it has not been
  updated for a while.

- Combine both BAMSurgeon _in silico_ spike in and the real SEQC2 training data
  **may** give you better model than using either, which was shown in
  [Sahraeian S.M.E. _et al_. 2022](https://doi.org/10.1186/s13059-021-02592-9).
  The reason may be that the real data's high-confidence call sets do not have
  the most challenging genomic regions, whereas _in silico_ data do not have the
  most realistic data characteristics. Combining both allows them to cover each
  other's shortcomings.

### Dockerized alignment pipeline based on GATK's best practices

Described at
[**somaticseq/utilities/dockered_pipelines**](https://github.com/bioinform/somaticseq/blob/v3.12.0/somaticseq/utilities/dockered_pipelines).
The module is `somaticseq_make_alignment_scripts`.

### Utilities

We have some generally useful scripts in [utilities](https://github.com/bioinform/somaticseq/blob/v3.12.0/somaticseq/utilities). Some
of the more useful tools, e.g.,

- `somaticseq_loci_counter` finds overlapping regions among multiple bed files.
- `somaticseq_run_workflows` is a rudimentary workflow manager that executes
  multiple scripts at once.
- `somaticseq_split_bed_into_equal_regions` splits one bed file into a number of
  output bed files, where each output bed file will have the same total length.
- `somaticseq_linguistic_sequence_complexity` calculates sequence complexity
  given a nucleotide sequence (e.g., GCCAGAC) based on
  [Troyanskaya OG _et al_. Bioinformatics 2002](https://doi.org/10.1093/bioinformatics/18.5.679).
