OSCR

Experience and behavior modulate piriform cortex odor representation in freely moving mice.

Code ↔ Paper

5 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 5 matches
  1. [1] § STAR★Methods › Method details › Behavioral pose estimation ↔ data_sample/responseExtraction_Behavior.m, lines 191–231 · score 0.78 · confidence cutoff, left ear, tracked points, subtracting, displacement, raw
  2. [2] § STAR★Methods › Method details › Behavioral pose estimation ↔ data_sample/responseExtraction_Behavior.m, lines 10–54 · score 0.65 · behavioral scores, behavior trace, prominence, framerate, confidence, match
  3. [3] § STAR★Methods › Method details › Response extraction ↔ data_sample/responseExtraction_Behavior.m, lines 10–54 · score 0.64 · Pre window, post odor, pre trial, peak, timepoint, shifting
  4. [4] § STAR★Methods › Method details › Lifetime sparseness and tuning ↔ Fig_S6/best_tuning_figs.m, lines 43–105 · score 0.62 · narrow tuning, median, sparseness, S6, lifetime, sparsely
  5. [5] § STAR★Methods › Method details › Calcium trace extraction ↔ data_sample/responseExtraction_Behavior.m, lines 528–604 · score 0.59 · spatial footprints, deconvolved trace, min, motion, correlation

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

