Skip to content

Commit

Permalink
Bug fixes for plot methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerdougan committed Jun 23, 2024
1 parent bb13b0f commit ffdb8c6
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 193 deletions.
45 changes: 2 additions & 43 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ waltlabtools

.. image:: https://img.shields.io/conda/vn/tylerdougan/waltlabtools?label=Anaconda
:target: https://anaconda.org/tylerdougan/waltlabtools
:alt: Conda
:alt: Anaconda
.. image:: https://img.shields.io/pypi/v/waltlabtools?label=PyPI
:target: https://pypi.org/project/waltlabtools
:alt: PyPI
.. image:: https://img.shields.io/readthedocs/waltlabtools?label=Documentation
:target: https://waltlabtools.readthedocs.io/en/latest/
:alt: Documentation
.. image:: https://img.shields.io/github/repo-size/tylerdougan/waltlabtools?label=GitHub
.. image:: https://img.shields.io/github/issues/tylerdougan/waltlabtools?label=GitHub
:target: https://github.com/tylerdougan/waltlabtools
:alt: GitHub


A collection of tools for biomedical research assay analysis in Python.

Key Features
Expand Down Expand Up @@ -51,46 +50,6 @@ first install Anaconda or
with Python).


Dependencies
^^^^^^^^^^^^

- waltlabtools requires

- `numpy <https://numpy.org/doc/stable/index.html>`__ ≥ 1.10

- `scipy <https://docs.scipy.org/doc/scipy/getting_started.html>`__ ≥ 1.3

- If installing with pip or conda, numpy and scipy will be installed
automatically

- Specific modules have additional requirements:

- `waltlabtools.read <https://waltlabtools.readthedocs.io/en/latest/waltlabtools.read.html>`__
(for importing data from Quanterix instruments) requires

- `pandas <https://pandas.pydata.org>`__ ≥ 0.25

- waltlabtools also plays well with

- `JAX <https://jax.readthedocs.io/en/latest/index.html>`__
for accelerated numerical computing – waltlabtools will use jax.numpy
instead of numpy if jax is loaded

- `JupyterLab <https://jupyterlab.readthedocs.io/en/stable/>`__
for interactively writing code

- `pandas <https://pandas.pydata.org>`__
for data import/export and organization

- `matplotlib <https://matplotlib.org>`__ for plotting

- `scikit-learn <https://scikit-learn.org/stable/>`__ for data analysis

All of these packages can all be installed using
`conda <https://docs.conda.io/projects/conda/en/latest/user-guide/install/download.html>`__
or `pip <https://pypi.org>`__.


Usage
^^^^^

