Python code repository for data analysis for U19 projects of Wilbrecht Lab. Analysis procedures include calcium signal processing, peristimulus visualization, GLM, neural decoding models and dimensionality models.
[CODE BASE UNDER CONSTRUCTION]
The documentation consists of the following subparts:
- data file structure
- code base structure
- event type naming system (ETNS)
- example code ...
The file structure listed here suggests one possible analysis file configurations in local/server file structures and is open to modifications.
- [root] - CADA_data: root for storing data of different modalities - ProbSwitch_Raw: Raw behavior data mats and other recording sources including photometry and binaries - ProbSwitch_FP_data: ProbSwitch_FP_data: preprocessed data with behavior and FP dff ready for further analysis -_: e.g. A2A-15B-B_RT_p151_session1_FP_RH - .mat: matlab consistent file saved with -v7.3 flag for hdf5 consistency - .hdf5: hdf5 file storing - RestaurantRow_Raw: Restaurant row data - RestaurantRow_FP_data: preprocessed restaurant row ... - CADA_plots: root for storing plots of different sub-projects - FP_NAc_D1D2_CADA: root for plots for NAc - FP_DMS_D1D2_CADA: root for plots for DMS ...
Data stored in this folders are organized by animal and session names in individual folders:
animal: A2A-15B-B_RT, session: p151_session1_FP_RH
To load a filename in python code base one could use
encode_to_filename(folder, animal, session, ftypes)
function in utils_loading.py
to obtain a dictionary (or string for single option) consisting of different file types. For instance to get the processed behavior mat of the session mentioned above we could use
folder = '<data_root>' # e.g. "<root>/CADA_data/ProbSwitch_FP_data/"
encode_to_filename(folder, 'A2A-15B-B_RT', 'p151_session1_FP_RH', 'behavior') # for more usage check specific code functions
- exper .mat
- behavior .mat (processed from exper and synced with FP times)
- bin_mat binary file
- green green fluorescence
- red red FP
- behavior .mat behavior file
- FP processed dff hdf5 file
Check
decode_from_filename
inutils.py
for more details for specific file name rule
behaviors.py
:- Key input: processed behavior .mat files in
ProbSwitch_FP_data
folder - Key output: trial-based behavior features or behavior times and other relevant statistics like movement times
- Key functions: (check specific code files for detailed descriptions)
get_trial_features(mat, feature, as_array=False)
get_behavior_times(mat, behavior)
- Special Note: the feature or behavior indexing follows the ETNS specified in the later section
- Key input: processed behavior .mat files in
FP_deconv_test.py
Tests regarding deconvolution algorithms on FP signalsmodeling.py
GLM/decoding models for FP data in ProbSwitch Tasks -- To be specified moreperistimulus.py
- Key input: dff traces and behavior times/features
- Key output: peristimulus plots of various kinds indexed by different behavior events
- Key functions: (check specific code files for detailed descriptions)
align_activities_with_event(sigs, times, event_times, time_window, discrete=True, align_last=False)
behavior_aligned_FP_plots(folder, plots, behaviors, choices, options, zscore=True, base_method='robust', denoise=True)
pipeline_FP_ProbSwitch.py
: Consists of different short hand pipelines to run for different analysis using helper functions from other code filesscript.py
Please ignore, unorganized analysis ideastests.py
Various tests for different analysis steps, can be referred them for example function usageutils.py
Different utility functions for analysis, including, loading, preprocessing, simulation, filtering, visualizattion, process managementutils_models.py
Utility functions for dimensionality reduction models and classifier/regression models
NBM
object manipulates trial-organized neural-behavioral pd.DataFrame
that contains the following columns:
- id columns:
animal, session, trial
androi
(in presence of trial alignedContSeries
features) - event/trial features: numerous information regarding the behavior trial, i.e., reward information, animal's decision
- aligned
ContSeries
columns:{event}_{series}|{time}
, e.g.outcome_neur|-0.5
, neural series aligned tooutcome
event at 0.5 before the event. orchoice_pose|0
, pose series aligned to when animal makes motor choice decisions.
It contains methods that manipulates neural-behavioral data that are organized by trials in following manners:
- align objects of type
ContSeries
to list of timestamps organized in trial structure - trial-lag feature columns, including neuroseries
lag_wide_df
More specific details in documenations in behaviors.py
center_in
center_out
side_in
outcome
side_out
- feature types:
R
: Reward contingency of a trial,'Rewarded', 'Unrewarded'
O
: Outcome contingency of a trial,'Incorrect', 'Correct Omission', 'Rewarded'
A
: Action Laterality of the specific action (e.g. side out) Note: this option will be modified for more careful action type groupingS
: Suggests whether a trial occurs Periswitch, useS[i]
to specify Preswitch with0,1..i
steps,S[-i]
to specify post switch with0,-1..-i
stepsITI
: inter trial interval bins
- for behavior times; use
{t+i}
to select event times ofi
trials forward (i>0
) or backward (i<0
) - for event features: it is perfectly valid to use chained notations to special a certain trial history: e.g.
R{t-3,t-2,t-1}
for 3 trial back reward history
The following code plot outcome times
plot_type = 'trial_average'
folder = "/Users/albertqu/Documents/7.Research/Wilbrecht_Lab/CADA_data/ProbSwitch_FP_data"
plots = "/Users/albertqu/Documents/7.Research/Wilbrecht_Lab/CADA_plots/FP_NAc_D1D2_CADA"
zscore = True # Should not matter with 1 session
base_method = 'robust_fast'
denoise = True # flag for whether to use wiener filter to clean noise from the source
for sg in ['Ca', 'DA']:
choices = get_probswitch_session_by_condition(folder, group='all', region='NAc', signal=sg)
# Plotting Option to generate a 1x2 plot for each session with column representing ipsi/contra port
# and different color representing different trial outcomes,
# for DA/Ca separately (specified by `sg` in the outer loop)
sigs = [sg]
row = "FP"
col = "A"
hue = "O"
rows = (sg, )
cols = ('ipsi', 'contra')
hues = ('Incorrect', 'Correct Omission', 'Rewarded')
ylims = [[(-1.5, 2.1)] * 2] # specifies the ylimit showing on the subplots
options = {'sigs': sigs, 'row': row, 'rows': rows, 'ylim': ylims,
'col': col, 'cols': cols, 'hue': hue, 'hues': hues, 'plot_type': plot_type}
behavior_aligned_FP_plots(folder, plots, 'outcome', choices, options,
zscore, base_method, denoise)