Skip to main content

A library for managing and analyzing immunosequencing data

Project description

mirpy

mirpy logo

mirpy is a Python library for working with AIRR-seq and immune repertoire data. It provides building blocks for:

  • parsing clonotype and repertoire tables;
  • loading and updating V/J segment libraries;
  • repertoire-level statistics and diversity analysis;
  • distance calculation and sequence matching;
  • prototype-based embeddings and comparative analysis.

The package is designed as a reusable toolkit rather than a single pipeline.

Installation

Requirements:

  • Python 3.11+
  • a C/C++ build toolchain for compiled extensions

Install from PyPI:

pip install mirpy-lib

Install from the repository root:

pip install .

For development:

pip install -e .

Main modules

  • mir.common: clonotypes, repertoires, parsers, segment libraries
  • mir.distances: aligners, search, graph-based utilities
  • mir.basic: diversity, sampling, segment usage, pgen helpers
  • mir.embedding: repertoire and prototype embeddings
  • mir.comparative: overlap, matching, TCRnet-style comparisons
  • mir.biomarkers: enrichment and biomarker detection utilities

Quick start

Load a segment library

from mir.common.segments import SegmentLibrary

lib = SegmentLibrary.load_default(
    genes={"TRA", "TRB"},
    organisms={"HomoSapiens"},
)

If a requested organism/locus pair is missing in the default local segment file, mirpy will download the missing V and J segments from IMGT and append them to the default resource file automatically.

Parse a table with clonotypes

from mir.common.parser import VDJtoolsParser

parser = VDJtoolsParser(lib=lib, sep="\t")
clonotypes = parser.parse("example.tsv")

Work with repertoires

from mir.common.repertoire import Repertoire

repertoire = Repertoire(clonotypes=clonotypes, gene="TRB")
print(repertoire.total)
print(repertoire.number_of_clones)

You can also load a repertoire directly from a file:

from mir.common.repertoire import Repertoire
from mir.common.parser import VDJtoolsParser

repertoire = Repertoire.load(
    parser=VDJtoolsParser(lib=lib, sep="\t"),
    path="example.tsv",
    gene="TRB",
)

Mask and match sequences

from mir.basic.alphabets import (
    aa_to_reduced,
    mask,
    matches,
    matches_aa_reduced,
    NT_MASK,
    AA_MASK,
)

nt_masked = mask("ATCGAT", (2, 5), NT_MASK)
assert nt_masked == b"ATNNNT"

aa = "CASTIV"
reduced = aa_to_reduced(aa)

# Matching ignores mask symbols: N for nucleotides, X for amino-acid alphabets.
assert matches(mask(aa, 0, AA_MASK), aa, AA_MASK)
assert matches_aa_reduced(aa, mask(reduced, 3, AA_MASK))

Resources

  • Example notebooks are available in notebooks/.
  • Source files for the API documentation are stored in docs/.
  • After GitHub Pages is enabled for the repository, the documentation site will be rebuilt automatically on each push to main.

Project status

The library is actively evolving. Some modules are more mature than others, and the public API may still change in places.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mirpy_lib-1.0.0-cp313-cp313-win_amd64.whl (540.1 kB view details)

Uploaded CPython 3.13Windows x86-64

mirpy_lib-1.0.0-cp313-cp313-win32.whl (521.6 kB view details)

Uploaded CPython 3.13Windows x86

