From b5330c33c6948e0a0c15709c8f3b26cf6921977f Mon Sep 17 00:00:00 2001 From: Martin Petr Date: Wed, 6 Dec 2023 13:42:27 +0100 Subject: [PATCH] Write updated test outputs --- tests/testthat/test-msprime-geneflow.R | 58 +++++++++++++------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/testthat/test-msprime-geneflow.R b/tests/testthat/test-msprime-geneflow.R index 53528dfae..90feda51a 100644 --- a/tests/testthat/test-msprime-geneflow.R +++ b/tests/testthat/test-msprime-geneflow.R @@ -137,24 +137,24 @@ df_f4 <- rbind(df_slim_f4, df_msprime_f4) %>% "x2 (no gene flow)")) %>% as.data.frame() -# current_f4_tsv <- paste0(tempfile(), ".tsv.gz") -# readr::write_tsv(df_f4, current_f4_tsv, progress = FALSE) +current_f4_tsv <- paste0(tempfile(), ".tsv.gz") +readr::write_tsv(df_f4, current_f4_tsv, progress = FALSE) original_f4_tsv <- sprintf("f4_%s.tsv.gz", Sys.info()["sysname"]) -# readr::write_tsv(df_f4, original_f4_tsv, progress = FALSE) +readr::write_tsv(df_f4, original_f4_tsv, progress = FALSE) orig_df_f4 <- readr::read_tsv(original_f4_tsv, show_col_types = FALSE, progress = FALSE) %>% as.data.frame() -# library(ggplot2) -# p_f4 <- ggplot(df_f4, aes(f4, fill = population)) + -# geom_histogram(bins = 50) + -# facet_grid(simulator ~ model) + -# geom_vline(xintercept = 0, linetype = 2) + -# labs(y = "number of individuals", x = "f4 statistic", -# title = "f4 statistics calculated on simulated data", -# subtitle = "Note that for f4 values ~0, the hypothesis of no gene flow can't be rejected") + -# theme(legend.position = "bottom") -# png_file <- sprintf("f4_%s.png", Sys.info()["sysname"]) -# ggsave(png_file, p_f4, width = 8, height = 5) +library(ggplot2) +p_f4 <- ggplot(df_f4, aes(f4, fill = population)) + + geom_histogram(bins = 50) + + facet_grid(simulator ~ model) + + geom_vline(xintercept = 0, linetype = 2) + + labs(y = "number of individuals", x = "f4 statistic", + title = "f4 statistics calculated on simulated data", + subtitle = "Note that for f4 values ~0, the hypothesis of no gene flow can't be rejected") + + theme(legend.position = "bottom") +png_file <- sprintf("f4_%s.png", Sys.info()["sysname"]) +ggsave(png_file, p_f4, width = 8, height = 5) test_that("f4 distributions from SLiM and msprime simulations match", { expect_equal(df_f4, orig_df_f4, tolerance = 1e-8) @@ -166,25 +166,25 @@ df_f4ratio <- rbind(df_slim_f4ratio, df_msprime_f4ratio) %>% "x2 (no gene flow)")) %>% as.data.frame() -# current_f4r_tsv <- paste0(tempfile(), ".tsv.gz") -# readr::write_tsv(df_f4ratio, current_f4r_tsv, progress = FALSE) +current_f4r_tsv <- paste0(tempfile(), ".tsv.gz") +readr::write_tsv(df_f4ratio, current_f4r_tsv, progress = FALSE) original_f4r_tsv <- sprintf("f4ratio_%s.tsv.gz", Sys.info()["sysname"]) -# readr::write_tsv(df_f4ratio, original_f4r_tsv, progress = FALSE) +readr::write_tsv(df_f4ratio, original_f4r_tsv, progress = FALSE) orig_df_f4ratio <- readr::read_tsv(original_f4r_tsv, show_col_types = FALSE, progress = FALSE) %>% as.data.frame() -# library(ggplot2) -# p_f4ratio <- ggplot(df_f4ratio, aes(alpha, fill = population)) + -# geom_histogram(bins = 30) + -# facet_grid(simulator ~ model) + -# geom_vline(xintercept = 0.1, linetype = 2) + -# labs(y = "number of individuals", x = "ancestry proportion (f4-ratio statistic)", -# title = "f4-ratio estimate of 'b' ancestry calculated from simulated data", -# subtitle = "Population 'x1' receives 10% gene flow (vertical dotted line) -# from 'b' in gene flow models, 'x2' never does") + -# theme(legend.position = "bottom") -# png_file <- sprintf("f4ratio_%s.png", Sys.info()["sysname"]) -# ggsave(png_file, p_f4ratio, width = 8, height = 5) +library(ggplot2) +p_f4ratio <- ggplot(df_f4ratio, aes(alpha, fill = population)) + + geom_histogram(bins = 30) + + facet_grid(simulator ~ model) + + geom_vline(xintercept = 0.1, linetype = 2) + + labs(y = "number of individuals", x = "ancestry proportion (f4-ratio statistic)", + title = "f4-ratio estimate of 'b' ancestry calculated from simulated data", + subtitle = "Population 'x1' receives 10% gene flow (vertical dotted line) +from 'b' in gene flow models, 'x2' never does") + + theme(legend.position = "bottom") +png_file <- sprintf("f4ratio_%s.png", Sys.info()["sysname"]) +ggsave(png_file, p_f4ratio, width = 8, height = 5) test_that("f4-ratio distributions from SLiM and msprime simulations match", { expect_equal(df_f4ratio, orig_df_f4ratio, tolerance = 1e-8)