Fast DNA search and [host] depletion using minimizers
Project description
Deacon for Python
Python bindings for Deacon, enabling fast multithreaded DNA sequence filtering for e.g. host pangenome depletion using Python code. These bindings load an index once, allowing subsequent filtering runs with low latency. Deacon's complete functionality is currently only available using the Rust/CLI version of Deacon.
Installation
uv install deacon
Quickstart
from deacon import Index
index = Index("panhuman-1.k31w15.idx")
stats = index.filter(
fastq_path,
deplete=True,
rename=True,
output=fastq_path.replace(".fastq.gz", ".clean.fastq.gz")
)
print(stats["seqs_in"], stats["seqs_out"])
Index()
Load a minimizer index or probabilistic filter from disk. The resulting object may be reused across many filter calls.
Index.fetch()
Download a prebuilt index, then load and return it (a static method, so Index.fetch(...) returns an Index). output is the local path to save to; when omitted it defaults to "{name}.k{k}w{w}.idx" in the working directory. The index is downloaded on every call — there is no local cache, so an existing file at that path is overwritten.
index = Index.fetch("panhuman-1", k=31, w=15, output=None)
Index.info()
Index.info(index_path) Returns a dict of index metadata:
| Key | Meaning |
|---|---|
k |
k-mer length |
w |
minimizer window size |
format |
exact-u64, exact-u128, or bff (binary fuse filter) |
count |
number of keys in index (fingerprint slot count for bff) |
Index.filter()
Filter a FASTA/FASTQ file or file pair against the index and return a dict of summary statistics. Auto-detects .gz/.zst/.xz compression on both input and output based on file extension. The Python GIL is released while filtering meaning calls benefit from multithreading. Refer to the main Deacon readme for more detailed usage examples.
def filter(
fastq, # input path (FASTA/FASTQ, optionally .gz/.zst/.xz)
fastq2=None, # second mate for paired reads
deplete=False, # False = search (keep matches); True = deplete (remove matches)
rename=False, # replace read names with sequential integers
rename_random=False, # replace read names with random strings
output=None, # output path; None writes to stdout
output2=None, # second output path for paired reads
abs_threshold=2, # min absolute minimizer hits to call a match
rel_threshold=0.01, # min proportion of minimizers hitting to call a match
prefix_length=0, # only use the first N bp of each read (0 = whole read)
output_fasta=False, # emit FASTA instead of FASTQ
threads=8, # worker threads for filtering
compression_level=2, # output compression level
compression_threads=0, # threads for output compression (0 = auto)
debug=False, # verbose per-read debug output
quiet=True, # suppress progress/log output on stderr
) -> dict
Modes. With deplete=False (the default, search mode) reads that match the index are kept; with deplete=True reads that match are removed (host depletion). A read is a match only when it clears both thresholds: at least abs_threshold minimizer hits and at least rel_threshold of its minimizers hitting the index.
Output. When output is None the filtered records are written to stdout. To count without keeping the filtered sequences, pass output="/dev/null". Statistics are returned regardless.
Return value. A dict including the run configuration (version, index, input/input2, output/output2, k, w, abs_threshold, rel_threshold, prefix_length, deplete, rename, rename_random) and the results:
| Key | Meaning |
|---|---|
seqs_in, seqs_out, seqs_removed |
sequence counts |
seqs_out_proportion, seqs_removed_proportion |
sequence proportions |
bp_in, bp_out, bp_removed |
base-pair counts |
bp_out_proportion, bp_removed_proportion |
base-pair proportions |
time |
wall-clock seconds |
seqs_per_second, bp_per_second |
throughput (filtering only) |
seqs_per_second_total, bp_per_second_total |
throughput (including load/IO) |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file deacon-0.16.0rc2.tar.gz.
File metadata
- Download URL: deacon-0.16.0rc2.tar.gz
- Upload date:
- Size: 3.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68ecbd8944b54a5d5a71afa7cccfbbd3b1aa4ae340f2e54a74f51a74b734534d
|
|
| MD5 |
0061a0e609c1350d5e99cae691c50bd2
|
|
| BLAKE2b-256 |
4d31a8d7cd1a75779269832c4f519e5011b4c729f70233fa6ef74340b82d78c9
|
Provenance
The following attestation bundles were made for deacon-0.16.0rc2.tar.gz:
Publisher:
release-pypi.yaml on bede/deacon
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deacon-0.16.0rc2.tar.gz -
Subject digest:
68ecbd8944b54a5d5a71afa7cccfbbd3b1aa4ae340f2e54a74f51a74b734534d - Sigstore transparency entry: 2039273360
- Sigstore integration time:
-
Permalink:
bede/deacon@a5454d5c0f795269ae3c0b4713bf7a78b4a51ef3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/bede
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yaml@a5454d5c0f795269ae3c0b4713bf7a78b4a51ef3 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file deacon-0.16.0rc2-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: deacon-0.16.0rc2-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.12+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83629372ec812c2fdb8d8489be7ab155df1284963c775e2cabf5214e93990436
|
|
| MD5 |
c8f3fb2e53a75c077fd0a4338ccab06c
|
|
| BLAKE2b-256 |
2b40bc61a8036f6ba9d9fc3d974d6f8b1f60b24e57d4ab9fc327ff4eb032a182
|
Provenance
The following attestation bundles were made for deacon-0.16.0rc2-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release-pypi.yaml on bede/deacon
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deacon-0.16.0rc2-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
83629372ec812c2fdb8d8489be7ab155df1284963c775e2cabf5214e93990436 - Sigstore transparency entry: 2039273521
- Sigstore integration time:
-
Permalink:
bede/deacon@a5454d5c0f795269ae3c0b4713bf7a78b4a51ef3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/bede
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yaml@a5454d5c0f795269ae3c0b4713bf7a78b4a51ef3 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file deacon-0.16.0rc2-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: deacon-0.16.0rc2-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.12+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96327a0b5969ec6760c20d52524755c08d7c35f5be6c8e20ce0212115ef19f0d
|
|
| MD5 |
302bf7fba65e6a9a7203446b0ec857d5
|
|
| BLAKE2b-256 |
2adef97db18441805391790c22a114f9bb4922bb26f8c33a60cc074b5cdd6a13
|
Provenance
The following attestation bundles were made for deacon-0.16.0rc2-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release-pypi.yaml on bede/deacon
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deacon-0.16.0rc2-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
96327a0b5969ec6760c20d52524755c08d7c35f5be6c8e20ce0212115ef19f0d - Sigstore transparency entry: 2039273438
- Sigstore integration time:
-
Permalink:
bede/deacon@a5454d5c0f795269ae3c0b4713bf7a78b4a51ef3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/bede
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yaml@a5454d5c0f795269ae3c0b4713bf7a78b4a51ef3 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file deacon-0.16.0rc2-cp312-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: deacon-0.16.0rc2-cp312-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.12+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dae6184f37ae0df0a4c1dd786e9e4b9b51adec20c2aa78cf08c2adc885a3ac8
|
|
| MD5 |
8824aff31326a5b7e876f58816b8f35f
|
|
| BLAKE2b-256 |
d27abd118031d852fdbad5128d76de6a8c83ed4abe0fabf65759977ae9bb93ed
|
Provenance
The following attestation bundles were made for deacon-0.16.0rc2-cp312-abi3-macosx_11_0_arm64.whl:
Publisher:
release-pypi.yaml on bede/deacon
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deacon-0.16.0rc2-cp312-abi3-macosx_11_0_arm64.whl -
Subject digest:
4dae6184f37ae0df0a4c1dd786e9e4b9b51adec20c2aa78cf08c2adc885a3ac8 - Sigstore transparency entry: 2039273582
- Sigstore integration time:
-
Permalink:
bede/deacon@a5454d5c0f795269ae3c0b4713bf7a78b4a51ef3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/bede
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yaml@a5454d5c0f795269ae3c0b4713bf7a78b4a51ef3 -
Trigger Event:
workflow_dispatch
-
Statement type: