Metadata-Version: 2.2
Name: migec
Version: 2.7.2
Summary: UMI barcode extraction, correction and consensus assembly for barcoded sequencing
Keywords: umi,barcode,consensus,airr,repseq,single-cell,sequencing
Author-Email: Mikhail Shugay <mikhail.shugay@gmail.com>
License: ISALGO LAB Academic and Non-Commercial Research License
         Version 1.0
         
         Copyright (c) 2026 ISALGO LAB. All rights reserved.
         
         0. DEFINITIONS
         
            "Software" means the software, source code, scripts, models, trained
            parameters, and associated documentation files distributed under this
            license, together with any Modification thereof.
         
            "Modification" means any change to, adaptation of, translation of, or work
            derived from the Software, in whole or in part.
         
            "Output" means any data produced by running the Software, including
            predictions, scores, embeddings, annotations, labels, rankings, alignments,
            simulated or synthetic data, and any file derived from them.
         
            "Model" means any machine-learning or statistical system whose parameters
            are fitted from data, including neural networks, gradient-boosted trees,
            regression models, and any set of trained parameters, whether or not
            distributed together with code.
         
            "You" means the individual or legal entity exercising the rights granted
            below.
         
            "Non-Commercial Use" means use for academic, educational, or scientific
            research purposes from which no commercial advantage or monetary
            compensation is sought or obtained, whether directly or indirectly.
         
            "Commercial Use" means any use that is not Non-Commercial Use, including
            without limitation: (a) use in or to develop a product, service, or
            pipeline that is sold, licensed, rented, or otherwise monetized;
            (b) use by a for-profit entity in connection with its business operations,
            including internal evaluation, benchmarking, or research and development;
            (c) use to provide services to third parties for a fee, including
            consulting, contract research, or hosted or cloud-based provision of the
            Software's functionality; (d) use in research performed under contract for,
            or funded directly by, a for-profit entity for that entity's proprietary
            benefit; and (e) any use described in Section 3.
         
         1. GRANT OF RIGHTS
         
            Permission is hereby granted, free of charge, to any person obtaining a
            copy of the Software, to use, copy, modify, merge, publish, and distribute
            the Software for Non-Commercial Use only, subject to all conditions below.
            No rights are granted other than those expressly stated here; all rights
            not expressly granted are reserved by the copyright holder.
         
         2. PROHIBITED USE
         
            Commercial Use of the Software is prohibited without a separate written
            license signed by the copyright holder.
         
         3. MACHINE-LEARNING AND MODEL TRAINING
         
            3.1 The following are permitted under this license only when the resulting
                Model and its Outputs are themselves put to Non-Commercial Use:
         
                (a) training, fine-tuning, pre-training, continued training, or
                    retraining any Model on the Software, on its source code, or on
                    its Output;
                (b) using the Output as training data, labels, targets, weak
                    supervision, reward or preference signal, validation data, or test
                    data for any Model;
                (c) using the Software or its Output to filter, clean, augment, score,
                    rank, deduplicate, or otherwise curate a data set used to train
                    any Model;
                (d) distilling, pruning, quantizing, compressing, or otherwise
                    deriving a second Model from any Model distributed as part of the
                    Software, or from that Model's Output;
                (e) using the Software or its Output to benchmark, evaluate, validate,
                    tune hyperparameters of, or select among Models;
                (f) embedding the Software, or a Model trained in any of the ways
                    above, in an automated or agent-driven pipeline.
         
            3.2 Each activity listed in Section 3.1 is Commercial Use, and therefore
                prohibited without a separate written license, whenever the resulting
                Model, its Outputs, its parameters, or any system containing it is:
                sold, licensed, rented, hosted, or otherwise monetized; used by or on
                behalf of a for-profit entity in connection with its business
                operations; used to provide services to third parties for a fee; or
                used to support an application for, prosecution of, or exploitation of
                a patent or other proprietary right held by a for-profit entity.
         
            3.3 A Model is subject to this Section regardless of how much of the
                Software or its Output contributed to that Model, and regardless of
                whether the Software or its Output can be recovered from the trained
                parameters. Intermediate steps do not remove a Model from the scope of
                this Section: a Model trained on a data set that was itself produced,
                curated, or filtered using the Software remains subject to it.
         
            3.4 Where a Model is trained partly on the Software or its Output and
                partly on other material, Section 3.2 applies to that Model in full.
         
            3.5 Publication of research results, including trained parameters released
                for Non-Commercial Use under terms no less restrictive than this
                license, is permitted and encouraged.
         
         4. REDISTRIBUTION
         
            You may distribute the Software, with or without Modification, provided
            that You:
         
            (a) retain this license in full, including the copyright notice of
                Section 0 and the disclaimer of Section 9, in all copies and in all
                Modifications;
            (b) do not sublicense the Software or impose any additional or different
                terms, so that every recipient receives exactly the rights and
                restrictions granted here and no more;
            (c) mark each Modification with a prominent notice stating that the file
                has been changed, by whom, and on what date;
            (d) charge no fee for the Software itself, beyond the actual cost of
                physical media or transmission.
         
         5. ATTRIBUTION
         
            Any publication, presentation, preprint, poster, or derived work that makes
            use of the Software must cite this repository, or the corresponding
            publication where one is specified in the repository. Any released Model
            covered by Section 3 must state in its accompanying documentation that the
            Software was used in its construction.
         
         6. NO TRADEMARK OR PATENT RIGHTS
         
            This license grants no right to use the names, trademarks, or logos of
            ISALGO LAB, the copyright holder, or any contributor, whether to endorse or
            promote any work or otherwise, without prior written permission. This
            license grants no patent rights, express or implied, under any patent owned
            or controlled by the copyright holder.
         
         7. TERM AND TERMINATION
         
            The rights granted here apply for as long as You comply with this license
            and terminate automatically, without notice, upon any breach. Rights may be
            reinstated in writing by the copyright holder. Sections 2, 3, 6, 8, and 9
            survive termination. Upon termination You must cease all use of the
            Software and destroy all copies in Your possession, except copies retained
            solely for archival purposes required by law or institutional policy.
         
         8. COMMERCIAL AND TRIAL LICENSING
         
            Parties seeking Commercial Use, use of the Software or its Output in
            training a Model for Commercial Use, an evaluation or trial license, or any
            rights beyond those granted here should contact ISALGO LAB. Such licenses are
            granted only in writing.
         
         9. DISCLAIMER OF WARRANTY AND LIMITATION OF LIABILITY
         
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
            IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
            FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
            THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
            LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
            FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
            DEALINGS IN THE SOFTWARE.
         
            The Software is a research tool. It is not validated for clinical,
            diagnostic, therapeutic, or any other use on which health, safety, or
            financial decisions depend.
         
         10. SEVERABILITY
         
            If any provision of this license is held unenforceable, that provision
            shall be modified to the minimum extent necessary to make it enforceable,
            and the remaining provisions shall remain in full effect.
         
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: C++
Project-URL: Homepage, https://github.com/antigenomics/migec
Project-URL: Documentation, https://antigenomics.github.io/migec/
Requires-Python: >=3.10
Requires-Dist: typer>=0.12
Requires-Dist: seqtree>=1.3.4
Provides-Extra: seqtree
Provides-Extra: notebooks
Requires-Dist: polars>=1.0; extra == "notebooks"
Requires-Dist: marimo; extra == "notebooks"
Requires-Dist: matplotlib>=3.8; extra == "notebooks"
Provides-Extra: docs
Requires-Dist: sphinx; extra == "docs"
Requires-Dist: pydata-sphinx-theme; extra == "docs"
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Provides-Extra: dev
Requires-Dist: ruff; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pybind11; extra == "dev"
Requires-Dist: marimo; extra == "dev"
Description-Content-Type: text/markdown

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/antigenomics/migec/master/assets/migec_dark.png">
    <img alt="migec" src="https://raw.githubusercontent.com/antigenomics/migec/master/assets/migec_light.png" width="340">
  </picture>
