Skip to content

Commit

Permalink
move single generic into annot_rse
Browse files Browse the repository at this point in the history
  • Loading branch information
kriemo committed Sep 10, 2023
1 parent c98d3ee commit 8ab8443
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 64 deletions.
51 changes: 0 additions & 51 deletions R/AllGenerics.R

This file was deleted.

53 changes: 53 additions & 0 deletions R/annot_rse.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 9 additions & 6 deletions R/pileup.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions R/sc-pileup.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion man/annot_snps.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8ab8443

Please sign in to comment.