Skip to main content

Fast Rust-backed per-base coverage computation over genomic regions from BAM files.

Project description

# Rust_covpyo3

A fast, Rust-backed Python library for computing per-base coverage over genomic regions from BAM files.

---



## Instalation

### dependencies:
python dependencies
```
pip install maturin
pip install numpy
```

rust
to install rust go to : https://www.rust-lang.org/tools/install
and follow the instruction usually it just required to copy paste a link in the terminal.

### install pip
can be installed by pip!
```bash
pip install Rust_covpyo3
```

### local build
If no prebuilt wheel is available for your platform, or you want to build from source, you'll need to compile the Rust backend yourself.

**1. Install Python dependencies**

```bash
pip install maturin numpy
```

**2. Install a recent Rust toolchain**

Follow the official instructions at https://www.rust-lang.org/tools/install — usually a single command pasted into your terminal.

**3. Build and install the wheel**

From the repository root:

```bash
cd Rust_covpyo3
maturin build --release
python -m pip install -U target/wheels/*.whl
```

The build can take 30 seconds to a few minutes depending on your internet connection.

> 💡 If you build multiple times, clear `target/wheels/` first so `pip` only sees one wheel to install.

> 💡 If you're working in a virtual environment and want hot-reloading during development, use `maturin develop` instead of `maturin build`. See the [maturin documentation](https://github.com/PyO3/maturin) for details.


## Usage

### `get_coverage_algo2`

Computes per-base coverage over a genomic region using an interval-based algorithm. Rather than piling up base-by-base, it parses each read's CIGAR string to determine the reference positions it covers, then increments a coverage array for those positions. This makes it efficient for sparse regions and gives you fine-grained control over which reads to include.

```python
from Rust_covpyo3 import get_coverage_algo2

coverage = get_coverage_algo2(
start=10000,
end=20000,
chrom="chr1",
strand="Plus",
bam_path="sample.bam",
lib="frFirstStrand",
mapq_thr=10,
flag_in=0,
flag_exclude=256,
)
# coverage is a list of ints, one per position from start to end
```

### Parameters

| Parameter | Type | Description |
|---|---|---|
| `start` | `int` | Start of the region (0-based, inclusive) |
| `end` | `int` | End of the region (0-based, exclusive) |
| `chrom` | `str` | Chromosome / sequence name |
| `strand` | `str` | `"Plus"`, `"Minus"`, or `"NA"` (unstranded) |
| `bam_path` | `str` | Path to an indexed BAM file |
| `lib` | `str` | Library type — accepted values: `frFirstStrand` (TruSeq stranded), `frSecondStrand`, `fFirstStrand`, `fSecondStrand`, `ffFirstStrand`, `ffSecondStrand`, `rfFirstStrand`, `rfSecondStrand`, `rFirstStrand`, `rSecondStrand`. See [BAMstrandSpecifier](https://github.com/rLannes/BAMstrandSpecifier) |
| `mapq_thr` | `int` | Minimum mapping quality. Set to `0` to disable filtering |
| `flag_in` | `int` | SAM flags that **must** be set (bitwise). Use `0` for no requirement |
| `flag_exclude` | `int` | SAM flags that **must not** be set (bitwise). e.g. `256` to exclude secondary alignments |

### Returns

A `list[int]` of length `end - start`, where each element is the read depth at that position.

### How it works

1. All reads overlapping the `[start, end)` region are fetched from the BAM index.
2. Each read is filtered by `flag_in` / `flag_exclude` and mapping quality.
3. For strand-specific libraries, the read's strand is inferred from its flags and the library type. Only reads matching the requested `strand` are kept. For unstranded libraries, all passing reads are counted.
4. The read's CIGAR string is parsed to extract the intervals on the reference that the read actually covers (skipping deletions and spliced regions).
5. Those intervals are intersected with `[start, end)` and the corresponding positions in the output array are incremented.


Project details


Download files

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

Source Distribution

rust_covpyo3-0.3.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distributions

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

rust_covpyo3-0.3.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

rust_covpyo3-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

rust_covpyo3-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

rust_covpyo3-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

rust_covpyo3-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

rust_covpyo3-0.3.0-cp39-cp39-macosx_11_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file rust_covpyo3-0.3.0.tar.gz.

File metadata

  • Download URL: rust_covpyo3-0.3.0.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.16

File hashes

Hashes for rust_covpyo3-0.3.0.tar.gz
Algorithm Hash digest
SHA256 083055f9dd7b02b2e85e738e49a81ed87d5d6bb9ff1322880ab9d41a01517a4a
MD5 995a4a5acf98df930e424567f0d782b8
BLAKE2b-256 ba1c0775794ac9bb3dd75d7146fe7c10801afb2f26bd4f7cd9d6dad83377cf5a

See more details on using hashes here.

File details

Details for the file rust_covpyo3-0.3.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rust_covpyo3-0.3.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f163e08628056fda5559621706275f77be6c21255ab05a291538a3adc98b6db7
MD5 368a2c9d1319a9a27c386ab3178cfe3e
BLAKE2b-256 8ff2a2a8d4a6a38aeb029a00be4fdfd539182a535dbe54b001ad6c6156efbf68

See more details on using hashes here.

File details

Details for the file rust_covpyo3-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rust_covpyo3-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 417e46e865e6e0616349e152101ce3818b4434d6f82a8732311902240ea5a34d
MD5 8dac044446103c6185db123bb300536e
BLAKE2b-256 fd4148aaa421055f5b1afb6d3f05b4cd52b3c123ddea8be8cf0337bbf4f6e297

See more details on using hashes here.

File details

Details for the file rust_covpyo3-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rust_covpyo3-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c725455acaa60d7493c3f677fad61e273930ebf1fc0ef73cef7cd519d8961b0a
MD5 4d56f1cf394cee2d6bf2e1ac768152b3
BLAKE2b-256 42c9314168e68004490297b8e38e6d4e124ebaefda0c8b989b51b290e02e4f74

See more details on using hashes here.

File details

Details for the file rust_covpyo3-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rust_covpyo3-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 882f53413ecef950f3ee229b954a1928b0bfe40397e869703b63161c8ff5eb3c
MD5 264edca728c22ff740304a775352d864
BLAKE2b-256 8cbaf947b38f33a24d60bf90fc2a92744557f648b498a3fc633133e86fad2ac4

See more details on using hashes here.

File details

Details for the file rust_covpyo3-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rust_covpyo3-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e463b276b92e79d6418442e25f89e6688706a3af1072df5a910ff3e80074081e
MD5 8c11fa92fdfbf7d2fdf4f4579356302c
BLAKE2b-256 1edafa291a168ee2e7569312748adf378b4b8e16f243ecfacf1a3adf9d4b1568

See more details on using hashes here.

File details

Details for the file rust_covpyo3-0.3.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rust_covpyo3-0.3.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4eba35305dc953e58fa129448f944de07dcde79db82cadeebf32baae0aaa8a1b
MD5 12f73e655348054bb83eaedd81550010
BLAKE2b-256 b4134cb6fba097b8e9d2656c39bc1a0db01d6be506720ad9f762f1b932795692

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