@@ -360,7 +360,7 @@ class Clustering(dj.Imported):
360
360
"""
361
361
A processing table to handle each ClusteringTask:
362
362
+ 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
364
364
"""
365
365
definition = """
366
366
-> ClusteringTask
@@ -375,24 +375,19 @@ def make(self, key):
375
375
376
376
if task_mode == 'load' :
377
377
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 )
386
379
elif task_mode == 'trigger' :
387
380
raise NotImplementedError ('Automatic triggering of clustering analysis is not yet supported' )
388
381
else :
389
382
raise ValueError (f'Unknown task mode: { task_mode } ' )
390
383
384
+ self .insert1 ({** key , 'clustering_time' : creation_time })
385
+
391
386
392
387
@schema
393
388
class Curation (dj .Manual ):
394
389
definition = """
395
- -> ClusteringTask
390
+ -> Clustering
396
391
curation_id: int
397
392
---
398
393
curation_time: datetime # time of generation of this set of curated clustering results
@@ -402,6 +397,24 @@ class Curation(dj.Manual):
402
397
curation_note='': varchar(2000)
403
398
"""
404
399
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
+
405
418
406
419
@schema
407
420
class Unit (dj .Imported ):
0 commit comments