cibrrig.postprocess.optotag
Functions to work with optogenetic stimulations, and in particular, tags. When run from command line will perform tag statistics
Attributes
Functions
|
Creates the rasters pre and post stimulation time. |
|
Runs the Stimulus Associated Latency Test (SALT - See Kvitsiani 2013) |
|
Computes the number of stims that a spike was observed and the pre and post stim spike rate |
|
Finds the optogenetic stimulations that are associated with a logged tagging episode. |
|
Plots rasters and PETHs for each cell aligned to stimulus. |
|
Computes a one-sided Kolmogorov-Smirnov test to determine if the number of spikes after the stim is |
|
Computes the optotag statistics on data from one probe. |
|
Run optotagging statistics on each probe in a session. |
|
CLI entry to run session |
Module Contents
- cibrrig.postprocess.optotag.compute_pre_post_raster(spike_times, spike_clusters, cluster_ids, stim_times, stim_duration=None, window_time=0.5, bin_size=0.001, mask_dur=0.002)[source]
Creates the rasters pre and post stimulation time. Optionally blanks periods around onset and offset of light to zero (default behavior) Wraps to the IBL bin_spikes2D
- Parameters:
spike_times (np.ndarray) – Array of times in seconds for each spike.
spike_clusters (np.ndarray) – Array of clusters for each spike.
cluster_ids (np.ndarray) – List of clusters to include.
stim_times (np.ndarray) – Onset times of each opto stim to align to.
stim_duration (float) – Duration of stimulus in seconds.
window_time (float, optional) – Size of the PETH to compute in seconds. Defaults to 0.5.
bin_size (float, optional) – Size of the bins of the PETH in seconds. Defaults to 0.001.
mask_dur (float, optional) – Duration to mask to zero near onset and offset in seconds. Defaults to 0.002.
- Returns:
- A tuple containing:
np.ndarray: pre_raster - Raster of spike counts before stimulus onset. Size: [n_stims, n_units, n_timebins].
np.ndarray: post_raster - Raster of spike counts after stimulus onset. Size: [n_stims, n_units, n_timebins].
- Return type:
tuple
- cibrrig.postprocess.optotag.run_salt(spike_times, spike_clusters, cluster_ids, stim_times, window_time=0.5, stim_duration=None, consideration_window=0.01)[source]
Runs the Stimulus Associated Latency Test (SALT - See Kvitsiani 2013) on given units.
Must pass data to matlab, and does so via saving to a temporary mat file. Automatically deletes the temporary mat file.
- Parameters:
spike_times (np.ndarray) – Array of times in seconds for each spike.
spike_clusters (np.ndarray) – Array of clusters for each spike.
cluster_ids (np.ndarray) – List of clusters to include.
stim_times (np.ndarray) – Onset times of each opto stim to align to.
window_time (float, optional) – Size of the PETH to compute in seconds. Defaults to 0.5.
stim_duration (float, optional) – Duration of stimulus in seconds. Defaults to None.
consideration_window (float, optional) – Time window to consider for analysis in seconds. Defaults to 0.01.
- Returns:
- A tuple containing:
np.ndarray: p_stat - SALT p-values for each cluster.
np.ndarray: I_stat - SALT I-values for each cluster.
- Return type:
tuple
- cibrrig.postprocess.optotag.compute_tagging_summary(spike_times, spike_clusters, cluster_ids, stim_times, stim_duration=None, window_time=0.01)[source]
Computes the number of stims that a spike was observed and the pre and post stim spike rate
- Parameters:
spike_times (1D numpy array) – times in seconds of every spike
spike_clusters (1D numpy array) – cluster assignments of every spike
cluster_ids (1D numpy array) – cluster ids to use.
stim_times (1D numpy array) – onset times of the optogenetic stimulus
window_time (float, optional) – window to compute spike rate in seconds. Defaults to 0.01.
- Returns:
Number of stimulations that evoked at least one spike pre_spikerate (1D numpy array): Spike rate in the window before stimulus onset post_spikerate (1D numpy array): Spike rate in the windw after stimulus onset
- Return type:
n_responsive_stims (1D numpy array)
- cibrrig.postprocess.optotag.extract_tagging_from_logs(log_df, laser, verbose=True)[source]
Finds the optogenetic stimulations that are associated with a logged tagging episode.
- Parameters:
log_df (pandas.DataFrame) – The log from the experiment, should be an autogenerated TSV.
opto_df (pandas.DataFrame) – The optogenetic stimulation dataframe extracted from the analog trace. Note: it must be synchronized.
verbose (bool, optional) – If True, prints verbose output. Defaults to True.
- Raises:
NotImplementedError – If more than one tagging episode is found.
ValueError – If no tagging episodes are found.
- Returns:
A subdataframe from opto_df that only contains the tagging data.
- Return type:
pandas.DataFrame
- cibrrig.postprocess.optotag.make_plots(spike_times, spike_clusters, cluster_ids, tags, save_folder, optotag_rez=None, pre_time=None, post_time=None, wavelength=473, consideration_window=0.01, cmap='magma', plot_desc=True, method='salt')[source]
Plots rasters and PETHs for each cell aligned to stimulus. Optionally marks each plot with some statistics. Saves to both png and svg
- Parameters:
spike_times (np.ndarray) – Array of times in seconds for each spike.
spike_clusters (np.ndarray) – Array of clusters for each spike.
cluster_ids (np.ndarray) – List of clusters to include.
tags (np.ndarray) – Array of tags for each stimulus.
save_folder (Path) – Folder to save the plots.
tag_df (pd.DataFrame, optional) – DataFrame containing tagging results. Defaults to None.
pre_time (float, optional) – Time before stimulus onset to include in plots. Defaults to None.
post_time (float, optional) – Time after stimulus onset to include in plots. Defaults to None.
wavelength (int, optional) – Wavelength of the stimulus in nm. Defaults to 473.
consideration_window (float, optional) – Time window to consider for analysis in seconds. Defaults to 0.01.
cmap (str, optional) – Colormap to use for plots. Defaults to “magma”.
plot_desc (bool, optional) – Whether to include descriptive text in plots. Defaults to False.
- cibrrig.postprocess.optotag.kstest_optotag(spike_times, spike_clusters, cluster_ids, tags, window_time, stim_duration)[source]
Computes a one-sided Kolmogorov-Smirnov test to determine if the number of spikes after the stim is more than before the stim. Useful in the case that we do not expect latencies to be tightly aligned, which is the case for the ChRmine optotag
- Parameters:
spike_times (1D numpy array) – times in seconds of every spike
spike_clusters (1D numpy array) – cluster assignments of every spike
cluster_ids (1D numpy array) – cluster ids to use.
stim_times (1D numpy array) – onset times of the optogenetic stimulus
window_time (float, optional) – window to compute spike rate in seconds. Defaults to 0.01.
tags (AlfBunch) – Opto stimulus data for the tags. Should have the attribute “intervals”
stim_duration (float) – Duration of stimulus in seconds.
- Returns:
p-value of the null hypothesis that FR_pre = FR_post. Each entry corresponds to an entry in “cluster_id”
- Return type:
p (list)
- cibrrig.postprocess.optotag.run_probe(probe_path, tags, consideration_window, wavelength, plot=False, no_matlab=False, overwrite=False)[source]
Computes the optotag statistics on data from one probe. Loads in from the ALF format. Computes:
SALT statistics
Heuristics for number of stims with spikes, spike rates
Kolmogorov-Smirnov test of significance
Saves data to the probe path with the namespace “salt” Saves the parameters associated with the computations (e.g., SALT-p cutoff) as a JSON in the probe path Optionally saves figures for each unit
- Parameters:
probe_path (pathlib Path) – Path to the spike ALF data (e.g., <session>/alf/probeXX)
tags (AlfBunch) – Object of opto stimulations for just the tagging stimulations
consideration_window (float) – Time in seconds to consider for statistical comparisons
wavelength (int) – Wavelength of the stimulus in nm.
plot (bool, optional) – If true, plots figures for each unit. Defaults to False.
- cibrrig.postprocess.optotag.run_session(session_path, consideration_window, plot, wavelength, no_matlab=False, overwrite=False)[source]
Run optotagging statistics on each probe in a session. Reads in the laser object to get the opto stimulation parameters. Reads in the log file to identify which stims are tags
- Parameters:
session_path (pathlib Path) – Alf session path (parents should be Subjects/<mouseID>)
consideration_window (float) – Time in seconds to consider for statistical comparisons
plot (bool, optional) – If true, plots figures for each unit. Defaults to False.
wavelength (float) – Wavelength of light used for plotting purposes
- cibrrig.postprocess.optotag.main(session_path, consideration_window, plot, wavelength, no_matlab, overwrite)[source]
CLI entry to run session
- Parameters:
session_path (pathlib Path) – Alf session path (parents should be Subjects/<mouseID>)
consideration_window (float) – Time in seconds to consider for statistical comparisons
plot (bool, optional) – If true, plots figures for each unit. Defaults to False.
wavelength (float) – Wavelength of light used for plotting purposes