Commit 2e2cee88 authored by aditya.bhagwat's avatar aditya.bhagwat
Browse files

Modularize/Streamline interface

parent f45d072d
Pipeline #147173 passed with stages
in 14 seconds
# Generated by roxygen2: do not edit by hand
export(add_context)
export(add_inverse_strand)
export(add_seq)
export(add_specificity)
export(bed_to_granges)
export(char_to_granges)
export(double_flank)
......@@ -14,8 +12,6 @@ export(extend_for_pe)
export(extend_pe_to_gg)
export(extract_matchranges)
export(extract_subranges)
export(filter_offtargets)
export(filter_ontargets)
export(find_gg)
export(find_primespacers)
export(find_spacers)
......@@ -88,6 +84,7 @@ importFrom(data.table,":=")
importFrom(data.table,.SD)
importFrom(data.table,as.data.table)
importFrom(data.table,data.table)
importFrom(data.table,fread)
importFrom(data.table,fwrite)
importFrom(data.table,setnafill)
importFrom(data.table,setnames)
......@@ -117,6 +114,7 @@ importFrom(magrittr,extract)
importFrom(magrittr,extract2)
importFrom(magrittr,set_names)
importFrom(methods,as)
importFrom(methods,is)
importFrom(reticulate,py_module_available)
importFrom(stats,complete.cases)
importFrom(stringi,stri_detect_regex)
......
......@@ -18,7 +18,7 @@
#' @importFrom BiocGenerics end end<- invertStrand
#' @importFrom BiocGenerics start start<- strand strand<-
#' @importFrom BSgenome getSeq getBSgenome
#' @importFrom data.table fwrite
#' @importFrom data.table fread fwrite
#' @importFrom data.table := data.table as.data.table setnames
#' @importFrom data.table setnames setorderv setnafill .SD
#' @importFrom GenomeInfoDb genome
......@@ -37,7 +37,7 @@
#' @importFrom grid arrow
#' @importFrom magrittr %>% %<>% add and
#' @importFrom magrittr extract extract2 set_names
#' @importFrom methods as
#' @importFrom methods as is
#' @importFrom tidyr separate_rows
#' @importFrom utils download.file getFromNamespace head
#' @importFrom utils tail read.csv read.table
......
......@@ -162,7 +162,7 @@ plot_intervals <- function(gr, xref = 'targetname', y = default_y(gr),
prepare_alpha <- function(plotgr, alpha_var){
if (!is.null(alpha_var)){
if (alpha_var == 'off'){
if (stri_startswith_fixed(alpha_var, 'off')){
mcols(plotgr)[[alpha_var]] %<>% cut(c(-Inf, 0, Inf), c('0', '1+'))}}
plotgr
}
......@@ -188,7 +188,7 @@ prepare_color <- function(plotgr, color_var){
scale_alpha <- function(p, alpha_var){
if (!is.null(alpha_var)){ if (alpha_var == 'off'){
if (!is.null(alpha_var)){ if (stri_startswith_fixed(alpha_var, 'off')){
p <- p + scale_alpha_manual(values = c(`0` = 1, `1+` = 0.3))
}}
p
......
......@@ -305,7 +305,9 @@ add_inverse_strand <- function(gr, verbose = FALSE, plot = FALSE, ...){
# Concatenate
newgr <- c(gr, revcomps)
newgr %<>% unique()
txt <- sprintf('\t\t%d ranges after adding inverse strands', length(newgr))
txt <- sprintf(
'\tRetain %d unique target ranges after adding inverse strands',
length(newgr))
# Sort
newgr <- sortSeqlevels(newgr)
......
......@@ -126,9 +126,10 @@ find_gg <- function(gr){
add_nickspacers <- function(primespacers, bsgenome,
ontargets = c('Doench2014', 'Doench2016'), mismatches = 2,
ontargetmethod = c('Doench2014', 'Doench2016'),
offtargetmethod = c('bowtie', 'vcountpdict')[1],
indexedgenomesdir = INDEXEDGENOMESDIR, outdir = OUTDIR, plot = TRUE
nickmatches = 3, indexedgenomesdir = INDEXEDGENOMESDIR, outdir = OUTDIR,
plot = TRUE, verbose = TRUE
){
# Check / Initialize
. <- crisprname <- crisprspacer <- crisprpam <- NULL
......@@ -136,17 +137,16 @@ add_nickspacers <- function(primespacers, bsgenome,
primespacers$pename <- primespacers$crisprname
primespacers$type <- 'pespacer'
# Get nick spacers
message('\tAdd nickspacers')
message('Find nickspacers')
nickzone <- invertStrand(down_flank(primespacers, -3+40-5, -3+90+17))
mcols(nickzone) %<>% extract(, c('targetname', 'pename'), drop = FALSE)
nickspacers <- find_spacers(nickzone, bsgenome, complement = FALSE,
ontargets = ontargets, offtargetmethod = offtargetmethod,
ontargetmethod = ontargetmethod, offtargetmethod = offtargetmethod,
offtargetfilterby = 'pename',
mismatches = mismatches, indexedgenomesdir = indexedgenomesdir,
mismatches = nickmatches, indexedgenomesdir = indexedgenomesdir,
outdir = outdir, plot=FALSE)
nickspacers$type <- 'nickspacer'
if (verbose) message('\tFound ', length(nickspacers), ' nickspacers')
mcols(nickspacers)[[ontargets]] %<>% round(digits = 2)
mcols(nickspacers)[[ontargetmethod]] %<>% round(digits = 2)
# Merge
nickdt <- gr2dt(nickspacers) %>%
extract( , .(
......@@ -154,13 +154,13 @@ add_nickspacers <- function(primespacers, bsgenome,
nickrange = as.character(granges(nickspacers)),
nickspacer = crisprspacer,
nickpam = crisprpam,
nickoff = off,
nickoff0 = off0,
nickoff1 = off1,
nickoff2 = off2)) %>%
extract(, (paste0('nick', ontargets)) :=
mcols(nickspacers)[[ontargets]]) %>%
extract( , lapply(.SD, pastelapse), by = 'pename')
nickoff = off))
for (i in seq(0, nickmatches)){
nickdt[, (paste0('nickoff',i)) := mcols(nickspacers)[[paste0('off',i)]]]
}
method <- ontargetmethod
nickdt[, (paste0('nick', method)) := mcols(nickspacers)[[method]]]
nickdt %<>% extract( , lapply(.SD, pastelapse), by = 'pename')
pedt <- gr2dt(primespacers)
pedt$type <- NULL
......@@ -196,12 +196,12 @@ pastelapse <- function(x) paste0(x, collapse = ';')
#' If named, names should be identical to those of \code{gr}
#' @param nprimer n primer nucleotides (default 13, max 17)
#' @param nrt n rev transcr nucleotides (default 16, recomm. 10-16)
#' @param ontargets 'Doench2014' or 'Doench2016': on-target scoring method
#' @param ontargetmethod 'Doench2014' or 'Doench2016': on-target scoring method
#' @param offtargetmethod 'bowtie' or 'vcountpdict'
#' @param mismatches no of primespacer mismatches
#' (default 0, to suppress offtarget analysis: -1)
#' @param nickmatches no of nickspacer offtarget mismatches
#' (default 2, to suppresses offtarget analysis: -1)
#' @param offtargetmethod 'bowtie' or 'vcountpdict'
#' (default 3, to suppresses offtarget analysis: -1)
#' @param indexedgenomesdir directory with indexed genomes
#' (as created by \code{\link{index_genome}})
#' @param outdir directory whre offtarget analysis output is written
......@@ -245,11 +245,10 @@ pastelapse <- function(x) paste0(x, collapse = ';')
#' @seealso \code{\link{find_spacers}} to find standard crispr sites
#' @export
find_primespacers <- function(gr, bsgenome, edits = get_plus_seq(bsgenome, gr),
nprimer = 13, nrt = 16, ontargets = c('Doench2014', 'Doench2016')[1],
mismatches = 0, nickmatches = 2,
nprimer = 13, nrt = 16, ontargetmethod = c('Doench2014', 'Doench2016')[1],
offtargetmethod = c('bowtie', 'vcountpdict')[1],
indexedgenomesdir = INDEXEDGENOMESDIR, outdir = OUTDIR,
verbose = TRUE, plot = TRUE, ...){
mismatches = 0, nickmatches = 3, indexedgenomesdir = INDEXEDGENOMESDIR,
outdir = OUTDIR, verbose = TRUE, plot = TRUE, ...){
# Assert
assert_is_all_of(gr, 'GRanges')
assert_is_all_of(bsgenome, 'BSgenome')
......@@ -257,13 +256,11 @@ find_primespacers <- function(gr, bsgenome, edits = get_plus_seq(bsgenome, gr),
assert_all_are_matching_regex(edits, '^[ACGTacgt]+$')
assert_are_same_length(gr, edits)
if (has_names(edits)) assert_are_identical(names(gr), names(edits))
assert_is_a_number(nprimer)
assert_is_a_number(nrt)
assert_is_a_number(nprimer); assert_is_a_number(nrt)
assert_all_are_less_than(nprimer, 17)
assert_is_subset(ontargets, c('Doench2016', 'Doench2014'))
assert_is_a_bool(verbose)
assert_is_a_bool(plot)
assert_is_a_bool(verbose); assert_is_a_bool(plot)
# Find GG in nrt window around target site
if (verbose) message('Find primespacers for ', length(gr), ' targets')
gr %<>% name_uniquely(); names(edits) <- names(gr)
gg <- gr %>% extend_pe_to_gg(nrt) %>% add_seq(bsgenome) %>% find_gg()
names(gg) <- gg$crisprname <- uniquify(gg$targetname)
......@@ -282,18 +279,17 @@ find_primespacers <- function(gr, bsgenome, edits = get_plus_seq(bsgenome, gr),
spacers$crisprtranscript <- transcripts$seq
spacers$crisprextension <- exts$seq
spacers$crisprextrange <- unname(as.character(granges(exts)))
# Add offtargets, ontargets, nickspacers
if (verbose) message("\tFound ", length(spacers), " spacers/3'extensions")
spacers %<>% add_offtargets(bsgenome, mismatches = mismatches, pam = 'NGG',
offtargetmethod = offtargetmethod,outdir = outdir,
indexedgenomesdir = indexedgenomesdir,
verbose= TRUE, plot = FALSE)
spacers %<>% add_ontargets(bsgenome, method = ontargets, plot = FALSE)
spacers %<>% add_nickspacers(bsgenome, ontargets = ontargets,
mismatches = nickmatches, offtargetmethod = offtargetmethod,
indexedgenomesdir = indexedgenomesdir,
outdir = outdir, plot = FALSE)
# Plot and Return
# Count offtargets, score ontargets, add nickspacers, plot, return
if (verbose) message("\tFound ", length(spacers), " primespacers")
spacers %<>% count_offtargets(bsgenome, mismatches=mismatches, pam='NGG',
offtargetmethod = offtargetmethod, outdir = outdir, indexedgenomesdir =
indexedgenomesdir, verbose= TRUE, plot = FALSE)
spacers %<>% score_ontargets(
bsgenome, ontargetmethod = ontargetmethod, plot = FALSE)
spacers %<>% add_nickspacers(bsgenome, ontargetmethod = ontargetmethod,
offtargetmethod = offtargetmethod,
nickmatches = nickmatches, indexedgenomesdir = indexedgenomesdir,
outdir = outdir, plot = FALSE)
if (plot) print(plot_intervals(spacers, ...))
spacers
}
......
......@@ -189,8 +189,9 @@ extract_matchranges <- function(gr, bsgenome, pattern, plot = FALSE){
#' @param spacer string: spacer pattern in extended IUPAC alphabet
#' @param pam string: pam pattern in extended IUPAC alphabet
#' @param complement TRUE (default) or FALSE: also search in compl ranges?
#' @param ontargets 'Doench2016' or 'Doench2016': on-target scoring method
#' @param ontargetmethod 'Doench2016' or 'Doench2016': on-target scoring method
#' @param offtargetmethod 'bowtie' (default) or 'vcountpdict'
#' @param offtargetfilterby filter for best off-target counts by this variable
#' @param subtract_targets TRUE or FALSE (default): whether to subtract target
#' (mis)matches from offtarget counts
#' @param mismatches 0-3: allowed mismatches in offtargetanalysis
......@@ -224,26 +225,29 @@ extract_matchranges <- function(gr, bsgenome, pattern, plot = FALSE){
#' bsgenome <- BSgenome.Mmusculus.UCSC.mm10::BSgenome.Mmusculus.UCSC.mm10
#' bedfile <- system.file('extdata/SRF.bed', package='multicrispr')
#' gr <- bed_to_granges(bedfile, 'mm10') %>% extend()
#' gr %<>% extract(1:100)
#' find_spacers(gr, bsgenome, subtract_targets = TRUE)
#' @seealso \code{\link{find_primespacers}} to find prime editing spacers
#' @export
find_spacers <- function(gr, bsgenome, spacer = strrep('N', 20), pam = 'NGG',
complement = TRUE, ontargets = c('Doench2014', 'Doench2016')[1],
complement = TRUE,
ontargetmethod = c('Doench2014', 'Doench2016')[1],
offtargetmethod = c('bowtie', 'vcountpdict')[1],
subtract_targets = FALSE, mismatches = 2,
offtargetfilterby = character(0),
subtract_targets = FALSE, mismatches = 3,
indexedgenomesdir = INDEXEDGENOMESDIR, outdir = OUTDIR,
verbose = TRUE, plot = TRUE, ...){
verbose = TRUE, plot = TRUE, ...
){
# Assert
assert_is_all_of(gr, 'GRanges')
assert_is_all_of(bsgenome, 'BSgenome')
assert_is_a_string(spacer)
assert_is_a_string(pam)
assert_is_a_bool(complement)
assert_is_subset(ontargets, c('Doench2016', 'Doench2014'))
assert_is_subset(mismatches, c(-1, 0,1,2))
assert_is_a_bool(verbose)
assert_is_a_bool(plot)
# Find
if (verbose) message('Find spacers in ', length(gr), ' targets')
if (complement){
gr %<>% add_inverse_strand(plot = FALSE, verbose = verbose)
}
......@@ -253,13 +257,16 @@ find_spacers <- function(gr, bsgenome, spacer = strrep('N', 20), pam = 'NGG',
spacers$crisprname <- names(spacers)
spacers$crisprspacer <- getSeq(bsgenome, spacers, as.character=TRUE)
spacers$crisprpam <- getSeq(bsgenome, pams, as.character=TRUE)
if (verbose) message('\tFound ', length(spacers), ' spacers')
# Add on/offtargets
spacers %<>% add_offtargets(
spacers %<>% count_offtargets(
bsgenome, targets = if (subtract_targets) gr else NULL,
mismatches = mismatches, pam = pam, offtargetmethod = offtargetmethod,
offtargetfilterby = offtargetfilterby,
outdir = outdir, indexedgenomesdir = indexedgenomesdir,
verbose = verbose, plot = FALSE)
spacers %<>% add_ontargets(bsgenome, method = ontargets, plot = FALSE)
spacers %<>% score_ontargets(
bsgenome, ontargetmethod = ontargetmethod, plot = FALSE)
# Plot/Return
if (plot) print(plot_intervals(spacers, ...)) #spacers$sitename <- NULL
spacers
......
......@@ -27,7 +27,7 @@
#' targets <- extend(bed_to_granges(bedfile, 'mm10'))
#' spacers <- find_spacers(targets, bsgenome)
#' (spacers %<>% add_context(bsgenome))
#' @export
#' @noRd
add_context <- function(spacers, bsgenome, verbose = TRUE){
# Prevent from stats::start from being used (leads to bug!)
......@@ -128,7 +128,7 @@ doench2016 <- function(
#'
#' @param spacers \code{\link[GenomicRanges]{GRanges-class}}: spacers
#' @param bsgenome \code{\link[BSgenome]{BSgenome-class}}
#' @param method 'Doench2014' (default) or 'Doench2016'
#' @param ontargetmethod 'Doench2014' (default) or 'Doench2016'
#' (requires non-NULL argument python, virtualenv, or condaenv)
#' @param cutoff value to filter on
#' @param chunksize Doench2016 is executed in chunks of chunksize
......@@ -163,11 +163,10 @@ doench2016 <- function(
#' bsgenome)
#' spacers <- find_primespacers(targets, bsgenome)
#' #spacers<- find_spacers(extend_for_pe(gr), bsgenome, complement = FALSE)
#' (spacers %<>% add_ontargets(bsgenome, 'Doench2014'))
#' (spacers %<>% score_ontargets(bsgenome, 'Doench2014'))
#' # reticulate::use_condaenv('azienv')
#' # reticulate::import('azimuth')
#' # spacers %<>% add_ontargets(bsgenome, 'Doench2016')
#' # filter_ontargets(spacers, bsgenome, 'Doench2016', 0.4)
#' # spacers %<>% score_ontargets(bsgenome, 'Doench2016')
#'
#' # TFBS example
#' #-------------
......@@ -177,9 +176,9 @@ doench2016 <- function(
#' spacers <- find_spacers(targets, bsgenome)
#' # reticulate::use_condaenv('azienv')
#' # reticulate::import('azienv')
#' # (spacers %<>% add_offtargets(bsgenome, targets))
#' # (spacers %>% add_ontargets(bsgenome, 'Doench2014'))
#' # (spacers %>% add_ontargets(bsgenome, 'Doench2016'))
#' # (spacers %<>% count_offtargets(bsgenome, targets))
#' # (spacers %>% score_ontargets(bsgenome, 'Doench2014'))
#' # (spacers %>% score_ontargets(bsgenome, 'Doench2016'))
#' @references
#' Doench 2014, Rational design of highly active sgRNAs for
#' CRISPR-Cas9-mediated gene inactivation. Nature Biotechnology,
......@@ -191,28 +190,30 @@ doench2016 <- function(
#'
#' Python module azimuth: github/MicrosoftResearch/azimuth
#' @noRd
add_ontargets <- function(
spacers, bsgenome, method= c('Doench2014', 'Doench2016')[1],
score_ontargets <- function(
spacers, bsgenome, ontargetmethod= c('Doench2014', 'Doench2016')[1],
chunksize = 10000, verbose = TRUE, plot = TRUE, ...
){
# Assert
crisprcontext <- NULL
assert_is_all_of(spacers, 'GRanges')
assert_is_a_string(method)
assert_is_subset(method, c('Doench2014', 'Doench2016'))
if (method %in% names(mcols(spacers))) mcols(spacers)[[method]] <- NULL
assert_is_a_string(ontargetmethod)
assert_is_subset(ontargetmethod, c('Doench2014', 'Doench2016'))
if (ontargetmethod %in% names(mcols(spacers))){
mcols(spacers)[[ontargetmethod]] <- NULL}
# Add contextseq
if (verbose) cmessage('\tScore spacers')
if (verbose) cmessage('\tScore ontargets')
spacers %<>% add_context(bsgenome, verbose = verbose)
spacerdt <- gr2dt(spacers)
scoredt <- data.table(crisprcontext = unique(spacerdt$crisprcontext))
# Score
scores <- switch(method,
scores <- switch(ontargetmethod,
Doench2014 = doench2014(scoredt$crisprcontext, verbose=verbose),
Doench2016 = doench2016(scoredt$crisprcontext, chunksize=chunksize,
verbose=verbose))
scoredt[ , (method) := scores ]
scoredt[ , (ontargetmethod) := scores ]
# Merge back in
mergedt <- merge(spacerdt, scoredt,
......@@ -228,44 +229,6 @@ add_ontargets <- function(
}
#' @rdname add_ontargets
add_efficiency <- function(...){
.Deprecated('add_ontargets')
add_ontargets(...)
}
filter_efficient <- function(...){
.Deprecated('filter_ontargets')
filter_ontargets(...)
}
#' @rdname add_ontargets
#' @export
filter_ontargets <- function(
spacers,
bsgenome,
method= c('Doench2014', 'Doench2016')[1],
cutoff,
verbose = TRUE,
plot = TRUE,
...
){
spacers %<>% add_ontargets(
bsgenome = bsgenome, method = method,
verbose = verbose, plot = plot, ...)
idx <- mcols(spacers)[[method]] > cutoff
if (verbose){
width <- nchar(length(idx))
cmessage('\t\t%s ranges', formatC(length(idx), width = width))
cmessage('\t\t%s ranges after filtering for %s > %s',
formatC(sum(idx), width = width), method, as.character(cutoff))
}
spacers %>% extract(idx)
}
default_alpha_var <- function(gr){
if ('off' %in% names(mcols(gr))) 'off' else NULL
}
\ No newline at end of file
......@@ -40,7 +40,7 @@
targets <- multicrispr::bed_to_granges(bedfile, genome='mm10', plot = FALSE)
extended <- extend(targets, -22, +22)
spacers <- find_spacers(
extended, bsgenome, ontargets = 'Doench2016', subtract_targets = TRUE)
extended, bsgenome, ontargetmethod = 'Doench2016', subtract_targets = TRUE)
# Select target to showcase
# Find a target that allows to showcase subtract_targets = TRUE
......@@ -94,7 +94,7 @@
plot_intervals(extended) %>% blanken()
ggsave('../graphs/prnp02_extended.pdf', width=1.3, height=0.6, device = grDevices::cairo_pdf, bg = 'transparent')
spacers <- find_primespacers(gr, bsgenome, ontargets = 'Doench2016')
spacers <- find_primespacers(gr, bsgenome, ontargetmethod = 'Doench2016')
#(plot_intervals(spacers, alpha_var = 'type', size_var = NULL) +
#scale_alpha_manual(values = c(`spacer` = 1, `3 extension` = 1, `nicking spacer` = 0))) %>% blanken()
#ggplot2::ggsave('../graphs/prnp03_primespacers.pdf', width=1.3, height=0.9, device = grDevices::cairo_pdf, bg = 'transparent')
......
......@@ -34,4 +34,4 @@ offtarget_comparison <- data.table( targetname = spacers$targetname,
V3 = pdict_results[ spacers$crisprspacer, on = 'readseq']$MM3,
B3 = bowtie_results[spacers$crisprspacer, on = 'readseq']$MM3
)
fwrite(offtarget_comparison, '../offtarget_comparison/offtarget_comparison.txt', sep = '\t')
\ No newline at end of file
fwrite(offtarget_comparison, '../offtarget_comparison/offtarget_comparison.txt', sep = '\t')
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/08_add_ontargets.R
\name{add_context}
\alias{add_context}
\title{Add [-4, +3] context}
\usage{
add_context(spacers, bsgenome, verbose = TRUE)
}
\arguments{
\item{spacers}{\code{\link[GenomicRanges]{GRanges-class}}: spacer ranges}
\item{bsgenome}{\code{\link[BSgenome]{BSgenome-class}}}
\item{verbose}{logical(1)}
}
\value{
character vector
}
\description{
Add context for Doench2016 scoring
}
\examples{
# PE example
#-----------
require(magrittr)
bsgenome <- BSgenome.Hsapiens.UCSC.hg38::BSgenome.Hsapiens.UCSC.hg38
gr <- char_to_granges(c(PRNP = 'chr20:4699600:+', # snp
HBB = 'chr11:5227002:-', # snp
HEXA = 'chr15:72346580-72346583:-', # del
CFTR = 'chr7:117559593-117559595:+'), # ins
bsgenome)
spacers <- find_spacers(extend_for_pe(gr), bsgenome, complement=FALSE)
(add_context(spacers, bsgenome))
# TFBS example
#-------------
bedfile <- system.file('extdata/SRF.bed', package = 'multicrispr')
bsgenome <- BSgenome.Mmusculus.UCSC.mm10::BSgenome.Mmusculus.UCSC.mm10
targets <- extend(bed_to_granges(bedfile, 'mm10'))
spacers <- find_spacers(targets, bsgenome)
(spacers \%<>\% add_context(bsgenome))
}
......@@ -10,10 +10,10 @@ find_primespacers(
edits = get_plus_seq(bsgenome, gr),
nprimer = 13,
nrt = 16,
ontargets = c("Doench2014", "Doench2016")[1],
mismatches = 0,
nickmatches = 2,
ontargetmethod = c("Doench2014", "Doench2016")[1],
offtargetmethod = c("bowtie", "vcountpdict")[1],
mismatches = 0,
nickmatches = 3,
indexedgenomesdir = INDEXEDGENOMESDIR,
outdir = OUTDIR,
verbose = TRUE,
......@@ -33,15 +33,15 @@ If named, names should be identical to those of \code{gr}}
\item{nrt}{n rev transcr nucleotides (default 16, recomm. 10-16)}
\item{ontargets}{'Doench2014' or 'Doench2016': on-target scoring method}
\item{ontargetmethod}{'Doench2014' or 'Doench2016': on-target scoring method}
\item{offtargetmethod}{'bowtie' or 'vcountpdict'}
\item{mismatches}{no of primespacer mismatches
(default 0, to suppress offtarget analysis: -1)}
\item{nickmatches}{no of nickspacer offtarget mismatches
(default 2, to suppresses offtarget analysis: -1)}
\item{offtargetmethod}{'bowtie' or 'vcountpdict'}
(default 3, to suppresses offtarget analysis: -1)}
\item{indexedgenomesdir}{directory with indexed genomes
(as created by \code{\link{index_genome}})}
......
......@@ -10,10 +10,11 @@ find_spacers(
spacer = strrep("N", 20),
pam = "NGG",
complement = TRUE,
ontargets = c("Doench2014", "Doench2016")[1],
ontargetmethod = c("Doench2014", "Doench2016")[1],
offtargetmethod = c("bowtie", "vcountpdict")[1],
offtargetfilterby = character(0),
subtract_targets = FALSE,
mismatches = 2,
mismatches = 3,
indexedgenomesdir = INDEXEDGENOMESDIR,
outdir = OUTDIR,
verbose = TRUE,
......@@ -32,10 +33,12 @@ find_spacers(
\item{complement}{TRUE (default) or FALSE: also search in compl ranges?}
\item{ontargets}{'Doench2016' or 'Doench2016': on-target scoring method}
\item{ontargetmethod}{'Doench2016' or 'Doench2016': on-target scoring method}
\item{offtargetmethod}{'bowtie' (default) or 'vcountpdict'}
\item{offtargetfilterby}{filter for best off-target counts by this variable}
\item{subtract_targets}{TRUE or FALSE (default): whether to subtract target
(mis)matches from offtarget counts}
......@@ -81,6 +84,7 @@ Find crispr spacers in targetranges
bsgenome <- BSgenome.Mmusculus.UCSC.mm10::BSgenome.Mmusculus.UCSC.mm10
bedfile <- system.file('extdata/SRF.bed', package='multicrispr')
gr <- bed_to_granges(bedfile, 'mm10') \%>\% extend()
gr \%<>\% extract(1:100)
find_spacers(gr, bsgenome, subtract_targets = TRUE)
}
\seealso{
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/07_add_offtargets.R
% Please edit documentation in R/07_count_offtargets.R
\name{has_been_indexed}
\alias{has_been_indexed}
\title{Has been indexed?}
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/07_add_offtargets.R
% Please edit documentation in R/07_count_offtargets.R
\name{index_genome}
\alias{index_genome}
\title{Index genome}
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/07_add_offtargets.R
% Please edit documentation in R/07_count_offtargets.R
\name{index_targets}
\alias{index_targets}
\title{Index targets}
......
......@@ -162,14 +162,15 @@ invisible(double_flank(targets, -200, -1, +1, +200, plot = TRUE))
```
## Find spacers
## Find spacers, count off-targets, score on-targets, find nickspacers
```{r, fig.small = TRUE, out.width = "70%", echo = FALSE }
knitr::include_graphics("../inst/extdata/03_find.png")
```
The next step is to find N20 spacers followed by NGG pam sites.
This can be done with `find_spacers`, after extending target range(s) to prime editing neighbourhood(s):
This can be done with `find_spacers`, after extending target range(s) to prime editing neighbourhood(s).
This function also counts off-targets and scores on-targets.
```{r, fig.width=3, fig.height=1.5}
bsgenome <- BSgenome.Hsapiens.UCSC.hg38::BSgenome.Hsapiens.UCSC.hg38
......@@ -177,43 +178,17 @@ neighbourhood <- extend_for_pe(targets, bsgenome)
spacers <- find_spacers(neighbourhood, bsgenome, complement = FALSE, mismatches = 0)
```
For prime editing, however, it is better to use `find_primespacers`, which performs target to neighbourhood extension implicitly, and also adds 3' extension (Fig 1) to returned spacer GRanges.
For prime editing, however, it is better to use `find_primespacers`, which performs target to neighbourhood extension implicitly, and also finds 3' extensions and nickspacers (Fig 1) to returned spacer GRanges.
```{r, fig.width=3.3, fig.height=1.7}
spacers <- find_primespacers(targets, bsgenome=bsgenome)
```