seqtree 1.3.4__tar.gz → 1.4.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.
Files changed (57) hide show
  1. {seqtree-1.3.4 → seqtree-1.4.0}/CHANGELOG.md +5 -0
  2. {seqtree-1.3.4 → seqtree-1.4.0}/CMakeLists.txt +1 -0
  3. {seqtree-1.3.4 → seqtree-1.4.0}/PKG-INFO +8 -2
  4. {seqtree-1.3.4 → seqtree-1.4.0}/README.md +7 -1
  5. seqtree-1.4.0/assets/workflow-dark.svg +70 -0
  6. seqtree-1.4.0/assets/workflow-light.svg +70 -0
  7. seqtree-1.4.0/assets/workflow.png +0 -0
  8. seqtree-1.4.0/include/seqtree/ranked_neighborhood.hpp +32 -0
  9. {seqtree-1.3.4 → seqtree-1.4.0}/pyproject.toml +1 -1
  10. {seqtree-1.3.4 → seqtree-1.4.0}/python/seqtree/gapblock.py +2 -2
  11. {seqtree-1.3.4 → seqtree-1.4.0}/src/_bindings.cpp +71 -0
  12. seqtree-1.4.0/src/ranked_neighborhood.cpp +144 -0
  13. {seqtree-1.3.4 → seqtree-1.4.0}/.gitattributes +0 -0
  14. {seqtree-1.3.4 → seqtree-1.4.0}/.gitignore +0 -0
  15. {seqtree-1.3.4 → seqtree-1.4.0}/LICENSE +0 -0
  16. {seqtree-1.3.4 → seqtree-1.4.0}/include/seqtree/kmer_index.hpp +0 -0
  17. {seqtree-1.3.4 → seqtree-1.4.0}/include/seqtree/parallel.hpp +0 -0
  18. {seqtree-1.3.4 → seqtree-1.4.0}/include/seqtree/seqtree.hpp +0 -0
  19. {seqtree-1.3.4 → seqtree-1.4.0}/include/seqtree/text_index.hpp +0 -0
  20. {seqtree-1.3.4 → seqtree-1.4.0}/include/seqtree/types.hpp +0 -0
  21. {seqtree-1.3.4 → seqtree-1.4.0}/python/seqtree/__init__.py +0 -0
  22. {seqtree-1.3.4 → seqtree-1.4.0}/python/seqtree/control.py +0 -0
  23. {seqtree-1.3.4 → seqtree-1.4.0}/python/seqtree/data/control_human_trb_aa.txt.gz +0 -0
  24. {seqtree-1.3.4 → seqtree-1.4.0}/python/seqtree/distance.py +0 -0
  25. {seqtree-1.3.4 → seqtree-1.4.0}/python/seqtree/evalue.py +0 -0
  26. {seqtree-1.3.4 → seqtree-1.4.0}/python/seqtree/layout.py +0 -0
  27. {seqtree-1.3.4 → seqtree-1.4.0}/python/seqtree/pairwise.py +0 -0
  28. {seqtree-1.3.4 → seqtree-1.4.0}/python/seqtree/pmhc.py +0 -0
  29. {seqtree-1.3.4 → seqtree-1.4.0}/python/seqtree/pmhc_evalue.py +0 -0
  30. {seqtree-1.3.4 → seqtree-1.4.0}/python/seqtree/py.typed +0 -0
  31. {seqtree-1.3.4 → seqtree-1.4.0}/python/seqtree/seeds.py +0 -0
  32. {seqtree-1.3.4 → seqtree-1.4.0}/python/seqtree/text_evalue.py +0 -0
  33. {seqtree-1.3.4 → seqtree-1.4.0}/src/alignment_max.cpp +0 -0
  34. {seqtree-1.3.4 → seqtree-1.4.0}/src/atomic_write.hpp +0 -0
  35. {seqtree-1.3.4 → seqtree-1.4.0}/src/blosum45.inc +0 -0
  36. {seqtree-1.3.4 → seqtree-1.4.0}/src/blosum62.inc +0 -0
  37. {seqtree-1.3.4 → seqtree-1.4.0}/src/blosum80.inc +0 -0
  38. {seqtree-1.3.4 → seqtree-1.4.0}/src/codec.cpp +0 -0
  39. {seqtree-1.3.4 → seqtree-1.4.0}/src/count_unit.hpp +0 -0
  40. {seqtree-1.3.4 → seqtree-1.4.0}/src/distance.cpp +0 -0
  41. {seqtree-1.3.4 → seqtree-1.4.0}/src/engine_seqtm.cpp +0 -0
  42. {seqtree-1.3.4 → seqtree-1.4.0}/src/engine_seqtrie.cpp +0 -0
  43. {seqtree-1.3.4 → seqtree-1.4.0}/src/engines.hpp +0 -0
  44. {seqtree-1.3.4 → seqtree-1.4.0}/src/gapblock.cpp +0 -0
  45. {seqtree-1.3.4 → seqtree-1.4.0}/src/index.cpp +0 -0
  46. {seqtree-1.3.4 → seqtree-1.4.0}/src/kmer_index.cpp +0 -0
  47. {seqtree-1.3.4 → seqtree-1.4.0}/src/pairwise.cpp +0 -0
  48. {seqtree-1.3.4 → seqtree-1.4.0}/src/pairwise_detail.hpp +0 -0
  49. {seqtree-1.3.4 → seqtree-1.4.0}/src/pam100.inc +0 -0
  50. {seqtree-1.3.4 → seqtree-1.4.0}/src/pam250.inc +0 -0
  51. {seqtree-1.3.4 → seqtree-1.4.0}/src/positional_matrix.cpp +0 -0
  52. {seqtree-1.3.4 → seqtree-1.4.0}/src/searcher.cpp +0 -0
  53. {seqtree-1.3.4 → seqtree-1.4.0}/src/structural.inc +0 -0
  54. {seqtree-1.3.4 → seqtree-1.4.0}/src/substitution_matrix.cpp +0 -0
  55. {seqtree-1.3.4 → seqtree-1.4.0}/src/text_index.cpp +0 -0
  56. {seqtree-1.3.4 → seqtree-1.4.0}/src/trie.cpp +0 -0
  57. {seqtree-1.3.4 → seqtree-1.4.0}/src/trie.hpp +0 -0
