Skip to content

Commit

Permalink
more idiomatic R
Browse files Browse the repository at this point in the history
  • Loading branch information
Zabolekar committed Aug 31, 2018
1 parent d507b46 commit 11d7722
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: readABF
Title: Loads Axon Binary Files
Version: 0.7.6
Version: 0.7.7
Authors@R: c(person("Stanislav", "Syekirin", role = c("aut", "cre"), email = "[email protected]"),
person("Florian", "Pein", role = "ctb", email = "[email protected]"))
Description: Loads Axon Binary Files (both ABF and ABF2) created by Axon Instruments/Molecular Devices software such as pClamp.
Expand Down
17 changes: 7 additions & 10 deletions R/readABF.R
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ readABF <- function (file) {
}

# read in the TagSection, do a few computations & write to header$tags
header$tags <- list()
header$tags <- list()
if (sections$TagSection$llNumEntries > 0) {
tmp <- list()
for (i in 1:sections$TagSection$llNumEntries) {
Expand Down Expand Up @@ -459,8 +459,7 @@ readABF <- function (file) {
stop("number of data points in episode not OK")
}
# separate channels
tmpd <- matrix(tmpd, header$nADCNumChannels, header$dataPtsPerChan)
tmpd <- t(tmpd)
tmpd <- matrix(tmpd, header$dataPtsPerChan, header$nADCNumChannels, byrow=TRUE)
# if data format is integer, scale appropriately; if it's float, tmpd is fine
if (!header$nDataFormat) {
for (j in 1:length(chInd)) {
Expand Down Expand Up @@ -526,7 +525,7 @@ readABF <- function (file) {
})
d <- list()
# the starting ticks of episodes in sample points WITHIN THE DATA FILE
selectedSegStartInPts <- ((sweeps-1)*dataPtsPerSweep)*dataSz + headOffset
selectedSegStartInPts <- (sweeps-1)*dataPtsPerSweep*dataSz + headOffset
for (i in seq(from=1, length.out=nSweeps)) { # because nSweeps sometimes is 0
seek(f, selectedSegStartInPts[i])
tmpd <- list(int16=int16, float32=float32)[[precision]](dataPtsPerSweep)
Expand All @@ -540,8 +539,7 @@ readABF <- function (file) {
stop("number of data points in episode not OK")
}
# separate channels
tmpd <- matrix(tmpd, header$nADCNumChannels, header$dataPtsPerChan)
tmpd <- t(tmpd)
tmpd <- matrix(tmpd, header$dataPtsPerChan, header$nADCNumChannels, byrow=TRUE)
# if data format is integer, scale appropriately; if it's float, d is fine
if (!header$nDataFormat) {
for (j in 1:length(chInd)) {
Expand Down Expand Up @@ -580,15 +578,14 @@ readABF <- function (file) {
stop("something went wrong reading file (", header$dataPts, " points should have been read, ", n,
" points actually read")
}
# separate channels..
tmpd <- matrix(tmpd, header$nADCNumChannels, header$dataPtsPerChan)
tmpd <- t(tmpd)
# separate channels
tmpd <- matrix(tmpd, header$dataPtsPerChan, header$nADCNumChannels, byrow=TRUE)

# if data format is integer, scale appropriately; if it's float, d is fine
if (!header$nDataFormat) {
for (j in 1:length(chInd)) {
ch <- recChIdx[chInd[j]]+1
tmpd[,j]=tmpd[,j]/(header$fInstrumentScaleFactor[ch]*header$fSignalGain[ch]*header$fADCProgrammableGain[ch]*
tmpd[,j] <- tmpd[,j]/(header$fInstrumentScaleFactor[ch]*header$fSignalGain[ch]*header$fADCProgrammableGain[ch]*
addGain[ch])*
header$fADCRange/header$lADCResolution+header$fInstrumentOffset[ch]-header$fSignalOffset[ch]
}
Expand Down

0 comments on commit 11d7722

Please sign in to comment.