Skip to content

Commit

Permalink
Deprecate pages module and update docs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
percyfal committed Nov 8, 2024
1 parent 42ee0ec commit e25d0a5
Show file tree
Hide file tree
Showing 22 changed files with 209 additions and 1,585 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dev-dependencies = [
"pip~=24.2",
"hatch-vcs~=0.4.0",
"watchfiles~=0.24.0",
"pytest-playwright~=0.5.2",
]

[project.scripts]
Expand Down
17 changes: 17 additions & 0 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ geopandas==1.0.1
# via tseda
geoviews==1.13.0
# via tseda
greenlet==3.1.1
# via playwright
h11==0.14.0
# via httpcore
hatch-vcs==0.4.0
Expand Down Expand Up @@ -365,6 +367,8 @@ pip==24.2
platformdirs==4.2.2
# via jupyter-core
# via pooch
playwright==1.48.0
# via pytest-playwright
pluggy==1.5.0
# via hatchling
# via pytest
Expand All @@ -388,6 +392,8 @@ pycparser==2.22
# via cffi
pyct==0.5.0
# via datashader
pyee==12.0.0
# via playwright
pygments==2.18.0
# via ipython
# via jupyter-console
Expand All @@ -407,6 +413,11 @@ pyshp==2.3.1
pyslim==1.0.4
# via stdpopsim
pytest==8.3.2
# via pytest-base-url
# via pytest-playwright
pytest-base-url==2.1.0
# via pytest-playwright
pytest-playwright==0.5.2
python-dateutil==2.9.0.post0
# via arrow
# via jupyter-client
Expand All @@ -415,6 +426,8 @@ python-dateutil==2.9.0.post0
python-json-logger==2.0.7
# via daiquiri
# via jupyter-events
python-slugify==8.0.4
# via pytest-playwright
pytz==2024.1
# via pandas
pyviz-comms==3.0.3
Expand Down Expand Up @@ -443,6 +456,7 @@ requests==2.32.3
# via jupyterlab-server
# via panel
# via pooch
# via pytest-base-url
rfc3339-validator==0.1.4
# via jsonschema
# via jupyter-events
Expand Down Expand Up @@ -487,6 +501,8 @@ svgwrite==1.4.3
terminado==0.18.1
# via jupyter-server
# via jupyter-server-terminals
text-unidecode==1.3
# via python-slugify
tinycss2==1.3.0
# via nbconvert
toolz==0.12.1
Expand Down Expand Up @@ -536,6 +552,7 @@ types-python-dateutil==2.9.0.20240821
# via arrow
typing-extensions==4.12.2
# via panel
# via pyee
# via pyright
tzdata==2024.1
# via pandas
Expand Down
28 changes: 0 additions & 28 deletions src/tseda/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,6 @@ def cli():
"""Command line interface for tseda."""


@cli.command()
@click.argument("path", type=click.Path(exists=True, dir_okay=False))
@click.option("--port", default=8080, help="Port to serve on")
@click.option(
"--show/--no-show",
default=True,
help="Launch a web-browser showing the app",
)
@click.option("--log-level", default="INFO", help="Logging level")
@click.option(
"--no-log-filter",
default=False,
is_flag=True,
help="Do not filter the output log (advanced debugging only)",
)
def serve2(path, port, show, log_level, no_log_filter):
"""
Run the tseda server, obsolete version.
"""
setup_logging(log_level, no_log_filter)

tsm = model.TSEdaModel(path)

logger.info("Starting panel server")
app_ = app.App(tsm)
pn.serve(app_.view(), port=port, show=show, verbose=False)


@cli.command()
@click.argument("tszip_path", type=click.Path(exists=True, dir_okay=False))
@click.option(
Expand Down
63 changes: 16 additions & 47 deletions src/tseda/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""Main application for tseda.
Provides the DataStoreApp class that is the main application for
tseda. The DataStoreApp subclasses the Viewer class from panel and
renders a panel.FastListTemplate object.
"""

import time

import daiquiri
Expand All @@ -7,7 +14,7 @@
from holoviews import opts
from panel.viewable import Viewer

from tseda import config, datastore, pages, vpages
from tseda import config, datastore, vpages

logger = daiquiri.getLogger("tseda")

Expand Down Expand Up @@ -41,56 +48,14 @@
)


class App:
def __init__(self, tsm):
self.tsm = tsm
t = time.time()
logger.info("Initialising pages")
self.pages = {page.title: page(tsm) for page in pages.PAGES}
self.spinner = pn.indicators.LoadingSpinner(
value=True, width=50, height=50
)
logger.info(f"Initialised pages in {time.time() - t:.2f}s")

def view(self):
page_titles = list(self.pages.keys())
header_selector = pn.widgets.RadioButtonGroup(
options=page_titles,
value=page_titles[0],
name="Select Page",
button_type="success",
)

@pn.depends(header_selector.param.value)
def get_content(selected_page):
yield self.spinner
yield self.pages[selected_page].content

@pn.depends(header_selector.param.value)
def get_sidebar(selected_page):
yield self.spinner
yield self.pages[selected_page].sidebar

template = pn.template.FastListTemplate(
title=self.tsm.name[:15] + "..."
if len(self.tsm.name) > 15
else self.tsm.name,
header=[header_selector],
sidebar=get_sidebar,
main=get_content,
raw_css=[RAW_CSS],
**DEFAULT_PARAMS,
)

return template


class DataStoreApp(Viewer):
"""Main application class for tseda visualization app."""

datastore = param.ClassSelector(class_=datastore.DataStore)

title = param.String()
title = param.String(doc="Application title")

views = param.List()
views = param.List(doc="What views to show on startup.")

def __init__(self, **params):
super().__init__(**params)
Expand All @@ -116,6 +81,10 @@ def __init__(self, **params):

@param.depends("views")
def view(self):
"""Main application view that renders a radio button group on
top with links to pages. Each page consists of a main content
page with plots and sidebars that provide user options for
configuring plots and outputs."""
page_titles = list(self.pages.keys())
header_selector = pn.widgets.RadioButtonGroup(
options=page_titles,
Expand Down
46 changes: 46 additions & 0 deletions src/tseda/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Helper module for serving the TSEda app from the command line using
panel serve.
This module is used to serve the TSEda app from the command line using
panel serve. One use case is for development purposes where the --dev
argument enables automated reloading of the app when the source code
changes. To launch the app from the command line run:
$ panel serve --dev --admin --show --args path/to/tszip_file.zip
See https://panel.holoviz.org/how_to/server/commandline.html for more
information.
"""

from tseda import app # noqa
from tseda import datastore # noqa
from tsbrowse.model import TSModel # noqa
import daiquiri
import sys

daiquiri.setup(level="WARN") # noqa
logger = daiquiri.getLogger("tseda")


if len(sys.argv) < 2:
logger.error(
"Please provide the path to a TreeSequence file via the --args option."
)
sys.exit(1)

path = sys.argv.pop()

tsm = TSModel(path)
individuals_table, sample_sets_table = datastore.preprocess(tsm)

app_ = app.DataStoreApp(
datastore=datastore.DataStore(
tsm=tsm,
individuals_table=individuals_table,
sample_sets_table=sample_sets_table,
),
title="TSEda Datastore App",
views=[datastore.IndividualsTable],
)

app_.view().servable()
Loading

0 comments on commit e25d0a5

Please sign in to comment.