File Exchange

image thumbnail

fcollman/abfload

version 1.13.0.0 (57.6 KB) by Forrest Collman
a version of abfload which is capable of reading abf 2.0 files

15 Downloads

Updated 05 Dec 2017

View Version History

GitHub view license on GitHub

a version of abfload which is capable of reading abf 2.0 files

Cite As

Forrest Collman (2020). fcollman/abfload (https://github.com/fcollman/abfload), GitHub. Retrieved .

Comments and Ratings (42)

Viktor Sinica

@Jonas the solution for comment extraction by iampritishpatil is available here. it works correctly for my episodic stimulation files:
https://github.com/fcollman/abfload/pull/5/commits/9fb0406fc02897161eedeffdd04d27f598534ecd

You need to insert the following 2 line between lines 290-291:
tmpIx3=strfind((char(BigString)'),'IN');
h.comment1=char(BigString(tmpIx2(1)+4:tmpIx3(1)-1))';

Eugenio Ricci

Sonal Kedia

Hi,
Does anyone know how to access the digital train information from the h files? DACepoch seems to have most of the other information about the protocol file but not about the digital out
Thanks!

Tiago Campelo

Hi,

I am just starting with MatLab and I am trying to use the abfload function.
I used the code:
[d]=abfload('file.abf','start',0,'stop','e','a') to load a gap-free abf v2.06 file. Unfortunately, this error message shows up after running this line:
Index exceeds matrix dimensions.

Error in abfload>pvpmod (line 1162)
assignin('caller', x{i}, x{i+1});

Error in abfload (line 128)
pvpmod(varargin);

Someone has any idea to solve this issue?

Thanks!

Alright, I found out the solution. Hope that helps to other people.
The waveform information can be extracted from the header for ABF <2 files.
The solution is very simple, although it took me a while to figure it out.

Simply add these three lines to the headPar structure (for ABF <2) within the define_header function:

'fEpochInitLevel', 2348, 'float', tmp;
'fEpochLevelInc', 2428, 'float', tmp;
'lEpochInitDuration', 2508, 'int16', tmp;

That will recover the parameters necessary to generate the waveform.
I found the information on how to do this on this site:
https://github.com/swharden/pyABF/tree/master/docs/advanced/abf-file-format
looks like an awesome python library to read .abf files (thanks Scott)
Best,
Saray

Dear Michael,
I found the source of the problem.
My abf files are version<2 (1.83), and therefore the error.
Is it possible still to extract the waveform? Im trying to adapt the code with no much success so far.
Thanks a lot in advance for the help,
Saray

Dear Michael,
Thanks a lot for the tip in returning the stimulus waveform, this is very helpful.
Unfortunately, I altered the code as you explained but I get an error.
Steps 1 and 3 are already included in the current version of the code.
When I include step 2 I get however this error :

Undefined variable "EpochPerDACSection" or class
"EpochPerDACSection.llNumEntries".

Error in abfload2 (line 432)
for i=1:EpochPerDACSection.llNumEntries

That is weird, since EpochPerDACSection is used before in line 372 with no apparent problem.
Any tip would be helpful,
Thanks a lot also to Forrest for the last version of the file

Kazuki Shigyo

Kazuki Shigyo

Yaime Perez Rivas

Thanks a lot! It seems to be working fine for me

Forrest Collman

My mistake, seems that fileexchange has integrated github, so now it will automatically stay synced with the github repo. Please message me if you'd like to be a contributor, or send a pull request with code changes.

Forrest Collman

Hi everyone, I don't work on electrophysiology anymore but I recognize that this function is still very useful to people using axon instruments. Michael's latest addition made me think that we need a more flexible way for the community to collaborate on this, and mathworks fileexchange doesn't do multiple-author contributions well. So I setup a github repo for this. I'll try to keep this file and the github repo synced, but perhaps people can fork and collaborate on that repo. www.github.com/fcollman/abfload. In that way they can also get credit for their contribution.

Michael McKinnon

I altered the code to return the stimulus waveform used to acquire the data. The functionality was basically already there, you just have to tell the function where to look in the ABF file. I noticed some other people were asking about doing the same, so If anyone is interested here's what I did:

1) Put this line right after "TagInfo=define_TagInfo;"

EpochPerDACInfo=define_EpochPerDACInfo

2) Put this code at the end of PART 2c, right before PART 2d

% --- read in the Epoch section and copy some values to header h
for i=1:EpochPerDACSection.llNumEntries
EPDsec(i)=ReadSection(fid,EpochPerDACSection.uBlockIndex*BLOCKSIZE+EpochPerDACSection.uBytes*(i-1),EpochPerDACInfo);
ii=EPDsec(i).nEpochNum+1;
h.nEpochNum(ii)=EPDsec(i).nEpochNum;
h.nDACNum(ii)=EPDsec(i).nDACNum;
h.nEpochType(ii)=EPDsec(i).nEpochType;
h.fEpochInitLevel(ii)=EPDsec(i).fEpochInitLevel;
h.fEpochLevelInc(ii)=EPDsec(i).fEpochLevelInc;
h.lEpochInitDuration(ii)=EPDsec(i).lEpochInitDuration;
h.lEpochDurationInc(ii)=EPDsec(i).lEpochDurationInc;
h.lEpochPulsePeriod(ii)=EPDsec(i).lEpochPulsePeriod;
h.lEpochPulseWidth(ii)=EPDsec(i).lEpochPulseWidth;
end

3) Copy this function into the local functions section