Expand Down
Binary file added docs/__pycache__/conf.cpython-312.pyc
Binary file not shown.
84 changes: 14 additions & 70 deletions docs/_build/_modules/waltlabtools/cal_curve.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions meta.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{% set name = "waltlabtools" %}
{% set version = "1.0.0b25" %}
{% set version = "1.0.0b26" %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
url: https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/waltlabtools-{{ version }}.tar.gz
sha256: 6804e087f3bc6b760e009355ca9c52e2bc161457915adc47c41620882432adbc
sha256: d38888eab34192924a264309c258ab0451a55b28f23bb08e35124e9ffd6ffa24

build:
noarch: python
Expand Down
10 changes: 4 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies = [
]
requires-python = ">= 3.8"
authors = [
{name = "Tyler Dougan", email = "tyler_dougan@hst.harvard.edu"}
{name = "Tyler Dougan", email = "tylerdougan@harvard.simplelogin.com"}
]
description = "A collection of tools for biomedical research assay analysis in Python."
readme = "README.rst"
Expand All @@ -29,8 +29,6 @@ classifiers = [
]

[project.optional-dependencies]
jax = ["jax"]
numba = ["numba"]
all = [
"jax",
"numba",
Expand All @@ -43,11 +41,11 @@ all = [
]

[project.urls]
Homepage = "https://github.com/tylerdougan/waltlabtools/"
Anaconda = "https://anaconda.org/tylerdougan/waltlabtools"
Documentation = "https://waltlabtools.readthedocs.io/en/latest/"
PyPI = "https://pypi.org/project/waltlabtools/"
Homepage = "https://github.com/tylerdougan/waltlabtools/"
"Issue Tracker" = "https://github.com/tylerdougan/waltlabtools/issues"
Anaconda = "https://anaconda.org/tylerdougan/waltlabtools"
PyPI = "https://pypi.org/project/waltlabtools/"

[tool.setuptools.dynamic]
version = {attr = "waltlabtools.__version__"}
Expand Down
3 changes: 2 additions & 1 deletion src/waltlabtools.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: waltlabtools
Version: 1.0.0b25
Version: 1.0.0b26
Summary: A collection of tools for biomedical research assay analysis in Python.
Author-email: Tyler Dougan <tyler_dougan@hst.harvard.edu>
Project-URL: Homepage, https://github.com/tylerdougan/waltlabtools/
Expand Down Expand Up @@ -35,6 +35,7 @@ Requires-Dist: numexpr; extra == "all"
Requires-Dist: bottleneck; extra == "all"
Requires-Dist: jinja2; extra == "all"
Requires-Dist: openpyxl; extra == "all"
Requires-Dist: xlrd; extra == "all"

waltlabtools
============
Expand Down
1 change: 1 addition & 0 deletions src/waltlabtools.egg-info/requires.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ numexpr
bottleneck
jinja2
openpyxl
xlrd

[jax]
jax
Expand Down
2 changes: 1 addition & 1 deletion src/waltlabtools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from .model import *
from .read import *

__version__ = "v1.0.0b26"
__version__ = "v1.0.0b27"
1 change: 1 addition & 0 deletions src/waltlabtools/_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def subplots(
nrows=nrows,
ncols=ncols,
squeeze=False,
**match_kwargs(fig.subplots, kwargs),
)
return fig, axs

Expand Down
84 changes: 14 additions & 70 deletions src/waltlabtools/cal_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,10 @@ def _make_curve_points(self, **kwargs):
)

trans = xscale.get_transform()
vmin = np.amin(self.X_)
vmax = np.amax(self.X_)
minpos = np.amin(self.X_[self.X_ > 0])
if np.isfinite(self.lod_):
vmin = min(vmin, self.lod_)
vmin = min(np.min(self.X_), self.lod_)
vmax = np.max(self.X_)
minpos = np.min(self.X_[self.X_ > 0])
if self.lod_ > 0:
minpos = min(minpos, self.lod_)
vmin, vmax = xscale.limit_range_for_scale(vmin=vmin, vmax=vmax, minpos=minpos)
trvmin = trans.transform(vmin)
Expand Down Expand Up @@ -797,77 +796,22 @@ def plot( # type: ignore
cols = self.index.get_level_values(levels[0]).unique()
ncols = self.index.get_level_values(levels[0]).nunique()
nrows = self.index.get_level_values(0).value_counts().max()
fig, axs = subplots(nrows=nrows, ncols=ncols, fig=fig, **kwargs)
fig, axs = subplots(
nrows=nrows, ncols=ncols, fig=fig, squeeze=False, **kwargs
)

ax_s = pd.Series(index=self.index)
ax_s = pd.Series(index=self.index.sort_values(), dtype=object)
for c, col in enumerate(cols):
# idx = sorted(self.index[self.index.get_level_values(levels[0]) == col])
# ax_s[col] = dict(zip(idx, axs[:, c]))
ax_s[col] = axs[: len(ax_s[col]), c]
else:
nrows = int(np.ceil(len(self) / max_cols))
ncols = int(np.ceil(len(self) / nrows))
fig, axs = subplots(nrows=nrows, ncols=ncols, fig=fig, **kwargs)
ax_s = pd.Series(dict(zip(self.index, np.ravel(axs))))
ax_s = pd.Series(dict(zip(self.index.sort_values(), np.ravel(axs))))

for i, ax in ax_s.items():
title = "\n".join(str(a) for a in i) if isinstance(i, tuple) else i
self[i].plot(ax=ax, title=title, **match_kwargs(self[i].plot, kwargs))

return ax_s.item() if len(ax_s) == 1 else axs # type: ignore
# self_notna = self[self.notna()]

# if len(self_notna) == 0:
# # empty series
# ax_map = {}

# elif len(self_notna) == 1:
# # only one CalCurve in series
# if ax is not None and isinstance(ax, Axes):
# if fig is None:
# fig = ax.figure
# elif fig is not None:
# ax = fig.subplots(**match_kwargs(plt.subplots, kwargs))
# else:
# fig, ax = self.subplots(**kwargs)
# ax_map = {self.index[0]: ax}

# elif self.index.nlevels == 1:
# # only one assay or only one plex
# if len(self) <= max_cols:
# fig, axs = self.subplots(ncols=len(self_notna), **kwargs)
# ax_map = {self_notna.index[i]: axs[i] for i in range(len(self_notna))}
# else:
# nrows = int(np.ceil(len(self) / max_cols))
# fig, axs = self.subplots(nrows=nrows, ncols=max_cols, **kwargs)
# ax_map = {
# self_notna.index[i]: axs[divmod(i, max_cols)]
# for i in range(len(self_notna))
# }

# else:
# # try to lay out cal curves according to assay and plex
# ncols = self.index.get_level_values(0).nunique()
# nrows = self.index.get_level_values(0).value_counts().max()
# fig, axs = self.subplots(nrows=nrows, ncols=ncols, **kwargs)
# ax_map = {}
# for a0, assay_level_0 in enumerate(
# sorted(self_notna.index.get_level_values(0).unique())
# ):
# for a1, assay_level_1 in enumerate(
# sorted(self_notna[assay_level_0].index)
# ):
# ax_map[(assay_level_0, assay_level_1)] = axs[a1, a0]

# for assay, ax in ax_map.items():
# if hasattr(assay, "__iter__") and not isinstance(assay, str):
# title = "\n".join([str(a) for a in assay])
# else:
# title = assay
# self[assay].plot(
# ax=ax, title=title, **match_kwargs(self[assay].plot, kwargs)
# ) # type: ignore
# return

# # if tight_layout:
# # plt.tight_layout()
if isinstance(self[i], CalCurve):
title = "\n".join(str(a) for a in i) if isinstance(i, tuple) else i
self[i].plot(ax=ax, title=title, **kwargs)

return ax_s.item() if len(ax_s) == 1 else axs

0 comments on commit ffdb8c6

Please sign in to comment.