Preprocessing of Intan files - MobsLab/PreProcessing GitHub Wiki

General information

Preprocessing of electrophysiology data refers to two main operations that are performed with the raw data:

  • Converting data from the formats of the recording software (Intan software in our case) to the convenient format (Matlab or Python);
  • Perform basic conventional transformations of the signal. These transformations are well-established in the community, so you do them now, and do not bother in the future.

Before you start the preprocessing, check that you have two folders:

If you recorded files in Intan:

  1. One comes from the Intan software and contains electrophysiology data with the files names such as
  • amplifier.dat- this is the file with brain signals - the heaviest and the most important of all; (if the merging and ref substraction is already done, the name of this file has to be amplifier_MXXX.dat (XXX=mouse number))
  • auxiliary.dat - this file contain 3-axis accelerometer data. Accelerometer is present only on 32 channel headstages, so you will not have this file if you record with 16 channel headstage;
  • digitalin.dat - this file contains information about your digital inputs. If you have not selected any digital inputs to be recorded, this file would not exist;
  • supply.dat - this file contains information about power supply to the recording board. Always exists.
  • time.dat - this file contains timestamps of the recording. Always exists. The name of this folder has to end by the date and time of the session : ‘_yymmdd_hhmmss’

If you recorded in OpenEphys:

Within your experimentN/recordingN you have two folders: continuous and events.

  • In continuous you have to make sure that you have file named continuous.dat. It contains all your brain recordings and accelerometers channels.
  • In events you have events from all modules of OpenEphys in Python .npy format. To convert them into .mat, open shell and type ~/Dropbox/Kteam/PrgMatlab/OnlinePlaceDecoding/matlab/convertEvents2Mat -p /path/to/your/recording/experimentN/recordingN/events/
  1. Another folder comes from the Matlab and the tracking code that you used to control your experiment. It contains video recorded from the camera and behavResources.mat with the results of tracking.

If you have both folders and all necessary files, you can start preprocessing. All codes are stored in Dropbox/PrgMatlab/Processing/. With these codes you can either preprocess one session of data or concatenate several separate recording sessions.
!!! Please have a back-up of the raw data you will preprocess. Raw data will be modified in the preprocessing !!!

Enter general information about the experiment

Start preprocessing in the new folder and make it current directory in Matlab. File ExpeInfo.mat will be created in this folder: it will contain information about your experiment and preprocessing procedures performed with your data.

Type GUI_StepOne_ExperimentInfo in the command line.

pasted image 0 Figure 1. Window to enter information about your experiment to be preprocessed. Called by GUI_StepOne_ExperimentInfo

Availability of fields will change with completion of the previous ones.

  • MouseNum - number of the mouse recorded (what is written on its cage);
  • Mouse strain - select mouse strain;
  • Experimenter - select who recorded the mouse (initials indicated: f.e., SB=Sophie Bagur);
  • Date - format: YYYY MM DD;
  • SessionName - name of the experiment, it will be placed in the name of the file; Tick SleepSession, if the resulting file contains only sleep.
  • RecordingRoom - select a room where you’ve recorded the experiment from the list;
  • RecordingEnvironment - select a recording environment where you’ve recorded the experiment from the list (f.e., UMaze, or HomeCage);
  • CameraType - select an option: either infrared FLIR camera or LogiTech WebCam;

Those are the the principal fields, without filling them out you will not be able to proceed in preprocessing. There are optional fields that you may fill out if they are relevant. Otherwise, press ‘I’m done’ button and ‘Next Step’ button.
Optional fields include:


  • Optogenetics - if you have injected the virus to do optogenetics experiment, please fill out the tab bellow:
  • Virus injected - select from the list below;
  • Injection location - select from the list below;
  • Fiber location - select from the list below;
  • Stimulation intensity - enter in the field the value you’ve measured with light-meter;
    Tick OptoSession if you perform stimulation in this session.

  • Drug Injection - if your experiment include drug injection, please fill out the tab bellow (you have possibility to enter info about two drugs - if you have only one leave the other one untouched):
  • Drug injected - select from the list below;
  • Dose - enter in the field in mg/kg;
  • Injection day - enter in the format YYYY MM DD;
  • Injection time - enter in the format HH MM;

  • Electrical Stimulation - if your animal is implanted with electrical stimulation electrode, please fill out the tab below (you have possibility to enter info about two stimulation sites - if you have only one leave the other one untouched):
  • Location - select location of stimulation electrode from the list below;
  • Intensity - enter in the field in V;
    Tick StimSession, if you stimulate during this session;

  • Any general comments? - here you can describe features and properties of this experiment that have not been described before. Notes, warnings and so forth. This field will be recorded in ‘Notes’ field of ‘General Information’ tab of XML file.