function EpochPerDACInfo=define_EpochPerDACInfo
EpochPerDACInfo={
'nEpochNum','int16',1;
'nDACNum','int16',1;
'nEpochType','int16',1;
'fEpochInitLevel','float',1;
'fEpochLevelInc','float',1;
'lEpochInitDuration','int32',1;
'lEpochDurationInc','int32',1;
'lEpochPulsePeriod','int32',1;
'lEpochPulseWidth','int32',1;
};

That should do it. I haven't tested it extensively, but it works for the files I've tested it on.

SKMEA6

Cengiz: Thanks a lot for your reply. I did some math and found out, that the numbers I get in h.tags have to be multiplied by the sample interval (50 µs in my case) to yield the time in seconds. I think somewhere it was written that it would directly give the value in seconds. Not sure whether this behavior is intended?

mtross

Cengiz Gunay

SKMEA6: Sometimes the sampling rate may be annotated wrong in the file so just make sure that they are correct.

SKMEA6

Thank you very much for putting this together.
However, I do not seem to get correct time stamps for the tags. I have a gap-free recording of approx. 30s with 14 tags distributed +/- evenly along the file. But I just get times below 1s out of the structure.

e.g. Tag 11 is at 22.477s in ClampFit, but:

>> h.tags(11).timeSinceRecStart

ans =

0.4495

I am new to MATLAB. Am I missing or confusing something?

Thanks a lot in advance,
Simon

Marjan R

I am using this m file in order to import the abf file from Clamfit(version 10.5.2.6). Yesterday by "accident" I was comparing the abf file on Clampfit, and also MATLAB. I realized after importing the abf file into MATLAB, the currents are shifted by -20 pA. For example, by looking at the Clampfit I can see the rheobase current is around 42 pA, while MATLAB gives me the value of 21 pA.

Is this version of abfload adoptable to clampfit version 10.5.2.6? Why Im not getting the same number as the real data file in Clampfit?!If I was not checking my file accidentally on Clampfit there was no way for me to fidn out abfload.m is shifting my input currents by ~ -20 pA... This is very annoying. What should I do?!

Dear Forrest
First of all thanks a lot for this extremely useful script :)
I have a question similar to Scott's one. Is the waveform recorded somewhere? I would like to plot an FI courve, from data recorded in current clamp. Maybe I have missed it but I did not see any variable where the values of the current employed are displayed.
Let me know if this is not the case.
Thanks a lot,
Saray

Cengiz Gunay

If you're getting the error

** abfload
Index exceeds matrix dimensions.

Error in abfload>pvpmod (line 1060)
assignin('caller', x{i}, x{i+1});

Error in abfload (line 145)
pvpmod(varargin);

In Matlab version 2014a, you can fix this by changing line 140 to:

if nargin==2 && ischar(varargin{1}{1}) && strcmp('info',varargin{1})

The only change is in the the ischar check, addressing varargin{1}{1} instead of varargin{1}. It's strange, but it works.

Thijs

Jeffrey Johnson

Very useful, thank you!

