Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
smped committed Apr 5, 2024
1 parent eae2957 commit 0d1bcc7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions R/helpers.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#' @keywords internal
#' @importFrom Biostrings IUPAC_CODE_MAP
#' @importFrom S4Vectors mcols mcols<-
.checkAlts <- function(var, alt_col) {
.checkAlts <- function(var, alt_col, ref_col = "REF") {

alt_col <- match.arg(alt_col, colnames(mcols(var)))
alts <- mcols(var)[[alt_col]]
if (is(alts, "XStringSetList")) alts <- as.character(unlist(alts))

## Check duplicate loci
dup <- duplicated(var)
err <- c()
dup <- duplicated(var)
if (any(dup))
err <- c(
err, "Duplicate variant loci found. Please choose which one to use"
Expand Down
9 changes: 5 additions & 4 deletions R/varTypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
#' @importFrom IRanges width
#' @export
varTypes <- function(x, alt_col = "ALT", ...){

## x should be a GRanges object with variants
stopifnot(is(x, "GRanges"))
stopifnot(alt_col %in% colnames(mcols(x)))
x <- .checkAlts(x, alt_col)

## Basic info
w <- width(x)
Expand All @@ -53,11 +54,11 @@ varTypes <- function(x, alt_col = "ALT", ...){

## Classify each range
snv <- w == 1 & alt_width == 1
ins <- alt_width > w
dels <- w > alt_width
ins <- alt_width > w & w == 1
dels <- w > alt_width & alt_width == 1
## All should add up to the total
if (sum(snv + ins + dels) != n)
stop("Some variants were unable to be uniquely identified")
stop("Some variants were unable to be identified as SNVs or InDels")

## Return output
out <- character(n)
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test_varTypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ test_that("varTypes errors as expected", {
type <- varTypes(var)
width(var)[type == "Insertion"] <- 2
expect_error(varTypes(var), "Some variants.+")
var$ALT <- 1
expect_error(varTypes(var), ".+is not TRUE")

})
8 changes: 8 additions & 0 deletions vignettes/creating_a_new_reference.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ Whilst the subsequent code is demonstrated on a small genomic region, the
complete process for creating a modified a reference can run in under 20 minutes
if using 4 or more cores.

Importantly, it is expected that the user will have carefully prepared their set of variants such that only the following exact variant types are included.

- **SNV**/**SNP**: The associated range must be of width 1 with a single base as the replacement allele
- **Insertions**: The position being replaced must be a single nucleotide with the replacement bases being > 1nt
- **Deletions**: The position being replaced must be > 1nt, whilst the replacement allele must be a single base

Any variants which do not conform to these criteria will likely cause a series of frustrating errors when attempting to use this package.

# Setup

## Installation
Expand Down

0 comments on commit 0d1bcc7

Please sign in to comment.