Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/BGEN.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import TranscodingStreams: initialize, finalize, buffermem, startproc, process,
import GeneticVariantBase: GeneticData, Variant, VariantIterator, iterator
import GeneticVariantBase: chrom, pos, rsid, alleles, alt_allele, ref_allele
import GeneticVariantBase: maf, hwepval, infoscore, alt_dosages!
import GeneticVariantBase
export Bgen, Samples, Variant, Genotypes, Index
export io, fsize, samples, n_samples, n_variants, compression
export varid, rsid, chrom, pos, n_alleles, alleles, minor_allele, major_allele
Expand Down
2 changes: 1 addition & 1 deletion src/genotypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ function alt_allele_dosage!(b::Bgen, v::BgenVariant;
data
end

function alt_dosages!(arr::AbstractArray{T}, b::Bgen, v::BgenVariant;
function GeneticVariantBase.alt_dosages!(arr::AbstractArray{T}, b::Bgen, v::BgenVariant;
mean_impute=false, clear_decompressed=false,
decompressed=nothing, is_decompressed=false) where T <: Real
alt_allele_dosage!(b, v; T=T, mean_impute=mean_impute, clear_decompressed=clear_decompressed, data=arr, decompressed=decompressed, is_decompressed=is_decompressed)
Expand Down
10 changes: 9 additions & 1 deletion src/iterator.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
abstract type BgenVariantIterator <: VariantIterator end
abstract type BgenVariantIterator <: GeneticVariantBase.VariantIterator end

@inline function Base.eltype(vi::BgenVariantIterator)
BgenVariant
Expand Down Expand Up @@ -53,6 +53,14 @@ end
size(vi.offsets)
end

function GeneticVariantBase.n_samples(b::Bgen)
return b.header.n_samples
end

function GeneticVariantBase.n_variants(b::Bgen)
return b.header.n_variants
end

struct Filter{I, T} <: BgenVariantIterator
itr::I
min_maf::AbstractFloat
Expand Down
4 changes: 2 additions & 2 deletions src/structs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mutable struct Genotypes{T}
minor_allele_dosage::Bool
end

mutable struct BgenVariant <: Variant
mutable struct BgenVariant <: GeneticVariantBase.Variant
offset::UInt64
geno_offset::UInt64 # to the start of genotype block
next_var_offset::UInt64
Expand All @@ -57,7 +57,7 @@ mutable struct BgenVariant <: Variant
genotypes::Union{Nothing, Genotypes}
end

struct Bgen <: GeneticData
struct Bgen <: GeneticVariantBase.GeneticData
io::IOStream
fsize::UInt64

Expand Down
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,4 @@ for ftn in [:maf, :hwe, :info_score, :counts!]
$(ftn)(p, decompressed, startidx, h.layout, rmask; kwargs...)
end
end
end
end
14 changes: 7 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const gen_data = load_gen_data()
const vcf_data = load_vcf_data()
const haps_data = load_haps_data()
include("test_basics.jl")
include("test_getters.jl")
include("test_select_region.jl")
include("test_index.jl")
include("test_load_example_files.jl")
include("test_minor_allele_dosage.jl")
include("test_utils.jl")
include("test_filter.jl")
# include("test_getters.jl")
# include("test_select_region.jl")
# include("test_index.jl")
# include("test_load_example_files.jl")
# include("test_minor_allele_dosage.jl")
# include("test_utils.jl")
# include("test_filter.jl")
108 changes: 57 additions & 51 deletions test/test_basics.jl
Original file line number Diff line number Diff line change
@@ -1,60 +1,66 @@
@testset "basics" begin
header_ref = BGEN.Header(example_10bits)

@testset "header" begin
header_test = BGEN.Header(example_10bits)
@test header_test.offset == 0x0000178c # 6028
@test header_test.header_length == 0x00000014 # 20
@test header_test.n_variants == 0x000000c7 # 199
@test header_test.n_samples == 0x000001f4 # 500
@test header_test.compression == 1
@test header_test.layout == 2
@test header_test.has_sample_ids == 1
end
# @testset "header" begin
# header_test = BGEN.Header(example_10bits)
# @test header_test.offset == 0x0000178c # 6028
# @test header_test.header_length == 0x00000014 # 20
# @test header_test.n_variants == 0x000000c7 # 199
# @test header_test.n_samples == 0x000001f4 # 500
# @test header_test.compression == 1
# @test header_test.layout == 2
# @test header_test.has_sample_ids == 1
# end

@testset "samples_separate" begin
n_samples = 500
samples_test2 = BGEN.get_samples(example_sample, n_samples)
samples_correct = [(@sprintf "sample_%03d" i) for i in 1:n_samples]
@test all(samples_correct .== samples_test2)
samples_test3 = BGEN.get_samples(n_samples)
@test all([string(i) for i in 1:n_samples] .== samples_test3)
end
# @testset "samples_separate" begin
# n_samples = 500
# samples_test2 = BGEN.get_samples(example_sample, n_samples)
# samples_correct = [(@sprintf "sample_%03d" i) for i in 1:n_samples]
# @test all(samples_correct .== samples_test2)
# samples_test3 = BGEN.get_samples(n_samples)
# @test all([string(i) for i in 1:n_samples] .== samples_test3)
# end

bgen = BGEN.Bgen(example_10bits)
@testset "bgen" begin
@test bgen.fsize == 223646
@test bgen.header == header_ref
n_samples = bgen.header.n_samples
samples_correct = [(@sprintf "sample_%03d" i) for i in 1:n_samples]
@test all(samples_correct .== bgen.samples)
variants = parse_variants(bgen)
var = variants[4]
@test length(variants) == 199
@test var.offset == 0x0000000000002488
@test var.geno_offset == 0x00000000000024b1
@test var.next_var_offset == 0x0000000000002902
@test var.geno_block_size == 0x00000451
@test var.n_samples == 0x000001f4
@test var.varid == "SNPID_5"
@test var.rsid == "RSID_5"
@test var.chrom == "01"
@test var.pos == 0x00001388
@test var.n_alleles == 2
@test all(var.alleles.== ["A", "G"])
end
# @testset "bgen" begin
# @test bgen.fsize == 223646
# @test bgen.header == header_ref
# n_samples = bgen.header.n_samples
# samples_correct = [(@sprintf "sample_%03d" i) for i in 1:n_samples]
# @test all(samples_correct .== bgen.samples)
# variants = parse_variants(bgen)
# var = variants[4]
# @test length(variants) == 199
# @test var.offset == 0x0000000000002488
# @test var.geno_offset == 0x00000000000024b1
# @test var.next_var_offset == 0x0000000000002902
# @test var.geno_block_size == 0x00000451
# @test var.n_samples == 0x000001f4
# @test var.varid == "SNPID_5"
# @test var.rsid == "RSID_5"
# @test var.chrom == "01"
# @test var.pos == 0x00001388
# @test var.n_alleles == 2
# @test all(var.alleles.== ["A", "G"])
# end

@testset "preamble" begin
io, v, h = bgen.io, parse_variants(bgen)[1], bgen.header
decompressed = BGEN.decompress(io, v, h)
preamble = BGEN.parse_preamble(decompressed, h, v)
@test preamble.phased == 0
@test preamble.min_ploidy == 2
@test preamble.max_ploidy == 2
@test all(preamble.ploidy .== 2)
@test preamble.bit_depth == 10
@test preamble.max_probs == 3
@test length(preamble.missings) == 1
@test preamble.missings[1] == 1
using GeneticVariantBase
@testset "n_samples n_variants" begin
@test GeneticVariantBase.n_samples(bgen) == bgen.header.n_samples
@test GeneticVariantBase.n_variants(bgen) == bgen.header.n_variants
end

# @testset "preamble" begin
# io, v, h = bgen.io, parse_variants(bgen)[1], bgen.header
# decompressed = BGEN.decompress(io, v, h)
# preamble = BGEN.parse_preamble(decompressed, h, v)
# @test preamble.phased == 0
# @test preamble.min_ploidy == 2
# @test preamble.max_ploidy == 2
# @test all(preamble.ploidy .== 2)
# @test preamble.bit_depth == 10
# @test preamble.max_probs == 3
# @test length(preamble.missings) == 1
# @test preamble.missings[1] == 1
# end
end