You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def get_sub(inst: Signal | mne.Info | str) -> str:
"""Gets the subject from the instance
Parameters
----------
inst : Signal
The instance to get the subject from
Returns
-------
str
The subject"""
if isinstance(inst, Signal):
inst = inst.info
elif isinstance(inst, str):
return f"{inst[0]}{int(inst[1:])}"
out_str = inst['subject_info']['his_id'][4:]
if len(out_str) == 1:
return out_str
return out_str[0] + str(int("".join(s for s in out_str if s.isdigit())))
The current implementation of get_sub (located in ieeg/viz/mri.py) will strip away the letters in a subject name, if they exist. For example, inputting D0107A will return D107, not D107A.
I propose a new implementation of get_sub below that just strips the leading zeroes. It will strip zeroes until it encounters a non-zero value. This should keep the suffix intact. For example, inputting D0107A will return D107A.
import re
def get_sub(inst: Signal | mne.Info | str) -> str:
"""Gets the subject ID from the instance, removes leading zeros from the numeric parts,
and preserves any letters (e.g., 'D0107A' becomes 'D107A', 'D0059A' becomes 'D59A').
Parameters
----------
inst : Signal | mne.Info | str
The instance (Signal, Info, or string) to get the subject ID from.
Returns
-------
str
The subject ID with leading zeros removed from the numeric parts (e.g., 'D0107A' becomes 'D107A').
"""
if isinstance(inst, Signal):
inst = inst.info
# If the instance is a string, return it after processing
if isinstance(inst, str):
# Use regex to match and remove leading zeros from the first numeric part
return re.sub(r'(\D*)(0*)(\d+)', lambda m: m.group(1) + m.group(3), inst)
# Extract subject ID from 'subject_info'
out_str = inst['subject_info']['his_id'][4:]
# Use regex to match and remove leading zeros from the first numeric part
return re.sub(r'(\D*)(0*)(\d+)', lambda m: m.group(1) + m.group(3), out_str)
The text was updated successfully, but these errors were encountered:
jimzhang629
changed the title
get_sub does not work with D107A because it has a letter in it's name
get_sub does not work with D107A because it has a letter in its name
Sep 24, 2024
The current implementation of get_sub (located in ieeg/viz/mri.py) will strip away the letters in a subject name, if they exist. For example, inputting D0107A will return D107, not D107A.
I propose a new implementation of get_sub below that just strips the leading zeroes. It will strip zeroes until it encounters a non-zero value. This should keep the suffix intact. For example, inputting D0107A will return D107A.
The text was updated successfully, but these errors were encountered: