tftokenizer 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,116 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "adler2"
7
+ version = "2.0.1"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
10
+
11
+ [[package]]
12
+ name = "cfg-if"
13
+ version = "1.0.5"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
16
+
17
+ [[package]]
18
+ name = "crc32fast"
19
+ version = "1.5.2"
20
+ source = "registry+https://github.com/rust-lang/crates.io-index"
21
+ checksum = "01a7799fd6b852db0e61728dde9a204c423b44d689dbd432522543614b490e78"
22
+ dependencies = [
23
+ "cfg-if",
24
+ ]
25
+
26
+ [[package]]
27
+ name = "crossbeam-deque"
28
+ version = "0.8.8"
29
+ source = "registry+https://github.com/rust-lang/crates.io-index"
30
+ checksum = "622f3fc73690be383c7214310406f28a90e6edeadc3cea882f9d71e495b9711a"
31
+ dependencies = [
32
+ "crossbeam-epoch",
33
+ "crossbeam-utils",
34
+ ]
35
+
36
+ [[package]]
37
+ name = "crossbeam-epoch"
38
+ version = "0.9.21"
39
+ source = "registry+https://github.com/rust-lang/crates.io-index"
40
+ checksum = "dc74980687109a3b14c72fd458107bf0baa1da1a1a805e178d15501ba9b86d9d"
41
+ dependencies = [
42
+ "crossbeam-utils",
43
+ ]
44
+
45
+ [[package]]
46
+ name = "crossbeam-utils"
47
+ version = "0.8.23"
48
+ source = "registry+https://github.com/rust-lang/crates.io-index"
49
+ checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
50
+
51
+ [[package]]
52
+ name = "either"
53
+ version = "1.19.0"
54
+ source = "registry+https://github.com/rust-lang/crates.io-index"
55
+ checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be"
56
+
57
+ [[package]]
58
+ name = "flate2"
59
+ version = "1.1.10"
60
+ source = "registry+https://github.com/rust-lang/crates.io-index"
61
+ checksum = "6e634e2e0ebac1ee034020da1ca582e17ffe4e0f5e985823721e168928136dcb"
62
+ dependencies = [
63
+ "crc32fast",
64
+ "miniz_oxide",
65
+ "zlib-rs",
66
+ ]
67
+
68
+ [[package]]
69
+ name = "miniz_oxide"
70
+ version = "0.9.1"
71
+ source = "registry+https://github.com/rust-lang/crates.io-index"
72
+ checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c"
73
+ dependencies = [
74
+ "adler2",
75
+ "simd-adler32",
76
+ ]
77
+
78
+ [[package]]
79
+ name = "rayon"
80
+ version = "1.12.0"
81
+ source = "registry+https://github.com/rust-lang/crates.io-index"
82
+ checksum = "fb39b166781f92d482534ef4b4b1b2568f42613b53e5b6c160e24cfbfa30926d"
83
+ dependencies = [
84
+ "either",
85
+ "rayon-core",
86
+ ]
87
+
88
+ [[package]]
89
+ name = "rayon-core"
90
+ version = "1.13.0"
91
+ source = "registry+https://github.com/rust-lang/crates.io-index"
92
+ checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91"
93
+ dependencies = [
94
+ "crossbeam-deque",
95
+ "crossbeam-utils",
96
+ ]
97
+
98
+ [[package]]
99
+ name = "simd-adler32"
100
+ version = "0.3.10"
101
+ source = "registry+https://github.com/rust-lang/crates.io-index"
102
+ checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea"
103
+
104
+ [[package]]
105
+ name = "tftokenizer"
106
+ version = "0.1.0"
107
+ dependencies = [
108
+ "flate2",
109
+ "rayon",
110
+ ]
111
+
112
+ [[package]]
113
+ name = "zlib-rs"
114
+ version = "0.6.8"
115
+ source = "registry+https://github.com/rust-lang/crates.io-index"
116
+ checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112"
@@ -0,0 +1,16 @@
1
+ [package]
2
+ name = "tftokenizer"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+
6
+ [lib]
7
+ crate-type = ["cdylib"]
8
+ path = "src/lib.rs"
9
+
10
+ [dependencies]
11
+ flate2 = "1.1"
12
+ rayon = "1.12"
13
+
14
+ [profile.release]
15
+ lto = true
16
+ codegen-units = 1
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SugarfreeSoda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ include Cargo.toml Cargo.lock
2
+ recursive-include src *.rs
@@ -0,0 +1,98 @@
1
+ Metadata-Version: 2.4
2
+ Name: tftokenizer
3
+ Version: 0.1.0
4
+ Summary: Tokenize the genome into bins carrying per-motif transcription-factor occupancy
5
+ License-Expression: MIT
6
+ Requires-Python: >=3.11
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: numpy>=1.26
10
+ Requires-Dist: scipy>=1.11
11
+ Requires-Dist: zarr>=3
12
+ Provides-Extra: test
13
+ Requires-Dist: pytest; extra == "test"
14
+ Dynamic: license-file
15
+
16
+ # TFTokenizer
17
+
18
+ TFTokenizer cuts a chromosome into variable-length tokens from transcription-factor motif hits. Each token
19
+ records the expected occupancy of every motif inside it.
20
+
21
+ It builds on the interval tokenizer of *Motif-aware Tokenization of the Genome: Towards Interpretable Modeling of
22
+ Gene Regulation*. That tokenizer marks each motif hit as 0/1. TFTokenizer instead weights each hit by its binding
23
+ strength and merges overlapping hits of a motif into occupancy sites.
24
+
25
+ ## Method
26
+
27
+ 1. **Binding strength.** A hit of motif *m* with JASPAR score *s* gets strength a = exp(β (S − μ<sub>m</sub>)), where
28
+ S = s / 100 · ln 10 (= −ln p). μ<sub>m</sub> is the 90th percentile of motif *m*'s scores on the training chromosomes,
29
+ and β = 0.5.
30
+ 2. **Occupancy sites.** Overlapping hits of the same motif (both strands) are merged into one site, with occupancy
31
+ θ = Σa / (1 + Σa) (capped at 0.99) and load H = −ln(1 − θ). H is spread evenly over the site, so each base carries H / site length.
32
+ 3. **Bins.** The per-base load of all motifs is summed and smoothed (Gaussian, σ = 3). Every peak contributes its two
33
+ crossings at half its prominence as bin edges. Stretches longer than 50 bp are cut every 25 bp.
34
+ 4. **Tokens.** For each bin and motif, the token value is Σ site load × fraction of the site inside the bin.
35
+
36
+ ## Install
37
+
38
+ ```bash
39
+ pip install tftokenizer
40
+ ```
41
+
42
+ Requires Python ≥ 3.11. Prebuilt wheels are published for Linux (x86_64, aarch64), macOS (Apple silicon, Intel) and
43
+ Windows (x64), so no Rust toolchain is needed. On other platforms pip builds from source, which needs
44
+ [Rust](https://rustup.rs).
45
+
46
+ ## Input
47
+
48
+ The motif hits of the UCSC JASPAR track, one table per chromosome. TFTokenizer downloads them itself:
49
+
50
+ ```bash
51
+ tftokenizer download --chroms chr19 chr22 # writes hits/chr19.tsv.gz and hits/chr22.tsv.gz
52
+ ```
53
+
54
+ The track file is large (196 GB for hg38 JASPAR2026), so only the chosen chromosomes are fetched: the records of a
55
+ chromosome lie together in the file, are located through its index and downloaded in one range request (2.0 GiB for
56
+ chr22). An interrupted download resumes where it stopped, and tables already there are skipped. Each table is what
57
+ `bigBedToBed -chrom=<chrom> -tsv` writes; `<chrom>.json` next to it records the source, row count and SHA-256.
58
+
59
+ Options: `--data` (folder, default `hits`), `--assembly` (default `hg38`), `--release` (default `JASPAR2026`) and
60
+ `--mirror` (default `https://hgdownload.soe.ucsc.edu`; the Europe mirror `https://hgdownload-euro.soe.ucsc.edu` can be
61
+ faster, depending on the network).
62
+
63
+ Tables of your own are passed with `--hits`: tab-separated, optionally gzipped, with a header, sorted by `chromStart`.
64
+ Columns used: `chrom chromStart chromEnd name score`.
65
+
66
+ ## Usage
67
+
68
+ Command line. Without `--hits`, `fit` and `tokenize` first download the missing tables into `--data`; `tokenize`
69
+ downloads the assembly and release the model was fitted on:
70
+
71
+ ```bash
72
+ tftokenizer fit --chroms chr19 --model model.npz
73
+ tftokenizer tokenize --chroms chr19 chr22 --model model.npz --out tokens
74
+ ```
75
+
76
+ With tables of your own (`{chrom}` is replaced by each chromosome name):
77
+
78
+ ```bash
79
+ tftokenizer fit --chroms chr19 --model model.npz --hits 'my_hits/{chrom}.tsv.gz'
80
+ ```
81
+
82
+ Python:
83
+
84
+ ```python
85
+ from tftokenizer import TFTokenizer, download
86
+
87
+ chr19, chr22 = download(["chr19", "chr22"], "hits")
88
+ tok = TFTokenizer().fit([(chr19, "chr19")])
89
+ tok.save("model.npz")
90
+ tok.tokenize(chr22, "chr22", "tokens/chr22")
91
+ ```
92
+
93
+ All tunable values live in `Params` (`tftokenizer/tokenizer.py`).
94
+ [`examples/quickstart.ipynb`](examples/quickstart.ipynb) reproduces the whole run: download, fit on chr19,
95
+ tokenize chr19 and chr22, and load the result.
96
+
97
+
98
+
@@ -0,0 +1,83 @@
1
+ # TFTokenizer
2
+
3
+ TFTokenizer cuts a chromosome into variable-length tokens from transcription-factor motif hits. Each token
4
+ records the expected occupancy of every motif inside it.
5
+
6
+ It builds on the interval tokenizer of *Motif-aware Tokenization of the Genome: Towards Interpretable Modeling of
7
+ Gene Regulation*. That tokenizer marks each motif hit as 0/1. TFTokenizer instead weights each hit by its binding
8
+ strength and merges overlapping hits of a motif into occupancy sites.
9
+
10
+ ## Method
11
+
12
+ 1. **Binding strength.** A hit of motif *m* with JASPAR score *s* gets strength a = exp(β (S − μ<sub>m</sub>)), where
13
+ S = s / 100 · ln 10 (= −ln p). μ<sub>m</sub> is the 90th percentile of motif *m*'s scores on the training chromosomes,
14
+ and β = 0.5.
15
+ 2. **Occupancy sites.** Overlapping hits of the same motif (both strands) are merged into one site, with occupancy
16
+ θ = Σa / (1 + Σa) (capped at 0.99) and load H = −ln(1 − θ). H is spread evenly over the site, so each base carries H / site length.
17
+ 3. **Bins.** The per-base load of all motifs is summed and smoothed (Gaussian, σ = 3). Every peak contributes its two
18
+ crossings at half its prominence as bin edges. Stretches longer than 50 bp are cut every 25 bp.
19
+ 4. **Tokens.** For each bin and motif, the token value is Σ site load × fraction of the site inside the bin.
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ pip install tftokenizer
25
+ ```
26
+
27
+ Requires Python ≥ 3.11. Prebuilt wheels are published for Linux (x86_64, aarch64), macOS (Apple silicon, Intel) and
28
+ Windows (x64), so no Rust toolchain is needed. On other platforms pip builds from source, which needs
29
+ [Rust](https://rustup.rs).
30
+
31
+ ## Input
32
+
33
+ The motif hits of the UCSC JASPAR track, one table per chromosome. TFTokenizer downloads them itself:
34
+
35
+ ```bash
36
+ tftokenizer download --chroms chr19 chr22 # writes hits/chr19.tsv.gz and hits/chr22.tsv.gz
37
+ ```
38
+
39
+ The track file is large (196 GB for hg38 JASPAR2026), so only the chosen chromosomes are fetched: the records of a
40
+ chromosome lie together in the file, are located through its index and downloaded in one range request (2.0 GiB for
41
+ chr22). An interrupted download resumes where it stopped, and tables already there are skipped. Each table is what
42
+ `bigBedToBed -chrom=<chrom> -tsv` writes; `<chrom>.json` next to it records the source, row count and SHA-256.
43
+
44
+ Options: `--data` (folder, default `hits`), `--assembly` (default `hg38`), `--release` (default `JASPAR2026`) and
45
+ `--mirror` (default `https://hgdownload.soe.ucsc.edu`; the Europe mirror `https://hgdownload-euro.soe.ucsc.edu` can be
46
+ faster, depending on the network).
47
+
48
+ Tables of your own are passed with `--hits`: tab-separated, optionally gzipped, with a header, sorted by `chromStart`.
49
+ Columns used: `chrom chromStart chromEnd name score`.
50
+
51
+ ## Usage
52
+
53
+ Command line. Without `--hits`, `fit` and `tokenize` first download the missing tables into `--data`; `tokenize`
54
+ downloads the assembly and release the model was fitted on:
55
+
56
+ ```bash
57
+ tftokenizer fit --chroms chr19 --model model.npz
58
+ tftokenizer tokenize --chroms chr19 chr22 --model model.npz --out tokens
59
+ ```
60
+
61
+ With tables of your own (`{chrom}` is replaced by each chromosome name):
62
+
63
+ ```bash
64
+ tftokenizer fit --chroms chr19 --model model.npz --hits 'my_hits/{chrom}.tsv.gz'
65
+ ```
66
+
67
+ Python:
68
+
69
+ ```python
70
+ from tftokenizer import TFTokenizer, download
71
+
72
+ chr19, chr22 = download(["chr19", "chr22"], "hits")
73
+ tok = TFTokenizer().fit([(chr19, "chr19")])
74
+ tok.save("model.npz")
75
+ tok.tokenize(chr22, "chr22", "tokens/chr22")
76
+ ```
77
+
78
+ All tunable values live in `Params` (`tftokenizer/tokenizer.py`).
79
+ [`examples/quickstart.ipynb`](examples/quickstart.ipynb) reproduces the whole run: download, fit on chr19,
80
+ tokenize chr19 and chr22, and load the result.
81
+
82
+
83
+
@@ -0,0 +1,46 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77", "setuptools-rust>=1.9"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "tftokenizer"
7
+ version = "0.1.0"
8
+ description = "Tokenize the genome into bins carrying per-motif transcription-factor occupancy"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.11"
13
+ dependencies = ["numpy>=1.26", "scipy>=1.11", "zarr>=3"]
14
+
15
+ [project.optional-dependencies]
16
+ test = ["pytest"]
17
+
18
+ [project.scripts]
19
+ tftokenizer = "tftokenizer.cli:main"
20
+
21
+ [tool.setuptools]
22
+ packages = ["tftokenizer"]
23
+
24
+ [[tool.setuptools-rust.ext-modules]]
25
+ target = "tftokenizer._native"
26
+ binding = "NoBinding"
27
+ py-limited-api = true
28
+ debug = false # release build also for editable installs (pip install -e .)
29
+
30
+ [tool.distutils.bdist_wheel]
31
+ py-limited-api = "cp311"
32
+
33
+ [tool.cibuildwheel]
34
+ build = "cp311-*"
35
+ skip = "*-musllinux_*"
36
+ archs = ["native"]
37
+ test-requires = "pytest"
38
+ test-command = "pytest {project}/tests"
39
+
40
+ [tool.cibuildwheel.linux]
41
+ before-all = "curl -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal"
42
+ environment = { PATH = "$PATH:$HOME/.cargo/bin" }
43
+
44
+ [[tool.cibuildwheel.overrides]]
45
+ select = "*-macosx_x86_64"
46
+ environment = { MACOSX_DEPLOYMENT_TARGET = "10.12" } # Rust's standard library needs macOS ≥ 10.12 on Intel Macs
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+