Skip to content

Commit

Permalink
🎨📝✅💚⬆️ Add geom_median to env, move favicon assets
Browse files Browse the repository at this point in the history
📝🎨 Add Bioconda project url to setup.py
🎨 Add toast when browser storage limits are reached (issue #11)
:art::memo: Move favicon to automappa/assets
:arrow_up::art: Add geom-median to environment.yml
:art: Add get_clusters_geom_medians(...) to celery tasks
:arrow_up::art: Bump VERSION to 2.2.0
:see_no_evil: Add data to .gitignore
  • Loading branch information
evanroyrees committed Apr 12, 2022
1 parent c096c3e commit ed8c0d1
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ app/__pycache__
dist
build
Automappa.egg-info
.env
.env
data
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.0
2.2.0
1 change: 0 additions & 1 deletion automappa/app/assets/site.webmanifest

This file was deleted.

File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
1 change: 1 addition & 0 deletions automappa/assets/site.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}
39 changes: 38 additions & 1 deletion automappa/celery.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/usr/bin/env python



import os
import glob
import pandas as pd

from autometa.common.external import hmmscan
from geom_median.numpy import compute_geometric_median
from celery import Celery, chain
from dotenv import load_dotenv
from autometa.common.external import hmmscan

load_dotenv()

Expand All @@ -21,6 +24,7 @@
# TODO: Marker symbols
# TODO: CheckM annotation
# TODO: kmer freq. analysis pipeline
# TODO: scatterplot 2-d embedding views

@CELERY.task
def hmmdb_formatter(hmmdb) -> None:
Expand Down Expand Up @@ -69,3 +73,36 @@ def scanner(seqfile, hmmdb, out) -> str:
out = os.path.join(outdir, outfilename)
hmmdb_formatter.s(hmmdb).apply_async()
scanner.s(seqfile, hmmdb, out).apply_async(countdown=2)


def get_clusters_geom_medians(df: pd.DataFrame, cluster_col: str = "cluster", weight_col: str='length') -> pd.DataFrame:
"""Compute each cluster's (`cluster_col`) geometric median weighted by contig length (`weight_col`)
Parameters
----------
df : pd.DataFrame
Table containing x_1 and x_2 coordinates and `cluster_col` from embedding
cluster_col : str, optional
Value to use for cluster column, by default "cluster"
weight_col : str, optional
Column to use for weighting the geometric median computation, by default 'length'
Returns
-------
pd.DataFrame
index=range(cluster_1, cluster_n), cols=[cluster_col, x_1, x_2, termination, weighted]
`x_1` and `x_2` correspond to the computed geometric median values corresponding to the respective cluster.
`termination` is the reason of termination passed from the `compute_geometric_median` function
`weighted` denotes the value that was used for weighting the cluster's geometric median (`weight_col`)
"""
medians = []
for cluster, dff in df.groupby(cluster_col):
points = dff[['x_1', 'x_2']].to_numpy()
if weight_col:
weights = dff[weight_col].to_numpy()
out = compute_geometric_median(points=points, weights=weights)
median = out.median
medians.append({cluster_col: cluster, "x_1": median[0], "x_2": median[1], "termination": out.termination, "weighted":weight_col})
medians_df = pd.DataFrame(medians)
return medians_df
18 changes: 16 additions & 2 deletions automappa/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,25 @@ def main():

# Check dataset size for dcc.Store(...) with browser limits...
# For details see: https://stackoverflow.com/a/61018107 and https://arty.name/localstorage.html
chrome_browser_quota = 5200000
chrome_browser_quota = 5_200_000
dataset_chars = len(binning.to_json(orient="split"))
if dataset_chars >= chrome_browser_quota:
logger.warning(f"{args.binning_main} exceeds browser storage limits ({dataset_chars} > {chrome_browser_quota}).")
logger.warning(f"{args.binning_main} exceeds browser storage limits ({dataset_chars:,} > {chrome_browser_quota:,}).")
logger.warning("Persisting refinements is DISABLED!")

browser_storage_toast = dbc.Toast(
f"{args.binning_main} exceeds browser storage limits ({dataset_chars:,} > {chrome_browser_quota:,}).",
id="positioned-toast",
header="Persisting refinements DISABLED",
is_open=True,
dismissable=True,
icon="danger",
# top: 66 positions the toast below the navbar
style={"position": "fixed", "top": 66, "right": 10, "width": 350},
)
else:
browser_storage_toast = dbc.Toast(is_open=False)

# Metagenome Annotations Store
metagenome_annotations_store = dcc.Store(
id="metagenome-annotations",
Expand Down Expand Up @@ -194,6 +207,7 @@ def main():
dbc.Tabs(
id="tabs", children=[refinement_tab, summary_tab], className="nav-fill"
),
html.Div(browser_storage_toast),
html.Div(id="tab-content"),
],
fluid=True,
Expand Down
3 changes: 2 additions & 1 deletion automappa/utils/figures.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from dash.exceptions import PreventUpdate
from plotly import graph_objects as go


def taxonomy_sankey(df: pd.DataFrame, selected_rank: str = "species") -> go.Figure:
ranks = ["superkingdom", "phylum", "class", "order", "family", "genus", "species"]
n_ranks = len(ranks[: ranks.index(selected_rank)])
Expand Down Expand Up @@ -113,6 +112,8 @@ def marker_size_scaler(x: pd.DataFrame, scale_by: str = "length") -> int:
return x_scaled




def get_scatterplot_2d(
df,
x_axis: str = "x_1",
Expand Down
6 changes: 6 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ dependencies:
- numpy
- pandas
- plotly
<<<<<<< Updated upstream
- python-dotenv
=======
- pip
- pip:
- geom-median
>>>>>>> Stashed changes
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def read(fname):
python_requires=">=3.7",
version=version,
packages=find_packages(exclude=["tests"]),
package_data={"": ["app/assets/*"]},
package_data={"": ["assets/*"]},
entry_points={
"console_scripts": [
"automappa = automappa.__main__:main",
Expand All @@ -32,6 +32,10 @@ def read(fname):
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/WiscEvan/Automappa",
project_urls={
"Bug Tracker": "https://github.com/WiscEvan/Automappa/issues",
"Bioconda": "https://anaconda.org/bioconda/automappa",
},
license="GNU Affero General Public License v3 or later (AGPLv3+)",
classifiers=[
"Programming Language :: Python",
Expand Down

0 comments on commit ed8c0d1

Please sign in to comment.