mirpy_lib-1.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (584.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

mirpy_lib-1.0.0-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl (599.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ i686

mirpy_lib-1.0.0-cp313-cp313-macosx_11_0_arm64.whl (520.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

mirpy_lib-1.0.0-cp312-cp312-win_amd64.whl (540.1 kB view details)

Uploaded CPython 3.12Windows x86-64

mirpy_lib-1.0.0-cp312-cp312-win32.whl (521.5 kB view details)

Uploaded CPython 3.12Windows x86

mirpy_lib-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (584.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

mirpy_lib-1.0.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (599.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ i686

mirpy_lib-1.0.0-cp312-cp312-macosx_11_0_arm64.whl (520.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

mirpy_lib-1.0.0-cp311-cp311-win_amd64.whl (537.5 kB view details)

Uploaded CPython 3.11Windows x86-64

mirpy_lib-1.0.0-cp311-cp311-win32.whl (520.0 kB view details)

Uploaded CPython 3.11Windows x86

mirpy_lib-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (584.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

mirpy_lib-1.0.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (597.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ i686

mirpy_lib-1.0.0-cp311-cp311-macosx_11_0_arm64.whl (518.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file mirpy_lib-1.0.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: mirpy_lib-1.0.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 540.1 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mirpy_lib-1.0.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 5228fdd9b58182e0d516303895b3975f159c4a5438b491f791d0f4aa3dbebce1
MD5 3f087d6d8fcefd44ba9718f94d24b13b
BLAKE2b-256 afd9a16d2444f2d009aabca15177361fa37068805906fb4116838c14e42899c7

See more details on using hashes here.

File details

Details for the file mirpy_lib-1.0.0-cp313-cp313-win32.whl.

File metadata

  • Download URL: mirpy_lib-1.0.0-cp313-cp313-win32.whl
  • Upload date:
  • Size: 521.6 kB
  • Tags: CPython 3.13, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mirpy_lib-1.0.0-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 9ac03e4b788b3fa50c6af3de0db4d0ed45f4a458df48c1cb3e5e5738ec34d30c
MD5 02b58ca946a6c56ca899a365137ba170
BLAKE2b-256 aedcb404d8ea3f6b530d20481ddef0f64c3c152e250f6fce7b6c40fcbc84197e

See more details on using hashes here.

File details

Details for the file mirpy_lib-1.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mirpy_lib-1.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 04c3bfe5f2a8bf4ec1a504358d0f0029f859f95c1587d22dfa12eaaa030b6191
MD5 b8138f726d3d8c3fb36c4abf832ff931
BLAKE2b-256 70565f5d2bdacab3be619b5a0dd196a6275daf0d480f082212f35416820b7bfe

See more details on using hashes here.

File details

Details for the file mirpy_lib-1.0.0-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for mirpy_lib-1.0.0-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 5f2a5b3a6991eebbf156514d7b41a4122683b5950e13779e093b992cf195cc9a
MD5 688a6a4526976a6a9222f94e290d568c
BLAKE2b-256 b4c5c809bb7a511d9a006ae09a445329f898f20ed67591b579084457b8307ac6

See more details on using hashes here.

File details

Details for the file mirpy_lib-1.0.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mirpy_lib-1.0.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5d62310a6184534ef9fda01f2122f4a8cb1fb12f4b0c98aaead5bee038b865da
MD5 fb24c6761bcb5c22e61b4d28d32e4ed7
BLAKE2b-256 b71c82c8581ee3416212e21506c83a2757a0843189320a0cbfa1e7184152884a

See more details on using hashes here.

File details

Details for the file mirpy_lib-1.0.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: mirpy_lib-1.0.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 540.1 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mirpy_lib-1.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6ac55140661fd223797a390656b2a407d71955249b8bb48409b9ba9894a206de
MD5 8eecc3296ff930eb85bbc57a2f96adf1
BLAKE2b-256 ee4acf417f2e19a4967c06d464cc84b1e4a3349023080253d66763c577d68558

See more details on using hashes here.

File details

Details for the file mirpy_lib-1.0.0-cp312-cp312-win32.whl.

File metadata

  • Download URL: mirpy_lib-1.0.0-cp312-cp312-win32.whl
  • Upload date:
  • Size: 521.5 kB
  • Tags: CPython 3.12, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mirpy_lib-1.0.0-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 caac2cdd13f70b9dbb93478aa7b5a25ae393f6f6c022c8b003faed2712b22022
MD5 b1c2db834697bee192cca858a853ce82
BLAKE2b-256 bd4d6dac0a91fc3fab3850acaed3c44f77a496f494d65575b2fe23797b997bb7

See more details on using hashes here.

File details

Details for the file mirpy_lib-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mirpy_lib-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 03ef9fccea1ddf4023a91c74b44ad28923f7a88515c260de5564c4ed5c63be98
MD5 41c9776ecd7ce2ca33386d73d39d5b40
BLAKE2b-256 0901513208c2c67f1832c6544f07ef37e96eb1daa345b9077aa7cafc2c2443c9

See more details on using hashes here.

File details

Details for the file mirpy_lib-1.0.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for mirpy_lib-1.0.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 2d8c5919658e3dda683665f15b1edaeb5c367947dfe3a25db02af0b4ceab8a43
MD5 5be333d90b2060a5abcc5993bec973a8
BLAKE2b-256 d34253f390b3b27df0fcfe39f01331467580d32ce385028aae98ac655f939534

See more details on using hashes here.

File details

Details for the file mirpy_lib-1.0.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mirpy_lib-1.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 db6611ccb0fb34ac46fc9df0c69a27f0aaa502b4d304b5011c59ea7c78688334
MD5 a675a6dfff6dc498f7b4394da35fb2bc
BLAKE2b-256 d7c0cf024de738d0d69855369190f39125376d32a548c3eaf4e8c5ec8df3886d

See more details on using hashes here.

File details

Details for the file mirpy_lib-1.0.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: mirpy_lib-1.0.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 537.5 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mirpy_lib-1.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6744d9dd6f3604980d711d608d5a071be44eba03963da753aeb5059438e9def5
MD5 04bf891deab41abf3118ba2634073d46
BLAKE2b-256 34a35c3e04b2c51b969b4ab7cabd8d92870191f9383406ef45ee385f4c12a454

See more details on using hashes here.

File details

Details for the file mirpy_lib-1.0.0-cp311-cp311-win32.whl.

File metadata

  • Download URL: mirpy_lib-1.0.0-cp311-cp311-win32.whl
  • Upload date:
  • Size: 520.0 kB
  • Tags: CPython 3.11, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mirpy_lib-1.0.0-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 a8f348bd89ab569258784f84c47d89ec2ba3df594ec32ed5c8cd99e11dcc433c
MD5 12e56484b80e903379cb0467d129857f
BLAKE2b-256 a85e294c0fc02eb3920bc97e6de7fecbce8d987bb301787e39f791f23de475cf

See more details on using hashes here.

File details

Details for the file mirpy_lib-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mirpy_lib-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 30a1a076b15158561a1e56e8977da72fafe35ad182dc2290eed99cb364b6fc60
MD5 604fc46bfb7e0894785e691f1a18af8e
BLAKE2b-256 2df918c3f6c95e1ffb5cbcf2df0870c7223e927c15661f502f02d708403f26d5

See more details on using hashes here.

File details

Details for the file mirpy_lib-1.0.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for mirpy_lib-1.0.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 353ab5c3baa64a46f3d0d1cb70ed221e44883ca986acc96d8c8e6f70e84a43a2
MD5 18f05c7c8480eeffe04fe5abf18e12df
BLAKE2b-256 585ed18b0c7d0d89d73c1481583870f209304d6eb1e96a6c00bb365eba5fface

See more details on using hashes here.

File details

Details for the file mirpy_lib-1.0.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mirpy_lib-1.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e08de107ea763e59236f351347d74cdd7d70784c2064881b7e811e936089b004
MD5 8401732884422ac8a445c2e488d5a4ee
BLAKE2b-256 5079f467d8634d896d91d624b5477eecaba7a3ef719a61f43d013316a9808f00

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page