Press ‘I’m done’ button - this will record your answers to ExpeInfo.mat. Press ‘Next Step’ button, and it will open GUI to enter information about electrophysiology files.

Enter general information about the recorded channels

You also can call it with GUI_StepTwo_RecordingInfo.

pasted image 0 (1) Figure 2. Window to enter general information about the identity of the channels recorded. Called by GUI_StepTwo_RecordingInfo

  • NumWidebandChannels - enter how many channels you have recorded. Usually, you record 16 or 32 channels, but the number could be any (if you supressed recording of some channels, f.e.);
  • Tick Are there spikes to process if you have spikes to process. This box checked will allow you to describe spike groups later, which will not happen if this box is not checked;
  • NumAcceleroChannels - choose how many accelerometer channels you have. 0 if you recorded with 16-channel headstage, or chose not to record accelerometer on other headstages. 3 if you recorded with 32-channel headstage, 6 if you recorded with 2 32-channel headstages, etc.
  • NumDigChannels - enter number of digital channels - it is 0 (if you did not record them or if you recorded a signal with OpenEphys) or 1 (if you did). Real number of channels is encoded in NumDigitalInputs - enter there how many inputs you have opened in the Intan Software to record. If you press on ‘? Digin ?’ yellow button, you will see help. To close it, press on the button again.
  • NumAnalogChannels - enter number of analog channels you recorded.

Press ‘I’m done’ button - this will record your answers to ExpeInfo.mat.

To assign real-world identity to each of your channels, press Channel Identity.

pasted image 0 (2) Figure 3. Window to enter identities of electrophysiological channels. Called by Channel Identity. Note small window in the upper right corner. It is called by pressing on Apply Same Info to Multiple Channels. See text for description

You will see the window with three rows of drop-down menus - each row corresponds to one channel you have. In the first column, you indicate which structure this channel corresponds to (for full list, see below). In the second column, you indicate whether the wire is in the right ot left hemisphere (or NaN - not applicable). In the third column, you indicate position of the electrode on the dorsal-ventral axis:

  • EEG (-1) when you record from above the dura mater;
  • ECOG (0) when you record from the surface of the skull;
  • Sup (1) when you record from the superficial layer;
  • Mid (2) when you record from the middle layer;
  • Deep (3) when you record from the deep layer’
  • NaN - not applicable.

Let’s go through possible options in the first column that describe structures:

  • Nthg - when the hole on the EIB is empty, or the channel is lost. This option will paint the row black;
  • dHPC - dorsal hippocampus. This option will paint the row light blue.
  • vHPC - ventral hippocampus. This option will paint the row light blue.
  • CA2 - This option will paint the row light blue.
  • CA3 - This option will paint the row light blue.
  • DenG - dentate gyrus. This option will paint the row light blue.
  • PFCx - prefrontal cortex. This option will paint the row red.
  • PaCx - parietal cortex. This option will paint the row orange.
  • MoCx - motor cortex. This option will paint the row orange.
  • AuCx - auditory cortex. This option will paint the row orange.
  • Bulb - olfactory bulb. This option will paint the row dark blue.
  • PiCx - piriform cortex. This option will paint the row blue.
  • VLPO of hypothalamus. This option will paint the row purple.
  • NRT - nucleus reticularis of thalamus. This option will paint the row violet.
  • AuTh - auditory thalamus. This option will paint the row orange.
  • TT - tenium tecta. This option will paint the row blue.
  • Amyg - amygdala. This option will paint the row green.
  • EKG - electrocardiogram. This option will paint the row yellow.
  • EMG - electromyogram. This option will paint the row yellow.
  • EOG - electrooculogram. This option will paint the row yellow.
  • Ref - reference. This option will paint the row transparent.
  • Accelero - accelerometer. This option will paint the row gray.
  • Stimulator - stimulator channel from online place decoding software. This option will paint the row pink.
  • Respi - respiration recorded in plethysmograph (or with thermocouple). This option will paint the row pink.
  • LaserInput - channel of stimulation laser - optogenetics. This option will paint the row pink.
  • Digin - digital input channel. This option will paint the row pink.
  • AnalogInput - This option will paint the row pink.

