
\subsection{Spike sorting pipeline}
We have applied the t-sne algorithm in two separate points of the spike sorting pipeline using two different spike representation feature sets as inputs to the algorithm. In the first instance (results in Figures 2, 3 and 4) the algorithm operated on the masked PCA components of the spikes detected as described in \cite{rossant_spike_2016}. In order to facilitate the input to t-sne of these components, we wrote python code that accepts the (masked or not) PCA components of the detected spikes, transforms these into a data set ready for the t-sne algorithm and calls the executable on it. We have also tried using raw data or non-masked PCA components as input to the t-sne algorithm, but found the masked-PCAs to consistently outperform these other inputs (results not shown). The second input feature set to the algorithm (results in Figure 5) was the distance to templates generated by the kilosort algorithm. In this case, the t-sne algorithm operated on feature vectors that measured how close or far each spike was to the set of spike templates that kilosort generated from the data.
\\We have also developed a minimal, and easily extensible, graphical user interface (GUI) that allows users to visualize the results of the t-sne algorithm and use this visualization to manually sort the detected spikes. The GUI offers a number of views and tools for manual spike sorting. These include: A 2D scatter plot of the t-sne results with several ways to select groups of spikes directly on the plot. A view to preview the selected group's average time traces for all channels. The presented data are not explicitly filtered, but the baseline is subtracted using the first 10 samples. An autocorrelogram view of the selected spikes with 1 ms resolution bins. A heat map view of the average difference between the minimum and the maximum values in the spikes' time window superimposed on the probe's layout diagram. A way to label a selected group and store it as a cluster in a pandas structure (saved to disk as a pickle). The GUI also allows selecting and previewing of all plots for any previously saved cluster, deleting a selected cluster and previewing all saved clusters on the t-sne scatter plot. A number of input boxes and buttons also allow the merging and splitting of clusters as well as the reassignment of spikes to different clusters.
\\The development of the GUI is based on the bokeh python library. This makes further development of good quality views as desired by individual users relatively easy and fast. At the same time the bokeh library will struggle with large number of points presented simultaneously on the t-sne view. For the gaming desktop described above the easy to work with limit was reached at about 500,000 spikes.
\\The python code design was informed by the need to keep the code simple and extendable. To achieve this we chose to implement only functions, without any obfuscating object orientation or passing data around data structures in more complicated ways other than function arguments and return statements. Individual functions are constructed to be self-standing and usable outside the context of the spike sorting workflow the code was designed for. For example the basic t-sne functions can operate on any other data of a samples x features dimensionality, or the functions that produce the average spike timecourses or the average heatmaps of the probes can easily be used to generate plots outside the confines of the gui. 