Browse Source

gin commit from med068pc183

Deleted files: 26
Andrey Vinogradov 3 years ago
parent
commit
7c6a545bfb
26 changed files with 0 additions and 3242 deletions
  1. BIN
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/AxionBioSystems_Matlab_guide.pdf
  2. 0 341
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/AxisFile.m
  3. 0 287
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/BlockVectorData.m
  4. 0 32
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/BlockVectorDataType.m
  5. 0 98
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/BlockVectorHeader.m
  6. 0 53
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/BlockVectorHeaderExtension.m
  7. 0 256
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/BlockVectorLegacyLoader.m
  8. 0 452
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/BlockVectorSet.m
  9. 0 90
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/CRC32.m
  10. 0 181
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/ChannelArray.m
  11. 0 115
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/ChannelMapping.m
  12. 0 44
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/DateTime.m
  13. 0 64
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/Entry.m
  14. 0 92
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/EntryRecord.m
  15. 0 49
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/EntryRecordID.m
  16. 0 106
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/LegacySupport.m
  17. 0 270
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/LoadArgs.m
  18. 0 82
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/Note.m
  19. 0 52
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/Spike_v1.m
  20. 0 85
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/Waveform.m
  21. 0 156
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/calc_spike_rate.m
  22. 0 42
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/load_AxIS_file.m
  23. BIN
      Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/ooo.mat
  24. 0 58
      Codes/MATLAB spike detection/ReadAxionChannelnew.m
  25. 0 188
      Codes/MATLAB spike detection/detect_spikes.m
  26. 0 49
      Codes/MATLAB spike detection/newreadspikes.m

BIN
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/AxionBioSystems_Matlab_guide.pdf


+ 0 - 341
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/AxisFile.m

@@ -1,341 +0,0 @@
-classdef AxisFile < handle
-    %AXISFILE: Class that holds all Data for a loaded Axion 1.X File
-    %
-    % Calling A = AxisFile('filename.raw') or AxisFile('filename.spk') will
-    % create an AxisFile object which contains the data set corresponding 
-    % to file 'y', as well as the notes and file name.
-    %
-    %   A = AxisFile('filename.raw') - loads file header information
-    %
-    % From here, the command 'z = A.DataSets(1)' stores a copy of the handle 
-    % to the first "BlockVectorSet" object in the file, which acts as a data
-    % map for the user.
-    %
-    % y = z.LoadData() of z, loads specific data regions of the dataset
-    % to y without reloading the entire file each time. For example: 
-    % 
-    %   a1data = z.LoadData('A1', 11) 
-    %
-    % will load all A1_11 information in the file and store it in a1Data.
-    %
-    %   y = x.DataSets.LoadData(well, electrode, timespan, dimensions) - loads 
-    %      channel data into array
-    %
-    %      dimension 1 ->   by plate, vector with 1 waveform per signal in 
-    %                       the plate
-    %      dimension 3 ->   by well, cell array of vectors 1 waveform per 
-    %                       signal with size (well rows, well columns)
-    %      dimension 5 ->   by electrode, reference electrodes by y{well row,
-    %                       well column, electrode column, electrode row}
-    %
-    % The LoadData() function loads data into instances of the class 
-    % 'Waveform', where the voltage and time vector data can be accessed via  
-    % the methods GetTimeVector() and GetVoltageVector(). See Also: Waveform.m
-    %
-    %   y{wr, wc, ec, er}.GetTimeVector - returns time vector based on start 
-    %                       time, length of data, and Sampling Frequency 
-    %                       in units of Seconds
-    %   y{wr, wc, ec, er}.GetVoltageVector - returns the voltage vector 
-    %                       with units of Volts
-    %
-    % Properties of AxisFile include:
-    %
-    %   FileName:           Path to file that this instance points to
-    %
-    %   PrimaryDataType:    The type of the Original / most relevant data 
-    %                       in this file. See Also: BlockVectorDataType.m
-    %
-    %   HeaderVersionMajor: Major version number of the loaded file. 
-    %                       (modern files should be 1)
-    %
-    %   HeaderVersionMinor: Minor version number of the loaded file.
-    %
-    %   Notes:              User Notes on this file See Also: Note.m
-    %
-    %   DataSets            Objects with access to the data and meta-data 
-    %                       contained by this file See Also: BlockVectorSet.m
-    %
-    % See Also: BlockVectorSet, Waveform, BlockVectorSet,
-    % BlockVectorDataType, Note
-    
-    
-    
-    properties (Constant = true, GetAccess = private)
-        %The following are contants used in the opening of Axis Files
-        MAGIC_WORD      = 'AxionBio';           % Preface to all modern Axis files
-        MAGIC_BETA_FILE = 64;                   % Preface to Some legacy Axis files
-        EXPECTED_NOTES_LENGTH_FIELD = 600;      % Number used as a validity check in Axis 1.0 file headers
-        
-        %Header CRC32 calculation constants
-        CRC_POLYNOMIAL = hex2dec('edb88320');   
-        CRC_SEED = hex2dec('ffffffff');
-        
-        %Header Size Constants, see documentation for details
-        PRIMARY_HEADER_CRCSIZE = 1018;
-        SUBHEADER_CRCSIZE = 1016;
-        PRIMARY_HEADER_MAXENTRIES = 123;
-        SUBHEADER_MAXENTRIES = 126;
-    end
-    
-    properties (SetAccess = private, GetAccess = private)
-        FileID;                % File Handle for file Access (fread, ftell, etc...)
-        NotesStart;            % Location in file (in Number of bytes from the beginning) of the primary notes field
-        EntriesStart;          % Staring byte of file entries
-    end
-    
-    properties (SetAccess = private, GetAccess = public)
-        %Basic File Data
-        FileName;             
-        PrimaryDataType;       
-        
-        %Version Number: Current version is (1.0)
-        HeaderVersionMajor;  
-        HeaderVersionMinor; 
-        
-        %Contained File Data
-        Notes;                 
-        DataSets;             
-    end
-    
-    methods
-
-        function this = AxisFile(varargin)
-            %AxisFile Opens a new handle to an Axis File
-            %  Required arguments:
-            %    filename    Pathname of the file to load
-            %                Note: Calling with mulitple file names results
-            %                in vector of AxisFile objects corresponding to
-            %                the input argument file names
-           
-         
-            if(nargin == 0)
-                this.FileID = [];
-                return;
-            end
-            if(nargin > 1)
-                this(nargin) = AxisFile;
-                for i = 1: nargin
-                    this(i) = AxisFile(varargin{i});
-                end
-                return;
-            end
-            fFilename = varargin{1};
-            this.FileName = fFilename;
-            this.FileID = fopen(fFilename,'r');
-            
-            fSetMap = containers.Map('KeyType', 'int64', 'ValueType', 'any');
-            this.Notes = Note.empty(0,0);
-            
-            if (this.FileID <= 0)
-                error(['AxisFile: ' this.FileName ' not found.']);
-            end
-            % Make sure that this is a format that we understand
-            versionOk = false;
-            versionWarn = false;
-            
-            % Check for the "magic word" sequence
-            fMagicRead = fread(this.FileID, length(AxisFile.MAGIC_WORD), '*char').';
-            if ~strcmp(AxisFile.MAGIC_WORD, fMagicRead)
-                
-                % Magic phrase not found -- check to see if this is an old-style file
-                if ~isempty(fMagicRead) && uint8(fMagicRead(1)) == AxisFile.MAGIC_BETA_FILE
-                    % This looks like a deprecated beta file
-                    warning('AxisFile:versionCheck', ['File ' fFilename ' looks like a deprecated AxIS v0.0 file format, Please Re-record it in Axis to update the header data']);
-                    
-                    [fType, fData, fChannelMapping, fHeader] = LegacySupport.GenerateRolstonEntries(this.FileID, fFilename((end-3):end));
-                    
-                    this.HeaderVersionMajor = 0;
-                    this.HeaderVersionMinor = 0;
-                    this.PrimaryDataType = fType;
-                    this.DataSets = BlockVectorSet(this, fData, fChannelMapping, fHeader);
-                    
-                    return;
-                else
-                    fclose(this.FileID);
-                    error('File format not recognized: %s', fFilename);
-                end
-                
-            else
-                
-                this.PrimaryDataType         = fread(this.FileID, 1, 'uint16=>uint16');
-                this.HeaderVersionMajor      = fread(this.FileID, 1, 'uint16=>uint16');
-                this.HeaderVersionMinor      = fread(this.FileID, 1, 'uint16=>uint16');
-                this.NotesStart              = fread(this.FileID, 1, 'uint64=>uint64');
-                fNotesLength                 = fread(this.FileID, 1, 'uint32=>uint32');
-                
-                if(fNotesLength ~= AxisFile.EXPECTED_NOTES_LENGTH_FIELD)
-                    error('Incorrect legacy notes length field');
-                end
-                
-                if this.HeaderVersionMajor == 0
-                    if this.HeaderVersionMinor == 1
-                        versionOk = true;
-                    elseif this.HeaderVersionMinor == 2
-                        versionOk = true;
-                    end
-                    
-                    this.EntriesStart = int64(this.NotesStart);
-                    fEntryRecords = LegacySupport.GenerateEntries(this.FileID, this.EntriesStart);
-                    
-                elseif this.HeaderVersionMajor == 1
-                    versionOk = true;
-                    
-                    this.EntriesStart        = fread(this.FileID, 1, 'int64=>int64');
-                    fEntrySlots = fread(this.FileID, AxisFile.PRIMARY_HEADER_MAXENTRIES, 'uint64=>uint64');
-                    fEntryRecords = EntryRecord.FromUint64(fEntrySlots);
-                    
-                    % Check CRC
-                    fseek(this.FileID, 0, 'bof');
-                    fCRCBytes = fread(this.FileID, AxisFile.PRIMARY_HEADER_CRCSIZE, 'uint8');
-                    fReadCRC = fread(this.FileID, 1, 'uint32');
-                    fCalcCRC = CRC32(AxisFile.CRC_POLYNOMIAL, AxisFile.CRC_SEED).Compute(fCRCBytes);
-                    
-                    if(fReadCRC ~= fCalcCRC)
-                        error('File header checksum was incorrect: %s', fFilename);
-                    end
-                    
-                    if this.HeaderVersionMinor > 0
-                        versionWarn = true;
-                    end
-                end
-                
-            end
-           
-            if ~versionOk
-                error('Unsupported file version %u.%u', ...
-                    this.HeaderVersionMajor, ...
-                    this.HeaderVersionMinor);
-            end
-            
-            % Version > 1.0 triggers a warning.
-            if versionWarn
-                warning(...
-                    'AxisFile:versionCheck',  ...
-                    'Unsupported file version %u.%u , Not all data for this may be shown, Please contact support@axion-biosystems.com for more information', ...
-                    this.HeaderVersionMajor, ...
-                    this.HeaderVersionMinor);
-            end
-
-            % Start Reading Entries
-            fseek(this.FileID, this.EntriesStart, 'bof');
-            
-            fTerminated = false;
-            
-            % Load file entries from the header
-            while(~fTerminated)
-                
-                for entryRecord = fEntryRecords
-                    switch(entryRecord.Type)
-                        
-                        case EntryRecordID.Terminate
-                            fTerminated = true;
-                            break
-                            
-                        case EntryRecordID.ChannelArray
-                            fChannelArray = ChannelArray(entryRecord, this.FileID);
-                            if(~isa(fCurrentBlockVectorSet.ChannelArray , 'ChannelArray'))
-                                fCurrentBlockVectorSet = fCurrentBlockVectorSet.Clone(fChannelArray);
-                                fSetMap(int64(fCurrentHeader.FirstBlock)) = fCurrentBlockVectorSet;
-                            else
-                                error('AxisFile: Only one ChannelArray per BlockVectorSet');
-                            end
-                            
-                        case EntryRecordID.BlockVectorHeader
-                            fCurrentHeader = BlockVectorHeader(entryRecord, this.FileID);
-                            
-                            fCurrentBlockVectorSet = BlockVectorSet(this, fCurrentHeader);
-                            
-                            fKey = int64(fCurrentHeader.FirstBlock);
-                            fSetMap(fKey) = fCurrentBlockVectorSet;
-                            
-                        case EntryRecordID.BlockVectorHeaderExtension
-                            if(~isempty(fCurrentBlockVectorSet.HeaderExtension) || ...
-                                isa(fCurrentBlockVectorSet.HeaderExtension, 'BlockVectorHeaderExtension'))
-                                error('AxisFile: Only one BlockVectorHeaderExtension per BlockVectorSet');
-                            end
-                            fCurrentBlockVectorSet = fCurrentBlockVectorSet.Clone(BlockVectorHeaderExtension(entryRecord, this.FileID));
-                            fSetMap(fCurrentBlockVectorSet.Header.FirstBlock) = fCurrentBlockVectorSet;
-                            
-                        case EntryRecordID.BlockVectorData
-                            fData = BlockVectorData(entryRecord, this.FileID);
-                            if(~isempty(fCurrentBlockVectorSet.Data) || ...
-                                isa(fCurrentBlockVectorSet.Data, 'BlockVectorData'))
-                                error('AxisFile: Only one BlockVectorData per BlockVectorSet');
-                            end
-                            fTargetSet = fSetMap(int64(fData.Start));
-                            if (~isa(fTargetSet, 'BlockVectorSet'))
-                                error('AxisFile: No header to match to data');
-                            end
-                            fTargetSet = fTargetSet.Clone(fData);
-                            fSetMap(fData.Start) = fTargetSet;
-                            
-                        case EntryRecordID.NotesArray
-                            this.Notes = [this.Notes ; Note.ParseArray(entryRecord, this.FileID)];
-                            
-                        otherwise
-                            fSkipSpace = double(entryRecord.Length);
-                            if(0 ~= fseek(this.FileID, fSkipSpace, 'cof'))
-                                error(ferror(this.FileID));
-                            end
-                            
-                    end
-                end
-                
-                if(~fTerminated)
-                    
-                    %Check Magic Bytes
-                    fMagicRead = fread(this.FileID, length(AxisFile.MAGIC_WORD), '*char').';
-                    if ~strcmp(AxisFile.MAGIC_WORD, fMagicRead)
-                        error('Bad sub header magic numbers: %s', fFilename);
-                    end
-                    
-                    %Read Entry Records
-                    fEntrySlots = fread(this.FileID, AxisFile.SUBHEADER_MAXENTRIES, 'uint64=>uint64');
-                    fEntryRecords = EntryRecord.FromUint64(fEntrySlots);
-                    
-                    %Check CRC of subheader
-                    fseek(this.FileID,( -1 * length(AxisFile.MAGIC_WORD)) - (8 * AxisFile.SUBHEADER_MAXENTRIES),'cof');
-                    fCRCBytes = fread(this.FileID, AxisFile.SUBHEADER_CRCSIZE, 'uint8');
-                    fReadCRC = fread(this.FileID, 1, 'uint32');
-                    fCalcCRC = CRC32(AxisFile.CRC_POLYNOMIAL, AxisFile.CRC_SEED).Compute(fCRCBytes);
-                    if(fReadCRC ~= fCalcCRC)
-                        error('Bad sub header checksum : %s', fFilename);
-                    end
-                    
-                    %skip 4 reserved bytes
-                    fseek(this.FileID, 4,'cof');
-                end
-                
-            end
-            
-            fValueSet = fSetMap.values;
-            
-            %Record Final Data Sets
-            this.DataSets = BlockVectorSet.empty(0,length(fSetMap));
-            for i = 1 : length(fValueSet)
-                this.DataSets(i) = fValueSet{i};
-            end
-            
-            %Sort Notes
-            [~,idx]=sort([this.Notes.Revision]);
-            this.Notes = this.Notes(idx);
-            
-        end
-        
-        
-        function delete(this)
-            %DELETE is the destructor for the class, ensures that the file
-            %stream is closed as the file reference is cleared from the
-            %workspace
-            
-            if ~isempty(this.FileID)
-                fclose(this.FileID);
-            end
-        end
-        
-    end
-    
-end
-
-
-

+ 0 - 287
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/BlockVectorData.m