In the second column, you have to define whether the wire in question is in the left or hemisphere. The third option is NaN.
You can also press ‘Apply Same Info to Multiple Channels’ and define several channels with the same information.

After you have defined the identities of each electrophysiological channel, you will be asked to provide the identities digital inputs you have recorded. After pressing ‘Digital Channel Identity’ button, the window will open with drop-down menus (their number will be equal to the number you have indicated in NumDigitalInputs field).

pasted image 0 (3) (1)
Figure 4. Window to enter identities of digital channels. Called by Digital Channel Identity.

Please select the identity if each digital input from the following list:

  • ONOFF - input that records switching on and off the recording of the data during the experiment;
  • STIM - input that records stimulation events;
  • CS+WN - conditioned stimulus being white noise sound paired with an unconditioned stimulus;
  • CS+Tone - conditioned stimulus being pure tone sound paired with an unconditioned stimulus;
  • CS-WN - conditioned stimulus being white noise sound unpaired with an unconditioned stimulus;
  • CS-Tone - conditioned stimulus being pure tone sound unpaired with an unconditioned stimulus;
  • DeltaTone - input that records sound tones delivered in response to the detection of the delta wave;
  • CAMERASYNC - input that records pulses that are meant to serve as a means of video-electrophy synchronization ;
  • Laser - input that records laser activity (optogenetics experiment);
  • Shock - input that records electrical shock events;
  • NaN - nothing on this input;
  • OdorON - input that records the onset of odor delivery;
  • OdorOFF - input that records the offset of odor delivery.

After you have recorded the identities, you can indicate the channels that will be used in the analysis later. The idea of this procedure is to select only the best channels which you are sure contain meaningful information for your analysis. For example, if your ECG wire is very noisy and often it’s not possible to see QRS-complexes, you would not want to include it in the analysis. Likewise, if you don’t see ripples on the channel that you thought you have inserted in the pyramidal layer of the hippocampus, there is no reason to mark it as a hippocampal channel with ripples (dHPC_rip).

To call this pop-up window, press ‘ChannelsToAnalyze’ button. You will see the following interface:

pasted image 0 (4) (1)
Figure 5. Window to enter channels that are good for analysis. Called by ChannelsToAnalyze

First, you should indicate the reference channel that will be used to re-reference your data. Indicate the number of your recorded reference channel in the Ref field. If you will not indicate the reference channel, that would mean you do not want re-referencing. You will have to indicate it later.
Indicate the number of any channel that is good for analysis in the following windows. If you do not have a channel for the particular structure leave NaN value in the field. If you have several good channels for one structure, select the best one:

  • Ref - reference;
  • Bulb_sup - superficial olfactory bulb channel;
  • Bilb_deep - deep olfactory bulb channel;
    Difference between superficial and deep olfactory bulb channels is defined by the inversion of respiration-related oscillations: the dipole is supposed to be situated at around the surface of olfactory bulb. If you have good inversion, mark one of the electrodes deep, and one electrode superficial. Deep electrode should have pronounced gamma oscillations during wakefulness.

04OBchan Figure 6. Example of olfactory bulb channels. Note the inversion of LFP - one of the channels is superficial, the other one is deep.

  • dHPC_sup - superficial dorsal hippocampus channel;
  • dHPC_deep - deep dorsal hippocampus channel;
  • dHPC_rip - dorsal hippocampus channel with ripples (pyramidal layer);

