R/import.R

###############################################################################
#
# author: Christoph Kiefer
# email: christophak@bmb.sdu.dk
#
################################################################################
#'
#' Import Cq Values Calculated Using LightCycler Software
#'
#' @param file A txt file with calculated Cq values from the LightCycler software
#' @param scheme A pipetting scheeme, e.g., generated by get.pipettingScheme.
#'     Generally a data.frame containing gene, cond, col and row information.
#'
#' @import readr
#' @import dplyr
#'
#' @examples scheme <- get.pipettingScheme(paste("primer", 1:7), c(1:5), 1, 2, 1, nrow = 10, first_col = 18)
#'     import.LCcq("data-raw/primer.txt", scheme, decimal_mark = ',')
#'
#' @export
import.LCcq <- function(file, pipettingScheme = NULL, decimal_mark = '.') {

     df <- read_tsv(file, locale = locale(decimal_mark = decimal_mark), skip = 1,
        col_types = cols(
            Include = col_character(),
            Color = col_integer(),
            Pos = col_character(),
            Name = col_character(),
            Cp = col_double(),
            Concentration = col_character(),
            Standard = col_integer(),
            Status = col_character())) %>%
        dplyr::select(cq = Cp, Pos) %>%
        mutate(col = as.integer(substr(Pos, 2, nchar(Pos))),
            row = substr(Pos, 1, 1)) %>%
        dplyr::select(-Pos)

    if (is.null(pipettingScheme)) {
        return(df)
    } else {
        pipettingScheme %>%
            left_join(df, by = c("col", "row"))
    }
}
kiefer-ch/qpcRo documentation built on May 31, 2019, 1:57 p.m.