From 7aaf86bb64c9fd02352bdc0d9a918ae106966910 Mon Sep 17 00:00:00 2001 From: Eirlys Tysall Date: Thu, 24 Oct 2024 14:22:04 +0100 Subject: [PATCH 1/3] Added tests for duplication issue when write gt to vcf using chunking. --- tests/testthat/test_gt_as_vcf.R | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/testthat/test_gt_as_vcf.R b/tests/testthat/test_gt_as_vcf.R index d4827c81..2a041770 100644 --- a/tests/testthat/test_gt_as_vcf.R +++ b/tests/testthat/test_gt_as_vcf.R @@ -43,3 +43,39 @@ test_that("test reading and writing is equivalent",{ expect_true(identical(show_genotypes(pop_a_vcf), show_genotypes(pop_a_vcf_rewrite))) expect_true(identical(show_loci(pop_a_vcf), show_loci(pop_a_vcf_rewrite))) }) + +#TESTS TO SHOW PROBLEM WITH CHUNKING: + +# when read file back in with cpp it lets you read it in despite duplicates so can +# see the issue +test_that("test reading and writing with chunking is equivalent cpp",{ + # write out to vcf with chunk size - smaller chunk size = more duplicates + vcf_path_chunked <- gt_as_vcf(test_gt, file = paste0(tempfile(),".vcf"), chunk_size = 2) + # read vcf back in with cpp + test_gt_chunked <- gen_tibble(vcf_path_chunked, quiet=TRUE, parser = "cpp", backingfile = tempfile("anolis_chunk_")) + # check they are the same + expect_true(identical(show_genotypes(test_gt), show_genotypes(test_gt_chunked))) + expect_true(identical(show_loci(test_gt), show_loci(test_gt_chunked))) + expect_equal(count_loci(test_gt_chunked), count_loci(test_gt)) +}) + +# when read file back in with vcfR it throws an error because of the duplicates +# so wont read in +test_that("test reading and writing with chunking is equivalent rvcf",{ + # write out to vcf with chunk size + vcf_path_chunked <- gt_as_vcf(test_gt, file = paste0(tempfile(),".vcf"), chunk_size = 2) + # read vcf back in with vcfR + test_gt_chunked <- gen_tibble(vcf_path_chunked, quiet=TRUE, parser = "vcfR", backingfile = tempfile("anolis_chunk_")) + # check they are the same + expect_true(identical(show_genotypes(test_gt), show_genotypes(test_gt_chunked))) + expect_true(identical(show_loci(test_gt), show_loci(test_gt_chunked))) + expect_equal(count_loci(test_gt_chunked), count_loci(test_gt)) +}) + + + + + + + + From 9de0f197d462c174614f494b62fc4c9ef1ba40ea Mon Sep 17 00:00:00 2001 From: Andrea Manica Date: Thu, 24 Oct 2024 16:07:35 +0100 Subject: [PATCH 2/3] fix chunking in writing as vcf --- R/gt_as_vcf.R | 15 ++++++++------- tests/testthat/test_gt_as_vcf.R | 11 +++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/R/gt_as_vcf.R b/R/gt_as_vcf.R index b7178feb..b6a35694 100644 --- a/R/gt_as_vcf.R +++ b/R/gt_as_vcf.R @@ -35,11 +35,12 @@ gt_as_vcf <- function(x, file = NULL, chunk_size = NULL, overwrite = FALSE){ } # set up chunks - chunks_vec <- c( - rep(chunk_size, floor(count_loci(x) / chunk_size)), - count_loci(x) %% chunk_size - ) - chunks_vec_index <- c(1,cumsum(chunks_vec)) + chunks_vec <- rep(chunk_size, floor(count_loci(x) / chunk_size)) + if (count_loci(x) %% chunk_size != 0){ + chunks_vec <- c(chunks_vec, count_loci(x) %% chunk_size) + } + chunks_vec_index <- c(0,cumsum(chunks_vec)) + # generate the header vcf_header <- c("##fileformat=VCFv4.3", @@ -68,13 +69,13 @@ gt_as_vcf <- function(x, file = NULL, chunk_size = NULL, overwrite = FALSE){ for (chunk_i in seq_along(chunks_vec)) { genotypes_matrix <- t(show_genotypes(x, loci_indices = - chunks_vec_index[chunk_i]:chunks_vec_index[chunk_i+1])) + (chunks_vec_index[chunk_i]+1):chunks_vec_index[chunk_i+1])) genotypes_matrix[genotypes_matrix==0] <- "0/0" genotypes_matrix[genotypes_matrix==1] <- "0/1" genotypes_matrix[genotypes_matrix==2] <- "1/1" genotypes_matrix[is.na(genotypes_matrix)] <- "./." # subset loci to this chunk - loci_sub <- show_loci(x)[chunks_vec_index[chunk_i]:chunks_vec_index[chunk_i+1],] + loci_sub <- show_loci(x)[(chunks_vec_index[chunk_i]+1):chunks_vec_index[chunk_i+1],] # add the other columns needed for the loci_cols <- c("chromosome", "position", "name", "allele_ref", "allele_alt") loci_sub <- loci_sub %>% select(any_of(loci_cols)) %>% diff --git a/tests/testthat/test_gt_as_vcf.R b/tests/testthat/test_gt_as_vcf.R index 2a041770..66bc25e6 100644 --- a/tests/testthat/test_gt_as_vcf.R +++ b/tests/testthat/test_gt_as_vcf.R @@ -57,6 +57,17 @@ test_that("test reading and writing with chunking is equivalent cpp",{ expect_true(identical(show_genotypes(test_gt), show_genotypes(test_gt_chunked))) expect_true(identical(show_loci(test_gt), show_loci(test_gt_chunked))) expect_equal(count_loci(test_gt_chunked), count_loci(test_gt)) + + # now do the same with chunk size that is not an exact divisor of the number of loci + vcf_path_chunked <- gt_as_vcf(test_gt, file = paste0(tempfile(),".vcf"), chunk_size = 4) + # read vcf back in with cpp + test_gt_chunked <- gen_tibble(vcf_path_chunked, quiet=TRUE, parser = "cpp", backingfile = tempfile("anolis_chunk_")) + # check they are the same + expect_true(identical(show_genotypes(test_gt), show_genotypes(test_gt_chunked))) + expect_true(identical(show_loci(test_gt), show_loci(test_gt_chunked))) + expect_equal(count_loci(test_gt_chunked), count_loci(test_gt)) + + }) # when read file back in with vcfR it throws an error because of the duplicates From bee3aba65f9197ba351fda677d4da02663350073 Mon Sep 17 00:00:00 2001 From: Andrea Manica Date: Thu, 24 Oct 2024 16:53:58 +0100 Subject: [PATCH 3/3] Fix genetic_dist as double --- R/gen_tibble.R | 2 +- data-raw/ideas/allele_sharing.R | 2 +- data-raw/ideas/fst_gt_compare_to_hier.R | 2 +- data-raw/ideas/fst_hier.R | 2 +- data-raw/ideas/fst_wc.R | 2 +- data-raw/ideas/fst_wc2.R | 2 +- data-raw/worked_comparisons/compare_fst.Rmd | 2 +- tests/testthat/test_gen_tibble.R | 14 +++++++------- tests/testthat/test_gen_tibble_save_load.R | 2 +- tests/testthat/test_group_by.R | 2 +- tests/testthat/test_gt_as_.R | 2 +- tests/testthat/test_gt_as_plink.R | 2 +- tests/testthat/test_gt_as_vcf.R | 8 ++------ tests/testthat/test_gt_extract_f2.R | 2 +- tests/testthat/test_indiv_het_obs.R | 4 ++-- tests/testthat/test_indiv_missingness.R | 2 +- tests/testthat/test_loci_freq.R | 4 ++-- tests/testthat/test_loci_ld_clump.R | 4 ++-- tests/testthat/test_loci_missingness.R | 4 ++-- .../testthat/test_loci_transversions_transitions.R | 4 ++-- tests/testthat/test_pairwise_allele_sharing.R | 2 +- tests/testthat/test_pairwise_pop_fst.R | 2 +- tests/testthat/test_pop_basic_stats.R | 2 +- tests/testthat/test_pop_fis_fst.R | 2 +- tests/testthat/test_rbind_gen_tibble.R | 6 +++--- tests/testthat/test_select_loci.R | 2 +- tests/testthat/test_select_loci_if.R | 2 +- tests/testthat/test_show_loci.R | 2 +- tests/testthat/test_snp_ibs.R | 2 +- tests/testthat/test_snp_king.R | 2 +- 30 files changed, 44 insertions(+), 48 deletions(-) diff --git a/R/gen_tibble.R b/R/gen_tibble.R index 8c276811..e10cc100 100644 --- a/R/gen_tibble.R +++ b/R/gen_tibble.R @@ -378,7 +378,7 @@ gt_write_bigsnp_from_dfs <- function(genotypes, indiv_meta, loci, map <- tibble(chromosome = loci$chromosome, marker.ID = loci$name, - genetic.dist = loci$genetic_dist, + genetic.dist = as.double(loci$genetic_dist), ## make sure that genetic.dist is double physical.pos = loci$position, allele1 = loci$allele_alt, allele2 = loci$allele_ref) diff --git a/data-raw/ideas/allele_sharing.R b/data-raw/ideas/allele_sharing.R index 95d94bc9..9a145efa 100644 --- a/data-raw/ideas/allele_sharing.R +++ b/data-raw/ideas/allele_sharing.R @@ -15,7 +15,7 @@ test_indiv_meta <- data.frame (id=c("a","b","c"), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/data-raw/ideas/fst_gt_compare_to_hier.R b/data-raw/ideas/fst_gt_compare_to_hier.R index 7cba7867..73d4ce09 100644 --- a/data-raw/ideas/fst_gt_compare_to_hier.R +++ b/data-raw/ideas/fst_gt_compare_to_hier.R @@ -10,7 +10,7 @@ test_indiv_meta <- data.frame (id=c("a","b","c","d","e","f","g"), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/data-raw/ideas/fst_hier.R b/data-raw/ideas/fst_hier.R index 82f28be4..56ddf1b7 100644 --- a/data-raw/ideas/fst_hier.R +++ b/data-raw/ideas/fst_hier.R @@ -12,7 +12,7 @@ test_indiv_meta <- data.frame (id=c("a","b","c","d","e","f","g"), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/data-raw/ideas/fst_wc.R b/data-raw/ideas/fst_wc.R index 3963e83c..e19bade2 100644 --- a/data-raw/ideas/fst_wc.R +++ b/data-raw/ideas/fst_wc.R @@ -10,7 +10,7 @@ test_indiv_meta <- data.frame (id=c("a","b","c","d","e","f","g"), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/data-raw/ideas/fst_wc2.R b/data-raw/ideas/fst_wc2.R index 3963e83c..e19bade2 100644 --- a/data-raw/ideas/fst_wc2.R +++ b/data-raw/ideas/fst_wc2.R @@ -10,7 +10,7 @@ test_indiv_meta <- data.frame (id=c("a","b","c","d","e","f","g"), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/data-raw/worked_comparisons/compare_fst.Rmd b/data-raw/worked_comparisons/compare_fst.Rmd index 382b7f19..3b4536a5 100644 --- a/data-raw/worked_comparisons/compare_fst.Rmd +++ b/data-raw/worked_comparisons/compare_fst.Rmd @@ -25,7 +25,7 @@ test_indiv_meta <- data.frame (id=c("a","b","c","d","e","f","g"), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/tests/testthat/test_gen_tibble.R b/tests/testthat/test_gen_tibble.R index 51c55148..8cf18701 100644 --- a/tests/testthat/test_gen_tibble.R +++ b/tests/testthat/test_gen_tibble.R @@ -7,7 +7,7 @@ test_genotypes <- rbind(c(1,1,0,1,1,0), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) @@ -112,7 +112,7 @@ test_that("gen_tibble loci is dataframe or tbl",{ 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) wrong_loci_matrix <- as.matrix(test_loci) @@ -150,7 +150,7 @@ test_that("gen_tibble identifies wrong loci table columns",{ wrong_loci <- data.frame(a=paste0("rs",1:6), b=paste0("chr",c(1,1,1,1,2,2)), c=as.integer(c(3,5,65,343,23,456)), - d = as.integer(rep(0,6)), + d = as.double(rep(0,6)), e = c("A","T","C","G","C","T"), f = c("T","C", NA,"C","G","A")) expect_error(test_dfs_gt <- gen_tibble(test_genotypes, indiv_meta = test_indiv_meta, @@ -437,7 +437,7 @@ test_genotypes <- rbind(c(1,1,0,1,1,0), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) @@ -492,7 +492,7 @@ test_that("chr_int is always an integer",{ test_loci_fac <- data.frame(name=paste0("rs",1:6), chromosome=as.factor(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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) test_gt <- gen_tibble(x = test_genotypes, loci = test_loci_fac, indiv_meta = test_indiv_meta, quiet = TRUE) @@ -531,7 +531,7 @@ test_genotypes <- rbind(c(1,1,0,1,1,0), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) @@ -590,7 +590,7 @@ test_that("additional vcf tests with larger file",{ # 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)), +# genetic_dist = as.double(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 diff --git a/tests/testthat/test_gen_tibble_save_load.R b/tests/testthat/test_gen_tibble_save_load.R index e74df9a1..e4065ebe 100644 --- a/tests/testthat/test_gen_tibble_save_load.R +++ b/tests/testthat/test_gen_tibble_save_load.R @@ -7,7 +7,7 @@ test_genotypes <- rbind(c(1,1,0,1,1,0), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/tests/testthat/test_group_by.R b/tests/testthat/test_group_by.R index d5494b5f..8c439f41 100644 --- a/tests/testthat/test_group_by.R +++ b/tests/testthat/test_group_by.R @@ -7,7 +7,7 @@ test_genotypes <- rbind(c(1,1,0,1,1,0), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/tests/testthat/test_gt_as_.R b/tests/testthat/test_gt_as_.R index bc8196f4..212b0c84 100644 --- a/tests/testthat/test_gt_as_.R +++ b/tests/testthat/test_gt_as_.R @@ -11,7 +11,7 @@ test_that("show_loci gets and sets information",{ 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/tests/testthat/test_gt_as_plink.R b/tests/testthat/test_gt_as_plink.R index 85dcd28f..6605e09c 100644 --- a/tests/testthat/test_gt_as_plink.R +++ b/tests/testthat/test_gt_as_plink.R @@ -7,7 +7,7 @@ test_genotypes <- rbind(c(1,1,0,1,1,0), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/tests/testthat/test_gt_as_vcf.R b/tests/testthat/test_gt_as_vcf.R index 66bc25e6..6ef24d38 100644 --- a/tests/testthat/test_gt_as_vcf.R +++ b/tests/testthat/test_gt_as_vcf.R @@ -8,7 +8,7 @@ test_genotypes <- rbind(c(1,1,0,1,1,0), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) @@ -44,10 +44,7 @@ test_that("test reading and writing is equivalent",{ expect_true(identical(show_loci(pop_a_vcf), show_loci(pop_a_vcf_rewrite))) }) -#TESTS TO SHOW PROBLEM WITH CHUNKING: -# when read file back in with cpp it lets you read it in despite duplicates so can -# see the issue test_that("test reading and writing with chunking is equivalent cpp",{ # write out to vcf with chunk size - smaller chunk size = more duplicates vcf_path_chunked <- gt_as_vcf(test_gt, file = paste0(tempfile(),".vcf"), chunk_size = 2) @@ -70,8 +67,7 @@ test_that("test reading and writing with chunking is equivalent cpp",{ }) -# when read file back in with vcfR it throws an error because of the duplicates -# so wont read in + test_that("test reading and writing with chunking is equivalent rvcf",{ # write out to vcf with chunk size vcf_path_chunked <- gt_as_vcf(test_gt, file = paste0(tempfile(),".vcf"), chunk_size = 2) diff --git a/tests/testthat/test_gt_extract_f2.R b/tests/testthat/test_gt_extract_f2.R index 3cee3c69..2ef26596 100644 --- a/tests/testthat/test_gt_extract_f2.R +++ b/tests/testthat/test_gt_extract_f2.R @@ -10,7 +10,7 @@ test_indiv_meta <- data.frame (id=c("a","b","c","d","e","f","g"), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/tests/testthat/test_indiv_het_obs.R b/tests/testthat/test_indiv_het_obs.R index 190ff05e..5d2ecea2 100644 --- a/tests/testthat/test_indiv_het_obs.R +++ b/tests/testthat/test_indiv_het_obs.R @@ -7,7 +7,7 @@ test_that("indiv_het_obs computes correctly",{ test_loci <- data.frame(name=paste0("rs",1:6), chromosome=c(1,1,1,1,2,2), position=c(3,5,65,343,23,456), - genetic_dist = as.integer(rep(0,6)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) @@ -33,7 +33,7 @@ test_that("indiv_het_obs returns 0's when all genotypes are homozygous", { test_loci <- data.frame(name=paste0("rs",1:6), chromosome=c(1,1,1,1,2,2), position=c(3,5,65,343,23,456), - genetic_dist = as.integer(rep(0,6)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/tests/testthat/test_indiv_missingness.R b/tests/testthat/test_indiv_missingness.R index 249b4e27..a6ca0091 100644 --- a/tests/testthat/test_indiv_missingness.R +++ b/tests/testthat/test_indiv_missingness.R @@ -6,7 +6,7 @@ test_genotypes <- rbind(c(1,1,0,1,1,2), test_loci <- data.frame(name=paste0("rs",1:6), chromosome=c(1,1,1,1,2,2), position=c(3,5,65,343,23,456), - genetic_dist = as.integer(rep(0,6)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/tests/testthat/test_loci_freq.R b/tests/testthat/test_loci_freq.R index 4e66133f..32089cb8 100644 --- a/tests/testthat/test_loci_freq.R +++ b/tests/testthat/test_loci_freq.R @@ -7,7 +7,7 @@ test_that("loci_alt_freq and loci_maf computes correctly",{ test_loci <- data.frame(name=paste0("rs",1:6), chromosome=c(1,1,1,1,2,2), position=c(3,5,65,343,23,456), - genetic_dist = as.integer(rep(0,6)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) test_gt <- gen_tibble(x = test_genotypes, loci = test_loci, indiv_meta = test_indiv_meta, quiet = TRUE) @@ -77,7 +77,7 @@ test_that("loci_alt_freq and loci_maf on grouped tibbles",{ 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/tests/testthat/test_loci_ld_clump.R b/tests/testthat/test_loci_ld_clump.R index 5efb9496..475352e9 100644 --- a/tests/testthat/test_loci_ld_clump.R +++ b/tests/testthat/test_loci_ld_clump.R @@ -6,7 +6,7 @@ test_genotypes <- rbind(c(2,2,0,1,1,2), test_loci <- data.frame(name=paste0("rs",1:6), chromosome=c(1,1,1,1,2,2), position=c(3,5,65,343,23,456), - genetic_dist = as.integer(rep(0,6)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) @@ -99,7 +99,7 @@ test_that("loci order",{ test_loci <- data.frame(name=paste0("rs",1:6), chromosome=c("chr2","chr1","chr1","chr1","chr2","chr1"), position=c(3,5,65,343,23,456), - genetic_dist = as.integer(rep(0,6)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/tests/testthat/test_loci_missingness.R b/tests/testthat/test_loci_missingness.R index 5bc03516..e167dcf2 100644 --- a/tests/testthat/test_loci_missingness.R +++ b/tests/testthat/test_loci_missingness.R @@ -7,7 +7,7 @@ test_that("loci_missingness",{ test_loci <- data.frame(name=paste0("rs",1:6), chromosome=c(1,1,1,1,2,2), position=c(3,5,65,343,23,456), - genetic_dist = as.integer(rep(0,6)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) @@ -48,7 +48,7 @@ test_that("loci_missingness on grouped tibble",{ 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/tests/testthat/test_loci_transversions_transitions.R b/tests/testthat/test_loci_transversions_transitions.R index f091f7f5..223eaf61 100644 --- a/tests/testthat/test_loci_transversions_transitions.R +++ b/tests/testthat/test_loci_transversions_transitions.R @@ -7,7 +7,7 @@ test_that("find transitions and transversions",{ test_loci <- data.frame(name=paste0("rs",1:6), chromosome=c(1,1,1,1,2,2), position=c(3,5,65,343,23,456), - genetic_dist = as.integer(rep(0,6)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) @@ -26,7 +26,7 @@ test_that("check warning message for different alleles",{ test_loci <- data.frame(name=paste0("rs",1:6), chromosome=c(1,1,1,1,2,2), position=c(3,5,65,343,23,456), - genetic_dist = as.integer(rep(0,6)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("a","t","c","g","c","t"), allele_alt = c("t","c", NA,"c","g","a")) diff --git a/tests/testthat/test_pairwise_allele_sharing.R b/tests/testthat/test_pairwise_allele_sharing.R index 4075bbd8..26316438 100644 --- a/tests/testthat/test_pairwise_allele_sharing.R +++ b/tests/testthat/test_pairwise_allele_sharing.R @@ -6,7 +6,7 @@ test_indiv_meta <- data.frame (id=c("a","b","c"), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/tests/testthat/test_pairwise_pop_fst.R b/tests/testthat/test_pairwise_pop_fst.R index f8ed5108..f5164aec 100644 --- a/tests/testthat/test_pairwise_pop_fst.R +++ b/tests/testthat/test_pairwise_pop_fst.R @@ -10,7 +10,7 @@ test_indiv_meta <- data.frame (id=c("a","b","c","d","e","f","g"), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/tests/testthat/test_pop_basic_stats.R b/tests/testthat/test_pop_basic_stats.R index 78af26a1..af41c365 100644 --- a/tests/testthat/test_pop_basic_stats.R +++ b/tests/testthat/test_pop_basic_stats.R @@ -10,7 +10,7 @@ test_indiv_meta <- data.frame (id=c("a","b","c","d","e","f","g"), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/tests/testthat/test_pop_fis_fst.R b/tests/testthat/test_pop_fis_fst.R index 48b910f9..b6835500 100644 --- a/tests/testthat/test_pop_fis_fst.R +++ b/tests/testthat/test_pop_fis_fst.R @@ -10,7 +10,7 @@ test_indiv_meta <- data.frame (id=c("a","b","c","d","e","f","g"), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/tests/testthat/test_rbind_gen_tibble.R b/tests/testthat/test_rbind_gen_tibble.R index 319b755c..da1bfbed 100644 --- a/tests/testthat/test_rbind_gen_tibble.R +++ b/tests/testthat/test_rbind_gen_tibble.R @@ -54,7 +54,7 @@ test_that("warning when no snps overlap",{ test_loci <- data.frame(name=paste0("rs",1:6), chromosome=c(1,1,1,1,2,2), position=c(3,5,65,343,23,456), - genetic_dist = as.integer(rep(0,6)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) test_gt <- gen_tibble(x = test_genotypes, loci = test_loci, indiv_meta = test_indiv_meta, quiet = TRUE) @@ -68,7 +68,7 @@ test_that("warning when no snps overlap",{ test_loci2 <- data.frame(name=paste0("rs",7:12), chromosome=c(1,1,1,1,2,2), position=c(3,5,65,343,23,456), - genetic_dist = as.integer(rep(0,6)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) test_gt2 <- gen_tibble(x = test_genotypes2, loci = test_loci2, indiv_meta = test_indiv_meta2, quiet = TRUE) @@ -93,7 +93,7 @@ test_that("warning when no snps overlap",{ test_loci2 <- data.frame(name=paste0("rs",1:6), chromosome=c(3,3,3,3,4,4), position=c(3,5,65,343,23,456), - genetic_dist = as.integer(rep(0,6)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) test_gt2 <- gen_tibble(x = test_genotypes2, loci = test_loci2, indiv_meta = test_indiv_meta2, quiet = TRUE) diff --git a/tests/testthat/test_select_loci.R b/tests/testthat/test_select_loci.R index a4136e9d..df602ae4 100644 --- a/tests/testthat/test_select_loci.R +++ b/tests/testthat/test_select_loci.R @@ -7,7 +7,7 @@ test_that("select_loci subsets correctly",{ test_loci <- data.frame(name=c(paste0("rs",1:4),paste0("x",1:2)), chromosome=c(1,1,1,1,2,2), position=c(3,5,65,343,23,456), - genetic_dist = as.integer(rep(0,6)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/tests/testthat/test_select_loci_if.R b/tests/testthat/test_select_loci_if.R index 078a77a1..6be55bfa 100644 --- a/tests/testthat/test_select_loci_if.R +++ b/tests/testthat/test_select_loci_if.R @@ -7,7 +7,7 @@ test_that("select_loci_if subsets correctly",{ test_loci <- data.frame(name=c(paste0("rs",1:4),paste0("x",1:2)), chromosome=c(1,1,1,1,2,2), position=c(3,5,65,343,23,456), - genetic_dist = as.integer(rep(0,6)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/tests/testthat/test_show_loci.R b/tests/testthat/test_show_loci.R index 6e6d3027..283ac26b 100644 --- a/tests/testthat/test_show_loci.R +++ b/tests/testthat/test_show_loci.R @@ -7,7 +7,7 @@ test_that("show_loci gets and sets information",{ test_loci <- data.frame(name=c(paste0("rs",1:4),paste0("x",1:2)), chromosome=as.integer(c(1,1,1,1,2,2)), position=as.integer(c(3,5,65,343,23,456)), - genetic_dist = as.integer(rep(0,6)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/tests/testthat/test_snp_ibs.R b/tests/testthat/test_snp_ibs.R index 56294f4e..67dce6a0 100644 --- a/tests/testthat/test_snp_ibs.R +++ b/tests/testthat/test_snp_ibs.R @@ -7,7 +7,7 @@ test_genotypes <- rbind(c(1,1,0,1,1,0), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A")) diff --git a/tests/testthat/test_snp_king.R b/tests/testthat/test_snp_king.R index a8efeb98..6ff10b6f 100644 --- a/tests/testthat/test_snp_king.R +++ b/tests/testthat/test_snp_king.R @@ -7,7 +7,7 @@ test_genotypes <- rbind(c(1,1,0,1,1,0), 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)), + genetic_dist = as.double(rep(0,6)), allele_ref = c("A","T","C","G","C","T"), allele_alt = c("T","C", NA,"C","G","A"))