The Lab
Our GitHub

Spooky Spikes

Instructions and Documentation

Developed by: Luka Zivkovic, and Srdjan Sumarac

Translational Neurophysiology and Brain Stimulation Lab
University of Toronto
University Health Network

Table of Contents


Spooky Spikes is a Python-based analysis tool for extracting features from electrophysiological data obtained through microelectrode recordings. The following documentation outlines important points of instruction pertaining to the tool's installation and functionality.

1. Installation and Launch

For the installation and launch of the Spooky Spikes analysis tool, please follow the steps enumerated below.

  1. Navigate to the corresponding Releases page within the application's GitHub repository.
  2. Download and run the latest Spooky Spikes installer application.
  3. Follow the instructions on the Spooky Spikes installer and complete all the required steps.
  4. Navigate to and click on the executable file named "Spooky Spikes" within the downloaded program folder.

You may create a shortcut targeting this final executable file to be displayed on your Desktop. The entire program folder may also be moved to any location. However, please ensure all files installed remain within the program folder. Otherwise, the application will not run.

2. Functionality

2.1. Importing Data

Electrophysiological signals can be imported in the “Source Data” section of the main panel (Figure 1). Spooky Spikes supports importing data from Spike2 datafiles (*.smr, *.smrx), comma-separated values format (CSV; *.csv), and MAT-Files (*.mat). For file requirements pertaining to each file extension, please refer to Table 1.

Filetype Requirements
Spike2 (*.smr, *.smrx)
  • At least one non-empty channel of type Adc/Waveform or RealWave.
MATLAB (*.mat)
  • Variables containing signal arrays should be named “values#”, where “#” is a unique integer signal ID for each array (e.g. values1, values2, …).
  • Each array variable should have an additional corresponding sampling frequency variable using the same naming convention “fs#” (e.g. fs1, fs2, …).
  • All variables not following the naming convention defined above will be ignored.
Comma Separated Values (*.csv)
  • Columns containing signal arrays should be named “values#”, where “#” is a unique integer signal ID for each array (e.g. values1, values2, …).
  • Each array column should have an additional corresponding sampling frequency column using the same naming convention “fs#” (e.g. fs1, fs2, …).
  • All columns not following the naming convention defined above will be ignored.

Table 1: the supported filetypes require specific internal structuring in order to be correctly interpreted by Spooky Spikes. This tables outlines file requirements for Spike2, CSV, and MAT-File formats.

After importing one of the supported filetypes, you will be able to select the signal contained within the file using the dropdown menu in the “Source Channel” section of the main panel on the left side of the dashboard (Figure 1). This menu will appear differently depending on the filetype selected. However, upon importing a file, the first signal found will be selected by default and displayed in the main tab.

Figure 1: initial state of the Spooky Spikes dashboard upon initial launch, outlining the general display and structure of the application.

2.2. Signal Preparation and Visualization

This section will introduce various preparatory steps available on the “Main” tab and left panel, which are to be taken before all signal features can be computed and displayed. These include filtering, peak threshold selection, threshold inversion, and signal visualization.

2.2.1. Filtering

By default, the filtering feature is disabled. To enable it, select the “Filtering” checkbox on the left panel in the “Parameters” section (Figure 1). This will allow the user to enter high-pass and low-pass frequency cutoffs for a fourth-order Butterworth filter that is applied to the imported signal. To utilize the frequency cutoffs for the filter, enter them into the corresponding widgets and press the “Set” button on the “Main” tab within the “Signal filtering” section. The signal will be updated on the main plot immediately upon setting cutoff frequencies. Please see Figure 2 for an example of setting frequency cutoffs in the correct dashboard sections.

If the user enters both high-pass and low-pass cutoffs, a bandpass filter design is applied. If only one of either a high-pass or low-pass cutoff is set, then a high-pass or low-pass filter design is applied, respectively. To disapply filtering and retain the raw data, users can either uncheck the “Filtering” checkbox, or clear the frequency cutoff entries, and press the “Set” button alongside empty widget boxes.

2.2.2. Threshold Selection

In order for various spike-dependent features to be computed, a threshold-crossing method is first applied to detect peaks of action potentials within the electrophysiological data. Within the “Threshold” section of the “Main” tab, the user can enter a scaling factor that is applied to the median absolute deviation (MAD) of the data. Press “Set” within the same section to apply the factor and calculate the threshold (Figure 2). Spike peaks will be computed immediately and will be available for visualization. If no threshold is set, features requiring a spike-train will not be computed and displayed on the “Features” tab.

It must also be noted that setting a threshold to detect spiking is a necessary prerequisite for analysis methods such as spike sorting (see Section 2.3).

2.2.3. Threshold Inversion

For some electrophysiological data, depending on the system one uses, spiking can occur in either the anodic (upward—positive) or cathodic (downward—negative) direction. Users can adjust the threshold detection direction such that it matches their data. By default, the threshold and detection of peaks is applied in the cathodic direction. However, click the “Invert Threshold” checkbox on the left panel in the “Parameters” section to apply this feature in the anodic direction.

2.2.4. Signal Visualization

