diff --git a/extract_abf_header_info.m b/extract_abf_header_info.m deleted file mode 100644 index 65667ba..0000000 --- a/extract_abf_header_info.m +++ /dev/null @@ -1,38 +0,0 @@ -% --- INSTRUCTIONS --- -% 1. Make sure 'abfload3.m' is in your MATLAB path. -% 2. Replace the placeholder path in the 'abfFilePath' variable below with the full path to your ABF file. -% 3. Run this script. It will create a file named 'abf_header_info.mat' in your current MATLAB directory. -% 4. Please upload the 'abf_header_info.mat' file for analysis. -% -------------------- - -% --- CONFIGURATION --- -% IMPORTANT: Please replace the placeholder path below with the actual path to your ABF file. -abfFilePath = '/Users/vanhoosr/data/saya/CNOdata/SHR/SHRNonly/2023_05_11_05_0003.abf'; % <-- SET YOUR FILE PATH HERE - -% --- SCRIPT --- -try - % Check if the file exists - if ~isfile(abfFilePath) - error('ABF file not found. Please update the abfFilePath variable.'); - end - - % Call abfload3 to get the header and data - fprintf('Loading ABF file: %s\n', abfFilePath); - [d, ~, h] = abfload3(abfFilePath); - - % Get the size of the data array - d_size = size(d); - - % Save the header and data size to a .mat file - outputFileName = 'abf_header_info.mat'; - fprintf('Saving header info to: %s\n', outputFileName); - save(outputFileName, 'h', 'd_size'); - - fprintf('\n--- DIAGNOSTIC SCRIPT COMPLETED SUCCESSFULLY ---\n'); - fprintf('Please upload the file named ''%s'' for analysis.\n', outputFileName); - -catch ME - fprintf('\n--- AN ERROR OCCURRED ---\n'); - fprintf('Error: %s\n', ME.message); - fprintf('Please check the file path and ensure that abfload3.m is in your MATLAB path.\n'); -end diff --git a/lib/abfload/abfload3.m b/lib/abfload/abfload3.m index 8e0f14c..bd53a24 100644 --- a/lib/abfload/abfload3.m +++ b/lib/abfload/abfload3.m @@ -448,6 +448,7 @@ h.DACEpoch(1).fEpochLevelInc=h.fEpochLevelInc(1:10); h.DACEpoch(1).lEpochInitDuration=h.lEpochInitDuration(1:10); h.DACEpoch(1).lEpochDurationInc=h.lEpochDurationInc(1:10); + h.DACEpoch(1).sDACChannelUnit = deblank(char(h.sDACChannelUnit(1,:))); if h.nDigitalEnable > 0 h.DACEpoch(1).nDigitalValue = h.nDigitalValue; h.DACEpoch(1).nDigitalTrainValue = h.nDigitalTrainValue; @@ -778,7 +779,11 @@ end pointStart = pointStart + duration; end - dac_waveforms(:, i, dac_num) = waveform; + if h.fFileVersionNumber >= 2 + dac_waveforms(:, i, dac_num) = waveform * h.DACsec(dac_num).fDACScaleFactor / h.fInstrumentScaleFactor(dac_num) + h.DACsec(dac_num).fDACHoldingLevel; + else + dac_waveforms(:, i, dac_num) = waveform; + end end end @@ -816,6 +821,15 @@ d = cat(2, d, dac_waveforms_permuted); for dac_num=1:num_dacs h.recChNames{end+1} = ['DAC_' int2str(h.DACEpoch(dac_num).nDACNum)]; + if h.fFileVersionNumber >= 2 + unit = Strings{h.DACsec(dac_num).lDACChannelUnitsIndex}; + else + unit = deblank(char(h.DACEpoch(dac_num).sDACChannelUnit)); + end + if isempty(unit) || all(isspace(unit)) + unit = 'pA'; + end + h.recChUnits{end+1} = unit; end if digital_dac_num > 0 @@ -823,6 +837,7 @@ d = cat(2, d, digital_waveforms_permuted); for i=1:8 h.recChNames{end+1} = ['DIGITAL_OUT_' int2str(i-1)]; + h.recChUnits{end+1} = ''; end end end @@ -1036,7 +1051,11 @@ 'fEpochLevelInc',1324,'float',repmat(-1,1,20); 'lEpochInitDuration',1404,'int32',repmat(-1,1,20); 'lEpochDurationInc',1484,'int32',repmat(-1,1,20); + 'fDACScaleFactor', 1592, 'float', repmat(-1,1,4); + 'fDACHoldingLevel', 1608, 'float', repmat(-1,1,4); 'nDigitalEnable',1582,'int16',-1; + 'sDACChannelName',1894,'uchar',repmat(-1,1,20); + 'sDACChannelUnit',1914,'uchar',repmat(-1,1,32); 'nDigitalValue',1684,'int16',repmat(-1,1,10); 'nDigitalTrainValue',1704,'int16',repmat(-1,1,10); 'nDigitalHolding',1724,'int16',-1; diff --git a/verify_abfload3_fix.m b/verify_abfload3_fix.m deleted file mode 100644 index d7aa762..0000000 --- a/verify_abfload3_fix.m +++ /dev/null @@ -1,66 +0,0 @@ -% Test script to verify the fix for abfload3.m - -% --- INSTRUCTIONS --- -% 1. Make sure 'abfload3.m' is in your MATLAB path. -% 2. Change the 'abfFilePath' variable below to the full path of your ABF file. -% 3. Run this script. -% -------------------- - -% --- CONFIGURATION --- -% IMPORTANT: Please replace the placeholder path below with the actual path to your ABF file. -% Example: abfFilePath = 'C:\Users\YourUser\Documents\data\your_file.abf'; -abfFilePath = 'path/to/your/abf/file.abf'; % <-- SET YOUR FILE PATH HERE - -% --- SCRIPT --- -try - % Check if the file exists - if ~isfile(abfFilePath) - error('ABF file not found at: %s', abfFilePath); - end - - % Call abfload3 - fprintf('Loading ABF file: %s\n', abfFilePath); - [d, si, h] = abfload3(abfFilePath); - - % Verification - fprintf('Verifying output...\n'); - - % Check for digital channel names in the header - digitalChannelsFound = false; - if isfield(h, 'recChNames') && iscell(h.recChNames) - for i = 1:numel(h.recChNames) - if startsWith(h.recChNames{i}, 'DIGITAL_OUT_') - digitalChannelsFound = true; - break; - end - end - end - - % Check that the data dimensions are correct - expectedNumChans = numel(h.recChNames); - actualNumChans = size(d, 2); - - if digitalChannelsFound && (expectedNumChans == actualNumChans) - fprintf('\n--- VERIFICATION SUCCESSFUL ---\n'); - fprintf('Digital channel data was found in the output.\n'); - fprintf('The ''h.recChNames'' field contains digital channel names, and the dimensions of the data array ''d'' are correct.\n'); - disp('Header fields:'); - disp(h); - else - fprintf('\n--- VERIFICATION FAILED ---\n'); - if ~digitalChannelsFound - fprintf('Digital channel names were NOT found in the ''h.recChNames'' field.\n'); - end - if (expectedNumChans ~= actualNumChans) - fprintf('The number of channels in the data array ''d'' (%d) does not match the number of channel names in the header (%d).\n', actualNumChans, expectedNumChans); - end - disp('Header fields:'); - disp(h); - end - -catch ME - fprintf('\n--- AN ERROR OCCURRED ---\n'); - fprintf('Error identifier: %s\n', ME.identifier); - fprintf('Error message: %s\n', ME.message); - fprintf('Please check the file path and ensure that abfload3.m is accessible.\n'); -end