@@ -1,287 +0,0 @@
-classdef BlockVectorData < Entry
-    %BlockVectorData contains instructions for loading the Data types 
-    %   (See BlockVectorDataType.m) from the data portions of the file
-    %   listed in the header.
-    
-    properties(GetAccess = protected, SetAccess = private)
-        FileID % File Handle to be used for file reading operations.
-    end
-    
-    methods
-        function this = BlockVectorData(aEntryRecord, aFileID)
-            %BlockVectorData: Constructs a new BlockVectorData corresponding  
-            % to an Entry Record and the file handle it came from
-            this = this@Entry(aEntryRecord, int64(ftell(aFileID)));
-            
-            this.FileID = aFileID;
-            fseek(this.FileID, double(this.EntryRecord.Length), 'cof');
-            
-            if ~(ftell(this.FileID) == (this.Start + this.EntryRecord.Length) || isinf(this.EntryRecord.Length))
-                error('Unexpected BlockVectorHeader length')
-            end
-            
-        end
-        
-        function Waveforms = GetRawV1ContinuousWaveforms(...
-                this, ...
-                aSourceSet, ...
-                aChannelsToLoad, ...
-                aTimeRange, ...
-                aDimensions)
-            
-            if aSourceSet.Header.NumSamplesPerBlock ~= 1
-                error('load_AxIS_raw:argNumSamplesPerBlock', ...
-                    'Invalid header for RAW file: incorrect samples per block');
-            end
-            
-            if aSourceSet.Header.BlockHeaderSize ~= 0
-                error('load_AxIS_raw:argBlockHeaderSize', ...
-                    'Invalid header for RAW file: incorrect block header size');
-            end
-            fseek(this.FileID, int64(this.Start), 'bof');
-            fStart = 0;
-            
-            % Read data
-            fSampleFreq =  int64(aSourceSet.Header.SamplingFrequency);
-            fChannelCount = int64(aSourceSet.Header.NumChannelsPerBlock);
-            fBytesPerSecond = fSampleFreq * fChannelCount * int64(2);
-            fMaxTime = int64(this.EntryRecord.Length / fBytesPerSecond);
-            if ~strcmp(aTimeRange, 'all')
-                fStart = aTimeRange(1);
-                fEnd =aTimeRange(2);
-                
-                if(fStart >= fEnd)
-                    warning('Invalid timespan argument: end time < start time. No valid waveform can be returned.');
-                    Waveforms = Waveform.empty;
-                    return;
-                end      
-                
-                fSkipInitialSamples = fStart * fSampleFreq;                
-                fSkipInitialBytes = fSkipInitialSamples * fChannelCount * int64(2);
-          
-                if(fStart > fMaxTime)
-                    warning( 'DataSet only contains %d Seconds of data (%d Seconds was the requested start time). No waveform will be returned.', fMaxTime, fStart);
-                    Waveforms = Waveform.empty;
-                    return;
-                end
-                
-                if(fEnd > fMaxTime)
-                   fEnd = fMaxTime; 
-                   warning('DataSet only contains %d Seconds of data. Returned waveforms will be shorter than requested (%d Seconds).', fMaxTime, fEnd - fStart);
-                end
-                
-                fNumSamples  = int64((fEnd - fStart) * aSourceSet.Header.SamplingFrequency);
-                
-                % skip past samples that are before the current time range
-                fseek(this.FileID, fSkipInitialBytes, 'cof');
-            else
-                fNumSamples =  int64((fMaxTime) * aSourceSet.Header.SamplingFrequency);
-            end
-            
-            % Read the data for the given channel, skipping from one to the next
-            fNumChannels = length(aSourceSet.ChannelArray.Channels);
-            
-            fMaxExtents = [max([aSourceSet.ChannelArray.Channels(:).WellRow]), ...
-                    max([aSourceSet.ChannelArray.Channels(:).WellColumn]), ...
-                    max([aSourceSet.ChannelArray.Channels(:).ElectrodeColumn]), ...
-                    max([aSourceSet.ChannelArray.Channels(:).ElectrodeRow])];
-                
-            switch aDimensions
-                    case {LoadArgs.ByPlateDimensions}
-                        Waveforms = [];
-                    case {LoadArgs.ByWellDimensions}
-                        Waveforms = cell(double(fMaxExtents(1:2)));
-                    case {LoadArgs.ByElectrodeDimensions}
-                        Waveforms = cell(double(fMaxExtents));
-            end
-            
-            if length(aChannelsToLoad) == 1
-                % We're only reading one channel. For efficiency, take advantage of fread's
-                % 'skip' argument.
-                
-                fread(this.FileID, aChannelsToLoad - 1, 'int16=>int16');
-                fWaveform = fread(this.FileID, fNumSamples, 'int16=>int16', 2*(fNumChannels - 1));
-                fChannelMapping = aSourceSet.ChannelArray.Channels(aChannelsToLoad);
-                
-                fWaveform = Waveform(fChannelMapping, fStart, fWaveform, aSourceSet);
-               
-                fOuputIndex = double([...
-                        fChannelMapping.WellRow, ...
-                        fChannelMapping.WellColumn, ...
-                        fChannelMapping.ElectrodeColumn, ...
-                        fChannelMapping.ElectrodeRow]);
-                    
-                switch aDimensions
-                        
-                        case {LoadArgs.ByPlateDimensions}
-                            Waveforms = fWaveform;
-                                                       
-                        case {LoadArgs.ByWellDimensions}
-                            Waveforms{fOuputIndex(1),fOuputIndex(2)} = fWaveform;
-                            
-                        case {LoadArgs.ByElectrodeDimensions}
-                            Waveforms{fOuputIndex(1),fOuputIndex(2), fOuputIndex(3),fOuputIndex(4)} = fWaveform;
-                   
-                end
-            else
-                
-                fNumSamples      = fNumSamples * fNumChannels;
-                fTempChannelData = fread(this.FileID, fNumSamples, 'int16=>int16');
-                
-                % This test (which can fail only when we read the the end of the file)
-                % makes sure that we didn't get a number of samples that's not divisible
-                % by the number of channels.
-                fRemainderCount = mod(length(fTempChannelData), fNumChannels);
-                if fRemainderCount ~= 0
-                    warning('load_AXiS_raw:remainderCheck', ...
-                        'File %s has wrong number of samples for %u channels', ...
-                        this, fNumChannels);
-                end
-                
-                % Convert the 1D array to a 2D array, with channel as the second dimension
-                % (starts as first dimension and then is transposed)
-                fTempChannelData = reshape(fTempChannelData(:), fNumChannels, []);
-                
-                for fChannelIndex = aChannelsToLoad
-                    
-                    fChannelMapping = aSourceSet.ChannelArray.Channels(fChannelIndex);
-                    fWaveform = fTempChannelData(fChannelIndex,:)';
-                    fWaveform = Waveform(fChannelMapping, fStart, fWaveform, aSourceSet);
-                    
-                    fOuputIndex = double([...
-                        fChannelMapping.WellRow, ...
-                        fChannelMapping.WellColumn, ...
-                        fChannelMapping.ElectrodeColumn, ...
-                        fChannelMapping.ElectrodeRow]);
-                    
-                    switch aDimensions
-                        
-                        case {LoadArgs.ByPlateDimensions}
-                            if(isempty(Waveforms))
-                                Waveforms = fWaveform;
-                            else
-                                Waveforms(length(Waveforms) + 1) = fWaveform;
-                            end
-                            
-                        case {LoadArgs.ByWellDimensions}
-                            Waveforms{fOuputIndex(1),fOuputIndex(2)}(...
-                                length(Waveforms{fOuputIndex(1),fOuputIndex(2)}) + 1) = fWaveform;
-                            
-                        case {LoadArgs.ByElectrodeDimensions}
-                            Waveforms{fOuputIndex(1),fOuputIndex(2), fOuputIndex(3),fOuputIndex(4)} = fWaveform; %We only expect one Waveform per channel
-                   
-                    end
-                end
-            end
-        end
-        
-        function Waveforms = GetSpikeV1Waveforms(...
-                this, ...
-                aSourceSet, ...
-                aChannelsToLoad, ...
-                aTimeRange, ...
-                aDimensions)
-            
-            if aSourceSet.Header.NumChannelsPerBlock ~= 1
-                error('Load_spike_v1:argNumChannelsPerBlock', ...
-                    'Invalid header for SPIKE file: incorrect channels per block');
-            end
-            
-            if aSourceSet.Header.BlockHeaderSize < Spike_v1.LOADED_HEADER_SIZE
-                error('Load_spike_v1:argBlockHeaderSize', ...
-                    'Invalid header for SPIKE file: block header size too small');
-            end
-            
-            if aSourceSet.Header.NumSamplesPerBlock < 1
-                error('load_AxIS_spike:argNumSamplesPerBlock', ...
-                    'Invalid header for SPIKE file: number of samples per block < 1');
-            end
-            
-            fHeader = aSourceSet.Header;
-            
-            if ischar(aTimeRange) && strcmp(aTimeRange, 'all')
-                fFirstSample = 0;
-                fLastSample  = Inf;
-            else
-                fFirstSample = aTimeRange(1) * fHeader.SamplingFrequency;
-                fLastSample  = aTimeRange(2) * fHeader.SamplingFrequency;
-            end
-            
-            fMaxExtents = [max([aSourceSet.ChannelArray.Channels(:).WellRow]), ...
-                max([aSourceSet.ChannelArray.Channels(:).WellColumn]), ...
-                max([aSourceSet.ChannelArray.Channels(:).ElectrodeColumn]), ...
-                max([aSourceSet.ChannelArray.Channels(:).ElectrodeRow])];
-            
-            switch aDimensions
-                case {LoadArgs.ByPlateDimensions}
-                    Waveforms = [];
-                case {LoadArgs.ByWellDimensions}
-                    Waveforms = cell(double(fMaxExtents(1:2)));
-                case {LoadArgs.ByElectrodeDimensions}
-                    Waveforms = cell(double(fMaxExtents));
-            end
-            
-            
-            fWaveformBytesSize = (fHeader.NumChannelsPerBlock * fHeader.NumSamplesPerBlock * 2) + fHeader.BlockHeaderSize;
-            fseek(this.FileID, int64(this.Start), 'bof');
-            fData = fread(this.FileID, this.EntryRecord.Length, 'int8=>int8');
-            fData = reshape(fData, fWaveformBytesSize, []);
-            fNumWaves = size(fData,2);
-            fNumWaves = fNumWaves(1);
-            fChannelArray = aSourceSet.ChannelArray;
-            for iWave = 1 : fNumWaves
-                fStartingSample = typecast(fData(1:8,iWave), 'int64');
-                
-                if fStartingSample < fFirstSample
-                    % Too early
-                    continue;
-                elseif fStartingSample >= fLastSample
-                    % Too late.  Since spikes are in chronological order, we
-                    % can stop reading now.
-                    break;
-                end
-                
-                fHardwareChannelIndex = typecast(fData(9,iWave), 'uint8');
-                fHardwareChannelAchk = typecast(fData(10,iWave), 'uint8');
-                fChannelIndex = fChannelArray.LookupChannel(fHardwareChannelAchk, fHardwareChannelIndex);
-                fChannelMapping = fChannelArray.Channels(fChannelIndex);
-                
-                fOuputIndex = double([...
-                    fChannelMapping.WellRow, ...
-                    fChannelMapping.WellColumn, ...
-                    fChannelMapping.ElectrodeColumn, ...
-                    fChannelMapping.ElectrodeRow]);
-                
-                if sum(eq(aChannelsToLoad, fChannelIndex))
-                    
-                    fWaveform = Spike_v1( ...
-                        fChannelMapping, ...
-                        double(fStartingSample) / fHeader.SamplingFrequency, ...
-                        typecast(fData(fHeader.BlockHeaderSize+1:fWaveformBytesSize,iWave)','int16')', ...
-                        aSourceSet, ...
-                        typecast(fData(11:14,iWave), 'uint32'), ...
-                        typecast(fData(15:22,iWave), 'double'), ...
-                        typecast(fData(23:30,iWave), 'double'));
-                    
-                    switch aDimensions
-                        
-                        case {LoadArgs.ByPlateDimensions}
-                            if(isempty(Waveforms))
-                                Waveforms = fWaveform;
-                            else
-                                Waveforms(length(Waveforms) + 1) = fWaveform;
-                            end
-                            
-                        case {LoadArgs.ByWellDimensions}
-                            Waveforms{fOuputIndex(1),fOuputIndex(2)}(...
-                                length(Waveforms{fOuputIndex(1),fOuputIndex(2)}) + 1) = fWaveform;
-                            
-                        case {LoadArgs.ByElectrodeDimensions}
-                            Waveforms{fOuputIndex(1),fOuputIndex(2), fOuputIndex(3),fOuputIndex(4)}(...
-                                length(Waveforms{fOuputIndex(1),fOuputIndex(2), fOuputIndex(3),fOuputIndex(4)}) + 1) = fWaveform;
-                    end
-                end
-            end
-        end
-    end
-end

+ 0 - 32
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/BlockVectorDataType.m

@@ -1,32 +0,0 @@
-classdef BlockVectorDataType < uint16
-    %BLOCKVECTORDATATYPE Enumeration of known types of block vector data.
-    %
-    %   Raw_v1:     Continuous data from an Axion Muse or Maestro device.
-    %
-    %   Spike_v1:   Binary Spike Data recorded by a Spike detector in Axis.
-    
-    
-    enumeration
-        Raw_v1(0)
-        Spike_v1(1)
-    end
-    
-    methods(Static)
-        function [value , success] = TryParse(aInput)
-            try
-                value = BlockVectorDataType(aInput);
-                success = true;
-            catch e
-                
-                warning(...
-                    'BlockVectorDataType:TryParse',  ...
-                    ['Unsupported BlockVectorDataType', e]);
-                
-                value = aInput;
-                success = false;
-            end
-        end
-    end
-    
-end
-

+ 0 - 98
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/BlockVectorHeader.m

@@ -1,98 +0,0 @@
-classdef BlockVectorHeader < Entry
-    %BlockVectorHeader Primary data regarding a BlockVectorSet of Data
-    %   This class contains the basic information about an entry of 
-    %   Block Vector Data that is necessary to load it as a series of
-    %   vectors. 
-    %    
-    %    SamplingFrequency:     Recording sampling rate (in Hz) of the data
-    %
-    %    VoltageScale:          Voltage (in Volts) of the conversion factor
-    %                           from the stored int16's in the Data vectors
-    %                           to a real voltage value. i.e. Signal =
-    %                           double(VoltageScale) * Waveform.Data
-    %
-    %    FileStartTime:         DateTime (See DateTime.m) when this
-    %                           recording started
-    %
-    %    ExperimentStartTime:   DateTime (See DateTime.m) when the
-    %                           device that acquired this data started
-    %                           aquiring
-    %
-    %    FirstBlock:            Pointer (# of bytes frome the beginning of
-    %                           the file) to the start of the associated
-    %                           BlockVectorData entry
-    %
-    %    NumChannelsPerBlock:   Number of Channels of data stored in every
-    %                           block of the data.
-    %
-    %    NumSamplesPerBlock:    Number of samples in every channel-wise
-    %                           vector of the block.
-    %
-    %    BlockHeaderSize:       Number of bytes used for header of each
-    %                           block.
-    %
-    
-    
-    
-    properties (Constant = true, GetAccess = public)
-        SIZE = 64;
-    end
-    
-    properties(GetAccess = public, SetAccess = private)
-        SamplingFrequency
-        VoltageScale
-        FileStartTime
-        ExperimentStartTime
-        FirstBlock
-        NumChannelsPerBlock
-        NumSamplesPerBlock
-        BlockHeaderSize
-    end
-    
-    methods
-        function this = BlockVectorHeader(aEntryRecord, aFileID)
-            this = this@Entry(aEntryRecord, int64(ftell(aFileID)));
-            
-            this.SamplingFrequency   = fread(aFileID, 1, 'double=>double');
-            this.VoltageScale        = fread(aFileID, 1, 'double=>double');
-            this.FileStartTime       = DateTime(aFileID);
-            this.ExperimentStartTime = DateTime(aFileID);
-            this.FirstBlock          = fread(aFileID, 1, 'int64=>int64');
-            this.NumChannelsPerBlock = fread(aFileID, 1, 'uint32=>uint32');
-            this.NumSamplesPerBlock  = fread(aFileID, 1, 'uint32=>uint32');
-            this.BlockHeaderSize     = fread(aFileID, 1, 'uint32=>uint32');
-            
-            if(this.EntryRecord.Length ~= -1 && ...
-                ftell(aFileID) ~= (this.Start + this.EntryRecord.Length))
-                error('Unexpected BlockVectorHeader length')
-            end
-            
-        end
-    end
-    
-    methods (Static = true)
-        function this = Generate(...
-                aFileID, ...
-                aSamplingFrequency, ...
-                aVoltageScale, ...
-                aFileStartTime, ...
-                aExperimentStartTime, ...
-                aFirstBlock, ...
-                aNumChannelsPerBlock, ...
-                aNumSamplesPerBlock, ...
-                aBlockHeaderSize)
-            
-            this = BlockVectorHeader(EntryRecord(EntryRecordID.BlockVectorHeader, -1), aFileID);
-            this.SamplingFrequency   = aSamplingFrequency;
-            this.VoltageScale        = aVoltageScale;
-            this.FileStartTime       = aFileStartTime;
-            this.ExperimentStartTime = aExperimentStartTime;
-            this.FirstBlock          = aFirstBlock;
-            this.NumChannelsPerBlock = aNumChannelsPerBlock;
-            this.NumSamplesPerBlock  = aNumSamplesPerBlock;
-            this.BlockHeaderSize     = aBlockHeaderSize;
-            
-        end
-    end
-    
-end

+ 0 - 53
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/BlockVectorHeaderExtension.m

@@ -1,53 +0,0 @@
-classdef BlockVectorHeaderExtension < Entry
-    %BlockVectorHeaderExtension: Contains additional metadata about a loaded
-    %   Block vector set.
-    %
-    %   ExtensionVersionMajor:  Latest and greatest is currently 1
-    %   
-    %   ExtensionVersionMinor:  Latest and greatest is currently 0
-    %
-    %   DataType                Type of the data in this entry 
-    %                           (BlockVectorDataType.m)
-    %
-    %   Added:                  DateTime that this DataSet was last
-    %                           Added to the file (DateTime.m)
-    %
-    %   Modified:               DateTime that this DataSet was last
-    %                           modified (DateTime.m)
-    %
-    %   Name:   `               Name for this dataset (May be blank)
-    %
-    %   Description:            Textual metadata from axis with processing 
-    %                           metadata for this dataset 
-    
-    properties(Constant, GetAccess = private)
-       MaxNameChar = 50;
-    end
-    
-    properties(GetAccess = public, SetAccess = private)
-       ExtensionVersionMajor
-       ExtensionVersionMinor
-       DataType
-       Added
-       Modified
-       Name
-       Description
-    end
-    
-    methods(Access = public)
-        function this = BlockVectorHeaderExtension(aEntryRecord, aFileID)
-            this = this@Entry(aEntryRecord, int64(ftell(aFileID)));
-            
-            this.ExtensionVersionMajor   = fread(aFileID, 1, 'uint16=>uint16');
-            this.ExtensionVersionMinor   = fread(aFileID, 1, 'uint16=>uint16');
-            this.DataType                = BlockVectorDataType.TryParse(fread(aFileID, 1, 'uint16=>uint16'));
-            this.Added                   = DateTime(aFileID);
-            this.Modified                = DateTime(aFileID);
-            this.Name                    = deblank(fread(aFileID, ...
-                (BlockVectorHeaderExtension.MaxNameChar), '*char').');
-            this.Description             = deblank(fread(aFileID, ...
-                (this.Start + this.EntryRecord.Length) - ftell(aFileID) , '*char').');
-            
-        end
-    end
-end

+ 0 - 256
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/BlockVectorLegacyLoader.m

@@ -1,256 +0,0 @@
-classdef BlockVectorLegacyLoader < BlockVectorData
-    %BLOCKVECTORLEGACYLOADER Static class with resources to load file data
-    %   to legacy style structures.
-    
-    properties(GetAccess = private, Constant = true)
-        % Fixed by file format - there's only 1 byte for each
-        MAX_CHANNEL_ARTICHOKE = 256;
-        MAX_CHANNEL_INDEX     = 256;
-    end
-    
-    methods (Static = true)
-        function aData = Legacy_Load_Raw_v1(aSourceData, aHeader, aTimeRange)
-            
-            % Check to make sure the file format makes sense for a raw file
-            if aHeader.header.numSamplesPerBlock ~= 1
-                error('load_AxIS_raw:argNumSamplesPerBlock', ...
-                    'Invalid header for RAW file: incorrect samples per block');
-            end
-            
-            if aHeader.header.blockHeaderSize ~= 0
-                error('load_AxIS_raw:argBlockHeaderSize', ...
-                    'Invalid header for RAW file: incorrect block header size');
-            end
-            
-            fseek(aSourceData.FileID, int64(aSourceData.Start), 'bof');
-            
-            % Copy input structure to output; then add information to output
-            aData = aHeader;
-            aData.numChannels = aData.header.numChannelsPerBlock;
-            if aData.numChannels ~= aData.channelArray.numChannels
-                error('load_AxIS_raw:mismatchNumChannels', ...
-                    'Invalid RAW file: mismatched number of channels');
-            end
-            
-            if isempty(aHeader.loadedChannels)
-                % No channels requested - don't read any data
-                return;
-            end
-            
-            % Read data
-            fSampleFreq =  int64(aData.samplingFrequency);
-            fChannelCount = int64(aData.numChannels);
-            fBytesPerSecond = fSampleFreq * fChannelCount * int64(2);
-            fMaxTime = int64(aSourceData.EntryRecord.Length / fBytesPerSecond);
-            if ~strcmp(aTimeRange, 'all')
-                fStart = aTimeRange(1);
-				fEnd =aTimeRange(2);
-                
-                if(fStart >= fEnd)
-                    warning('Invalid timespan argument: end time < start time. No valid waveform can be returned.');
-                    return;
-                end
-                if(fStart > fMaxTime)
-                    warning( 'DataSet only contains %d Seconds of data (%d Seconds was the requested start time). No waveform will be returned.', fMaxTime, fStart);
-                    return;
-                end
-                if(fEnd > fMaxTime)
-                   fEnd = fMaxTime; 
-                   warning('DataSet only contains %d Seconds of data. Returned waveforms will be shorter than requested (%d Seconds).', fMaxTime, fEnd - fStart);
-                end
-                
-                fSkipInitialSamples = fStart * fSampleFreq; 
-                fSkipInitialBytes = fSkipInitialSamples * fChannelCount * int64(2);
-                
-                fNumSamples  = int64((fEnd - fStart) * fSampleFreq);
-                
-				fseek(aSourceData.FileID, fSkipInitialBytes, 'cof');				
-            else
-                fNumSamples = int64(fMaxTime * fSampleFreq);
-            end
-            
-            if length(aHeader.loadedChannels) == 1
-                % We're only reading one channel. For efficiency, take advantage of fread's
-                % 'skip' argument.
-                
-                % First, read and throw away other channels at the beginning of the data
-                fread(aSourceData.FileID, aHeader.loadedChannels - 1, 'int16=>int16');
-                
-                % Read the data for the given channel, skipping from one to the next
-                aData.channelData = fread(aSourceData.FileID, fNumSamples, 'int16=>int16', 2*(aData.numChannels - 1));
-            else
-                % We're reading multiple channels.  There's no easy way to translate this into a
-                % single fread, so we read all of the channels in the sample range in question,
-                % then remap, throwing away what we didn't want.
-                
-                % First, read everything within the time range
-                fNumSamples      = fNumSamples * int64(aData.numChannels);
-                fTempChannelData = fread(aSourceData.FileID, fNumSamples, 'int16=>int16');
-                
-                % This test (which can fail only when we read the the end of the file)
-                % makes sure that we didn't get a number of samples that's not divisible
-                % by the number of channels.
-                fRemainderCount = mod(length(fTempChannelData), aData.numChannels);
-                if fRemainderCount ~= 0
-                    warning('load_AXiS_raw:remainderCheck', ...
-                        'File %s has wrong number of samples for %u channels', ...
-                        aSourceData.FileID, aData.numChannels);
-                end
-                
-                % Convert the 1D array to a 2D array, with channel as the second dimension
-                % (starts as first dimension and then is transposed)
-                fTempChannelData = reshape(fTempChannelData(:), aData.numChannels, []);
-                
-                % Remap
-                aData.channelData = fTempChannelData(aData.loadedChannels, :);
-                aData.channelData = aData.channelData';
-            end
-        end
-        
-        function aData = Legacy_Load_spike_v1(aSourceData, aHeader, aTimeRange)
-            % Check to make sure the file format makes sense for a spike file
-            if aHeader.header.numChannelsPerBlock ~= 1
-                error('Load_spike_v1:argNumChannelsPerBlock', ...
-                    'Invalid header for SPIKE file: incorrect channels per block');
-            end
-            
-            if aHeader.header.blockHeaderSize < Spike_v1.LOADED_HEADER_SIZE
-                error('Load_spike_v1:argBlockHeaderSize', ...
-                    'Invalid header for SPIKE file: block header size too small');
-            end
-            
-            if aHeader.header.numSamplesPerBlock < 1
-                error('load_AxIS_spike:argNumSamplesPerBlock', ...
-                    'Invalid header for SPIKE file: number of samples per block < 1');
-            end
-            
-            % Copy input structure to output; then add information to output
-            aData = aHeader;
-            
-            if isempty(aHeader.loadedChannels)
-                % No channels requested - don't read any data
-                return;
-            end
-            
-            if ischar(aTimeRange) && strcmp(aTimeRange, 'all')
-                fFirstSample = 0;
-                fLastSample  = Inf;
-            else
-                fFirstSample = aTimeRange(1) * aData.samplingFrequency;
-                fLastSample  = aTimeRange(2) * aData.samplingFrequency;
-            end
-            
-            fSparseChannelIndex = sparse(...
-                double([aData.channelArray.channel.channelAchk] + 1) , ...
-                double([aData.channelArray.channel.channelIndex] + 1), ...
-                double(1:aData.channelArray.numChannels), ...
-                BlockVectorLegacyLoader.MAX_CHANNEL_ARTICHOKE,...
-                BlockVectorLegacyLoader.MAX_CHANNEL_INDEX);
-            
-            spikeIndex = 1;
-            
-            % Manage the spike array to avoid "growing" it
-            fSpikeArrayCapacity = 0;
-            
-            fseek(aSourceData.FileID, int64(aSourceData.Start), 'bof');
-            fStop = aSourceData.Start + aSourceData.EntryRecord.Length;
-            
-            while ftell(aSourceData.FileID) < fStop
-                % Load the block header for this spike
-                fCurrentSpike = [];
-                fCurrentSpike.startingSample      = fread(aSourceData.FileID, 1, 'int64'); %Changed uint64 to int64
-                
-                if feof(aSourceData.FileID)
-                    % we were at the end of the file
-                    break;
-                end
-                
-                fHardwareChannelIndex              = fread(aSourceData.FileID, 1, 'uint8');
-                fHardwareChannelAchk               = fread(aSourceData.FileID, 1, 'uint8');
-                fCurrentSpike.triggerSampleOffset  = fread(aSourceData.FileID, 1, 'uint32');
-                fCurrentSpike.stDev                = fread(aSourceData.FileID, 1, 'double');
-                fCurrentSpike.threshold            = fread(aSourceData.FileID, 1, 'double');
-                
-                % Get well and electrode row and column
-                fCurrentSpike.channelArrayIndex = full(fSparseChannelIndex(fHardwareChannelAchk + 1, fHardwareChannelIndex + 1));
-                if fCurrentSpike.channelArrayIndex == 0
-                    error('load_AxIS_spike:invalidSpikeChannel', ...
-                        ['Spike has invalid Artichoke/Channel number ' num2str(fHardwareChannelAchk) ...
-                        ' / ' num2str(fHardwareChannelIndex)]);
-                end
-                
-                fCurrentSpike.channelInfo = aData.channelArray.channel(fCurrentSpike.channelArrayIndex);
-                
-                % Historical channel number -- XY, where X = electrodeColumn and Y = electrodeRow
-                % This field is deprecated, since it doesn't contain multiwell information.
-                fCurrentSpike.channel = 10*fCurrentSpike.channelInfo.electrodeColumn + ...
-                    fCurrentSpike.channelInfo.electrodeRow;
-                
-                % Seek forward to the end of the header.
-                % It might seem cleaner to do this by saving the current position
-                % before we read the header and seeking forward from there.
-                % However, that method will not handle files larger than 4GB if fseek
-                % and ftell are not 64-bit clean.
-                fseek(aSourceData.FileID, aData.header.blockHeaderSize - Spike_v1.LOADED_HEADER_SIZE, 'cof');
-                
-                if ftell(aSourceData.FileID) >= fStop
-                    % file ended before the start of the data -- looks like a truncated file
-                    warning('load_AxIS_spike:headerTruncated', ...
-                        'Spike header truncated at end of file');
-                    break;
-                end
-                
-                % Read the data for this spike
-                fCurrentSpike.waveform = fread(aSourceData.FileID, aData.header.numSamplesPerBlock, 'int16=>int16');
-                
-                if length(fCurrentSpike.waveform) < aData.header.numSamplesPerBlock
-                    % file ended in the middle of the data
-                    warning('load_AxIS_spike:dataTruncated', ...
-                        'Spike data truncated at end of file');
-                    break;
-                end
-                
-                % Does this spike match the channel filter?  If not, skip it.
-                if ~ismember(fCurrentSpike.channelArrayIndex, aData.loadedChannels)
-                    continue;
-                end
-                
-                % Does this spike match the time filter?
-                if fCurrentSpike.startingSample < fFirstSample
-                    % Too early
-                    continue;
-                elseif fCurrentSpike.startingSample >= fLastSample
-                    % Too late.  Since spikes are in chronological order, we
-                    % can stop reading now.
-                    break;
-                end
-                
-                
-                % Check for capacity in the spike array
-                if spikeIndex > fSpikeArrayCapacity
-                    if fSpikeArrayCapacity == 0
-                        % Let it grow on its own
-                        fSpikeArrayCapacity = 1;
-                    else
-                        % Double the capacity
-                        fSpikeArrayCapacity = fSpikeArrayCapacity * 2;
-                        aData.spikes(fSpikeArrayCapacity).startingSample = -1;
-                    end
-                end
-                
-                % save the spike
-                aData.spikes(spikeIndex) = fCurrentSpike;
-                spikeIndex = spikeIndex + 1;
-            end
-            
-            % trim down the spike array
-            if spikeIndex > 1
-                aData.spikes = aData.spikes(1:spikeIndex-1);
-            else
-                aData.spikes = [];
-            end
-        end
-    end
-    
-end
-

+ 0 - 452
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/BlockVectorSet.m

@@ -1,452 +0,0 @@
-classdef BlockVectorSet < handle
-    %BLOCKVECTORSET is a grouping of data and metadata for a series of data contained within an AxisFile.
-    %   this class is composed of 4 major parts:
-    %
-    %   ChannelArray:    The channel array (See ChannelArray.m) is a listing of
-    %                    all of the channels that were recorded in this
-    %                    loaded set.
-    %
-    %   Header:          The header of the data (See BlockVectorHeader.m) contains the basic infomation
-    %                    that is used in loading and using the data in this
-    %                    set (e.g. Sampling Frequency, Voltage Scale, etc...)
-    %
-    %   HeaderExtension: The header extension (See BlockVectorHeaderExtension.m)
-    %                    contains metadata about the data capture / Reprocessing.
-    %
-    %   Data:            The data in this file (See BlockVectorData.m)
-    %                    contains the methods for loading the sample data
-    %                    from this set.
-    
-    properties (SetAccess = private, GetAccess = private)
-        sourceFile
-    end
-    
-    properties(GetAccess = public, SetAccess = private)
-        ChannelArray
-        Header
-        HeaderExtension
-        Data
-    end
-    
-    methods
-        
-        function this = BlockVectorSet(varargin)
-            this.setval(varargin{:});
-        end
-        
-        
-        function clone = Clone(this, varargin)
-            clone = BlockVectorSet();
-            if(isa(this.ChannelArray,'ChannelArray'))
-                clone.ChannelArray = this.ChannelArray;
-            end
-            if(isa(this.Header,'BlockVectorHeader'))
-                clone.Header = this.Header;
-            end
-            if(isa(this.HeaderExtension,'BlockVectorHeaderExtension'))
-                clone.HeaderExtension = this.HeaderExtension;
-            end
-            if(isa(this.Data,'BlockVectorData'))
-                clone.Data = this.Data;
-            end
-            if(isa(this.sourceFile,'AxisFile'))
-                clone.sourceFile = this.sourceFile;
-            end
-            clone.setval(varargin{:});
-        end
-        
-    end
-    
-    methods(Access = private)
-        
-        function setval(this, varargin)
-            for i = 1:length(varargin)
-                
-                arg = varargin{i};
-                
-                if(isa(arg,'ChannelArray'))
-                    this.ChannelArray = arg;
-                elseif(isa(arg,'BlockVectorHeader'))
-                    this.Header = arg;
-                elseif(isa(arg,'BlockVectorHeaderExtension'))
-                    this.HeaderExtension = arg;
-                elseif(isa(arg,'BlockVectorData'))
-                    this.Data = arg;
-                elseif(isa(arg,'AxisFile'))
-                    this.sourceFile = arg;
-                else
-                    error('Unknown member type');
-                end
-                
-            end
-        end
-        
-    end
-    
-    methods (Access = public)
-        
-        
-        function aData = LoadData(this, varargin)
-            % LoadData loads a Dataset, creaing a data structure similar
-            % to the one created by load_AxIS_file (Deprecated)
-            %
-            %  Legal forms:
-            %     data = LoadData();
-            %     data = LoadData(well);
-            %     data = LoadData(electrode);
-            %     data = LoadData(well, electrode);
-            %     data = LoadData(timespan);
-            %     data = LoadData(well, timespan);
-            %     data = LoadData(electrode, timespan);
-            %     data = LoadData(well, electrode, timespan);
-            %     data = LoadData(dimensions);
-            %     data = LoadData(well, dimensions);
-            %     data = LoadData(electrode, dimensions);
-            %     data = LoadData(well, electrode, dimensions);
-            %     data = LoadData(timespan, dimensions);
-            %     data = LoadData(well, timespan, dimensions);
-            %     data = LoadData(electrode, timespan, dimensions);
-            %     data = LoadData(well, electrode, timespan, dimensions);
-            %
-            %  Optional arguments:
-            %    well        String listing which wells (in a multiwell file) to load.
-            %                Format is a comma-delimited string with whitespace ignored, e.g.
-            %                'A1, B2,C3' limits the data loaded to wells A1, B2, and C3.
-            %                Also acceptable: 'all' to load all wells.
-            %                If this parameter is omitted, all wells are loaded.
-            %                For a single-well file, this parameter is ignored.
-            %
-            %    electrode   Which electrodes to load.  Format is either a comma-delimited string
-            %                with whitespace ignored (e.g. '11, 22,33') or a single channel number;
-            %                that is, a number, not part of a string.
-            %                Also acceptable: 'all' to load all channels and 'none', '-1', or -1
-            %                to load no data (returns only header information).
-            %                If this parameter is omitted, all channels are loaded.
-            %
-            %    timespan    Span of time, in seconds, over which to load data.  Format is a two-element
-            %                array, [t0 t1], where t0 is the start time and t1 is the end time and both
-            %                are in seconds after the first sample in the file.  Samples returned are ones
-            %                that were taken at time >= t0 and <= t1.  The beginning of the file
-            %                is at 0 seconds.
-            %                If this parameter is omitted, the data is not filtered based on time.
-            %
-            %    dimensions  Preferred number of dimensions to report the waveforms in.
-            %                Value must be a whole number scalar: 1, 3, or 5 (Other values are ignored):
-            %
-            %                dimensions = 1 -> ByPlate: returns a vector of Waveform objects, 1 Waveform
-            %                                  per signal in the plate
-            %
-            %                dimensions = 3 -> ByWell: Cell Array of vectors of waveform 1 Waveform per signal
-            %                                  in the electrode with size (well Rows) x (well Columns)
-            %
-            %                dimensions = 5 -> ByElectrode: Cell Array of vectors of waveform 1 Waveform per .
-            %                                  signal in the electrode with size (well Rows) x (well Columns) x
-            %                                  (electrode Columns) x (electrode Rows)
-            %
-            %                NOTE: The default loading dimensions for
-            %                continous raw data is 5 and the default for
-            %                spike data is 3.
-            
-            fLoadArgs = LoadArgs(varargin);
-            fTargetWell = fLoadArgs.Well;
-            fTargetElectrode = fLoadArgs.Electrode;
-            
-            fChannelsToLoad = BlockVectorSet.get_channels_to_load(this.ChannelArray, fTargetWell, fTargetElectrode);
-            
-            if(isempty(this.HeaderExtension))
-                fDataType = this.sourceFile.PrimaryDataType;
-            else
-                fDataType = this.HeaderExtension.DataType;
-            end
-            
-            if(fDataType == BlockVectorDataType.Raw_v1)
-                fDimensions = fLoadArgs.Dimensions;
-                if(isempty(fDimensions))
-                    fDimensions = LoadArgs.ByElectrodeDimensions;
-                end
-                aData = this.Data.GetRawV1ContinuousWaveforms( ...
-                    this, ...
-                    fChannelsToLoad, ...
-                    fLoadArgs.Timespan, ...
-                    fDimensions);
-                
-            elseif(fDataType == BlockVectorDataType.Spike_v1)
-                fDimensions = fLoadArgs.Dimensions;
-                if(isempty(fDimensions))
-                    fDimensions = LoadArgs.ByElectrodeDimensions;
-                end
-                aData = this.Data.GetSpikeV1Waveforms( ...
-                    this, ...
-                    fChannelsToLoad, ...
-                    fLoadArgs.Timespan, ...
-                    fDimensions);
-                
-            end
-            
-        end
-        
-        function aData = load_as_legacy_struct(this, varargin)
-            % load_AsLegacyStruct loads a dataset, creating a data structure similar
-            % to the one created by load_AxIS_file (Deprecated)
-            %
-            %  Legal forms:
-            %     data = load_as_legacy_struct();
-            %     data = load_as_legacy_struct(well);
-            %     data = load_as_legacy_struct(electrode);
-            %     data = load_as_legacy_struct(well, electrode);
-            %     data = load_as_legacy_struct(timespan);
-            %     data = load_as_legacy_struct(well, timespan);
-            %     data = load_as_legacy_struct(electrode, timespan);
-            %     data = load_as_legacy_struct(well, electrode, timespan);
-            %
-            %
-            %  Optional arguments:
-            %    well        String listing which wells (in a multiwell file) to load.
-            %                Format is a comma-delimited string with whitespace ignored, e.g.
-            %                'A1, B2,C3' limits the data loaded to wells A1, B2, and C3.
-            %                Also acceptable: 'all' to load all wells.
-            %                If this parameter is omitted, all wells are loaded.
-            %                For a single-well file, this parameter is ignored.
-            %
-            %    electrode   Which electrodes to load.  Format is either a comma-delimited string
-            %                with whitespace ignored (e.g. '11, 22,33') or a single channel number;
-            %                that is, a number, not part of a string.
-            %                Also acceptable: 'all' to load all channels and 'none', '-1', or -1
-            %                to load no data (returns only header information).
-            %                If this parameter is omitted, all channels are loaded.
-            %
-            %    timespan    Span of time, in seconds, over which to load data.  Format is a two-element
-            %                array, [t0 t1], where t0 is the start time and t1 is the end time and both
-            %                are in seconds after the first sample in the file.  Samples returned are ones
-            %                that were taken at time >= t0 and <= t1.  The beginning of the file
-            %                is at 0 seconds.
-            %                If this parameter is omitted, the data is not filtered based on time.
-            %
-            
-            fLoadArgs = LoadArgs(varargin{:});
-            fTargetWell = fLoadArgs.Well;
-            fTargetElectrode = fLoadArgs.Electrode;
-            fTimeRange = fLoadArgs.Timespan;
-            
-            aData = [];
-            aData.header = [];
-            
-            %Check for Required ource file
-            fSourceFile = this.sourceFile;
-            if(~isa(fSourceFile,'AxisFile'))
-                error('BlockVectorSet: Source file not specified');
-            end
-            
-            %Check for optional BlockVectorHeaderExtension and Notes
-            if(~isempty(fSourceFile.Notes))
-                [~,idx]=max([fSourceFile.Notes.Revision]);
-
-                fNotes = fSourceFile.Notes(idx);
-                aData.notes = [];
-                aData.notes.investigator = fNotes.Investigator;
-                aData.notes.experimentId = fNotes.ExperimentID;
-                aData.notes.notes = fNotes.Description;
-            end
-            
-            aData.header.fileTypeNumber     = fSourceFile.PrimaryDataType; %Default incase we don't have a header extension
-            aData.header.headerVersionMajor = fSourceFile.HeaderVersionMajor;
-            aData.header.headerVersionMinor = fSourceFile.HeaderVersionMinor;
-
-            %Check for Required Entries
-            fChannelArray = this.ChannelArray;
-            if(~isa(fChannelArray,'ChannelArray'))
-                error('BlockVectorSet: Channel array was not specified for this file.');
-            end
-            
-            fHeader = this.Header;
-            if(~isa(fHeader,'BlockVectorHeader'))
-                error('BlockVectorSet: BlockVectorHeader was not specified for this file.');
-            end
-            
-            fData = this.Data;
-            if(~isa(fData,'BlockVectorData'))
-                error('BlockVectorSet: No Data found');
-            end
-            
-            %Check for optional BlockVectorHeaderExtension
-            fHeaderExtension = this.HeaderExtension;
-            if(isa(fHeaderExtension,'BlockVectorHeaderExtension'))
-                aData.header.fileTypeNumber = fHeaderExtension.DataType;
-            end
-            
-            %Handle Channel Array Data
-            aData.channelArray = [];
-            aData.channelArray.plateType = fChannelArray.PlateType;
-            aData.channelArray.numChannels = length(fChannelArray.Channels);
-
-            aData.channelArray.channel = [];
-            for i = 1:aData.channelArray.numChannels
-                aData.channelArray.channel(i).wellColumn      = fChannelArray.Channels(i).WellColumn;
-                aData.channelArray.channel(i).wellRow         = fChannelArray.Channels(i).WellRow;
-                aData.channelArray.channel(i).electrodeColumn = fChannelArray.Channels(i).ElectrodeColumn;
-                aData.channelArray.channel(i).electrodeRow    = fChannelArray.Channels(i).ElectrodeRow;
-                aData.channelArray.channel(i).channelAchk     = fChannelArray.Channels(i).ChannelAchk;
-                aData.channelArray.channel(i).channelIndex    = fChannelArray.Channels(i).ChannelIndex;
-                aData.channelArray.channel(i).auxData         = fChannelArray.Channels(i).AuxData;
-            end
-
-            %Handle BlockVectorHeaders Data
-            
-            aData.samplingFrequency = fHeader.SamplingFrequency;
-            aData.voltageScale = fHeader.VoltageScale;
-
-            aData.header.numChannelsPerBlock = fHeader.NumChannelsPerBlock;
-            aData.header.numSamplesPerBlock  = fHeader.NumSamplesPerBlock;
-            aData.header.blockHeaderSize     = fHeader.BlockHeaderSize;
-
-            if(~isempty(fHeader.FileStartTime))
-
-                aData.fileStartTime = [];
-
-                aData.fileStartTime.year        = fHeader.FileStartTime.Year;
-                aData.fileStartTime.month       = fHeader.FileStartTime.Month;
-                aData.fileStartTime.day         = fHeader.FileStartTime.Day;
-                aData.fileStartTime.hour        = fHeader.FileStartTime.Hour;
-                aData.fileStartTime.minute      = fHeader.FileStartTime.Minute;
-                aData.fileStartTime.second      = fHeader.FileStartTime.Second;
-                aData.fileStartTime.millisecond = fHeader.FileStartTime.Millisecond;
-
-            end
-
-            if(~isempty(fHeader.ExperimentStartTime))
-
-                aData.experimentStartTime = [];
-                aData.experimentStartTime.year        = fHeader.ExperimentStartTime.Year;
-                aData.experimentStartTime.month       = fHeader.ExperimentStartTime.Month;
-                aData.experimentStartTime.day         = fHeader.ExperimentStartTime.Day;
-                aData.experimentStartTime.hour        = fHeader.ExperimentStartTime.Hour;
-                aData.experimentStartTime.minute      = fHeader.ExperimentStartTime.Minute;
-                aData.experimentStartTime.second      = fHeader.ExperimentStartTime.Second;
-                aData.experimentStartTime.millisecond = fHeader.ExperimentStartTime.Millisecond;
-
-            end
-
-            fChannelsToLoad = BlockVectorSet.get_channels_to_load(fChannelArray, fTargetWell, fTargetElectrode);
-            aData.loadedChannels = fChannelsToLoad;
-            
-            %Handle Data 
-            
-            if aData.header.fileTypeNumber == BlockVectorDataType.Raw_v1
-                aData.fileType = 'raw';
-                aData = BlockVectorLegacyLoader.Legacy_Load_Raw_v1(fData, aData, fTimeRange);
-
-            elseif aData.header.fileTypeNumber == BlockVectorDataType.Spike_v1
-                aData.fileType = 'spike';
-                aData = BlockVectorLegacyLoader.Legacy_Load_spike_v1(fData, aData, fTimeRange);
-
-            else
-                error('BlockVectorSet: Unsupported file type number %u', aData.header.fileTypeNumber);
-            end
-            
-            aData = rmfield(aData, 'header');
-        end
-    end
-    
-    methods(Static, Access = private)
-        
-        function ChannelListOut = get_channels_to_load(aChannelArray, aTargetWells, aTargetElectrodes)
-            
-            % Decode the aTargetWells string
-            if strcmp(aTargetWells, 'all')
-                % User has requested all wells - figure out what those
-                % are from the channel array
-                fTargetWells = BlockVectorSet.all_wells_electrodes([aChannelArray.Channels.WellColumn], ...
-                    [aChannelArray.Channels.WellRow]);
-            else
-                fTargetWells = aTargetWells;
-            end
-            
-            % Decode the aTargetElectrodes string
-            if strcmp(aTargetElectrodes, 'all')
-                % User has requested all electrodes - figure out what those
-                % are from the channel array
-                fTargetElectrodes = BlockVectorSet.all_wells_electrodes([aChannelArray.Channels.ElectrodeColumn], ...
-                    [aChannelArray.Channels.ElectrodeRow]);
-            elseif strcmp(aTargetElectrodes, 'none')
-                % User has requested no electrodes
-                fTargetElectrodes = [];
-            else
-                fTargetElectrodes = aTargetElectrodes;
-            end
-            
-            ChannelListOut = zeros(1, size(fTargetWells, 1) * size(fTargetElectrodes, 1));
-            if ~isempty(ChannelListOut)
-                
-                for fChannelArrayIndex = 1:length(aChannelArray.Channels)
-                    fCurrentChannel = aChannelArray.Channels(fChannelArrayIndex);
-                    
-                    [fFoundWell, fIdxWell] = ismember( [fCurrentChannel.WellColumn  fCurrentChannel.WellRow], ...
-                        fTargetWells, 'rows');
-                    if ~any(fFoundWell)
-                        continue;
-                    end
-                    
-                    [fFoundElectrode, fIdxElectrode ] = ismember( [fCurrentChannel.ElectrodeColumn  fCurrentChannel.ElectrodeRow], ...
-                        fTargetElectrodes, 'rows');
-                    
-                    if ~any(fFoundElectrode)
-                        continue;
-                    end
-                    
-                    ChannelListOut( (fIdxWell - 1) * size(fTargetElectrodes, 1) + fIdxElectrode ) = fChannelArrayIndex;
-                end
-                
-                % Notify the user of any requested channels that weren't found in the channel array.
-                % This is not necessarily an error; for example, if a whole well is requested, and
-                % some channels in that well weren't recorded, we should return the well without
-                % the "missing" channel.
-                fChannelIdxZeros = find(ChannelListOut == 0);
-                for i=1:length(fChannelIdxZeros)
-                    fIdxNotFound = fChannelIdxZeros(i);
-                    fMissingWell = floor((fIdxNotFound-1) / size(fTargetElectrodes, 1)) + 1;
-                    fMissingElectrode = mod(fIdxNotFound-1, size(fTargetElectrodes, 1)) + 1;
-                    warning('get_channels_to_load:invalidWellElectrode', ...
-                        sprintf('Well/electrode %d %d / %d %d not recorded in file', ...
-                        fTargetWells(fMissingWell, 1), fTargetWells(fMissingWell, 2), ...
-                        fTargetElectrodes(fMissingElectrode, 1), fTargetElectrodes(fMissingElectrode, 2)));
-                end
-                
-                % Strip out any zeros from aChannelListOut, because these correspond to channels that weren't in
-                % the loaded channel array, and therefore won't be loaded.
-                ChannelListOut = ChannelListOut( ChannelListOut ~= 0 );
-            end
-            
-        end % end function
-        
-        % Subfunction to expand an 'all' well or electrode list
-        function fOutput = all_wells_electrodes(aColumns, aRows)
-            
-            fOutput  = [];
-            aColumns = unique(aColumns); % sort ascending and dedup
-            aRows    = unique(aRows);
-            
-            for fiRow = 1:length(aRows)
-                for fiCol = 1:length(aColumns)
-                    fOutput = [ fOutput ; aColumns(fiCol) aRows(fiRow) ];
-                end
-            end
-            
-        end
-        
-        % Subfunction to help with channel array search
-        function aMatch = match_well_electrode(aChannelStruct, aWellElectrode)
-            
-            if aChannelStruct.wellColumn == aWellElectrode(1) && ...
-                    aChannelStruct.wellRow    == aWellElectrode(2) && ...
-                    aChannelStruct.electrodeColumn == aWellElectrode(3) && ...
-                    aChannelStruct.electrodeRow    == aWellElectrode(4)
-                aMatch = 1;
-            else
-                aMatch = 0;
-            end
-            
-        end
-    end
-    
-end
-

+ 0 - 90
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/CRC32.m

@@ -1,90 +0,0 @@
-classdef CRC32 < handle
-    %CRC32 Class for calculating CRC32s
-    %   For Quick Reference, see http://en.wikipedia.org/wiki/Cyclic_redundancy_check
-    %   CRC32 implementation adapted from: http://damieng.com/blog/2006/08/08/calculating_crc32_in_c_and_net
-    
-     
-    properties (SetAccess = private, GetAccess = private)
-        table
-    end
-    
-    properties (Constant = true, GetAccess = public)
-        DefaultPolynomial = hex2dec('edb88320');
-        DefaultSeed = hex2dec('ffffffff');
-    end
-    
-    properties (SetAccess = private, GetAccess = public)
-        Polynomial
-        Seed
-        Hash
-    end
-    
-    methods (Access = public)
-        
-      function this = CRC32(aPolynomial, aSeed) 
-          if nargin < 2
-            aSeed = CRC32.DefaultSeed;
-          end
-          if nargin < 1
-              aPolynomial = CRC32.DefaultPolynomial;
-          end
-         this.Polynomial = cast(aPolynomial, 'uint32');
-         this.Seed = cast(aSeed, 'uint32');
-         this.table = CRC32.InitializeTable(this.Polynomial);
-         this.Initialize();
-      end
-      
-      function Initialize(this)
-          this.Hash = cast(this.Seed, 'uint32');
-      end
-        
-      function crc = Compute(this, bytes, start, size)
-          if nargin < 3
-            start = 1;
-          end
-          if nargin < 4
-            size =  length(bytes) - start + 1;
-          end
-          crc = bitxor(... %This is Just a bitwise not
-            CRC32.DefaultSeed,...
-            this.CalculateHash(this.table, this.Seed, bytes, start, size)); 
-      end
-            
-    end
-    
-    methods (Access = private, Static = true)
-        
-        function createTable = InitializeTable(aPolynomial) 
-            
-            polynomial = cast(aPolynomial, 'uint32');
-            createTable = cast(zeros(256, 0), 'uint32');
-            
-            for i = 0 : 255
-                entry = cast(i, 'uint32');
-                for j = 0 : 7
-                    if bitand(entry, uint32(1)) == uint32(1)
-                        entry = bitxor( (bitshift(entry, -1)) , polynomial);
-                    else
-                        entry = (bitshift(entry, -1));
-                    end
-                        
-                end
-                createTable(i + 1) = entry;
-            end
-        end        
-        
-        function crc = CalculateHash(table, seed, buffer, start, size) 
-            crc = seed;
-            crcspace = (1:size) + (start - 1);
-            for i = crcspace
-                lookup = cast( bitand(...
-                    bitxor(buffer(i) , crc), ...
-                    255), 'uint8');
-                crc = bitxor(...
-                    bitshift(crc , -8) , ...
-                    table(uint16(lookup) + 1));
-            end
-        end 
-    end
-end
-

+ 0 - 181
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/ChannelArray.m

@@ -1,181 +0,0 @@
-classdef ChannelArray < Entry
-    %CHANNELARRAY Class that represents a list of loaded Channels in a BlockVectorDataSet
-    %
-    %   PlateType:  Numeric ID of the loaded plate that thes channels are 
-    %               associated with.
-    %
-    %   Channels:   Vector of Channelmapping objects in the order that they
-    %               are included in continuous file.
-    
-    properties (GetAccess = private, SetAccess = private)
-        electrodeHashMap
-        channelHashMap
-    end
-    
-    properties(GetAccess = public, SetAccess = private)
-        PlateType
-        Channels
-    end
-    
-    
-    methods(Static, Access = private)
-        function varagout = HandleVarargin(varargin)
-            if(nargin == 0)
-                varagout = {};
-            elseif(nargin == 2)
-                varagout{1} = varargin{1};
-                varagout{2} = int64(ftell( varargin{2}));
-            else
-                error('Argument Error')
-            end
-        end
-    end
-    
-    methods (Access = public)
-        function this = ChannelArray(varargin)
-            entryConstructorArgs = ChannelArray.HandleVarargin(varargin{:}); ...
-            this = this@Entry(entryConstructorArgs{:});
-            
-            if(nargin == 0)
-                this.PlateType = [];
-                this.Channels = [];
-                this.electrodeHashMap = [];
-                this.channelHashMap = [];
-            elseif(nargin == 2)
-                aFileID = varargin{2};
-                this.PlateType   = fread(aFileID, 1, 'uint32=>uint32');
-                fNnumChannels = fread(aFileID, 1, 'uint32=>uint32');
-                
-                this.Channels = ChannelMapping.empty(0, fNnumChannels);
-          
-                fIndices = int32(1:fNnumChannels);
-                for i = fIndices
-                    this.Channels(i) = ChannelMapping(aFileID);
-                end
-                
-                
-                this.RebuildHashMaps();
-                
-                
-                if(ftell(aFileID) ~= (this.Start + this.EntryRecord.Length))
-                    error('Unexpected Channel array length')
-                end
-            else
-                error('Argument Error')
-            end
-            
-        end
-        
-        function index = LookupElectrode(this, ...
-                aWellColumn, aWellRow,...
-                aElectrodeColumn, aElectrodeRow)
-            %LookupElectrode: Quickly finds the index Channels of a given
-            %                 electrode position
-            
-            index = this.electrodeHashMap(ChannelMapping.HashElectrode(...
-                aWellColumn, aWellRow, aElectrodeColumn, aElectrodeRow));
-            
-        end
-        
-        function index = LookupChannel(this, ...
-                aChannelAchk, aChannelIndex)
-            %LookupChannel:   Quickly finds the index Channels of a given
-            %                 Amplifier (Artichoke) channel
-            index = this.channelHashMap(ChannelArray.HashChannel(...
-                aChannelAchk, aChannelIndex));
-            
-        end
-        
-    end
-    
-    methods(Access = private)
-        
-        function RebuildHashMaps(this)
-            
-            this.electrodeHashMap = containers.Map('KeyType', 'int32', 'ValueType', 'int32');
-            this.channelHashMap = containers.Map('KeyType', 'int32', 'ValueType', 'int32');
-            
-            fIndices = 1 : length(this.Channels);
-            
-            for fIndex = fIndices
-                
-                fElectrodeHash = ChannelArray.HashElectrode( ...
-                    this.Channels(fIndex).WellColumn,...
-                    this.Channels(fIndex).WellRow,...
-                    this.Channels(fIndex).ElectrodeColumn,...
-                    this.Channels(fIndex).ElectrodeRow);
-                
-                fChannelHash = ChannelArray.HashChannel( ...
-                    this.Channels(fIndex).ChannelAchk,...
-                    this.Channels(fIndex).ChannelIndex);
-                
-                if (this.electrodeHashMap.isKey(fElectrodeHash) || this.channelHashMap.isKey(fElectrodeHash))
-                    error('Key already added')
-                end
-                
-                this.electrodeHashMap(fElectrodeHash) =  fIndex;
-                this.channelHashMap(fChannelHash) = fIndex;
-                
-            end
-        end
-    end
-    
-    methods(Access = private, Static = true)
-            
-        
-        function hash = HashElectrode( ...
-                aWellColumn, aWellRow,...
-                aElectrodeColumn, aElectrodeRow)
-            
-            hash = bitshift(uint32(aWellColumn), 24);
-            hash = bitor(bitshift(uint32(aWellRow), 16), hash);
-            hash = bitor(bitshift(uint32(aElectrodeColumn), 8), hash);
-            hash = bitor(uint32(aElectrodeRow), hash);
-            
-            hash = uint32(hash);
-            
-        end
-        
-        function hash = HashChannel( ...
-                aChannelAchk, aChannelIndex)
-            
-            hash = bitshift(uint32(aChannelAchk), 8);
-            hash = bitor(uint32(aChannelIndex), hash);
-            
-            hash = uint32(hash);
-            
-        end
-        
-    end
-    
-    methods (Static)
-        function fChannelArray = version_0_1_channel_array()
-            
-            fChannelArray = ChannelArray();
-            % Hardware-to-grid channel mapping. This is a constant only for Muse Beta (AxIS v0.1)
-            % and file format version 0.1.  For later versions, mapping is loaded from the file itself.
-            fChannelMapping          = LegacySupport.P200D30S_CHANNEL_MAPPING;
-            fChannelArray.PlateType   = LegacySupport.P200D30S_PLATE_TYPE;
-            
-            fChannelArray.Channels = ChannelMapping.empty(0,(length(fChannelMapping)));
-            
-            for fiCol = 1:size(fChannelMapping, 1)
-                for fiRow = 1:size(fChannelMapping, 2)
-                    fCurrentChannelIndex = fChannelMapping(fiRow, fiCol);
-                    
-                    fNewMapping = ChannelMapping(...
-                        1, 1,...
-                        fiCol, fiRow,...
-                        0, fCurrentChannelIndex);
-                    
-                    fChannelArray.Channels(fCurrentChannelIndex + 1) = fNewMapping;
-                end
-            end
-            
-            fChannelArray.RebuildHashMaps();
-            
-        end
-    end
-    
-end
-

+ 0 - 115
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/ChannelMapping.m

@@ -1,115 +0,0 @@
-classdef ChannelMapping
-    %CHANNELMAPPING represents the mapping of an electrode position to an
-    %Amplifier (Artichoke) channel by way of the plate it was recorded
-    %with. 
-    %
-    %     WellRow:          Numeric representation of the well row (e.g. A -> 1)
-    %
-    %     WellColumn:       Well column number of this electrode
-    %
-    %     ElectrodeColumn:  Column in the well of the electrode
-    %
-    %     ElectrodeRow:     Row in the well of the electrode
-    %
-    %     ChannelAchk:      Specific amplifer chip (Artichoke) to which the 
-    %                       electrode was connected 
-    %
-    %     ChannelIndex:     Specific channel number of connected amplifier 
-    %                       to which the electrode was connected 
-    %
-    %     AuxData:          Additional data for programmatic usage
-   
-    properties (GetAccess = private, Constant = true)
-        nullByte = typecast(int8(-1), 'uint8');
-        nullWord = typecast(int16(-1), 'uint16');
-    end
-    
-    properties (GetAccess = public, SetAccess = private)
-        WellRow
-        WellColumn
-        ElectrodeColumn
-        ElectrodeRow
-        ChannelAchk
-        ChannelIndex
-        AuxData
-    end
-   
-    methods(Access = public)
-        
-        function this = ChannelMapping( varargin )
-            
-            fNArgIn = length(varargin);
-            
-            if(fNArgIn == 0)
-                % Create a nonsense (Null) Channel Mapping 
-                this.WellRow         = ChannelMapping.nullByte;
-                this.WellColumn      = ChannelMapping.nullByte;
-                this.ElectrodeColumn = ChannelMapping.nullByte;
-                this.ElectrodeRow    = ChannelMapping.nullByte;
-                this.ChannelAchk     = ChannelMapping.nullByte;
-                this.ChannelIndex    = ChannelMapping.nullByte;
-                this.AuxData         = ChannelMapping.nullWord;
-                
-            elseif(fNArgIn == 1)                
-                % Assume Argument is a file ID from fOpen and that is
-                % seeked to the correct spot, read in arguments from this
-                % file
-                
-                aFileID = varargin{1};
-                
-                this.WellColumn      = fread(aFileID, 1, 'uint8=>uint8');
-                this.WellRow         = fread(aFileID, 1, 'uint8=>uint8');
-                this.ElectrodeColumn = fread(aFileID, 1, 'uint8=>uint8');
-                this.ElectrodeRow    = fread(aFileID, 1, 'uint8=>uint8');
-                this.ChannelAchk     = fread(aFileID, 1, 'uint8=>uint8');
-                this.ChannelIndex    = fread(aFileID, 1, 'uint8=>uint8');
-                this.AuxData         = fread(aFileID, 1, 'uint16=>uint16');
-                
-            elseif (fNArgIn == 6)
-                % Construct a new Channel Mapping from Scratch
-                % Argument order is(WellRow, WellColumn, ElectrodeColumn,
-                % ElectrodeRow, ChannelAchk, ChannelIndex)
-                
-                this.WellRow         = uint8(varargin{1});
-                this.WellColumn      = uint8(varargin{2});
-                this.ElectrodeColumn = uint8(varargin{3});
-                this.ElectrodeRow    = uint8(varargin{4});
-                this.ChannelAchk     = uint8(varargin{5});
-                this.ChannelIndex    = uint8(varargin{6});
-                this.AuxData         = ChannelMapping.nullWord;
-                
-            elseif (fNArgIn == 7)
-                % Construct a new Channel Mapping from Scratch
-                % Argument order is(WellRow, WellColumn, ElectrodeColumn,
-                % ElectrodeRow, ChannelAchk, ChannelIndex, AuxData)
-                
-                this.WellRow         = uint8(varargin{1});
-                this.WellColumn      = uint8(varargin{2});
-                this.ElectrodeColumn = uint8(varargin{3});
-                this.ElectrodeRow    = uint8(varargin{4});
-                this.ChannelAchk     = uint8(varargin{5});
-                this.ChannelIndex    = uint8(varargin{6});
-                this.AuxData         = uint16(varargin{7});
-            else
-                error('Argument Error')
-            end
-        end
-        
-        function retval = eq(this, aObj)
-            if(~isa(aObj, 'ChannelMapping') ...
-               || ~isa(this, 'ChannelMapping') )
-                retval = 0;
-                return;
-            end
-            retval = ...
-                this.WellRow ==  aObj.WellRow ...
-                && this.WellColumn ==  aObj.WellColumn ...
-                && this.ElectrodeColumn ==  aObj.ElectrodeColumn ...
-                && this.ElectrodeRow ==  aObj.ElectrodeRow ...
-                && this.ChannelAchk ==  aObj.ChannelAchk ...
-                && this.ChannelIndex ==  aObj.ChannelIndex;
-            
-        end
-    end
-end
-

+ 0 - 44
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/DateTime.m

@@ -1,44 +0,0 @@
-classdef DateTime
-    %DATETIME class representation of a date and time.
-    properties (GetAccess = public, SetAccess = private)
-        Year
-        Month
-        Day
-        Hour
-        Minute
-        Second
-        Millisecond
-    end
-    
-    methods(Access = public)
-        
-        function this = DateTime(aFileID)
-            %DateTime: Loads a DateTime from a file, assuming the read stream is
-            %pointed at the correct location.
-            this.Year        = fread(aFileID, 1, 'uint16=>double');
-            this.Month       = fread(aFileID, 1, 'uint16=>double');
-            this.Day         = fread(aFileID, 1, 'uint16=>double');
-            this.Hour        = fread(aFileID, 1, 'uint16=>double');
-            this.Minute      = fread(aFileID, 1, 'uint16=>double');
-            this.Second      = fread(aFileID, 1, 'uint16=>double');
-            this.Millisecond = fread(aFileID, 1, 'uint16=>double');
-        end
-       
-        function datevector = ToDateTimeVect(this)
-            %returns a six element date vector containing the represented time
-            % and date in decimal form.
-            % See also: clock, datevec, datenum, now
-            fSeconds = this.Second + (this.Millisecond * 1e-3);
-            datevector = double([this.Year this.Month this.Day this.Hour this.Minute fSeconds]);
-        end
-        
-        function  datenumber = ToDateTimeNumber(this)
-            % returns the represented date and time as a serial date 
-            %  number.
-            % See also: clock, datevec, datenum, now
-            datenumber = datenum(this.ToDateTimeVect());
-        end
-    end
-    
-end
-

+ 0 - 64
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/Entry.m

@@ -1,64 +0,0 @@
-classdef(Abstract = true) Entry < handle 
-    
-    %ENTRY base class for all Axion file entries
-    %
-    %   EntryRecord: Record that indicated this recod in the file.
-    %   
-    %   Start:       Location (# of bytes from start of file) of this
-    %                entryss
-    
-    properties (GetAccess = private, SetAccess = private)
-        indiciesForChannels
-        indiciesForElectrodes
-    end
-    
-    properties (GetAccess = public, SetAccess = private)
-        EntryRecord
-        Start
-    end
-    
-    methods (Access = protected)
-        function this = Entry(varargin)
-            % Entry: Construct a new instance of Entry.
-            %s
-            % Valid aruments:
-            % 
-            % Entry()           Consructs an entry that is not tied to a
-            %                   location in a file.
-            %
-            % Entry(aEntryRecord, aStart) Constructs a new Entry where:
-            %
-            %   aEntryRecord:   An EntryRecord that specifies the type and
-            %                   the length of the entry in the file
-            %
-            %   aStart:         An int64 specifiying the number of bytes 
-            %                   from the beginning of the file where the
-            %                   entry starts in the file.
-            %
-            
-            fNumArgs = length(varargin);
-            
-            if fNumArgs == 0
-                % Handle the no-argument case
-                return
-            elseif  fNumArgs == 2
-                aEntryRecord = varargin{1};
-                aStart = varargin{2};
-            else
-                error('Entry: Argument Error')
-            end 
-            
-            if(~isa(aEntryRecord, 'EntryRecord'))
-                error('Entry: Unexpected Type')
-            end
-            
-            if(~isa(aStart, 'int64'))
-                error('Entry: Unexpected Type')
-            end
-            this.EntryRecord = aEntryRecord;
-            this.Start = aStart;
-        end
-    end
-    
-end
-

+ 0 - 92
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/EntryRecord.m

@@ -1,92 +0,0 @@
-classdef EntryRecord
-    %ENTRYRECORD Structure representing an area of data in an Axis file
-    %
-    %   Type:   Type of data in the associated entry. See: EntryRecordID.m
-    %
-    %   Length: Length (in bytes) of the associated data entry.
-    %
-    
-    properties(Constant, GetAccess = private)
-        LENGTH_MASK_HIGH = uint64(hex2dec(  'ffffff'));
-        LENGTH_MASK_LOW  = uint64(hex2dec('ffffffff'));
-        
-    end
-    
-    properties(GetAccess = public, SetAccess = private)
-        Type
-        Length
-    end
-    
-    methods
-        function this = EntryRecord(aType, aLength)
-            if nargin > 0
-                this.Type = EntryRecordID(aType);
-                if(isinf(aLength) == 1)
-                    this.Length = inf;
-                else
-                    this.Length = int64(aLength);
-                end
-            end
-        end
-    end
-    
-    methods(Static = true)
-        
-        function this = FromUint64(aValues)
-            % FromUint64: Deserailizes an entry record from its native 64
-            % bit format in AxIS files.
-            %
-            %   ----------------64 Bits--------------
-            %   | ID (1 Byte) |   Length (7 Bytes)  |
-            %   -------------------------------------
-            %
-            % Note that only the last entry in a file amy have length ==
-            % (0x00ff ffff ffff  ffff) which denotes an entry that reads to
-            % the end of the file. These entrist have a length feild == inf
-            % when deserialized
-            %
-            this = EntryRecord.empty(0, length(aValues));
-            
-            if(~isa(aValues, 'uint64'))
-                error('EntryRecord.FromUint64: aValues must be of type uint64)');
-            end
-            
-            for i= 1:length(aValues)
-                long = aValues(i);
-                % Read the upper word (with ID feild)
-                [fID, fHaveParser] = EntryRecordID.TryParse(bitshift(long, int8(8-64))); 
-                % Shift right 4 bytes and mask with LENGTH_MASK_HIGH
-                fLength = uint64(bitand(bitshift(long, int8(32-64)), EntryRecord.LENGTH_MASK_HIGH));
-                % Start the check to see if this may be a 'Read to the end' 
-                % style EntryRecord
-                fIsinf = fLength == EntryRecord.LENGTH_MASK_HIGH;
-                % Shift left 4 bytes to be andded with lower word
-                fLength = uint64(bitshift(fLength, 32));
-                
-                % Read the lower word
-                fLowWord = uint64(bitand(long, EntryRecord.LENGTH_MASK_LOW));
-                % Finish the check to see if this may be a 'Read to the end' 
-                % style EntryRecord
-                fIsinf = fIsinf && (fLowWord == EntryRecord.LENGTH_MASK_LOW);
-                
-                %Recombine the upper and lower length portions.
-                fLength = int64(bitor(...
-                    fLength,...
-                    fLowWord));
-                
-                % If we don't know this Entry record type, read it as
-                % skipped
-                if(~fHaveParser)
-                    fID = EntryRecordID.Skip;
-                end
-                
-                if(fIsinf)
-                    this(i) = EntryRecord(fID, inf);
-                else
-                    this(i) = EntryRecord(fID, fLength);
-                end
-            end
-        end
-    end
-end
-

+ 0 - 49
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/EntryRecordID.m

@@ -1,49 +0,0 @@
-classdef EntryRecordID < uint8
-    %ENTRYRECORDID Values for entry record types used in headers /
-    %   subheaders
-    %
-    %   Terminate: Used to indicate the end of the record entries in
-    %   headers/ subheaders.
-    %
-    %   Skip: Indicates an area of the file to be ignored.
-    %
-    %   NotesArray: see Notes.m
-    %
-    %   ChannelArray: see ChannelArray.m
-    %
-    %   BlockVectorHeader: see BlockVectorHeader.m
-    %
-    %   BlockVectorData: see BlockVectorData.m
-    %
-    %   BlockVectorHeaderExtension: see BlockVectorHeaderExtension.m
-    
-    enumeration
-        Terminate(uint8(hex2dec('00'))),...
-        Skip(uint8(hex2dec('ff'))),...
-        NotesArray(uint8(hex2dec('01'))) ,...
-        ChannelArray(uint8(hex2dec('02'))),...
-        BlockVectorHeader(uint8(hex2dec('03'))),...
-        BlockVectorData(uint8(hex2dec('04'))),...
-        BlockVectorHeaderExtension(uint8(hex2dec('05')))
-    end
-    
-    
-    methods(Static)
-        function [value , success] = TryParse(aInput)
-            try
-                value = EntryRecordID(aInput);
-                success = true;
-            catch e
-                
-                warning(...
-                    'EntryRecordID:TryParse',  ...
-                    ['Unsupported EntryRecordID', e.message]);
-                
-                value = aInput;
-                success = false;
-            end
-        end
-    end
-    
-end
-

+ 0 - 106
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/LegacySupport.m

@@ -1,106 +0,0 @@
-classdef LegacySupport
-    %LEGACYSUPPORT This is a static class that contains resources for
-    %loading old style Axis Data
-    
-    properties(Constant)
-        P200D30S_PLATE_TYPE      = hex2dec('0400001');
-        INITIAL_HEADER_LENGTH = 1024;
-        DATA_START_OFFSET = 44;
-        CHANNEL_ARRAY_OFFSET = 4;
-        
-        NUM_COEFFICIENTS = 4;
-        
-        P200D30S_CHANNEL_MAPPING = ...
-            [54 50 46 42 35 36 37 38 ;
-            53 49 45 41 31 32 33 34 ;
-            52 48 44 40 27 28 29 30 ;
-            51 47 43 39 23 24 25 26 ;
-            58 57 56 55  7 11 15 19 ;
-            62 61 60 59  8 12 16 20 ;
-            2  1  0 63  9 13 17 21 ;
-            6  5  4  3 10 14 18 22 ];
-    end
-    
-    methods(Static)
-        
-        function fEntryRecords = GenerateEntries(aFileID, aEntriesStart)
-            
-            fseek(aFileID, LegacySupport.INITIAL_HEADER_LENGTH + LegacySupport.DATA_START_OFFSET, 'bof');% 44 is the offset of the datastart in the Matlab Freindly Header
-            fDataStart = fread(aFileID, 1, 'int64');
-            
-            fseek(aFileID, LegacySupport.INITIAL_HEADER_LENGTH + BlockVectorHeader.SIZE + LegacySupport.CHANNEL_ARRAY_OFFSET, 'bof');
-            fNumChannels = fread(aFileID, 1, 'uint32=>uint32');
-            fChannelArraySize = 8 * (fNumChannels + 1);
-            
-            fseek(aFileID, 0, 'eof');
-            fEOF = ftell(aFileID);
-            
-            fPostNotesGap = LegacySupport.INITIAL_HEADER_LENGTH - (aEntriesStart + Note.SIZE);
-            fPostChannelsGap = fDataStart - (LegacySupport.INITIAL_HEADER_LENGTH + BlockVectorHeader.SIZE +fChannelArraySize);
-            
-            fEntryRecords = EntryRecord(EntryRecordID.NotesArray, Note.SIZE);
-            
-            fEntryRecords = [fEntryRecords EntryRecord(EntryRecordID.Skip, fPostNotesGap)];
-            
-            fEntryRecords = [fEntryRecords EntryRecord(EntryRecordID.BlockVectorHeader, BlockVectorHeader.SIZE)];
-            
-            fEntryRecords = [fEntryRecords EntryRecord(EntryRecordID.ChannelArray, fChannelArraySize)];
-            
-            fEntryRecords = [fEntryRecords EntryRecord(EntryRecordID.Skip, fPostChannelsGap)];
-            
-            fEntryRecords = [fEntryRecords EntryRecord(EntryRecordID.BlockVectorData, fEOF - fDataStart)];
-            
-            fEntryRecords = [fEntryRecords EntryRecord(EntryRecordID.Terminate, 0)];
-            
-        end
-        
-        function [fType, fData, fChannelMapping, fHeader] = GenerateRolstonEntries(aFileID, aExtension)
-            fChannelMapping = ChannelArray.version_0_1_channel_array();
-            
-            fseek(aFileID, 0, 'eof');
-            fEOF = ftell(aFileID);
-            fseek(aFileID, 0, 'bof');
-            
-            if strcmp(aExtension, '.raw')
-                % Read header
-               
-                fType = BlockVectorDataType.Raw_v1;
-                fNumChannels       = fread(aFileID, 1, 'uint16');
-                fSamplingFrequency = fread(aFileID, 1, 'uint32');
-                fread(aFileID, 1, 'uint16');  %Gain
-                
-                coefficients = fread(aFileID, LegacySupport.NUM_COEFFICIENTS, 'double');
-                fVoltageScale = coefficients(2) / 1200;
-                
-                fExperimentStartTime = DateTime(aFileID);
-                fNumSamples = 1;
-                
-            elseif strcmp(aExtension, '.spk')
-                error('LegacySupport:Unsupported', ...
-                    'File appears to be a deprecated AxIS v0.0 spike file, this type of file is not supported');            
-            else
-                error('LegacySupport:extension', ...
-                    'File appears to be a deprecated AxIS v0.0 file, but filename does not end with .raw or .spk');
-            end
-            
-            fDataStart = ftell(aFileID);
-            
-            fHeader = BlockVectorHeader.Generate(...
-                aFileID, ...
-                fSamplingFrequency, ...
-                fVoltageScale, ...
-                fExperimentStartTime, ...
-                fExperimentStartTime, ...
-                fDataStart, ...
-                fNumChannels, ...
-                fNumSamples, ...
-                0);
-            
-            fData = EntryRecord(EntryRecordID.BlockVectorData, fEOF - fDataStart);
-            fseek(aFileID, double(fDataStart), 'bof');
-            fData = BlockVectorData(fData, aFileID);
-            
-        end
-    end
-end
-

+ 0 - 270
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/LoadArgs.m

@@ -1,270 +0,0 @@
-classdef LoadArgs < handle
-    %LOADARGS parser for file loading arguments
-    
-    properties (GetAccess = private, Constant = true)
-        wellVal = 1;
-        electrodeVal = 2;
-        timespanVal = 3;
-        dimensionsVal = 4;
-    end
-    
-    properties (GetAccess = public, Constant = true)
-        ByPlateDimensions = 1;
-        ByWellDimensions = 3;
-        ByElectrodeDimensions = 5;
-    end
-    
-    properties (GetAccess = public, SetAccess = private)
-        Well
-        Electrode
-        Timespan
-        Dimensions
-    end
-    
-    methods (Static)
-        
-        function this = LoadArgs(argin)
-            % Internal support function for AxisFile Construction
-            % loadAxISFileParseArgs Parses arguments for file readers
-            %
-            %  Legal forms:
-            %     LoadArgs();
-            %     LoadArgs(well);
-            %     LoadArgs(electrode);
-            %     LoadArgs(well, electrode);
-            %     LoadArgs(timespan);
-            %     LoadArgs(well, timespan);
-            %     LoadArgs(electrode, timespan);
-            %     LoadArgs(well, electrode, timespan);
-            %     LoadArgs(dimensions);
-            %     LoadArgs(well, dimensions);
-            %     LoadArgs(electrode, dimensions);
-            %     LoadArgs(well, electrode, dimensions);
-            %     LoadArgs(timespan, dimensions);
-            %     LoadArgs(well, timespan, dimensions);
-            %     LoadArgs(electrode, timespan, dimensions);
-            %     LoadArgs(well, electrode, timespan, dimensions);
-            %
-            %  Required arguments:
-            %    filename    Pathname of the file to load
-            %
-            %  Optional arguments:
-            %    well        String listing which wells (in a multiwell file) to load.
-            %                Format is a comma-delimited string with whitespace ignored, e.g.
-            %                'A1, B2,C3' limits the data loaded to wells A1, B2, and C3.
-            %                Also acceptable: 'all' to load all wells.
-            %                If this parameter is omitted, all wells are loaded.
-            %                For a single-well file, this parameter is ignored.
-            %
-            %    electrode   Which electrodes to load.  Format is either a comma-delimited string
-            %                with whitespace ignored (e.g. '11, 22,33') or a single channel number;
-            %                that is, a number, not part of a string.
-            %                Also acceptable: 'all' to load all channels and 'none', '-1', or -1
-            %                to load no data (returns only header information).
-            %                If this parameter is omitted, all channels are loaded.
-            %
-            %    timespan    Span of time, in seconds, over which to load data.  Format is a two-element
-            %                array, [t0 t1], where t0 is the start time and t1 is the end time and both
-            %                are in seconds after the first sample in the file.  Samples returned are ones
-            %                that were taken at time >= t0 and <= t1.  The beginning of the file
-            %                is at 0 seconds.
-            %                If this parameter is omitted, the data is not filtered based on time.
-            %
-            %    dimensions  Preferred number of dimensions to report the waveforms in.
-            %                Value must be a whole number scalar, and only certain values are allowed:
-            %
-            %                dimensions = 1 -> ByPlate: returns a vector of Waveform objects, 1 Waveform
-            %                        s          per signal in the plate
-            %                dimensions = 3 -> ByWell: Cell Array of vectors of waveform 1 Waveform per signal
-            %                                  in the electrode with size (well Rows) x (well Columns)
-            %                dimensions = 5 -> ByElectrode: Cell Array of vectors of waveform 1 Waveform per .
-            %                                  signal in the electrode with size (well Rows) x (well Columns) x
-            %                                  (electrode Columns) x (electrode Rows)
-            this.Well = [];
-            this.Electrode = [];
-            this.Timespan = [];
-            this.Dimensions = [];
-            
-            fLastArg = [];
-            
-            fNumArgs = length(argin);
-            
-            if fNumArgs > 4
-                error('LoadArgs:excessArgs', 'Too many arguments specified');
-            end
-            
-            for i = 1:fNumArgs
-                fCurrentArg = argin{i};
-                
-                if isempty(fCurrentArg) %ignore empty args
-                    continue
-                end
-                
-                if isempty(fLastArg)
-                    fParseAsWell = LoadArgs.canonical_well_electrode_argument(fCurrentArg, LoadArgs.wellVal);
-                    if ~isempty(fParseAsWell)
-                        % Argument is a well
-                        this.Well = fParseAsWell;
-                        fLastArg = LoadArgs.wellVal;
-                        continue;
-                    end
-                end
-                
-                if isempty(fLastArg) || fLastArg == LoadArgs.wellVal
-                    fParseAsElectrode = LoadArgs.canonical_well_electrode_argument(fCurrentArg, LoadArgs.electrodeVal);
-                    if ~isempty(fParseAsElectrode)
-                        % Argument is an electrode
-                        this.Electrode = fParseAsElectrode;
-                        fLastArg = LoadArgs.electrodeVal;
-                        continue;
-                    end
-                end
-                
-                if isempty(fLastArg) || fLastArg == LoadArgs.wellVal || fLastArg == LoadArgs.electrodeVal
-                    fParseAsTimespan = LoadArgs.canonical_timespan_argument(fCurrentArg);
-                    if ~isempty(fParseAsTimespan)
-                        % Argument is a timespanVal
-                        if isnumeric(fParseAsTimespan) && fParseAsTimespan(2) < fParseAsTimespan(1)
-                            error('load_AxIS_file_parse_args:invalidTimespan', 'Invalid timespan argument: t1 < t0');
-                        end
-                        
-                        this.Timespan = fParseAsTimespan;
-                        fLastArg = LoadArgs.timespanVal;
-                        continue;
-                    end
-                end
-                
-                if isempty(fLastArg) || i == length(argin)
-                    if isscalar(fCurrentArg)
-                        switch fCurrentArg
-                            case { LoadArgs.ByPlateDimensions, ...
-                                   LoadArgs.ByWellDimensions, ...
-                                   LoadArgs.ByElectrodeDimensions} 
-                                this.Dimensions = fCurrentArg;
-                            otherwise
-                                this.Dimensions = [];
-                        end
-                        fLastArg = LoadArgs.dimensionsVal;
-                        continue;
-                    end
-                end
-                
-                % If we get here, the argument couldn't be parsed
-                error('load_AxIS_file_parse_args:invalidArg', ['Invalid argument #' num2str(i+1) ' to load_AxIS_file']);
-            end
-            
-            if isempty(this.Well)
-                % Default: all wells
-                this.Well = 'all';
-            end
-            
-            if isempty(this.Electrode)
-                % Default: all electrodes
-                this.Electrode = 'all';
-            end
-            
-            if isempty(this.Timespan)
-                % Default: all time
-                this.Timespan = 'all';
-            end
-            
-        end
-        
-    end
-    
-    methods(Static, Access = private)
-        
-        function aParseOutput = canonical_well_electrode_argument(aArgument, type)
-            
-            DELIMITER = ',';
-            aParseOutput = [];
-            
-            % Error-check argument type
-            if isa(aArgument, 'LoadArgs') && ~(LoadArgs.wellVal || LoadArgs.electrodeVal)
-                error('canonical_well_electrode_argument:invalidArgType', 'Internal error: Invalid argument type for parsing');
-            end
-            
-            % Special cases
-            if strcmpi(aArgument, 'all')
-                aParseOutput = 'all';
-            elseif type == LoadArgs.electrodeVal && isscalar(aArgument) && aArgument == -1
-                aParseOutput = 'none';
-            elseif type == LoadArgs.electrodeVal && isscalar(aArgument) && isnumeric(aArgument) && aArgument > 10
-                aParseOutput = [floor(aArgument/10) mod(aArgument, 10) ];
-            elseif ischar(aArgument)
-                
-                if type == LoadArgs.electrodeVal && ( strcmp(strtrim(aArgument), '-1') || strcmpi(aArgument, 'none') )
-                    aParseOutput = 'none';
-                    return;
-                end
-                
-                
-                % Convert well names to upper case
-                fCanonicalArg = upper(aArgument);
-                
-                % Strip whitespace
-                fCanonicalArg(isspace(fCanonicalArg)) = [];
-                
-                % Is it valid?
-                while ~isempty(fCanonicalArg)
-                    if   length(fCanonicalArg) >= 2 &&  ...
-                            ( (type == LoadArgs.wellVal)      && isletter(fCanonicalArg(1))    && LoadArgs.isdigit_ax(fCanonicalArg(2))) || ...
-                            ( (type == LoadArgs.electrodeVal) && LoadArgs.isdigit_ax(fCanonicalArg(1))  && LoadArgs.isdigit_ax(fCanonicalArg(2)))
-                        
-                        % Valid format
-                        if type == LoadArgs.wellVal
-                            % Format is Letter then Number, where letter is the row and number is the column
-                            % Build array of column, row
-                            [nextWell, fCanonicalArg] = strtok(fCanonicalArg, ',');
-                            aParseOutput = [ aParseOutput ; ...
-                                             str2num(nextWell(2:end)) (char(nextWell(1)) - char('A') + 1)];
-                        else
-                            % Format is Number then Number, where the first is the column and the second is the row
-                            % Build array of column, row
-                            [nextWell, fCanonicalArg] = strtok(fCanonicalArg, ',');
-                            aParseOutput = [ aParseOutput ; ...
-                                             str2num(nextWell(1)) str2num(nextWell(2:end))];
-                        end
-                        
-                        % Look for the next delimiter
-                        if length(fCanonicalArg) >= 1
-                            if fCanonicalArg(1) == DELIMITER
-                                fCanonicalArg = fCanonicalArg(2:end);
-                            else
-                                % Invalid next character - not a delimiter
-                                aParseOutput = [];
-                                break;
-                            end
-                        end
-                    else
-                        % Invalid Well ID
-                        aParseOutput = [];
-                        break;
-                    end
-                end
-            end
-        end
-        
-        function aParseOutput = canonical_timespan_argument(aArgument)
-            
-            if isvector(aArgument) && length(aArgument) == 2 && isnumeric(aArgument)
-                aParseOutput = aArgument(:);
-            else
-                aParseOutput = [];
-            end
-            
-        end
-        
-        function t = isdigit_ax(c)
-            %ISDIGIT True for decimal digits.
-            %
-            %   For a string C, ISDIGIT(C) is 1 for decimal digits and 0 otherwise.
-            %
-            narginchk(1, 1);
-            
-            t = ischar(c) & ( '0' <= c ) & ( c <= '9' );
-        end
-        
-    end
-end
-

+ 0 - 82
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/Note.m

@@ -1,82 +0,0 @@
-classdef Note < Entry
-    %Note Container class for Axis File notes
-    %
-    %   Investigator:   Text data taken from 'Investigator' field of the Axis
-    %                   GUI
-    %
-    %   ExperimentID:   Text data taken from 'Experiment ID' field of the Axis
-    %                   GUI
-    %
-    %   Description:    Text data taken from 'Description' field of the Axis
-    %                   GUI
-    %
-    %   Revision:       Number of revisions this note has experienced 
-    %
-    %   RevisionDate:   Date this note was last revised (See DateTime.m) 
-    
-    properties (Constant = true, GetAccess = public)
-        SIZE = 618;
-    end
-    
-    properties (Constant = true, GetAccess = private)
-        %Constants for offsets and sizes in binary notes entries.
-        ExperimentIDOffset = 50;
-        DescriptionOffset = 100;
-        RevisionOffset = 600;
-        InvestigatorLength = 50;
-        ExperimentIDLength = 50;
-        DescriptionLength = 500;
-    end
-    
-    properties (GetAccess = public, SetAccess = private)
-        Investigator
-        ExperimentID
-        Description
-        Revision
-        RevisionDate
-    end
-    
-    methods
-        function this = Note(aEntryRecord, aFileID)
-            this = this@Entry(aEntryRecord, int64(ftell(aFileID)));
-            
-            if(nargin == 0)
-                return
-            end
-            
-            this.Investigator = deblank(fread(aFileID, Note.InvestigatorLength, '*char').');
-            % strip '\r' characters so that lines aren't double-spaced
-            this.Investigator(this.Investigator==13)=[];
-            
-            fseek(aFileID, this.Start + Note.ExperimentIDOffset, 'bof');
-            this.ExperimentID = deblank(fread(aFileID, Note.ExperimentIDLength, '*char').');
-            % strip '\r' characters so that lines aren't double-spaced
-            this.ExperimentID(this.ExperimentID==13)=[];
-            
-            fseek(aFileID, this.Start + Note.DescriptionOffset, 'bof');
-            this.Description = deblank(fread(aFileID, Note.DescriptionLength, '*char').');
-            % strip '\r' characters so that lines aren't double-spaced
-            this.Description(this.Description==13)=[];
-            
-            fseek(aFileID, this.Start + Note.RevisionOffset, 'bof');
-            this.Revision = fread(aFileID, 1, 'uint32=>uint32');
-            this.RevisionDate = DateTime(aFileID);
-            
-            if(ftell(aFileID) ~= (this.Start + this.EntryRecord.Length))
-                error('Unexpected BlockVectorHeader length')
-            end
-            
-        end
-    end
-    
-    methods(Static = true)
-        function array = ParseArray(aEntryRecord, aFileID)
-            fCount = aEntryRecord.Length / Note.SIZE;
-            array = Note.empty(0,fCount);
-            for i = 1 : fCount
-                fEntryRecord = EntryRecord(EntryRecordID.NotesArray, Note.SIZE);
-                array(i) = Note(fEntryRecord, aFileID);
-            end
-        end
-    end
-end

+ 0 - 52
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/Spike_v1.m

@@ -1,52 +0,0 @@
-classdef Spike_v1 < Waveform
-    %SPIKE_V1: An extension of Waveform that represents a spike recorded by
-    %          spike detector in Axis.
-    %
-    %   TriggerSampleOffset: Offset (in samples) from the start of the
-    %                        waveform where the spike detector was
-    %                        triggered
-    %
-    %   StandardDeviation:   RMS voltage value of the signal noise at the
-    %                        time the spike was caputred
-    %
-    %   ThresholdMultiplier: Multiplier(if applicable) of the RMS Noise that was 
-    %                        used as the trigger voltage for this spike
-    %
-    
-    
-    properties(GetAccess = public, Constant = true)
-        LOADED_HEADER_SIZE = 30;
-    end
-    
-    properties (GetAccess = public, SetAccess = private)
-        TriggerSampleOffset
-        StandardDeviation
-        ThresholdMultiplier
-    end
-    
-    methods
-        
-        function this = Spike_v1( ...
-                aChannel, ...
-                aStart, ...
-                aData, ...
-                aSource,  ...
-                aTriggerSampleOffset, ...
-                aStandardDeviation, ...
-                aThresholdMultiplier)
-            if(nargin == 0)
-                return;
-            end
-            
-            this.Channel = aChannel;
-            this.Start = aStart;
-            this.Data = aData;
-            this.Source = aSource;
-            this.TriggerSampleOffset = aTriggerSampleOffset;
-            this.StandardDeviation = aStandardDeviation;
-            this.ThresholdMultiplier = aThresholdMultiplier;
-        end
-    end
-    
-end
-

+ 0 - 85
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/Waveform.m

@@ -1,85 +0,0 @@
-classdef Waveform
-    %WAVEFORM Container for single dimensional recorded sample data
-    %
-    %   Channel:    Source Location of the waveform
-    %
-    %   Start:      Time(In Seconds) of Recording Start
-    %
-    %   Data:       Sample data
-    %
-    %   Source:     BlockVectorDataSet that contains this Waveform
-    
-    properties(GetAccess = public, SetAccess = protected)
-        Channel;
-        Start;
-        Data;
-        Source;
-    end
-    
-    methods
-        
-        function this = Waveform(aChannel, aStart, aData, aSource)
-            
-            if(nargin == 0)
-                return;
-            end
-            
-            if(~isa(aChannel,'ChannelMapping'))
-                error(['Waveform: Unexpected Argument for aChannel: ' aChannel]);
-            end
-            
-            if(~isa(aSource,'BlockVectorSet'))
-                error(['Waveform: Unexpected Argument for aSource: ' aSource]);
-            end
-            
-            this.Channel = aChannel;
-            this.Start = aStart;
-            this.Data = aData;
-            this.Source = aSource;
-        end
-        
-        function [timeData, voltageData] = GetTimeVoltageVector(this)
-            %GetTimeVoltageVector: Returns a vector for time and voltage
-            % for this waveform in a single call
-            timeData = this.GetTimeVector();
-            voltageData = this.GetVoltageVector();
-        end
-        
-        function voltageData = GetVoltageVector(this)
-            % GetTimeVector: returns a voltage vector for this waveform based
-            % on the uncasted sample data (Stored as int16) and the source
-            % header's specified voltage scale 
-            %
-            % If this Method is called on an array of waveforms, the
-            % lengths of the waveforms MUST agree
-            fData = double([this(:).Data]);
-            fSource = [this(:).Source];
-            fHeader = [fSource(:).Header];
-            fVoltageScale = [fHeader(:).VoltageScale];
-            voltageData = fData * diag(fVoltageScale);
-        end
-        
-        function timeData = GetTimeVector(this)
-            % GetTimeVector: returns a time vector for this waveform based
-            % on the Start time, Length of the data, and the Sampling
-            % Frequency of the source header
-            %
-            % If this Method is called on an array of waveforms, the
-            % lengths of the waveforms MUST agree
-            fSource = [this(:).Source];
-            fHeader = [fSource(:).Header];
-            fSamplingPeriod = 1./[fHeader(:).SamplingFrequency];
-            
-            timeData = repmat((0 : (length(this(1).Data) - 1))', 1,length(this));
-            timeData = timeData * diag(fSamplingPeriod);
-            
-            fStart = ones(size(timeData));
-            fStart = fStart * diag([this(:).Start]);
-            
-            timeData = timeData + fStart;
-        end
-        
-    end
-    
-end
-

+ 0 - 156
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/calc_spike_rate.m

@@ -1,156 +0,0 @@
-  %
-  %  calc_spike_rate(aInputFile, aOutputFile, aIntervalSeconds, aStartSeconds, aEndSeconds)
-  %   
-  %   Required Parameters
-  %     aInputFile        path and name of the input spike file
-  %     aOutputFile       path and name of the spike rate file to write (in CSV format)
-  %
-  %   Optional Parameters
-  %     aStartSeconds     time you want to start from in the file, in seconds (default 0)
-  %     aEndSeconds       time you want to stop, in seconds (default Inf, end of file)
-  %     aIntervalSeconds  interval that will be used between aStartSeconds and aEndSeconds (default 60)
-  %
-  %   Note: Parameters must be specified in order.  If optional parameters are omitted,
-  %         the default is used, as follows:
-  %
-  %     calc_spike_rate(aInputFile, aOutputFile)
-  %         => uses defaults for aIntervalSeconds, aStartSeconds, aEndSeconds
-  %
-  %     calc_spike_rate(aInputFile, aOutputFile, aIntervalSeconds)
-  %         => uses defaults for StartSeconds, aEndSeconds
-  %
-  %     calc_spike_rate(aInputFile, aOutputFile, aIntervalSeconds, aStartSeconds)
-  %         => uses defaults for aEndSeconds
-  %
-  %
-  %  The script will divide the time between aStartSeconds and aEndSeconds into N intervals,
-  %  where N = aEndSeconds - aStartSeconds) / aIntervalSeconds, rounded up, and output
-  %  spike counts for the intervals:
-  %
-  %  [aStartSeconds,                           aStartSeconds +   aIntervalSeconds)
-  %  [aStartSeconds +       aIntervalSeconds,  aStartSeconds + 2*aIntervalSeconds)
-  %  [aStartSeconds +     2*aIntervalSeconds,  aStartSeconds + 3*aIntervalSeconds)
-  %  ....
-  %  [aStartSeconds + (N-1)*aIntervalSeconds, aStartSeconds +  N*aIntervalSeconds)
-  %
-
-function calc_spike_rate(aInputFile, aOutputFile, aIntervalSeconds, aStartSeconds, aEndSeconds)
-
-    ELECTRODE_ROWS = 8;
-    ELECTRODE_COLS = 8;
-    NUM_ELECTRODES = ELECTRODE_ROWS * ELECTRODE_COLS;
-
-    % Handle default arguments:
-    % aIntervalSeconds = 60
-    % aStartSeconds = 0
-    % aEndSeconds = Inf
-    if nargin < 3
-        aIntervalSeconds = 60;
-    end
-    
-    if nargin < 4
-        aStartSeconds = 0;
-    end
-    
-    if nargin < 5
-        aEndSeconds = Inf;
-    end
-    
-    if nargin > 5
-        error('calc_spike_rate:tooManyParameters', ['calc_spike_rate: Too many input parameters']);
-    end
-
-    if ischar(aInputFile)
-        disp(['Loading spikes from file ' aInputFile]);
-        
-        fSpikeData = load_AxIS_file(aInputFile, [aStartSeconds aEndSeconds]);
-    else
-        error('calc_spike_rate:invalidFileName', ['calc_spike_rate: Invalid file name: ' aInputFile]);
-    end
-    
-    if ~strcmp(fSpikeData.fileType, 'spike') 
-        if strcmp(fSpikeData.fileType, 'spike-beta')
-            % This is a beta-format spike file.  Not currently supported by calc_spike_rate.
-            error('calc_spike_rate:betaFormat', ['Beta-format spike file not supported: ' aInputFile]);
-        else
-            % File was not a spike file
-            error('calc_spike_rate:invalidSpikeFile', ['Invalid spike file format in file ' aInputFile]);
-        end
-    end
-    
-    % If aEndSeconds is infinite, we want to read until the end of the file, but we can't leave
-    % it as Inf, because then we'll try to create a table with an infinite number of rows.  Instead,
-    % base it on the last spike in the file.
-    if aEndSeconds == Inf
-        aEndSeconds = (fSpikeData.spikes(end).startingSample + fSpikeData.spikes(end).triggerSampleOffset) / ...
-                      fSpikeData.samplingFrequency;  
-    end
-    
-    fNumIntervals = ceil((aEndSeconds - aStartSeconds) / aIntervalSeconds);
-    
-    fSpikeCounts = zeros(fNumIntervals, ELECTRODE_ROWS, ELECTRODE_COLS);
-    
-    for i=1:length(fSpikeData.spikes)
-        % Iterate over each loaded spike and determine whether or where it falls in the spike
-        % rate table.
-        fSpikeTime = (fSpikeData.spikes(i).startingSample + fSpikeData.spikes(i).triggerSampleOffset) / ...
-                     fSpikeData.samplingFrequency;
-        fSpikeInterval = floor((fSpikeTime - aStartSeconds) / aIntervalSeconds);
-        
-        if fSpikeInterval < 0
-            % This spike was too early to be counted
-            continue;
-        elseif fSpikeInterval >= fNumIntervals
-            % This spike was too late to be counted.  Since the file is ordered by spike time,
-            % we can stop reading.
-            break;
-        else
-            % we have the channel number ranging from 11 to 88 (this is more a label than a number)
-            % Decode it:
-            fChannelY = floor(fSpikeData.spikes(i).channel / 10);
-            fChannelX = mod(fSpikeData.spikes(i).channel, 10);
-            %fChannelIndex = fChannelX + (fChannelY - 1) * ELECTRODE_COLS;
-
-            fSpikeCounts(fSpikeInterval + 1, fChannelY, fChannelX) =  ...
-                    fSpikeCounts(fSpikeInterval + 1, fChannelY, fChannelX) + 1;
-        end
-    end
-    
-    % Make sure file doesn't exist so we don't overwrite it
-    if exist(aOutputFile, 'file')
-        error('calc_spike_rate:outputFileExists', ['Output file already exists: ' aOutputFile]);
-    end
-    
-    % Write spike rates in CSV format
-    fid = fopen(aOutputFile, 'w');
-    if fid == -1
-        % error opening output file
-        error('calc_spike_rate:errorOpeningOutputFile', ['Couldn''t write to output file ' aOutputFile]);
-    end
-    
-    fprintf(fid, 'Interval Start (S),Interval End (S)');
-    for i=1:ELECTRODE_ROWS
-        for j=1:ELECTRODE_COLS
-            fprintf(fid, ',Channel %d%d', i, j);
-        end
-    end
-    
-    fprintf(fid, '\n');
-    
-    for fInterval=1:fNumIntervals
-        fprintf(fid, '%f,%f', aStartSeconds + (fInterval - 1) * aIntervalSeconds, ...
-                              aStartSeconds + fInterval * aIntervalSeconds);
-                              
-        for i=1:ELECTRODE_ROWS
-            for j=1:ELECTRODE_COLS
-                fprintf(fid, ',%d', fSpikeCounts(fInterval, i, j));
-            end
-        end
-        
-        fprintf(fid, '\n');
-    end
-    
-    fclose(fid);
-    
-    disp(['Finished writing ' aOutputFile]);
-

+ 0 - 42
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/Axion MATLAB Files/load_AxIS_file.m

@@ -1,42 +0,0 @@
-%load_AxIS_file [[DEPRECATED]] reads raw recording files created by AxIS
-%
-%  Legal forms:
-%     data = load_AxIS_file(filename);
-%     data = load_AxIS_file(filename, well);
-%     data = load_AxIS_file(filename, electrode);
-%     data = load_AxIS_file(filename, well, electrode);
-%     data = load_AxIS_file(filename, timespan);
-%     data = load_AxIS_file(filename, well, timespan);
-%     data = load_AxIS_file(filename, electrode, timespan);
-%     data = load_AxIS_file(filename, well, electrode, timespan);
-%
-%  Required arguments:
-%    filename    Pathname of the file to load
-%
-%  Optional arguments:
-%    well        String listing which wells (in a multiwell file) to load.
-%                Format is a comma-delimited string with whitespace ignored, e.g.
-%                'A1, B2,C3' limits the data loaded to wells A1, B2, and C3.
-%                Also acceptable: 'all' to load all wells.
-%                If this parameter is omitted, all wells are loaded.
-%                For a single-well file, this parameter is ignored.
-%
-%    electrode   Which electrodes to load.  Format is either a comma-delimited string
-%                with whitespace ignored (e.g. '11, 22,33') or a single channel number;
-%                that is, a number, not part of a string.
-%                Also acceptable: 'all' to load all channels and 'none', '-1', or -1
-%                to load no data (returns only header information).
-%                If this parameter is omitted, all channels are loaded.
-%
-%    timespan    Span of time, in seconds, over which to load data.  Format is a two-element
-%                array, [t0 t1], where t0 is the start time and t1 is the end time and both
-%                are in seconds after the first sample in the file.  Samples returned are ones
-%                that were taken at time >= t0 and <= t1.  The beginning of the file
-%                is at 0 seconds.
-%                If this parameter is omitted, the data is not filtered based on time.
-%
-
-function aData = load_AxIS_file(aFileName, varargin)
-    aData = AxisFile(aFileName).DataSets(1).load_as_legacy_struct(varargin);
-end
-

BIN
Codes/MATLAB spike detection/BatchAnalyser_1.2/FileInput/ooo.mat


+ 0 - 58
Codes/MATLAB spike detection/ReadAxionChannelnew.m

@@ -1,58 +0,0 @@
-function [error,data,duration, chlabel] = ReadAxionChannel(obj)
-            
-            %well does not exist jump to another and display...might be not
-            %recorded or so
-            %jump to the next
-            %if channel (single)does not exist then display channel not recorded 
-            %next
-            data = []; %there in Meeri's code to return at least something with e.g. error=1
-            %error = 0;
-            %duration = [];
-            m_well=strcat(char(64+obj.last_well_row+1),num2str(obj.last_well_col+1));
-            fid = H5F.open(obj.getCurrentFile());
-            gid = H5G.open(fid,['/Data/' m_well]);
-            while ~H5L.exists(gid,'slink','H5P_DEFAULT')
-                fprintf([mwell 'seems to be excluded\n']);
-                obj = obj.JumpNextWell;
-                m_well=strcat(char(64+obj.last_well_row+1),num2str(obj.last_well_col+1));
-                gid = H5G.open(fid,['/Data/' m_well]);
-            end
-            %m_well=strcat(char(64+obj.last_well_row+1),num2str(obj.last_well_col+1));
-            m_ch=strcat(num2str(obj.last_ch_col+1),num2str(obj.last_ch_row+1));
-            chlabel = strcat(m_well,'_',m_ch); % which well which electrode
-            disp(['now reading: ' chlabel]);
-            try 
-                
-                data = h5read(obj.getCurrentFile(),['/Data/' m_well '/' m_ch]);
-                %if isempty(obj.duration)
-                    %duration = length(data)/obj.samplerate;
-                    %obj.duration = duration;
-                %else
-                    %duration = obj.duration;%better when open file?????
-                %end
-                error = 0;
-            catch %err
-                error = 1;
-                InactiveChannels=h5read(obj.getCurrentFile(), '/DataInfo/InactiveChannels');
-                if any(contains(InactiveChannels, chlabel)) 
-                    disp(['Channel' ' ' chlabel ' ' 'is inactive, it is not recorded in the initial analysed file.'])
-                else
-                    disp(['Smth wrong with' ' ' chlabel ' ' 'channel reading!']); %ADDED
-                end
-          
-            end 
-        end
-        %%
-function obj = JumpNextWell(obj)        
-    if obj.final_well_col-1 <= obj.last_well_col 
-        obj.last_well_col = obj.first_well_col-1;
-        if obj.final_well_row-1 <= obj.last_well_row
-            disp('All channels have been read from!');
-            obj.file_finished = 1;
-        else
-            obj.last_well_row = obj.last_well_row+1;
-        end
-    else
-        obj.last_well_col = obj.last_well_col+1;
-    end
-end

+ 0 - 188
Codes/MATLAB spike detection/detect_spikes.m

@@ -1,188 +0,0 @@
-function [spikes,thr,thrmax, noise_std_detect, noise_std_sorted, index] = amp_detect(x,handles)
-% Detect spikes with amplitude thresholding. Uses median estimation.
-% Detection is done with filters set by fmin_detect and fmax_detect. Spikes
-% are stored for sorting using fmin_sort and fmax_sort. This trick can
-% eliminate noise in the detection but keeps the spikes shapes for sorting.
-
-%The initial (only amp thresholding) version was taken by Meeri from
-%some ?? Wave Clus PROGRAM Get_spikes ?? or so
-%Stationary Wavelet Transform Teager Energy Operator block is added by Andrey.
-%Workflow: %1. Amplitude thresholding detects spikes in the prefiltered signal with TCF=4.5
-           %2. The number of the detected spikes is fed into SWTTEO algorithm
-           %3. The spike detected by both algorithms are considered as True Positives (within error window)        
-               
-x = double(x);
-
-% Depends:
-% toolbox             :  \signal\signal\ellip.m
-% other               :  filtfilt
-% other               :  fix_filter
-% other               :  int_spikes
-%
-% 090814 korjattu ohi-indeksointi lis??m?ll? tarkistukset spike storing
-% osioon
-
-sr=handles.par.sr;
-w_pre=handles.par.w_pre;
-w_post=handles.par.w_post;
-ref=handles.par.ref;
-detect = handles.par.detection;
-stdmin = handles.par.stdmin;
-stdmax = handles.par.stdmax;
-fmin_detect = handles.par.detect_fmin;
-fmax_detect = handles.par.detect_fmax;
-fmin_sort = handles.par.sort_fmin;
-fmax_sort = handles.par.sort_fmax;
-index1 = [];
-spikes = [];
-thr = [];
-thrmax = [];
-noise_std_detect = [];
-noise_std_sorted = [];
-
-% HIGH-PASS FILTER OF THE DATA
-
-xf=zeros(length(x),1);
-if exist('ellip')                         %Checks for the signal processing toolbox
-    [b,a]=ellip(2,0.1,40,[fmin_detect fmax_detect]*2/sr);
-    xf_detect=filtfilt(b,a,x);
-    [b,a]=ellip(2,0.1,40,[fmin_sort fmax_sort]*2/sr);
-    xf=filtfilt(b,a,x);
-else
-    xf=fix_filter(x);                   %Does a bandpass filtering between [300 3000] without the toolbox.
-    xf_detect = xf;
-end
-lx=length(xf);
-
-%clear x; MOVED TO THE END 
-
-noise_std_detect = median(abs(xf_detect))/0.6745;
-noise_std_sorted = median(abs(xf))/0.6745;
-thr = stdmin * noise_std_detect;        %thr for detection is based on detected settings.
-thrmax = stdmax * noise_std_sorted;     %thrmax for artifact removal is based on sorted settings.
-
-% LOCATE SPIKE TIMES
-switch detect
-    case 'pos'
-        nspk = 0;
-        xaux = find(xf_detect(w_pre+2:end-w_post-2) > thr) +w_pre+1;
-        xaux0 = 0;
-        for i=1:length(xaux)
-            if xaux(i) >= xaux0 + ref
-                [maxi, iaux]=max((xf(xaux(i):xaux(i)+floor(ref/2)-1)));    %introduces alignment
-                nspk = nspk + 1;
-                index1(nspk) = iaux + xaux(i) -1;
-                xaux0 = index1(nspk);
-            end
-        end
-    case 'neg'
-        nspk = 0;
-        xaux = find(xf_detect(w_pre+2:end-w_post-2) < -thr) +w_pre+1;
-        xaux0 = 0;
-        for i=1:length(xaux)
-            if xaux(i) >= xaux0 + ref
-                [maxi, iaux]=min((xf(xaux(i):xaux(i)+floor(ref/2)-1)));    %introduces alignment
-                nspk = nspk + 1;
-                index1(nspk) = iaux + xaux(i) -1;
-                xaux0 = index1(nspk);
-            end
-        end
-    case 'both'
-        nspk = 0;
-        % palauttaa ei-nollat ja lis?? niihin w_pre+1
-        % absoluuttisista arvoista
-        % jotka xf_detectiss? v?lill? w_pre+2:end-w_post-2
-        xaux = find(abs(xf_detect(w_pre+2:end-w_post-2)) > thr) +w_pre+1;
-        xaux0 = 0;
-        for i=1:length(xaux)
-            if xaux(i) >= xaux0 + ref
-                [maxi, iaux]=max(abs(xf(xaux(i):xaux(i)+floor(ref/2)-1)));    %introduces alignment
-                nspk = nspk + 1;
-                if isempty(iaux)
-                    iaux = 0;
-                end
-                index1(nspk) = iaux + xaux(i) -1; % heitt?? virheilmon: index sis?lt?? spiketimet, maxi ja iaux tyhji?
-                xaux0 = index1(nspk);
-            end
-        end
-end
-%some values for SWTTEO
-in.M = xf_detect;
-in.SaRa = sr;
-%Parameters
-params.method = 'numspikes';
-params.numspikes = numel(index1);
-params.filter = 0;
-if sr==10000
-    params.wavLevel=2;
-elseif sr==12500
-    params.wavLevel=3;
-elseif sr==25000
-    params.wavLevel=4;
-elseif sr==50000
-    params.wavLevel=5;
-else
-    error('Is it smth else than MCS or Axion? I know only sampling frequencies 10000, 12500, 25000 and 50000!')
-end
-
-%Getting result for the SET NUMSPIKES from SWTTEO algorithm
-index2= SWTTEO(in,params);
-
-%Selecting the spikes detected by both algorithms within some []error
-%interval
-errortime=ceil(2e-4*sr);%(in samples)
-
-check=zeros(1, params.numspikes);
-for i=1:params.numspikes
-    check(i)=any(abs(index2(i)-index1)<=errortime);
-end
-
-index=index2.*check;
-index=index(index>0);
-index=sort(index);
- 
-nspk=numel(index);
-% SPIKE STORING (with or without interpolation)
-% tehd??n vain jos spikej? indexiss?!
-if ~isempty(index)
-    ls=w_pre+w_post;
-    spikes=zeros(nspk,ls+4);
-    xf=[xf zeros(1,w_post)];              % xf ja zeros ei yhteensopivia
-    parfor i=1:nspk                          %Eliminates artifacts
-        if max(abs( xf(index(i)-w_pre:index(i)+w_post) )) < thrmax
-            % jos piikin indeksi datan vika tai tokavika piste niin aiheuttaa
-            % ohi indeksoinnin, eik? piikkimuotokaan ole kokonainen
-            % eli eliminoidaan artifactina
-            if ~(index(i)+w_post+2 > length(xf))
-                % lis?t??n nollaborderia, koska piikki aivan datan alussa
-                if index(i)-w_pre-1 < 1 
-                    spikes(i,:)=[0 xf(abs(index(i)-w_pre:index(i)+w_post+2))];
-                else
-                    spikes(i,:)=xf(abs(index(i)-w_pre-1:index(i)+w_post+2));
-                    % aiheuttaa ongelman jos index(i)-w_pre-1 < 1
-                    % tai
-                    % jos index(i)+w_post+2 > length(xf)
-                    % eli jos piikki on datassa alle w_pren p??ss? alusta
-                    % tai aivan datan lopussa
-                    % --> t?ll?in ei saada kokonaista piikkimuotoa, joten
-                end
-            end
-        end
-    end
-    aux = find(spikes(:,w_pre)==0);       %erases indexes that were artifacts
-    spikes(aux,:)=[];
-    index(aux)=[];
-    
-    clear x; %moved from line 57
-
-end
-        
-switch handles.par.interpolation
-    case 'n'
-        %eliminates borders that were introduced for interpolation 
-        spikes(:,end-1:end)=[];       % laittaa kaikille vikan ja tokavikan []
-        spikes(:,1:2)=[];             % laittaa kaikille ekan ja tokan []
-    case 'y'
-        %Does interpolation
-        spikes = int_spikes(spikes,handles);   
-end

+ 0 - 49
Codes/MATLAB spike detection/newreadspikes.m

@@ -1,49 +0,0 @@
-function [r_result, obj] = ReadSpikesFromNextChannel(obj) % palauttaa seuraavan kanavan indexes & waves etc
-
-            % onko viel? elektrodeita, jotka pit?isi lukea
-            if obj.file_finished &&...% jos oli viimeinen tai eka kanava
-                obj.last_file >= length(obj.files) % ja jos ei ole tiedostoja jotka pit?isi lukea                        
-                Finalcsv=sortrows(obj.T, 2);
-                thefilename=strsplit(obj.getCurrentFile(), '.');
-                thefilename=thefilename{1};
-                writetable(Finalcsv, strcat(thefilename,'_', 'spikes.csv'));
-                disp('All files have been read from!');
-                r_result = [];
-            else % ei ole eka tai vika kanava, tai on tiedostoja joista pit?isi lukea
-                % Tarvitseeko avata uusi tiedosto
-                if obj.file_finished&&...
-                    obj.last_file>0
-                    Finalcsv=sortrows(obj.T, 2);
-                    thefilename=strsplit(obj.getCurrentFile(), '.');
-                    thefilename=thefilename{1};
-                    writetable(Finalcsv, strcat(thefilename,'_', 'spikes.csv'));
-                    obj.T=table; %zeroing the table
-                    obj = obj.OpenNewFile();
-                end
-                
-                if obj.file_finished
-                    obj = obj.OpenNewFile(); %( obj.files(obj.last_file+1) );
-                end
-                
-                
-                %Reading the channel 
-                [r_result.error,m_data, r_result.duration, r_result.chlabel] = obj.ReadAxionChannel();
-                
-                %disp(r_result.chlabel)
-                
-                obj = obj.SiirraOsoittimetSeuraavaan();
-                if ~r_result.error
-                    % check if the channel is behaving properly or if is noisy  
-                    obj.spkdetconf.par.sr = obj.samplerate; 
-                    [r_result.indexes, r_result.spikes, r_result.threshold, ~, r_result.noise, ~] = DetectSpikes_Amp(m_data, obj.spkdetconf);
-                                                           
-                    Time=r_result.indexes;                  
-                    Channel=string(repmat(r_result.chlabel, numel(r_result.indexes),1));
-                    %repeating the channel label as many times %as the number
-                    %of the detected spikes. (For the table creation)
-                    TT=table(Channel, Time);
-                    obj.T=[obj.T; TT];
-                end
-            end
-        end
-