One suggestion - I had some trouble with rounding errors in the calculation of the start point. This appears ultimately to have been due to a badly-written header value for h.fADCSampleInterval (MCDataTool's problem, not yours!) but I was able to partially solve the problem by changing lines 674/683 from FLOOR commands to ROUND commands. I don't understand the use of FLOOR here, since the values on these lines ought to come out integers (subject to rounding error)...we don't want to FLOOR an index value of 4.99999999 to 4!

Also, line 676 appears to be useless. Due to the FLOOR (or ROUND) operation on 674, STARTPT is already an integer. 676 takes the FLOOR of STARTPT*X/X, which certainly won't fix a rounding error but could introduce one. I have commented 676 out to no detriment.

As a side note, if anybody is using MCDataTool to export to .abf, you may have a problem with the value of h.fADCSampleInterval as written to the header. (This is not the fault of ABFLOAD.) If you believe you may be getting frame shifts when reading an .abf written by MCDataTool, feel free to contact me via the email listed in my profile.

Blake Richards

Worked perfectly for me using ABF v2 files with both episodic and gap-free data! Thank you!!!!

James Hounshell

Forrest Collman

hi scott,

i'm not sure actually. i sent you an email to your yahoo address, if you send me a sample i can take a look.

forrest

Scott

Hi,
Sorry if I overlooked something obvious, but I was wondering if there is a way to extract the waveform data (i.e. the command waveform for vclamp experiments) for Abf v2 files. I am (unfortunately) working with both v1 and v2 files. I found that readabf extracts the command waveform info for abf<2 but when I try to use it on abf=2, I get a "maximum variable size...is exceeded" error.
Any advice on how to best extract the command waveform information would be greatly appreciated!

Jonas

Hi,

I'm using abf2load for plotting of IV curves from episodic traces.

I'm not very experienced in Matlab. Is there any possibility to extract the clampex comment (which you can manually enter after a each recording) in with abf2load?
I was trying to find it in the code but was unsuccessful so far. Would be nice if someone could give me some advice.

Thanks in advance,
Jonas

wjg

Another bug + fix. If you request a subset of channels, you get them in the order listed in the 'channels' argument. However, if you request all channels, they always are returned in the same order as the file, even if the order given in 'channels' is different. The fix is to change line 674 from:

elseif length(chInd)/h.nADCNumChannels<1

to:

elseif length(chInd)/h.nADCNumChannels<1 || any(chInd ~= 1:h.nADCNumChannels)

Matthew

@Ryan and anyone else having the empty goodstart problem:

Look at lines 270 through 275. The name of the program that saved the ABF file is part of the file format. If you saved yours in another program, for instance Clampfit, changing 'axoscope' to the name of the program should work (or, for slightly more robustness, adding a second isempty() check). It solved the problem for me, although it's still a messy hack (as the comments in 270 and 272 do, to be fair, point out).

Ryan

I have the same problems with the tag section, which I have to comment out. Once I do that, the program works about 80% of the time as opposed to about 30% of the time. I also have issues with the following error:

??? Attempted to access goodstart(1); index out of bounds because numel(goodstart)=0.

Error in ==> abfload at 277
BigString=BigString(goodstart(1):end)';

Error in ==> Converter at 63
d1=abfload(abf);

Arthur

Forrest, I ran into a problem with abf files containing tags. When I try to load them I get the following error:

??? The following error occurred converting from struct to double:
Error using ==> double
Conversion to double from struct is not possible.

Error in ==> abfload at 327
Tagsec(i)=ReadSection(fid,TagSection.uBlockIndex*BLOCKSIZE+TagSection.uBytes*(i-1),TagInfo);

The problem seems to be in the line just before (line 325):

Tagsec=[];

This creates an empty double array, but output of the following loop is a struct. Simply commenting line 325 solved the problem for me.

Thanks again for an otherwise great function.

Cengiz Gunay

Apologies.. The file I was trying to load seem to be corrupt and couldn't be loaded by pClamp 10, either. So please ignore the previous post. The correct files can be read by abf2load. Thanks!

Cengiz Gunay

I am getting this error with some ABF2 files from pClamp10:

>> Kslow1_vc = abf2voltage_clamp([ Kfastslow_datadir '008/09821026.abf' ]);
** abf2load
opening ~/prinzlab/Logy/Data Compilation/Potassium Data/Subtracted/008/09821026.abf..
{??? Index exceeds matrix dimensions.

Error in ==> abf2load at 291
h.recChNames=strvcat(h.recChNames, Strings{ADCsec(i).lADCChannelNameIndex});
...
}
291 h.recChNames=strvcat(h.recChNames, Strings{ADCsec(i).lADCChannelNameIndex});
K>>
K>> ADCsec(i).lADCChannelNameIndex

ans =

64265

There are only about 7000 Strings, so this is way out of bounds. I also tried the python version of abf2load that is part of Neo, but that chokes on these files, too. I can send a copy of the file if you can take a look at it.

Thanks for the otherwise very useful utility!

(molecular devices developer page link is broken now. Is there a way to get to that code?)

Andrius Gaigalas

I can read gap free abf files only if statements 326-329 are comments. This problem was seen before and I thought it was fixed. I have MatLab R2009 student edition runing on MS Vista.

Rune W Berg

Arthur

works great!

Julie Haas

Thanks so much! Works great on my episodic data on a PC.

Peter

Works with my episodic stimulation-recording data. Thanks for sharing the code!

Olivier

Forrest Collman

I have fixed the error that was causing JoAnna's problem

JoAnna

I commented out line 329, and importing abf v2.0 files seems to work now.

JoAnna

Currently, it is unable to run. It appears to have errors in the "tag" support that was recently added. Thus far I have had errors in lines 321 and 329.

MATLAB Release Compatibility
Created with R2008a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: abfload

Inspired: loadVclampAbf, APanalysis, Peaker Analysis Toolbox

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!