if (1 == 0) {
    
    library("testthat"); library("STITCH"); library("rrbgen")
    dir <- "/data/smew1/rdavies/stitch_development/STITCH_github_latest/STITCH"
    dir <- "~/proj/STITCH/"
    setwd(paste0(dir, "/STITCH/R"))
    a <- dir(pattern = "*.R")
    b <- grep("~", a)
    if (length(b) > 0) {
        a <- a[-b]
    }
    o <- sapply(a, source)
    setwd(dir)
    Sys.setenv(PATH = paste0(getwd(), ":", Sys.getenv("PATH")))

}


n_snps <- 1000
reads_span_n_snps <- 6
chr <- 1
original_chr <- chr
n_reads <- 5 / (reads_span_n_snps / n_snps) ## want about 5X / sample
extension <- c("bgvcf" = ".vcf.gz", "bgen" = ".bgen")

K <- 10000
phasemaster <- matrix(sample(c(0, 1), replace = TRUE, n_snps * K), ncol = K)
L <- 10 + seq(1, 3 * n_snps, 3)
L_original <- L

data_package <- make_acceptance_test_data_package(
    n_samples = 10,
    n_snps = n_snps,
    n_reads = n_reads,
    L = L,
    seed = 3,
    chr = "chr5",
    K = 2,
    reads_span_n_snps = reads_span_n_snps,
    phasemaster = phasemaster
)
refpack <- make_reference_package(
    n_snps = n_snps,
    L = L,
    n_samples_per_pop = 4,
    reference_populations = c("CEU", "GBR", "CHB"),
    chr = chr,
    phasemaster = phasemaster
)


test_that("STITCH can initialize with very large reference data", {

    output_format <- "bgvcf"

    outputdir <- make_unique_tempdir()
    set.seed(478)

    STITCH(
        chr = data_package$chr,
        bamlist = data_package$bamlist,
        posfile = data_package$posfile,
        genfile = data_package$genfile,
        outputdir = outputdir,
        reference_haplotype_file = refpack$reference_haplotype_file,
        reference_legend_file = refpack$reference_legend_file,
        K = K,
        S = 3,
        nGen = 100,
        nCores = 1,
        output_format = output_format
    )

    check_output_against_phase(
        file.path(outputdir, paste0("stitch.", data_package$chr, extension[output_format])),
        data_package,
        output_format,
        which_snps = NULL,
        tol = 0.2
    )

})

