getZScalesWithNTGuides: Calculate Z-score scaling factors using non-targeting guides

View source: R/MAUDE.R

getZScalesWithNTGuidesR Documentation

Calculate Z-score scaling factors using non-targeting guides

Description

Calculates scaling factors to calibrate element-wise Z-scores by repeatedly calculating a set of "null" Z-scores by repeatedly sampling the given numbers of non-targeting guides per element. This function is not normally used directly.

Usage

getZScalesWithNTGuides(ntData, uGuidesPerElement, mergeBy, ntSampleFold = 10)

Arguments

ntData

data.frame containing the data for the non-targeting guides

uGuidesPerElement

a unique vector of guide counts per element

mergeBy

a character vector containing the header(s) that demarcate the screen/experiment/replicate ID(s)

ntSampleFold

how many times to sample each non-targeting guide to make the Z score scale (defaults to 10)

Value

a data.frame containing a Z-score scaling factor, one for every number of guides and unique entry in mergeBy

Examples

fakeReadData = data.frame(id=rep(1:1000,2), expt=c(rep("e1",1000), rep("e2",1000)), 
                          A=rpois(2000, lambda = 100), B=rpois(2000, lambda = 100),
                          C=rpois(2000, lambda = 100), D=rpois(2000, lambda = 100),
                          E=rpois(2000, lambda = 100), F=rpois(2000, lambda = 100),
                          NotSorted=rpois(2000, lambda = 100), 
                          negControl = rep(rnorm(1000)>0,2), stringsAsFactors = FALSE)
expts = unique(fakeReadData["expt"]);
curSortBins = makeBinModel(data.frame(Bin = c("A","B","C","D","E","F"), fraction = rep(0.1,6)))
curSortBins = rbind(curSortBins, curSortBins) # duplicate and use same for both expts
curSortBins$expt = c(rep(expts$expt[1],6),rep(expts$expt[2],6))
guideHits = findGuideHitsAllScreens(experiments = expts, countDataFrame=fakeReadData,
                                    binStats = curSortBins, unsortedBin = "NotSorted",
                                    negativeControl="negControl")
guideZScales = getZScalesWithNTGuides(guideHits[guideHits$negControl,], uGuidesPerElement=1:10, 
  mergeBy=names(expts))
if(require("ggplot2")){
  p=ggplot(guideZScales, aes(x=numGuides, y=Zscale, colour=expt))+geom_point()+geom_line();
  print(p)
}

Carldeboer/MAUDE documentation built on March 27, 2022, 8:50 p.m.