Skip to content

Commit

Permalink
Write updated test outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
bodkan committed Dec 6, 2023
1 parent aee84ef commit b5330c3
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions tests/testthat/test-msprime-geneflow.R
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit b5330c3

Please sign in to comment.