optimouse 0.1.0__py3-none-any.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.
- modules/__init__.py +21 -0
- modules/bruker_concat_tif.py +650 -0
- modules/compute_zcorr.py +2040 -0
- modules/extraction.py +559 -0
- modules/motion_correction.py +982 -0
- modules/utils/plot_zones.py +125 -0
- modules/utils/save_z_motion_args.py +93 -0
- optimouse-0.1.0.dist-info/METADATA +321 -0
- optimouse-0.1.0.dist-info/RECORD +24 -0
- optimouse-0.1.0.dist-info/WHEEL +5 -0
- optimouse-0.1.0.dist-info/licenses/LICENSE.md +21 -0
- optimouse-0.1.0.dist-info/top_level.txt +2 -0
- pipeline/__init__.py +0 -0
- pipeline/configs/config_C57_O1M2_10022023_run1run2.json +107 -0
- pipeline/configs/config_C57_O1M2_10022023_run1run2run3run4.json +114 -0
- pipeline/configs/config_template_cnmf.json +123 -0
- pipeline/configs/config_template_suite2p.json +102 -0
- pipeline/configs/config_test.json +114 -0
- pipeline/pipeline_cnmf.py +263 -0
- pipeline/pipeline_mcorr.py +299 -0
- pipeline/roi_zcorr.py +65 -0
- pipeline/utils/__init__.py +0 -0
- pipeline/utils/config_loader.py +92 -0
- pipeline/utils/pipeline_utils.py +537 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"""Plotting functions for visualizing zone patterns and labeled zones.
|
|
2
|
+
|
|
3
|
+
Example usage:
|
|
4
|
+
plot_labeled_and_zone_patterns(labeled_zones, zone_pattern, export_path='/home/wanglab/data/2P/Analysis/Scnn1aAi14_B2M0/04222024/run1run2/test_modules')
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
import matplotlib.pyplot as plt
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
def plot_zone_pattern(zone_pattern, zone_pattern_contig, export_path=None):
|
|
13
|
+
"""
|
|
14
|
+
Create visualization of the patch zones and their continuity.
|
|
15
|
+
|
|
16
|
+
Parameters:
|
|
17
|
+
-----------
|
|
18
|
+
zone_pattern : numpy.ndarray
|
|
19
|
+
2D array containing the zone pattern with non-contiguous unique zone IDs
|
|
20
|
+
zone_pattern_contig : numpy.ndarray
|
|
21
|
+
2D array containing the zone pattern with continuous zone IDs
|
|
22
|
+
export_path : str or pathlib.Path, optional
|
|
23
|
+
Path where to save the figure. If None, figure will be displayed but not saved.
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
--------
|
|
27
|
+
fig : matplotlib.figure.Figure
|
|
28
|
+
The figure object containing the plots
|
|
29
|
+
"""
|
|
30
|
+
# Create figure with two subplots
|
|
31
|
+
fig, axes = plt.subplots(1, 2, figsize=(12, 6))
|
|
32
|
+
|
|
33
|
+
# Plot original zone pattern
|
|
34
|
+
unique_zones = len(np.unique(zone_pattern)) - 1 # Subtract 1 for background (0)
|
|
35
|
+
cmap = plt.cm.get_cmap('plasma', unique_zones)
|
|
36
|
+
im0 = axes[0].imshow(zone_pattern, cmap=cmap)
|
|
37
|
+
axes[0].set_title(f'Original Zone Pattern\n({unique_zones} unique zones)')
|
|
38
|
+
axes[0].set_xticks([])
|
|
39
|
+
axes[0].set_yticks([])
|
|
40
|
+
|
|
41
|
+
# Plot continuous zone pattern
|
|
42
|
+
unique_contig = len(np.unique(zone_pattern_contig)) - 1 # Subtract 1 for background (0)
|
|
43
|
+
cmap = plt.cm.get_cmap('viridis', unique_contig)
|
|
44
|
+
im1 = axes[1].imshow(zone_pattern_contig, cmap=cmap)
|
|
45
|
+
axes[1].set_title(f'Continuous Zone Pattern\n({unique_contig} zones)')
|
|
46
|
+
axes[1].set_xticks([])
|
|
47
|
+
axes[1].set_yticks([])
|
|
48
|
+
|
|
49
|
+
# Add colorbars
|
|
50
|
+
cbar0 = fig.colorbar(im0, ax=axes[0], fraction=0.046, pad=0.04)
|
|
51
|
+
cbar0.set_label('Zone ID (non-contiguous)')
|
|
52
|
+
cbar1 = fig.colorbar(im1, ax=axes[1], fraction=0.046, pad=0.04)
|
|
53
|
+
cbar1.set_label('Zone ID (contiguous)')
|
|
54
|
+
|
|
55
|
+
plt.tight_layout()
|
|
56
|
+
|
|
57
|
+
# Save figure if export_path is provided
|
|
58
|
+
if export_path is not None:
|
|
59
|
+
# Convert string path to Path object if needed
|
|
60
|
+
export_path = Path(export_path)
|
|
61
|
+
|
|
62
|
+
# Ensure plot directory exists
|
|
63
|
+
plot_dir = export_path / 'plots'
|
|
64
|
+
plot_dir.mkdir(parents=True, exist_ok=True)
|
|
65
|
+
|
|
66
|
+
# Save the figure
|
|
67
|
+
fig_path = plot_dir / 'zone_patterns.png'
|
|
68
|
+
fig.savefig(fig_path, dpi=150, bbox_inches='tight')
|
|
69
|
+
print(f"Zone pattern figure saved to {fig_path}")
|
|
70
|
+
|
|
71
|
+
return fig
|
|
72
|
+
|
|
73
|
+
def plot_labeled_and_zone_patterns(labeled_zones, zone_pattern, export_path=None):
|
|
74
|
+
"""
|
|
75
|
+
Plot labeled_zones and zone_pattern side by side for comparison.
|
|
76
|
+
|
|
77
|
+
Parameters:
|
|
78
|
+
-----------
|
|
79
|
+
labeled_zones : numpy.ndarray
|
|
80
|
+
2D array containing the labeled zones.
|
|
81
|
+
zone_pattern : numpy.ndarray
|
|
82
|
+
2D array containing the zone pattern.
|
|
83
|
+
export_path : str or pathlib.Path, optional
|
|
84
|
+
Path where to save the figure. If None, the figure will be displayed but not saved.
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
--------
|
|
88
|
+
fig : matplotlib.figure.Figure
|
|
89
|
+
The figure object containing the plots.
|
|
90
|
+
"""
|
|
91
|
+
# Create figure with two subplots
|
|
92
|
+
fig, axes = plt.subplots(1, 2, figsize=(12, 6))
|
|
93
|
+
|
|
94
|
+
# Plot labeled_zones
|
|
95
|
+
unique_labeled_zones = len(np.unique(labeled_zones)) - 1 # Subtract 1 for background (0)
|
|
96
|
+
cmap_labeled = plt.cm.get_cmap('tab20', unique_labeled_zones)
|
|
97
|
+
im0 = axes[0].imshow(labeled_zones, cmap=cmap_labeled)
|
|
98
|
+
axes[0].set_title(f'Labeled Zones\n({unique_labeled_zones} unique zones)')
|
|
99
|
+
axes[0].set_xticks([])
|
|
100
|
+
axes[0].set_yticks([])
|
|
101
|
+
cbar0 = fig.colorbar(im0, ax=axes[0], fraction=0.046, pad=0.04)
|
|
102
|
+
cbar0.set_label('Zone ID')
|
|
103
|
+
|
|
104
|
+
# Plot zone_pattern
|
|
105
|
+
unique_zone_pattern = len(np.unique(zone_pattern)) - 1 # Subtract 1 for background (0)
|
|
106
|
+
cmap_zone = plt.cm.get_cmap('viridis', unique_zone_pattern)
|
|
107
|
+
im1 = axes[1].imshow(zone_pattern, cmap=cmap_zone)
|
|
108
|
+
axes[1].set_title(f'Zone Pattern\n({unique_zone_pattern} unique zones)')
|
|
109
|
+
axes[1].set_xticks([])
|
|
110
|
+
axes[1].set_yticks([])
|
|
111
|
+
cbar1 = fig.colorbar(im1, ax=axes[1], fraction=0.046, pad=0.04)
|
|
112
|
+
cbar1.set_label('Zone ID')
|
|
113
|
+
|
|
114
|
+
plt.tight_layout()
|
|
115
|
+
|
|
116
|
+
# Save figure if export_path is provided
|
|
117
|
+
if export_path is not None:
|
|
118
|
+
export_path = Path(export_path)
|
|
119
|
+
plot_dir = export_path / 'plots'
|
|
120
|
+
plot_dir.mkdir(parents=True, exist_ok=True)
|
|
121
|
+
fig_path = plot_dir / 'labeled_and_zone_patterns.png'
|
|
122
|
+
fig.savefig(fig_path, dpi=150, bbox_inches='tight')
|
|
123
|
+
print(f"Labeled and zone patterns figure saved to {fig_path}")
|
|
124
|
+
|
|
125
|
+
return fig
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# To run before call
|
|
2
|
+
# zcorr_movie, z_motion_scaling_factors = subtract_z_motion_patches(
|
|
3
|
+
# mcorr_movie_path,
|
|
4
|
+
# zstack_path / z_shifted_file,
|
|
5
|
+
# z_correlation,
|
|
6
|
+
# parameters['params_mcorr']['main'],
|
|
7
|
+
# subtract_method,
|
|
8
|
+
# True
|
|
9
|
+
# )
|
|
10
|
+
|
|
11
|
+
import datetime
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
def save_z_motion_args(mesmerize_path, args_dict):
|
|
15
|
+
"""
|
|
16
|
+
Save z-motion correction arguments to JSON for reproducibility.
|
|
17
|
+
|
|
18
|
+
This function serializes both the paths and parameters used for z-motion
|
|
19
|
+
correction, as well as summary information about array shapes and key
|
|
20
|
+
statistics from z_correlation data.
|
|
21
|
+
|
|
22
|
+
Parameters:
|
|
23
|
+
-----------
|
|
24
|
+
mesmerize_path : pathlib.Path
|
|
25
|
+
Directory where arguments should be saved
|
|
26
|
+
args_dict : dict
|
|
27
|
+
Dictionary containing the z-motion arguments
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
--------
|
|
31
|
+
pathlib.Path
|
|
32
|
+
Path to the saved arguments file
|
|
33
|
+
"""
|
|
34
|
+
import json
|
|
35
|
+
import datetime
|
|
36
|
+
import numpy as np
|
|
37
|
+
|
|
38
|
+
# Create output directory if it doesn't exist
|
|
39
|
+
mesmerize_path.mkdir(parents=True, exist_ok=True)
|
|
40
|
+
|
|
41
|
+
# Generate a timestamp for the filename
|
|
42
|
+
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
43
|
+
args_path = mesmerize_path / f"z_motion_args_{timestamp}.json"
|
|
44
|
+
|
|
45
|
+
# Process z_correlation data to make it serializable
|
|
46
|
+
if 'z_correlation' in args_dict:
|
|
47
|
+
z_corr_info = {}
|
|
48
|
+
for key in args_dict['z_correlation'].keys():
|
|
49
|
+
array = args_dict['z_correlation'][key]
|
|
50
|
+
z_corr_info[key] = {
|
|
51
|
+
'shape': list(array.shape),
|
|
52
|
+
'dtype': str(array.dtype),
|
|
53
|
+
'min': float(array.min()),
|
|
54
|
+
'max': float(array.max()),
|
|
55
|
+
'mean': float(array.mean()),
|
|
56
|
+
'std': float(array.std()),
|
|
57
|
+
# Include 10 sample values (safely serializable)
|
|
58
|
+
'samples': array.flat[:10].tolist()
|
|
59
|
+
}
|
|
60
|
+
# Replace z_correlation with its info
|
|
61
|
+
args_dict['z_correlation'] = z_corr_info
|
|
62
|
+
|
|
63
|
+
# Convert paths to strings and handle other non-serializable objects
|
|
64
|
+
serializable_args = {}
|
|
65
|
+
for key, value in args_dict.items():
|
|
66
|
+
if hasattr(value, 'resolve'): # Path object
|
|
67
|
+
serializable_args[key] = str(value)
|
|
68
|
+
elif isinstance(value, np.ndarray):
|
|
69
|
+
serializable_args[key] = f"Array with shape {value.shape}, dtype {value.dtype}"
|
|
70
|
+
else:
|
|
71
|
+
serializable_args[key] = value
|
|
72
|
+
|
|
73
|
+
# Save the serializable args to JSON file
|
|
74
|
+
with open(args_path, 'w') as f:
|
|
75
|
+
json.dump(serializable_args, f, indent=4)
|
|
76
|
+
|
|
77
|
+
print(f"Z-motion arguments saved to: {args_path}")
|
|
78
|
+
return args_path
|
|
79
|
+
|
|
80
|
+
# Prepare the arguments dictionary for saving
|
|
81
|
+
z_motion_args = {
|
|
82
|
+
'mcorr_movie_path': mcorr_movie_path,
|
|
83
|
+
'zstack_file': zstack_path / z_shifted_file,
|
|
84
|
+
'z_correlation_keys': list(z_correlation.keys()),
|
|
85
|
+
'z_correlation': {k: z_correlation[k] for k in ['zcorr', 'zpos']},
|
|
86
|
+
'mcorr_params': parameters['params_mcorr']['main'],
|
|
87
|
+
'subtract_method': subtract_method,
|
|
88
|
+
'save_tiffs': True,
|
|
89
|
+
'timestamp': datetime.datetime.now().isoformat()
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
# Save the arguments
|
|
93
|
+
save_z_motion_args(mesmerize_path, z_motion_args)
|
|
@@ -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
|
+
[](https://www.python.org/)
|
|
45
|
+
[](https://github.com/flatironinstitute/CaImAn)
|
|
46
|
+

|
|
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,24 @@
|
|
|
1
|
+
modules/__init__.py,sha256=sveLDniGAD4S-_77nq5eU6l9iaqWzTgBbJ0z7WGWoKU,617
|
|
2
|
+
modules/bruker_concat_tif.py,sha256=zPGNTMltEp0ezl_bRq8AUAXIVf0QnTl4lrRogn5-sJY,27670
|
|
3
|
+
modules/compute_zcorr.py,sha256=w8MENeZenSkEFe3XEHfHfI2yJIOeTkdxRfuKKG3Lx4A,90743
|
|
4
|
+
modules/extraction.py,sha256=YFOw6rzFw-DsBxtYNAnId7ptiWoow6KrbWGD5SoHv3o,20417
|
|
5
|
+
modules/motion_correction.py,sha256=e9J5x_td9_YYXeykFfPpWZfj4xj90J_hqv86ak38cEQ,40168
|
|
6
|
+
modules/utils/plot_zones.py,sha256=tS5CJGYFG1QupIEb2W8KdyCvITP_FmHkTsWXeN33vlM,4720
|
|
7
|
+
modules/utils/save_z_motion_args.py,sha256=N7CrkjCB5pnzHwUWp2fuUgCaoBkLlA4R68EQGIESt3o,3207
|
|
8
|
+
optimouse-0.1.0.dist-info/licenses/LICENSE.md,sha256=SMxbzVx-P2rZW75lRWfz4KzkunJPibGQoTaiGj08XCo,1086
|
|
9
|
+
pipeline/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
pipeline/pipeline_cnmf.py,sha256=Kepm7u2hk2PoeENuVoWNhRyFrnV5UVjk7QV8tz7LWOQ,8738
|
|
11
|
+
pipeline/pipeline_mcorr.py,sha256=Nhit1eq2ZAkZt5BULkffnYUQuDmn-OaeCOyM9W79-Z4,10374
|
|
12
|
+
pipeline/roi_zcorr.py,sha256=5d00fM02cRN8AqdL54nMmFRkku-OODzkyb_rgX4s0_U,1962
|
|
13
|
+
pipeline/configs/config_C57_O1M2_10022023_run1run2.json,sha256=4n3Jh2ITRpiUG6MDtZt1gS56wxBJEfYUhej0pauvTmQ,2710
|
|
14
|
+
pipeline/configs/config_C57_O1M2_10022023_run1run2run3run4.json,sha256=2Dfnk42CGw6aIMieraSGS4gYW05Q2wmEZF9kee42m68,3153
|
|
15
|
+
pipeline/configs/config_template_cnmf.json,sha256=IjS2tFae8CvrUdlVyc72tPCzLm_qRdp2_Aah1rH9QRU,3772
|
|
16
|
+
pipeline/configs/config_template_suite2p.json,sha256=h3R4Y2Oohv3PqnvISj2l1W__0JkX5FQr_Y0kw0EcyU4,3239
|
|
17
|
+
pipeline/configs/config_test.json,sha256=D06TS51KV8fQp-Snekoks1BqXa1wON_IDRGUu35ABHU,2892
|
|
18
|
+
pipeline/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
|
+
pipeline/utils/config_loader.py,sha256=ILCL17SXI1cwoylInNzyrxznqaICtodtyxVqQV6xUeQ,3136
|
|
20
|
+
pipeline/utils/pipeline_utils.py,sha256=mN_ibhWlSSl1T3rqC9xwPc5a3HcsedwYeMZAL6r5KwE,20271
|
|
21
|
+
optimouse-0.1.0.dist-info/METADATA,sha256=j4vXKMWdT6z-3ELOPBAtFWO8NLjuKRh75BjdLgf84fo,9073
|
|
22
|
+
optimouse-0.1.0.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
|
|
23
|
+
optimouse-0.1.0.dist-info/top_level.txt,sha256=mT1ik7DiKUOvy9HS7a7KnD7L8ywdXQgaFCD3Ha5uvCM,17
|
|
24
|
+
optimouse-0.1.0.dist-info/RECORD,,
|
|
@@ -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.
|
pipeline/__init__.py
ADDED
|
File without changes
|