On the “Main” tab, the signal the user has selected will appear in time-series format on the graph. The “Plot Display” section of the “Main” tab includes three checkboxes, all of which provide additional flexibility for visualizing spiking within the signal. The “Spike Train” checkbox will show the locations of the spikes as an event-plot above the main signal. “Event Peaks” will display the spike peaks overlayed on top of the main signal within the main plot. Finally, “Threshold Bar” will present a fixed dotted line at the amplitude corresponding to the threshold for peak detection. It must be noted that all three of the available display features enumerated in this paragraph only become available after a threshold has been set, since a threshold is the necessary condition for peak detection. Additionally, users can zoom in and out, move the signal, and save the figure using the toolbar at the bottom of the tab, directly below the plot. Please see Figure 2 for an example of the utilization of all three visualization methods.

Figure 2: example analysis pipeline using “Main” tab features of Spooky Spikes. Here is outlined file importation, channel selection, filtering, threshold selection and inversion, as well as signal and spike visualization.

2.3. Spike Sorting

Spooky Spikes includes spike sorting capabilities. Users can select between various clusters of noise and spikes to isolate the activity of interest and refine their analyses. This spike sorting method consists of a principal component analysis followed by k-Means clustering. The first two principal components are displayed on the “Spike Sorting” tab. Additionally, users may refine their spike sorting results by manually selecting the fixed number of clusters used to fit the data on the same tab under the “Number of Clusters” heading (Figure 3). Otherwise, the number of clusters is automatically determined based on optimal clustering performance using a silhouette score as a quality metric. The silhouette score for the selected cluster is displayed on the “Features” tab.

Figure 3: spike sorting results display including the spread of the first two principal components pertaining to spike waveforms, and the number of clusters used in the clustering computation.

Following spike sorting, features are re-calculated based on the selected cluster. The selected cluster is then displayed on the dropdown menu in the “Select Cluster” section of the “Main” tab. By default, the cluster with spike peaks possessing the highest average amplitude is selected. Within the same tab, the spike waveforms corresponding to the selected cluster are displayed on the main plot as distinctly coloured compared to the rest of the signal (Figure 4). As users select different clusters, signal features are re-calculated according to the cluster that has been chosen. This processing method offers an efficient means of isolating different activity and dynamically computing signal characteristics.

Figure 4: spike sorting results display including the selected cluster corresponding to the highest mean spike amplitude, and distinctly coloured spike waveforms of the respective cluster.

2.4. Results of Analysis

Following the fulfillment of the necessary preparatory requirements, features are calculated dynamically and presented in the form of numerical displays as well as figures. Additionally, as previously noted in various places, features are dynamically calculated depending on the method used for detecting spike peaks. As users switch between methods (threshold-crossing versus spike sorting), or even alter clustering parameters (number of clusters and selected cluster), the features will be re-computed accordingly. This must be considered, since small alterations in user-selected parameters can drastically change the results obtained from Spooky Spikes.

2.4.1. Numerical Displays

Those signal features which are numerically formatted are displayed on the “Features” tab, and correspond to the following categories: patterned, quality metrics, spike-train oscillations, and local field potential (LFP) power (Figure 5). It must be noted that if a simple threshold-crossing method is used to calculate spikes and thus, features, then the silhouette score will not be available, since this is a quality metric pertaining to the clustering algorithm used in spike sorting. Furthermore, all characteristics within the LFP category do not require the detection of spiking peaks to be computed, but are calculated and displayed immediately upon importation of the source datafile, and/or selection of the source channel.

Figure 5: results of analysis in numerical format displayed on the “Features” tab, as well as buttons corresponding to three available figures (ISI Plot, Oscillations Plot, LFP Plot).

2.4.2. Figures

The final component of signal feature display involves four different figures, all of which are available on the “Features” tab under their corresponding sections (Figure 5). The first figure (“ISI Plot”) displays a histogram of log-inter-spike-interval durations. A Gaussian mixture model is fitted to the data and displayed, along with the component Gaussian curves (Figure 6A). Next, the “Oscillations Plot” presents spike-train oscillations at four different frequency bands with highlighted bursting regions (Figure 6B). The “LFP Plot” shows the signal’s power spectral density on the leftmost graph of the pop-up window, followed by LFP oscillations over time at four different frequency bands with highlighted bursting regions (Figure 6C). Finally, "Autocorrelation Plot" reveals the signal's autocorrelation up to a 0.5-second lag. Additionally, the power spectrum at four different frequency bands is displayed (Figure 6D).

A
B
C
D
Figure 6: results of analysis in figure format. A) Log-inter-spike-interval duration histogram (“ISI Plot” button), B) spike-train oscillations over time with highlighted bursting regions (“Oscillations Plot” button), C) power spectral density (left) and LFP oscillations over time with highlighted bursting regions (right; “LFP Plot” button), D) autocorrelation up to a lag of 0.5 seconds (left) and power spectrum of spiketrain oscillations at four frequency bands ("Autocorrelation Plot" button).

2.5. Exporting Data

Spooky Spikes allows users to save the results of their analysis. All save options can be found on the main left panel of the application under the “Export” heading (Figure 7). First, users can save the numerical features extracted from the electrophysiological signal to a spreadsheet. Each feature corresponds to a distinct column while the first row is populated by the resultant features. Furthermore, the signal segment can be saved along with the timestamps of individual spikes found either by threshold-crossing or spike sorting. The “Save Segment (All Spikes)” option will save the imported signal and all spiking timestamps as events in separate channels, or columns depending on the filetype used at the save. Additionally, “Save Segment (Selected Cluster)” will save the imported signal and only the timestamps of spikes belonging to the selected cluster following spike sorting.

Figure 7: save options.