66import importlib
77from decimal import Decimal
88
9+ from element_interface .utils import find_root_directory , find_full_path , dict_to_uuid
10+
911from .readers import spikeglx , kilosort , openephys
10- from . import probe , find_full_path , find_root_directory , dict_to_uuid , get_logger
12+ from . import probe , get_logger
13+
1114
1215log = get_logger (__name__ )
1316
@@ -52,7 +55,6 @@ def activate(ephys_schema_name, probe_schema_name=None, *, create_schema=True,
5255 global _linking_module
5356 _linking_module = linking_module
5457
55- # activate
5658 probe .activate (probe_schema_name , create_schema = create_schema ,
5759 create_tables = create_tables )
5860 schema .activate (ephys_schema_name , create_schema = create_schema ,
@@ -63,9 +65,10 @@ def activate(ephys_schema_name, probe_schema_name=None, *, create_schema=True,
6365
6466def get_ephys_root_data_dir () -> list :
6567 """
66- All data paths, directories in DataJoint Elements are recommended to be stored as
67- relative paths, with respect to some user-configured "root" directory,
68- which varies from machine to machine (e.g. different mounted drive locations)
68+ All data paths, directories in DataJoint Elements are recommended to be
69+ stored as relative paths, with respect to some user-configured "root"
70+ directory, which varies from machine to machine (e.g. different mounted
71+ drive locations)
6972
7073 get_ephys_root_data_dir() -> list
7174 This user-provided function retrieves the possible root data directories
@@ -91,7 +94,7 @@ def get_session_directory(session_key: dict) -> str:
9194 Retrieve the session directory containing the
9295 recorded Neuropixels data for a given Session
9396 :param session_key: a dictionary of one Session `key`
94- :return: a string for full path to the session directory
97+ :return: a string for relative or full path to the session directory
9598 """
9699 return _linking_module .get_session_directory (session_key )
97100
@@ -224,21 +227,22 @@ class EphysFile(dj.Part):
224227 """
225228
226229 def make (self , key ):
227- sess_dir = find_full_path (get_ephys_root_data_dir (),
230+ session_dir = find_full_path (get_ephys_root_data_dir (),
228231 get_session_directory (key ))
229232 inserted_probe_serial_number = (ProbeInsertion * probe .Probe & key ).fetch1 ('probe' )
230233
231234 # search session dir and determine acquisition software
232235 for ephys_pattern , ephys_acq_type in zip (['*.ap.meta' , '*.oebin' ],
233236 ['SpikeGLX' , 'Open Ephys' ]):
234- ephys_meta_filepaths = list (sess_dir .rglob (ephys_pattern ))
237+ ephys_meta_filepaths = list (session_dir .rglob (ephys_pattern ))
235238 if ephys_meta_filepaths :
236239 acq_software = ephys_acq_type
237240 break
238241 else :
239242 raise FileNotFoundError (
240243 f'Ephys recording data not found!'
241- f' Neither SpikeGLX nor Open Ephys recording files found' )
244+ f' Neither SpikeGLX nor Open Ephys recording files found'
245+ f' in { session_dir } ' )
242246
243247 supported_probe_types = probe .ProbeType .fetch ('probe_type' )
244248
@@ -277,12 +281,13 @@ def make(self, key):
277281 'recording_duration' : (spikeglx_meta .recording_duration
278282 or spikeglx .retrieve_recording_duration (meta_filepath ))})
279283
280- root_dir = find_root_directory (get_ephys_root_data_dir (), meta_filepath )
284+ root_dir = find_root_directory (get_ephys_root_data_dir (),
285+ meta_filepath )
281286 self .EphysFile .insert1 ({
282287 ** key ,
283288 'file_path' : meta_filepath .relative_to (root_dir ).as_posix ()})
284289 elif acq_software == 'Open Ephys' :
285- dataset = openephys .OpenEphys (sess_dir )
290+ dataset = openephys .OpenEphys (session_dir )
286291 for serial_number , probe_data in dataset .probes .items ():
287292 if str (serial_number ) == inserted_probe_serial_number :
288293 break
@@ -313,8 +318,7 @@ def make(self, key):
313318 'recording_datetime' : probe_data .recording_info ['recording_datetimes' ][0 ],
314319 'recording_duration' : np .sum (probe_data .recording_info ['recording_durations' ])})
315320
316- root_dir = find_root_directory (
317- get_ephys_root_data_dir (),
321+ root_dir = find_root_directory (get_ephys_root_data_dir (),
318322 probe_data .recording_info ['recording_files' ][0 ])
319323 self .EphysFile .insert ([{** key ,
320324 'file_path' : fp .relative_to (root_dir ).as_posix ()}
@@ -661,16 +665,16 @@ class Curation(dj.Manual):
661665 curation_id: int
662666 ---
663667 curation_time: datetime # time of generation of this set of curated clustering results
664- curation_output_dir: varchar(255) # output directory of the curated results, relative to clustering root data directory
668+ curation_output_dir: varchar(255) # output directory of the curated results, relative to root data directory
665669 quality_control: bool # has this clustering result undergone quality control?
666670 manual_curation: bool # has manual curation been performed on this clustering result?
667671 curation_note='': varchar(2000)
668672 """
669673
670674 def create1_from_clustering_task (self , key , curation_note = '' ):
671675 """
672- A convenient function to create a new corresponding "Curation"
673- for a particular "ClusteringTask"
676+ A function to create a new corresponding "Curation" for a particular
677+ "ClusteringTask"
674678 """
675679 if key not in Clustering ():
676680 raise ValueError (f'No corresponding entry in Clustering available'
@@ -684,8 +688,10 @@ def create1_from_clustering_task(self, key, curation_note=''):
684688 # Synthesize curation_id
685689 curation_id = dj .U ().aggr (self & key , n = 'ifnull(max(curation_id)+1,1)' ).fetch1 ('n' )
686690 self .insert1 ({** key , 'curation_id' : curation_id ,
687- 'curation_time' : creation_time , 'curation_output_dir' : output_dir ,
688- 'quality_control' : is_qc , 'manual_curation' : is_curated ,
691+ 'curation_time' : creation_time ,
692+ 'curation_output_dir' : output_dir ,
693+ 'quality_control' : is_qc ,
694+ 'manual_curation' : is_curated ,
689695 'curation_note' : curation_note })
690696
691697
@@ -835,9 +841,9 @@ def yield_unit_waveforms():
835841 spikeglx_meta_filepath = get_spikeglx_meta_filepath (key )
836842 neuropixels_recording = spikeglx .SpikeGLX (spikeglx_meta_filepath .parent )
837843 elif acq_software == 'Open Ephys' :
838- sess_dir = find_full_path (get_ephys_root_data_dir (),
839- get_session_directory (key ))
840- openephys_dataset = openephys .OpenEphys (sess_dir )
844+ session_dir = find_full_path (get_ephys_root_data_dir (),
845+ get_session_directory (key ))
846+ openephys_dataset = openephys .OpenEphys (session_dir )
841847 neuropixels_recording = openephys_dataset .probes [probe_serial_number ]
842848
843849 def yield_unit_waveforms ():
@@ -884,12 +890,13 @@ def get_spikeglx_meta_filepath(ephys_recording_key):
884890 except FileNotFoundError :
885891 # if not found, search in session_dir again
886892 if not spikeglx_meta_filepath .exists ():
887- sess_dir = find_full_path (get_ephys_root_data_dir (),
888- get_session_directory (ephys_recording_key ))
893+ session_dir = find_full_path (get_ephys_root_data_dir (),
894+ get_session_directory (
895+ ephys_recording_key ))
889896 inserted_probe_serial_number = (ProbeInsertion * probe .Probe
890897 & ephys_recording_key ).fetch1 ('probe' )
891898
892- spikeglx_meta_filepaths = [fp for fp in sess_dir .rglob ('*.ap.meta' )]
899+ spikeglx_meta_filepaths = [fp for fp in session_dir .rglob ('*.ap.meta' )]
893900 for meta_filepath in spikeglx_meta_filepaths :
894901 spikeglx_meta = spikeglx .SpikeGLXMeta (meta_filepath )
895902 if str (spikeglx_meta .probe_SN ) == inserted_probe_serial_number :
0 commit comments