Skip to content

Commit

Permalink
support custom colors in plots
Browse files Browse the repository at this point in the history
  • Loading branch information
cdiener committed Sep 12, 2024
1 parent 8a948f6 commit af1b22a
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 19 deletions.
Binary file modified docs/media_results.qza
Binary file not shown.
Binary file modified docs/minimal_medium.qza
Binary file not shown.
Binary file modified docs/sample_minimal_media.qza
Binary file not shown.
13 changes: 8 additions & 5 deletions q2_micom/_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from qiime2 import MetadataColumn


def plot_growth(output_dir: str, results: GrowthResults) -> None:
def plot_growth(
output_dir: str, results: GrowthResults, metadata: MetadataColumn = None
) -> None:
"""Plot the taxa growth rates."""
viz.plot_growth(
results,
join(output_dir, "index.html"),
)
meta = None if metadata is None else metadata.to_series()
viz.plot_growth(results, join(output_dir, "index.html"), groups=meta)


def exchanges_per_sample(
Expand All @@ -31,13 +31,16 @@ def exchanges_per_taxon(
output_dir: str,
results: GrowthResults,
direction: str = "import",
metadata: MetadataColumn = None,
perplexity: int = 20,
) -> None:
"""Plot the exchange fluxes."""
meta = None if metadata is None else metadata.to_series()
viz.plot_exchanges_per_taxon(
results,
join(output_dir, "index.html"),
direction,
groups=meta,
perplexity=perplexity,
)

Expand Down
6 changes: 4 additions & 2 deletions q2_micom/plugin_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,14 +400,14 @@
plugin.visualizers.register_function(
function=q2_micom.plot_growth,
inputs={"results": MicomResults},
parameters={},
parameters={"metadata": MetadataColumn[Categorical]},
input_descriptions={
"results": (
"A set of MICOM analysis results. "
"Contains predicted groath rates and exchange fluxes."
)
},
parameter_descriptions={},
parameter_descriptions={"metadata": "The metadata variable to use."},
name="Plot taxa growth rates.",
description=(
"Plot predicted growth rates for each taxon in each sample. "
Expand Down Expand Up @@ -451,6 +451,7 @@
inputs={"results": MicomResults},
parameters={
"direction": Str % Choices("import", "export"),
"metadata": MetadataColumn[Categorical],
"perplexity": Int % Range(2, None),
},
input_descriptions={
Expand All @@ -461,6 +462,7 @@
},
parameter_descriptions={
"direction": "The direction of the flux.",
"metadata": "The metadata variable to use.",
"perplexity": "TSNE parameter. Relates to the number of neighbors used to "
"calculate distances. Smaller values preserve more local "
"structure and larger values preserve more global structure.",
Expand Down
10 changes: 10 additions & 0 deletions q2_micom/tests/test_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@

def test_growth_plots():
r = results.view(GrowthResults)
mcol = q2.Metadata.load(path.join(this_dir, "data", "metadata.tsv")).get_column(
"status"
)
with TemporaryDirectory(prefix="q2-micom-") as d:
q2m.plot_growth(str(d), r)
assert q2m.tests.check_viz(str(d))
q2m.plot_growth(str(d), r, metadata=mcol)
assert q2m.tests.check_viz(str(d))


def test_exchanges_per_sample():
Expand All @@ -28,9 +33,14 @@ def test_exchanges_per_sample():

def test_exchanges_per_taxon():
r = results.view(GrowthResults)
mcol = q2.Metadata.load(path.join(this_dir, "data", "metadata.tsv")).get_column(
"status"
)
with TemporaryDirectory(prefix="q2-micom-") as d:
q2m.exchanges_per_taxon(str(d), r)
assert q2m.tests.check_viz(str(d))
q2m.exchanges_per_taxon(str(d), r, metadata=mcol)
assert q2m.tests.check_viz(str(d))


def test_plot_tradeoff():
Expand Down
24 changes: 12 additions & 12 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ long_description = file: README.md
long_description_content_type = text/markdown
license = Apache License 2.0
url = https://github.com/micom-dev/q2-micom
classifiers =
classifiers =
Development Status :: 4 - Beta
Intended Audience :: Science/Research
Topic :: Scientific/Engineering :: Bio-Informatics
Expand All @@ -22,7 +22,7 @@ classifiers =
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
keywords =
keywords =
microbiome
modeling
metabolism
Expand All @@ -32,26 +32,26 @@ keywords =
zip_safe = False
packages = find:
python_requires = >=3.6
install_requires =
install_requires =
cobra>=0.29.0
micom>=0.36.0
micom>=0.37.0
jinja2>=2.10.3
qiime2>=2023.2
rich>=6.0
pandas>=1.0
numpy<2.0
tests_require =
tests_require =
coverage
pytest
pytest-cov
flake8

[options.package_data]
q2_micom =
q2_micom =
citations.bib

[options.entry_points]
qiime2.plugins =
qiime2.plugins =
q2-micom = q2_micom.plugin_setup:plugin

[bumpversion:file:setup.py]
Expand All @@ -63,7 +63,7 @@ search = __version__ = "{current_version}"
replace = __version__ = "{new_version}"

[tool:pytest]
filterwarnings =
filterwarnings =
ignore::DeprecationWarning
ignore::FutureWarning

Expand All @@ -76,15 +76,15 @@ branch = True
omit = q2_micom/tests/*

[coverage:report]
exclude_lines =
exclude_lines =
pragma: no cover

def __repr__
if self\.debug

raise AssertionError
raise NotImplementedError

if 0:
if __name__ == .__main__.:
ignore_errors = True
Expand Down

0 comments on commit af1b22a

Please sign in to comment.