|
| 1 | +% SpeedControlledSteps.m |
| 2 | + |
| 3 | +%%Import data and metadata |
| 4 | +ephysData = ImportPatchData('incl',1); |
| 5 | +projects = {'FAT';'SYM'}; |
| 6 | + |
| 7 | +%fix a couple messed up names |
| 8 | +ephysData.FAT029 = ephysData.FAT029s; |
| 9 | +ephysData.FAT017 = ephysData.FAT017e001; |
| 10 | +ephysData.FAT164 = ephysData.FAT164001; |
| 11 | +ephysData = rmfield(ephysData,{'FAT017e001';'FAT029s';'FAT164001'}); |
| 12 | + |
| 13 | +ephysData = FilterProjectData(ephysData, projects); |
| 14 | +clear projects; |
| 15 | + |
| 16 | +ephysMetaData = ImportMetaData(); %Recording Database.xlsx |
| 17 | +attenuationData = ImportMetaData(); %AttenuationCalcs.xlsx |
| 18 | + |
| 19 | +%% Select recordings that match parameters based on metadata |
| 20 | + |
| 21 | +strainList = {'TU2769'}; |
| 22 | +internalList = {'IC2'}; |
| 23 | +stimPosition = {'anterior'}; |
| 24 | + |
| 25 | +wormPrep = {'dissected'}; |
| 26 | +cellDist = [40 200]; % stimulus/cell distance in um |
| 27 | +resistCutoff = '<250'; % Rs < 250 MOhm |
| 28 | +extFilterFreq = 2.5; % frequency of low-pass filter for stimulus command |
| 29 | +includeFlag = 1; |
| 30 | + |
| 31 | +anteriorControlCells = FilterRecordings(ephysData, ephysMetaData,... |
| 32 | + 'strain', strainList, 'internal', internalList, ... |
| 33 | + 'stimLocation', stimPosition, 'wormPrep', wormPrep, ... |
| 34 | + 'cellStimDistUm',cellDist, 'RsM', resistCutoff, ... |
| 35 | + 'stimFilterFrequencykHz', extFilterFreq, 'included', includeFlag); |
| 36 | + |
| 37 | +clear cellDist strainList internalList cellTypeList stimPosition resistCutoff ans wormPrep excludeCells; |
| 38 | + |
| 39 | +% This results in a file with three columns: cell ID, series, and sweeps |
| 40 | +% that have been approved for analysis use. |
| 41 | + |
| 42 | +%% Visual/manual exclusion of bad sweeps |
| 43 | +% This is mainly based on excluding sweeps with leak > 10pA, but also |
| 44 | +% sweeps where the recording was lost partway through or some unexpected |
| 45 | +% source of noise was clearly at play. |
| 46 | + |
| 47 | +% If you have already made a list of sweeps, skip this section and load the |
| 48 | +% list in the next section. |
| 49 | + |
| 50 | +protList ={'Control'}; |
| 51 | +matchType = 'first'; |
| 52 | + |
| 53 | +ExcludeSweeps(ephysData, protList, anteriorControlCells, 'matchType', matchType); |
| 54 | + |
| 55 | + |
| 56 | +%% Find MRCs |
| 57 | +% Lists: antAllSteps.xlsx and postAllSteps.xlsx from 180810 should contain |
| 58 | +% all relevant steps for anterior and posterior stimulation, respectively. |
| 59 | +protList ={'Control'}; |
| 60 | +matchType = 'first'; |
| 61 | + |
| 62 | +sortSweeps = {'magnitude','magnitude','magnitude','magnitude'}; |
| 63 | + |
| 64 | +[anteriorMRCs, antStim] = IdAnalysis(ephysData,protList,anteriorControlCells,'num','matchType',matchType, ... |
| 65 | + 'tauType','thalfmax', 'sortSweepsBy', sortSweeps, 'integrateCurrent',1 , ... |
| 66 | + 'recParameters', ephysMetaData,'sepByStimDistance',1,'subZeroCharge',1); |
| 67 | + |
| 68 | +clear protList sortSweeps matchType |
| 69 | + |
| 70 | +%% Average and plot |
| 71 | + |
| 72 | +% Set the filename |
| 73 | +fname = 'PatchData/controlSpeed_attCorrected(190729).xls'; |
| 74 | + |
| 75 | +eachSize = [4 8 12]'; |
| 76 | +distLimits = [40 200]; % limit to same average distance for anterior and posterior |
| 77 | +distCol = 12; |
| 78 | +whichStim = 1; %on or off |
| 79 | +noCorr = 0; % 1 to skip space clamp voltage attenuation correction |
| 80 | +Vc = -0.06; %in V |
| 81 | +Ena = 0.094; % in V |
| 82 | + |
| 83 | +% Manually change dType to 'curr', 'char', 'act', or 'decay' depending on |
| 84 | +% which analysis you would like to do. |
| 85 | +whichMRCs = anteriorMRCs; |
| 86 | +dType = 'curr'; |
| 87 | + |
| 88 | +switch dType |
| 89 | + case 'curr' |
| 90 | + peakCol = 6; % peak current |
| 91 | + case 'char' |
| 92 | + peakCol = 11; % integrated current/charge |
| 93 | + case 'act' |
| 94 | + peakCol = 8; % activation time constant |
| 95 | + case 'decay' |
| 96 | + peakCol = 9; % decay time constant |
| 97 | +end |
| 98 | + |
| 99 | +if whichStim == 2 |
| 100 | + eachSize = -eachSize; |
| 101 | +end |
| 102 | + |
| 103 | +thisAtt = attenuationData(:,[2 8 10]); |
| 104 | +thisName = cell(0); |
| 105 | +ant_Out = cell(length(eachSize)+1,size(whichMRCs,1)); |
| 106 | + |
| 107 | +for iCell = 1:size(whichMRCs,1) |
| 108 | + thisCell = whichMRCs{iCell,whichStim+2}; |
| 109 | + thisDist = mean(thisCell(:,distCol)); % check if cell distance is in range |
| 110 | + if thisDist <= distLimits(2) && thisDist >= distLimits(1) |
| 111 | + thisName{iCell,1} = whichMRCs{iCell,1}; %name |
| 112 | + thisName{iCell,2} = thisDist; |
| 113 | + ant_Out{1,iCell} = [dType '_' thisName{iCell,1}]; |
| 114 | + hasAtt = strcmp(thisName{iCell,1},thisAtt(:,1)); |
| 115 | + Iact = []; |
| 116 | + |
| 117 | + for iSize = 1:length(eachSize) |
| 118 | + stepSize = eachSize(iSize); |
| 119 | + whichStep = round(thisCell(:,1)*2)/2 == stepSize; %round to nearest 0.5 |
| 120 | + if any(whichStep) |
| 121 | + |
| 122 | + if any(hasAtt) && thisAtt{hasAtt,2} %if attenuation calc exists and not omitCell |
| 123 | + if noCorr == 0 || strcmp(dType,'peak') || strcmp(dType,'charge') %attenuation correction for current/charge but not taus |
| 124 | + Vm = Vc * thisAtt{hasAtt,3}; |
| 125 | + Im = thisCell(whichStep,peakCol); |
| 126 | + |
| 127 | + Iact(iSize,1) = (Im * (Vc-Ena)) ./ (Vm-Ena); |
| 128 | + else |
| 129 | + Im = thisCell(whichStep,peakCol); |
| 130 | + Iact(iSize,1) = Im; |
| 131 | + end |
| 132 | + else |
| 133 | + Iact(iSize,1) = nan; |
| 134 | + end |
| 135 | + |
| 136 | + else |
| 137 | + Iact(iSize,1) = nan; |
| 138 | + end |
| 139 | + end |
| 140 | + ant_Out(2:length(eachSize)+1,iCell) = num2cell(Iact); |
| 141 | + end |
| 142 | +end |
| 143 | +ant_Name = [{'Anterior', 'Ant_Dist'}; thisName]; |
| 144 | +ant_Out = ant_Out(:,~cellfun(@isempty, ant_Out(1,:))); % clear out empty waves (where dist didn't match) |
| 145 | +ant_Name = ant_Name(~cellfun(@isempty, ant_Name(:,1)),:); |
| 146 | + |
| 147 | +ant_Out = [[{'stepSize'};num2cell(eachSize)] ant_Out]; % append stepSize wave |
| 148 | + |
| 149 | +xlswrite(fname,ant_Out,['ant_' dType]); |
| 150 | +xlswrite(fname,ant_Name,'antStats'); |
| 151 | + |
| 152 | +clear iCell thisCell Iact whichMRCs whichStep hasAtt thisAtt Vc Ena thisName |
| 153 | + |
| 154 | +%% Normalize based on current/charge at given step size and write to xls |
| 155 | +% Normalizes within each condition |
| 156 | + |
| 157 | +stepSize = 12; % must be negative for off |
| 158 | + |
| 159 | +%Anterior |
| 160 | +which_Out = ant_Out; |
| 161 | +norm_Out = cell(size(which_Out)); |
| 162 | + |
| 163 | +currMat = cell2mat(which_Out(2:end,2:end)); |
| 164 | +whichRow = find(cellfun(@(x) abs(x - stepSize) < 0.5, which_Out(2:end,1))); |
| 165 | +normRow = currMat(whichRow,:); |
| 166 | +normMat = bsxfun(@rdivide,currMat,normRow); |
| 167 | +norm_Out(2:end,2:end) = num2cell(normMat); |
| 168 | +norm_Out(:,1) = which_Out(:,1); |
| 169 | +norm_Out(1,2:end) = cellfun(@(x) ['norm_' x],which_Out(1,2:end),'un',0); |
| 170 | + |
| 171 | +ant_Norm = norm_Out; |
| 172 | +xlswrite(fname,ant_Norm,['ant_' dType '_Norm']); |
| 173 | + |
| 174 | +clear currMat which Row normRow normMat norm_Out |
| 175 | + |
| 176 | + |
0 commit comments