Skip to content

Commit 820e499

Browse files
committed
migrate advanced allelefreq tests
1 parent 3840860 commit 820e499

File tree

1 file changed

+100
-23
lines changed

1 file changed

+100
-23
lines changed

test/allelegenofreq.jl

Lines changed: 100 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,112 @@
11
module TestAlleleGenoFreq
22

33
using PopGenCore
4+
using DataFrames
45
using Test
56

6-
cats = @nancycats
7+
cats = @nancycats ;
78
g = cats.genodata.genotype[1:10]
9+
sharks = @gulfsharks ;
810

9-
@testset "Allele Frequencies" begin
10-
@test allele_freq(cats) isa NamedTuple
11-
@test allele_freq(g) isa Dict
12-
@test allele_freq(g[5]) isa Dict
13-
@test allele_freq_vec(g) isa AbstractVector
14-
a = allele_freq(g)
15-
b = allele_freq(cats.genodata.genotype[11:20])
16-
@test avg_allele_freq([a,b]) isa Dict
17-
@test avg_allele_freq([a,b], 2) isa Dict
18-
@test allele_freq(cats, "fca8") isa Dict
19-
@test allele_freq(cats, "fca8", population = true) isa DataFrames.DataFrame
20-
@test allele_freq(133, g) isa AbstractFloat
11+
@testset "Allele Frequncies" begin
12+
@testset "Basic" begin
13+
@test allele_freq(cats) isa NamedTuple
14+
@test allele_freq(g) isa Dict
15+
@test allele_freq(g[5]) isa Dict
16+
@test allele_freq_vec(g) isa AbstractVector
17+
a = allele_freq(g)
18+
b = allele_freq(cats.genodata.genotype[11:20])
19+
@test avg_allele_freq([a,b]) isa Dict
20+
@test avg_allele_freq([a,b], 2) isa Dict
21+
@test allele_freq(cats, "fca8") isa Dict
22+
@test allele_freq(cats, "fca8", population = true) isa DataFrame
23+
@test allele_freq(133, g) isa AbstractFloat
24+
end
25+
26+
@testset "Nuanced" begin
27+
@test length(allele_freq(cats)) == 9
28+
@test eltype(allele_freq(cats)) == Dict{Int16,Float64}
29+
@test allele_freq(cats.genodata.genotype) isa Dict{Int16,Float64}
30+
df_cats = DataFrames.combine(
31+
groupby(cats.genodata, :population),
32+
:genotype => allele_freq => :genos
33+
)
34+
@test size(df_cats) == (17,2)
35+
@test eltype(df_cats.genos) == Dict{Int16,Float64}
36+
@test length(allele_freq(cats, "fca8")) == 16
37+
@test allele_freq(cats, "fca8") isa Dict{Int16,Float64}
38+
39+
@test length(allele_freq(sharks)) == 2209
40+
@test eltype(allele_freq(sharks)) == Dict{Int8,Float64}
41+
@test allele_freq(sharks.genodata.genotype) isa Dict{Int8,Float64}
42+
df_sharks = DataFrames.combine(
43+
groupby(sharks.genodata, :population),
44+
:genotype => allele_freq => :genos
45+
)
46+
@test size(df_sharks) == (7,2)
47+
@test eltype(df_sharks.genos) == Dict{Int8,Float64}
48+
@test length(allele_freq(sharks, "contig_2784")) == 2
49+
@test allele_freq(sharks, "contig_2784") isa Dict{Int8,Float64}
50+
51+
@test allele_freq_vec([(1,1), (2,2), (2,1)]) == [0.5, 0.5]
52+
@test allele_freq_vec(missing) === missing
53+
end
54+
end
55+
56+
@testset "Genotype Frequncies" begin
57+
@testset "Basic" begin
58+
@test geno_freq(g) isa Dict
59+
@test geno_freq(cats, "fca8") isa Dict
60+
@test geno_freq(cats, "fca8", population = true) isa DataFrame
61+
@test geno_freq_expected(g) isa Dict
62+
@test geno_freq_expected(cats, "fca8") isa Dict
63+
@test geno_freq_expected(cats, "fca8", population = true) isa DataFrame
64+
end
65+
66+
@testset "Nuanced" begin
67+
@test length(geno_freq(cats.genodata.genotype)) == 295
68+
@test typeof(geno_freq(cats.genodata.genotype)) <: Dict{<:Tuple,Float64}
69+
@test length(geno_freq(cats, "fca8")) == 51
70+
@test typeof(geno_freq(cats, "fca8")) <: Dict{<:Tuple,Float64}
71+
@test size(geno_freq(cats, "fca8", population = true)) == (17,2)
72+
73+
@test length(geno_freq_expected(cats.genodata.genotype)) == 6241
74+
@test typeof(geno_freq_expected(cats.genodata.genotype)) <: Dict{<:Tuple,Float64}
75+
@test length(geno_freq_expected(cats, "fca8")) == 256
76+
@test typeof(geno_freq_expected(cats, "fca8")) <: Dict{<:Tuple,Float64}
77+
@test size(geno_freq_expected(cats, "fca8", population = true)) == (17,2)
78+
79+
@test length(geno_freq(sharks.genodata.genotype)) == 12
80+
@test length(geno_freq(sharks, "contig_2784")) == 2
81+
@test typeof(geno_freq(sharks, "contig_2784")) <: Dict{<:Tuple,Float64}
82+
@test size(geno_freq(sharks, "contig_2784", population = true)) == (7,2)
83+
84+
@test length(geno_freq_expected(sharks.genodata.genotype)) == 25
85+
@test typeof(geno_freq_expected(sharks.genodata.genotype)) <: Dict{<:Tuple,Float64}
86+
@test length(geno_freq_expected(sharks, "contig_2784")) == 4
87+
@test typeof(geno_freq_expected(sharks, "contig_2784")) <: Dict{<:Tuple,Float64}
88+
@test size(geno_freq_expected(sharks, "contig_2784", population = true)) == (7,2)
89+
end
2190
end
2291

