igm-team / meaRtools

An R package for the Comprehensive Analysis of Neuronal Networks Recorded on Microelectrode Arrays
GNU General Public License v3.0
5 stars 5 forks source link

mi_find_bursts issue #51

Open Clementp69 opened 3 years ago

Clementp69 commented 3 years ago

Hi,

I am using the function "mi_find_bursts" in R to detect burst but the function calls an item ".calc_ibi" that I didn't find.

ibi2 <- c(NA, .calc_ibi(spikes, bursts))

Can you help me with this?

Thanks in advance, Clément G

sje30 commented 3 years ago

hmm, that's odd. I can't find it either. I will need to investigate. In the meantime, this seems to be an old definition that might be useful (but I will need to check).


.calc_ibi <- function(spikes, b) {
  ## Compute the interburst intervals (IBI) for one spike train.
  ## Only valid if more than one burst.

  nburst <- .num_bursts(b)
  if (nburst == 0) {
    res <- NA # no bursts
  } else {
    if (nburst == 1) {
      res <- NA # cannot compute  IBI w/only 1 burst.
    } else {
      ## find end spike in each burst.
      end <- b[, "beg"] + b[, "len"] - 1

      ## for n bursts, there will be n bursts minus 1 IBIs.
      start_spikes <- b[2:nburst, "beg"]
      end_spikes <- end[1:(nburst - 1)]
      ## NEX uses a strange definition of IBI: it counts the time between
      ## the first spike of n burst and the first spike of n burst
      ## plus one as the IBI.
      ## If we want to use that definition, use the following line:
      ## end.spikes equal b where 1 to nburst minus 1
      res <- spikes[start_spikes] - spikes[end_spikes]
    }
  }
  res
}

.num_bursts <- function(b) {
  ## Return the number of bursts found for a spike train.
  if (is.na(b[1]))
    0
  else
    nrow(b)
}

.calc_all_ibi <- function(s, allb) {
  ## Compute IBI for all spike trains.
  nchannels <- s$NCells
  ibis <- list()
  for (i in 1:nchannels) {
    ibis[[i]] <- .calc_ibi(s$spikes[[i]], allb[[i]])
  }

  ibis
}
saharg commented 3 years ago

Hi both,

you can find the source code here: https://rdrr.io/cran/meaRtools/src/R/burst_stats.R

Best wishes, Sahar

On Wed, May 26, 2021, 7:46 AM Clementp69 @.***> wrote:

Hi,

I am using the function "mi_find_bursts" in R to detect burst but the function calls an item ".calc_ibi" that I didn't find.

ibi2 <- c(NA, .calc_ibi(spikes, bursts))

Can you help me with this?

Thanks in advance, Clément G

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/igm-team/meaRtools/issues/51, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADIL3OF5O4TDWHCCHFEMDVLTPTNQ7ANCNFSM45R3BIWA .