Skip to content

Commit 733ca57

Browse files
committed
Support tcat in parse_spikeglx_name
1 parent a54c191 commit 733ca57

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

neo/rawio/spikeglxrawio.py

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -396,52 +396,60 @@ def parse_spikeglx_fname(fname):
396396
This function is copied/modified from Graham Findlay.
397397
398398
Notes:
399-
* Sometimes the original file name is modified by the user and "_gt0_" or "_t0_"
399+
* Sometimes the original file name is modified by the user and "_gt0_" or "_t0_"
400400
are manually removed. In that case gate_name and trigger_num will be None.
401+
* If tcat is used, then the trigger_num will be set to "cat".
401402
402403
Parameters
403404
---------
404405
fname: str
405406
The filename to parse without the extension, e.g. "my-run-name_g0_t1.imec2.lf"
407+
406408
Returns
407409
-------
408410
run_name: str
409411
The run name, e.g. "my-run-name".
410412
gate_num: int or None
411413
The gate identifier, e.g. 0.
412-
trigger_num: int or None
413-
The trigger identifier, e.g. 1.
414+
trigger_num: int | str or None
415+
The trigger identifier, e.g. 1. If tcat is used, then the trigger_num will be set to "cat".
414416
device: str
415417
The probe identifier, e.g. "imec2"
416418
stream_kind: str or None
417419
The data type identifier, "lf" or "ap" or None
418420
"""
419-
r = re.findall(r"(\S*)_g(\d*)_t(\d*)\.(\S*).(ap|lf)", fname)
420-
if len(r) == 1:
421+
re_standard = re.findall(r"(\S*)_g(\d*)_t(\d*)\.(\S*).(ap|lf)", fname)
422+
re_tcat = re.findall(r"(\S*)_g(\d*)_tcat.(\S*).(ap|lf)", fname)
423+
re_nidq = re.findall(r"(\S*)_g(\d*)_t(\d*)\.(\S*)", fname)
424+
if len(re_standard) == 1:
421425
# standard case with probe
422-
run_name, gate_num, trigger_num, device, stream_kind = r[0]
426+
run_name, gate_num, trigger_num, device, stream_kind = re_standard[0]
427+
elif len(re_tcat) == 1:
428+
# tcat case
429+
run_name, gate_num, device, stream_kind = re_tcat[0]
430+
trigger_num = "cat"
431+
elif len(re_nidq) == 1:
432+
# case for nidaq
433+
run_name, gate_num, trigger_num, device = re_nidq[0]
434+
stream_kind = None
423435
else:
424-
r = re.findall(r"(\S*)_g(\d*)_t(\d*)\.(\S*)", fname)
425-
if len(r) == 1:
426-
# case for nidaq
427-
run_name, gate_num, trigger_num, device = r[0]
428-
stream_kind = None
436+
# the naming do not correspond lets try something more easy
437+
# example: sglx_xxx.imec0.ap
438+
re_else = re.findall(r"(\S*)\.(\S*).(ap|lf)", fname)
439+
re_else_nidq = re.findall(r"(\S*)\.(\S*)", fname)
440+
if len(re_else) == 1:
441+
run_name, device, stream_kind = re_else_nidq[0]
442+
gate_num, trigger_num = None, None
443+
elif len(re_else_nidq) == 1:
444+
# easy case for nidaq, example: sglx_xxx.nidq
445+
run_name, device = re_else_nidq[0]
446+
gate_num, trigger_num, stream_kind = None, None, None
429447
else:
430-
# the naming do not correspond lets try something more easy
431-
# example: sglx_xxx.imec0.ap
432-
r = re.findall(r"(\S*)\.(\S*).(ap|lf)", fname)
433-
if len(r) == 1:
434-
run_name, device, stream_kind = r[0]
435-
gate_num, trigger_num = None, None
436-
else:
437-
# easy case for nidaq, example: sglx_xxx.nidq
438-
r = re.findall(r"(\S*)\.(\S*)", fname)
439-
run_name, device = r[0]
440-
gate_num, trigger_num, stream_kind = None, None, None
448+
raise ValueError(f"Cannot parse filename {fname}")
441449

442450
if gate_num is not None:
443451
gate_num = int(gate_num)
444-
if trigger_num is not None:
452+
if trigger_num is not None and trigger_num != "cat":
445453
trigger_num = int(trigger_num)
446454

447455
return (run_name, gate_num, trigger_num, device, stream_kind)

0 commit comments

Comments
 (0)