Skip to content

Commit

Permalink
add html exports for interactive plots
Browse files Browse the repository at this point in the history
  • Loading branch information
tschuelia committed Dec 12, 2023
1 parent 384d1c7 commit f6b5ac9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/cli_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ Running Pandora in the command line will produce a number of (intermediate) outp
- ``*.fst``: The results of ``smartpca`` Fst computation (in case of MDS analyses)
- In case you specified ``keep_replicates: true`` in your config, there will also be the dataset files for the windows (``*.geno``, ``*.snp``, ``*.ind``).

- ``plots/``: If you set ``plot_results: true`` in your config, this directory will contain all plots Pandora generated during the execution. The names of the files should be self-explanatory.
- ``plots/``: If you set ``plot_results: true`` in your config, this directory will contain all plots Pandora generated during the execution. The names of the files should be self-explanatory. As of version 1.0.8, we provide each plot in two formats: pdf and HTML. You can open the HTML file in any browser to see an interactive version of the plot.
6 changes: 0 additions & 6 deletions docs/examples/plotting.rst

This file was deleted.

12 changes: 12 additions & 0 deletions pandora/pandora.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ def _plot_dataset(self, dataset: EigenDataset, plot_prefix: str) -> None:
fig.write_image(
self.pandora_config.plot_dir / f"{plot_prefix}_with_populations.pdf"
)
fig.write_html(
self.pandora_config.plot_dir / f"{plot_prefix}_with_populations.html"
)

# plot with annotated clusters
fig = plot_clusters(
Expand All @@ -511,6 +514,9 @@ def _plot_dataset(self, dataset: EigenDataset, plot_prefix: str) -> None:
fig.write_image(
self.pandora_config.plot_dir / f"{plot_prefix}_with_clusters.pdf"
)
fig.write_html(
self.pandora_config.plot_dir / f"{plot_prefix}_with_clusters.html"
)

if len(self.dataset.embedding_populations) > 0:
fig = plot_projections(
Expand All @@ -522,6 +528,9 @@ def _plot_dataset(self, dataset: EigenDataset, plot_prefix: str) -> None:
fig.write_image(
self.pandora_config.plot_dir / f"{plot_prefix}_projections.pdf"
)
fig.write_html(
self.pandora_config.plot_dir / f"{plot_prefix}_projections.html"
)

def bootstrap_embeddings(self) -> None:
"""Draws bootstrap replicates of ``self.dataset`` and computes and compares the respective embedding for all
Expand Down Expand Up @@ -681,10 +690,13 @@ def _plot_sample_support_values(

if projected_samples_only:
fig_name = "projected_sample_support_values.pdf"
fig_name_html = "projected_sample_support_values.html"
else:
fig_name = "sample_support_values.pdf"
fig_name_html = "sample_support_values.html"

fig.write_image(self.pandora_config.plot_dir / fig_name)
fig.write_html(self.pandora_config.plot_dir / fig_name_html)
return fig

def _compare_replicates_similarity(self) -> None:
Expand Down
12 changes: 6 additions & 6 deletions tests/test_pandora.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ def test_do_pca(self, pandora_test_config):

# pandora's dataset's PCA should be a PCA object now and not None
assert isinstance(pandora.dataset.pca, PCA)
# plot directory should contain two plots
assert len(list(pandora.pandora_config.plot_dir.iterdir())) == 2
# plot directory should contain four plots (two pdf, two html)
assert len(list(pandora.pandora_config.plot_dir.iterdir())) == 4

def test_do_mds(self, pandora_test_config_mds):
pandora = Pandora(pandora_test_config_mds)
Expand All @@ -238,8 +238,8 @@ def test_do_mds(self, pandora_test_config_mds):

# pandora's dataset's MDS should be a MDS object now and not None
assert isinstance(pandora.dataset.mds, MDS)
# plot directory should contain two plots
assert len(list(pandora.pandora_config.plot_dir.iterdir())) == 2
# plot directory should contain four plots (two pdf, two html)
assert len(list(pandora.pandora_config.plot_dir.iterdir())) == 4

def test_do_pca_with_pca_populations(
self, pandora_test_config_with_embedding_populations
Expand All @@ -254,8 +254,8 @@ def test_do_pca_with_pca_populations(
# pandora's dataset's PCA should be a PCA object now and not None
assert isinstance(pandora.dataset.pca, PCA)

# plot directory should contain three plots
assert len(list(pandora.pandora_config.plot_dir.iterdir())) == 3
# plot directory should contain six plots (3 pdf, 3 html)
assert len(list(pandora.pandora_config.plot_dir.iterdir())) == 6

def test_plot_dataset_fails_if_pca_is_missing(self, pandora_test_config):
pandora = Pandora(pandora_test_config)
Expand Down

0 comments on commit f6b5ac9

Please sign in to comment.