R/plotLadderCopy.R

Defines functions .plotLadderCopy plotLadderCopy

.plotLadderCopy <- function(seqs, copy, read, title, xl, yl)
{
    x2 <- sapply(strsplit(seqs, "_"), `[`, 2)
    x3 <- sapply(strsplit(seqs, "_"), `[`, 3)
    
    data <- data.frame(seqs=seqs, std=as.factor(paste(x2, x3, sep="_")), copy=copy, read=read)
    data <- data[!is.na(data$read) & !is.infinite(data$read),]
    
    p <- ggplot(data=data, aes_string(x='data$copy', y='data$read')) +
                 xlab(xl) +
                 ylab(yl) +
                 ggtitle(title) +
                 geom_point(aes_string(colour='std'), size=0.7) +
                 guides(colour=FALSE) +
                 geom_line(aes_string(colour='std'),   linetype='11', size=0.5) +
                 theme_bw() +
                 theme(plot.title = element_text(hjust=0.5))
    p <- .transformPlot(p)

    if (!is.null(.env("report")))
    {
        print(lm(data$read ~ data$copy)$coefficients[[2]])
        print(cor(data$copy, data$read)[[1]]^2)
    }
    
    suppressWarnings(print(p))
}

plotLadderCopy <- function(seqs, copy, read, title=NULL, xl=NULL, yl=NULL)
{
    tryCatch({ .plotLadderCopy(seqs, copy, read, title, xl, yl) }, error=function(x) { emptyPlot(xl, yl, title) })
}
sequinstandards/RAnaquin documentation built on Aug. 9, 2019, 2:46 p.m.