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,21 +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
+
145
+ session_dir = find_full_path (get_ephys_root_data_dir (),
146
+ get_session_directory (key ))
144
147
145
148
inserted_probe_serial_number = (ProbeInsertion * probe .Probe & key ).fetch1 ('probe' )
146
149
147
150
# search session dir and determine acquisition software
148
151
for ephys_pattern , ephys_acq_type in zip (['*.ap.meta' , '*.oebin' ],
149
152
['SpikeGLX' , 'Open Ephys' ]):
150
- ephys_meta_filepaths = [fp for fp in sess_dir .rglob (ephys_pattern )]
153
+ ephys_meta_filepaths = [fp for fp in session_dir .rglob (ephys_pattern )]
151
154
if ephys_meta_filepaths :
152
155
acq_software = ephys_acq_type
153
156
break
154
157
else :
155
158
raise FileNotFoundError (
156
159
f'Ephys recording data not found!'
157
- f' Neither SpikeGLX nor Open Ephys recording files found' )
160
+ f' Neither SpikeGLX nor Open Ephys recording files found'
161
+ f' in { session_dir } ' )
158
162
159
163
if acq_software == 'SpikeGLX' :
160
164
for meta_filepath in ephys_meta_filepaths :
@@ -187,12 +191,13 @@ def make(self, key):
187
191
'acq_software' : acq_software ,
188
192
'sampling_rate' : spikeglx_meta .meta ['imSampRate' ]})
189
193
190
- 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 )
191
196
self .EphysFile .insert1 ({
192
197
** key ,
193
198
'file_path' : meta_filepath .relative_to (root_dir ).as_posix ()})
194
199
elif acq_software == 'Open Ephys' :
195
- dataset = openephys .OpenEphys (sess_dir )
200
+ dataset = openephys .OpenEphys (session_dir )
196
201
for serial_number , probe_data in dataset .probes .items ():
197
202
if str (serial_number ) == inserted_probe_serial_number :
198
203
break
@@ -220,8 +225,7 @@ def make(self, key):
220
225
'acq_software' : acq_software ,
221
226
'sampling_rate' : probe_data .ap_meta ['sample_rate' ]})
222
227
223
- root_dir = find_root_directory (
224
- get_ephys_root_data_dir (),
228
+ root_dir = find_root_directory (get_ephys_root_data_dir (),
225
229
probe_data .recording_info ['recording_files' ][0 ])
226
230
self .EphysFile .insert ([{** key ,
227
231
'file_path' : fp .relative_to (root_dir ).as_posix ()}
@@ -290,8 +294,11 @@ def make(self, key):
290
294
shank , shank_col , shank_row , _ = spikeglx_recording .apmeta .shankmap ['data' ][recorded_site ]
291
295
electrode_keys .append (probe_electrodes [(shank , shank_col , shank_row )])
292
296
elif acq_software == 'Open Ephys' :
293
- sess_dir = pathlib .Path (get_session_directory (key ))
294
- loaded_oe = openephys .OpenEphys (sess_dir )
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 )
295
302
oe_probe = loaded_oe .probes [probe_sn ]
296
303
297
304
lfp_channel_ind = np .arange (
@@ -442,16 +449,16 @@ class Curation(dj.Manual):
442
449
curation_id: int
443
450
---
444
451
curation_time: datetime # time of generation of this set of curated clustering results
445
- 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
446
453
quality_control: bool # has this clustering result undergone quality control?
447
454
manual_curation: bool # has manual curation been performed on this clustering result?
448
455
curation_note='': varchar(2000)
449
456
"""
450
457
451
458
def create1_from_clustering_task (self , key , curation_note = '' ):
452
459
"""
453
- A convenient function to create a new corresponding "Curation"
454
- for a particular "ClusteringTask"
460
+ A function to create a new corresponding "Curation" for a particular
461
+ "ClusteringTask"
455
462
"""
456
463
if key not in Clustering ():
457
464
raise ValueError (f'No corresponding entry in Clustering available'
@@ -465,8 +472,10 @@ def create1_from_clustering_task(self, key, curation_note=''):
465
472
# Synthesize curation_id
466
473
curation_id = dj .U ().aggr (self & key , n = 'ifnull(max(curation_id)+1,1)' ).fetch1 ('n' )
467
474
self .insert1 ({** key , 'curation_id' : curation_id ,
468
- 'curation_time' : creation_time , 'curation_output_dir' : output_dir ,
469
- '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 ,
470
479
'curation_note' : curation_note })
471
480
472
481
@@ -613,8 +622,9 @@ def yield_unit_waveforms():
613
622
spikeglx_meta_filepath = get_spikeglx_meta_filepath (key )
614
623
neuropixels_recording = spikeglx .SpikeGLX (spikeglx_meta_filepath .parent )
615
624
elif acq_software == 'Open Ephys' :
616
- sess_dir = pathlib .Path (get_session_directory (key ))
617
- openephys_dataset = openephys .OpenEphys (sess_dir )
625
+ session_dir = find_full_path (get_ephys_root_data_dir (),
626
+ get_session_directory (key ))
627
+ openephys_dataset = openephys .OpenEphys (session_dir )
618
628
neuropixels_recording = openephys_dataset .probes [probe_serial_number ]
619
629
620
630
def yield_unit_waveforms ():
@@ -659,11 +669,13 @@ def get_spikeglx_meta_filepath(ephys_recording_key):
659
669
except FileNotFoundError :
660
670
# if not found, search in session_dir again
661
671
if not spikeglx_meta_filepath .exists ():
662
- 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 ))
663
675
inserted_probe_serial_number = (ProbeInsertion * probe .Probe
664
676
& ephys_recording_key ).fetch1 ('probe' )
665
677
666
- 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' )]
667
679
for meta_filepath in spikeglx_meta_filepaths :
668
680
spikeglx_meta = spikeglx .SpikeGLXMeta (meta_filepath )
669
681
if str (spikeglx_meta .probe_SN ) == inserted_probe_serial_number :
@@ -696,8 +708,9 @@ def get_neuropixels_channel2electrode_map(ephys_recording_key, acq_software):
696
708
for recorded_site , (shank , shank_col , shank_row , _ ) in enumerate (
697
709
spikeglx_meta .shankmap ['data' ])}
698
710
elif acq_software == 'Open Ephys' :
699
- sess_dir = pathlib .Path (get_session_directory (ephys_recording_key ))
700
- openephys_dataset = openephys .OpenEphys (sess_dir )
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 )
701
714
probe_serial_number = (ProbeInsertion & ephys_recording_key ).fetch1 ('probe' )
702
715
probe_dataset = openephys_dataset .probes [probe_serial_number ]
703
716
0 commit comments