Skip to content

Commit

Permalink
Merge pull request #1501 from alejoe91/spikeglx-tcat
Browse files Browse the repository at this point in the history
Spikeglx: parse TCAT input
  • Loading branch information
alejoe91 authored Jul 8, 2024
2 parents 4b71f45 + 8867f03 commit 8d4dc9a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 26 deletions.
62 changes: 36 additions & 26 deletions neo/rawio/spikeglxrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,61 +387,71 @@ def parse_spikeglx_fname(fname):
Consider the filenames: `Noise4Sam_g0_t0.nidq.bin` or `Noise4Sam_g0_t0.imec0.lf.bin`
The filenames consist of 3 or 4 parts separated by `.`
1. "Noise4Sam_g0_t0" will be the `name` variable. This choosen by the user at recording time.
2. "_g0_" is the "gate_num"
3. "_t0_" is the "trigger_num"
2. "g0" is the "gate_num"
3. "t0" is the "trigger_num"
4. "nidq" or "imec0" will give the `device`
5. "lf" or "ap" will be the `stream_kind`
`stream_name` variable is the concatenation of `device.stream_kind`
`stream_name` variable is the concatenation of `device.stream_kind`
If CatGT is used, then the trigger numbers in the file names ("t0"/"t1"/etc.)
will be renamed to "tcat". In this case, the parsed "trigger_num" will be set to "cat".
This function is copied/modified from Graham Findlay.
Notes:
* Sometimes the original file name is modified by the user and "_gt0_" or "_t0_"
* Sometimes the original file name is modified by the user and "_g0_" or "_t0_"
are manually removed. In that case gate_name and trigger_num will be None.
Parameters
---------
fname: str
The filename to parse without the extension, e.g. "my-run-name_g0_t1.imec2.lf"
Returns
-------
run_name: str
The run name, e.g. "my-run-name".
gate_num: int or None
The gate identifier, e.g. 0.
trigger_num: int or None
The trigger identifier, e.g. 1.
trigger_num: int | str or None
The trigger identifier, e.g. 1. If CatGT is used, then the trigger_num will be set to "cat".
device: str
The probe identifier, e.g. "imec2"
stream_kind: str or None
The data type identifier, "lf" or "ap" or None
"""
r = re.findall(r"(\S*)_g(\d*)_t(\d*)\.(\S*).(ap|lf)", fname)
if len(r) == 1:
re_standard = re.findall(r"(\S*)_g(\d*)_t(\d*)\.(\S*).(ap|lf)", fname)
re_tcat = re.findall(r"(\S*)_g(\d*)_tcat.(\S*).(ap|lf)", fname)
re_nidq = re.findall(r"(\S*)_g(\d*)_t(\d*)\.(\S*)", fname)
if len(re_standard) == 1:
# standard case with probe
run_name, gate_num, trigger_num, device, stream_kind = r[0]
run_name, gate_num, trigger_num, device, stream_kind = re_standard[0]
elif len(re_tcat) == 1:
# tcat case
run_name, gate_num, device, stream_kind = re_tcat[0]
trigger_num = "cat"
elif len(re_nidq) == 1:
# case for nidaq
run_name, gate_num, trigger_num, device = re_nidq[0]
stream_kind = None
else:
r = re.findall(r"(\S*)_g(\d*)_t(\d*)\.(\S*)", fname)
if len(r) == 1:
# case for nidaq
run_name, gate_num, trigger_num, device = r[0]
stream_kind = None
# the naming do not correspond lets try something more easy
# example: sglx_xxx.imec0.ap
re_else = re.findall(r"(\S*)\.(\S*).(ap|lf)", fname)
re_else_nidq = re.findall(r"(\S*)\.(\S*)", fname)
if len(re_else) == 1:
run_name, device, stream_kind = re_else_nidq[0]
gate_num, trigger_num = None, None
elif len(re_else_nidq) == 1:
# easy case for nidaq, example: sglx_xxx.nidq
run_name, device = re_else_nidq[0]
gate_num, trigger_num, stream_kind = None, None, None
else:
# the naming do not correspond lets try something more easy
# example: sglx_xxx.imec0.ap
r = re.findall(r"(\S*)\.(\S*).(ap|lf)", fname)
if len(r) == 1:
run_name, device, stream_kind = r[0]
gate_num, trigger_num = None, None
else:
# easy case for nidaq, example: sglx_xxx.nidq
r = re.findall(r"(\S*)\.(\S*)", fname)
run_name, device = r[0]
gate_num, trigger_num, stream_kind = None, None, None
raise ValueError(f"Cannot parse filename {fname}")

if gate_num is not None:
gate_num = int(gate_num)
if trigger_num is not None:
if trigger_num is not None and trigger_num != "cat":
trigger_num = int(trigger_num)

return (run_name, gate_num, trigger_num, device, stream_kind)
Expand Down
7 changes: 7 additions & 0 deletions neo/test/rawiotest/test_spikeglxrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class TestSpikeGLXRawIO(BaseTestRawIO, unittest.TestCase):
"spikeglx/NP2_subset_with_sync",
# NP-ultra
"spikeglx/np_ultra_stub",
# CatGT
"spikeglx/multi_trigger_multi_gate/CatGT/CatGT-A",
"spikeglx/multi_trigger_multi_gate/CatGT/CatGT-B",
"spikeglx/multi_trigger_multi_gate/CatGT/CatGT-C",
"spikeglx/multi_trigger_multi_gate/CatGT/CatGT-D",
"spikeglx/multi_trigger_multi_gate/CatGT/CatGT-E",
"spikeglx/multi_trigger_multi_gate/CatGT/Supercat-A",
]

def test_with_location(self):
Expand Down

0 comments on commit 8d4dc9a

Please sign in to comment.