Difference between superficial, middle and deep hippocampal channels could be attributed to their relations to the occurence of sharp-wave ripples complexes. Middle hippocampal channel (aka pyramidal layer) is characterized by flat appearance and pronounced ripples without much of a sharp wave. This is the layer where the neurons are most densely packed - the probability to find neurons there is the highest. Superficial hippocampal channel is above the middle one and is characterized by the sharp wave deflection up with minimum amount of ripples. Deep hippocampal channel is detectable of the presence of negative sharp wave ripple deflection.

01HipChan Figure 7. Example of hippocampal channels. Note the prominent ripples on dHPC_rip channel. dHPC_sup is defined by the presence of positive sharp waves that accompany ripples. Sharp waves in dHPC_deep are downwards.

  • PaCx_sup - superficial parietal cortex channel;
  • PaCx_deep - deep parietal cortex channel;
  • PFCx_sup - superficial prefrontal cortex channel;
  • PFCx_deltasup - superficial prefrontal cortex channel that would be perfect for differential detection of delta waves (different from _deltadeep only during delta waves);
  • PFCx_deep - deep prefrontal cortex channel;
  • PFCx_deltadeep - deep prefrontal cortex channel that would be perfect for differential detection of delta waves (different from _deltasup only during delta waves);
    Cortical channels could be subdivided in superficial, deep and middle ones. They could be differentiated by the deflection of delta wave. In superficial channels delta wave deflection is negative, in middle ones it is flat, and in deep cortical channels the deltas are upwards.
    For the differential detection of delta waves, it is more convenient to use channels that are very similar in activity except during the times of delta waves. In that case, we would call cortical delta deep channel (PFCx_deltadeep) the channel with positive delta deflection, and cortical delta superficial channel (PFCx_deltasup) the channel that repeats the PFCx_deltadeep everywhere except the delta wave: the delta on it could be either flat or negative.

06PFC Figure 8. Example of prefrontal cortex channels. Arrows point at the delta wave event. Note that in deep layers the delta wave appears positive, but the more superficial you go, the more negative it becomes. In the middle layers, delta waves are flat.

  • PFCx_spindle - prefrontal cortex channel with spindles;

05Spindles Figure 8. Example of prefrontal cortex spindle channel.

  • MoCx_sup - superficial motor cortex channel;
  • MoCx_deep - deep motor cortex channel;
  • AuCx - auditory cortex channel;
  • AuTh - auditory thalamus channel;
  • NRT - nucleus reticularis of thalamus channel;
  • Amyg - amygdala channel;
  • PiCx - piriform cortex;
  • InsCx - insular cortex channel;
  • TaeniaTecta - taenia tecta channel;
  • EMG - electromyography channel;
  • EKG - electrocardiography channel;
  • VLPO - VLPO nucleus of hypothalamus channel;
  • Respi - respiration channel (recorded with plethysmography or thermocouple - not from within olfactory bulb!).

Press ‘Ok’ when you have done with assigning channels to analyze, press ‘Get spike channel info’ to give the information about your spike processing pipeline. Note that this button will not be available if you have not ticked ‘Are there spikes to process?’ checkbox.

Upon pressing, you will be asked to give the number of spike groups which would be equal to your number of good spike groups (tetrodes, in case you record neurons with tetrodes). You will get a window with the number of rows that is equal to number of spike groups. Fill up the second column with number of channels in each spike group. The third column is reference channels that you will subtract from each channel of your spike group. (You may want to subtract averaged non-spiky tetrode to make automatic spike sorting more powerful.) If you indicate more than one channels for re-referencing, the average of indicated channel will be subtracted from each channel in the spike group. For spike group re-referencing, you have three options:

  • Subtract nothing from any given spike group: leave the corresponding third column blank
  • Subtract the same averaged reference from each spike group: to do that either fill up the third columns with the same numbers, or press ‘Apply Ref channels’ where you can make batch fill-up.
  • Subtract individual group of reference channels from each spike group: indicate reference group separately for each spike group.
    Re-referencing procedure will create a branch of files to which suffix ‘_SpikeRef’ would be added. You can also define the period of threshold calculation for the spike extraction step. It is 0-60 sec by default.

