pycbas 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,36 @@
1
+ # Python
2
+ __pycache__/
3
+ *.pyc
4
+ *.pyo
5
+ *.egg-info/
6
+ dist/
7
+ build/
8
+
9
+ # Pixi
10
+ .pixi/
11
+
12
+ # MkDocs build output
13
+ site/
14
+
15
+ # Pytest
16
+ .pytest_cache/
17
+
18
+ # OS
19
+ .DS_Store
20
+ Thumbs.db
21
+
22
+ # Cached results (regenerable)
23
+ **/*.npz
24
+
25
+ # Reference materials (not for distribution)
26
+ papers/
27
+ cbas_paper_docling/
28
+ igor_cbas/
29
+ DanielStudentImplementation/
30
+ utilities/
31
+ notes/
32
+ notes.md
33
+
34
+ # Raw downloaded data (regenerable from source)
35
+ data/noel_ibl_mice/raw/
36
+ data/ibl_mice/raw/
pycbas-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Demetris Roumis
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.
pycbas-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,159 @@
1
+ Metadata-Version: 2.4
2
+ Name: pycbas
3
+ Version: 0.1.0
4
+ Summary: Choice-Wide Behavioral Association Study — identify behavioral sequences that differ between groups or correlate with continuous measures
5
+ Project-URL: Repository, https://github.com/droumis/pycbas
6
+ Author: Demetris Roumis
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Requires-Python: >=3.11
10
+ Requires-Dist: numba>=0.59
11
+ Requires-Dist: numpy>=1.24
12
+ Provides-Extra: dev
13
+ Requires-Dist: matplotlib>=3.7; extra == 'dev'
14
+ Requires-Dist: pandas>=2.0; extra == 'dev'
15
+ Requires-Dist: pytest>=7; extra == 'dev'
16
+ Requires-Dist: scipy>=1.11; extra == 'dev'
17
+ Provides-Extra: gui
18
+ Requires-Dist: bokeh>=3.3; extra == 'gui'
19
+ Requires-Dist: holoviews>=1.18; extra == 'gui'
20
+ Requires-Dist: pandas>=2.0; extra == 'gui'
21
+ Requires-Dist: panel>=1.4; extra == 'gui'
22
+ Description-Content-Type: text/markdown
23
+
24
+ # pycbas
25
+
26
+ Python implementation of the [CBAS algorithm](https://github.com/dbkastner/CBAS) (Choice-Wide Behavioral Association Study) for identifying behavioral sequences that differ significantly between experimental groups or correlate with a continuous measure.
27
+
28
+ Uses Romano-Wolf step-down for multiple comparison correction and k-FWER iteration for false discovery proportion control.
29
+
30
+ **Reference:** Kastner et al., "Choice-Wide Behavioral Association Study" [(2026 preprint)](https://www.biorxiv.org/content/10.1101/2024.02.26.582115v4)
31
+
32
+ ## Interactive GUI
33
+
34
+ A no-code interface for running CBAS analyses. Load data from a local folder, auto-detect parameters and analysis mode, run the pipeline, and explore results visually.
35
+
36
+ ```bash
37
+ git clone https://github.com/droumis/pycbas.git
38
+ cd pycbas
39
+
40
+ # option 1: pixi (recommended)
41
+ pixi run gui
42
+
43
+ # option 2: conda/mamba + pip
44
+ conda create -n pycbas python=3.11
45
+ conda activate pycbas
46
+ pip install -e ".[gui]"
47
+ pycbas gui
48
+ ```
49
+
50
+ See the [GUI documentation](https://droumis.github.io/pycbas/app/) for details.
51
+
52
+ ## Installation
53
+
54
+ We recommend installing in a dedicated environment (conda, mamba, or pixi) rather than your base environment.
55
+
56
+ ```bash
57
+ git clone https://github.com/droumis/pycbas.git
58
+ cd pycbas
59
+
60
+ # option 1: pixi (handles everything)
61
+ pixi install
62
+
63
+ # option 2: conda/mamba + pip
64
+ conda create -n pycbas python=3.11
65
+ conda activate pycbas
66
+ pip install -e ".[dev]"
67
+ ```
68
+
69
+ ## Quick start
70
+
71
+ ### Comparative mode (group differences)
72
+
73
+ ```python
74
+ from pycbas import CBASParams, load_subject_data, run_cbas_comparative
75
+
76
+ subjects_data = [load_subject_data(f) for f in data_files]
77
+ group_labels = [0, 0, 0, 1, 1, 1]
78
+
79
+ params = CBASParams(
80
+ num_arms=6,
81
+ seq_len_max=6,
82
+ criterion=800,
83
+ resample_number=10000,
84
+ )
85
+
86
+ result = run_cbas_comparative(subjects_data, group_labels, params)
87
+ print(f"{result.n_significant} significant sequences (k={result.k_final})")
88
+ ```
89
+
90
+ ### Correlative mode (continuous covariate)
91
+
92
+ ```python
93
+ from pycbas import run_cbas_correlative
94
+
95
+ result = run_cbas_correlative(subjects_data, cbit_scores, params)
96
+ ```
97
+
98
+ ### Resource estimation
99
+
100
+ ```python
101
+ from pycbas import estimate_resources, print_resource_estimate
102
+
103
+ est = estimate_resources(num_arms=12, seq_len_max=8, n_observed=5000)
104
+ print_resource_estimate(est)
105
+ ```
106
+
107
+ ## Parameters
108
+
109
+ | Parameter | Default | Description |
110
+ |-----------|---------|-------------|
111
+ | `num_arms` | 6 | Number of base symbols (choices) |
112
+ | `seq_len_max` | 6 | Maximum sequence length L |
113
+ | `criterion` | 800 | Number of trials used per subject |
114
+ | `resample_number` | 10,000 | Bootstrap resamples M |
115
+ | `alpha` | 0.5 | Significance threshold for FDP control |
116
+ | `gamma` | 0.05 | FDP tolerance |
117
+ | `centering` | False | Center bootstrap null (False matches Igor) |
118
+ | `block_aware` | False | Prevent sequences from spanning block/session boundaries |
119
+
120
+ ## Performance
121
+
122
+ | Dataset | Subjects | Sequences | Time | Peak RAM |
123
+ |---|---|---|---|---|
124
+ | Flies (2-arm, L=10) | 1,566 | 2,046 | ~21s | ~560 MB |
125
+ | Humans (6-arm, L=4) | 1,413 | 408 | ~3s | ~155 MB |
126
+ | Rats (6-arm, L=6) | 105 | 16,378 | ~7s | ~3.6 GB |
127
+
128
+ Timings on Apple M-series. The chunked pipeline (`chunked=True`, default) trades ~30% more time for ~40% less memory. Bootstrap and step-down are parallelized via numba. Set `NUMBA_DISABLE_JIT=1` to disable for debugging.
129
+
130
+ ## Validation
131
+
132
+ Exact match with the original Igor implementation on flies (1,605/2,046, k=81) and humans (31/408, k=2). Test statistics match to floating-point precision. Rats (105 subjects, `block_aware=True`): 572/16,378 significant (k=29), exact match with David's Igor implementation. Test statistics agree within 1e-4 on all 16,376 overlapping sequences.
133
+
134
+ See [results/validation_summary.md](results/validation_summary.md) for details, or per-dataset reports:
135
+ - [Flies](results/flies/validation_report.md)
136
+ - [Humans](results/humans/validation_report.md)
137
+ - [Rats](results/rats/validation_report.md)
138
+
139
+ ## Documentation
140
+
141
+ Full docs at **[droumis.github.io/pycbas](https://droumis.github.io/pycbas/)**
142
+
143
+ - [User Guide](https://droumis.github.io/pycbas/guide/) - data format, parameter selection, working with results
144
+ - [Algorithm](https://droumis.github.io/pycbas/algorithm/) - the step-down and k-FWER procedure in detail
145
+ - [API Reference](https://droumis.github.io/pycbas/api/) - all public functions and classes
146
+
147
+ ## Development
148
+
149
+ ```bash
150
+ pixi install # set up environment
151
+ pixi run test # run tests
152
+ pixi run flies # run fly analysis (paper params)
153
+ pixi run human # run human analysis
154
+ pixi run rats # run rat analysis
155
+ ```
156
+
157
+ ## License
158
+
159
+ MIT
pycbas-0.1.0/README.md ADDED
@@ -0,0 +1,136 @@
1
+ # pycbas
2
+
3
+ Python implementation of the [CBAS algorithm](https://github.com/dbkastner/CBAS) (Choice-Wide Behavioral Association Study) for identifying behavioral sequences that differ significantly between experimental groups or correlate with a continuous measure.
4
+
5
+ Uses Romano-Wolf step-down for multiple comparison correction and k-FWER iteration for false discovery proportion control.
6
+
7
+ **Reference:** Kastner et al., "Choice-Wide Behavioral Association Study" [(2026 preprint)](https://www.biorxiv.org/content/10.1101/2024.02.26.582115v4)
8
+
9
+ ## Interactive GUI
10
+
11
+ A no-code interface for running CBAS analyses. Load data from a local folder, auto-detect parameters and analysis mode, run the pipeline, and explore results visually.
12
+
13
+ ```bash
14
+ git clone https://github.com/droumis/pycbas.git
15
+ cd pycbas
16
+
17
+ # option 1: pixi (recommended)
18
+ pixi run gui
19
+
20
+ # option 2: conda/mamba + pip
21
+ conda create -n pycbas python=3.11
22
+ conda activate pycbas
23
+ pip install -e ".[gui]"
24
+ pycbas gui
25
+ ```
26
+
27
+ See the [GUI documentation](https://droumis.github.io/pycbas/app/) for details.
28
+
29
+ ## Installation
30
+
31
+ We recommend installing in a dedicated environment (conda, mamba, or pixi) rather than your base environment.
32
+
33
+ ```bash
34
+ git clone https://github.com/droumis/pycbas.git
35
+ cd pycbas
36
+
37
+ # option 1: pixi (handles everything)
38
+ pixi install
39
+
40
+ # option 2: conda/mamba + pip
41
+ conda create -n pycbas python=3.11
42
+ conda activate pycbas
43
+ pip install -e ".[dev]"
44
+ ```
45
+
46
+ ## Quick start
47
+
48
+ ### Comparative mode (group differences)
49
+
50
+ ```python
51
+ from pycbas import CBASParams, load_subject_data, run_cbas_comparative
52
+
53
+ subjects_data = [load_subject_data(f) for f in data_files]
54
+ group_labels = [0, 0, 0, 1, 1, 1]
55
+
56
+ params = CBASParams(
57
+ num_arms=6,
58
+ seq_len_max=6,
59
+ criterion=800,
60
+ resample_number=10000,
61
+ )
62
+
63
+ result = run_cbas_comparative(subjects_data, group_labels, params)
64
+ print(f"{result.n_significant} significant sequences (k={result.k_final})")
65
+ ```
66
+
67
+ ### Correlative mode (continuous covariate)
68
+
69
+ ```python
70
+ from pycbas import run_cbas_correlative
71
+
72
+ result = run_cbas_correlative(subjects_data, cbit_scores, params)
73
+ ```
74
+
75
+ ### Resource estimation
76
+
77
+ ```python
78
+ from pycbas import estimate_resources, print_resource_estimate
79
+
80
+ est = estimate_resources(num_arms=12, seq_len_max=8, n_observed=5000)
81
+ print_resource_estimate(est)
82
+ ```
83
+
84
+ ## Parameters
85
+
86
+ | Parameter | Default | Description |
87
+ |-----------|---------|-------------|
88
+ | `num_arms` | 6 | Number of base symbols (choices) |
89
+ | `seq_len_max` | 6 | Maximum sequence length L |
90
+ | `criterion` | 800 | Number of trials used per subject |
91
+ | `resample_number` | 10,000 | Bootstrap resamples M |
92
+ | `alpha` | 0.5 | Significance threshold for FDP control |
93
+ | `gamma` | 0.05 | FDP tolerance |
94
+ | `centering` | False | Center bootstrap null (False matches Igor) |
95
+ | `block_aware` | False | Prevent sequences from spanning block/session boundaries |
96
+
97
+ ## Performance
98
+
99
+ | Dataset | Subjects | Sequences | Time | Peak RAM |
100
+ |---|---|---|---|---|
101
+ | Flies (2-arm, L=10) | 1,566 | 2,046 | ~21s | ~560 MB |
102
+ | Humans (6-arm, L=4) | 1,413 | 408 | ~3s | ~155 MB |
103
+ | Rats (6-arm, L=6) | 105 | 16,378 | ~7s | ~3.6 GB |
104
+
105
+ Timings on Apple M-series. The chunked pipeline (`chunked=True`, default) trades ~30% more time for ~40% less memory. Bootstrap and step-down are parallelized via numba. Set `NUMBA_DISABLE_JIT=1` to disable for debugging.
106
+
107
+ ## Validation
108
+
109
+ Exact match with the original Igor implementation on flies (1,605/2,046, k=81) and humans (31/408, k=2). Test statistics match to floating-point precision. Rats (105 subjects, `block_aware=True`): 572/16,378 significant (k=29), exact match with David's Igor implementation. Test statistics agree within 1e-4 on all 16,376 overlapping sequences.
110
+
111
+ See [results/validation_summary.md](results/validation_summary.md) for details, or per-dataset reports:
112
+ - [Flies](results/flies/validation_report.md)
113
+ - [Humans](results/humans/validation_report.md)
114
+ - [Rats](results/rats/validation_report.md)
115
+
116
+ ## Documentation
117
+
118
+ Full docs at **[droumis.github.io/pycbas](https://droumis.github.io/pycbas/)**
119
+
120
+ - [User Guide](https://droumis.github.io/pycbas/guide/) - data format, parameter selection, working with results
121
+ - [Algorithm](https://droumis.github.io/pycbas/algorithm/) - the step-down and k-FWER procedure in detail
122
+ - [API Reference](https://droumis.github.io/pycbas/api/) - all public functions and classes
123
+
124
+ ## Development
125
+
126
+ ```bash
127
+ pixi install # set up environment
128
+ pixi run test # run tests
129
+ pixi run flies # run fly analysis (paper params)
130
+ pixi run human # run human analysis
131
+ pixi run rats # run rat analysis
132
+ ```
133
+
134
+ ## License
135
+
136
+ MIT
@@ -0,0 +1,48 @@
1
+ """
2
+ pycbas -- Choice-Wide Behavioral Association Study.
3
+
4
+ A Python implementation of the CBAS algorithm for identifying behavioral
5
+ sequences that differ between experimental groups or correlate with a
6
+ continuous measure. Uses Romano-Wolf step-down for multiple comparison
7
+ correction and k-FWER iteration for false discovery proportion control.
8
+
9
+ Reference: Kastner et al., "Choice-Wide Behavioral Association Study"
10
+ (2026 preprint) https://www.biorxiv.org/content/10.1101/2024.02.26.582115v4
11
+ """
12
+
13
+ from .params import CBASParams, CBASResult
14
+ from .io import (load_subject_data, extract_choice_stream, extract_choice_streams_by_block,
15
+ enumerate_sequences, enumerate_sequences_block_aware)
16
+ from .core import build_count_matrix, compute_test_stats, compute_test_stats_correlative
17
+ from .bootstrap import bootstrap_test_stats, bootstrap_test_stats_correlative
18
+ from .stepdown import (
19
+ romano_wolf_stepdown,
20
+ find_k_fwer,
21
+ find_k_fwer_k1,
22
+ find_k_fwer_chunked,
23
+ )
24
+ from .resources import estimate_resources, print_resource_estimate
25
+ from .pipeline import run_cbas_comparative, run_cbas_correlative
26
+
27
+ __all__ = [
28
+ "CBASParams",
29
+ "CBASResult",
30
+ "load_subject_data",
31
+ "extract_choice_stream",
32
+ "extract_choice_streams_by_block",
33
+ "enumerate_sequences",
34
+ "enumerate_sequences_block_aware",
35
+ "build_count_matrix",
36
+ "compute_test_stats",
37
+ "compute_test_stats_correlative",
38
+ "bootstrap_test_stats",
39
+ "bootstrap_test_stats_correlative",
40
+ "romano_wolf_stepdown",
41
+ "find_k_fwer",
42
+ "find_k_fwer_k1",
43
+ "find_k_fwer_chunked",
44
+ "run_cbas_comparative",
45
+ "run_cbas_correlative",
46
+ "estimate_resources",
47
+ "print_resource_estimate",
48
+ ]