Skip to content

Latest commit

 

History

History
238 lines (168 loc) · 10.3 KB

README.md

File metadata and controls

238 lines (168 loc) · 10.3 KB

Stanford Stages

Automated sleep staging scoring and narcolepsy identification.

Instructions

Software requirements and instructions can be found here.

NOTE: The currently supported version of Python is >= 3.6. Previous versions of Python have been shown to yield erroneous results. We are actively looking into this issue.

Attribution

Please use the following citation when referencing this software.

Jens B. Stephansen, Alexander N. Olesen, Mads Olsen, Aditya Ambati, Eileen B. Leary, Hyatt E. Moore, Oscar Carrillo et al. "Neural network analysis of sleep stages enables efficient diagnosis of narcolepsy.". Nature Communications 9, Article number:5229 (2018).

@article{Stephansen2018,
author = {Stephansen, Jens B and Olesen, Alexander N and Olsen, Mads and Ambati, Aditya and Leary, Eileen B and Moore, Hyatt E and Carrillo, Oscar and Lin, Ling and Han, Fang and Yan, Han and Sun, Yun L and Dauvilliers, Yves and Scholz, Sabine and Barateau, Lucie and Hogl, Birgit and Stefani, Ambra and Hong, Seung Chul and Kim, Tae Won and Pizza, Fabio and Plazzi, Giuseppe and Vandi, Stefano and Antelmi, Elena and Perrin, Dimitri and Kuna, Samuel T and Schweitzer, Paula K and Kushida, Clete and Peppard, Paul E and Sorensen, Helge B. D. and Jennum, Poul and Mignot, Emmanuel},
doi = {10.1038/s41467-018-07229-3},
journal = {Nature Communications},
number = {5229},
title = {{Neural network analysis of sleep stages enables efficient diagnosis of narcolepsy}},
volume = {9},
year = {2018}
}

Initial configuration

Models

Classification models are hosted externally and should be downloaded and extracted into the repositories 'ml/' subfolder

When complete the 'ml/' directory tree should like:

ac/
gp/
noiseM.mat
scaling

Validation

The sleep study CHP_040.edf is may be used to verify your setup. It can be downloaded from the following mirrors:

  1. Mirror 1 [380 MB]
  2. Mirror 2 [380 MB]

The sleep study may be placed in any directory. Edit the shell script verify_chp_040.sh so that the absolute pathname for CHP040.edf is given for the FILENAME variable. In this example, it is assumed to have been saved to the directory /Users/unknown/data/sleep/narcoTest/ and so the the FILENAME variable should be set as follows:

FILENAME="/Users/unknown/data/sleep/narcoTest/CHP040.edf"

See the single model validation configuration

Using one model (quick check)

This validation tests your configuration using one model, 'ac_rh_ls_lstm_01' and is recommended as a first step to making sure the application is configured correctly simply because it takes less time to check than running all 16 models.

  1. Edit the inf_config.py file so that the model_used property is set as follows:
self.models_used = ['ac_rh_ls_lstm_01']
  1. Run the shell script from a command line terminal as:
sh ./verify_chp_040.sh
  1. Check results

Upon successful completion, a hypnogram file and hypnodensity image will be created and saved in the same directory as the input CHP040.edf file.

Expected results for the ac_rh_ls_lstm_01 hypnogram and hypnodensity results can be found here:

Expected diagnosis output is:

Score: -0.0076
Diagnosis: Narcolepsy type 1

Using all models

This validation tests your configuration using all 16 models and is the recommended way for running the application.

  1. Edit the inf_config.py file and ensure that model_used property is set as follows:
self.models_used = ['ac_rh_ls_lstm_01', 'ac_rh_ls_lstm_02',
                    'ac_rh_ls_lstm_03', 'ac_rh_ls_lstm_04',
                    'ac_rh_ls_lstm_05', 'ac_rh_ls_lstm_06',
                    'ac_rh_ls_lstm_07', 'ac_rh_ls_lstm_08',
                    'ac_rh_ls_lstm_09', 'ac_rh_ls_lstm_10',
                    'ac_rh_ls_lstm_11', 'ac_rh_ls_lstm_12',
                    'ac_rh_ls_lstm_13', 'ac_rh_ls_lstm_14',
                    'ac_rh_ls_lstm_15', 'ac_rh_ls_lstm_16']
  1. Run the shell script from a command line terminal as:
sh ./verify_chp_040.sh

Note: If the shell script has been run before using a single model, you will need to delete the previously cached "pickle" files. Edit the verify_chp_040.sh script and uncomment the line:

# rm /Users/unknown/data/sleep/narcoTest/CHP040.\*pkl

