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