optimouse 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.
Files changed (34) hide show
  1. optimouse-0.1.0/LICENSE.md +21 -0
  2. optimouse-0.1.0/PKG-INFO +321 -0
  3. optimouse-0.1.0/README.md +280 -0
  4. optimouse-0.1.0/modules/__init__.py +21 -0
  5. optimouse-0.1.0/modules/bruker_concat_tif.py +650 -0
  6. optimouse-0.1.0/modules/compute_zcorr.py +2040 -0
  7. optimouse-0.1.0/modules/extraction.py +559 -0
  8. optimouse-0.1.0/modules/motion_correction.py +982 -0
  9. optimouse-0.1.0/modules/utils/plot_zones.py +125 -0
  10. optimouse-0.1.0/modules/utils/save_z_motion_args.py +93 -0
  11. optimouse-0.1.0/optimouse.egg-info/PKG-INFO +321 -0
  12. optimouse-0.1.0/optimouse.egg-info/SOURCES.txt +32 -0
  13. optimouse-0.1.0/optimouse.egg-info/dependency_links.txt +1 -0
  14. optimouse-0.1.0/optimouse.egg-info/requires.txt +19 -0
  15. optimouse-0.1.0/optimouse.egg-info/top_level.txt +2 -0
  16. optimouse-0.1.0/pipeline/__init__.py +0 -0
  17. optimouse-0.1.0/pipeline/configs/config_C57_O1M2_10022023_run1run2.json +107 -0
  18. optimouse-0.1.0/pipeline/configs/config_C57_O1M2_10022023_run1run2run3run4.json +114 -0
  19. optimouse-0.1.0/pipeline/configs/config_template_cnmf.json +123 -0
  20. optimouse-0.1.0/pipeline/configs/config_template_suite2p.json +102 -0
  21. optimouse-0.1.0/pipeline/configs/config_test.json +114 -0
  22. optimouse-0.1.0/pipeline/pipeline_cnmf.py +263 -0
  23. optimouse-0.1.0/pipeline/pipeline_mcorr.py +299 -0
  24. optimouse-0.1.0/pipeline/roi_zcorr.py +65 -0
  25. optimouse-0.1.0/pipeline/utils/__init__.py +0 -0
  26. optimouse-0.1.0/pipeline/utils/config_loader.py +92 -0
  27. optimouse-0.1.0/pipeline/utils/pipeline_utils.py +537 -0
  28. optimouse-0.1.0/pyproject.toml +71 -0
  29. optimouse-0.1.0/setup.cfg +4 -0
  30. optimouse-0.1.0/tests/test_make_composite_f_anat.py +252 -0
  31. optimouse-0.1.0/tests/test_module.py +83 -0
  32. optimouse-0.1.0/tests/test_motion_correction.py +416 -0
  33. optimouse-0.1.0/tests/test_patch_plots_efficient.py +234 -0
  34. optimouse-0.1.0/tests/test_subtract_z_motion_patches.py +143 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Vincent Prevosto, Manuel Levy
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,321 @@
1
+ Metadata-Version: 2.4
2
+ Name: optimouse
3
+ Version: 0.1.0
4
+ Summary: 2-photon calcium imaging data processing pipeline with CaImAn / Suite2P
5
+ Author-email: Vincent Prevosto <prevosto@mit.edu>, Manuel Levy <levym@mit.edu>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/vncntprvst/2P-proc
8
+ Project-URL: Repository, https://github.com/vncntprvst/2P-proc
9
+ Project-URL: Issues, https://github.com/vncntprvst/2P-proc/issues
10
+ Keywords: calcium imaging,2-photon,neuroscience,image processing,CaImAn
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
17
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
18
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
19
+ Classifier: Topic :: Scientific/Engineering :: Visualization
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE.md
23
+ Requires-Dist: caiman<=1.13.0,>=1.12.2
24
+ Requires-Dist: mesmerize-core>=0.5.0
25
+ Requires-Dist: numpy>=1.26.4
26
+ Requires-Dist: scipy>=1.15.3
27
+ Requires-Dist: scikit-image>=0.25.2
28
+ Requires-Dist: tifffile>=2025.5.10
29
+ Requires-Dist: h5py>=3.14.0
30
+ Requires-Dist: opencv-python>=4.11.0.86
31
+ Requires-Dist: pylibtiff>=0.7.0
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
34
+ Requires-Dist: pytest-cov>=3.0.0; extra == "dev"
35
+ Requires-Dist: black>=22.0.0; extra == "dev"
36
+ Requires-Dist: ruff>=0.0.200; extra == "dev"
37
+ Provides-Extra: viz
38
+ Requires-Dist: fastplotlib>=0.1.0a16; extra == "viz"
39
+ Requires-Dist: plotly>=6.5.2; extra == "viz"
40
+ Dynamic: license-file
41
+
42
+ # 2P-proc (optimouse)
43
+
44
+ [![Python Version](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/)
45
+ [![CaImAn Version](https://img.shields.io/badge/CaImAn-1.12.2+-green)](https://github.com/flatironinstitute/CaImAn)
46
+ ![License](https://img.shields.io/badge/license-MIT-red)
47
+
48
+ **2P-proc (optimouse)** is a 2-photon calcium imaging data processing pipeline built on [CaImAn](https://github.com/flatironinstitute/CaImAn/) and [Mesmerize](https://github.com/nel-lab/mesmerize-core/).
49
+
50
+ This package provides:
51
+ - **Motion correction**: Rigid and non-rigid motion correction with optional z-drift correction
52
+ - **ROI extraction**: CNMF-based and Suite2p-based cell detection and segmentation
53
+ - **Spike deconvolution**: Temporal activity inference from calcium signals
54
+ - **Parameter optimization**: Notebooks for systematic parameter exploration
55
+ - **Multi-session registration**: Cross-session ROI alignment using CaImAn's registration algorithm
56
+
57
+ ## Installation
58
+
59
+ ### Option 1: Install from GitHub (recommended)
60
+
61
+ ```bash
62
+ # Create and activate conda environment
63
+ conda create -n toupie python=3.10 -c conda-forge # Name the env any name you prefer
64
+ conda activate toupie
65
+ # Install optimouse
66
+ pip install git+https://github.com/vncntprvst/2P-proc.git
67
+ # Install CaImAn manager
68
+ caimanmanager install
69
+ ```
70
+
71
+ ### Option 2: Development install
72
+
73
+ ```bash
74
+ # Clone repository
75
+ git clone https://github.com/vncntprvst/2P-proc.git
76
+ cd 2P-proc
77
+
78
+ # Create and activate environment
79
+ conda create -n toupie python=3.10 -c conda-forge # Name the env any name you prefer
80
+ conda activate toupie
81
+ # Install in editable mode
82
+ pip install -e .
83
+ # Optional: install visualization
84
+ pip install -e ".[viz]"
85
+ # Install CaImAn manager
86
+ caimanmanager install
87
+ ```
88
+
89
+ ### Additional dependencies
90
+
91
+ For z-correction:
92
+ ```bash
93
+ conda install -c conda-forge mkl mkl_fft
94
+ pip install suite2p
95
+ ```
96
+
97
+ For visualization:
98
+ ```bash
99
+ pip install "fastplotlib[notebook]"
100
+ pip install plotly
101
+ ```
102
+
103
+ ## Quick Start
104
+
105
+ ### 1. Configure your pipeline
106
+
107
+ Create a configuration JSON based on `pipeline/configs/config_template_cnmf.json` or `pipeline/configs/config_template_suite2p.json`.
108
+
109
+ **CNMF-based extraction** (`config_template_cnmf.json`):
110
+ ```json
111
+ {
112
+ "experimenter": "FirstName LastName",
113
+ "subject": {
114
+ "name": "SUBJECT_ID",
115
+ "sex": "M/F/U",
116
+ "genotype": "Strain or Genotype"
117
+ },
118
+ "imaging": {
119
+ "date": "SESSION_DATE",
120
+ "fr": 20,
121
+ "Npixel_x": 765,
122
+ "Npixel_y": 765,
123
+ "microns_per_pixel": 1.45
124
+ },
125
+ "paths": {
126
+ "data_paths": [
127
+ "DATA_ROOT/SUBJECT_ID/SESSION_DATE/TSeries-001"
128
+ ],
129
+ "export_paths": [
130
+ "EXPORT_ROOT/SUBJECT_ID/SESSION_DATE/cnmf"
131
+ ],
132
+ "zstack_paths": [
133
+ "DATA_ROOT/SUBJECT_ID/SESSION_DATE/ZSeries-004"
134
+ ]
135
+ },
136
+ "params_mcorr": {
137
+ "method": "caiman",
138
+ "main": {
139
+ "strides": [36, 36],
140
+ "overlaps": [24, 24],
141
+ "max_shifts": [12, 12],
142
+ "pw_rigid": true
143
+ },
144
+ "save_mcorr_movie": "tiff",
145
+ "z_motion_correction": {
146
+ "zstack_shift": {
147
+ "Ch": 2,
148
+ "Nz": 41
149
+ },
150
+ "non_rigid": false
151
+ }
152
+ },
153
+ "params_extraction": {
154
+ "method": "cnmf",
155
+ "main": {
156
+ "p": 0,
157
+ "K": 8,
158
+ "gSig": [5, 5],
159
+ "merge_thr": 0.8,
160
+ "min_SNR": 3.0,
161
+ "rval_thr": 0.85,
162
+ "use_cnn": true
163
+ }
164
+ },
165
+ "logging": {
166
+ "log_path": "EXPORT_ROOT/SUBJECT_ID",
167
+ "log_level": "INFO"
168
+ }
169
+ }
170
+ ```
171
+
172
+ **Suite2p-based extraction** (`config_template_suite2p.json`):
173
+ ```json
174
+ {
175
+ "experimenter": "FirstName LastName",
176
+ "subject": {
177
+ "name": "SUBJECT_ID",
178
+ "sex": "M/F/U"
179
+ },
180
+ "imaging": {
181
+ "date": "SESSION_DATE",
182
+ "fr": 20,
183
+ "Npixel_x": 765,
184
+ "Npixel_y": 765
185
+ },
186
+ "paths": {
187
+ "data_paths": [
188
+ "DATA_ROOT/SUBJECT_ID/SESSION_DATE/TSeries-001"
189
+ ],
190
+ "export_paths": [
191
+ "EXPORT_ROOT/SUBJECT_ID/SESSION_DATE/suite2p"
192
+ ],
193
+ "zstack_paths": [
194
+ "DATA_ROOT/SUBJECT_ID/SESSION_DATE/ZSeries-004"
195
+ ]
196
+ },
197
+ "params_mcorr": {
198
+ "method": "caiman",
199
+ "main": {
200
+ "strides": [36, 36],
201
+ "overlaps": [24, 24],
202
+ "max_shifts": [12, 12],
203
+ "pw_rigid": true
204
+ },
205
+ "save_mcorr_movie": "tiff"
206
+ },
207
+ "params_extraction": {
208
+ "method": "suite2p",
209
+ "main": {
210
+ "decay_time": 0.3
211
+ }
212
+ }
213
+ }
214
+ ```
215
+
216
+ ### 2. Run the pipeline
217
+
218
+ **On a local machine:**
219
+
220
+ ```bash
221
+ python pipeline/pipeline_mcorr.py configs/my_config.json
222
+ python pipeline/pipeline_cnmf.py configs/my_config.json
223
+ ```
224
+
225
+ **On a cluster with SLURM:**
226
+
227
+ ```bash
228
+ sbatch scripts/batch_2P_pipeline.sh configs/my_config.json
229
+ ```
230
+
231
+ ### 3. Multi-session registration
232
+
233
+ ```bash
234
+ python Caiman/multisession_registration.py --json configs/my_config.json
235
+ ```
236
+
237
+ ## Pipeline Components
238
+
239
+ ### Motion Correction
240
+ - Rigid and non-rigid motion correction using NoRMCorre algorithm
241
+ - Optional z-drift correction using anatomical z-stack
242
+ - Export to multiple formats (TIFF, memmap, HDF5)
243
+
244
+ ### ROI Extraction
245
+ - CNMF (CaImAn): Constrained non-negative matrix factorization with automatic component quality assessment
246
+ - Suite2p: Fast, correlation-based clustering and SVD-accelerated cell detection and extraction
247
+ - Both methods provide denoised fluorescence traces and deconvolved spikes
248
+
249
+ ### ROI Z-Correction
250
+ - Regress and subtract axial drift from ROI traces
251
+ - Compatible with both CaImAn and Suite2p outputs
252
+ - Preserves temporal dynamics while correcting for z-motion
253
+
254
+ ### Parameter Optimization
255
+ Jupyter notebooks in `Mesmerize/` for systematic parameter exploration:
256
+ - `optimize_mcorr_bruker.ipynb`: Motion correction parameters
257
+ - `optimize_cnmf_bruker.ipynb`: CNMF extraction parameters
258
+ - `pipeline_notebook_template.ipynb`: Complete pipeline template
259
+
260
+ ## Testing
261
+
262
+ ```bash
263
+ # Download test data (~1.2GB)
264
+ ./scripts/download_test_data.sh
265
+
266
+ # Run motion correction test
267
+ ./scripts/run_motion_correction_test.sh
268
+
269
+ # Run full test suite
270
+ pytest tests/
271
+ ```
272
+
273
+ ## Container Support
274
+
275
+ Docker/Singularity containers are available for cluster computing:
276
+ - `containers/2p_proc`: Main processing container with optimouse installed
277
+ - `containers/suite2p`: Suite2p-based extraction pipeline
278
+ - `containers/allenneuraldynamics`: Integration with AIND extraction capsule
279
+
280
+ Build and use containers:
281
+ ```bash
282
+ # Build container
283
+ cd containers/analysis_2p
284
+ docker build -t optimouse:latest .
285
+
286
+ # Run with Singularity
287
+ singularity exec containers/analysis-2p_latest.sif python pipeline/pipeline_mcorr.py config.json
288
+ ```
289
+
290
+ ## Documentation
291
+
292
+ - **Configuration**: See `pipeline/configs/config_template_cnmf.json` for all available parameters
293
+ - **API Reference**: Coming soon
294
+ - **Tutorials**: Jupyter notebooks in `Mesmerize/` and `Caiman/`
295
+
296
+ ## Post-Processing and Analysis
297
+
298
+ For post-processing analysis (behavior integration, population analysis, etc.), see the companion repository:
299
+ **[Analysis 2P](https://github.com/pseudomanu/Analysis_2P)** - Matlab-based analysis pipeline with DeepLabCut and Rastermap integration
300
+
301
+ ## Contributing
302
+
303
+ Contributions are welcome! Please:
304
+ 1. Fork the repository
305
+ 2. Create a feature branch
306
+ 3. Make your changes with tests
307
+ 4. Submit a pull request
308
+
309
+ ## Citation
310
+
311
+ If you use this software, please cite:
312
+ - CaImAn: Giovannucci et al. (2019) eLife
313
+ - Mesmerize: Kolar et al. (2019) Nature Communications
314
+
315
+ ## License
316
+
317
+ This project is licensed under the MIT License - see [LICENSE.md](LICENSE.md) for details.
318
+
319
+ ## Support
320
+
321
+ - **Issues**: [GitHub Issues](https://github.com/vncntprvst/2P-proc/issues)
@@ -0,0 +1,280 @@
1
+ # 2P-proc (optimouse)
2
+
3
+ [![Python Version](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/)
4
+ [![CaImAn Version](https://img.shields.io/badge/CaImAn-1.12.2+-green)](https://github.com/flatironinstitute/CaImAn)
5
+ ![License](https://img.shields.io/badge/license-MIT-red)
6
+
7
+ **2P-proc (optimouse)** is a 2-photon calcium imaging data processing pipeline built on [CaImAn](https://github.com/flatironinstitute/CaImAn/) and [Mesmerize](https://github.com/nel-lab/mesmerize-core/).
8
+
9
+ This package provides:
10
+ - **Motion correction**: Rigid and non-rigid motion correction with optional z-drift correction
11
+ - **ROI extraction**: CNMF-based and Suite2p-based cell detection and segmentation
12
+ - **Spike deconvolution**: Temporal activity inference from calcium signals
13
+ - **Parameter optimization**: Notebooks for systematic parameter exploration
14
+ - **Multi-session registration**: Cross-session ROI alignment using CaImAn's registration algorithm
15
+
16
+ ## Installation
17
+
18
+ ### Option 1: Install from GitHub (recommended)
19
+
20
+ ```bash
21
+ # Create and activate conda environment
22
+ conda create -n toupie python=3.10 -c conda-forge # Name the env any name you prefer
23
+ conda activate toupie
24
+ # Install optimouse
25
+ pip install git+https://github.com/vncntprvst/2P-proc.git
26
+ # Install CaImAn manager
27
+ caimanmanager install
28
+ ```
29
+
30
+ ### Option 2: Development install
31
+
32
+ ```bash
33
+ # Clone repository
34
+ git clone https://github.com/vncntprvst/2P-proc.git
35
+ cd 2P-proc
36
+
37
+ # Create and activate environment
38
+ conda create -n toupie python=3.10 -c conda-forge # Name the env any name you prefer
39
+ conda activate toupie
40
+ # Install in editable mode
41
+ pip install -e .
42
+ # Optional: install visualization
43
+ pip install -e ".[viz]"
44
+ # Install CaImAn manager
45
+ caimanmanager install
46
+ ```
47
+
48
+ ### Additional dependencies
49
+
50
+ For z-correction:
51
+ ```bash
52
+ conda install -c conda-forge mkl mkl_fft
53
+ pip install suite2p
54
+ ```
55
+
56
+ For visualization:
57
+ ```bash
58
+ pip install "fastplotlib[notebook]"
59
+ pip install plotly
60
+ ```
61
+
62
+ ## Quick Start
63
+
64
+ ### 1. Configure your pipeline
65
+
66
+ Create a configuration JSON based on `pipeline/configs/config_template_cnmf.json` or `pipeline/configs/config_template_suite2p.json`.
67
+
68
+ **CNMF-based extraction** (`config_template_cnmf.json`):
69
+ ```json
70
+ {
71
+ "experimenter": "FirstName LastName",
72
+ "subject": {
73
+ "name": "SUBJECT_ID",
74
+ "sex": "M/F/U",
75
+ "genotype": "Strain or Genotype"
76
+ },
77
+ "imaging": {
78
+ "date": "SESSION_DATE",
79
+ "fr": 20,
80
+ "Npixel_x": 765,
81
+ "Npixel_y": 765,
82
+ "microns_per_pixel": 1.45
83
+ },
84
+ "paths": {
85
+ "data_paths": [
86
+ "DATA_ROOT/SUBJECT_ID/SESSION_DATE/TSeries-001"
87
+ ],
88
+ "export_paths": [
89
+ "EXPORT_ROOT/SUBJECT_ID/SESSION_DATE/cnmf"
90
+ ],
91
+ "zstack_paths": [
92
+ "DATA_ROOT/SUBJECT_ID/SESSION_DATE/ZSeries-004"
93
+ ]
94
+ },
95
+ "params_mcorr": {
96
+ "method": "caiman",
97
+ "main": {
98
+ "strides": [36, 36],
99
+ "overlaps": [24, 24],
100
+ "max_shifts": [12, 12],
101
+ "pw_rigid": true
102
+ },
103
+ "save_mcorr_movie": "tiff",
104
+ "z_motion_correction": {
105
+ "zstack_shift": {
106
+ "Ch": 2,
107
+ "Nz": 41
108
+ },
109
+ "non_rigid": false
110
+ }
111
+ },
112
+ "params_extraction": {
113
+ "method": "cnmf",
114
+ "main": {
115
+ "p": 0,
116
+ "K": 8,
117
+ "gSig": [5, 5],
118
+ "merge_thr": 0.8,
119
+ "min_SNR": 3.0,
120
+ "rval_thr": 0.85,
121
+ "use_cnn": true
122
+ }
123
+ },
124
+ "logging": {
125
+ "log_path": "EXPORT_ROOT/SUBJECT_ID",
126
+ "log_level": "INFO"
127
+ }
128
+ }
129
+ ```
130
+
131
+ **Suite2p-based extraction** (`config_template_suite2p.json`):
132
+ ```json
133
+ {
134
+ "experimenter": "FirstName LastName",
135
+ "subject": {
136
+ "name": "SUBJECT_ID",
137
+ "sex": "M/F/U"
138
+ },
139
+ "imaging": {
140
+ "date": "SESSION_DATE",
141
+ "fr": 20,
142
+ "Npixel_x": 765,
143
+ "Npixel_y": 765
144
+ },
145
+ "paths": {
146
+ "data_paths": [
147
+ "DATA_ROOT/SUBJECT_ID/SESSION_DATE/TSeries-001"
148
+ ],
149
+ "export_paths": [
150
+ "EXPORT_ROOT/SUBJECT_ID/SESSION_DATE/suite2p"
151
+ ],
152
+ "zstack_paths": [
153
+ "DATA_ROOT/SUBJECT_ID/SESSION_DATE/ZSeries-004"
154
+ ]
155
+ },
156
+ "params_mcorr": {
157
+ "method": "caiman",
158
+ "main": {
159
+ "strides": [36, 36],
160
+ "overlaps": [24, 24],
161
+ "max_shifts": [12, 12],
162
+ "pw_rigid": true
163
+ },
164
+ "save_mcorr_movie": "tiff"
165
+ },
166
+ "params_extraction": {
167
+ "method": "suite2p",
168
+ "main": {
169
+ "decay_time": 0.3
170
+ }
171
+ }
172
+ }
173
+ ```
174
+
175
+ ### 2. Run the pipeline
176
+
177
+ **On a local machine:**
178
+
179
+ ```bash
180
+ python pipeline/pipeline_mcorr.py configs/my_config.json
181
+ python pipeline/pipeline_cnmf.py configs/my_config.json
182
+ ```
183
+
184
+ **On a cluster with SLURM:**
185
+
186
+ ```bash
187
+ sbatch scripts/batch_2P_pipeline.sh configs/my_config.json
188
+ ```
189
+
190
+ ### 3. Multi-session registration
191
+
192
+ ```bash
193
+ python Caiman/multisession_registration.py --json configs/my_config.json
194
+ ```
195
+
196
+ ## Pipeline Components
197
+
198
+ ### Motion Correction
199
+ - Rigid and non-rigid motion correction using NoRMCorre algorithm
200
+ - Optional z-drift correction using anatomical z-stack
201
+ - Export to multiple formats (TIFF, memmap, HDF5)
202
+
203
+ ### ROI Extraction
204
+ - CNMF (CaImAn): Constrained non-negative matrix factorization with automatic component quality assessment
205
+ - Suite2p: Fast, correlation-based clustering and SVD-accelerated cell detection and extraction
206
+ - Both methods provide denoised fluorescence traces and deconvolved spikes
207
+
208
+ ### ROI Z-Correction
209
+ - Regress and subtract axial drift from ROI traces
210
+ - Compatible with both CaImAn and Suite2p outputs
211
+ - Preserves temporal dynamics while correcting for z-motion
212
+
213
+ ### Parameter Optimization
214
+ Jupyter notebooks in `Mesmerize/` for systematic parameter exploration:
215
+ - `optimize_mcorr_bruker.ipynb`: Motion correction parameters
216
+ - `optimize_cnmf_bruker.ipynb`: CNMF extraction parameters
217
+ - `pipeline_notebook_template.ipynb`: Complete pipeline template
218
+
219
+ ## Testing
220
+
221
+ ```bash
222
+ # Download test data (~1.2GB)
223
+ ./scripts/download_test_data.sh
224
+
225
+ # Run motion correction test
226
+ ./scripts/run_motion_correction_test.sh
227
+
228
+ # Run full test suite
229
+ pytest tests/
230
+ ```
231
+
232
+ ## Container Support
233
+
234
+ Docker/Singularity containers are available for cluster computing:
235
+ - `containers/2p_proc`: Main processing container with optimouse installed
236
+ - `containers/suite2p`: Suite2p-based extraction pipeline
237
+ - `containers/allenneuraldynamics`: Integration with AIND extraction capsule
238
+
239
+ Build and use containers:
240
+ ```bash
241
+ # Build container
242
+ cd containers/analysis_2p
243
+ docker build -t optimouse:latest .
244
+
245
+ # Run with Singularity
246
+ singularity exec containers/analysis-2p_latest.sif python pipeline/pipeline_mcorr.py config.json
247
+ ```
248
+
249
+ ## Documentation
250
+
251
+ - **Configuration**: See `pipeline/configs/config_template_cnmf.json` for all available parameters
252
+ - **API Reference**: Coming soon
253
+ - **Tutorials**: Jupyter notebooks in `Mesmerize/` and `Caiman/`
254
+
255
+ ## Post-Processing and Analysis
256
+
257
+ For post-processing analysis (behavior integration, population analysis, etc.), see the companion repository:
258
+ **[Analysis 2P](https://github.com/pseudomanu/Analysis_2P)** - Matlab-based analysis pipeline with DeepLabCut and Rastermap integration
259
+
260
+ ## Contributing
261
+
262
+ Contributions are welcome! Please:
263
+ 1. Fork the repository
264
+ 2. Create a feature branch
265
+ 3. Make your changes with tests
266
+ 4. Submit a pull request
267
+
268
+ ## Citation
269
+
270
+ If you use this software, please cite:
271
+ - CaImAn: Giovannucci et al. (2019) eLife
272
+ - Mesmerize: Kolar et al. (2019) Nature Communications
273
+
274
+ ## License
275
+
276
+ This project is licensed under the MIT License - see [LICENSE.md](LICENSE.md) for details.
277
+
278
+ ## Support
279
+
280
+ - **Issues**: [GitHub Issues](https://github.com/vncntprvst/2P-proc/issues)
@@ -0,0 +1,21 @@
1
+ """
2
+ Analysis 2P Pipeline modules
3
+
4
+ This package contains core modules for the Analysis 2P pipeline:
5
+ - bruker_concat_tif: Functions to concatenate Bruker microscopy files
6
+ - motion_correction: Complete motion correction workflow
7
+ - compute_zcorr: Functions for Z-motion correction
8
+ - extraction: Functions for extracting ROIs and traces from 2P data
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ # Version information
14
+ __version__ = "1.1.0"
15
+ __author__ = "Manuel Levy, Vincent Prevosto"
16
+
17
+ # Import core modules
18
+ from . import bruker_concat_tif
19
+ from . import compute_zcorr
20
+ from . import motion_correction
21
+ from . import extraction