to remove any previously saved pickle files.

  1. Check results

Upon successful completion, a hypnogram file and hypnodensity image will be created and saved in the same directory as the input CHP040.edf file.

Expected results for may be found here:

Expected diagnosis output is:

Score: 0.1658
Diagnosis: Narcolepsy type 1

Output

Narcolepsy diagnosis

The algorithm produces values between −1 and 1, with 1 indicating a high probability of narcolepsy. The cut-off threshold between narcolepsy type 1 and “other“ is set at −0.03. See Neural network analysis of sleep stages enables efficient diagnosis of narcolepsy for details.

Hypnogram

The hypnogram provides a numeric indicator of wake or sleep stage for every epoch scored.
By default, epochs are scored in 15 s intervals as follows:

  • Wake: 0
  • Stage 1 sleep: 1
  • Stage 2 sleep: 2
  • Stage 3/4 sleep: 3
  • Rapid eye movement (REM) sleep: 5

Hypnodensity

Text

The hypnodensity text output is the same length (number of epochs/rows) as the hypnogram. Instead of a sleep score, however, five probabilities are given representing the likelihood of the sleep stage corresponding to its column for the current epoch. Probabilities are ordered starting with wake, and moving to deeper stages of sleep, with REM sleep last.

For example:

0.24 0.01 0.02 0.03 0.70

Represents

  • Wake: 24% likelihood
  • Stage 1 sleep: 1% likelihood
  • Stage 2 sleep: 2% likelihood
  • Stage 3/4 sleep: 3% likelihood
  • REM sleep: 70% likelihood

Image

The x-axis of the hypnodensity plot represents the epochs from the beginning to the end of the study, which are measured in 15 s intervals by default. The y-axis ranges from 0 to 1 and represents the hypnodensity - the probability of each sleep stage and wake.
Different colors are used to represent wake and each sleep stage. For each epoch, the probability of wake is drawn first as a vertical line to the proportion of the y-axis range it represents. Stage 1 is then stacked on top of this, followed by Stages 2, 3/4, and REM sleep such that the entire spectrum is covered. Color matching is as follows:

  • Wake: white
  • Stage 1 sleep: pink
  • Stage 2 sleep: aqua/turquoise
  • Stage 3/4 sleep: blue
  • REM sleep: green

Input

JSON arguments

Javascript object notation (json) is used for passing parameters to the application.

Three parameters that can be adjusted include setting the channel indices for input, and what output should be printed to the screen and/or saved to disk.
The keys for these parameters, and their corresponding definitions are as follows:

  • channel_indices

    • Description Assigns channel indices corresponding to the central, occipital, occular, and chin EMG. One or two EEG channels may be assigned to the central and occipital categories. Both left and right EOG channels are required for the corresponding occular category, and one channel is required for the chin EMG. In the event that two channels are presented for an EEG category (central or occipital), a quality metric is calculated for each channel, and the optimal channel is selected for use. Channel indices are 0 based and correspond to the channel labels list provided in the .EDF file header.
    • Supported keys and values
      • central: C3 or C4 channel index
      • central3: C3 channel index
      • central4: C4 channel index
      • centrals: [C3 channel index, C4 channel index]
      • occipital: O1 or O2 channel index
      • occipital1: O1 channel index
      • occipital2: O2 channel index
      • occipitals: [O1 channel index, O2 channel index]
      • eog_l: Left EOG channel index
      • eog_r: Right EOG channel index
      • eogs: [Left EOG channel index, Right EOG channel index]
      • chin_emg: EMG channel index
  • show

    • Description Flags for determining which results are output to the console.
    • Supported keys: allowed and [default] values
      • plot: true or [false]
      • hypnodensity: true or [false]
      • hypnogram: true or [false]
      • diagnosis: [true] or false
  • save

    • Description Flags for determining which results are saved to disk. Files are saved to the same directory as the input .edf file. Save filenames are generated by pairing the .edf file's basename with the file extension matching the output type requested.
    • Supported keys: allowed and [default] values (file extension used by default when true)
      • plot: [true] or false (.hypnodensity.png)
      • hypnodensity: [true] or false (.hypnodensity.txt)
      • hypnogram: [true] or false (.hypnogram.txt)
      • diagnosis: [true] or false (.diagnosis.txt)
  • filename

    • Description Alternative filename to use in place of the default naming convention and path location used when saving results.
    • Supported keys
      • plot: Full path for hypnodensity image file
      • hypnodensity: Full path for hypnodensity output text file
      • hypnogram: Full path for hypnogram output text file
      • diagnosis: Full path for diagnosis output text file