4
4
import numpy as np
5
5
import inspect
6
6
import importlib
7
+ from element_interface .utils import find_root_directory , find_full_path , dict_to_uuid
7
8
8
9
from .readers import spikeglx , kilosort , openephys
9
- from . import probe , find_full_path , find_root_directory , dict_to_uuid
10
+ from . import probe
10
11
11
12
schema = dj .schema ()
12
13
@@ -46,7 +47,6 @@ def activate(ephys_schema_name, probe_schema_name=None, *, create_schema=True,
46
47
global _linking_module
47
48
_linking_module = linking_module
48
49
49
- # activate
50
50
probe .activate (probe_schema_name , create_schema = create_schema ,
51
51
create_tables = create_tables )
52
52
schema .activate (ephys_schema_name , create_schema = create_schema ,
@@ -57,9 +57,10 @@ def activate(ephys_schema_name, probe_schema_name=None, *, create_schema=True,
57
57
58
58
def get_ephys_root_data_dir () -> list :
59
59
"""
60
- All data paths, directories in DataJoint Elements are recommended to be stored as
61
- relative paths, with respect to some user-configured "root" directory,
62
- which varies from machine to machine (e.g. different mounted drive locations)
60
+ All data paths, directories in DataJoint Elements are recommended to be
61
+ stored as relative paths, with respect to some user-configured "root"
62
+ directory, which varies from machine to machine (e.g. different mounted
63
+ drive locations)
63
64
64
65
get_ephys_root_data_dir() -> list
65
66
This user-provided function retrieves the possible root data directories
@@ -78,7 +79,7 @@ def get_session_directory(session_key: dict) -> str:
78
79
Retrieve the session directory containing the
79
80
recorded Neuropixels data for a given Session
80
81
:param session_key: a dictionary of one Session `key`
81
- :return: a string for full path to the session directory
82
+ :return: a string for relative or full path to the session directory
82
83
"""
83
84
return _linking_module .get_session_directory (session_key )
84
85
@@ -140,23 +141,24 @@ class EphysFile(dj.Part):
140
141
"""
141
142
142
143
def make (self , key ):
143
- sess_dir = pathlib .Path (get_session_directory (key ))
144
- sess_dir_full = find_full_path (get_ephys_root_data_dir (), sess_dir )
144
+
145
+ session_dir = find_full_path (get_ephys_root_data_dir (),
146
+ get_session_directory (key ))
145
147
146
148
inserted_probe_serial_number = (ProbeInsertion * probe .Probe & key ).fetch1 ('probe' )
147
149
148
150
# search session dir and determine acquisition software
149
151
for ephys_pattern , ephys_acq_type in zip (['*.ap.meta' , '*.oebin' ],
150
152
['SpikeGLX' , 'Open Ephys' ]):
151
- ephys_meta_filepaths = [fp for fp in sess_dir_full .rglob (ephys_pattern )]
153
+ ephys_meta_filepaths = [fp for fp in session_dir .rglob (ephys_pattern )]
152
154
if ephys_meta_filepaths :
153
155
acq_software = ephys_acq_type
154
156
break
155
157
else :
156
158
raise FileNotFoundError (
157
159
f'Ephys recording data not found!'
158
160
f' Neither SpikeGLX nor Open Ephys recording files found'
159
- f' in { sess_dir } ' )
161
+ f' in { session_dir } ' )
160
162
161
163
if acq_software == 'SpikeGLX' :
162
164
for meta_filepath in ephys_meta_filepaths :
@@ -189,12 +191,13 @@ def make(self, key):
189
191
'acq_software' : acq_software ,
190
192
'sampling_rate' : spikeglx_meta .meta ['imSampRate' ]})
191
193
192
- root_dir = find_root_directory (get_ephys_root_data_dir (), meta_filepath )
194
+ root_dir = find_root_directory (get_ephys_root_data_dir (),
195
+ meta_filepath )
193
196
self .EphysFile .insert1 ({
194
197
** key ,
195
198
'file_path' : meta_filepath .relative_to (root_dir ).as_posix ()})
196
199
elif acq_software == 'Open Ephys' :
197
- dataset = openephys .OpenEphys (sess_dir_full )
200
+ dataset = openephys .OpenEphys (session_dir )
198
201
for serial_number , probe_data in dataset .probes .items ():
199
202
if str (serial_number ) == inserted_probe_serial_number :
200
203
break
@@ -222,8 +225,7 @@ def make(self, key):
222
225
'acq_software' : acq_software ,
223
226
'sampling_rate' : probe_data .ap_meta ['sample_rate' ]})
224
227
225
- root_dir = find_root_directory (
226
- get_ephys_root_data_dir (),
228
+ root_dir = find_root_directory (get_ephys_root_data_dir (),
227
229
probe_data .recording_info ['recording_files' ][0 ])
228
230
self .EphysFile .insert ([{** key ,
229
231
'file_path' : fp .relative_to (root_dir ).as_posix ()}
@@ -292,9 +294,11 @@ def make(self, key):
292
294
shank , shank_col , shank_row , _ = spikeglx_recording .apmeta .shankmap ['data' ][recorded_site ]
293
295
electrode_keys .append (probe_electrodes [(shank , shank_col , shank_row )])
294
296
elif acq_software == 'Open Ephys' :
295
- sess_dir = pathlib .Path (get_session_directory (key ))
296
- sess_dir_full = find_full_path (get_ephys_root_data_dir (), sess_dir )
297
- loaded_oe = openephys .OpenEphys (sess_dir_full )
297
+
298
+ session_dir = find_full_path (get_ephys_root_data_dir (),
299
+ get_session_directory (key ))
300
+
301
+ loaded_oe = openephys .OpenEphys (session_dir )
298
302
oe_probe = loaded_oe .probes [probe_sn ]
299
303
300
304
lfp_channel_ind = np .arange (
@@ -445,16 +449,16 @@ class Curation(dj.Manual):
445
449
curation_id: int
446
450
---
447
451
curation_time: datetime # time of generation of this set of curated clustering results
448
- curation_output_dir: varchar(255) # output directory of the curated results, relative to clustering root data directory
452
+ curation_output_dir: varchar(255) # output directory of the curated results, relative to root data directory
449
453
quality_control: bool # has this clustering result undergone quality control?
450
454
manual_curation: bool # has manual curation been performed on this clustering result?
451
455
curation_note='': varchar(2000)
452
456
"""
453
457
454
458
def create1_from_clustering_task (self , key , curation_note = '' ):
455
459
"""
456
- A convenient function to create a new corresponding "Curation"
457
- for a particular "ClusteringTask"
460
+ A function to create a new corresponding "Curation" for a particular
461
+ "ClusteringTask"
458
462
"""
459
463
if key not in Clustering ():
460
464
raise ValueError (f'No corresponding entry in Clustering available'
@@ -468,8 +472,10 @@ def create1_from_clustering_task(self, key, curation_note=''):
468
472
# Synthesize curation_id
469
473
curation_id = dj .U ().aggr (self & key , n = 'ifnull(max(curation_id)+1,1)' ).fetch1 ('n' )
470
474
self .insert1 ({** key , 'curation_id' : curation_id ,
471
- 'curation_time' : creation_time , 'curation_output_dir' : output_dir ,
472
- 'quality_control' : is_qc , 'manual_curation' : is_curated ,
475
+ 'curation_time' : creation_time ,
476
+ 'curation_output_dir' : output_dir ,
477
+ 'quality_control' : is_qc ,
478
+ 'manual_curation' : is_curated ,
473
479
'curation_note' : curation_note })
474
480
475
481
@@ -616,9 +622,9 @@ def yield_unit_waveforms():
616
622
spikeglx_meta_filepath = get_spikeglx_meta_filepath (key )
617
623
neuropixels_recording = spikeglx .SpikeGLX (spikeglx_meta_filepath .parent )
618
624
elif acq_software == 'Open Ephys' :
619
- sess_dir = pathlib . Path ( get_session_directory ( key ))
620
- sess_dir_full = find_full_path ( get_ephys_root_data_dir (), sess_dir )
621
- openephys_dataset = openephys .OpenEphys (sess_dir_full )
625
+ session_dir = find_full_path ( get_ephys_root_data_dir (),
626
+ get_session_directory ( key ) )
627
+ openephys_dataset = openephys .OpenEphys (session_dir )
622
628
neuropixels_recording = openephys_dataset .probes [probe_serial_number ]
623
629
624
630
def yield_unit_waveforms ():
@@ -663,11 +669,13 @@ def get_spikeglx_meta_filepath(ephys_recording_key):
663
669
except FileNotFoundError :
664
670
# if not found, search in session_dir again
665
671
if not spikeglx_meta_filepath .exists ():
666
- sess_dir = pathlib .Path (get_session_directory (ephys_recording_key ))
672
+ session_dir = find_full_path (get_ephys_root_data_dir (),
673
+ get_session_directory (
674
+ ephys_recording_key ))
667
675
inserted_probe_serial_number = (ProbeInsertion * probe .Probe
668
676
& ephys_recording_key ).fetch1 ('probe' )
669
677
670
- spikeglx_meta_filepaths = [fp for fp in sess_dir .rglob ('*.ap.meta' )]
678
+ spikeglx_meta_filepaths = [fp for fp in session_dir .rglob ('*.ap.meta' )]
671
679
for meta_filepath in spikeglx_meta_filepaths :
672
680
spikeglx_meta = spikeglx .SpikeGLXMeta (meta_filepath )
673
681
if str (spikeglx_meta .probe_SN ) == inserted_probe_serial_number :
@@ -700,9 +708,9 @@ def get_neuropixels_channel2electrode_map(ephys_recording_key, acq_software):
700
708
for recorded_site , (shank , shank_col , shank_row , _ ) in enumerate (
701
709
spikeglx_meta .shankmap ['data' ])}
702
710
elif acq_software == 'Open Ephys' :
703
- sess_dir = pathlib . Path ( get_session_directory ( ephys_recording_key ))
704
- sess_dir_full = find_full_path ( get_ephys_root_data_dir (), sess_dir )
705
- openephys_dataset = openephys .OpenEphys (sess_dir_full )
711
+ session_dir = find_full_path ( get_ephys_root_data_dir (),
712
+ get_session_directory ( ephys_recording_key ) )
713
+ openephys_dataset = openephys .OpenEphys (session_dir )
706
714
probe_serial_number = (ProbeInsertion & ephys_recording_key ).fetch1 ('probe' )
707
715
probe_dataset = openephys_dataset .probes [probe_serial_number ]
708
716
0 commit comments