@@ -5,6 +5,11 @@ versioning: breaking changes need a **major** bump.
5
5
 
6
6
  ## Unreleased
7
7
 
8
+ ## 1.4.0
9
+
10
+ - Add a native grouped ranked-neighborhood reducer with tie-inclusive radii,
11
+ fixed target and competitor pools, optional weights, and bounded output.
12
+
8
13
  ## 1.3.4
9
14
 
10
15
  - Clamp oversized CPU/thread requests to the available budget instead of aborting.
@@ -27,6 +27,7 @@ add_library(seqtree_core STATIC
27
27
  src/engine_seqtrie.cpp
28
28
  src/searcher.cpp
29
29
  src/gapblock.cpp
30
+ src/ranked_neighborhood.cpp
30
31
  src/pairwise.cpp
31
32
  src/alignment_max.cpp
32
33
  src/distance.cpp
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: seqtree
3
- Version: 1.3.4
3
+ Version: 1.4.0
4
4
  Summary: Fast fuzzy search over biological sequences (C++ core, Python bindings)
5
5
  Keywords: sequence-search,fuzzy-matching,CDR3,immunology,bioinformatics,trie
6
6
  Author-Email: ISALGO laboratory <mikhail.shugay@gmail.com>
@@ -42,6 +42,12 @@ Fast fuzzy search over biological sequences (amino-acid or nucleotide), as a C++
42
42
  core with a minimal Python binding. Build an immutable index once, then search
43
43
  single queries or massive batches in parallel.
44
44
 
45
+ <picture>
46
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/antigenomics/seqtree/master/assets/workflow-dark.svg">
47
+ <source srcset="https://raw.githubusercontent.com/antigenomics/seqtree/master/assets/workflow-light.svg">
48
+ <img alt="seqtree workflow: inputs, batched processing and outputs. Schematic illustrations." src="https://raw.githubusercontent.com/antigenomics/seqtree/master/assets/workflow.png" width="100%">
49
+ </picture>
50
+
45
51
  ## Install
46
52
 
47
53
  ```fish
@@ -68,7 +74,7 @@ queries = ["CASSLAPGATNEKLFF", "CASSLELGATNEKLFF"]
68
74
  results = idx.search_batch(queries, p)
69
75
  ```
70
76
 
71
- That is the whole core loop. Significance, gap blocks, alignment and distances are in
77
+ Significance, gap blocks, alignment and distances are in
72
78
  [More examples](#more-examples) below, and the
73
79
  [docs](https://antigenomics.github.io/seqtree/) explain the why.
74
80
 
@@ -10,6 +10,12 @@ Fast fuzzy search over biological sequences (amino-acid or nucleotide), as a C++
10
10
  core with a minimal Python binding. Build an immutable index once, then search
11
11
  single queries or massive batches in parallel.
12
12
 
13
+ <picture>
14
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/antigenomics/seqtree/master/assets/workflow-dark.svg">
15
+ <source srcset="https://raw.githubusercontent.com/antigenomics/seqtree/master/assets/workflow-light.svg">
16
+ <img alt="seqtree workflow: inputs, batched processing and outputs. Schematic illustrations." src="https://raw.githubusercontent.com/antigenomics/seqtree/master/assets/workflow.png" width="100%">
17
+ </picture>
18
+
13
19
  ## Install
14
20
 
15
21
  ```fish
@@ -36,7 +42,7 @@ queries = ["CASSLAPGATNEKLFF", "CASSLELGATNEKLFF"]
36
42
  results = idx.search_batch(queries, p)
37
43
  ```
38
44
 
39
- That is the whole core loop. Significance, gap blocks, alignment and distances are in
45
+ Significance, gap blocks, alignment and distances are in
40
46
  [More examples](#more-examples) below, and the
41
47
  [docs](https://antigenomics.github.io/seqtree/) explain the why.
42
48
 
@@ -0,0 +1,70 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="1200" height="760" viewBox="0 0 1200 760" role="img" aria-labelledby="title desc"><title id="title">From sequence collections to fast batch search</title><desc id="desc">Build an immutable index once; submit queries together. Illustrations are schematic, not measured results.</desc><!-- Editable schematic, not measured observations. PNG: rsvg-convert assets/workflow-light.svg -o assets/workflow.png -->
2
+ <rect width="1200" height="760" fill="#1a2332"/><g font-family="Arial, Helvetica, sans-serif">
3
+ <text x="56" y="72" font-size="32" fill="#eef2f7" font-weight="700">From sequence collections to fast batch search</text>
4
+ <text x="56" y="110" font-size="19" fill="#9cadbf" font-weight="400">Build an immutable index once; submit queries together.</text>
5
+ <path d="M56 142 H1144" fill="none" stroke="#354254" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
6
+ <rect x="80" y="220" width="72" height="7" fill="#83b5e7" opacity="0.95"/>
7
+ <rect x="158" y="220" width="28" height="7" fill="#ffbd59" opacity="0.95"/>
8
+ <rect x="192" y="220" width="70" height="7" fill="#25c39d" opacity="0.95"/>
9
+ <rect x="80" y="240" width="72" height="7" fill="#83b5e7" opacity="0.83"/>
10
+ <rect x="158" y="240" width="28" height="7" fill="#ffbd59" opacity="0.83"/>
11
+ <rect x="192" y="240" width="70" height="7" fill="#25c39d" opacity="0.83"/>
12
+ <rect x="80" y="260" width="72" height="7" fill="#83b5e7" opacity="0.71"/>
13
+ <rect x="158" y="260" width="28" height="7" fill="#ffbd59" opacity="0.71"/>
14
+ <rect x="192" y="260" width="70" height="7" fill="#25c39d" opacity="0.71"/>
15
+ <rect x="80" y="280" width="72" height="7" fill="#83b5e7" opacity="0.59"/>
16
+ <rect x="158" y="280" width="28" height="7" fill="#ffbd59" opacity="0.59"/>
17
+ <rect x="192" y="280" width="70" height="7" fill="#25c39d" opacity="0.59"/>
18
+ <circle cx="565" cy="200" r="9" fill="#25c39d" stroke="#25c39d" stroke-width="2"/>
19
+ <circle cx="495" cy="250" r="9" fill="#25c39d" stroke="#25c39d" stroke-width="2"/>
20
+ <circle cx="635" cy="250" r="9" fill="#25c39d" stroke="#25c39d" stroke-width="2"/>
21
+ <circle cx="460" cy="308" r="9" fill="#25c39d" stroke="#25c39d" stroke-width="2"/>
22
+ <circle cx="530" cy="308" r="9" fill="#25c39d" stroke="#25c39d" stroke-width="2"/>
23
+ <circle cx="605" cy="308" r="9" fill="#25c39d" stroke="#25c39d" stroke-width="2"/>
24
+ <circle cx="675" cy="308" r="9" fill="#25c39d" stroke="#25c39d" stroke-width="2"/>
25
+ <path d="M565 209 L495 241" fill="none" stroke="#9cadbf" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
26
+ <path d="M565 209 L635 241" fill="none" stroke="#9cadbf" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
27
+ <path d="M495 259 L460 299" fill="none" stroke="#9cadbf" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
28
+ <path d="M495 259 L530 299" fill="none" stroke="#9cadbf" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
29
+ <path d="M635 259 L605 299" fill="none" stroke="#9cadbf" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
30
+ <path d="M635 259 L675 299" fill="none" stroke="#9cadbf" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
31
+ <rect x="842" y="220" width="72" height="7" fill="#83b5e7" opacity="0.95"/>
32
+ <rect x="920" y="220" width="28" height="7" fill="#ffbd59" opacity="0.95"/>
33
+ <rect x="954" y="220" width="70" height="7" fill="#25c39d" opacity="0.95"/>
34
+ <rect x="842" y="240" width="72" height="7" fill="#83b5e7" opacity="0.83"/>
35
+ <rect x="920" y="240" width="28" height="7" fill="#ffbd59" opacity="0.83"/>
36
+ <rect x="954" y="240" width="70" height="7" fill="#25c39d" opacity="0.83"/>
37
+ <rect x="842" y="260" width="72" height="7" fill="#83b5e7" opacity="0.71"/>
38
+ <rect x="920" y="260" width="28" height="7" fill="#ffbd59" opacity="0.71"/>
39
+ <rect x="954" y="260" width="70" height="7" fill="#25c39d" opacity="0.71"/>
40
+ <rect x="842" y="280" width="72" height="7" fill="#83b5e7" opacity="0.59"/>
41
+ <rect x="920" y="280" width="28" height="7" fill="#ffbd59" opacity="0.59"/>
42
+ <rect x="954" y="280" width="70" height="7" fill="#25c39d" opacity="0.59"/>
43
+ <path d="M355 258 h40 m-8 -7 8 7 -8 7" fill="none" stroke="#9cadbf" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
44
+ <path d="M745 258 h40 m-8 -7 8 7 -8 7" fill="none" stroke="#9cadbf" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
45
+ <text x="56" y="386" font-size="24" fill="#eef2f7" font-weight="700">Reference collection</text>
46
+ <text x="56" y="420" font-size="17" fill="#9cadbf" font-weight="400">Amino-acid or nucleotide sequences</text>
47
+ <text x="56" y="447" font-size="17" fill="#9cadbf" font-weight="400">Caller-owned IDs and annotations</text>
48
+ <text x="446" y="386" font-size="24" fill="#eef2f7" font-weight="700">Immutable native index</text>
49
+ <text x="446" y="420" font-size="17" fill="#9cadbf" font-weight="400">Whole-sequence or substring search</text>
50
+ <text x="446" y="447" font-size="17" fill="#9cadbf" font-weight="400">Shared read-only reference state</text>
51
+ <text x="836" y="386" font-size="24" fill="#eef2f7" font-weight="700">One batch of queries</text>
52
+ <text x="836" y="420" font-size="17" fill="#9cadbf" font-weight="400">Hits, alignments and reductions</text>
53
+ <text x="836" y="447" font-size="17" fill="#9cadbf" font-weight="400">Automatic allocation-aware parallelism</text>
54
+ <path d="M56 483 H1144" fill="none" stroke="#354254" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
55
+ <rect x="56" y="522" width="27" height="4" fill="#83b5e7" opacity="1"/>
56
+ <text x="56" y="566" font-size="23" fill="#eef2f7" font-weight="700">Indexed search</text>
57
+ <text x="56" y="603" font-size="16" fill="#9cadbf" font-weight="400">Bounded fuzzy matches and top hits.</text>
58
+ <text x="56" y="629" font-size="16" fill="#9cadbf" font-weight="400">TextIndex finds substrings in long records.</text>
59
+ <rect x="446" y="522" width="27" height="4" fill="#25c39d" opacity="1"/>
60
+ <text x="446" y="566" font-size="23" fill="#eef2f7" font-weight="700">Pairwise operations</text>
61
+ <text x="446" y="603" font-size="16" fill="#9cadbf" font-weight="400">Affine alignment and sequence distances.</text>
62
+ <text x="446" y="629" font-size="16" fill="#9cadbf" font-weight="400">Gap-block scoring and matrix reductions.</text>
63
+ <rect x="836" y="522" width="27" height="4" fill="#ffbd59" opacity="1"/>
64
+ <text x="836" y="566" font-size="23" fill="#eef2f7" font-weight="700">Composable outputs</text>
65
+ <text x="836" y="603" font-size="16" fill="#9cadbf" font-weight="400">Map ref_id back to your reference rows.</text>
66
+ <text x="836" y="629" font-size="16" fill="#9cadbf" font-weight="400">Biological interpretation stays downstream.</text>
67
+ <path d="M56 678 H1144" fill="none" stroke="#354254" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
68
+ <text x="56" y="719" font-size="17" fill="#9cadbf" font-weight="400">C++20 + Python API</text>
69
+ <text x="735" y="719" font-size="16" fill="#9cadbf" font-weight="400">Batch APIs · shared resources · automatic CPU budgets</text>
70
+ </g></svg>
@@ -0,0 +1,70 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="1200" height="760" viewBox="0 0 1200 760" role="img" aria-labelledby="title desc"><title id="title">From sequence collections to fast batch search</title><desc id="desc">Build an immutable index once; submit queries together. Illustrations are schematic, not measured results.</desc><!-- Editable schematic, not measured observations. PNG: rsvg-convert assets/workflow-light.svg -o assets/workflow.png -->
2
+ <rect width="1200" height="760" fill="#ffffff"/><g font-family="Arial, Helvetica, sans-serif">
3
+ <text x="56" y="72" font-size="32" fill="#1a2332" font-weight="700">From sequence collections to fast batch search</text>
4
+ <text x="56" y="110" font-size="19" fill="#54657a" font-weight="400">Build an immutable index once; submit queries together.</text>
5
+ <path d="M56 142 H1144" fill="none" stroke="#e6e9ee" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
6
+ <rect x="80" y="220" width="72" height="7" fill="#3f75ac" opacity="0.95"/>
7
+ <rect x="158" y="220" width="28" height="7" fill="#b17b20" opacity="0.95"/>
8
+ <rect x="192" y="220" width="70" height="7" fill="#168b78" opacity="0.95"/>
9
+ <rect x="80" y="240" width="72" height="7" fill="#3f75ac" opacity="0.83"/>
10
+ <rect x="158" y="240" width="28" height="7" fill="#b17b20" opacity="0.83"/>
11
+ <rect x="192" y="240" width="70" height="7" fill="#168b78" opacity="0.83"/>
12
+ <rect x="80" y="260" width="72" height="7" fill="#3f75ac" opacity="0.71"/>
13
+ <rect x="158" y="260" width="28" height="7" fill="#b17b20" opacity="0.71"/>
14
+ <rect x="192" y="260" width="70" height="7" fill="#168b78" opacity="0.71"/>
15
+ <rect x="80" y="280" width="72" height="7" fill="#3f75ac" opacity="0.59"/>
16
+ <rect x="158" y="280" width="28" height="7" fill="#b17b20" opacity="0.59"/>
17
+ <rect x="192" y="280" width="70" height="7" fill="#168b78" opacity="0.59"/>
18
+ <circle cx="565" cy="200" r="9" fill="#168b78" stroke="#168b78" stroke-width="2"/>
19
+ <circle cx="495" cy="250" r="9" fill="#168b78" stroke="#168b78" stroke-width="2"/>
20
+ <circle cx="635" cy="250" r="9" fill="#168b78" stroke="#168b78" stroke-width="2"/>
21
+ <circle cx="460" cy="308" r="9" fill="#168b78" stroke="#168b78" stroke-width="2"/>
22
+ <circle cx="530" cy="308" r="9" fill="#168b78" stroke="#168b78" stroke-width="2"/>
23
+ <circle cx="605" cy="308" r="9" fill="#168b78" stroke="#168b78" stroke-width="2"/>
24
+ <circle cx="675" cy="308" r="9" fill="#168b78" stroke="#168b78" stroke-width="2"/>
25
+ <path d="M565 209 L495 241" fill="none" stroke="#54657a" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
26
+ <path d="M565 209 L635 241" fill="none" stroke="#54657a" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
27
+ <path d="M495 259 L460 299" fill="none" stroke="#54657a" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
28
+ <path d="M495 259 L530 299" fill="none" stroke="#54657a" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
29
+ <path d="M635 259 L605 299" fill="none" stroke="#54657a" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
30
+ <path d="M635 259 L675 299" fill="none" stroke="#54657a" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
31
+ <rect x="842" y="220" width="72" height="7" fill="#3f75ac" opacity="0.95"/>
32
+ <rect x="920" y="220" width="28" height="7" fill="#b17b20" opacity="0.95"/>
33
+ <rect x="954" y="220" width="70" height="7" fill="#168b78" opacity="0.95"/>
34
+ <rect x="842" y="240" width="72" height="7" fill="#3f75ac" opacity="0.83"/>
35
+ <rect x="920" y="240" width="28" height="7" fill="#b17b20" opacity="0.83"/>
36
+ <rect x="954" y="240" width="70" height="7" fill="#168b78" opacity="0.83"/>
37
+ <rect x="842" y="260" width="72" height="7" fill="#3f75ac" opacity="0.71"/>
38
+ <rect x="920" y="260" width="28" height="7" fill="#b17b20" opacity="0.71"/>
39
+ <rect x="954" y="260" width="70" height="7" fill="#168b78" opacity="0.71"/>
40
+ <rect x="842" y="280" width="72" height="7" fill="#3f75ac" opacity="0.59"/>
41
+ <rect x="920" y="280" width="28" height="7" fill="#b17b20" opacity="0.59"/>
42
+ <rect x="954" y="280" width="70" height="7" fill="#168b78" opacity="0.59"/>
43
+ <path d="M355 258 h40 m-8 -7 8 7 -8 7" fill="none" stroke="#54657a" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
44
+ <path d="M745 258 h40 m-8 -7 8 7 -8 7" fill="none" stroke="#54657a" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
45
+ <text x="56" y="386" font-size="24" fill="#1a2332" font-weight="700">Reference collection</text>
46
+ <text x="56" y="420" font-size="17" fill="#54657a" font-weight="400">Amino-acid or nucleotide sequences</text>
47
+ <text x="56" y="447" font-size="17" fill="#54657a" font-weight="400">Caller-owned IDs and annotations</text>
48
+ <text x="446" y="386" font-size="24" fill="#1a2332" font-weight="700">Immutable native index</text>
49
+ <text x="446" y="420" font-size="17" fill="#54657a" font-weight="400">Whole-sequence or substring search</text>
50
+ <text x="446" y="447" font-size="17" fill="#54657a" font-weight="400">Shared read-only reference state</text>
51
+ <text x="836" y="386" font-size="24" fill="#1a2332" font-weight="700">One batch of queries</text>
52
+ <text x="836" y="420" font-size="17" fill="#54657a" font-weight="400">Hits, alignments and reductions</text>
53
+ <text x="836" y="447" font-size="17" fill="#54657a" font-weight="400">Automatic allocation-aware parallelism</text>
54
+ <path d="M56 483 H1144" fill="none" stroke="#e6e9ee" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
55
+ <rect x="56" y="522" width="27" height="4" fill="#3f75ac" opacity="1"/>
56
+ <text x="56" y="566" font-size="23" fill="#1a2332" font-weight="700">Indexed search</text>
57
+ <text x="56" y="603" font-size="16" fill="#54657a" font-weight="400">Bounded fuzzy matches and top hits.</text>
58
+ <text x="56" y="629" font-size="16" fill="#54657a" font-weight="400">TextIndex finds substrings in long records.</text>
59
+ <rect x="446" y="522" width="27" height="4" fill="#168b78" opacity="1"/>
60
+ <text x="446" y="566" font-size="23" fill="#1a2332" font-weight="700">Pairwise operations</text>
61
+ <text x="446" y="603" font-size="16" fill="#54657a" font-weight="400">Affine alignment and sequence distances.</text>
62
+ <text x="446" y="629" font-size="16" fill="#54657a" font-weight="400">Gap-block scoring and matrix reductions.</text>
63
+ <rect x="836" y="522" width="27" height="4" fill="#b17b20" opacity="1"/>
64
+ <text x="836" y="566" font-size="23" fill="#1a2332" font-weight="700">Composable outputs</text>
65
+ <text x="836" y="603" font-size="16" fill="#54657a" font-weight="400">Map ref_id back to your reference rows.</text>
66
+ <text x="836" y="629" font-size="16" fill="#54657a" font-weight="400">Biological interpretation stays downstream.</text>
67
+ <path d="M56 678 H1144" fill="none" stroke="#e6e9ee" stroke-width="2" stroke-linejoin="round" stroke-linecap="round"/>
68
+ <text x="56" y="719" font-size="17" fill="#54657a" font-weight="400">C++20 + Python API</text>
69
+ <text x="735" y="719" font-size="16" fill="#54657a" font-weight="400">Batch APIs · shared resources · automatic CPU budgets</text>
70
+ </g></svg>
Binary file
@@ -0,0 +1,32 @@
1
+ #pragma once
2
+
3
+ #include <cstddef>
4
+ #include <cstdint>
5
+ #include <optional>
6
+ #include <span>
7
+ #include <vector>
8
+
9
+ namespace seqtree {
10
+
11
+ class RankedNeighborhood {
12
+ public:
13
+ using Pools = std::vector<std::vector<uint32_t>>;
14
+ using Weights = std::vector<std::optional<std::vector<double>>>;
15
+
16
+ RankedNeighborhood(Pools targets, Pools controls, Weights target_weights = {},
17
+ Weights control_weights = {});
18
+
19
+ const std::vector<size_t>& rank_offsets() const { return offsets_; }
20
+
21
+ // Row-major (query, packed rank slot, field): radius, count, sum, target mass, control mass.
22
+ std::vector<double> reduce(std::span<const double> distances, size_t rows, size_t columns,
23
+ bool distinct, double taper_unit, int threads, size_t max_result_bytes) const;
24
+
25
+ private:
26
+ Pools targets_, controls_;
27
+ Weights target_weights_, control_weights_;
28
+ std::vector<size_t> offsets_{0};
29
+ size_t min_columns_ = 0;
30
+ };
31
+
32
+ } // namespace seqtree
@@ -4,7 +4,7 @@ build-backend = "scikit_build_core.build"
4
4
 
5
5
  [project]
6
6
  name = "seqtree"
7
- version = "1.3.4"
7
+ version = "1.4.0"
8
8
  description = "Fast fuzzy search over biological sequences (C++ core, Python bindings)"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -51,12 +51,12 @@ from ._core import gapblock_paired_topk_batch as _gapblock_paired_topk_batch
51
51
  from ._core import gapblock_paired_count_batch as _gapblock_paired_count_batch
52
52
  from ._core import gapblock_paired_sum_count_batch as _gapblock_paired_sum_count_batch
53
53
 
54
- from ._core import gapblock_grouped_count_batch as _gapblock_grouped_count_batch, _GroupedGeometry
54
+ from ._core import gapblock_grouped_count_batch as _gapblock_grouped_count_batch, _GroupedGeometry, RankedNeighborhood
55
55
 
56
56
  __all__ = [
57
57
  "gapblock_score", "score_matrix", "ball_batch", "group_audit_batch", "topk_batch", "count_batch", "paired_topk_batch", "paired_count_batch", "paired_sum_count_batch", "deletion_variants", "central_prior", "profile_prior",
58
58
  "frame_prior", "positions_prior", "embed_in_frame", "gap_cost", "GapBlockIndex", "ScoreMatrix",
59
- "IslandProfile", "PairedFeatureOffsets", "grouped_count_batch", "grouped_paired_sum_count_batch",
59
+ "IslandProfile", "PairedFeatureOffsets", "RankedNeighborhood", "grouped_count_batch", "grouped_paired_sum_count_batch",
60
60
  ]
61
61
 
62
62
  #: A prior value large enough that no layout carrying it can ever win, yet small enough that
@@ -1,5 +1,6 @@
1
1
  #include "seqtree/seqtree.hpp"
2
2
  #include "seqtree/kmer_index.hpp"
3
+ #include "seqtree/ranked_neighborhood.hpp"
3
4
  #include "seqtree/text_index.hpp"
4
5
 
5
6
  #include <nanobind/nanobind.h>
@@ -12,6 +13,7 @@
12
13
  #include <nanobind/stl/vector.h>
13
14
 
14
15
  #include <algorithm>
16
+ #include <cstring>
15
17
  #include <exception>
16
18
  #include <optional>
17
19
  #include <string>
@@ -350,6 +352,49 @@ PyType_Slot kCountBufferSlots[] = {
350
352
  {Py_bf_releasebuffer,(void*)release_view},{0,nullptr}
351
353
  };
352
354
 
355
+ struct RankedBlock {
356
+ std::vector<double> data;
357
+ size_t rows, slots;
358
+ };
359
+
360
+ int ranked_block_getbuffer(PyObject* obj, Py_buffer* view, int flags) {
361
+ if (flags & PyBUF_WRITABLE) {
362
+ PyErr_SetString(PyExc_BufferError, "ranked neighborhood blocks are read-only");
363
+ return -1;
364
+ }
365
+ const auto* block = nb::inst_ptr<RankedBlock>(obj);
366
+ const Py_ssize_t shape[] = {Py_ssize_t(block->rows), Py_ssize_t(block->slots), 5};
367
+ const Py_ssize_t strides[] = {Py_ssize_t(sizeof(double) * 5 * block->slots),
368
+ Py_ssize_t(sizeof(double) * 5), Py_ssize_t(sizeof(double))};
369
+ fill_view(obj, view, flags, const_cast<double*>(block->data.data()), 3, shape, strides, sizeof(double), "d");
370
+ return 0;
371
+ }
372
+
373
+ PyType_Slot kRankedBlockSlots[] = {
374
+ {Py_bf_getbuffer, (void*)ranked_block_getbuffer},
375
+ {Py_bf_releasebuffer, (void*)release_view},
376
+ {0, nullptr}
377
+ };
378
+
379
+ RankedBlock reduce_ranked(const RankedNeighborhood& reducer, const nb::object& distances,
380
+ bool distinct, double taper_unit, int threads, size_t max_result_bytes) {
381
+ struct DistanceView {
382
+ Py_buffer view{};
383
+ ~DistanceView() { if (view.obj) PyBuffer_Release(&view); }
384
+ } buffer;
385
+ auto& view = buffer.view;
386
+ if (PyObject_GetBuffer(distances.ptr(), &view, PyBUF_C_CONTIGUOUS | PyBUF_FORMAT) < 0)
387
+ throw nb::python_error();
388
+ if (view.ndim != 2 || view.itemsize != sizeof(double) || std::strcmp(view.format, "d") != 0 ||
389
+ reinterpret_cast<uintptr_t>(view.buf) % alignof(double))
390
+ throw nb::value_error("distances must be a C-contiguous aligned float64 matrix");
391
+ const auto rows = size_t(view.shape[0]), columns = size_t(view.shape[1]);
392
+ const std::span data(static_cast<const double*>(view.buf), size_t(view.len) / sizeof(double));
393
+ nb::gil_scoped_release release;
394
+ return {reducer.reduce(data, rows, columns, distinct, taper_unit, threads, max_result_bytes),
395
+ rows, reducer.rank_offsets().back()};
396
+ }
397
+
353
398
  // A read-only 1-D typed window onto memory a TextResult owns. Same reasoning as ScoreMatrix:
354
399
  // seqtree has no runtime dependencies, so the way out is the buffer protocol, not an ndarray.
355
400
  // `owner` is a strong reference to the TextResult, so a view outlives the dict it came from.
@@ -930,6 +975,32 @@ NB_MODULE(_core, m) {
930
975
  .def(nb::init<std::vector<std::vector<int32_t>>, std::vector<std::vector<int32_t>>, std::vector<std::vector<int32_t>>, double, int32_t>(),
931
976
  nb::arg("query_codes"), nb::arg("reference_codes"), nb::arg("costs"), nb::arg("weight")=1.0, nb::arg("scale")=1);
932
977
 
978
+ nb::class_<RankedBlock>(m, "_RankedBlock", nb::type_slots(kRankedBlockSlots));
979
+ nb::class_<RankedNeighborhood>(m, "RankedNeighborhood", R"doc(
980
+ Prepare aligned target and competitor pools of strictly increasing reference indices.
981
+ Supply optional per-key weights as already normalized masses, or None for a uniform pool.
982
+ Target width fixes the maximum of one and ceil(log(width)) ranks, or zero for an empty target.
983
+ )doc")
984
+ .def(nb::init<RankedNeighborhood::Pools, RankedNeighborhood::Pools, RankedNeighborhood::Weights,
985
+ RankedNeighborhood::Weights>(),
986
+ nb::arg("targets"), nb::arg("controls"), nb::kw_only(),
987
+ nb::arg("target_weights") = RankedNeighborhood::Weights{},
988
+ nb::arg("control_weights") = RankedNeighborhood::Weights{})
989
+ .def_prop_ro("rank_offsets", &RankedNeighborhood::rank_offsets,
990
+ "Prefix offsets for each target's fixed rank slots.")
991
+ .def("reduce", &reduce_ranked, nb::arg("distances"), nb::kw_only(), nb::arg("distinct") = false,
992
+ nb::arg("taper_unit") = 0., nb::arg("threads") = 0,
993
+ nb::arg("max_result_bytes") = size_t(64) * 1024 * 1024, R"doc(
994
+ Reduce one C-contiguous aligned float64 query-by-reference distance block.
995
+ Positive infinity masks a key and preserves its fixed pool exposure.
996
+ Return a read-only float64 buffer of shape (queries, rank_offsets[-1], 5), with
997
+ fields radius, inclusive target count, target distance sum, target mass, and control mass.
998
+ Unused ranks have infinite radius and zero aggregate fields.
999
+ Distinct mode visits each occupied radius once; otherwise tied key ranks repeat.
1000
+ A positive taper unit extends both masses linearly to zero two units beyond the radius.
1001
+ Counts and sums remain inclusive and unweighted in both cases.
1002
+ )doc");
1003
+
933
1004
  m.def("gapblock_matrix", &py_gapblock_matrix, nb::arg("queries"), nb::arg("refs"),
934
1005
  nb::arg("alphabet") = "aa", nb::arg("matrix") = std::nullopt, nb::arg("gap_open") = 1,
935
1006
  nb::arg("gap_extend") = 1, nb::arg("prior") = std::vector<int32_t>{},
@@ -0,0 +1,144 @@
1
+ #include "seqtree/ranked_neighborhood.hpp"
2
+ #include "seqtree/parallel.hpp"
3
+
4
+ #include <algorithm>
5
+ #include <iterator>
6
+ #include <cmath>
7
+ #include <limits>
8
+ #include <stdexcept>
9
+ #include <utility>
10
+
11
+ namespace seqtree {
12
+ namespace {
13
+
14
+ constexpr double inf = std::numeric_limits<double>::infinity();
15
+ constexpr size_t fields = 5;
16
+
17
+ size_t validate(const RankedNeighborhood::Pools& pools, RankedNeighborhood::Weights& weights) {
18
+ if (weights.empty()) weights.resize(pools.size());
19
+ if (weights.size() != pools.size()) throw std::invalid_argument("weights must align with pools");
20
+ size_t columns = 0;
21
+ for (size_t i = 0; i < pools.size(); ++i) {
22
+ const auto& pool = pools[i];
23
+ if (!std::is_sorted(pool.begin(), pool.end()) || std::adjacent_find(pool.begin(), pool.end()) != pool.end())
24
+ throw std::invalid_argument("reference indices in each pool must be strictly increasing");
25
+ if (!pool.empty()) columns = std::max(columns, size_t(pool.back()) + 1);
26
+ if (const auto& w = weights[i]; w && (w->size() != pool.size() ||
27
+ std::any_of(w->begin(), w->end(), [](double value) { return !std::isfinite(value) || value < 0; })))
28
+ throw std::invalid_argument("each weight vector must contain one finite nonnegative value per key");
29
+ }
30
+ return columns;
31
+ }
32
+
33
+ struct Scratch {
34
+ std::vector<double> ordered, radii, bins;
35
+ };
36
+
37
+ void add_pool(std::span<const double> row, const std::vector<uint32_t>& pool,
38
+ const std::optional<std::vector<double>>& weights, std::span<const double> radii,
39
+ std::span<double> result, bool target, double taper_unit) {
40
+ const auto weight = weights ? weights->data() : nullptr;
41
+ const size_t mass = target ? 3 : 4;
42
+ const auto last = radii.back();
43
+ for (size_t i = 0; i < pool.size(); ++i) {
44
+ const auto d = row[pool[i]];
45
+ if (d > last && (!taper_unit || (d - last) / taper_unit >= 2)) continue;
46
+ const size_t bin = std::lower_bound(radii.begin(), radii.end(), d) - radii.begin();
47
+ const double w = weight ? weight[i] : 1;
48
+ if (bin < radii.size()) {
49
+ auto slot = result.subspan(fields * bin, fields);
50
+ if (target) {
51
+ ++slot[1];
52
+ slot[2] += d;
53
+ }
54
+ slot[mass] += w;
55
+ }
56
+ if (taper_unit) {
57
+ for (size_t j = bin; j > 0; --j) {
58
+ const double factor = 1 - .5 * ((d - radii[j - 1]) / taper_unit);
59
+ if (factor <= 0) break;
60
+ // Offset past the inclusive mass fields. Soft contributions must not propagate
61
+ // to the next rank when we turn the hard bins into cumulative totals.
62
+ result[fields * radii.size() + 2 * (j - 1) + (target ? 0 : 1)] += w * factor;
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ } // namespace
69
+
70
+ RankedNeighborhood::RankedNeighborhood(Pools targets, Pools controls, Weights target_weights, Weights control_weights)
71
+ : targets_(std::move(targets)), controls_(std::move(controls)),
72
+ target_weights_(std::move(target_weights)), control_weights_(std::move(control_weights)) {
73
+ if (targets_.size() != controls_.size()) throw std::invalid_argument("target and control pools must align");
74
+ min_columns_ = std::max(validate(targets_, target_weights_), validate(controls_, control_weights_));
75
+ for (const auto& pool : targets_) {
76
+ const size_t cap = pool.empty() ? 0 : std::max<size_t>(1, std::ceil(std::log(pool.size())));
77
+ offsets_.push_back(offsets_.back() + cap);
78
+ }
79
+ }
80
+
81
+ std::vector<double> RankedNeighborhood::reduce(std::span<const double> distances, size_t rows, size_t columns,
82
+ bool distinct, double taper_unit, int threads,
83
+ size_t max_result_bytes) const {
84
+ if ((columns && rows > distances.size() / columns) || rows * columns != distances.size())
85
+ throw std::invalid_argument("distance block shape does not match its values");
86
+ if (columns < min_columns_) throw std::invalid_argument("distance block has too few reference columns");
87
+ if (!std::isfinite(taper_unit) || taper_unit < 0) throw std::invalid_argument("taper unit must be finite and nonnegative");
88
+ const size_t slots = offsets_.back();
89
+ if (rows && slots > max_result_bytes / sizeof(double) / fields / rows)
90
+ throw std::invalid_argument("ranked result exceeds byte budget; reduce a smaller query block");
91
+ std::vector<double> output(rows * slots * fields);
92
+ parallel_for(rows, threads, [] { return Scratch{}; }, [&](size_t q, Scratch& scratch) {
93
+ const auto row = distances.subspan(q * columns, columns);
94
+ if (std::any_of(row.begin(), row.end(), [](double d) { return !(d >= 0); }))
95
+ throw std::invalid_argument("distances must be nonnegative or positive infinity");
96
+ if (!slots) return;
97
+ auto& [ordered, radii, bins] = scratch;
98
+ auto query = std::span(output).subspan(q * slots * fields, slots * fields);
99
+ for (size_t g = 0; g < targets_.size(); ++g) {
100
+ const size_t cap = offsets_[g + 1] - offsets_[g];
101
+ if (!cap) continue;
102
+ const auto group = query.subspan(offsets_[g] * fields, cap * fields);
103
+ for (size_t i = 0; i < cap; ++i) group[i * fields] = inf;
104
+ ordered.clear();
105
+ for (const auto id : targets_[g])
106
+ if (row[id] != inf) ordered.push_back(row[id]);
107
+ if (ordered.empty()) continue;
108
+ if (distinct) {
109
+ std::sort(ordered.begin(), ordered.end());
110
+ ordered.erase(std::unique(ordered.begin(), ordered.end()), ordered.end());
111
+ } else {
112
+ std::partial_sort(ordered.begin(), ordered.begin() + std::min(cap, ordered.size()), ordered.end());
113
+ }
114
+ ordered.resize(std::min(cap, ordered.size()));
115
+ radii.clear();
116
+ std::unique_copy(ordered.begin(), ordered.end(), std::back_inserter(radii));
117
+ bins.assign(radii.size() * (fields + (taper_unit ? 2 : 0)), 0);
118
+ add_pool(row, targets_[g], target_weights_[g], radii, bins, true, taper_unit);
119
+ add_pool(row, controls_[g], control_weights_[g], radii, bins, false, taper_unit);
120
+
121
+ for (size_t i = 0; i < radii.size(); ++i) {
122
+ bins[i * fields] = radii[i];
123
+ if (i)
124
+ for (size_t j = 1; j < fields; ++j) bins[i * fields + j] += bins[(i - 1) * fields + j];
125
+ }
126
+ if (taper_unit) {
127
+ const size_t soft = radii.size() * fields;
128
+ for (size_t i = 0; i < radii.size(); ++i) {
129
+ bins[i * fields + 3] += bins[soft + 2 * i];
130
+ bins[i * fields + 4] += bins[soft + 2 * i + 1];
131
+ }
132
+ }
133
+
134
+ size_t bin = 0;
135
+ for (size_t i = 0; i < ordered.size(); ++i) {
136
+ if (ordered[i] != radii[bin]) ++bin;
137
+ std::copy_n(bins.begin() + bin * fields, fields, group.begin() + i * fields);
138
+ }
139
+ }
140
+ });
141
+ return output;
142
+ }
143
+
144
+ } // namespace seqtree
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes