diff --git a/R/AllGenerics.R b/R/AllGenerics.R deleted file mode 100644 index e8fbc6f..0000000 --- a/R/AllGenerics.R +++ /dev/null @@ -1,51 +0,0 @@ -#' Annotate known SNP positions -#' -#' @description This function will annotate a [GRanges] or the rowRanges of -#' a [SummarizedExperiment] with SNPs from a SNP package. -#' -#' @param obj GRanges or SummarizedExperiment object -#' @param dbsnp SNPlocs package, see available packages from -#' [BSgenome::available.SNPs()] -#' @param chrom only operate on a specified chromosome -#' @param col_to_aggr column from SNPlocs package to add to -#' input. If multiple SNPs overlap these values will be concatenated -#' as comma separated values. -#' @param genome A BSgenome object, which if supplied, will be used to provide -#' additional `snp_ref_allele` and `snp_alt_alleles` columns containing the -#' reference and alt allele sequences, with respect to the positive strand. -#' Additionally the snp sequences will be checked against the allele at the site -#' if a column named `ALT` is present in object. The strand of the site will be -#' used to determine if the `ALT` allele needs to be complemented prior to -#' comparing against the SNP db (which always returns sequences w.r.t the -#' plus strand). -#' @param drop If TRUE, remove sites overlapping SNPs -#' @param RLE If TRUE, columns added will returned as [S4Vectors::Rle()] vectors -#' to reduce memory -#' -#' @param ... For the generic, further arguments to pass to specific methods. -#' Unused for now. -#' -#' @return Either a GRanges or SummarizedExperiment object with -#' a new column added with information from `col_to_aggr` and optionally -#' `snp_ref_allele`, `snp_alt_alleles`, and `snp_matches_site` annotations. -#' -#' @examples -#' if (require(SNPlocs.Hsapiens.dbSNP144.GRCh38)) { -#' gr <- GRanges(rep("22", 10), -#' IRanges( -#' seq(10510077, -#' 10610077, -#' by = 1000 -#' )[1:10], -#' width = 250 -#' ), -#' strand = "+" -#' ) -#' genome(gr) <- "GRCh38.p2" -#' annot_snps(gr, SNPlocs.Hsapiens.dbSNP144.GRCh38) -#' } -#' @seealso [SNPlocs.Hsapiens.dbSNP144.GRCh38](https://bioconductor.org/packages/release/data/annotation/html/SNPlocs.Hsapiens.dbSNP144.GRCh38.html) -#' @export -annot_snps <- function(obj, ...) { - UseMethod("annot_snps", obj) -} diff --git a/R/annot_rse.R b/R/annot_rse.R index a0a7183..28196c2 100644 --- a/R/annot_rse.R +++ b/R/annot_rse.R @@ -1,3 +1,56 @@ +#' Annotate known SNP positions +#' +#' @description This function will annotate a [GRanges] or the rowRanges of +#' a [SummarizedExperiment] with SNPs from a SNP package. +#' +#' @param obj GRanges or SummarizedExperiment object +#' @param dbsnp SNPlocs package, see available packages from +#' [BSgenome::available.SNPs()] +#' @param chrom only operate on a specified chromosome +#' @param col_to_aggr column from SNPlocs package to add to +#' input. If multiple SNPs overlap these values will be concatenated +#' as comma separated values. +#' @param genome A BSgenome object, which if supplied, will be used to provide +#' additional `snp_ref_allele` and `snp_alt_alleles` columns containing the +#' reference and alt allele sequences, with respect to the positive strand. +#' Additionally the snp sequences will be checked against the allele at the site +#' if a column named `ALT` is present in object. The strand of the site will be +#' used to determine if the `ALT` allele needs to be complemented prior to +#' comparing against the SNP db (which always returns sequences w.r.t the +#' plus strand). +#' @param drop If TRUE, remove sites overlapping SNPs +#' @param RLE If TRUE, columns added will returned as [S4Vectors::Rle()] vectors +#' to reduce memory +#' +#' @param ... For the generic, further arguments to pass to specific methods. +#' Unused for now. +#' +#' @return Either a GRanges or SummarizedExperiment object with +#' a new column added with information from `col_to_aggr` and optionally +#' `snp_ref_allele`, `snp_alt_alleles`, and `snp_matches_site` annotations. +#' +#' @examples +#' if (require(SNPlocs.Hsapiens.dbSNP144.GRCh38)) { +#' gr <- GRanges(rep("22", 10), +#' IRanges( +#' seq(10510077, +#' 10610077, +#' by = 1000 +#' )[1:10], +#' width = 250 +#' ), +#' strand = "+" +#' ) +#' genome(gr) <- "GRCh38.p2" +#' annot_snps(gr, SNPlocs.Hsapiens.dbSNP144.GRCh38) +#' } +#' @seealso [SNPlocs.Hsapiens.dbSNP144.GRCh38](https://bioconductor.org/packages/release/data/annotation/html/SNPlocs.Hsapiens.dbSNP144.GRCh38.html) +#' @export +annot_snps <- function(obj, ...) { + UseMethod("annot_snps", obj) +} + + #' @rdname annot_snps #' @importFrom BSgenome snpsByOverlaps #' @export diff --git a/R/pileup.R b/R/pileup.R index 4fe6e42..03d4874 100644 --- a/R/pileup.R +++ b/R/pileup.R @@ -151,12 +151,7 @@ pileup_sites <- function(bamfiles, ## set default bam flags if not supplied if (identical(param@bam_flags, Rsamtools::scanBamFlag())) { - param@bam_flags <- Rsamtools::scanBamFlag( - isSecondaryAlignment = FALSE, - isNotPassingQualityCont = FALSE, - isDuplicate = FALSE, - isSupplementaryAlignment = FALSE - ) + param@bam_flags <- defaultBulkBamFlags } fp <- cfilterParam(param, n_files) @@ -304,6 +299,14 @@ setup_valid_regions <- function(bam, chroms, region = NULL, fasta = NULL) { # IRanges/GRanges are limited to this max int MAX_INT <- 536870912 +defaultBulkBamFlags <- Rsamtools::scanBamFlag( + isSecondaryAlignment = FALSE, + isNotPassingQualityCont = FALSE, + isDuplicate = FALSE, + isSupplementaryAlignment = FALSE +) + + # parses a region string (e.g. "chr1:456-567" or "chr1") # using htslib into chrom, start, and end (0-based start) # returns a list with chrom, start, and end entries diff --git a/R/sc-pileup.R b/R/sc-pileup.R index 19da8ff..47448e1 100644 --- a/R/sc-pileup.R +++ b/R/sc-pileup.R @@ -155,15 +155,10 @@ pileup_cells <- function(bamfiles, ## set default bam flags if not supplied if (identical(param@bam_flags, Rsamtools::scanBamFlag())) { - param@bam_flags <- Rsamtools::scanBamFlag( - isSecondaryAlignment = FALSE, - isSupplementaryAlignment = FALSE, - isNotPassingQualityControls = FALSE - ) + param@bam_flags <- defaultScBamFlags } cell_barcodes <- cell_barcodes[!is.na(cell_barcodes)] - cb_tag <- check_tag(cb_tag) umi_tag <- check_tag(umi_tag) @@ -255,6 +250,12 @@ pileup_cells <- function(bamfiles, res } +defaultScBamFlags <- Rsamtools::scanBamFlag( + isSecondaryAlignment = FALSE, + isSupplementaryAlignment = FALSE, + isNotPassingQualityControls = FALSE +) + get_sc_pileup <- function(bamfn, index, id, sites, barcodes, outfile_prefix, chrom, umi_tag, cb_tag, param, diff --git a/man/annot_snps.Rd b/man/annot_snps.Rd index c5249ca..758580d 100644 --- a/man/annot_snps.Rd +++ b/man/annot_snps.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/AllGenerics.R, R/annot_rse.R +% Please edit documentation in R/annot_rse.R \name{annot_snps} \alias{annot_snps} \alias{annot_snps.GRanges}