23-
@testset "Genotype Frequencies" begin
24-
@test geno_count_observed(g) isa Dict
25-
@test geno_count_observed([missing, missing]) === missing
26-
@test geno_count_expected(g) isa Dict
27-
@test geno_freq(g) isa Dict
28-
@test geno_freq(cats, "fca8") isa Dict
29-
@test geno_freq(cats, "fca8", population = true) isa DataFrames.DataFrame
30-
@test geno_freq_expected(g) isa Dict
31-
@test geno_freq_expected(cats, "fca8") isa Dict
32-
@test geno_freq_expected(cats, "fca8", population = true) isa DataFrames.DataFrame
92+
@testset "Genotype Counts" begin
93+
@testset "Basic" begin
94+
@test geno_count_observed(g) isa Dict
95+
@test geno_count_observed([missing, missing]) === missing
96+
@test geno_count_expected(g) isa Dict
97+
end
98+
99+
@testset "Nuanced" begin
100+
@test length(geno_count_observed(cats.genodata.genotype)) == 295
101+
@test typeof(geno_count_observed(cats.genodata.genotype)) <: Dict{<:Tuple,Int64}
102+
@test length(geno_count_expected(cats.genodata.genotype)) == 6241
103+
@test typeof(geno_count_expected(cats.genodata.genotype)) <: Dict{<:Tuple,Float64}
104+
105+
@test length(geno_count_observed(sharks.genodata.genotype)) == 12
106+
@test typeof(geno_count_observed(sharks.genodata.genotype)) <: Dict{<:Tuple,Int64}
107+
@test length(geno_count_expected(sharks.genodata.genotype)) == 25
108+
@test typeof(geno_count_expected(sharks.genodata.genotype)) <: Dict{<:Tuple,Float64}
109+
end
33110
end
34111

35112
end

0 commit comments

Comments
 (0)