R/quantDeltaF_Fo.R

Defines functions quantDeltaF_Fo

Documented in quantDeltaF_Fo

#' A function used to quantify the response in the region of interest normalized by F/Fo.
#'
#' It normalizes the intensity data during stimulus window by calculating an average Fo before stimulus, and then dviding the fluorescence values in this window by the background Fo.
#'
#'
#'
#' Normalizing first by an averaged background (Fo) right before stimulus corrects for photobleaching/drift.
#'
#'
#'
#' Inputs:
#' <<<<<<< HEAD
#' @param Data = Dataframe containing fluorescence intensity data
#' @param Conditions = vectory of integers indicating when
#' @param averageWindow = the window to use prior to stimulus for calculating Fo
#' =======
#' >>>>>>> master
#'
#' i = odd index of conditions (corresponds of start of new condition)
#' j = index of response
#'
#'
#'


quantDeltaF_Fo <- function(data, conditions, averageWindow){
  tempList <- list() # Need to declare empty list to store the data temporarily

  response <-   ((mean(data[conditions[i]-averageWindow:conditions[i],4]) -
                    mean(data[conditions[i]-averageWindow:conditions[i],4])) /
                   (mean(data[conditions[i]-averageWindow:conditions[i],4])))

  tempList[1] <- response

  j=1

  for (i in seq(1,(length(conditions)-1),2)){

    j = j + 1

    response <-   ((mean(data[conditions[i]:conditions[i+1],4]) -
                     mean(data[conditions[i]-averageWindow:conditions[i],4])) /
                     (mean(data[conditions[i]-averageWindow:conditions[i],4])))


    # if (response < 0){
    #   response = 0
    # }



    tempList[j] <- response

  }

  tempList <- t(tempList)



  return(data.frame(tempList))

}
FafferMcgee/calcium-analysis documentation built on Sept. 3, 2020, 12:07 a.m.