Skip to content

Commit 3be2173

Browse files
committed
Add test_plot_genes_with_gene_labels
1 parent cc1ce67 commit 3be2173

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

tests/anoph/test_genome_features.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,33 @@ def test_plot_genes(fixture, api: AnophelesGenomeFeaturesData):
133133
assert isinstance(fig, bokeh.plotting.figure)
134134

135135

136+
@parametrize_with_cases("fixture,api", cases=".")
137+
def test_plot_genes_with_gene_labels(fixture, api: AnophelesGenomeFeaturesData):
138+
# For each contig in the fixture...
139+
for contig in fixture.contigs:
140+
# Get the genes for this contig.
141+
genes_df = api.genome_features(region=contig).query("type == 'gene'")
142+
143+
# If there are no genes, we cannot label them.
144+
if not genes_df.empty:
145+
# Get a random number of genes to sample.
146+
random_genes_n = np.random.randint(low=1, high=len(genes_df) + 1)
147+
148+
# Get a random sample of genes.
149+
random_sample_genes_df = genes_df.sample(n=random_genes_n)
150+
151+
# Put the random gene "ID" and its "Name" in a dictionary.
152+
random_gene_labels = dict(
153+
zip(random_sample_genes_df["ID"], random_sample_genes_df["Name"])
154+
)
155+
156+
# Check that we get a Bokeh figure from plot_genes() with these gene_labels.
157+
fig = api.plot_genes(
158+
region=contig, show=False, gene_labels=random_gene_labels
159+
)
160+
assert isinstance(fig, bokeh.plotting.figure)
161+
162+
136163
@parametrize_with_cases("fixture,api", cases=".")
137164
def test_plot_transcript(fixture, api: AnophelesGenomeFeaturesData):
138165
for contig in fixture.contigs:

0 commit comments

Comments
 (0)