R/Calculate_score.R

# Copyright 2018 Google LLC
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.

#' Calculate the synergy scores for drug combinations
#'
#' A function to calculate the synergy scores for drug combinations using different
#' models.
#'
#' @param data a list object generated by function \code{\link{ReshapeData}}
#' @param method a parameter to specify which models to use to calculate the synergy scores. Choices are "ZIP",
#' "Bliss", "HSA" and "Loewe". Defaults to "ZIP".
#' @param correction a parameter to specify if baseline correction is used or not. Defaults to TRUE.
#' @param Emin the minimal effect of the drug used in the 4-parameter log-logistic function to fit the dose-response 
#' curve. If it is not NA, it is fixed the value assigned by the user. Defaults to 0. For "Bliss", "HSA" and "Loewe" model,
#' it is used only when correction is required.
#' @param Emax the maximal effect of the drug used in the 4-parameter log-logistic function to fit the dose-response 
#' curve. If it is not NA, it is fixed the value assigned by the user. Defaults to 100. For "Bliss", "HSA" and "Loewe" model,
#' it is used only when correction is required.
#' @param nan.handle a parameter to specify if L.4 function or LL.4 function is used when fitting with LL.4 produces
#' NaNs.
#' @return a list of the following components:
#' \item{dose.response.mats}{ the same as the input data component.}
#' \item{drug.pairs}{the same as the input data component.}
#' \item{scores}{a list of matrixes of synergy scores.}
#' \item{method}{the method used to calculate the synergy scores.}
#' @author Liye He \email{liye.he@helsinki.fi}
#' @references Yadav B, Wennerberg K, Aittokallio T, Tang J. Searching for Drug Synergy in Complex Dose-Response Landscape Using an Interaction Potency Model.
#' Computational and Structural Biotechnology Journal 2015; 13: 504-513.
#' @examples
#' data("mathews_screening_data")
#' data <- ReshapeData(mathews_screening_data)
#' scores <- CalculateSynergy(data)
CalculateSynergy <- function(data, method = "ZIP", correction = TRUE, Emin = 0, Emax = 100, nan.handle = c("LL4", "L4")) {
  if(!is.list(data)) {
    stop("Input data is not a list format!")
  }
  if(!method %in% c("ZIP", "HSA", "Bliss", "Loewe")) {
    stop("The method parameter can only be one of the following: ZIP, HSA, Bliss and Loewe.")
  }
  dose.response.mats <- data$dose.response.mats
  num.pairs <- length(dose.response.mats)
  scores <- list() ## save delta scores for each drug combination
  nan.handle <- match.arg(nan.handle)
  for (i in 1:num.pairs) {
    response.mat <- dose.response.mats[[i]]
    scores[[i]] <- switch(method,
                          ZIP = ZIP(response.mat, correction, Emin = Emin, Emax = Emax, nan.handle),
                          HSA = HSA(response.mat, correction, Emin = Emin, Emax = Emax, nan.handle),
                          Bliss = Bliss(response.mat, correction, Emin = Emin, Emax = Emax, nan.handle),
                          Loewe = Loewe(response.mat, correction, Emin = Emin, Emax = Emax, nan.handle))
  }

  data$scores <- scores
  data$method <- method
  return(data)
}
google/synergyfinderengineered documentation built on May 16, 2019, 2:31 a.m.