Skip to content

Commit

Permalink
fix read bgen
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierlabayle committed Jun 7, 2024
1 parent f0c00a3 commit 210f521
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ function keep_only_imputed(associations, bgen_prefix, chr)
return innerjoin(associations, imputed_rsids, on=:SNP)
end

get_bgen_chromosome(bgen_files, chr) = only(filter(
x -> endswith(x, Regex(string("[^0-9]", chr, ".bgen"))),
bgen_files
))

function read_bgen_chromosome(bgen_prefix, chr)
all_bgens = files_matching_prefix(bgen_prefix)
bgen_file = only(filter(x -> endswith(x, string(chr, ".bgen")), all_bgens))
bgen_files = files_matching_prefix(bgen_prefix)
bgen_file = get_bgen_chromosome(bgen_files, chr)
return TargeneCore.read_bgen(bgen_file)
end

Expand Down
14 changes: 14 additions & 0 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ end
1 0 1 0
0 1 0 1
]
# Test get_bgen_chromosome
bgen_files = [
"ukb_53116_chr11.bgen",
"ukb_53116_chr12.bgen",
"ukb_53116_chr12.bgen.bgi",
"ukb_53116_chr12.sample",
"ukb_53116_chr2.bgen",
"ukb_53116_chr2.bgen.bgi",
"ukb_53116_chr2.sample"
]
@test Simulations.get_bgen_chromosome(bgen_files, 2) == "ukb_53116_chr2.bgen"
@test Simulations.get_bgen_chromosome(bgen_files, 12) == "ukb_53116_chr12.bgen"
@test Simulations.get_bgen_chromosome(bgen_files, 11) == "ukb_53116_chr11.bgen"

# Test read_bgen_chromosome(bgen_prefix, chr)
bgen_prefix = joinpath(TARGENCORE_TESTDIR, "data", "ukbb", "imputed", "ukbb")
b = Simulations.read_bgen_chromosome(bgen_prefix, 12)
Expand Down

0 comments on commit 210f521

Please sign in to comment.