Advertisement
UF6

nhpPlxDataExtractCombine

UF6
Mar 6th, 2018
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 19.60 KB | None | 0 0
  1. % NOTES
  2. % SpikeMat (ts x channels )
  3. % Creates and populates UnitQualityMat with Loc,Name,Ch,Unit Info
  4. % v2: add waveforms to the unitInfoMat
  5.  
  6. % nhpPath = goto_nhp();
  7. % dataPath = fullfile(nhpPath, 'data');
  8.  
  9. % goto_nhp; cd('data');
  10.  
  11. %% Edit ------------------------------------------------------------------------
  12. cd('C:\Users\rocke\Desktop\nhp-project')
  13. dbstop if error
  14.  
  15. if nargin == 0
  16.   fileDirs = {
  17.       './data/2016-05-18_jones'
  18.     };
  19. end
  20.  
  21. fs = 1000; %Hz, resolution of spike proccess
  22.  
  23. overwriteBool = false;
  24.  
  25. allAlignments = {'recordingStart', 'condTone', 'pureTone', 'allTone', 'puff'};
  26. % allAlignments = {'recordingStart', 'DBSonset', 'DBSoffset', 'condTone', 'pureTone', 'allTone', 'puff'}
  27.  
  28. minQuality = .8;
  29.  
  30. % monkeyname = 'mr. jones';
  31. % secsBeforeDataStart = 50;
  32. % secsPostDataStart = 130;
  33.  
  34. debugBool = 0;
  35.  
  36. %% -----------------------------------------------------------------------------
  37.  
  38. %% DEV TODOs
  39. % ...
  40.  
  41. %% parse options
  42. if nargin
  43.   % ensure input is cell array
  44.   if ~iscell(fileDirs)
  45.     fileDirs = {fileDirs};
  46.   end
  47. end
  48.  
  49. % ensure allAlignments is cell array
  50. if ~iscell(allAlignments)
  51.   allAlignments = {allAlignments};
  52. end
  53.  
  54. nAlignments = length(allAlignments);
  55.  
  56. nDirs = length(fileDirs);
  57. for iDir = 1:nDirs
  58.   fileDir = fileDirs{iDir};
  59.  
  60.   fprintf('Dir (%i/%i): %s \n', iDir, nDirs, fileDir);
  61.  
  62.   % check for existing files
  63.   saveFilesExist = nan(nAlignments,1);
  64.   for iAlignment = 1:nAlignments
  65.     thisAlignment = allAlignments{iAlignment};
  66.    
  67.     saveFilename = sprintf('spikeDataCombined_%s.mat', thisAlignment); % filename based on alignment
  68.     saveFilepath = fullfile(fileDir, saveFilename);
  69.    
  70.     saveFilesExist(iAlignment) = exist(saveFilepath, 'file');
  71.    
  72.     clear thisAlignment saveFilename saveFilepath
  73.   end
  74.  
  75.   if all(saveFilesExist) && ~overwriteBool
  76.     fprintf('  All save files exist, skipping dir... \n');
  77.     % continue
  78.   end
  79.  
  80.   % Get file names
  81.   files = lscell(fileDir);
  82.   dataFiles = files(contains(files, '.plx'));
  83.   nFiles = length(dataFiles);
  84.  
  85.   % skip if no files
  86.   if isempty(dataFiles)
  87.     % continue
  88.   end
  89.  
  90.   %% unitInfoMatCombined
  91.   unitInfoMatCombined = load(fullfile(fileDir, 'unitInfoMatCombined.mat'));
  92.   unitInfoMatCombined = unitInfoMatCombined.UnitInfoMatCombined;
  93.  
  94.   %% check number of units
  95.   for iFile = 1:nFiles
  96.     file = dataFiles{iFile};
  97.     filePathIn = fullfile(fileDir, file);
  98.    
  99.     spikeCounts{iFile} = plx_info(filePathIn, 1);
  100.    
  101.     unitsPerCh{iFile} = sum(logical(spikeCounts{iFile}));
  102.     totalUnitsPerFile(iFile) = sum(unitsPerCh{iFile});
  103.   end
  104.  
  105.   if sum(totalUnitsPerFile) ~= length(unitInfoMatCombined)
  106.     warning('Number of units found does not match those known from sessionInfo file. Skipping dir...')
  107.     % continue
  108.   end
  109.  
  110.   %% filter units
  111.   qualityUnits = ([unitInfoMatCombined.Quality] >= minQuality);
  112.   qualityUnits = qualityUnits & [unitInfoMatCombined.Isolated]; % check isolated==true
  113.   %   nQualityUnits = sum(qualityUnits);
  114.  
  115.   assert(nFiles == 2)
  116.  
  117.   % split into 2 files
  118.   qualityUnitsInFileLogical{1} = qualityUnits(1:totalUnitsPerFile(1));
  119.   qualityUnitsInFileLogical{2} = qualityUnits(totalUnitsPerFile(1)+1:end);
  120.  
  121.   % update unitInfoMatCombined
  122.   unitInfoMatCombined(~qualityUnits) = [];
  123.  
  124.   %% load plexon spike data (*.plx)
  125.  
  126.   fprintf('  Loading plexon spike data... \n')
  127.  
  128.   % Open files
  129.   spikeTimesSec = cell(nFiles,1);
  130.   spikeCounts = cell(nFiles,1);
  131.   for iFile = 1:nFiles
  132.     % File Path
  133.     file = dataFiles{iFile};
  134.     filePathIn = fullfile(fileDir, file);
  135.     [~,fileName] = fileparts(filePathIn);
  136.    
  137.     % File Print
  138.     fprintf('    File (%i/%i): %s \n', iFile, nFiles, fileName);
  139.    
  140.     qualityUnitsInFile{iFile} = find(qualityUnitsInFileLogical{iFile});
  141.    
  142.     % load data
  143.     verboseBool = false;
  144.     [spikeTimesSec{iFile}, ~, ~, durationSec, plxFs] = nhpPlxDataExtract(filePathIn, verboseBool, debugBool, qualityUnitsInFile{iFile});
  145.       % spikeTimesSec{file}{unit}
  146.       % Note: assumes last ch loaded by plx is empty/extra
  147.   end
  148.  
  149.   fprintf('  Done loading plexon spike data. \n');
  150.  
  151.   %% load sessionInfo
  152.   sessionInfoFile = files{contains(files, 'sessionInfo')};
  153.   sessionInfoPath = fullfile(fileDir, sessionInfoFile);
  154.   sessionInfoData = load(sessionInfoPath);
  155.   sessionInfo = sessionInfoData.sessionInfo;
  156.  
  157.   %% create binary spike process
  158.   fprintf('  Creating binary spike process... \n');
  159.  
  160.   for thisAlignment = allAlignments(:)'
  161.     thisAlignment = thisAlignment{1};
  162.    
  163.     fprintf('    Alignment: %s \n', thisAlignment);
  164.    
  165.     % start metadata
  166.     metadata.alignment = thisAlignment;
  167.     metadata.unitInfoMatCombined = unitInfoMatCombined;
  168.     metadata.sessionInfo = sessionInfo;
  169.    
  170.     % check for existing file
  171.     saveFilename = sprintf('spikeDataCombined_%s.mat', thisAlignment); % filename based on alignment
  172.     saveFilepath = fullfile(fileDir, saveFilename);
  173.     if exist(saveFilepath, 'file') && ~overwriteBool
  174.       fprintf('      Save file exists, skipping alignment %s (%s)\n', thisAlignment, saveFilepath);
  175.       % continue
  176.     end
  177.    
  178.     spkDataCombined = cell(nFiles, 1);
  179.  
  180.     for iFile = 1:nFiles
  181.       thisFileSpikeTimesSec = spikeTimesSec{iFile};
  182.  
  183.   %     nonEmptyChs = ~cellfun(@isempty, thisFileSpikeTimesSec);
  184.   %     unitsPerCh = sum(logical(spikeCounts{iFile}));
  185.   %     nTotalUnits = sum(unitsPerCh{iFile});
  186.       nTotalQualityUnits = length(qualityUnitsInFile{iFile});
  187.  
  188.       % ignore the empty last extra channel erroneously added by readall plx
  189.   %     nonEmptyChs(end) = 1;
  190.  
  191.       switch thisAlignment
  192.         case 'recordingStart'
  193.           unitDim = 2;
  194.           nTimeInd = ceil(durationSec * fs);
  195.           spkDataCombined{iFile} = zeros(nTimeInd, nTotalQualityUnits, 'single'); % time by units
  196.  
  197.           for iUnit = 1:nTotalQualityUnits
  198.             thisUnitSpikeTimesSec = thisFileSpikeTimesSec{iUnit};
  199.  
  200.             % convert times to indicies
  201.             thisUnitSpikeInds = round(thisUnitSpikeTimesSec * fs);
  202.  
  203.             spkDataCombined{iFile}(thisUnitSpikeInds, iUnit) = 1;
  204.           end
  205.           clear iUnit
  206.  
  207.         case {'condTone', 'pureTone', 'allTone', 'puff'}
  208.           % cond tone start min about 1 sec away from puff
  209.           % pure tone start min about 3 sec away from puff
  210.           % 2 tones start min about 4 sec away from each other
  211.  
  212.           % tone: 500 ms
  213.           % puff: ~106 ms (105-110 ms skewed right)
  214.  
  215.           % convert trial start time stamps to unts of ms
  216.           puffTimesSec = sessionInfo.CondPuffTone.PuffTimes / plxFs;
  217.           condToneTimesSec = sessionInfo.CondPuffTone.condSoundOnsetTimesPts / plxFs;
  218.           pureToneTimeSec = sessionInfo.CondPuffTone.pureToneOnsetTimesPts / plxFs;
  219.          
  220.           unitDim = 3;
  221.  
  222.           switch thisAlignment
  223.             case 'condTone'
  224.               % 500 ms before start, 2000 ms after start
  225.               % gets 500 ms before tone, tone, puff, and ~1400 ms after puff
  226.  
  227.               preEvntTimeLenInMs = 500; %ms
  228.               postEvntTimeLenInMs = 2000; %ms
  229.  
  230.               trialEvntsSec = condToneTimesSec;
  231.  
  232.               spkDataCombined{iFile} = makeTrialData(preEvntTimeLenInMs, postEvntTimeLenInMs, trialEvntsSec);
  233.               metadata.trials_Start_Evnt_End_sec = getTrialsStart_Evnt_End(preEvntTimeLenInMs, postEvntTimeLenInMs, trialEvntsSec);
  234.             case 'pureTone'
  235.               % 500 ms before start, 2000 ms after start
  236.               % gets 500 ms before tone, tone, and 1500 ms after tone, but no puff
  237.  
  238.               preEvntTimeLenInMs = 500;
  239.               postEvntTimeLenInMs = 2000;
  240.  
  241.               trialEvntsSec = pureToneTimeSec;
  242.  
  243.               spkDataCombined{iFile} = makeTrialData(preEvntTimeLenInMs, postEvntTimeLenInMs, trialEvntsSec);
  244.               metadata.trials_Start_Evnt_End_sec = getTrialsStart_Evnt_End(preEvntTimeLenInMs, postEvntTimeLenInMs, trialEvntsSec);
  245.             case 'allTone'
  246.               % 500 ms before start, 900 ms after start
  247.               % gets 500 ms before tone, tone, and 400 ms after tone, but no puff
  248.  
  249.               preEvntTimeLenInMs = 500; %ms
  250.               postEvntTimeLenInMs = 900; %ms
  251.  
  252.               trialEvntsSec = sort([condToneTimesSec(:); pureToneTimeSec(:)]);
  253.  
  254.               spkDataCombined{iFile} = makeTrialData(preEvntTimeLenInMs, postEvntTimeLenInMs, trialEvntsSec);
  255.               metadata.trials_Start_Evnt_End_sec = getTrialsStart_Evnt_End(preEvntTimeLenInMs, postEvntTimeLenInMs, trialEvntsSec);
  256.  
  257.               metadata.pureTrials_Start_Evnt_End_sec = getTrialsStart_Evnt_End(preEvntTimeLenInMs, postEvntTimeLenInMs, pureToneTimeSec);
  258.               metadata.condTrials_Start_Evnt_End_sec = getTrialsStart_Evnt_End(preEvntTimeLenInMs, postEvntTimeLenInMs, condToneTimesSec);
  259.             case 'puff'
  260.               % 500 ms before start, 1100 ms after start
  261.               % gets 500 ms before puff, puff and ~1000 ms puff tone, but no tones
  262.  
  263.               preEvntTimeLenInMs = 500; %ms
  264.               postEvntTimeLenInMs = 1100; %ms
  265.  
  266.               trialEvntsSec = puffTimesSec;
  267.  
  268.               spkDataCombined{iFile} = makeTrialData(preEvntTimeLenInMs, postEvntTimeLenInMs, trialEvntsSec);
  269.               metadata.trials_Start_Evnt_End_sec = getTrialsStart_Evnt_End(preEvntTimeLenInMs, postEvntTimeLenInMs, trialEvntsSec);
  270.           end % 2nd switch alignment
  271.         case {'DBSonset', 'DBSoffset'}
  272.           unitDim = 3;
  273.          
  274.           % FIXME
  275.   %         nDBS = length(sessionInfo.DBS);
  276.   %         nBins = (secsBeforeDataStart+secsPostDataStart)*1000;
  277.   %         spkData = zeros(nBins,totalUnits,nDBS);
  278.   %        
  279.   %         % make spkdata equivalent size with interneuron/unit quality/ unsorted
  280.   %         tempTrialSpks = []; %binSpikeCountsTrial = zeros(nBins,1);
  281.   %         unitNumCrossRef = [];
  282.   %         chNameUnitCrossRef = {};
  283.   %         unitWaveforms = {};
  284.   %        
  285.   %         % MAYBE USE HIST INSTEAD???
  286.   %         for d = 1:nDBS
  287.   %           if contains(alignment,'DBSonset','IgnoreCase',true)
  288.   %             trialZeroMsec = round(sessionInfo.DBS(d).onsetOffsetTimePts(1,1)/30);
  289.   %             %     %PuffsAdjustedTimes = [LOCtimePts - dataZeroPt + secsBeforeDataStart*fs];  % time of LOC (in drugStart dataMatrix) from the onset of the data clip
  290.   %             % put in cell array
  291.   %           elseif contains(alignment,'DBSoffset','IgnoreCase',true)
  292.   %             trialZeroMsec = round(sessionInfo.DBS(d).onsetOffsetTimePts(1,2)/30);
  293.   %           end
  294.   %           %Trial Start in Msec Pts
  295.   %           dataStartPts = trialZeroMsec - secsBeforeDataStart*fs; % points (msec  for NS2) before (drug) start to take data
  296.   %           dataEndPts = trialZeroMsec + secsPostDataStart*fs;
  297.   %           unitCount = 0;
  298.   %           for ch = 1:size(allts,2)-1 % %subtract the empty extra channel erroneously added by readall plx
  299.   %             for u=1:maxUnitsPerCh(ch)
  300.   %               unitCount = unitCount+1;
  301.   %               unitNumCrossRef(unitCount,:) = [ch u];
  302.   %               chNameUnitCrossRef{unitCount} = channel_names{ch};
  303.   %               binSpikeCountsTrial = zeros(nBins,1);
  304.   %               tempTrialSpks = allts{u,ch}(allts{u,ch}> (dataStartPts/fs) & allts{u,ch}< (dataEndPts/fs));
  305.   %               if isempty(tempTrialSpks)
  306.   %               else
  307.   %                 tempAdjSpkTimes = round(tempTrialSpks*fs)-dataStartPts;
  308.   %                 if tempAdjSpkTimes(1) == 0 % if first spike happens at time 0 of trial (toss it)
  309.   %                   tempAdjSpkTimes = tempAdjSpkTimes(2:end); %toss first spike, cant index @ 0
  310.   %                 end
  311.   %                 unitWaveforms{unitCount} = allwf{u,ch};
  312.   %                 binSpikeCountsTrial([tempAdjSpkTimes])=1; %spikes adjusted to bins
  313.   %                 spkData(:,unitCount,d) = binSpikeCountsTrial;
  314.   %                 % see if short ISIs, warn how many
  315.   %                 shortISIind = find(diff(tempTrialSpks)<.001);
  316.   %                 if any(shortISIind)
  317.   %                   warning('DBS run %d: %d short ISI spikes for unit %d ',d,length(shortISIind),unitCount)
  318.   %                   % for total n spikes do nnShortISIS =1 for each count
  319.   %                 end
  320.   %               end
  321.   %             end
  322.   %           end
  323.   %         end
  324.   %       end % case {'DBSonset', 'DBSoffset'}
  325.       end % switch alignment
  326.  
  327.       %% FIXME
  328.  
  329.   %     %% indexing into the unit data matrix
  330.   %     chNamesSTR = string(channel_names);
  331.   %     elec1ChInd = contains(chNamesSTR,'elec1');
  332.   %     elec2ChInd = contains(chNamesSTR,'elec2');
  333.   %
  334.   %     if strcmpi(arrayLocation,'pfc')%elec 1- :FEF, 2- vlPFC
  335.   %        sprintf('making spikeMat for pfc: %s',monkeyname)
  336.   %        FEFchInd = elec1ChInd;
  337.   %        vlPFCchInd = elec2ChInd;
  338.   %         FEFchIndNum = find(FEFchInd ==1);
  339.   %         FEFUnits = ismember(unitNumCrossRef(:,1),FEFchIndNum);
  340.   %         vlPFCchIndNum = find(vlPFCchInd ==1);
  341.   %         vlPFCUnits = ismember(unitNumCrossRef(:,1),vlPFCchIndNum);
  342.   %     elseif strcmpi(arrayLocation,'ppcstg')
  343.   %           sprintf('making spikeMat for ppcstg: %s',monkeyname)
  344.   %           %mr. jones: 1- stg; 2-ppc; mary 2- stg, 1- ppc
  345.   %           STGchInd = elec1ChInd;
  346.   %           PPCchInd = elec2ChInd;
  347.   %           if contains(monkeyname,'mary','IgnoreCase',true) %flip the elec assignments
  348.   %                STGchInd = elec2ChInd;
  349.   %                PPCchInd = elec1ChInd;
  350.   %           end
  351.   %         PPCchIndNum = find(PPCchInd ==1);
  352.   %         PPCUnits = ismember(unitNumCrossRef(:,1),PPCchIndNum);
  353.   %         STGchIndNum = find(STGchInd ==1);
  354.   %         STGUnits = ismember(unitNumCrossRef(:,1),STGchIndNum);    
  355.   %     end
  356.   %
  357.   %     %% Make unitInfoMat (each entry is unit in this spike matrix)
  358.   %     % populates: Loc, ElecName,Ch,UnitNum (in its ns6/.dat file),... TimeRangeSecs (0 = unstable/in and out sort), Waveforms
  359.   %     unitInfoMat(1:totalUnits) = struct('Location',[],'ElectrodeName',[],'Channel',[],'UnitNum',[],'Quality',[],'Interneuron',[],'Isolated',[],'TimeRangeSecs',[],'Waveforms',[]);
  360.   %
  361.   %     if contains(arrayLocation,'pfc','IgnoreCase',true)
  362.   %         [L1{1:length(FEFUnits)}] = deal('FEF');
  363.   %         [unitInfoMat(FEFUnits).Location] = L1{:};
  364.   %         [L2{1:length(vlPFCUnits)}] = deal('vlPFC');
  365.   %         [unitInfoMat(vlPFCUnits).Location] = L2{:};
  366.   %     else
  367.   %         [L1{1:length(PPCUnits)}] = deal('PPC');
  368.   %         [unitInfoMat(PPCUnits).Location] = L1{:};
  369.   %         [L2{1:length(STGUnits)}] = deal('STG');
  370.   %         [unitInfoMat(STGUnits).Location] = L2{:};
  371.   %     end
  372.   %     [unitInfoMat(:).ElectrodeName] = chNameUnitCrossRef{:}; %true for both array sets
  373.   %     unitNumXrefCell = num2cell(unitNumCrossRef);
  374.   %         [unitInfoMat(:).Channel] = unitNumXrefCell{:,1};% clarify unit num 1 = unsorted
  375.   %         [unitInfoMat(:).UnitNum] = unitNumXrefCell{:,2};
  376.   %     [unitInfoMat(:).Waveforms] = unitWaveforms{:};
  377.  
  378.     end % files
  379.  
  380.     % concat units from both files into numeric array from cell array
  381.     fileDataLengths = cellfun(@(x) size(x,1), spkDataCombined);
  382.    
  383.     % trim data to min length if not equal lengths
  384.     if ~all(~diff(fileDataLengths))
  385.       minLen = min(fileDataLengths);
  386.       spkDataCombined = cellfun(@(x) x(1:minLen, :, :), spkDataCombined, 'Uni', false);
  387.     end
  388.    
  389.     % combine files
  390.     spkDataCombined = cat(unitDim, spkDataCombined{:}); %#ok<NASGU>
  391.  
  392.     % Save Spike Data (not binned, well only 1msec bin)
  393. %     save(saveFilepath, 'spkDataCombined','metadata','-v7.3');
  394.     fprintf('      Saved: %s \n', saveFilepath);
  395.  
  396.     clear spkDataCombined metadata
  397.   end % allAlignments
  398. end % dirs
  399.  
  400. fprintf('\nDone! \n\n')
  401.  
  402.   %% Nested fn
  403.   function spkDataCombined = makeTrialData(preEvntTimeLenInMs, postEvntTimeLenInMs, trialEvntsSec)
  404.    
  405.     % parse inputs
  406.     preEvntTimeIndLen = round(preEvntTimeLenInMs * fs/1000);
  407.     postEvntTimeIndLen = round(postEvntTimeLenInMs * fs/1000);
  408.     trialEvntsInd = round(trialEvntsSec * fs);
  409.     nTrials = length(trialEvntsInd);
  410.    
  411.     % preallocate
  412.     nTimeInd = preEvntTimeIndLen + postEvntTimeIndLen;
  413.     spkDataCombined = zeros(nTimeInd, nTrials, nTotalQualityUnits, 'single'); % time by trials by units
  414.    
  415.     for iUnit = 1:nTotalQualityUnits
  416.       thisUnitSpikeTimesSec = thisFileSpikeTimesSec{iUnit};
  417.      
  418.       % convert times to indicies
  419.       thisUnitSpikeInds = round(thisUnitSpikeTimesSec * fs);
  420.      
  421.       for iTrial = 1:nTrials
  422.         thisTrialEvntInd = trialEvntsInd(iTrial);
  423.         thisTrialStartInd = (thisTrialEvntInd-preEvntTimeIndLen);
  424.         thisTrialEndInd = (thisTrialEvntInd + postEvntTimeIndLen);
  425.  
  426.         thisTrialSpikeInds = thisUnitSpikeInds( thisUnitSpikeInds >= thisTrialStartInd & thisUnitSpikeInds <= thisTrialEndInd ) - thisTrialStartInd + 1; % +1 so doesn't start at 0
  427.        
  428.         spkDataCombined(thisTrialSpikeInds, iTrial, iUnit) = 1;
  429.       end
  430.     end
  431.     clear iUnit
  432.    
  433.   end
  434.  
  435. end % main
  436.  
  437.  
  438. %% Local fn
  439. function trials_Start_Evnt_End_sec = getTrialsStart_Evnt_End(preEvntTimeLenInMs, postEvntTimeLenInMs, trialEvntsSec)
  440.   trialEvntsSec = trialEvntsSec(:); % make col vec
  441.  
  442.   % make matrix of [Start Evnt End] cols and rows of trials
  443.   trials_Start_Evnt_End_sec = [trialEvntsSec - preEvntTimeLenInMs/1000, trialEvntsSec, trialEvntsSec + postEvntTimeLenInMs/1000];
  444. end
  445.  
  446.  
  447. %Finish Manual Entries
  448.     % Quality: 0-1; Interneuron (by eye): 0/1; Isolated: 0/1;
  449.     % TimeRangeSecs:[# #;# #]; 0 = unstable; consider? 1 = present throughout ;
  450.     %quality of non-isolated indicates quality
  451.     % of multiunit remaining in unsorted
  452. %Reorder and save spikeDataMat
  453.  
  454.  
  455. % next analyses will require:
  456. % c = extractfield(UnitInfoMat,'Location')
  457. % concatenate structs (PFC and PPCSTG) via catStruct = [unitQuality, unitQuality2];
  458. %find best rated neuron on single channel; must MUST take neurons with
  459. %time-range that ~= 0; time range of 0 means unstable
  460.  
  461.  
  462. %function to guassian kernel smooth spike train (; make kermel w/ normpdf( LOOK @ p320 in ch20 in M4Nv2
  463.        
  464.  
  465. % LATER FIGURE OUT: deal with short ISI spikes on same unit (< 1ms apart)
  466.                 %right now can incorrectly add extra spikes, need to adjust stamps before putting in binSpikeCounts
  467. %                     shortISIind = find(diff(tempTrialSpks)<.001);
  468. %                   floorTS = floor(tempTrialSpks(shortISIind)*fs)/fs;
  469. %                     ceilTS = ceil(tempTrialSpks(shortISIind+1)*fs)/fs;
  470. %                 if any(shortISIind)
  471. %                 warning('added short ISI spike to next bin for unit %d',unitCount)
  472. %                     % for total n spikes do nnShortISIS =1 for each count
  473. %                 end
  474. %                     nlostspikes = total - nnz        
  475. %                   % If want actual counts per bin)  
  476. %                   for b = 1:nBins
  477. %                 window = 1+(b-1): 1+b;
  478. %                 spkData(b,unitCount,n) = any(tempTrialSpks>= + binsize(;
  479. %                 spkDataMulti % dataMat w/ multiple spiikes per msec counted          
  480. %             end
  481. %         end
  482. %     end
  483. %    
  484. % end
  485. %
  486. % binSpikeCounts = zeros(nBins,nCh,nTrials);
  487. % binSpikeCountsTrial = zeros(nBins,1);
  488. % window = [];
  489. % for k = 1:nTrials
  490. %     for j = 1:nCh
  491. %         for b = 1:nBins        
  492. %             window = 1+(b-1): 1+b;
  493. %             window = window(window <= size(spikeMatrix,1));
  494. %             winStarts(i) = window(1);
  495. %             binSpikeCounts(i,j,k) = sum(spikeMatrix(window,j,k));
  496. %         end
  497. %     end
  498. % end
  499. % for n = 1:nDBS
  500. %     for ch = 1:size(allts,2)-1 % %subtract the empty extra channel erroneously added by readall plx
  501. %         for u=1:maxUnits(ch)
  502. %             unitCount = unitCount+1;
  503. %             spkData(:,unitCount,n) = allts(ch,u);
  504. %         end
  505. %     end
  506. % end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement