yasa icon indicating copy to clipboard operation
yasa copied to clipboard

YASA for automatic rodent sleep staging

Open kshtjkumar opened this issue 8 months ago • 3 comments

Hi, I have long-duration screw EEG recordings from a mouse model and would like to perform automatic sleep staging to distinguish between sleep and wake states. The primary goal is to accurately identify when the animal is asleep versus awake.

I’ve tried using the existing sleep staging algorithm in YASA, which is trained on human data, but I’m unsure whether it’s valid for use with rodent EEG. I also came across the YASA issue thread discussing rodent data support, but unfortunately, there’s no example notebook available for implementation.

Could you please guide me on how to classify sleep versus wake using only EEG data from rodents? I do not have EMG recordings—only 4 channels of EEG are available.

Thank you

kshtjkumar avatar Apr 04 '25 14:04 kshtjkumar

Could you please guide me on how to classify sleep versus wake using only EEG data from rodents? I do not have EMG recordings—only 4 channels of EEG are available.

As you've pointed out, this is not possible using YASA in its current form. I am not aware of anyone actively developing this feature but there seems to be a lot of interest if you would be willing to take it on! See also the FAQ question Can I use YASA to score animal data...?. Related to #72 and #212.

remrama avatar Apr 04 '25 18:04 remrama

hi @remrama, I tried the SleepStgaing function written in #72, but since am new to this am not sure if I have made an error or something is missing, I get this error when i try to predict:

NameError                                 Traceback (most recent call last)
Cell In[8], line 16
     14 for i in raw.ch_names:
     15     sls = SleepStaging(raw, eeg_name=i) # C4 = 6
---> 16     sls.predict()
     17     sls.predict_proba()
     18     sls.plot_predict_proba()

Cell In[7], line 426, in SleepStaging.predict(self, path_to_model, epoch_sec, bands)
    424     self.fit(epoch_sec, bands)
    425 # Load and validate pre-trained classifier
--> 426 clf = self._load_model(path_to_model)
    427 # Now we make sure that the features are aligned
    428 X = self._features.copy()[clf.featurename]

Cell In[7], line 386, in SleepStaging._load_model(self, path_to_model)
    384 if path_to_model == "auto":
    385     from pathlib import Path
--> 386     clf_dir = os.path.join(str(Path(file).parent), 'classifiers/')
    387     name = 'clf_eeg'
    388     name = name + '+eog' if 'eog' in self.ch_types else name

NameError: name 'file' is not defined

kshtjkumar avatar Apr 06 '25 14:04 kshtjkumar

Looking back at #72 I think that line has __file__, not file.

But also just a heads up that the code in that Issue is not fully supported yet. It's not guaranteed to work and I don't have any experience with it so I can't troubleshoot much. So I expect it will require some effort to make it all work. If you get it working and find it useful please mention that here and we can consider merging into YASA!

remrama avatar Apr 06 '25 17:04 remrama