LZGraphs 3.0.0__cp313-cp313-win_amd64.whl

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.
LZGraphs/__init__.py ADDED
@@ -0,0 +1,94 @@
1
+ """LZGraphs — LZ76 compression graphs for sequence repertoire analysis.
2
+
3
+ High-performance C backend with full LZ76 dictionary constraint enforcement.
4
+ """
5
+
6
+ __version__ = "3.0.0"
7
+
8
+ from ._graph import LZGraph
9
+ from ._pgen_dist import PgenDistribution
10
+ from ._simulation_result import SimulationResult
11
+ from ._errors import LZGraphError, NoGeneDataError, ConvergenceError, CorruptFileError
12
+ from . import _clzgraph as _c
13
+
14
+
15
+ def jensen_shannon_divergence(a, b):
16
+ """Jensen-Shannon divergence between two LZGraphs."""
17
+ return _c.jensen_shannon_divergence(a._cap, b._cap)
18
+
19
+
20
+ def k_diversity(sequences, k, *, variant='aap', draws=100, seed=None):
21
+ """K-diversity: subsample k sequences, count nodes, repeat.
22
+
23
+ Returns {'mean': float, 'std': float, 'ci_low': float, 'ci_high': float}
24
+ """
25
+ return _c.k_diversity(list(sequences), k, variant, draws,
26
+ seed if seed is not None else -1)
27
+
28
+
29
+ def saturation_curve(sequences, *, variant='aap', log_every=100):
30
+ """Node/edge saturation as sequences are added.
31
+
32
+ Returns list of {'n_sequences': int, 'n_nodes': int, 'n_edges': int}
33
+ """
34
+ return _c.saturation_curve(list(sequences), variant, log_every)
35
+
36
+
37
+ def lz76_decompose(sequence):
38
+ """LZ76 decomposition into subpatterns.
39
+
40
+ Example: lz76_decompose('CASSLGIRRT') -> ['C','A','S','SL','G','I','R','RT']
41
+ """
42
+ return _c.lz76_decompose(sequence)
43
+
44
+
45
+ def set_log_level(level='info'):
46
+ """Enable logging to stderr at the given level.
47
+
48
+ Levels: 'none', 'error', 'warn', 'info', 'debug', 'trace'.
49
+ 'none' disables logging. Default is 'info'.
50
+
51
+ Example:
52
+ LZGraphs.set_log_level('info') # see build progress and timing
53
+ LZGraphs.set_log_level('debug') # see algorithm decisions
54
+ LZGraphs.set_log_level('none') # silence all output
55
+ """
56
+ _c.set_log_level(level)
57
+
58
+
59
+ def set_log_callback(callback, level='info'):
60
+ """Set a custom log callback.
61
+
62
+ Args:
63
+ callback: A callable(level: int, message: str), or None to disable.
64
+ Level values: 1=error, 2=warn, 3=info, 4=debug, 5=trace.
65
+ level: Maximum level to emit.
66
+
67
+ Example:
68
+ import logging
69
+ logger = logging.getLogger('lzgraphs')
70
+ LEVEL_MAP = {1: logging.ERROR, 2: logging.WARNING, 3: logging.INFO,
71
+ 4: logging.DEBUG, 5: logging.DEBUG}
72
+ LZGraphs.set_log_callback(
73
+ lambda lvl, msg: logger.log(LEVEL_MAP.get(lvl, logging.DEBUG), msg),
74
+ level='info'
75
+ )
76
+ """
77
+ _c.set_log_callback(callback, level)
78
+
79
+
80
+ __all__ = [
81
+ 'LZGraph',
82
+ 'PgenDistribution',
83
+ 'SimulationResult',
84
+ 'LZGraphError',
85
+ 'NoGeneDataError',
86
+ 'ConvergenceError',
87
+ 'CorruptFileError',
88
+ 'jensen_shannon_divergence',
89
+ 'k_diversity',
90
+ 'saturation_curve',
91
+ 'lz76_decompose',
92
+ 'set_log_level',
93
+ 'set_log_callback',
94
+ ]