From 7947a54dddece0ab3e6f9aa55427539916ea7bc1 Mon Sep 17 00:00:00 2001 From: Zilong-Li Date: Mon, 26 Feb 2024 12:37:58 +0100 Subject: [PATCH] v0.4.0 --- DESCRIPTION | 4 ++-- NEWS.md | 5 +++++ R/vcf-tables.R | 5 ++++- cran-comments.md | 4 +--- man/vcftable.Rd | 5 ++++- tests/testthat/test-vcf-table.R | 5 +++++ 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 751d1f4..c3ad394 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", , "zilong.dk@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-5859-2078")), @@ -11,7 +11,7 @@ Description: The 'vcfpp.h' () 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 diff --git a/NEWS.md b/NEWS.md index ca5f10a..4e8b2dc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/vcf-tables.R b/R/vcf-tables.R index 2551ab0..78ae6b7 100644 --- a/R/vcf-tables.R +++ b/R/vcf-tables.R @@ -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 @@ -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 @@ -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) } diff --git a/cran-comments.md b/cran-comments.md index c174243..2948016 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -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 diff --git a/man/vcftable.Rd b/man/vcftable.Rd index 63167da..5f61d03 100644 --- a/man/vcftable.Rd +++ b/man/vcftable.Rd @@ -14,7 +14,8 @@ vcftable( qual = 0, pass = FALSE, info = TRUE, - collapse = TRUE + collapse = TRUE, + setid = FALSE ) } \arguments{ @@ -43,6 +44,8 @@ where M is #markers and N is #samples. default TRUE will collapse the genotypes Set this to FALSE if one wants to maintain the phasing order, e.g. "1|0" is parsed as c(1, 0) with collapse=FALSE. 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.} + +\item{setid}{logical. reset ID column as CHR_POS_REF_ALT.} } \value{ Return a list containing the following components: diff --git a/tests/testthat/test-vcf-table.R b/tests/testthat/test-vcf-table.R index acfbe81..d330762 100644 --- a/tests/testthat/test-vcf-table.R +++ b/tests/testthat/test-vcf-table.R @@ -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)