@@ -1528,6 +1528,100 @@ def test_plot_frequencies_time_series(
15281528 assert isinstance (fig , go .Figure )
15291529
15301530
1531+ @parametrize_with_cases ("fixture,api" , cases = "." )
1532+ def test_plot_frequencies_time_series_with_taxa (
1533+ fixture ,
1534+ api : AnophelesSnpFrequencyAnalysis ,
1535+ ):
1536+ # Pick test parameters at random.
1537+ all_sample_sets = api .sample_sets ()["sample_set" ].to_list ()
1538+ sample_sets = random .choice (all_sample_sets )
1539+ site_mask = random .choice (api .site_mask_ids + (None ,))
1540+ transcript = random_transcript (api = api ).name
1541+ area_by = random .choice (["country" , "admin1_iso" , "admin2_name" ])
1542+ period_by = random .choice (["year" , "quarter" , "month" ])
1543+
1544+ # Pick a random taxon and taxa from valid taxa.
1545+ sample_sets_taxa = (
1546+ api .sample_metadata (sample_sets = sample_sets )["taxon" ].dropna ().unique ().tolist ()
1547+ )
1548+ taxon = random .choice (sample_sets_taxa )
1549+ taxa = random .sample (sample_sets_taxa , random .randint (1 , len (sample_sets_taxa )))
1550+
1551+ # Compute SNP frequencies.
1552+ ds = api .snp_allele_frequencies_advanced (
1553+ transcript = transcript ,
1554+ area_by = area_by ,
1555+ period_by = period_by ,
1556+ sample_sets = sample_sets ,
1557+ min_cohort_size = 1 , # Don't exclude any samples.
1558+ site_mask = site_mask ,
1559+ )
1560+
1561+ # Trim things down a bit for speed.
1562+ ds = ds .isel (variants = slice (0 , 100 ))
1563+
1564+ # Plot with taxon.
1565+ fig = api .plot_frequencies_time_series (ds , show = False , taxa = taxon )
1566+
1567+ # Test taxon plot.
1568+ assert isinstance (fig , go .Figure )
1569+
1570+ # Plot with taxa.
1571+ fig = api .plot_frequencies_time_series (ds , show = False , taxa = taxa )
1572+
1573+ # Test taxa plot.
1574+ assert isinstance (fig , go .Figure )
1575+
1576+
1577+ @parametrize_with_cases ("fixture,api" , cases = "." )
1578+ def test_plot_frequencies_time_series_with_areas (
1579+ fixture ,
1580+ api : AnophelesSnpFrequencyAnalysis ,
1581+ ):
1582+ # Pick test parameters at random.
1583+ all_sample_sets = api .sample_sets ()["sample_set" ].to_list ()
1584+ sample_sets = random .choice (all_sample_sets )
1585+ site_mask = random .choice (api .site_mask_ids + (None ,))
1586+ transcript = random_transcript (api = api ).name
1587+ area_by = random .choice (["country" , "admin1_iso" , "admin2_name" ])
1588+ period_by = random .choice (["year" , "quarter" , "month" ])
1589+
1590+ # Compute SNP frequencies.
1591+ ds = api .snp_allele_frequencies_advanced (
1592+ transcript = transcript ,
1593+ area_by = area_by ,
1594+ period_by = period_by ,
1595+ sample_sets = sample_sets ,
1596+ min_cohort_size = 1 , # Don't exclude any samples.
1597+ site_mask = site_mask ,
1598+ )
1599+
1600+ # Trim things down a bit for speed.
1601+ ds = ds .isel (variants = slice (0 , 100 ))
1602+
1603+ # Extract cohorts into a DataFrame.
1604+ cohort_vars = [v for v in ds if str (v ).startswith ("cohort_" )]
1605+ df_cohorts = ds [cohort_vars ].to_dataframe ()
1606+
1607+ # Pick a random area and areas from valid areas.
1608+ cohorts_areas = df_cohorts ["cohort_area" ].dropna ().unique ().tolist ()
1609+ area = random .choice (cohorts_areas )
1610+ areas = random .sample (cohorts_areas , random .randint (1 , len (cohorts_areas )))
1611+
1612+ # Plot with area.
1613+ fig = api .plot_frequencies_time_series (ds , show = False , areas = area )
1614+
1615+ # Test areas plot.
1616+ assert isinstance (fig , go .Figure )
1617+
1618+ # Plot with areas.
1619+ fig = api .plot_frequencies_time_series (ds , show = False , areas = areas )
1620+
1621+ # Test area plot.
1622+ assert isinstance (fig , go .Figure )
1623+
1624+
15311625@parametrize_with_cases ("fixture,api" , cases = "." )
15321626def test_plot_frequencies_interactive_map (
15331627 fixture ,
0 commit comments