sl-shared-assets 1.0.0rc1__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.
Potentially problematic release.
This version of sl-shared-assets might be problematic. Click here for more details.
- sl_shared_assets/__init__.py +96 -0
- sl_shared_assets/__init__.pyi +87 -0
- sl_shared_assets/cli.py +72 -0
- sl_shared_assets/cli.pyi +17 -0
- sl_shared_assets/data_classes.py +1435 -0
- sl_shared_assets/data_classes.pyi +646 -0
- sl_shared_assets/packaging_tools.py +133 -0
- sl_shared_assets/packaging_tools.pyi +52 -0
- sl_shared_assets/py.typed +0 -0
- sl_shared_assets/server.py +293 -0
- sl_shared_assets/server.pyi +112 -0
- sl_shared_assets/suite2p.py +449 -0
- sl_shared_assets/suite2p.pyi +188 -0
- sl_shared_assets/transfer_tools.py +119 -0
- sl_shared_assets/transfer_tools.pyi +53 -0
- sl_shared_assets-1.0.0rc1.dist-info/METADATA +849 -0
- sl_shared_assets-1.0.0rc1.dist-info/RECORD +20 -0
- sl_shared_assets-1.0.0rc1.dist-info/WHEEL +4 -0
- sl_shared_assets-1.0.0rc1.dist-info/entry_points.txt +3 -0
- sl_shared_assets-1.0.0rc1.dist-info/licenses/LICENSE +674 -0
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
"""This module provides the classes used to store suite2p runtime configuration parameters in .YAML files. This is used
|
|
2
|
+
by the sl-forgery library to configure mesoscope data processing via the suite2p library, both during single-day and
|
|
3
|
+
multiday registration processing."""
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
from dataclasses import field, asdict, dataclass
|
|
7
|
+
|
|
8
|
+
from ataraxis_data_structures import YamlConfig
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class Main:
|
|
13
|
+
"""Stores global settings used to broadly define the suite2p processing configuration."""
|
|
14
|
+
|
|
15
|
+
nplanes: int = 3
|
|
16
|
+
"""The number of imaging planes in each TIFF file sequence. For Mesoscope frames, this is the number of individual
|
|
17
|
+
ROI boxes drawn over the cranial window."""
|
|
18
|
+
|
|
19
|
+
nchannels: int = 1
|
|
20
|
+
"""The number of channels per imaging plane. Typically this is either 1 or 2."""
|
|
21
|
+
|
|
22
|
+
functional_chan: int = 1
|
|
23
|
+
"""The channel used for extracting functional ROIs (uses 1-based indexing, e.g., 1 means the first channel)."""
|
|
24
|
+
|
|
25
|
+
tau: float = 0.4
|
|
26
|
+
"""The timescale of the sensor, in seconds, used for computing the deconvolution kernel. The kernel is fixed to
|
|
27
|
+
have this decay and is not fit to the data. Note, the default value was optimized for GCamp6f animals used in
|
|
28
|
+
Weinan's OSM Manuscript."""
|
|
29
|
+
|
|
30
|
+
force_sktiff: bool = True
|
|
31
|
+
"""Determines whether to force the use of scikit-image for reading TIFF files. This HAS to be true for our tiff
|
|
32
|
+
files, as they are compressed in a way that cannot be read with ScanImage tiff reader."""
|
|
33
|
+
|
|
34
|
+
fs: float = 10.0014
|
|
35
|
+
"""The sampling rate per plane in Hertz. This is automatically overwritten using ops.json file generated by our
|
|
36
|
+
preprocessing pipeline to match the specific acquisition frequency of the processed dataset."""
|
|
37
|
+
|
|
38
|
+
do_bidiphase: bool = False
|
|
39
|
+
"""Determines whether to perform computation of bidirectional phase offset for misaligned line scanning
|
|
40
|
+
(applies to two-photon recordings only). The suite2p estimates the bidirectional phase offset from
|
|
41
|
+
‘nimg_init’ frames if this is set to 1 (and ‘bidiphase’ to 0), and then applies this computed offset to all
|
|
42
|
+
frames."""
|
|
43
|
+
|
|
44
|
+
bidiphase: int = 0
|
|
45
|
+
"""The user-specified bidirectional phase offset for line scanning experiments. If set to any value besides 0, then
|
|
46
|
+
this offset is used and applied to all frames in the recording."""
|
|
47
|
+
|
|
48
|
+
bidi_corrected: bool = False
|
|
49
|
+
"""Indicates whether bidirectional phase correction has been applied tot he registered dataset."""
|
|
50
|
+
|
|
51
|
+
frames_include: int = -1
|
|
52
|
+
"""Determines the number of frames to process, if greater than zero. If negative (-1), the suite2p is configured
|
|
53
|
+
to process all available frames."""
|
|
54
|
+
|
|
55
|
+
multiplane_parallel: bool = False
|
|
56
|
+
"""Determines whether to parallelize plane processing for multiplane data. This requires a properly configured
|
|
57
|
+
server to parallelize the computations and will not work on the local machine. Due to how suite2p is used in the
|
|
58
|
+
lab, this has to always be set to False."""
|
|
59
|
+
|
|
60
|
+
ignore_flyback: list[int] = field(default_factory=list)
|
|
61
|
+
"""The list of plane indices to ignore as flyback planes that typically contain no valid imaging data."""
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@dataclass
|
|
65
|
+
class FileIO:
|
|
66
|
+
"""Stores I/O settings used to specify input data file locations, formats, and output storage options."""
|
|
67
|
+
|
|
68
|
+
fast_disk: list[str] = field(default_factory=list)
|
|
69
|
+
"""Specifies the locations where to store the temporary binary files created during processing. If no directories
|
|
70
|
+
are provided here, 'save_path0' is used to store the temporary files."""
|
|
71
|
+
|
|
72
|
+
delete_bin: bool = False
|
|
73
|
+
"""Determines whether to delete the binary file created during the cell registration stage (registered cells .bin
|
|
74
|
+
file). Since registered cell binaries are used by multi-day registration extension, this need to be False for all
|
|
75
|
+
lab recordings."""
|
|
76
|
+
|
|
77
|
+
mesoscan: bool = True
|
|
78
|
+
"""Indicates whether the input file is a ScanImage Mesoscope recording. For our data, this is always True and all
|
|
79
|
+
other formats are False."""
|
|
80
|
+
|
|
81
|
+
bruker: bool = False
|
|
82
|
+
"""Indicates whether the provided TIFF files are single-page BRUKER TIFFs."""
|
|
83
|
+
|
|
84
|
+
bruker_bidirectional: bool = False
|
|
85
|
+
"""Specifies whether BRUKER files are bidirectional multiplane recordings."""
|
|
86
|
+
|
|
87
|
+
h5py: list[str] = field(default_factory=list)
|
|
88
|
+
"""The list of paths to h5py files that will be used as inputs. If provided, these paths overwrite the 'data_path'
|
|
89
|
+
field."""
|
|
90
|
+
|
|
91
|
+
h5py_key: str = "data"
|
|
92
|
+
"""The key used to access the data array in an h5py file. This should only be provided if 'h5py' is not set to
|
|
93
|
+
an empty list."""
|
|
94
|
+
|
|
95
|
+
nwb_file: str = ""
|
|
96
|
+
"""Specifies the path to the NWB file to use as an input."""
|
|
97
|
+
|
|
98
|
+
nwb_driver: str = ""
|
|
99
|
+
"""The location or name of the driver for reading the NWB file."""
|
|
100
|
+
|
|
101
|
+
nwb_series: str = ""
|
|
102
|
+
"""The name of the TwoPhotonSeries in the NWB file to retrieve data from."""
|
|
103
|
+
|
|
104
|
+
save_path0: list[str] = field(default_factory=list)
|
|
105
|
+
"""Lists directory paths where the pipeline results should be saved. Typically, this is defined as a single-item
|
|
106
|
+
list that stores the path to the output folder used by the processed session's data."""
|
|
107
|
+
|
|
108
|
+
save_folder: list[str] = field(default_factory=list)
|
|
109
|
+
"""Lists folder names under which the results should be stored. If this is not provided, the pipeline defaults to
|
|
110
|
+
using 'suite2p' as the root folder, created under the path specified by save_path0."""
|
|
111
|
+
|
|
112
|
+
look_one_level_down: bool = False
|
|
113
|
+
"""Determines whether to search for TIFF files in the subfolders when searching for Tiff files. If this is True,
|
|
114
|
+
the list of evaluated subfolders have to be defined via the 'subfolders' field."""
|
|
115
|
+
|
|
116
|
+
subfolders: list[str] = field(default_factory=list)
|
|
117
|
+
"""The list of specific subfolder names to search through for TIFF files."""
|
|
118
|
+
|
|
119
|
+
move_bin: bool = False
|
|
120
|
+
"""Determines whether to move the binary file to the save directory after processing, if 'fast_disk' differs from
|
|
121
|
+
the 'save_path0'."""
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@dataclass
|
|
125
|
+
class Output:
|
|
126
|
+
"""Stores I/O settings used to define the output format and organization of the processing results."""
|
|
127
|
+
|
|
128
|
+
preclassify: float = 0.5
|
|
129
|
+
"""The probability threshold for pre-classification of cells to use before signal extraction. If this is set to
|
|
130
|
+
0.0, then all detected ROIs are kept and signals are computed."""
|
|
131
|
+
|
|
132
|
+
save_nwb: bool = False
|
|
133
|
+
"""Determines whether to save the output as an NWB file."""
|
|
134
|
+
|
|
135
|
+
save_mat: bool = False
|
|
136
|
+
"""Determines whether to save the results in MATLAB format (e.g., Fall.mat)."""
|
|
137
|
+
|
|
138
|
+
combined: bool = True
|
|
139
|
+
"""Determines whether to combine results across planes into a separate 'combined' folder at the end of
|
|
140
|
+
processing."""
|
|
141
|
+
|
|
142
|
+
aspect: float = 0.666666666
|
|
143
|
+
"""The pixel-to-micron ratio (X:Y) for correctly displaying the image aspect ratio in the GUI (not used in headless
|
|
144
|
+
processing)."""
|
|
145
|
+
|
|
146
|
+
report_time: bool = False
|
|
147
|
+
"""Determines whether to return a dictionary reporting the processing time for each plane."""
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
@dataclass
|
|
151
|
+
class Registration:
|
|
152
|
+
"""Stores rigid registration settings used for correcting motion artifacts between frames."""
|
|
153
|
+
|
|
154
|
+
do_registration: bool = True
|
|
155
|
+
"""Determines whether to run the motion registration."""
|
|
156
|
+
|
|
157
|
+
align_by_chan: int = 1
|
|
158
|
+
"""The channel to use for alignment (uses 1-based indexing, so 1 means 1st channel and 2 means 2nd channel). If the
|
|
159
|
+
recording features both a functional and non-functional channels, it may be better to use the non-functional
|
|
160
|
+
channel for this purpose."""
|
|
161
|
+
|
|
162
|
+
nimg_init: int = 500
|
|
163
|
+
"""The number of frames to use to compute the reference image for registration."""
|
|
164
|
+
|
|
165
|
+
batch_size: int = 1000
|
|
166
|
+
"""The number of frames to register simultaneously in each batch. This depends on memory constraints. It is faster
|
|
167
|
+
to run the registration if the batch is larger, but it requires more RAM."""
|
|
168
|
+
|
|
169
|
+
maxregshift: float = 0.1
|
|
170
|
+
"""The maximum allowed shift during registration, given as a fraction of the frame size, in pixels
|
|
171
|
+
(e.g., 0.1 indicates 10%)."""
|
|
172
|
+
|
|
173
|
+
smooth_sigma: float = 1.15
|
|
174
|
+
"""The standard deviation (in pixels) of the Gaussian used to smooth the phase correlation between the reference
|
|
175
|
+
image and the current frame."""
|
|
176
|
+
|
|
177
|
+
smooth_sigma_time: float = 0.0
|
|
178
|
+
"""The standard deviation (in frames) of the Gaussian used to temporally smooth the data before computing
|
|
179
|
+
phase correlation."""
|
|
180
|
+
|
|
181
|
+
keep_movie_raw: bool = False
|
|
182
|
+
"""Determines whether to keep the binary file of the raw (non-registered) frames. This is desirable when initially
|
|
183
|
+
configuring the suite2p parameters, as it allows visually comparing registered frames to non-registered frames in
|
|
184
|
+
the GUI. For well-calibrated runtime, it is advised to have this set to False."""
|
|
185
|
+
|
|
186
|
+
two_step_registration: bool = False
|
|
187
|
+
"""Determines whether to perform a two-step registration (initial registration followed by refinement registration).
|
|
188
|
+
This may be necessary for low signal-to-noise data. This requires 'keep_movie_raw' to be set to True."""
|
|
189
|
+
|
|
190
|
+
reg_tif: bool = False
|
|
191
|
+
"""Determines whether to write the registered binary data to TIFF files."""
|
|
192
|
+
|
|
193
|
+
reg_tif_chan2: bool = False
|
|
194
|
+
"""Determines whether to generate TIFF files for the registered non-functional (channel 2) data."""
|
|
195
|
+
|
|
196
|
+
subpixel: int = 10
|
|
197
|
+
"""The precision for the subpixel registration (1/subpixel steps)."""
|
|
198
|
+
|
|
199
|
+
th_badframes: float = 1.0
|
|
200
|
+
"""The threshold for excluding poor-quality frames when performing cropping. Setting this to a smaller value
|
|
201
|
+
excludes more frames."""
|
|
202
|
+
|
|
203
|
+
norm_frames: bool = True
|
|
204
|
+
"""Determines whether to normalize frames during shift detection to improve registration accuracy."""
|
|
205
|
+
|
|
206
|
+
force_refImg: bool = False
|
|
207
|
+
"""Determines whether to force the use of a pre-stored reference image for registration."""
|
|
208
|
+
|
|
209
|
+
pad_fft: bool = False
|
|
210
|
+
"""Determines whether to pad the image during the FFT portion of the registration to reduce edge effects."""
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
@dataclass
|
|
214
|
+
class OnePRegistration:
|
|
215
|
+
"""Stores additional pre-registration processing settings used to improve the registration of 1-photon datasets."""
|
|
216
|
+
|
|
217
|
+
one_p_reg: bool = False
|
|
218
|
+
"""Determines whether to perform high-pass spatial filtering and tapering to improve one-photon image
|
|
219
|
+
registration. For 2-photon datasets, this should be set to False."""
|
|
220
|
+
|
|
221
|
+
spatial_hp_reg: int = 42
|
|
222
|
+
"""The window size, in pixels, for spatial high-pass filtering performed before registration."""
|
|
223
|
+
|
|
224
|
+
pre_smooth: float = 0.0
|
|
225
|
+
"""The standard deviation for Gaussian smoothing applied before spatial high-pass filtering
|
|
226
|
+
(applied only if > 0)."""
|
|
227
|
+
|
|
228
|
+
spatial_taper: float = 40.0
|
|
229
|
+
"""The number of pixels to ignore at the image edges to reduce edge artifacts during registration."""
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
@dataclass
|
|
233
|
+
class NonRigid:
|
|
234
|
+
"""Stores non-rigid registration settings used to improve motion registration in complex datasets."""
|
|
235
|
+
|
|
236
|
+
nonrigid: bool = True
|
|
237
|
+
"""Determines whether to perform non-rigid registration to correct for local motion and deformation. This is used
|
|
238
|
+
for correcting non-uniform motion."""
|
|
239
|
+
|
|
240
|
+
block_size: list[int] = field(default_factory=lambda: [128, 128])
|
|
241
|
+
"""The block size, in pixels, for non-rigid registration, defining the dimensions of subregions used in
|
|
242
|
+
the correction. It is recommended to keep this size a power of 2 and / or 3 for more efficient FFT computation."""
|
|
243
|
+
|
|
244
|
+
snr_thresh: float = 1.2
|
|
245
|
+
"""The signal-to-noise ratio threshold. The phase correlation peak must be this many times higher than the
|
|
246
|
+
noise level for the algorithm to accept the block shift and apply it to the output dataset."""
|
|
247
|
+
|
|
248
|
+
maxregshiftNR: float = 5.0
|
|
249
|
+
"""The maximum allowed shift, in pixels, for each block relative to the rigid registration shift."""
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
@dataclass
|
|
253
|
+
class ROIDetection:
|
|
254
|
+
"""Stores ROI detection and extraction settings used to identify cells and their activity signals."""
|
|
255
|
+
|
|
256
|
+
roidetect: bool = True
|
|
257
|
+
"""Determines whether to perform ROI detection and subsequent signal extraction."""
|
|
258
|
+
|
|
259
|
+
sparse_mode: bool = True
|
|
260
|
+
"""Determines whether to use the sparse mode for cell detection, which is well-suited for data with sparse
|
|
261
|
+
signals."""
|
|
262
|
+
|
|
263
|
+
spatial_scale: int = 0
|
|
264
|
+
"""The optimal spatial scale, in pixels, of the recording. This is used to adjust detection sensitivity. A value of
|
|
265
|
+
0 means automatic detection based on the recording's spatial scale. Values above 0 are applied in increments of 6
|
|
266
|
+
pixels (1 -> 6 pixels, 2-> 12 pixels, etc.)."""
|
|
267
|
+
|
|
268
|
+
connected: bool = True
|
|
269
|
+
"""Determines whether to require the detected ROIs to be fully connected regions."""
|
|
270
|
+
|
|
271
|
+
threshold_scaling: float = 2.0
|
|
272
|
+
"""The scaling factor for the detection threshold. This determines how distinctly ROIs have to stand out from
|
|
273
|
+
background noise to be considered valid."""
|
|
274
|
+
|
|
275
|
+
spatial_hp_detect: int = 25
|
|
276
|
+
"""The window size, in pixels, for spatial high-pass filtering applied before neuropil subtraction during
|
|
277
|
+
ROI detection."""
|
|
278
|
+
|
|
279
|
+
max_overlap: float = 0.75
|
|
280
|
+
"""The maximum allowed fraction of overlapping pixels between ROIs. ROIs that overlap above this threshold are be
|
|
281
|
+
discarded."""
|
|
282
|
+
|
|
283
|
+
high_pass: int = 100
|
|
284
|
+
"""The window size, in frames, for running mean subtraction over time to remove low-frequency drift."""
|
|
285
|
+
|
|
286
|
+
smooth_masks: bool = True
|
|
287
|
+
"""Determines whether to smooth the ROI masks in the final pass of cell detection."""
|
|
288
|
+
|
|
289
|
+
max_iterations: int = 50
|
|
290
|
+
"""The maximum number of iterations allowed for cell extraction."""
|
|
291
|
+
|
|
292
|
+
nbinned: int = 5000
|
|
293
|
+
"""The maximum number of binned frames to use for ROI detection to speed up processing."""
|
|
294
|
+
|
|
295
|
+
denoise: bool = False
|
|
296
|
+
"""Determines whether to denoise the binned movie before cell detection in sparse mode to enhance performance.
|
|
297
|
+
If enabled, 'sparse_mode' has to be True."""
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
@dataclass
|
|
301
|
+
class CellposeDetection:
|
|
302
|
+
"""Stores Cellpose algorithm settings used for cell detection."""
|
|
303
|
+
|
|
304
|
+
anatomical_only: int = 0
|
|
305
|
+
"""Specifies the Cellpose mode for cell detection:
|
|
306
|
+
0: Do not use Cellpose. This automatically disables all other fields in this section.
|
|
307
|
+
1: Detect masks on the max projection divided by the mean image.
|
|
308
|
+
2: Detect masks on the mean image.
|
|
309
|
+
3: Detect masks on the enhanced mean image.
|
|
310
|
+
4: Detect masks on the max projection image.
|
|
311
|
+
"""
|
|
312
|
+
|
|
313
|
+
diameter: int = 0
|
|
314
|
+
"""Specifies the diameter, in pixels, of cells to look for. If set to 0, Cellpose estimates the diameter
|
|
315
|
+
automatically.."""
|
|
316
|
+
|
|
317
|
+
cellprob_threshold: float = 0.0
|
|
318
|
+
"""The threshold for cell detection, used to filter out low-confidence detections."""
|
|
319
|
+
|
|
320
|
+
flow_threshold: float = 1.5
|
|
321
|
+
"""The flow threshold, used to control the sensitivity to cell boundaries."""
|
|
322
|
+
|
|
323
|
+
spatial_hp_cp: int = 0
|
|
324
|
+
"""The window size, in pixels, for spatial high-pass filtering applied to the image before Cellpose processing."""
|
|
325
|
+
|
|
326
|
+
pretrained_model: str = "cyto"
|
|
327
|
+
"""Specifies the pretrained model to use for cell detection. Can be a built-in model name (e.g., 'cyto') or a
|
|
328
|
+
path to a custom model."""
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
@dataclass
|
|
332
|
+
class SignalExtraction:
|
|
333
|
+
"""Stores settings used to extract fluorescence signals from ROIs and surrounding neuropil regions."""
|
|
334
|
+
|
|
335
|
+
neuropil_extract: bool = True
|
|
336
|
+
"""Determines whether to extract neuropil signals."""
|
|
337
|
+
|
|
338
|
+
allow_overlap: bool = False
|
|
339
|
+
"""Determines whether to allow overlap pixels (pixels shared by multiple ROIs) to be used in the signal extraction.
|
|
340
|
+
Typically this is set to False to avoid contamination."""
|
|
341
|
+
|
|
342
|
+
min_neuropil_pixels: int = 350
|
|
343
|
+
"""The minimum number of pixels required to compute the neuropil signal for each cell."""
|
|
344
|
+
|
|
345
|
+
inner_neuropil_radius: int = 2
|
|
346
|
+
"""The number of pixels to keep between the ROI and the surrounding neuropil region to avoid signal bleed-over."""
|
|
347
|
+
|
|
348
|
+
lam_percentile: int = 50
|
|
349
|
+
"""The percentile of Lambda within area to ignore when excluding the brightest pixels during neuropil extraction."""
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
@dataclass
|
|
353
|
+
class SpikeDeconvolution:
|
|
354
|
+
"""Stores settings used to deconvolve calcium signals to infer spike trains."""
|
|
355
|
+
|
|
356
|
+
spikedetect: bool = True
|
|
357
|
+
"""Determines whether to perform spike deconvolution to convert calcium signals into estimated spike trains."""
|
|
358
|
+
|
|
359
|
+
neucoeff: float = 0.7
|
|
360
|
+
"""The neuropil coefficient applied for signal correction before deconvolution."""
|
|
361
|
+
|
|
362
|
+
baseline: str = "maximin"
|
|
363
|
+
"""Specifies the method to compute the baseline of each trace. This baseline is then subtracted from each cell.
|
|
364
|
+
‘maximin’ computes a moving baseline by filtering the data with a Gaussian of width 'sig_baseline' * 'fs', and then
|
|
365
|
+
minimum filtering with a window of 'win_baseline' * 'fs', and then maximum filtering with the same window.
|
|
366
|
+
‘constant’ computes a constant baseline by filtering with a Gaussian of width 'sig_baseline' * 'fs' and then taking
|
|
367
|
+
the minimum value of this filtered trace. ‘constant_percentile’ computes a constant baseline by taking the
|
|
368
|
+
'prctile_baseline' percentile of the trace."""
|
|
369
|
+
|
|
370
|
+
win_baseline: float = 60.0
|
|
371
|
+
"""The time window, in seconds, over which to compute the baseline filter."""
|
|
372
|
+
|
|
373
|
+
sig_baseline: float = 10.0
|
|
374
|
+
"""The standard deviation, in seconds, of the Gaussian filter applied to smooth the baseline signal."""
|
|
375
|
+
|
|
376
|
+
prctile_baseline: float = 8.0
|
|
377
|
+
"""The percentile used to determine the baseline level of each trace (typically a low percentile reflecting
|
|
378
|
+
minimal activity)."""
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
@dataclass
|
|
382
|
+
class Classification:
|
|
383
|
+
"""Stores settings used to classify detected ROIs as real cells or artifacts."""
|
|
384
|
+
|
|
385
|
+
soma_crop: bool = True
|
|
386
|
+
"""Determines whether to crop dendritic regions from detected ROIs to focus on the cell body for classification
|
|
387
|
+
purposes."""
|
|
388
|
+
|
|
389
|
+
use_builtin_classifier: bool = False
|
|
390
|
+
"""Determines whether to use the built-in classifier for cell detection."""
|
|
391
|
+
|
|
392
|
+
classifier_path: str = ""
|
|
393
|
+
"""The path to a custom classifier file, if not using the built-in classifier."""
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
@dataclass
|
|
397
|
+
class Channel2:
|
|
398
|
+
"""Stores settings for processing the second channel in multichannel datasets."""
|
|
399
|
+
|
|
400
|
+
chan2_thres: float = 0.65
|
|
401
|
+
"""The threshold for considering an ROI registered in one channel as detected in the second channel."""
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
@dataclass
|
|
405
|
+
class Suite2PConfiguration(YamlConfig):
|
|
406
|
+
"""Stores the user-addressable suite2p configuration parameters, organized into subsections.
|
|
407
|
+
|
|
408
|
+
This class is used during processing to instruct suite2p on how to process the data. Specifically, it provides a
|
|
409
|
+
user-friendly way of specifying all user-addressable parameters through a .YAML file. The sl-forgery library then
|
|
410
|
+
loads the data from .yaml file and uses it to configure the single-day suite2p pipeline and the multiday suite2p
|
|
411
|
+
pipeline.
|
|
412
|
+
|
|
413
|
+
Notes:
|
|
414
|
+
The .YAML file uses section names that match the suite2p documentation sections. This way, users can always
|
|
415
|
+
consult the suite2p documentation for information on the purpose of each field inside every subsection.
|
|
416
|
+
"""
|
|
417
|
+
|
|
418
|
+
# Define the instances of each nested settings class as fields
|
|
419
|
+
main: Main = field(default_factory=Main)
|
|
420
|
+
file_io: FileIO = field(default_factory=FileIO)
|
|
421
|
+
output: Output = field(default_factory=Output)
|
|
422
|
+
registration: Registration = field(default_factory=Registration)
|
|
423
|
+
one_p_registration: OnePRegistration = field(default_factory=OnePRegistration)
|
|
424
|
+
non_rigid: NonRigid = field(default_factory=NonRigid)
|
|
425
|
+
roi_detection: ROIDetection = field(default_factory=ROIDetection)
|
|
426
|
+
cellpose_detection: CellposeDetection = field(default_factory=CellposeDetection)
|
|
427
|
+
signal_extraction: SignalExtraction = field(default_factory=SignalExtraction)
|
|
428
|
+
spike_deconvolution: SpikeDeconvolution = field(default_factory=SpikeDeconvolution)
|
|
429
|
+
classification: Classification = field(default_factory=Classification)
|
|
430
|
+
channel2: Channel2 = field(default_factory=Channel2)
|
|
431
|
+
|
|
432
|
+
def to_ops(self) -> dict[str, Any]:
|
|
433
|
+
"""Converts the class instance to a dictionary and returns it to caller.
|
|
434
|
+
|
|
435
|
+
This dictionary can be passed to suite2p functions either as an 'ops' or 'db' argument to control the
|
|
436
|
+
processing runtime.
|
|
437
|
+
"""
|
|
438
|
+
|
|
439
|
+
# Creates an empty dictionary to store all keys and values
|
|
440
|
+
combined_ops = {}
|
|
441
|
+
|
|
442
|
+
# Iterates through all dataclass fields
|
|
443
|
+
# noinspection PyTypeChecker
|
|
444
|
+
for section_name, section in asdict(self).items():
|
|
445
|
+
# Adds all keys and values from each section to the combined dictionary
|
|
446
|
+
if isinstance(section, dict):
|
|
447
|
+
combined_ops.update(section)
|
|
448
|
+
|
|
449
|
+
return combined_ops
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
from dataclasses import field, dataclass
|
|
3
|
+
|
|
4
|
+
from _typeshed import Incomplete
|
|
5
|
+
from ataraxis_data_structures import YamlConfig
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class Main:
|
|
9
|
+
"""Stores global settings used to broadly define the suite2p processing configuration."""
|
|
10
|
+
|
|
11
|
+
nplanes: int = ...
|
|
12
|
+
nchannels: int = ...
|
|
13
|
+
functional_chan: int = ...
|
|
14
|
+
tau: float = ...
|
|
15
|
+
force_sktiff: bool = ...
|
|
16
|
+
fs: float = ...
|
|
17
|
+
do_bidiphase: bool = ...
|
|
18
|
+
bidiphase: int = ...
|
|
19
|
+
bidi_corrected: bool = ...
|
|
20
|
+
frames_include: int = ...
|
|
21
|
+
multiplane_parallel: bool = ...
|
|
22
|
+
ignore_flyback: list[int] = field(default_factory=list)
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class FileIO:
|
|
26
|
+
"""Stores I/O settings used to specify input data file locations, formats, and output storage options."""
|
|
27
|
+
|
|
28
|
+
fast_disk: list[str] = field(default_factory=list)
|
|
29
|
+
delete_bin: bool = ...
|
|
30
|
+
mesoscan: bool = ...
|
|
31
|
+
bruker: bool = ...
|
|
32
|
+
bruker_bidirectional: bool = ...
|
|
33
|
+
h5py: list[str] = field(default_factory=list)
|
|
34
|
+
h5py_key: str = ...
|
|
35
|
+
nwb_file: str = ...
|
|
36
|
+
nwb_driver: str = ...
|
|
37
|
+
nwb_series: str = ...
|
|
38
|
+
save_path0: list[str] = field(default_factory=list)
|
|
39
|
+
save_folder: list[str] = field(default_factory=list)
|
|
40
|
+
look_one_level_down: bool = ...
|
|
41
|
+
subfolders: list[str] = field(default_factory=list)
|
|
42
|
+
move_bin: bool = ...
|
|
43
|
+
|
|
44
|
+
@dataclass
|
|
45
|
+
class Output:
|
|
46
|
+
"""Stores I/O settings used to define the output format and organization of the processing results."""
|
|
47
|
+
|
|
48
|
+
preclassify: float = ...
|
|
49
|
+
save_nwb: bool = ...
|
|
50
|
+
save_mat: bool = ...
|
|
51
|
+
combined: bool = ...
|
|
52
|
+
aspect: float = ...
|
|
53
|
+
report_time: bool = ...
|
|
54
|
+
|
|
55
|
+
@dataclass
|
|
56
|
+
class Registration:
|
|
57
|
+
"""Stores rigid registration settings used for correcting motion artifacts between frames."""
|
|
58
|
+
|
|
59
|
+
do_registration: bool = ...
|
|
60
|
+
align_by_chan: int = ...
|
|
61
|
+
nimg_init: int = ...
|
|
62
|
+
batch_size: int = ...
|
|
63
|
+
maxregshift: float = ...
|
|
64
|
+
smooth_sigma: float = ...
|
|
65
|
+
smooth_sigma_time: float = ...
|
|
66
|
+
keep_movie_raw: bool = ...
|
|
67
|
+
two_step_registration: bool = ...
|
|
68
|
+
reg_tif: bool = ...
|
|
69
|
+
reg_tif_chan2: bool = ...
|
|
70
|
+
subpixel: int = ...
|
|
71
|
+
th_badframes: float = ...
|
|
72
|
+
norm_frames: bool = ...
|
|
73
|
+
force_refImg: bool = ...
|
|
74
|
+
pad_fft: bool = ...
|
|
75
|
+
|
|
76
|
+
@dataclass
|
|
77
|
+
class OnePRegistration:
|
|
78
|
+
"""Stores additional pre-registration processing settings used to improve the registration of 1-photon datasets."""
|
|
79
|
+
|
|
80
|
+
one_p_reg: bool = ...
|
|
81
|
+
spatial_hp_reg: int = ...
|
|
82
|
+
pre_smooth: float = ...
|
|
83
|
+
spatial_taper: float = ...
|
|
84
|
+
|
|
85
|
+
@dataclass
|
|
86
|
+
class NonRigid:
|
|
87
|
+
"""Stores non-rigid registration settings used to improve motion registration in complex datasets."""
|
|
88
|
+
|
|
89
|
+
nonrigid: bool = ...
|
|
90
|
+
block_size: list[int] = field(default_factory=Incomplete)
|
|
91
|
+
snr_thresh: float = ...
|
|
92
|
+
maxregshiftNR: float = ...
|
|
93
|
+
|
|
94
|
+
@dataclass
|
|
95
|
+
class ROIDetection:
|
|
96
|
+
"""Stores ROI detection and extraction settings used to identify cells and their activity signals."""
|
|
97
|
+
|
|
98
|
+
roidetect: bool = ...
|
|
99
|
+
sparse_mode: bool = ...
|
|
100
|
+
spatial_scale: int = ...
|
|
101
|
+
connected: bool = ...
|
|
102
|
+
threshold_scaling: float = ...
|
|
103
|
+
spatial_hp_detect: int = ...
|
|
104
|
+
max_overlap: float = ...
|
|
105
|
+
high_pass: int = ...
|
|
106
|
+
smooth_masks: bool = ...
|
|
107
|
+
max_iterations: int = ...
|
|
108
|
+
nbinned: int = ...
|
|
109
|
+
denoise: bool = ...
|
|
110
|
+
|
|
111
|
+
@dataclass
|
|
112
|
+
class CellposeDetection:
|
|
113
|
+
"""Stores Cellpose algorithm settings used for cell detection."""
|
|
114
|
+
|
|
115
|
+
anatomical_only: int = ...
|
|
116
|
+
diameter: int = ...
|
|
117
|
+
cellprob_threshold: float = ...
|
|
118
|
+
flow_threshold: float = ...
|
|
119
|
+
spatial_hp_cp: int = ...
|
|
120
|
+
pretrained_model: str = ...
|
|
121
|
+
|
|
122
|
+
@dataclass
|
|
123
|
+
class SignalExtraction:
|
|
124
|
+
"""Stores settings used to extract fluorescence signals from ROIs and surrounding neuropil regions."""
|
|
125
|
+
|
|
126
|
+
neuropil_extract: bool = ...
|
|
127
|
+
allow_overlap: bool = ...
|
|
128
|
+
min_neuropil_pixels: int = ...
|
|
129
|
+
inner_neuropil_radius: int = ...
|
|
130
|
+
lam_percentile: int = ...
|
|
131
|
+
|
|
132
|
+
@dataclass
|
|
133
|
+
class SpikeDeconvolution:
|
|
134
|
+
"""Stores settings used to deconvolve calcium signals to infer spike trains."""
|
|
135
|
+
|
|
136
|
+
spikedetect: bool = ...
|
|
137
|
+
neucoeff: float = ...
|
|
138
|
+
baseline: str = ...
|
|
139
|
+
win_baseline: float = ...
|
|
140
|
+
sig_baseline: float = ...
|
|
141
|
+
prctile_baseline: float = ...
|
|
142
|
+
|
|
143
|
+
@dataclass
|
|
144
|
+
class Classification:
|
|
145
|
+
"""Stores settings used to classify detected ROIs as real cells or artifacts."""
|
|
146
|
+
|
|
147
|
+
soma_crop: bool = ...
|
|
148
|
+
use_builtin_classifier: bool = ...
|
|
149
|
+
classifier_path: str = ...
|
|
150
|
+
|
|
151
|
+
@dataclass
|
|
152
|
+
class Channel2:
|
|
153
|
+
"""Stores settings for processing the second channel in multichannel datasets."""
|
|
154
|
+
|
|
155
|
+
chan2_thres: float = ...
|
|
156
|
+
|
|
157
|
+
@dataclass
|
|
158
|
+
class Suite2PConfiguration(YamlConfig):
|
|
159
|
+
"""Stores the user-addressable suite2p configuration parameters, organized into subsections.
|
|
160
|
+
|
|
161
|
+
This class is used during processing to instruct suite2p on how to process the data. Specifically, it provides a
|
|
162
|
+
user-friendly way of specifying all user-addressable parameters through a .YAML file. The sl-forgery library then
|
|
163
|
+
loads the data from .yaml file and uses it to configure the single-day suite2p pipeline and the multiday suite2p
|
|
164
|
+
pipeline.
|
|
165
|
+
|
|
166
|
+
Notes:
|
|
167
|
+
The .YAML file uses section names that match the suite2p documentation sections. This way, users can always
|
|
168
|
+
consult the suite2p documentation for information on the purpose of each field inside every subsection.
|
|
169
|
+
"""
|
|
170
|
+
|
|
171
|
+
main: Main = field(default_factory=Main)
|
|
172
|
+
file_io: FileIO = field(default_factory=FileIO)
|
|
173
|
+
output: Output = field(default_factory=Output)
|
|
174
|
+
registration: Registration = field(default_factory=Registration)
|
|
175
|
+
one_p_registration: OnePRegistration = field(default_factory=OnePRegistration)
|
|
176
|
+
non_rigid: NonRigid = field(default_factory=NonRigid)
|
|
177
|
+
roi_detection: ROIDetection = field(default_factory=ROIDetection)
|
|
178
|
+
cellpose_detection: CellposeDetection = field(default_factory=CellposeDetection)
|
|
179
|
+
signal_extraction: SignalExtraction = field(default_factory=SignalExtraction)
|
|
180
|
+
spike_deconvolution: SpikeDeconvolution = field(default_factory=SpikeDeconvolution)
|
|
181
|
+
classification: Classification = field(default_factory=Classification)
|
|
182
|
+
channel2: Channel2 = field(default_factory=Channel2)
|
|
183
|
+
def to_ops(self) -> dict[str, Any]:
|
|
184
|
+
"""Converts the class instance to a dictionary and returns it to caller.
|
|
185
|
+
|
|
186
|
+
This dictionary can be passed to suite2p functions either as an 'ops' or 'db' argument to control the
|
|
187
|
+
processing runtime.
|
|
188
|
+
"""
|