Screenshot from 2019-04-15 10:59:10

Figure 9. Window to enter spike groups. Called by Get spike channel info

Enter information about the location of files to process

When you have done with describing channels identity, press ‘I’m done’ button. This will take you to the last step of preprocessing interface:

Screenshot from 2019-03-25 13:06:41

Figure 10. Window to define files to process. Called by GUI_StepThree_FolderInfo

In the upper left corner you will see the resume about your data. If everything is ok there, please click on the ‘GetTheDataFolders’ button. You will have to answer several questions about the data:

  • Is there ephys? - Do you have .dat files?
  • Which software did you use? <If you used Intan only for all your recordings to be pre-processed please press Intan, if you used OpenEphys at least in the single recording please press OpenEphys or mixed
  • Is there behavior? - Do you have behavResources.mat with tracking?
  • Do you want to clean spike files (from stimulations and high-amplitude noise)? If you press Yes here, .spk files with waveforms and .res files with spike times will be cleaned from all spikes that fall within StimEpoch in behavResources.mat and from all periods when signal exceeds 290 mkV (1500 in a.u.). Upon pressing Yes, you will have to enter the duration of stimulation in seconds.
  • Number of folders to concatenate- Type 1 if you have only one session of data to pre-process and type the actual number if you have more.

!!! Note that at the moment you can pre-process either the files that were recorded entirely in Intan or entirely in OpenEphys

Screenshot from 2019-03-25 14:02:17 Figure 11. Window to enter folders with files. Called by GetTheDataFolders

In the new pop-up window you will see a table with ‘GetFile’ button in the left column. If you press this button, you will be asked to select a folder that contains files recorded with Intan (<amplifier.dat>, <digitalin.dat>, etc.) first, and then a folder that contains results of tracking (<behavResources.mat>). In case of OpenEphys, you should provide the folder with continuous.dat. You should keep the folder structure intact starting from recordingN/ level - structure.oebin and sync_messages.txt are used files and they should be stored in original places. The folders should be provided always in such order! After you have selected the folders their full paths will appear in the second and third columns of the window.
The fourth column is reserved for the name of this specific session. Interval set with this name, that delineates the session in time, will be created in the behavResources.mat if you concatenate several sessions together. The interval sets will be stored in the structure SessionEpoch.
In the fifth column, you can indicate that you do not want re-referencing by checking ‘RefDone’ check box. This could be when you do not have any good reference recorded, or you have already done the re-referencing, or for other reason. If you check ‘MergeDone’ box, the procedure of merging amplifier.dat, auxiliary.dat and digitalin.dat in one file will not be executed. This could be when you have already done it, or for other reason. If you chose OpenEphys branch of the analysis before, instead of ‘MergeDone’radio button, you will have ‘IntanRecorded’ button. Press it for the recordings that have been recorded in Intan software rather than in Open Ehpys software. Fill out these fields for all sessions you want to concatenate or pre-process and press ‘I’m done’ button.
Then press on the drop-down menu that contains the list of folders for preprocessing, and check that everything is correct.

After pressing ‘I’m done’ button the pre-processing will start.

Screenshot from 2019-03-25 14:23:10 Figure 13. Final look of final window

If you have only one recording session to pre-process, behavResources.mat will be copied to the folder you do preprocessing in. If you concatenate several recorded sessions, the code will create the following variables in concatenated behavResources:

  • behavResources - a structure that lists all concatenated behavResources.mat files that you concatenate in the order you gave to the code. So, for example, behavResources(3).mask would be a mask from the 3rd session.
  • SessionEpoch - a structure that contains interval sets that correspond to the start and the end of each concatenated recorded session in concatenated file. They will have the names that you entered in the fourth column of the folders window (see p. 11);
  • ZoneNames - all names of any zones that were found in all concatenated sessions.

All the other variables are the same as in normal behavResources but the time and data are concatenated together.

⚠️ **GitHub.com Fallback** ⚠️