Skip to content

Commit ce90dc6

Browse files
author
Thinh Nguyen
committed
specify a separate get_clustering_root_data_dir() - handle cases where raw ephys and clustering results are stored a different root locations (e.g. different mount points)
1 parent 4185ba3 commit ce90dc6

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

element_array_ephys/ephys.py

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ def activate(ephys_schema_name, probe_schema_name=None, *, create_schema=True,
3434
+ get_ephys_root_data_dir() -> str
3535
Retrieve the root data directory - e.g. containing all subject/sessions data
3636
:return: a string for full path to the root data directory
37+
+ get_clustering_root_data_dir() -> str
38+
Retrieve the root data directory containing all subject/sessions clustering data
39+
Note: if not provided, use "get_ephys_root_data_dir()"
40+
:return: a string for full path to the clustering root data directory
3741
+ get_session_directory(session_key: dict) -> str
3842
Retrieve the session directory containing the recorded Neuropixels data for a given Session
3943
:param session_key: a dictionary of one Session `key`
@@ -60,12 +64,25 @@ def activate(ephys_schema_name, probe_schema_name=None, *, create_schema=True,
6064
def get_ephys_root_data_dir() -> str:
6165
"""
6266
get_ephys_root_data_dir() -> str
63-
Retrieve the root data directory - e.g. containing all subject/sessions data
64-
:return: a string for full path to the root data directory
67+
Retrieve the root data directory - e.g. containing all subject/sessions ephys data
68+
:return: a string for full path to the ephys root data directory
6569
"""
6670
return _linking_module.get_ephys_root_data_dir()
6771

6872

73+
def get_clustering_root_data_dir() -> str:
74+
"""
75+
get_clustering_root_data_dir() -> str
76+
Retrieve the root data directory containing all subject/sessions clustering data
77+
Note: if not provided, use "get_ephys_root_data_dir()"
78+
:return: a string for full path to the clustering root data directory
79+
"""
80+
if not hasattr(_linking_module, 'get_clustering_root_data_dir'):
81+
return get_ephys_root_data_dir()
82+
83+
return _linking_module.get_clustering_root_data_dir()
84+
85+
6986
def get_session_directory(session_key: dict) -> str:
7087
"""
7188
get_session_directory(session_key: dict) -> str
@@ -396,7 +413,7 @@ class Clustering(dj.Imported):
396413
"""
397414

398415
def make(self, key):
399-
root_dir = pathlib.Path(get_ephys_root_data_dir())
416+
root_dir = pathlib.Path(get_clustering_root_data_dir())
400417
task_mode, output_dir = (ClusteringTask & key).fetch1(
401418
'task_mode', 'clustering_output_dir')
402419
ks_dir = root_dir / output_dir
@@ -435,7 +452,7 @@ def create1_from_clustering_task(self, key, curation_note=''):
435452
raise ValueError(f'No corresponding entry in Clustering available'
436453
f' for: {key}; do `Clustering.populate(key)`')
437454

438-
root_dir = pathlib.Path(get_ephys_root_data_dir())
455+
root_dir = pathlib.Path(get_clustering_root_data_dir())
439456
task_mode, output_dir = (ClusteringTask & key).fetch1(
440457
'task_mode', 'clustering_output_dir')
441458
ks_dir = root_dir / output_dir
@@ -468,7 +485,7 @@ class Unit(dj.Part):
468485
"""
469486

470487
def make(self, key):
471-
root_dir = pathlib.Path(get_ephys_root_data_dir())
488+
root_dir = pathlib.Path(get_clustering_root_data_dir())
472489
ks_dir = root_dir / (Curation & key).fetch1('curation_output_dir')
473490
ks = kilosort.Kilosort(ks_dir)
474491
acq_software = (EphysRecording & key).fetch1('acq_software')
@@ -539,7 +556,7 @@ def key_source(self):
539556
return Curation()
540557

541558
def make(self, key):
542-
root_dir = pathlib.Path(get_ephys_root_data_dir())
559+
root_dir = pathlib.Path(get_clustering_root_data_dir())
543560
ks_dir = root_dir / (Curation & key).fetch1('curation_output_dir')
544561
ks = kilosort.Kilosort(ks_dir)
545562

@@ -572,8 +589,9 @@ def make(self, key):
572589
'peak_chn_waveform_mean': channel_waveform})
573590
else:
574591
if acq_software == 'SpikeGLX':
575-
npx_meta_fp = root_dir / (EphysRecording.EphysFile & key
576-
& 'file_path LIKE "%.ap.meta"').fetch1('file_path')
592+
ephys_root_dir = get_ephys_root_data_dir()
593+
npx_meta_fp = ephys_root_dir / (EphysRecording.EphysFile & key
594+
& 'file_path LIKE "%.ap.meta"').fetch1('file_path')
577595
npx_recording = spikeglx.SpikeGLX(npx_meta_fp.parent)
578596
elif acq_software == 'OpenEphys':
579597
sess_dir = pathlib.Path(get_session_directory(key))
@@ -636,8 +654,8 @@ def get_neuropixels_channel2electrode_map(ephys_recording_key, acq_software):
636654
root_dir = pathlib.Path(get_ephys_root_data_dir())
637655
if acq_software == 'SpikeGLX':
638656
npx_meta_path = root_dir / (EphysRecording.EphysFile
639-
& ephys_recording_key
640-
& 'file_path LIKE "%.ap.meta"').fetch1('file_path')
657+
& ephys_recording_key
658+
& 'file_path LIKE "%.ap.meta"').fetch1('file_path')
641659
neuropixels_dir = (root_dir / npx_meta_path).parent
642660

643661
meta_filepath = next(pathlib.Path(neuropixels_dir).glob('*.ap.meta'))
@@ -651,9 +669,9 @@ def get_neuropixels_channel2electrode_map(ephys_recording_key, acq_software):
651669
for recorded_site, (shank, shank_col, shank_row, _) in enumerate(
652670
spikeglx_meta.shankmap['data']):
653671
channel2electrode_map[recorded_site] = (q_electrodes
654-
& {'shank': shank,
655-
'shank_col': shank_col,
656-
'shank_row': shank_row}).fetch1('KEY')
672+
& {'shank': shank,
673+
'shank_col': shank_col,
674+
'shank_row': shank_row}).fetch1('KEY')
657675
elif acq_software == 'OpenEphys':
658676
sess_dir = pathlib.Path(get_session_directory(ephys_recording_key))
659677
loaded_oe = openephys.OpenEphys(sess_dir)
@@ -665,7 +683,8 @@ def get_neuropixels_channel2electrode_map(ephys_recording_key, acq_software):
665683
* EphysRecording & ephys_recording_key)
666684
channel2electrode_map = {}
667685
for chn_idx in oe_probe.ap_meta['channels_ids']:
668-
channel2electrode_map[chn_idx] = (q_electrodes & {'electrode': chn_idx}).fetch1('KEY')
686+
channel2electrode_map[chn_idx] = (q_electrodes
687+
& {'electrode': chn_idx}).fetch1('KEY')
669688

670689
return channel2electrode_map
671690

0 commit comments

Comments
 (0)