Skip to content

Commit 6859e52

Browse files
author
Thinh Nguyen
committed
Curation downstream from Clustering - move Curation insertion in Clustering.make() to a separate utility function
1 parent 64bd47d commit 6859e52

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

elements_ephys/ephys.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ class Clustering(dj.Imported):
360360
"""
361361
A processing table to handle each ClusteringTask:
362362
+ If `task_mode == "trigger"`: trigger clustering analysis according to the ClusteringParamSet (e.g. launch a kilosort job)
363-
+ If `task_mode == "load"`: verify output and create a corresponding entry in the Curation table
363+
+ If `task_mode == "load"`: verify output
364364
"""
365365
definition = """
366366
-> ClusteringTask
@@ -375,24 +375,19 @@ def make(self, key):
375375

376376
if task_mode == 'load':
377377
ks = kilosort.Kilosort(ks_dir) # check if the directory is a valid Kilosort output
378-
creation_time, is_curated, is_qc = kilosort.extract_clustering_info(ks_dir)
379-
# Synthesize curation_id
380-
curation_id = (dj.U().aggr(Curation & key, n='max(curation_id)').fetch1('n') or 0) + 1
381-
382-
self.insert1({**key, 'clustering_time': creation_time})
383-
Curation.insert1({**key, 'curation_id': curation_id,
384-
'curation_time': creation_time, 'curation_output_dir': output_dir,
385-
'quality_control': is_qc, 'manual_curation': is_curated})
378+
creation_time, _, _ = kilosort.extract_clustering_info(ks_dir)
386379
elif task_mode == 'trigger':
387380
raise NotImplementedError('Automatic triggering of clustering analysis is not yet supported')
388381
else:
389382
raise ValueError(f'Unknown task mode: {task_mode}')
390383

384+
self.insert1({**key, 'clustering_time': creation_time})
385+
391386

392387
@schema
393388
class Curation(dj.Manual):
394389
definition = """
395-
-> ClusteringTask
390+
-> Clustering
396391
curation_id: int
397392
---
398393
curation_time: datetime # time of generation of this set of curated clustering results
@@ -402,6 +397,24 @@ class Curation(dj.Manual):
402397
curation_note='': varchar(2000)
403398
"""
404399

400+
def create1_from_clustering_task(self, key, curation_note=''):
401+
"""
402+
A convenient function to create a new corresponding "Curation" for a particular "ClusteringTask"
403+
"""
404+
if not len(Clustering & key):
405+
raise ValueError(f'No corresponding entry in Clustering available for: {key}; do `Clustering.populate(key)`')
406+
407+
root_dir = pathlib.Path(get_ephys_root_data_dir())
408+
task_mode, output_dir = (ClusteringTask & key).fetch1('task_mode', 'clustering_output_dir')
409+
ks_dir = root_dir / output_dir
410+
creation_time, is_curated, is_qc = kilosort.extract_clustering_info(ks_dir)
411+
# Synthesize curation_id
412+
curation_id = (dj.U().aggr(self & key, n='max(curation_id)').fetch1('n') or 0) + 1
413+
self.insert1({**key, 'curation_id': curation_id,
414+
'curation_time': creation_time, 'curation_output_dir': output_dir,
415+
'quality_control': is_qc, 'manual_curation': is_curated,
416+
'curation_note': curation_note})
417+
405418

406419
@schema
407420
class Unit(dj.Imported):

0 commit comments

Comments
 (0)