Skip to content

Commit

Permalink
v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Zilong-Li committed Feb 26, 2024
1 parent ba21da9 commit 7947a54
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: vcfppR
Title: Rapid Manipulation of the Variant Call Format (VCF)
Version: 0.3.8
Version: 0.4.0
Authors@R: c(
person("Zilong", "Li", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-5859-2078")),
Expand All @@ -11,7 +11,7 @@ Description: The 'vcfpp.h' (<https://github.com/Zilong-Li/vcfpp>) provides an ea
Encoding: UTF-8
Depends: R (>= 3.6.0)
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# vcfppR 0.4.0

* add `setid` option for vcftable
* patches for upcoming Rtools on windows

# vcfppR 0.3.8

* fix issues on M1 Mac
Expand Down
5 changes: 4 additions & 1 deletion R/vcf-tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#' If the FORMAT to extract is not "GT", then with collapse=TRUE it will try to turn a list of the extracted vector into a matrix.
#' However, this raises issues when one variant is mutliallelic resulting in more vaules than others.
#'
#' @param setid logical. reset ID column as CHR_POS_REF_ALT.
#'
#' @return Return a list containing the following components:
#'\describe{
#'\item{samples}{: character vector; \cr
Expand Down Expand Up @@ -87,7 +89,7 @@
#' str(res)
#' @export
vcftable <- function(vcffile, region = "", samples = "-", vartype = "all", format = "GT", ids = NULL,
qual = 0, pass = FALSE, info = TRUE, collapse = TRUE) {
qual = 0, pass = FALSE, info = TRUE, collapse = TRUE, setid = FALSE) {
snps <- FALSE
indels <- FALSE
svs <- FALSE
Expand Down Expand Up @@ -117,6 +119,7 @@ vcftable <- function(vcffile, region = "", samples = "-", vartype = "all", forma
res <- tableFormat(vcffile, region, samples, format, ids, qual, pass, info, snps, indels, multiallelics, multisnps, svs)
if(is.list(res[[10]]) && collapse) res[[10]] <- do.call("rbind", res[[10]])
}
if(setid) res$id <- paste(res$chr, res$pos, res$ref, res$alt, sep = "_")
return(res)
}

4 changes: 1 addition & 3 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
Fix issues on M1 Mac

https://cran.r-project.org/web/checks/check_results_vcfppR.html
Fix issue for upcoming Rtools on windows

5 changes: 4 additions & 1 deletion man/vcftable.Rd

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

5 changes: 5 additions & 0 deletions tests/testthat/test-vcf-table.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ test_that("extract GT for all SNPs", {
expect_identical(sum(res$alt!=""), length(res$alt))
})

test_that("extract SNPs by ID and reset ID afterwards", {
res <- vcftable(vcffile, vartype = "snps", id = c("chr21:5030516:G:A"), setid = TRUE)
expect_identical(res$id, "chr21_5030516_G_A")
})

test_that("extract GT for a indel with FILTER not displaying PASS", {
res <- vcftable(vcffile, id = c("chr21:5030240:AC:A"), vartype = "indels", pass = TRUE)
expect_equal(length(res$gt), 0)
Expand Down

0 comments on commit 7947a54

Please sign in to comment.