Home > BauerLab > MATLAB > lib > +gcamp > gcampImagingRaw.m

gcampImagingRaw

PURPOSE ^

gcampImagingRaw Processes rawData mat file to output hemoglobin data, gcamp, and

SYNOPSIS ^

function [raw, time, xform_hb, xform_gcamp, xform_gcampCorr, isbrain, xform_isbrain, markers]= gcampImagingRaw(raw, systemInfo, sessionInfo, varargin)

DESCRIPTION ^

gcampImagingRaw Processes rawData mat file to output hemoglobin data, gcamp, and
corrected gcamp data
   Input:
       raw = rawData data in 4D matrix form
       systemInfo = information about the imaging system used, such as
       which channels are rgb, and which LED files to use
       sessionInfo = information about the session, including sampling
       rate of data and lowpass highpass filtering options.
       mask (optional) = brain mask, logical array. If mask isn't given, then a GUI
       opens that user interacts with to make the mask. (needs to be
       provided with markers)
       markers (optional) = brain markers (needs to be provided with
       isbrain)
       darkFrames (parameter) = number of frames at the beginning that is
       dark
       ledDir (parameter) = directory of where the led spectrum text files are
       extCoeffDir (parameter) = directory of where hb extinction coefficients are 
   Output:
       xform_hb
       xform_gcamp
       xform_gcampCorr
       isbrain
       xform_isbrain
       markers
   Example:
       [rawData, time, xform_hb, xform_gcamp, xform_gcampCorr, isbrain, xform_isbrain, markers] ...
           = gcampImaging(tiffFileName, systemInfo, sessionInfo, 'ledDir', "C:\Repositories\GitHub\BauerLab\MATLAB\parameters\+bauerParams\ledSpectra")

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [raw, time, xform_hb, xform_gcamp, xform_gcampCorr, isbrain, xform_isbrain, markers] ...
0002     = gcampImagingRaw(raw, systemInfo, sessionInfo, varargin)
0003 %gcampImagingRaw Processes rawData mat file to output hemoglobin data, gcamp, and
0004 %corrected gcamp data
0005 %   Input:
0006 %       raw = rawData data in 4D matrix form
0007 %       systemInfo = information about the imaging system used, such as
0008 %       which channels are rgb, and which LED files to use
0009 %       sessionInfo = information about the session, including sampling
0010 %       rate of data and lowpass highpass filtering options.
0011 %       mask (optional) = brain mask, logical array. If mask isn't given, then a GUI
0012 %       opens that user interacts with to make the mask. (needs to be
0013 %       provided with markers)
0014 %       markers (optional) = brain markers (needs to be provided with
0015 %       isbrain)
0016 %       darkFrames (parameter) = number of frames at the beginning that is
0017 %       dark
0018 %       ledDir (parameter) = directory of where the led spectrum text files are
0019 %       extCoeffDir (parameter) = directory of where hb extinction coefficients are
0020 %   Output:
0021 %       xform_hb
0022 %       xform_gcamp
0023 %       xform_gcampCorr
0024 %       isbrain
0025 %       xform_isbrain
0026 %       markers
0027 %   Example:
0028 %       [rawData, time, xform_hb, xform_gcamp, xform_gcampCorr, isbrain, xform_isbrain, markers] ...
0029 %           = gcampImaging(tiffFileName, systemInfo, sessionInfo, 'ledDir', "C:\Repositories\GitHub\BauerLab\MATLAB\parameters\+bauerParams\ledSpectra")
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 % gcamp specific parameters
0053 hbSpecies = 2:4; % which LED channels are for hemoglobin?
0054 gcampSpecies = 1; % which LED channels are for gcamp?
0055 blueWavelength = 458; % nm
0056 greenWavelength = 512; % nm
0057 bluePath = 5.6E-4; % m
0058 greenPath = 5.7E-4; % m
0059 
0060 extCoeffFile = fullfile(extCoeffDir,"prahl_extinct_coef.txt");
0061 
0062 %% load tif file and convert it to mat file
0063 
0064 freqIn = sessionInfo.framerate; % sampling rate
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 %% remove dark frames as baseline
0081 
0082 darkFrames = raw(:,:,:,2:darkFrameNum); % 1st frame not considered
0083 if numel(darkFrames) > 0
0084     darkFrame = nanmean(darkFrames,4);
0085     
0086     % subtract darkframe from rest of the data
0087     raw = raw - repmat(darkFrame,1,1,1,size(raw,4));
0088 end
0089 
0090 if darkFrameNum < 1
0091     % get rid of first frame since it is nonsensical
0092     raw(:,:,:,1) = [];
0093     time(1) = [];
0094 else
0095     % get rid of first few frames that are dark
0096     raw(:,:,:,1:darkFrameNum) = [];
0097     time(1:darkFrameNum) = [];
0098     
0099     % make first frame 0 + 2/frameRate
0100     time = time - (time(1) - 2/freqOut); % first frame is 2/freqOut, and then so on
0101     % 2/freqOut because 1st frame is always bad.
0102 end
0103 
0104 %% make mask
0105 
0106 if getMask % only if the mask has to be gotten
0107     rgbInd = systemInfo.rgb;
0108     WL = squeeze(raw(:,:,rgbInd,1)); % makes nxnx3 array for white light image
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     % get landmarks and save mask file
0114     [isbrain, markers] = mouse.expSpecific.getLandMarksandMask(WL);
0115 end
0116 
0117 %% process raw
0118 
0119 procRaw = gcamp.procRaw(raw);
0120 
0121 %% get hemoglobin data
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 % hbData is in unit of mole/L
0137 
0138 xform_hb = mouse.expSpecific.transformHb(hbData, markers);
0139 
0140 %% get gcamp data
0141 
0142 disp('get gcamp data');
0143 
0144 fluorBandpassFreq = [highpassFreq lowpassFreq];
0145 
0146 gcampData = procRaw(:,:,gcampSpecies,:);
0147 gcampData = mouse.expSpecific.procFluor(gcampData); % detrending occurs
0148 
0149 xform_gcamp = mouse.expSpecific.transformHb(gcampData, markers);
0150 
0151 %% correct gcamp for hemoglobin
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

Generated on Fri 28-Dec-2018 21:42:50 by m2html © 2005