</p>

<p align="center">
  <a href="https://pypi.org/project/migec/"><img alt="PyPI" src="https://img.shields.io/pypi/v/migec"></a>
  <a href="https://github.com/antigenomics/migec/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/antigenomics/migec/actions/workflows/ci.yml/badge.svg"></a>
  <a href="https://antigenomics.github.io/migec/"><img alt="docs" src="https://github.com/antigenomics/migec/actions/workflows/docs.yml/badge.svg"></a>
  <img alt="python" src="https://img.shields.io/badge/python-3.10%2B-blue">
  <img alt="C++" src="https://img.shields.io/badge/C%2B%2B-20-blue">
  <img alt="license" src="https://img.shields.io/badge/license-Academic%20%26%20Non--Commercial-green">
</p>

<h1 align="center">migec — molecular identifiers, reliable consensus</h1>

**Extract barcodes, correct UMI errors and assemble molecular consensus sequences.**
MIGEC combines a C++20 core with a Python CLI for bulk and cell-barcoded sequencing.
It reconstructs molecules; receptor annotation belongs to [ARDA](https://github.com/antigenomics/arda).

<p align="center"><img alt="Schematic: extract barcodes, correct UMI errors, assemble consensus and inspect QC" src="https://raw.githubusercontent.com/antigenomics/migec/master/assets/pipeline.svg" width="440"></p>

## Install

```bash
pip install migec
migec info
```

Binary wheels support CPython 3.10–3.13 on Linux x86-64 and macOS arm64.
For a source checkout, run `bash setup.sh`. See [installation](https://antigenomics.github.io/migec/installation.html).
The original Groovy version remains on [`legacy-v1`](https://github.com/antigenomics/migec/tree/legacy-v1).

## Quick start

Declare the barcode layout from your library protocol, then run the three stages:

```bash
migec checkout reads.fq.gz --bc-pattern '^NNNNNNNN' --sample S1 -o out/
migec refine out/S1.fq.gz -o ref/
migec assemble ref/S1.fq.gz -o cons/
```

`N` captures a UMI base; `X` captures a cell-barcode base. Positional slices such as
`0:8`, named chemistry presets and sample barcode tables are also supported.
Use [layouts](https://antigenomics.github.io/migec/layouts.html) to match your protocol,
and [examples](https://antigenomics.github.io/migec/examples.html) for paired and single-cell libraries.

| Stage | Result |
|---|---|
| `checkout` | Trimmed, tagged reads and extraction QC |
| `refine` | Corrected UMI assignments, parent lineage and error diagnostics |
| `assemble` | Consensus FASTQ, molecule tables and confidence estimates |
| `plot` | QC figures derived from the stage TSVs |

Molecule identity includes sample, cell and UMI. Consensus FASTQ preserves identifiers in
read names and SAM-style tags. `--min-reads` defaults to 1: shallow molecules remain represented.
Use `migec subsample` for a smaller library while retaining all reads of selected molecules.

## Why MIGEC

- **Evidence-aware correction.** Required seqtree searches support quality-aware UMI correction;
  bulk correction supports two substitutions, while cell-tagged correction retains radius one.
  Homopolymer UMI indel correction is not implemented.
- **Honest consensus confidence.** Quality is capped by the pre-amplification error floor;
  consensus cannot remove errors already present before amplification.
- **Inspectable results.** Barcode lineage, depth, collisions and quality are reported beside
  the consensus. Read counts and molecule counts remain distinct.
- **Native processing.** Streaming C++ stages expose a Python API and thread budgets for
  workstation and scheduled-cluster use.

<p align="center"><img alt="Molecule depth distribution: bars count molecules; the line counts their reads" src="https://raw.githubusercontent.com/antigenomics/migec/master/assets/coverage.svg" width="70%"></p>

The illustration above is measured QC, not a schematic. Existing benchmark results, their
populations and tradeoffs remain in [post-processing](https://antigenomics.github.io/migec/postprocessing.html),
[validation](https://antigenomics.github.io/migec/validation.html) and
[performance](https://antigenomics.github.io/migec/performance.html).

## Documentation

Documentation follows the four Diátaxis needs:

| Need | Start here |
|---|---|
| **Tutorial — learn by running** | [Quickstart](https://antigenomics.github.io/migec/quickstart.html), [worked examples](https://antigenomics.github.io/migec/examples.html) |
| **How-to — complete a task** | [Layouts](https://antigenomics.github.io/migec/layouts.html), [existing UMI tags](https://antigenomics.github.io/migec/byo_umi.html), [cohorts](https://antigenomics.github.io/migec/nextflow.html), [downstream tools](https://antigenomics.github.io/migec/downstream.html) |
| **Reference — look up an interface** | [Commands](https://antigenomics.github.io/migec/commands.html), [formats](https://antigenomics.github.io/migec/formats.html) |
| **Explanation — understand decisions** | [Method](https://antigenomics.github.io/migec/method.html), [quality floor](https://antigenomics.github.io/migec/quality_floor.html), [barcode space](https://antigenomics.github.io/migec/barcode_space.html) |

## Development and agent use

```bash
bash setup.sh
source .venv/bin/activate
python -m pytest tests/unit tests/synthetic -q
ruff check python/ tests/
sphinx-build -W --keep-going -b html docs docs/_build/html
```

The repository skill is [`skills/migec/SKILL.md`](https://github.com/antigenomics/migec/blob/master/skills/migec/SKILL.md).
Design and measured limitations live in [`project/`](https://github.com/antigenomics/migec/tree/master/project/) and [`ROADMAP.md`](https://github.com/antigenomics/migec/blob/master/ROADMAP.md);
public data provenance is in [`SOURCES.md`](https://github.com/antigenomics/migec/blob/master/SOURCES.md).

## Citing

Until the v2 paper exists, cite the original methods:

- Shugay M *et al.* Towards error-free profiling of immune repertoires. *Nat Methods* 11:653–655
  (2014). doi:10.1038/nmeth.2960
- Shugay M *et al.* MAGERI: Computational pipeline for molecular-barcoded targeted resequencing.
  *PLoS Comput Biol* 13(5):e1005480 (2017). doi:10.1371/journal.pcbi.1005480
- Turchaninova MA *et al.* High-quality full-length immunoglobulin profiling with unique molecular 
  barcoding. *Nat Protoc* 11(9):1599-616 (2016). doi: 10.1038/nprot.2016.093

## License

ISALGO LAB Academic and Non-Commercial Research License v1.0. See [`LICENSE`](https://github.com/antigenomics/migec/blob/master/LICENSE).
