Skip to content

Commit

Permalink
Use cpp parser by default to read vcf
Browse files Browse the repository at this point in the history
Fix #6
  • Loading branch information
dramanica committed Sep 13, 2024
1 parent ae11cf4 commit 7c5ef31
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
3 changes: 0 additions & 3 deletions R/gen_tibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ gen_tibble.character <-

# parser for vcf
parser <- match.arg(parser)
if (parser=="cpp"){
message("The cpp parser is still experimental, use vcfR for serious work")
}

# check that valid alleles does not contain zero
if ("0" %in% valid_alleles){
Expand Down
3 changes: 2 additions & 1 deletion R/gen_tibble_vcf.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# read in a vcf
gen_tibble_vcf <- function(x, ..., parser = "vcfR",
gen_tibble_vcf <- function(x, ..., parser = "cpp",
chunk_size = NULL,
valid_alleles = c("A", "T", "C", "G"),
missing_alleles = c("0","."),
backingfile = NULL, quiet = FALSE) {
parser <- match.arg(parser, c("vcfR", "cpp"))
if (parser == "cpp"){
rds_path <- vcf_to_fbm_cpp(x,
backingfile = backingfile,
Expand Down
58 changes: 30 additions & 28 deletions tests/testthat/test_gen_tibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ test_that("gen_tibble from files",{
# PLINK VCF files
########################
vcf_path <- system.file("extdata/pop_a.vcf", package = "tidypopgen")
pop_a_vcf_gt <- gen_tibble(vcf_path, quiet=TRUE,backingfile = tempfile())
pop_a_vcf_gt <- gen_tibble(vcf_path, quiet=TRUE,backingfile = tempfile(), parser="vcfR")
expect_true(all.equal(show_genotypes(pop_a_gt),show_genotypes(pop_a_vcf_gt)))
# reload it in chunks
pop_a_vcf_gt2 <- gen_tibble(vcf_path, quiet=TRUE,backingfile = tempfile(),
Expand Down Expand Up @@ -417,30 +417,32 @@ test_that("check summary stats are the same for gen_tibbles read in different wa

})

test_that("on error, we remove the old fils",{
# create file
test_indiv_meta <- data.frame (id=c("a","b","c"),
population = c("pop1","pop1","pop2"))
test_genotypes <- rbind(c(1,1,0,1,1,0),
c(2,1,0,0,0,0),
c(2,2,0,0,1,1))
test_loci <- data.frame(name=paste0("rs",1:6),
chromosome=paste0("chr",c(1,1,1,1,2,2)),
position=as.integer(c(3,5,65,343,23,456)),
genetic_dist = as.integer(rep(0,6)),
allele_ref = c("A","T","C","G","C","T"),
allele_alt = c("T","C", NA,"C","G","A"))
test_loci_wrong <- test_loci
test_loci_wrong$allele_alt[1] <- "N"
this_bkfile <- tempfile()
expect_error(test_dfs_gt <- gen_tibble(test_genotypes, indiv_meta = test_indiv_meta,
loci = test_loci_wrong,
backingfile = this_bkfile,
quiet = TRUE),"valid alleles are")
expect_false(file.exists(paste0(this_bkfile,".bk")))
test_dfs_gt <- gen_tibble(test_genotypes, indiv_meta = test_indiv_meta,
loci = test_loci,
backingfile = this_bkfile,
quiet = TRUE)
expect_true(file.exists(paste0(this_bkfile,".bk")))
})
# Windows prevents the deletion of the backing file. It's something to do with the memory mapping
# library used by bigsnpr
# test_that("on error, we remove the old files",{
# # create file
# test_indiv_meta <- data.frame (id=c("a","b","c"),
# population = c("pop1","pop1","pop2"))
# test_genotypes <- rbind(c(1,1,0,1,1,0),
# c(2,1,0,0,0,0),
# c(2,2,0,0,1,1))
# test_loci <- data.frame(name=paste0("rs",1:6),
# chromosome=paste0("chr",c(1,1,1,1,2,2)),
# position=as.integer(c(3,5,65,343,23,456)),
# genetic_dist = as.integer(rep(0,6)),
# allele_ref = c("A","T","C","G","C","T"),
# allele_alt = c("T","C", NA,"C","G","A"))
# test_loci_wrong <- test_loci
# test_loci_wrong$allele_alt[1] <- "N"
# this_bkfile <- tempfile()
# expect_error(test_dfs_gt <- gen_tibble(test_genotypes, indiv_meta = test_indiv_meta,
# loci = test_loci_wrong,
# backingfile = this_bkfile,
# quiet = TRUE),"valid alleles are")
# expect_false(file.exists(paste0(this_bkfile,".bk")))
# test_dfs_gt <- gen_tibble(test_genotypes, indiv_meta = test_indiv_meta,
# loci = test_loci,
# backingfile = this_bkfile,
# quiet = TRUE)
# expect_true(file.exists(paste0(this_bkfile,".bk")))
# })

0 comments on commit 7c5ef31

Please sign in to comment.