Rules
Upload rules for lab data management.
This module provides rules for processing data uploads to the database. Rules handle validation, preprocessing, and storage of different data types.
Default rules included:
- UploadRule: Base rule for generic file uploads
- EphysRule: Rule for electrophysiology data (SpikeGLX)
- TwoPhotonRule: Rule for two-photon microscopy data (ScanImage/Scanbox)
- OnePhotonRule: Rule for one-photon imaging data (Widefield - labcams)
- MiniscopeRule: Rule for (UCLA) Miniscope imaging data
- FixedBrainRule: Rule for fixed tissue microscopy data
- ReplaceRule: Rule for replacing existing files
Custom rules can be added to the user_preferences.json configuration.
UploadRule
Source code in labdata/rules/utils.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
__init__(job_id, prefs=None)
Rule to apply on upload.
1) Checksum on the files; compare with provided (reserve job if use_db)
2) Apply function
3) Checksum on the output - the files that changed
4) Submit upload
5) Update tables
Can submit job on slurm, some of these can be long or take resources.
Source code in labdata/rules/utils.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
FixedBrainRule
Bases: UploadRule
Source code in labdata/rules/imaging.py
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
parse_metadata(data)
Reads metadata from a MultifolderTiffStack
Source code in labdata/rules/imaging.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
EphysRule
Bases: UploadRule
Source code in labdata/rules/ephys.py
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
TwoPhotonRule
Bases: UploadRule
Source code in labdata/rules/imaging.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
OnePhotonRule
Bases: UploadRule
Source code in labdata/rules/imaging.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
MiniscopeRule
Bases: UploadRule
Source code in labdata/rules/imaging.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
process_upload_jobs(key=None, rule='all', n_jobs=8, job_host=None, force=False, prefs=None)
Process UploadJobs using UploadRule(s). Custom upload rules can be added as plugins, just include in prefs['upload_rules']
Joao Couto - labdata 2024
Source code in labdata/rules/__init__.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
Auxiliary Functions
Upload rules for lab data management.
This module provides rules for processing data uploads to the database. Rules handle validation, preprocessing, and storage of different data types.
Default rules included:
- UploadRule: Base rule for generic file uploads
- EphysRule: Rule for electrophysiology data (SpikeGLX)
- TwoPhotonRule: Rule for two-photon microscopy data (ScanImage/Scanbox)
- OnePhotonRule: Rule for one-photon imaging data (Widefield - labcams)
- MiniscopeRule: Rule for (UCLA) Miniscope imaging data
- FixedBrainRule: Rule for fixed tissue microscopy data
- ReplaceRule: Rule for replacing existing files
Custom rules can be added to the user_preferences.json configuration.
MultifolderTiffStack
Bases: object
Source code in labdata/rules/imaging.py
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | |
__init__(channel_folders, extensions=['.ome.tif', '.tif', '.TIFF'])
Simple class to access tiff files that are organized in a folders Each folder is a channel and contains multiple TIFF files.
This is the format of the lightsheet microscope for example. It is a place-holder class that should be modified to work for scanimage files also.
Source code in labdata/rules/imaging.py
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 | |
compress_imaging_stack(stack, filename, chunksize=256, compression='blosc2', clevel=6, shuffle=1, filters=[], zarr_format=2, scratch_path=None, check_dataset=True)
stack is in shape [nframes,nchan,H,W]
Typical use case for two photon datasets: - blosc2 compression clevel 6, shuffle 1, no filters this will take ~10min/25Gb and the result is a file 77% of the original file. Typical use case for one photon datasets: - blosc2 compression clevel 6, shuffle 1, no filters Typical use for lightsheet imaging: - blosc2 compression clevel 6, shuffle 1, no filters
TODO: implement a way of changing the chunksize of the inner dimensions.. TODO: implement a way to skip the zip
Source code in labdata/rules/imaging.py
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | |
compress_ephys_file(filename, local_path=None, ext='.bin', n_jobs=DEFAULT_N_JOBS, check_after_compress=True, prefs=None)
Compress ephys data
Source code in labdata/rules/ephys.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
extract_events_from_nidq(paths)
Extracts the events from the nidq files (spikeglx) and formats it so they can be inserted in the database.
Source code in labdata/rules/ephys.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
ephys_noise_statistics_from_file(filepath, channel_indices, gain, sampling_rate=30000, duration=60)
statistics = ephys_noise_statistics_from_file(filepath,channel_indices, gain, sampling_rate = 30000, duration = 60)
Gets the noise statistics from a raw data file. It won't parse the whole file, instead it will extract 2 chunks, one from t=duration to t=duration2 and another from t=end of recording-duration2 to t=end of recording-duration. Then computes: the peak to peak, min, max, median and absolute median deviation of those chunks.
This is useful just to compare the start and end of the recording or to have ballpark estimations of these values. For more accurate measurements split the recording in chunks of e.g. 1 second, compute it for the entire file, then average and std. This will max if there are artifacts in the chunks.
Joao Couto - labdata 2024
Source code in labdata/rules/ephys.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
get_probe_configuration(meta)
Meta can be a file or a dictionary. Uses spks for now to parse the metadata.
Source code in labdata/rules/ephys.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
insert_miniscope_dataset(schema, key, local_paths=None, skip_duplicates=False)
Source code in labdata/rules/imaging.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | |
mmap_wfield_binary(filename, mode='r', nframes=None, shape=None, dtype='uint16')
Loads frames from a binary file as a memory map. This is useful when the data does not fit to memory.
Inputs:
filename (str) : fileformat convention, file ends in _NCHANNELS_H_W_DTYPE.dat
mode (str) : memory map access mode (default 'r')
'r' | Open existing file for reading only.
'r+' | Open existing file for reading and writing.
nframes (int) : number of frames to read (default is None: the entire file)
offset (int) : offset frame number (default 0)
shape (list|tuple) : dimensions (NCHANNELS, HEIGHT, WIDTH) default is None
dtype (str) : datatype (default uint16)
Returns:
A memory mapped array with size (NFRAMES,NCHANNELS, HEIGHT, WIDTH).
Example: dat = mmap_dat(filename)
This is from wfield - jcouto
Source code in labdata/rules/imaging.py
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | |
read_ome_tif(file)
Source code in labdata/rules/imaging.py
561 562 563 564 565 566 567 568 569 | |
insert_widefield_dataset(schema, key, local_paths=None, skip_duplicates=False)
Insert widefield dataset keys (assumes data were collected with labcams but there can be adapted to support other formats.) ask jpcouto@gmail.com
Source code in labdata/rules/imaging.py
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 | |