Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ABF: improve support for ABFs with variable sweep lengths #141

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions dev/python/2024-09-17 verjinia.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys
import pathlib

try:
PATH_HERE = pathlib.Path(__file__).parent
PATH_ABFS = PATH_HERE.joinpath("../../data/abfs/").resolve()
PATH_SRC = PATH_HERE.joinpath("../../src/").resolve()
print(PATH_SRC)
sys.path.insert(0, str(PATH_SRC))
import pyabf
except:
raise EnvironmentError()
1

if __name__ == "__main__":
abf = pyabf.ABF(R"C:\Users\swharden\Documents\Temp\24215056.abf")

for abf_path in pathlib.Path(PATH_ABFS).glob("*.abf"):
abf = pyabf.ABF(abf_path)
14 changes: 11 additions & 3 deletions src/pyabf/abf.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ def _readHeadersV2(self, fb: BufferedReader):
try:
# This is the correct way, but it doesn't seem to work for every ABF.
# I think this is because there is a bug in the string indexer.
#self.userList = self._stringsIndexed.indexedStrings[self._userListSection.nStringIndex[0]]
#self.userList = [float(x) for x in self.userList.split(",")]
# self.userList = self._stringsIndexed.indexedStrings[self._userListSection.nStringIndex[0]]
# self.userList = [float(x) for x in self.userList.split(",")]

# This is weird but it's been in the code for a while and seems to work.
firstBlockStrings = self._stringsSection._stringsRaw[0].split(
Expand All @@ -351,6 +351,14 @@ def _readHeadersV2(self, fb: BufferedReader):
self.sweepCount = self._headerV2.lActualEpisodes
self.channelList = list(range(self.channelCount))

# correct dataPointCount for ABFs with variable length sweeps
# https://github.com/swharden/pyABF/issues/140
# https://github.com/swharden/pyABF/issues/108
if hasattr(self, "_synchArraySection"):
variableDataPointCount = sum(self._synchArraySection.lLength)
if (variableDataPointCount > 0 and variableDataPointCount != self.dataPointCount):
self.dataPointCount = variableDataPointCount

# tags
self.tagComments = self._tagSection.sComment
self.tagTimesSec = self._tagSection.lTagTime
Expand All @@ -376,7 +384,7 @@ def _readHeadersV2(self, fb: BufferedReader):
self._dataGain = [1]*self.channelCount
self._dataOffset = [0]*self.channelCount
for i in range(self.channelCount):
#adcIndex = self._adcSection.nADCSamplingSeq[i]
# adcIndex = self._adcSection.nADCSamplingSeq[i]
# NOTE: ADC sequence is handled inside the ADC section so it doesn't need to be handled here
adcIndex = i
self._dataGain[i] /= self._adcSection.fInstrumentScaleFactor[adcIndex]
Expand Down
Loading