1- import random
2-
31import pytest
4- from pytest_cases import parametrize_with_cases
52import plotly .graph_objects as go # type: ignore
63
7- from malariagen_data import af1 as _af1
8- from malariagen_data import ag3 as _ag3
9- from malariagen_data .anoph .snp_frq import AnophelesSnpFrequencyAnalysis
10-
11-
12- @pytest .fixture
13- def ag3_sim_api (ag3_sim_fixture ):
14- return AnophelesSnpFrequencyAnalysis (
15- url = ag3_sim_fixture .url ,
16- config_path = _ag3 .CONFIG_PATH ,
17- major_version_number = _ag3 .MAJOR_VERSION_NUMBER ,
18- major_version_path = _ag3 .MAJOR_VERSION_PATH ,
19- pre = True ,
20- aim_metadata_dtype = {
21- "aim_species_fraction_arab" : "float64" ,
22- "aim_species_fraction_colu" : "float64" ,
23- "aim_species_fraction_colu_no2l" : "float64" ,
24- "aim_species_gambcolu_arabiensis" : object ,
25- "aim_species_gambiae_coluzzii" : object ,
26- "aim_species" : object ,
27- },
28- gff_gene_type = "gene" ,
29- gff_gene_name_attribute = "Name" ,
30- gff_default_attributes = ("ID" , "Parent" , "Name" , "description" ),
31- default_site_mask = "gamb_colu_arab" ,
32- results_cache = ag3_sim_fixture .results_cache_path .as_posix (),
33- taxon_colors = _ag3 .TAXON_COLORS ,
34- )
35-
36-
37- @pytest .fixture
38- def af1_sim_api (af1_sim_fixture ):
39- return AnophelesSnpFrequencyAnalysis (
40- url = af1_sim_fixture .url ,
41- config_path = _af1 .CONFIG_PATH ,
42- major_version_number = _af1 .MAJOR_VERSION_NUMBER ,
43- major_version_path = _af1 .MAJOR_VERSION_PATH ,
44- pre = False ,
45- gff_gene_type = "protein_coding_gene" ,
46- gff_gene_name_attribute = "Note" ,
47- gff_default_attributes = ("ID" , "Parent" , "Note" , "description" ),
48- default_site_mask = "funestus" ,
49- results_cache = af1_sim_fixture .results_cache_path .as_posix (),
50- taxon_colors = _af1 .TAXON_COLORS ,
51- )
52-
53-
54- # N.B., here we use pytest_cases to parametrize tests. Each
55- # function whose name begins with "case_" defines a set of
56- # inputs to the test functions. See the documentation for
57- # pytest_cases for more information, e.g.:
58- #
59- # https://smarie.github.io/python-pytest-cases/#basic-usage
60- #
61- # We use this approach here because we want to use fixtures
62- # as test parameters, which is otherwise hard to do with
63- # pytest alone.
64-
65-
66- def case_ag3_sim (ag3_sim_fixture , ag3_sim_api ):
67- return ag3_sim_fixture , ag3_sim_api
68-
69-
70- def case_af1_sim (af1_sim_fixture , af1_sim_api ):
71- return af1_sim_fixture , af1_sim_api
72-
73-
74- @parametrize_with_cases ("fixture,api" , cases = "." )
75- def test_plot_frequencies_heatmap (
76- fixture ,
77- api : AnophelesSnpFrequencyAnalysis ,
78- ):
79- # Pick test parameters at random.
80- all_sample_sets = api .sample_sets ()["sample_set" ].to_list ()
81- sample_sets = random .choice (all_sample_sets )
82- site_mask = random .choice (api .site_mask_ids + (None ,))
83- min_cohort_size = random .randint (0 , 2 )
84- transcript = fixture .random_transcript_id ()
85- cohorts = random .choice (
86- ["admin1_year" , "admin1_month" , "admin2_year" , "admin2_month" ]
87- )
88-
89- # Set up call params.
90- params = dict (
91- transcript = transcript ,
92- cohorts = cohorts ,
93- min_cohort_size = min_cohort_size ,
94- site_mask = site_mask ,
95- sample_sets = sample_sets ,
96- )
4+ import random
975
98- # Test SNP allele frequencies.
99- df_snp = api .snp_allele_frequencies (** params )
100- fig = api .plot_frequencies_heatmap (df_snp , show = False , max_len = None )
101- assert isinstance (fig , go .Figure )
1026
103- # Test amino acid change allele frequencies.
104- df_aa = api . aa_allele_frequencies ( ** params )
105- fig = api .plot_frequencies_heatmap (df_aa , show = False , max_len = None )
7+ @ pytest . mark . skip
8+ def test_plot_frequencies_heatmap ( api , frq_df ):
9+ fig = api .plot_frequencies_heatmap (frq_df , show = False , max_len = None )
10610 assert isinstance (fig , go .Figure )
10711
10812 # Test max_len behaviour.
10913 with pytest .raises (ValueError ):
110- api .plot_frequencies_heatmap (df_snp , show = False , max_len = len (df_snp ) - 1 )
14+ api .plot_frequencies_heatmap (frq_df , show = False , max_len = len (frq_df ) - 1 )
11115
11216 # Test index parameter - if None, should use dataframe index.
113- fig = api .plot_frequencies_heatmap (df_snp , show = False , index = None , max_len = None )
17+ fig = api .plot_frequencies_heatmap (frq_df , show = False , index = None , max_len = None )
11418 # Not unique.
11519 with pytest .raises (ValueError ):
116- api .plot_frequencies_heatmap (df_snp , show = False , index = "contig" , max_len = None )
117-
20+ api .plot_frequencies_heatmap (frq_df , show = False , index = "contig" , max_len = None )
11821
119- @parametrize_with_cases ("fixture,api" , cases = "." )
120- def test_plot_frequencies_time_series (
121- fixture ,
122- api : AnophelesSnpFrequencyAnalysis ,
123- ):
124- # Pick test parameters at random.
125- all_sample_sets = api .sample_sets ()["sample_set" ].to_list ()
126- sample_sets = random .choice (all_sample_sets )
127- site_mask = random .choice (api .site_mask_ids + (None ,))
128- min_cohort_size = random .randint (0 , 2 )
129- transcript = fixture .random_transcript_id ()
130- area_by = random .choice (["country" , "admin1_iso" , "admin2_name" ])
131- period_by = random .choice (["year" , "quarter" , "month" ])
132-
133- # Compute SNP frequencies.
134- ds = api .snp_allele_frequencies_advanced (
135- transcript = transcript ,
136- area_by = area_by ,
137- period_by = period_by ,
138- sample_sets = sample_sets ,
139- min_cohort_size = min_cohort_size ,
140- site_mask = site_mask ,
141- )
14222
23+ @pytest .mark .skip
24+ def test_plot_frequencies_time_series (api , ds ):
14325 # Trim things down a bit for speed.
14426 ds = ds .isel (variants = slice (0 , 100 ))
14527
@@ -149,57 +31,14 @@ def test_plot_frequencies_time_series(
14931 # Test.
15032 assert isinstance (fig , go .Figure )
15133
152- # Compute amino acid change frequencies.
153- ds = api .aa_allele_frequencies_advanced (
154- transcript = transcript ,
155- area_by = area_by ,
156- period_by = period_by ,
157- sample_sets = sample_sets ,
158- min_cohort_size = min_cohort_size ,
159- )
16034
35+ @pytest .mark .skip
36+ def test_plot_frequencies_time_series_with_taxa (api , ds ):
16137 # Trim things down a bit for speed.
16238 ds = ds .isel (variants = slice (0 , 100 ))
16339
164- # Plot.
165- fig = api .plot_frequencies_time_series (ds , show = False )
166-
167- # Test.
168- assert isinstance (fig , go .Figure )
169-
170-
171- @parametrize_with_cases ("fixture,api" , cases = "." )
172- def test_plot_frequencies_time_series_with_taxa (
173- fixture ,
174- api : AnophelesSnpFrequencyAnalysis ,
175- ):
176- # Pick test parameters at random.
177- all_sample_sets = api .sample_sets ()["sample_set" ].to_list ()
178- sample_sets = random .choice (all_sample_sets )
179- site_mask = random .choice (api .site_mask_ids + (None ,))
180- transcript = fixture .random_transcript_id ()
181- area_by = random .choice (["country" , "admin1_iso" , "admin2_name" ])
182- period_by = random .choice (["year" , "quarter" , "month" ])
183-
184- # Pick a random taxon and taxa from valid taxa.
185- sample_sets_taxa = (
186- api .sample_metadata (sample_sets = sample_sets )["taxon" ].dropna ().unique ().tolist ()
187- )
188- taxon = random .choice (sample_sets_taxa )
189- taxa = random .sample (sample_sets_taxa , random .randint (1 , len (sample_sets_taxa )))
190-
191- # Compute SNP frequencies.
192- ds = api .snp_allele_frequencies_advanced (
193- transcript = transcript ,
194- area_by = area_by ,
195- period_by = period_by ,
196- sample_sets = sample_sets ,
197- min_cohort_size = 1 , # Don't exclude any samples.
198- site_mask = site_mask ,
199- )
200-
201- # Trim things down a bit for speed.
202- ds = ds .isel (variants = slice (0 , 100 ))
40+ taxa = list (ds .cohort_taxon .to_dataframe ()["cohort_taxon" ].unique ())
41+ taxon = random .choice (taxa )
20342
20443 # Plot with taxon.
20544 fig = api .plot_frequencies_time_series (ds , show = False , taxa = taxon )
@@ -214,29 +53,8 @@ def test_plot_frequencies_time_series_with_taxa(
21453 assert isinstance (fig , go .Figure )
21554
21655
217- @parametrize_with_cases ("fixture,api" , cases = "." )
218- def test_plot_frequencies_time_series_with_areas (
219- fixture ,
220- api : AnophelesSnpFrequencyAnalysis ,
221- ):
222- # Pick test parameters at random.
223- all_sample_sets = api .sample_sets ()["sample_set" ].to_list ()
224- sample_sets = random .choice (all_sample_sets )
225- site_mask = random .choice (api .site_mask_ids + (None ,))
226- transcript = fixture .random_transcript_id ()
227- area_by = random .choice (["country" , "admin1_iso" , "admin2_name" ])
228- period_by = random .choice (["year" , "quarter" , "month" ])
229-
230- # Compute SNP frequencies.
231- ds = api .snp_allele_frequencies_advanced (
232- transcript = transcript ,
233- area_by = area_by ,
234- period_by = period_by ,
235- sample_sets = sample_sets ,
236- min_cohort_size = 1 , # Don't exclude any samples.
237- site_mask = site_mask ,
238- )
239-
56+ @pytest .mark .skip
57+ def test_plot_frequencies_time_series_with_areas (api , ds ):
24058 # Trim things down a bit for speed.
24159 ds = ds .isel (variants = slice (0 , 100 ))
24260
@@ -262,50 +80,10 @@ def test_plot_frequencies_time_series_with_areas(
26280 assert isinstance (fig , go .Figure )
26381
26482
265- @parametrize_with_cases ("fixture,api" , cases = "." )
266- def test_plot_frequencies_interactive_map (
267- fixture ,
268- api : AnophelesSnpFrequencyAnalysis ,
269- ):
83+ @pytest .mark .skip
84+ def test_plot_frequencies_interactive_map (api , ds ):
27085 import ipywidgets # type: ignore
27186
272- # Pick test parameters at random.
273- all_sample_sets = api .sample_sets ()["sample_set" ].to_list ()
274- sample_sets = random .choice (all_sample_sets )
275- site_mask = random .choice (api .site_mask_ids + (None ,))
276- min_cohort_size = random .randint (0 , 2 )
277- transcript = fixture .random_transcript_id ()
278- area_by = random .choice (["country" , "admin1_iso" , "admin2_name" ])
279- period_by = random .choice (["year" , "quarter" , "month" ])
280-
281- # Compute SNP frequencies.
282- ds = api .snp_allele_frequencies_advanced (
283- transcript = transcript ,
284- area_by = area_by ,
285- period_by = period_by ,
286- sample_sets = sample_sets ,
287- min_cohort_size = min_cohort_size ,
288- site_mask = site_mask ,
289- )
290-
291- # Trim things down a bit for speed.
292- ds = ds .isel (variants = slice (0 , 100 ))
293-
294- # Plot.
295- fig = api .plot_frequencies_interactive_map (ds )
296-
297- # Test.
298- assert isinstance (fig , ipywidgets .Widget )
299-
300- # Compute amino acid change frequencies.
301- ds = api .aa_allele_frequencies_advanced (
302- transcript = transcript ,
303- area_by = area_by ,
304- period_by = period_by ,
305- sample_sets = sample_sets ,
306- min_cohort_size = min_cohort_size ,
307- )
308-
30987 # Trim things down a bit for speed.
31088 ds = ds .isel (variants = slice (0 , 100 ))
31189
0 commit comments