MATLAB · 730 lines · 47 KB · GPL-3.0 · 4 matches

  1. clear;
  2. % Note before starting; mouse NEC273332 does not have any behavioral data,
  3. % given the current way this script is written, a behavior file is
  4. % expected, so I have supplied a dummy file in the main directory. Didn't
  5. % want to use seperate trace extraction scripts for behavior/no behahvior
  6. % and I haven't updated this code to have behavioral flags in it. Because
  7. % of this, mouse NEC273332 is removed from the behavior tables at the end
  8. % of the code before saving the output files.
  9. %% Input Parameters
  10. % ***READ THROUGH THIS SECTION FIRST***
  11. % Some alternate methods commented in the code, otherwise just change
  12. % parameters below. All input parameters are saved in a structure termed
  13. % "inputValue" and have descriptions below.
  14. % Key file for sorting trial days, framerates, animal number, etc.
  15. inputValue.KeyTable = readtable('data_sample\Key.csv');
  16. % Folder where raw files are; easy to just use the same one as the key file
  17. myFolder = '.\data_sample';
  18. % Settings for smoothing raw data if desired; toggle for choosing to use
  19. % method and set value for number of frames to smooth over
  20. inputValue.SmoothToggle = 0; % 1 to smooth; 0 to not smooth
  21. inputValue.SmoothWindow = 3; % number of frames to smooth over if toggled on
  22. % Detection settings; cutoffs for DF detection and thresholding optios if
  23. % combining with a z-cutoff; peak finder settings included
  24. % for both combined detection and for whole trace event detection
  25. inputValue.SDcutoff = 2.5; % SD cutoff in DF detection; same for excitation and inhibition as of now
  26. inputValue.Zcutoff_combinedDetect = 1.0; % z score cutoff for combined detection with DF
  27. inputValue.Zcutoff_wholeTrace = 1; % z score cutoff for whole trace peak and activeness detection
  28. inputValue.PeakDistance = 5; % min distance between peaks IN FRAMES; avoids double counting peaks at flat areas, default 5 for 1s with gcamp6s @ 5 fps
  29. inputValue.Prominence = 0.5; % measure of how high peaks stand out (z-scored) from neighbers; also avoids double counting flat areas
  30. % trace details; framerate input, inputValue.timePoints to look at for DF
  31. % calculations; specifications for pre/post windows; bin size for whole
  32. % trial activity analysis
  33. inputValue.preTrial = 2; % time for pre-trial df measurement in seconds
  34. inputValue.postTrial = 5; % time for post-trial df measurement in seconds
  35. inputValue.trialTrace_Pre = 15; % time for trace extraction pre odor in seconds
  36. inputValue.trialTrace_Post = 25; % time for trace extraction post odor in seconds
  37. inputValue.totalZ_Bins = 300; % length of time IN SECONDS for binning zPeaks across whole trace
  38. inputValue.totalZ_Bins_max = 20; % cap value to z bins to avoid mis-matched sizing; make larger than biggest possible
  39. inputValue.shifter_maxFrames = 50; % total frames to move shifter DF value past OG timepoint
  40. inputValue.shifter_pre = 2; % time for pre-trial on shifter in seconds
  41. inputValue.shifter_post = 5; % time for post-trial on shifter in seconds
  42. inputValue.preValue_shift = 15; % time before timepoints in seconds to calculate pre-window values
  43. inputValue.behaviorTrace_Pre = 25; % time for trace extraction of pre behavior in seconds
  44. % settings for behavioral scoring from DLC files
  45. inputValue.DLC_cutoff = .95; % confidence cutoff for using DLC coord values
  46. inputValue.frate_BEH = 60; % set value for behavior camera framerate; has some jitter in actuality, but this is only used for trial window determination
  47. %% Things to be done globally before loop time
  48. % Initialize empty output tables; grows as things get added with each loop;
  49. % matlab will complain about this, but i don't have a better solution as of yet
  50. OutputTable = cell2table(cell(0,42), 'VariableNames', {'Animal','BehaviorGroup','State','Day','Odor','Abs_CellNumber','CellReg_Index',...
  51. 'Abs_TrialN','Stim_TrialN','DeltaValue_Max','DeltaValue_Mean','DeltaValue_Max_Z','DeltaValue_Min','Responders_EX','Responders_IN',...
  52. 'Responders_CombinedEX','ZPeaksN_byTrial','MotionPost','MotionPre','NoseDisp','MotionCorr','Pre_DeltaValue_Mean','Pre_DeltaValue_Max_Z',...
  53. 'Pre_DeltaValue_Max','Pre_DeltaValue_Min','Pre_Responders_CombinedEX','Pre_Responders_EX','Pre_Responders_IN','Pre_ZPeaksN_byTrial',...
  54. 'Pre_MotionPost','Pre_MotionPre','Pre_NoseDisp','Pre_MotionCorr','DeltaValue_Max_adjustNose','Responders_EX_adjustNose','Responders_CombinedEX_adjustNose',...
  55. 'DeltaValue_MaxShifter','DeltaValue_MaxZShifter','Responders_CombinedEX_Shifter','Pre_DeltaValue_MaxShifter','Pre_DeltaValue_MaxZShifter','Pre_Responders_CombinedEX_Shifter'});
  56. TrialTrace_Table = cell2table(cell(0,11), 'VariableNames', {'Animal','BehaviorGroup','State','Day','Odor','Abs_CellNumber',...
  57. 'CellReg_Index','Abs_TrialN','Stim_TrialN','Ztrace_trial_final','Rawtrace_trial_final'});
  58. Pre_TrialTrace_Table = cell2table(cell(0,11), 'VariableNames', {'Animal','BehaviorGroup','State','Day','Odor','Abs_CellNumber',...
  59. 'CellReg_Index','Abs_TrialN','Stim_TrialN','Pre_Ztrace_trial_final','Pre_Rawtrace_trial_final'});
  60. WholeTrace_Table = cell2table(cell(0,9), 'VariableNames', {'Animal','BehaviorGroup','State','Day',...
  61. 'Abs_CellNumber','CellReg_Index','RecordingLength','Sum_All_PeaksN','Peaks_Bins'});
  62. BEHTrace_Table = cell2table(cell(0,9), 'VariableNames', {'Animal','BehaviorGroup','State','Day','Odor'...
  63. ,'Abs_TrialN','Stim_TrialN','Motion_trial_final','NoseDisp_trial_final'});
  64. ZTraces = {};
  65. Peaks_Array = {};
  66. Footprints_MasterTable = cell2table(cell(0,7), 'VariableNames',{'Animal','BehaviorGroup','State','Day','Abs_CellNumber','CellReg_Index','Footprint'});
  67. Behavior_Array = {};
  68. % Check to make sure that folder actually exists. Warn user if it doesn't.
  69. if ~isdir(myFolder)
  70. errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
  71. uiwait(warndlg(errorMessage));
  72. return;
  73. end
  74. % Get a list of all files in the folder with the desired file name pattern.
  75. Deconvolved_Trace_Pattern = fullfile(myFolder, '*DeconTrace.csv'); % Deconvolved traces
  76. Deconvolved_Traces_List = dir(Deconvolved_Trace_Pattern);
  77. Raw_Trace_Pattern = fullfile(myFolder, '*RawTrace.csv'); % Raw traces
  78. Raw_Trace_List = dir(Raw_Trace_Pattern);
  79. Timestamp_Pattern = fullfile(myFolder, '*timeStamps.csv'); % Timestamps
  80. Timestamp_List = dir(Timestamp_Pattern);
  81. Note_Pattern = fullfile(myFolder, '*notes.csv'); % Event points with stamps
  82. Note_List = dir(Note_Pattern);
  83. Index_Pattern = fullfile(myFolder, '*index.csv'); % Deconvolved traces
  84. Index_List = dir(Index_Pattern);
  85. Footprints_Pattern = fullfile(myFolder,'*.mat'); % footprints files
  86. Footprints_List = dir(Footprints_Pattern);
  87. Behavior_Pattern = fullfile(myFolder, '*Behavior.csv'); % behavior values
  88. Behavior_List = dir(Behavior_Pattern);
  89. BehaviorStamps_Pattern = fullfile(myFolder, '*stampsBeh.csv'); % behavior stamps
  90. BehaviorStamps_List = dir(BehaviorStamps_Pattern);
  91. %% Loop through matching traces/timestamps
  92. % make sure to follow formatting guide here; organized so that files are
  93. % listed in the folder in the correct ordered to match traces with their
  94. % respective timestamps, notes, and index
  95. %typically runs to length(Deconvolved_Traces_List); alter to manual
  96. %numbers if you only want to run a specific set of animals
  97. for k = 1:length(Deconvolved_Traces_List)
  98. baseDecon_TraceName = Deconvolved_Traces_List(k).name; % base name of file
  99. fullDecon_TraceName = fullfile(myFolder, baseDecon_TraceName); % file name + relative folder directory
  100. inputValue.deconvolvedTrace = load(fullDecon_TraceName); % loaded trace
  101. baseRaw_TraceName = Raw_Trace_List(k).name; % base name of file
  102. fullRaw_TraceName = fullfile(myFolder, baseRaw_TraceName); % file name + relative folder directory
  103. inputValue.rawTrace = load(fullRaw_TraceName); % loaded file
  104. baseTimestamp_Name = Timestamp_List(k).name; % base name of file
  105. fullTimestamp_Name = fullfile(myFolder, baseTimestamp_Name); % file name + relative folder directory
  106. inputValue.timestamp = readtable(fullTimestamp_Name); % loaded file
  107. baseNote_Name = Note_List(k).name; % base name of file
  108. fullNote_Name = fullfile(myFolder, baseNote_Name); % file name + relative folder directory
  109. inputValue.notes = readtable(fullNote_Name); % loaded file
  110. baseIndex_Name = Index_List(k).name; % base name of file
  111. fullIndex_Name = fullfile(myFolder, baseIndex_Name); % file name + relative folder directory
  112. inputValue.Index = load(fullIndex_Name); % loaded file
  113. baseFootprints_Name = Footprints_List(k).name; % base name of file
  114. fullFootprints_Name = fullfile(myFolder, baseFootprints_Name); % file name + relative folder directory
  115. inputValue.Footprints = load(fullFootprints_Name); % loaded file
  116. baseBehavior_Name = Behavior_List(k).name; % base name of file
  117. fullBehavior_Name = fullfile(myFolder, baseBehavior_Name); % file name + relative folder directory
  118. inputValue.Behavior = readmatrix(fullBehavior_Name, 'NumHeaderLines', 3); % loaded file
  119. inputValue.Behavior = inputValue.Behavior(:,2:end);
  120. baseBehaviorStamps_Name = BehaviorStamps_List(k).name; % base name of file
  121. fullBehaviorStamps_Name = fullfile(myFolder, baseBehaviorStamps_Name); % file name + relative folder directory
  122. inputValue.BehaviorStamps = readtable(fullBehaviorStamps_Name); % loaded file
  123. % have to change/reformat scope timestamps based on scope version number; coded to V4,
  124. % change the column calls for the vectors if the names be different
  125. Times_Vector = table2array(inputValue.notes(:,1));
  126. Stamps_TimeVector = inputValue.timestamp.('TimeStamp_ms_');
  127. Stamps_FrameVector = inputValue.timestamp.('FrameNumber');
  128. % generates timepoints from the notes/timestamps files; adjusts frame value for downsample input
  129. for i = 1:length(Times_Vector)
  130. time_holder = Times_Vector(i);
  131. [val,idx]=min(abs(Stamps_TimeVector-time_holder));
  132. inputValue.timePoints(i) = Stamps_FrameVector(idx);
  133. end
  134. inputValue.downSampleFactor = table2array(inputValue.KeyTable(k,'StampDownsampleFactor')); % used to convert time stamps if using downsampled data
  135. inputValue.frate = table2array(inputValue.KeyTable(k,'FrameRateFinal')); %frames per second
  136. inputValue.timePoints = round(inputValue.timePoints ./ inputValue.downSampleFactor); %downsample timepoints
  137. % generates timepoints for behavior file from the notes/timestamps files
  138. Stamps_TimeVector_BEH = inputValue.BehaviorStamps.('TimeStamp_ms_');
  139. Stamps_FrameVector_BEH = inputValue.BehaviorStamps.('FrameNumber');
  140. for i = 1:length(Times_Vector)
  141. time_holder = Times_Vector(i);
  142. [val,idx]=min(abs(Stamps_TimeVector_BEH-time_holder));
  143. inputValue.timePoints_BEH(i) = Stamps_FrameVector_BEH(idx);
  144. end
  145. % Behavior stuff for total file
  146. % eudlidean displacement of all tracked components from frame to frame
  147. %avg_beh_FR = max(inputValue.BehaviorStamps.('FrameNumber')) / (max(inputValue.BehaviorStamps.('TimeStamp_ms_')) / 1000);
  148. % find total number of tracked points, initialize empty arrays
  149. total_n = (size(inputValue.Behavior,2))/3;
  150. euclid_all = zeros(length(inputValue.Behavior),total_n);
  151. log_all = zeros(length(inputValue.Behavior),total_n);
  152. % for each set of x/y points, find euclidean distance from point to
  153. % point for each frame recorded
  154. for i = 1:total_n
  155. current_coords = inputValue.Behavior(:,((3*i)-2):((3*i)-1));
  156. log_all(:,i) = inputValue.Behavior(:,(3*i)) > inputValue.DLC_cutoff;
  157. for ii = 1:(length(current_coords)-1)
  158. euc_distance_scope_point = sqrt((current_coords(ii+1,1)-current_coords(ii,1))^2 + ...
  159. (current_coords(ii+1,2)-current_coords(ii,2))^2 );
  160. euclid_scope(ii+1) = euc_distance_scope_point;
  161. end
  162. euclid_all(:,i) = euclid_scope;
  163. clear euclid_scope
  164. end
  165. % remove any points that don't meet the input confidence cutoff and
  166. % calculate average across all tracked points, sum across moving window
  167. % for downsampled version (adjusted to match scope final frate)
  168. euclid_all(log_all == 0) = NaN;
  169. average_euclid = mean(euclid_all,2,'omitNaN');
  170. euclid_down = movsum(average_euclid,(inputValue.frate_BEH/inputValue.frate));
  171. % nose displacement from either ear (use left if possible)
  172. log_nose_left = sum(inputValue.Behavior(:,[3,6]) > inputValue.DLC_cutoff,2) == 2;
  173. log_nose_right = sum(inputValue.Behavior(:,[3,9]) > inputValue.DLC_cutoff,2) == 2;
  174. displacement_nose_left = (inputValue.Behavior(:,2) - inputValue.Behavior(:,5));
  175. displacement_nose_right = (inputValue.Behavior(:,2) - inputValue.Behavior(:,8));
  176. displacement_final = zeros(length(inputValue.Behavior),1);
  177. % using left ear as default; only use right if its the only one, averaging
  178. % when both there can cause some weird jitter in the signal with it coming
  179. % and going from in frame
  180. for i = 1:length(inputValue.Behavior)
  181. if log_nose_left(i) == 1 && log_nose_right(i) == 1
  182. displacement_final(i) = displacement_nose_left(i);
  183. elseif log_nose_left(i) == 1 && log_nose_right(i) == 0
  184. displacement_final(i) = displacement_nose_left(i);
  185. elseif log_nose_left(i) == 0 && log_nose_right(i) == 1
  186. displacement_final(i) = displacement_nose_right(i);
  187. elseif log_nose_left(i) == 0 && log_nose_right(i) == 0
  188. displacement_final(i) = NaN;
  189. end
  190. end
  191. displacement_final = displacement_final .* -1;
  192. clear log_nose_left log_nose_right
  193. % Zscoring for deconvolved values; input array, sample std dev (not pop), dimension (rows = 2)
  194. Decon_Z = zscore(inputValue.deconvolvedTrace, 0, 2);
  195. Raw_Z = zscore(inputValue.rawTrace, 0, 2);
  196. % Smoothing function if used on raw data; input array, dimension (rows = 2), method, window
  197. if inputValue.SmoothToggle == 1
  198. RawTrace_PostSmooth = smoothdata(inputValue.rawTrace, 2, 'movmean', inputValue.SmoothWindow);
  199. else if inputValue.SmoothToggle == 0
  200. RawTrace_PostSmooth = inputValue.rawTrace;
  201. end
  202. end
  203. % subtract min value from all values to shift to avoid negative values
  204. RawTrace_PostSmooth = RawTrace_PostSmooth - min(RawTrace_PostSmooth, [], 2);
  205. % Peak detection from z-scored data; coded by britgod
  206. allZPeaks = zeros(size(Decon_Z)); %peak location and size saved to this array
  207. allZPeaks_logical = zeros(size(Decon_Z));
  208. allrawPeaks = zeros(size(Decon_Z));
  209. for ii = 1:size(Decon_Z, 1)
  210. [dummy_pks, dummy_locs] = findpeaks(Decon_Z(ii,:),'MinPeakHeight', inputValue.Zcutoff_wholeTrace, 'MinPeakWidth', inputValue.PeakDistance, 'MinPeakProminence', inputValue.Prominence);
  211. placeholderZ = zeros(1,length(Decon_Z));
  212. placeholderZ(dummy_locs) = dummy_pks;
  213. placeholderraw = zeros(1,length(Decon_Z));
  214. placeholderraw(dummy_locs) = Decon_Z(ii,dummy_locs);
  215. allZPeaks(ii,:) = placeholderZ;
  216. allZPeaks_logical(ii,:) = (placeholderZ >0);
  217. allrawPeaks(ii,:) = placeholderraw;
  218. clear dummy_pks dummy_locs placeholder
  219. end
  220. PeakTotal_perCell = sum(allZPeaks_logical,2);
  221. Zabove_threshold = Decon_Z > inputValue.Zcutoff_wholeTrace;
  222. % DF calculation at stimulus inputValue.timePoints for raw signal
  223. % initializing empty arrays
  224. preMean_Z = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  225. postMaxV_Z = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  226. pre_stdD = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  227. preMean = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  228. postMean = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  229. postMaxV = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  230. postMinV = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  231. Responders_Zthreshold = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  232. ZPeaksN_timepoints = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  233. Ztrace_trial = cell(1,size(inputValue.timePoints,2));
  234. Rawtrace_trial = cell(1,size(inputValue.timePoints,2));
  235. Motion_trial = cell(1,size(inputValue.timePoints,2));
  236. NoseDisp_trial = cell(1,size(inputValue.timePoints,2));
  237. preMotion = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  238. postMotion = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  239. postNose = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  240. postNose_IDX = zeros(1,size(inputValue.timePoints,2));
  241. % check for NaN in timepoints (dropped trials); fill those as NaN, then
  242. % actually pull real values from trials that were not dropped
  243. for ii = 1:size(inputValue.timePoints,2)
  244. if inputValue.timePoints(ii) == 0
  245. preMean_Z(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  246. postMaxV_Z(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  247. pre_stdD(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  248. preMean(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  249. postMean(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  250. postMaxV(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  251. postMinV(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  252. Responders_Zthreshold(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  253. ZPeaksN_timepoints(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  254. Ztrace_trial{ii} = NaN(size(inputValue.deconvolvedTrace,1),((inputValue.trialTrace_Pre*inputValue.frate)+(inputValue.trialTrace_Post*inputValue.frate)));
  255. Rawtrace_trial{ii} = NaN(size(inputValue.deconvolvedTrace,1),((inputValue.trialTrace_Pre*inputValue.frate)+(inputValue.trialTrace_Post*inputValue.frate)));
  256. Motion_trial{ii} = NaN(size(inputValue.deconvolvedTrace,1),((inputValue.behaviorTrace_Pre*inputValue.frate)+(inputValue.trialTrace_Post*inputValue.frate)));
  257. NoseDisp_trial{ii} = NaN(size(inputValue.deconvolvedTrace,1),((inputValue.behaviorTrace_Pre*inputValue.frate)+(inputValue.trialTrace_Post*inputValue.frate)));
  258. preMotion(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  259. postMotion(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  260. postNose(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  261. else
  262. % first group is taking raw or ztrace values from timepoints and
  263. % splitting to new arrays; trial measures include pre window while
  264. Ztrace_trial_holder = Decon_Z(:,(inputValue.timePoints(ii)-(inputValue.frate * inputValue.trialTrace_Pre)):(inputValue.timePoints(ii) + ((inputValue.frate * inputValue.trialTrace_Post))-1));
  265. Ztrace_trial{ii} = Ztrace_trial_holder;
  266. Rawtrace_trial_holder = RawTrace_PostSmooth(:,(inputValue.timePoints(ii)-(inputValue.frate * inputValue.trialTrace_Pre)):(inputValue.timePoints(ii) + ((inputValue.frate * inputValue.trialTrace_Post))-1));
  267. Rawtrace_trial{ii} = Rawtrace_trial_holder;
  268. Motion_trial_holder = average_euclid((inputValue.timePoints_BEH(ii)-(inputValue.frate_BEH * inputValue.behaviorTrace_Pre)):(inputValue.timePoints_BEH(ii) + ((inputValue.frate_BEH * inputValue.trialTrace_Post))-1));
  269. Motion_trial{ii} = Motion_trial_holder.';
  270. NoseDisp_trial_holder = displacement_final((inputValue.timePoints_BEH(ii)-(inputValue.frate_BEH * inputValue.behaviorTrace_Pre)):(inputValue.timePoints_BEH(ii) + ((inputValue.frate_BEH * inputValue.trialTrace_Post))-1));
  271. NoseDisp_trial{ii} = NoseDisp_trial_holder.';
  272. % second group is calculating values of interest around timepoints;
  273. % includes pre/post means, max's, responders, etc.
  274. pre_stdD(:,ii) = std(RawTrace_PostSmooth(:,((inputValue.timePoints(ii)-(inputValue.preTrial * inputValue.frate))):(inputValue.timePoints(ii)-1)), 0, 2);
  275. preMean(:,ii) = mean(RawTrace_PostSmooth(:,((inputValue.timePoints(ii)-(inputValue.preTrial * inputValue.frate))):(inputValue.timePoints(ii)-1)), 2);
  276. preMean_Z(:,ii) = mean(Raw_Z(:,((inputValue.timePoints(ii)-(inputValue.preTrial * inputValue.frate))):(inputValue.timePoints(ii)-1)), 2);
  277. postMean(:,ii) = mean(RawTrace_PostSmooth(:,(inputValue.timePoints(ii)):((inputValue.timePoints(ii)-1)+(inputValue.postTrial*inputValue.frate))), 2);
  278. [postMaxHolder,postMaxIndex] = max(RawTrace_PostSmooth(:,(inputValue.timePoints(ii)):((inputValue.timePoints(ii)-1)+(inputValue.postTrial*inputValue.frate))), [], 2);
  279. postMaxV(:,ii) = postMaxHolder;
  280. [postMaxZHolder,postMaxZIndex] = max(Raw_Z(:,(inputValue.timePoints(ii)):((inputValue.timePoints(ii)-1)+(inputValue.postTrial*inputValue.frate))), [], 2);
  281. postMaxV_Z(:,ii) = postMaxZHolder;
  282. postMinHolder = min(RawTrace_PostSmooth(:,(inputValue.timePoints(ii)):((inputValue.timePoints(ii)-1)+(inputValue.postTrial*inputValue.frate))), [], 2);
  283. postMinV(:,ii) = postMinHolder;
  284. zMaxHolder = max(Decon_Z(:,(inputValue.timePoints(ii)):((inputValue.timePoints(ii)-1)+(inputValue.postTrial*inputValue.frate))), [], 2);
  285. Responders_Zthreshold(:,ii) = zMaxHolder;
  286. ZPeaksN_timepoints(:,ii) = sum(allZPeaks_logical(:,(inputValue.timePoints(ii)):((inputValue.timePoints(ii)-1)+(inputValue.postTrial*inputValue.frate))),2);
  287. %DLC behavior things; nose displacement is an average +/- 2 frames
  288. %on either side of the displacment peak in the post trial window
  289. preMotion(:,ii) = repmat(mean(average_euclid((inputValue.timePoints_BEH(ii)-(inputValue.preTrial * inputValue.frate_BEH)):(inputValue.timePoints_BEH(ii)-1))),size(Decon_Z,1),1);
  290. postMotion(:,ii) = repmat(mean(average_euclid(inputValue.timePoints_BEH(ii):((inputValue.timePoints_BEH(ii)-1)+(inputValue.postTrial*inputValue.frate_BEH)))),size(Decon_Z,1),1);
  291. [postNose_max,postNose_max_idx] = max(displacement_final(inputValue.timePoints_BEH(ii):((inputValue.timePoints_BEH(ii)-1)+(inputValue.postTrial*inputValue.frate_BEH))));
  292. postNose(:,ii) = mean(displacement_final((inputValue.timePoints_BEH(ii)+postNose_max_idx-3):(inputValue.timePoints_BEH(ii)+postNose_max_idx+1)),'omitNaN');
  293. postNose_IDX(:,ii) = postNose_max_idx;
  294. end
  295. end
  296. % new set of timepoints for shifting delta window to time of nose
  297. % raising minus 3 frames as a small buffer to the behavior point
  298. inputValue.timePoints_BEH_New = (inputValue.timePoints_BEH + postNose_IDX);
  299. for q = 1:length(Times_Vector)
  300. time_holder = inputValue.timePoints_BEH_New(q);
  301. [val,idx]=min(abs(Stamps_FrameVector_BEH-time_holder));
  302. inputValue.times_BEH_new(q) = Stamps_TimeVector_BEH(idx);
  303. end
  304. for r = 1:length(Times_Vector)
  305. time_holder = inputValue.times_BEH_new(r);
  306. [val,idx]=min(abs(Stamps_TimeVector-time_holder));
  307. inputValue.timePoints_BEH_adjustedNose(r) = Stamps_FrameVector(idx);
  308. end
  309. % downsample new adjusted behavior timepoints to match scope frames
  310. inputValue.timePoints_BEH_adjustedNose = round(inputValue.timePoints_BEH_adjustedNose ./ inputValue.downSampleFactor);
  311. % create extra empty arrays and pull stuff of interest from any adjusted timepoints
  312. preMean_adjustNose = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  313. postMaxV_adjustNose = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  314. pre_stdD_adjustNose = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  315. % check for NaN in timepoints (dropped trials); fill those as NaN, then
  316. % actually pull real values from trials that were not dropped
  317. for ii = 1:size(inputValue.timePoints,2)
  318. if inputValue.timePoints(ii) == 0
  319. preMean_adjustNose(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  320. postMaxV_adjustNose(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  321. pre_stdD_adjustNose(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  322. else
  323. pre_stdD_adjustNose(:,ii) = std(RawTrace_PostSmooth(:,((inputValue.timePoints_BEH_adjustedNose(ii)-(inputValue.preTrial * inputValue.frate))):(inputValue.timePoints_BEH_adjustedNose(ii)-1)), 0, 2);
  324. [postMaxHolder_adjustNose,postMaxIndex_adjustNose] = max(RawTrace_PostSmooth(:,(inputValue.timePoints_BEH_adjustedNose(ii)):((inputValue.timePoints_BEH_adjustedNose(ii)-1)+(inputValue.postTrial*inputValue.frate))), [], 2);
  325. postMaxV_adjustNose(:,ii) = postMaxHolder_adjustNose;
  326. preMean_adjustNose(:,ii) = mean(RawTrace_PostSmooth(:,((inputValue.timePoints_BEH_adjustedNose(ii)-(inputValue.preTrial * inputValue.frate))):(inputValue.timePoints_BEH_adjustedNose(ii)-1)), 2);
  327. end
  328. end
  329. % calculate desired outputs
  330. deltaV_mean = postMean - preMean;
  331. deltaV_max_Z = (postMaxV_Z - preMean_Z);
  332. deltaV_max = ((postMaxV - preMean));
  333. deltaV_min = ((preMean - postMinV));
  334. delta_detect_EX = ((postMaxV - preMean) ./ (pre_stdD) > inputValue.SDcutoff);
  335. delta_detect_IN = ((preMean - postMinV) ./ (pre_stdD) > inputValue.SDcutoff);
  336. combined_detectEX = (delta_detect_EX .* (Responders_Zthreshold > inputValue.Zcutoff_combinedDetect));
  337. post_motion_corr = repmat((corr(postMotion(1,:).',postMaxV.','rows','complete')).',1,size(inputValue.timePoints,2));
  338. deltaV_max_adjustNose = (postMaxV_adjustNose-preMean);
  339. delta_detect_EX_adjustNose = ((postMaxV_adjustNose - preMean_adjustNose) ./ (pre_stdD_adjustNose) > inputValue.SDcutoff);
  340. combined_detect_EX_adjustNose = (delta_detect_EX_adjustNose .* (Responders_Zthreshold > inputValue.Zcutoff_combinedDetect));
  341. % DF calculation at time before stimulus inputValue.timePoints;
  342. % post-measure window size used to determine how long pre the normal
  343. % timepoint to set the new, pre-timepoints
  344. Pre_preMean_Z = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  345. Pre_postMaxV_Z = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  346. Pre__stdD = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  347. Pre_Mean = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  348. Pre_postMean = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  349. Pre_postMaxV = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  350. Pre_postMinV = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  351. Pre_Responders_Zthreshold = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  352. Pre_ZPeaksN_timepoints = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  353. Pre_Ztrace_trial = cell(1,size(inputValue.timePoints,2));
  354. Pre_Rawtrace_trial = cell(1,size(inputValue.timePoints,2));
  355. Pre_preMotion = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  356. Pre_postMotion = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  357. Pre_postNose = zeros(size(Decon_Z,1),size(inputValue.timePoints,2));
  358. % check for NaN in timepoints (dropped trials); fill those as NaN, then
  359. % actually pull real values from trials that were not dropped
  360. for ii = 1:size(inputValue.timePoints,2)
  361. if inputValue.timePoints(ii) == 0
  362. Pre_preMean_Z(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  363. Pre_postMaxV_Z(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  364. Pre__stdD(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  365. Pre_Mean(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  366. Pre_postMean(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  367. Pre_postMaxV(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  368. Pre_postMinV(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  369. Pre_Responders_Zthreshold(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  370. Pre_ZPeaksN_timepoints(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  371. Pre_Ztrace_trial{ii} = NaN(size(inputValue.deconvolvedTrace,1),((inputValue.trialTrace_Pre*inputValue.frate)+(inputValue.trialTrace_Post*inputValue.frate)));
  372. Pre_Rawtrace_trial{ii} = NaN(size(inputValue.deconvolvedTrace,1),((inputValue.trialTrace_Pre*inputValue.frate)+(inputValue.trialTrace_Post*inputValue.frate)));
  373. Pre_preMotion(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  374. Pre_postMotion(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  375. Pre_postNose(:,ii) = NaN(size(inputValue.deconvolvedTrace,1),1);
  376. else
  377. % first group is taking raw or ztrace values from timepoints and
  378. % splitting to new arrays; trial measures include pre window while
  379. % behavior is only the freezing window
  380. Ztrace_trial_holder = Decon_Z(:,(inputValue.timePoints(ii)-(inputValue.frate * inputValue.trialTrace_Pre)-(inputValue.frate*inputValue.postTrial)):(inputValue.timePoints(ii) + ((inputValue.frate * inputValue.trialTrace_Post))-1-(inputValue.frate*inputValue.postTrial)));
  381. Pre_Ztrace_trial{ii} = Ztrace_trial_holder;
  382. Rawtrace_trial_holder = RawTrace_PostSmooth(:,(inputValue.timePoints(ii)-(inputValue.frate * inputValue.trialTrace_Pre)-(inputValue.frate*inputValue.postTrial)):(inputValue.timePoints(ii) + ((inputValue.frate * inputValue.trialTrace_Post))-1-(inputValue.frate*inputValue.postTrial)));
  383. Pre_Rawtrace_trial{ii} = Rawtrace_trial_holder;
  384. % second group is calculating values of interest around timepoints;
  385. % includes pre/post means, max's, responders, etc.
  386. timepoints_adjusted = inputValue.timePoints(ii) - (inputValue.preValue_shift * inputValue.frate);
  387. timepoints_adjustedBEH = inputValue.timePoints_BEH(ii) - (inputValue.preValue_shift * inputValue.frate_BEH);
  388. Pre__stdD(:,ii) = std(RawTrace_PostSmooth(:,((timepoints_adjusted-(inputValue.preTrial * inputValue.frate)-(inputValue.frate*inputValue.postTrial))):(timepoints_adjusted-1-(inputValue.frate*inputValue.postTrial))), 0, 2);
  389. Pre_Mean(:,ii) = mean(RawTrace_PostSmooth(:,((timepoints_adjusted-(inputValue.preTrial * inputValue.frate)-(inputValue.frate*inputValue.postTrial))):(timepoints_adjusted-1-(inputValue.frate*inputValue.postTrial))), 2);
  390. Pre_preMean_Z(:,ii) = mean(Raw_Z(:,((timepoints_adjusted-(inputValue.preTrial * inputValue.frate)-(inputValue.frate*inputValue.postTrial))):(timepoints_adjusted-1-(inputValue.frate*inputValue.postTrial))), 2);
  391. Pre_postMean(:,ii) = mean(RawTrace_PostSmooth(:,(timepoints_adjusted-(inputValue.frate*inputValue.postTrial)):((timepoints_adjusted-1)+(inputValue.postTrial*inputValue.frate)-(inputValue.frate*inputValue.postTrial))), 2);
  392. [postMaxHolder,postMaxIndex] = max(RawTrace_PostSmooth(:,(timepoints_adjusted-(inputValue.frate*inputValue.postTrial)):((timepoints_adjusted-1)+(inputValue.postTrial*inputValue.frate)-(inputValue.frate*inputValue.postTrial))), [], 2);
  393. Pre_postMaxV(:,ii) = postMaxHolder;
  394. [postMaxZHolder,postMaxZIndex] = max(Raw_Z(:,(timepoints_adjusted-(inputValue.frate*inputValue.postTrial)):((timepoints_adjusted-1)+(inputValue.postTrial*inputValue.frate)-(inputValue.frate*inputValue.postTrial))), [], 2);
  395. Pre_postMaxV_Z(:,ii) = postMaxZHolder;
  396. postMinHolder = min(RawTrace_PostSmooth(:,(timepoints_adjusted-(inputValue.frate*inputValue.postTrial)):((timepoints_adjusted-1)+(inputValue.postTrial*inputValue.frate)-(inputValue.frate*inputValue.postTrial))), [], 2);
  397. Pre_postMinV(:,ii) = postMinHolder;
  398. zMaxHolder = max(Decon_Z(:,(timepoints_adjusted-(inputValue.frate*inputValue.postTrial)):((timepoints_adjusted-1)+(inputValue.postTrial*inputValue.frate)-(inputValue.frate*inputValue.postTrial))), [], 2);
  399. Pre_Responders_Zthreshold(:,ii) = zMaxHolder;
  400. Pre_ZPeaksN_timepoints(:,ii) = sum(allZPeaks_logical(:,(timepoints_adjusted-(inputValue.frate*inputValue.postTrial)):((timepoints_adjusted-1)+(inputValue.postTrial*inputValue.frate)-(inputValue.frate*inputValue.postTrial))),2);
  401. %DLC behavior things; nose displacement is an average +/- 2 frames
  402. %on either side of the displacment peak in the post trial window
  403. Pre_preMotion(:,ii) = repmat(mean(average_euclid((timepoints_adjustedBEH-(inputValue.preTrial * inputValue.frate_BEH)-(inputValue.frate_BEH*inputValue.postTrial)):(timepoints_adjustedBEH-1-(inputValue.frate_BEH*inputValue.postTrial)))),size(Decon_Z,1),1);
  404. Pre_postMotion(:,ii) = repmat(mean(average_euclid((timepoints_adjustedBEH-(inputValue.frate_BEH*inputValue.postTrial)):((timepoints_adjustedBEH-1)+(inputValue.postTrial*inputValue.frate_BEH)-(inputValue.frate_BEH*inputValue.postTrial)))),size(Decon_Z,1),1);
  405. [postNose_max,postNose_max_idx] = max(displacement_final((timepoints_adjustedBEH-(inputValue.frate_BEH*inputValue.postTrial)):((timepoints_adjustedBEH-1)+(inputValue.postTrial*inputValue.frate_BEH)-(inputValue.frate_BEH*inputValue.postTrial))));
  406. Pre_postNose(:,ii) = mean(displacement_final((timepoints_adjustedBEH+postNose_max_idx-3-(inputValue.frate_BEH*inputValue.postTrial)):(timepoints_adjustedBEH+postNose_max_idx+1-(inputValue.frate_BEH*inputValue.postTrial))),'omitNaN');
  407. end
  408. end
  409. % calculate stuff you want as an output
  410. Pre_deltaV_mean = Pre_postMean - Pre_Mean;
  411. Pre_deltaV_max_Z = (Pre_postMaxV_Z - Pre_preMean_Z);
  412. Pre_deltaV_max = ((Pre_postMaxV - Pre_Mean));
  413. Pre_deltaV_min = ((Pre_Mean - Pre_postMinV));
  414. Pre_delta_detect_EX = ((Pre_postMaxV - Pre_Mean) ./ (Pre__stdD) > inputValue.SDcutoff);
  415. Pre_delta_detect_IN = ((Pre_Mean - Pre_postMinV) ./ (Pre__stdD) > inputValue.SDcutoff);
  416. Pre_combined_detectEX = (Pre_delta_detect_EX .* (Pre_Responders_Zthreshold > inputValue.Zcutoff_combinedDetect));
  417. Pre_post_motion_corr = repmat((corr(Pre_postMotion(1,:).',Pre_postMaxV.','rows','complete')).',1,size(inputValue.timePoints,2));
  418. %delta shifter code; shifting along the response window x2 and calculate new deltas
  419. %based on the shift across all possible points, generates a larger cell
  420. %matrix encompassing all possible points
  421. postMaxV_shifter = cell(1,size(inputValue.timePoints,2));
  422. preMean_shifter = cell(1,size(inputValue.timePoints,2));
  423. postMaxV_Delta_shifter = cell(1,size(inputValue.timePoints,2));
  424. postMaxV_CombinedResponders_shifter = cell(1,size(inputValue.timePoints,2));
  425. deltaZ_shifter = cell(1,size(inputValue.timePoints,2));
  426. Pre_postMaxV_shifter = cell(1,size(inputValue.timePoints,2));
  427. Pre_postMaxV_CombinedResponders_shifter = cell(1,size(inputValue.timePoints,2));
  428. Pre_deltaZ_shifter = cell(1,size(inputValue.timePoints,2));
  429. wPre = inputValue.shifter_pre * inputValue.frate;
  430. wPost = inputValue.shifter_post * inputValue.frate;
  431. for ii = 1:size(inputValue.timePoints,2)
  432. if inputValue.timePoints(ii) == 0
  433. dummy = NaN(size(Decon_Z,1),inputValue.shifter_maxFrames);
  434. postMaxV_shifter{1,ii} = dummy;
  435. preMean_shifter{1,ii} = dummy;
  436. postMaxV_Delta_shifter{1,ii} = dummy;
  437. postMaxV_CombinedResponders_shifter{1,ii} = dummy;
  438. deltaZ_shifter{1,ii} = dummy;
  439. Pre_postMaxV_shifter{1,ii} = dummy;
  440. Pre_postMaxV_CombinedResponders_shifter{1,ii} = dummy;
  441. Pre_deltaZ_shifter{1,ii} = dummy;
  442. else
  443. postMaxV_shifter_now = zeros(size(Decon_Z,1),inputValue.shifter_maxFrames);
  444. preMean_shifter_now = zeros(size(Decon_Z,1),inputValue.shifter_maxFrames);
  445. preStd_shifter_now = zeros(size(Decon_Z,1),inputValue.shifter_maxFrames);
  446. Zmax_shifter_holder = zeros(size(Decon_Z,1),inputValue.shifter_maxFrames);
  447. ZpreMean_shifter_holder = zeros(size(Decon_Z,1),inputValue.shifter_maxFrames);
  448. Pre_std_shifter_holder = zeros(size(Decon_Z,1),inputValue.shifter_maxFrames);
  449. Pre_Mean_shifter_holder = zeros(size(Decon_Z,1),inputValue.shifter_maxFrames);
  450. Pre_Max_shifter_holder = zeros(size(Decon_Z,1),inputValue.shifter_maxFrames);
  451. Pre_Zmax_shifter_holder = zeros(size(Decon_Z,1),inputValue.shifter_maxFrames);
  452. Pre_ZpreMean_shifter_holder = zeros(size(Decon_Z,1),inputValue.shifter_maxFrames);
  453. for q = (1:inputValue.shifter_maxFrames)-1
  454. postMaxV_shifter_now(:,(q+1)) = max(RawTrace_PostSmooth(:,(inputValue.timePoints(ii)+q):(inputValue.timePoints(ii)+q-1+wPost)), [], 2);
  455. preMean_shifter_now(:,(q+1)) = mean(RawTrace_PostSmooth(:,(inputValue.timePoints(ii)+q-wPre):(inputValue.timePoints(ii)+q-1)), 2);
  456. preStd_shifter_now(:,(q+1)) = std(RawTrace_PostSmooth(:,(inputValue.timePoints(ii)+q-wPre):(inputValue.timePoints(ii)+q-1)), 0, 2);
  457. Zmax_shifter_holder(:,(q+1)) = max(Decon_Z(:,(inputValue.timePoints(ii)+q):(inputValue.timePoints(ii)+q-1+wPost)), [], 2);
  458. ZpreMean_shifter_holder(:,(q+1)) = mean(Decon_Z(:,(inputValue.timePoints(ii)+q-wPost-wPre):(inputValue.timePoints(ii)+q-wPost-1)), 2);
  459. timepoints_adjusted = inputValue.timePoints(ii) - (inputValue.preValue_shift * inputValue.frate);
  460. Pre_std_shifter_holder(:,(q+1)) = std(RawTrace_PostSmooth(:,(timepoints_adjusted+q-wPost-wPre-inputValue.shifter_maxFrames):(timepoints_adjusted+q-wPost-inputValue.shifter_maxFrames-1)), 0, 2);
  461. Pre_Mean_shifter_holder(:,(q+1)) = mean(RawTrace_PostSmooth(:,(timepoints_adjusted+q-wPost-wPre-inputValue.shifter_maxFrames):(timepoints_adjusted+q-wPost-inputValue.shifter_maxFrames-1)), 2);
  462. Pre_Max_shifter_holder(:,(q+1)) = max(RawTrace_PostSmooth(:,(timepoints_adjusted+q-wPost-inputValue.shifter_maxFrames):(timepoints_adjusted+q-1-inputValue.shifter_maxFrames)), [], 2);
  463. Pre_Zmax_shifter_holder(:,(q+1)) = max(Decon_Z(:,(timepoints_adjusted+q-wPost-inputValue.shifter_maxFrames):(timepoints_adjusted+q-1-inputValue.shifter_maxFrames)), [], 2);
  464. Pre_ZpreMean_shifter_holder(:,(q+1)) = mean(Decon_Z(:,(timepoints_adjusted+q-wPost-wPre-inputValue.shifter_maxFrames):(timepoints_adjusted+q-wPost-inputValue.shifter_maxFrames-1)), 2);
  465. end
  466. postMaxV_CombinedResponders_shifter{1,ii} = (((postMaxV_shifter_now - preMean_shifter_now) ./ preStd_shifter_now) >...
  467. inputValue.SDcutoff) & (Zmax_shifter_holder > inputValue.Zcutoff_combinedDetect);
  468. postMaxV_Delta_shifter{1,ii} = (postMaxV_shifter_now - preMean_shifter_now);
  469. postMaxV_shifter{1,ii} = postMaxV_shifter_now;
  470. preMean_shifter{1,ii} = preMean_shifter_now;
  471. deltaZ_shifter{1,ii} = (Zmax_shifter_holder - ZpreMean_shifter_holder);
  472. Pre_postMaxV_shifter{1,ii} = (Pre_Max_shifter_holder - Pre_Mean_shifter_holder);
  473. Pre_postMaxV_CombinedResponders_shifter{1,ii} = (((Pre_Max_shifter_holder - Pre_Mean_shifter_holder) ./ Pre_std_shifter_holder) >...
  474. inputValue.SDcutoff) & (Pre_Zmax_shifter_holder > inputValue.Zcutoff_combinedDetect);
  475. Pre_deltaZ_shifter{1,ii} = (Pre_Zmax_shifter_holder - Pre_ZpreMean_shifter_holder);
  476. end
  477. end
  478. % pull things that go into table for absolute cell #, day, behavior group, etc.
  479. Animal = cellstr(repmat(char(table2array(inputValue.KeyTable(k,'AnimalNumber'))),size(deltaV_max,1),1));
  480. Day = repmat(table2array(inputValue.KeyTable(k,'Day')),size(deltaV_max,1),1);
  481. Abs_CellNumber = transpose(1:size(deltaV_max,1));
  482. BehaviorGroup = cellstr(repmat(char(table2array(inputValue.KeyTable(k,'BehaviorGroup'))),size(deltaV_max,1),1));
  483. State = cellstr(repmat(char(table2array(inputValue.KeyTable(k,'State'))),size(deltaV_max,1),1));
  484. Footprint = num2cell(inputValue.Footprints.spatial_footprints,[2 3]);
  485. % cell reg sometimes leaves out cells that
  486. % were included in the initial spatial footprints from the final index
  487. % added this line in to resort the cell-index for the
  488. % final table and to then include a zero value for any cell that was in
  489. % the original footprints for a day but wasn't included in the final
  490. % output
  491. CellReg_Index = zeros(size(inputValue.deconvolvedTrace,1),1);
  492. for i = 1:size(inputValue.deconvolvedTrace,1)
  493. if find(inputValue.Index == i) > 0 % if the index exists, put the right number in
  494. CellReg_Index(i,:) = find(inputValue.Index == i);
  495. else % otherwise, drop a zero in to indicate it wasn't included
  496. CellReg_Index(i,:) = 0;
  497. end
  498. end
  499. % pull output values and odors for each trial, add to table with above
  500. % indentifiers for each cell
  501. for i = 1:size(deltaV_max,2)
  502. Odor = cellstr(repmat(char(table2array(inputValue.notes(i,2))),size(deltaV_max,1),1));
  503. Abs_TrialN = repmat(i,size(deltaV_max,1),1);
  504. % get absolute trial number; truncate to current
  505. % trial being looked at, then count string appearence of that odor
  506. counter_trunc = table2array(inputValue.notes(1:i,2));
  507. Stim_TrialN = repmat(sum(count(counter_trunc,table2array(inputValue.notes(i,2)))),size(deltaV_max,1),1);
  508. % add numbers into the table; fill gaps with NaN; uses
  509. % zeros for trace delta values (as those are always a number that isn't
  510. % zero. For logical indices, not converting to NaN. Max trial length
  511. % input globally at the start of the script determines the number of
  512. % columns for each table, so make sure thats right. To_add number
  513. % pulled solely from the delta frame as it should match the others.
  514. DeltaValue_MaxShifter = postMaxV_Delta_shifter{1,i};
  515. DeltaValue_MaxZShifter = deltaZ_shifter{1,i};
  516. Responders_CombinedEX_Shifter = postMaxV_CombinedResponders_shifter{1,i};
  517. DeltaValue_Mean = deltaV_mean(:,i);
  518. DeltaValue_Max_Z = deltaV_max_Z(:,i);
  519. DeltaValue_Max = deltaV_max(:,i);
  520. DeltaValue_Min = deltaV_min(:,i);
  521. Responders_CombinedEX = combined_detectEX(:,i);
  522. Responders_EX = delta_detect_EX(:,i);
  523. Responders_IN = delta_detect_IN(:,i);
  524. ZPeaksN_byTrial = ZPeaksN_timepoints(:,i);
  525. MotionPost = postMotion(:,i);
  526. MotionPre = preMotion(:,i);
  527. NoseDisp = postNose(:,i);
  528. MotionCorr = post_motion_corr(:,i);
  529. DeltaValue_Max_adjustNose = deltaV_max_adjustNose(:,i);
  530. Responders_EX_adjustNose = delta_detect_EX_adjustNose(:,i);
  531. Responders_CombinedEX_adjustNose = combined_detect_EX_adjustNose(:,i);
  532. Pre_DeltaValue_MaxShifter = Pre_postMaxV_shifter{1,i};
  533. Pre_DeltaValue_MaxZShifter = Pre_deltaZ_shifter{1,i};
  534. Pre_Responders_CombinedEX_Shifter = Pre_postMaxV_CombinedResponders_shifter{1,i};
  535. Pre_DeltaValue_Mean = Pre_deltaV_mean(:,i);
  536. Pre_DeltaValue_Max_Z = Pre_deltaV_max_Z(:,i);
  537. Pre_DeltaValue_Max = Pre_deltaV_max(:,i);
  538. Pre_DeltaValue_Min = Pre_deltaV_min(:,i);
  539. Pre_Responders_CombinedEX = Pre_combined_detectEX(:,i);
  540. Pre_Responders_EX = Pre_delta_detect_EX(:,i);
  541. Pre_Responders_IN = Pre_delta_detect_IN(:,i);
  542. Pre_ZPeaksN_byTrial = Pre_ZPeaksN_timepoints(:,i);
  543. Pre_MotionPost = Pre_postMotion(:,i);
  544. Pre_MotionPre = Pre_preMotion(:,i);
  545. Pre_NoseDisp = Pre_postNose(:,i);
  546. Pre_MotionCorr = Pre_post_motion_corr(:,i);
  547. %combine outputs, then append to final table/arrays
  548. newTableInput = table(Animal,BehaviorGroup,State,Day,Odor,Abs_CellNumber,CellReg_Index,Abs_TrialN,Stim_TrialN,...
  549. DeltaValue_Max,DeltaValue_Mean,DeltaValue_Max_Z,DeltaValue_Min,Responders_EX,Responders_IN,Responders_CombinedEX,...
  550. ZPeaksN_byTrial,MotionPost,MotionPre,NoseDisp,MotionCorr,Pre_DeltaValue_Mean,Pre_DeltaValue_Max_Z,Pre_DeltaValue_Max,...
  551. Pre_DeltaValue_Min,Pre_Responders_CombinedEX,Pre_Responders_EX,Pre_Responders_IN,Pre_ZPeaksN_byTrial,Pre_MotionPost,...
  552. Pre_MotionPre,Pre_NoseDisp,Pre_MotionCorr,DeltaValue_Max_adjustNose,Responders_EX_adjustNose,Responders_CombinedEX_adjustNose,...
  553. DeltaValue_MaxShifter,DeltaValue_MaxZShifter,Responders_CombinedEX_Shifter,Pre_DeltaValue_MaxShifter,Pre_DeltaValue_MaxZShifter,...
  554. Pre_Responders_CombinedEX_Shifter);
  555. OutputTable = [OutputTable;newTableInput];
  556. Ztrace_trial_final = num2cell(Ztrace_trial{i},2);
  557. Rawtrace_trial_final = num2cell(Rawtrace_trial{i},2);
  558. Pre_Ztrace_trial_final = num2cell(Pre_Ztrace_trial{i},2);
  559. Pre_Rawtrace_trial_final = num2cell(Pre_Rawtrace_trial{i},2);
  560. % output for trial traces
  561. new_trialTable_input = table(Animal,BehaviorGroup,State,Day,Odor,Abs_CellNumber,...
  562. CellReg_Index,Abs_TrialN,Stim_TrialN,Ztrace_trial_final,Rawtrace_trial_final);
  563. TrialTrace_Table = [TrialTrace_Table;new_trialTable_input];
  564. Pre_new_trialTable_input = table(Animal,BehaviorGroup,State,Day,Odor,Abs_CellNumber,...
  565. CellReg_Index,Abs_TrialN,Stim_TrialN,Pre_Ztrace_trial_final,Pre_Rawtrace_trial_final);
  566. Pre_TrialTrace_Table = [Pre_TrialTrace_Table;Pre_new_trialTable_input];
  567. % wipe cell arrays from each loop, will otherwise keep adding on to
  568. % prior entries
  569. clear ZTrace_trial_final Rawtrace_trial_final Pre_Ztrace_trial_final...
  570. Pre_Rawtrace_trial_final
  571. end
  572. totalPeak_Bins = floor(size(allZPeaks,2) / (inputValue.totalZ_Bins * inputValue.frate));
  573. for i = 1:totalPeak_Bins
  574. peaks_now = allZPeaks_logical(:,(i*inputValue.totalZ_Bins*inputValue.frate-...
  575. inputValue.totalZ_Bins*inputValue.frate + 1):...
  576. (i*inputValue.totalZ_Bins*inputValue.frate));
  577. sum_peaks_now = sum(peaks_now,2);
  578. Peaks_Bins{i} = sum_peaks_now;
  579. end
  580. % output of info relevant to the total traces
  581. Peaks_Bins = cell2mat(Peaks_Bins);
  582. Peaks_Bins(:,end+1:inputValue.totalZ_Bins_max) = NaN; % add to backfill for differing recording lengths
  583. RecordingLength = repmat(length(Decon_Z),size(allrawPeaks,1),1);
  584. Sum_All_PeaksN = sum(allZPeaks_logical,2);
  585. new_WholeTableInput = table(Animal,BehaviorGroup,State,Day,Abs_CellNumber,CellReg_Index,RecordingLength,Sum_All_PeaksN,Peaks_Bins);
  586. WholeTrace_Table = [WholeTrace_Table;new_WholeTableInput];
  587. % ouput of info relevant to footprints
  588. new_FootprintsInput = table(Animal,BehaviorGroup,State,Day,Abs_CellNumber,CellReg_Index,Footprint);
  589. Footprints_MasterTable = [Footprints_MasterTable;new_FootprintsInput];
  590. % behavior table input; after above loop for trial info so i can re-use
  591. % table info; don't put before any of the other ones as lable structure is
  592. % different for this table
  593. Motion_trial_final = Motion_trial.';
  594. NoseDisp_trial_final = NoseDisp_trial.';
  595. Animal = repmat(Animal(1),size(inputValue.timePoints,2),1);
  596. BehaviorGroup = repmat(BehaviorGroup(1),size(inputValue.timePoints,2),1);
  597. State = repmat(State(1),size(inputValue.timePoints,2),1);
  598. Odor = table2cell(inputValue.notes(:,2));
  599. Day = repmat(Day(1),size(inputValue.timePoints,2),1);
  600. Abs_TrialN = (1:size(inputValue.timePoints,2)).';
  601. Stim_TrialN = zeros(size(inputValue.timePoints,2),1);
  602. for i = 1:size(deltaV_max,2)
  603. counter_trunc = table2array(inputValue.notes(1:i,2));
  604. Stim_TrialN(i) = sum(count(counter_trunc,table2array(inputValue.notes(i,2))));
  605. end
  606. new_BEHinput = table(Animal,BehaviorGroup,State,Day,Odor,Abs_TrialN,Stim_TrialN,...
  607. Motion_trial_final,NoseDisp_trial_final);
  608. BEHTrace_Table = [BEHTrace_Table;new_BEHinput];
  609. clear Motion_trial_final NoseDisp_trial_final
  610. % wipe cell arrays from each loop
  611. clear Ztrace_Behavior Ztrace_trial Rawtrace_trial Rawtrace_Behavior Peaks_Bins Pre_Ztrace_trial_final Pre_Rawtrace_trial_final
  612. % wipe timepoints input to avoid leftovers from long files
  613. inputValue.timePoints = [];
  614. inputValue.timePoints_BEH = [];
  615. inputValue.timePoints_BEH_New = [];
  616. inputValue.timePoints_BEH_adjustedNose = [];
  617. inputValue.times_BEH_new = [];
  618. % output for behavior
  619. MotionIdx = average_euclid;
  620. NoseDisp = displacement_final;
  621. new_behavior_input = {MotionIdx,NoseDisp;};
  622. Behavior_Array = [Behavior_Array;new_behavior_input];
  623. % ZTrace Table; saved in order of trial appearance in list
  624. Trace = Decon_Z;
  625. new_ZTrace = {Trace};
  626. ZTraces = [ZTraces;new_ZTrace];
  627. Peaks = allZPeaks;
  628. new_Peaks = {allZPeaks};
  629. Peaks_Array = [Peaks_Array;new_Peaks];
  630. end
  631. %% any manual trimming post-running
  632. % remove animal that doesn't actual have behavioral data from those arrays
  633. BEHTrace_Table(strcmp(BEHTrace_Table.Animal,'NEC273332')==true,:) = [];
  634. Behavior_Array(1:6,:) = [];
  635. %% save final output tables/arrays
  636. save('InputParameters.mat', 'inputValue');
  637. save('OutputTable.mat','OutputTable');
  638. save('TrialTraces.mat', 'TrialTrace_Table');
  639. save('Pre_TrialTraces.mat','Pre_TrialTrace_Table');
  640. save('WholeTrace_Table.mat','WholeTrace_Table');
  641. save('ZTraces.mat','ZTraces');
  642. save('Peaks_All.mat','Peaks_Array');
  643. save('Footprints_MasterTable.mat','Footprints_MasterTable','-v7.3');
  644. save('Behavior_MasterTable.mat','Behavior_Array');
  645. save('Behavior_TraceTable.mat','BEHTrace_Table');
  646. % use '-v7.3' flag in saves after file names if they too big

responseExtraction_Behavior.m at commit 6c7b41a, under GPL-3.0 · at the source

Overview

Authors: Ian F. Chapman1,2, Martin A. Raymond1,3, Max L. Fletcher1
ORCID iDs: Ian F. Chapman
  1. Department of Anatomy & Neurobiology, University of Tennessee Health Science Center, Memphis, TN, USA
  2. Monell Chemical Senses Center, Philadelphia, PA, USA
  3. Department of Psychology, Brandeis University, Waltham, PA, USA
Institutions: University of Tennessee Health Science Center (United States); Monell Chemical Senses Center (United States); Brandeis University (United States)
Journal: iScience, volume 29, issue 6, article 115897
Dates: received 5 November 2025; accepted 22 April 2026; published online 27 April 2026
Type: Research article · Language: English
License: CC BY-NC-ND
Identifiers: DOI 10.1016/j.isci.2026.115897 · PMID 42181288 · PMCID PMC13197642 · OpenAlex W4391792311
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: mouse (organism), systems (subfield)
Methods: Connectivity, Statistics, Machine learning, fMRI & imaging
Keywords: neuroscience, behavioral neuroscience, systems neuroscience
Topic: Olfactory and Sensory Function Studies (Sensory Systems, Neuroscience), according to OpenAlex
Funding: NIH (DC013779); Monell Chemical Senses Center (T32DC000014)
Citations: not cited yet (Europe PMC); 73 references in the paper
Research resources: pAAV(AAV1).Syn.GCaMP6s.WPRE.SV40 RRID:Addgene_100843, C57BL/6 mice RRID:IMSR_JAX:000664

Abstract

The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.

Repositories

Its files are read in the Code ↔ Paper reader above, with 5 matches between paragraphs and lines of code.

Zenodo 19666573

License: GPL-3.0
State: the link answers, verified on 30 September 2026
Evidence: files inventoried
Size: 1 file
Software Heritage: not checked
Found in: “Data and code availability”
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Availability: 1 check, the latest on 30 September 2026: the link answers (HTTP 200)
  • 30 September 2026: the link answers (HTTP 200)
At the source:

aharoni-lab/miniscope-daq-qt-software

License: GPL-3.0
State: the link answers, verified on 30 September 2026
Evidence: files inventoried
Commit: 7e644bf52ba5b6f4cdbe0be7f8ed52fd2f792aaa, 1 August 2026
Languages: C++ (39), C/C++ (26), Python (2), Shell (2)
Size: 195 files, 69 scripts
Software Heritage: not archived
Found in: the text, “Behavioral and imaging equipment”
Holds: README, license file, environment (conda-lock.yml, environment.yml, packaging/conda-virtual-packages.yml), tests, continuous integration
Not found: CITATION.cff, documentation
Tools: NumPy (1 file), OpenCV (1 file), TensorFlow (1 file)
Availability: 1 check, the latest on 30 September 2026: the link answers
  • 30 September 2026: the link answers
71 files

ifchapman/chapman-et-al-iscience

License: GPL-3.0
State: the link answers, verified on 30 September 2026
Evidence: files inventoried
Commit: 6c7b41a57ae366fb9a24237d0946c8d459f902a5, 20 April 2026
Languages: MATLAB (46)
Size: 67 files, 46 scripts
Software Heritage: not archived
Found in: the Zenodo archive record
Holds: README, license file
Not found: CITATION.cff, environment file, tests, continuous integration, documentation
Availability: 1 check, the latest on 30 September 2026: the link answers
  • 30 September 2026: the link answers
48 files

The paper's code and data availability statement is in the Data section.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 3 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 115 scripts, each with its path and the digest of its content;
  • 5 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

No dataset and no data link were found in the paper.

Code and data availability statement

The paper has a code and data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

  • it points to the authors' code: Zenodo 19666573
  • it says that the data are available on request
  • it says that the code is available on request

Read it in the paper: doi.org/10.1016/j.isci.2026.115897.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 30 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 3 authors, 3 keywords, 2 funders, 72 references, 2 RRIDs.

Cite

This paper

Chapman, I. F., Raymond, M. A., & Fletcher, M. L. (2026). Experience and behavior modulate piriform cortex odor representation in freely moving mice. iScience, 29(6), 115897. https://doi.org/10.1016/j.isci.2026.115897

BibTeX

@article{chapman2026experience,
author = {Chapman, Ian F. and Raymond, Martin A. and Fletcher, Max L.},
title = {{Experience and behavior modulate piriform cortex odor representation in freely moving mice}},
journal = {iScience},
year = {2026},
month = apr,
volume = {29},
number = {6},
pages = {115897},
publisher = {Elsevier},
issn = {2589-0042},
doi = {10.1016/j.isci.2026.115897},
url = {https://doi.org/10.1016/j.isci.2026.115897},
pmid = {42181288},
pmcid = {PMC13197642}
}

RIS

TY - JOUR
AU - Chapman, Ian F.
AU - Raymond, Martin A.
AU - Fletcher, Max L.
TI - Experience and behavior modulate piriform cortex odor representation in freely moving mice
T2 - iScience
J2 - iScience
PY - 2026
DA - 2026/04/27
VL - 29
IS - 6
SP - 115897
SN - 2589-0042
PB - Elsevier
DO - 10.1016/j.isci.2026.115897
UR - https://doi.org/10.1016/j.isci.2026.115897
LA - en
ER -

CSL-JSON

{
"id": "10.1016/j.isci.2026.115897",
"type": "article-journal",
"title": "Experience and behavior modulate piriform cortex odor representation in freely moving mice",
"container-title": "iScience",
"author": [
{
"family": "Chapman",
"given": "Ian F."
},
{
"family": "Raymond",
"given": "Martin A."
},
{
"family": "Fletcher",
"given": "Max L."
}
],
"container-title-short": "iScience",
"volume": "29",
"issue": "6",
"page": "115897",
"DOI": "10.1016/j.isci.2026.115897",
"PMID": "42181288",
"PMCID": "PMC13197642",
"ISSN": "2589-0042",
"publisher": "Elsevier",
"URL": "https://doi.org/10.1016/j.isci.2026.115897",
"language": "en",
"issued": {
"date-parts": [
[
2026,
4,
27
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1038/s41467-026-70356-9
A topographical organization in the primary olfactory cortex.
Journal: Nature communications
In common: systems, mouse, 17 references
[2] doi:10.7554/elife.103373
Experience shapes the transformation of olfactory representations along the cortico-hippocampal pathway.
Journal: eLife
In common: mouse, 11 references
[3] doi:10.7554/elife.107905 [code]
Adult-neurogenesis allows for representational stability and flexibility in early olfactory system.
Journal: eLife
In common: 9 references
[4] doi:10.1371/journal.pcbi.1014297 [code]
Statistics of cortical representational drift can enable robust readout.
Journal: PLoS computational biology
In common: NumPy, systems, 7 references
[5] doi:10.1038/s41467-026-72445-1 [code]
Perception and neural representation of intermittent odor stimuli in mice.
Journal: Nature communications
In common: NumPy, mouse, 6 references
[6] doi:10.1038/s41467-026-75792-1 [code]
Temporal drift of sleep-wake representations in hypothalamic neuronal ensembles.
Journal: Nature communications
In common: Signal Processing Toolbox, systems, mouse, 5 references
[7] doi:10.1038/s41467-026-71356-5 [code]
Generalization of fear learning is shaped by inhibitory sensory processing in mice.
Journal: Nature communications
In common: mouse, 5 references
[8] doi:10.1038/s41593-026-02232-0 [code]
Entorhinal cortex represents task-relevant remote locations independently of CA1.
Journal: Nature neuroscience
In common: OpenCV, Signal Processing Toolbox, Statistics and Machine Learning Toolbox, 1 other tool, systems, mouse, 2 references
[9] doi:10.1038/s41593-026-02377-y [code]
Representations of the intrinsic value of information in mouse orbitofrontal cortex.
Journal: Nature neuroscience
In common: Statistics and Machine Learning Toolbox, systems, mouse, 4 references
[10] doi:10.1038/s41467-026-73001-7 [code]
Separable and integrated pleasantness coding for appetitive and aversive odors across olfactory and ventral prefrontal cortices.
Journal: Nature communications
In common: Signal Processing Toolbox, Statistics and Machine Learning Toolbox, 3 references

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.