0001 function [raw, time, xform_hb, xform_gcamp, xform_gcampCorr, isbrain, xform_isbrain, markers] ...
0002 = gcampImagingRaw(raw, systemInfo, sessionInfo, varargin)
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 p = inputParser;
0032 pkgDir = what('bauerParams');
0033 addParameter(p,'ledDir',string(fullfile(pkgDir.path,'ledSpectra')),@isstring);
0034 addParameter(p,'extCoeffDir',string(pkgDir.path),@isstring);
0035 addParameter(p,'darkFrames',0,@isnumeric);
0036 addOptional(p,'mask',[],@islogical);
0037 addOptional(p,'markers',[],@isstruct);
0038 parse(p,varargin{:});
0039
0040 if isempty(p.Results.mask)
0041 getMask = true;
0042 else
0043 getMask = false;
0044 isbrain = p.Results.mask;
0045 markers = p.Results.markers;
0046 end
0047
0048 ledDir = p.Results.ledDir;
0049 extCoeffDir = p.Results.extCoeffDir;
0050 darkFrameNum = p.Results.darkFrames;
0051
0052
0053 hbSpecies = 2:4;
0054 gcampSpecies = 1;
0055 blueWavelength = 458;
0056 greenWavelength = 512;
0057 bluePath = 5.6E-4;
0058 greenPath = 5.7E-4;
0059
0060 extCoeffFile = fullfile(extCoeffDir,"prahl_extinct_coef.txt");
0061
0062
0063
0064 freqIn = sessionInfo.framerate;
0065 freqOut = sessionInfo.freqout;
0066
0067 time = 1:size(raw,4);
0068 time = time./freqIn;
0069
0070 if freqOut == freqIn
0071 else
0072 disp([' downsample from ' num2str(freqIn) ' Hz to ' num2str(freqOut) ' Hz']);
0073
0074 resampledT = 1:round(size(raw,4)./freqIn*freqOut);
0075 raw = mouse.freq.resampledata(raw,time,resampledT);
0076
0077 time = resampledT;
0078 end
0079
0080
0081
0082 darkFrames = raw(:,:,:,2:darkFrameNum);
0083 if numel(darkFrames) > 0
0084 darkFrame = nanmean(darkFrames,4);
0085
0086
0087 raw = raw - repmat(darkFrame,1,1,1,size(raw,4));
0088 end
0089
0090 if darkFrameNum < 1
0091
0092 raw(:,:,:,1) = [];
0093 time(1) = [];
0094 else
0095
0096 raw(:,:,:,1:darkFrameNum) = [];
0097 time(1:darkFrameNum) = [];
0098
0099
0100 time = time - (time(1) - 2/freqOut);
0101
0102 end
0103
0104
0105
0106 if getMask
0107 rgbInd = systemInfo.rgb;
0108 WL = squeeze(raw(:,:,rgbInd,1));
0109 WL(:,:,1) = WL(:,:,1)./max(max(WL(:,:,1)));
0110 WL(:,:,2) = WL(:,:,2)./max(max(WL(:,:,2)));
0111 WL(:,:,3) = WL(:,:,3)./max(max(WL(:,:,3)));
0112
0113
0114 [isbrain, markers] = mouse.expSpecific.getLandMarksandMask(WL);
0115 end
0116
0117
0118
0119 procRaw = gcamp.procRaw(raw);
0120
0121
0122
0123 disp('get hemoglobin data');
0124
0125 for ind = 1:numel(systemInfo.LEDFiles)
0126 systemInfo.LEDFiles(ind) = fullfile(ledDir,systemInfo.LEDFiles(ind));
0127 end
0128
0129 highpassFreq = sessionInfo.highpass;
0130 lowpassFreq = sessionInfo.lowpass;
0131 oisBandpassFreq = [highpassFreq lowpassFreq];
0132
0133 [hbData, ~, ~]= ...
0134 mouse.preprocess.procOIS(procRaw(:,:,hbSpecies,:),...
0135 systemInfo.LEDFiles(hbSpecies), extCoeffFile, isbrain);
0136
0137
0138 xform_hb = mouse.expSpecific.transformHb(hbData, markers);
0139
0140
0141
0142 disp('get gcamp data');
0143
0144 fluorBandpassFreq = [highpassFreq lowpassFreq];
0145
0146 gcampData = procRaw(:,:,gcampSpecies,:);
0147 gcampData = mouse.expSpecific.procFluor(gcampData);
0148
0149 xform_gcamp = mouse.expSpecific.transformHb(gcampData, markers);
0150
0151
0152
0153 [lambda, extCoeff] = mouse.expSpecific.getHbExtCoeff(extCoeffFile);
0154
0155 blueLambdaInd = find(lambda == blueWavelength);
0156 greenLambdaInd = find(lambda == greenWavelength);
0157
0158 hbOAbsCoeff = extCoeff([blueLambdaInd greenLambdaInd],1);
0159 hbRAbsCoeff = extCoeff([blueLambdaInd greenLambdaInd],2);
0160
0161 xform_gcampCorr = mouse.physics.correctHb(xform_gcamp,xform_hb,...
0162 hbOAbsCoeff,hbRAbsCoeff,bluePath,greenPath);
0163
0164 xform_isbrain = mouse.expSpecific.transformHb(isbrain, markers);
0165
0166 end
0167