Skip to content

Commit

Permalink
Pkg_restructure (#20)
Browse files Browse the repository at this point in the history
* 🎨 move to src layout

* 🔥 moved to pyproject.toml (from setup.py)

* 🎨🔖 switch to dynamic versioning based on tags

- each commit gets his own version relativ to the last tag
- releases do not require manuel setting of version (they pick it up from the git tags)

* 🐛 set src pkg path correctly for readthedocs

* 🐛 forgot to activate scm via setting an entry in pyproject.toml

see https://setuptools-scm.readthedocs.io
  • Loading branch information
enryH authored Jan 17, 2025
1 parent 6fcb846 commit 6f08e8b
Show file tree
Hide file tree
Showing 36 changed files with 89 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Options:
```bash
# pwd: docs
# apidoc
sphinx-apidoc --force --implicit-namespaces --module-first -o reference ../acore
sphinx-apidoc --force --implicit-namespaces --module-first -o reference ../src/acore
# build docs
sphinx-build -n -W --keep-going -b html ./ ./_build/
```
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
from pathlib import Path

PROJECT_ROOT = Path(__file__).parent.parent
PACKAGE_ROOT = PROJECT_ROOT / "acore"
PACKAGE_ROOT = PROJECT_ROOT / "src" / "acore"

def run_apidoc(_):
from sphinx.ext import apidoc
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = [{ name = "Alberto Santos Delgado", email = "[email protected]" },
{ name = "Henry Webel", email = "[email protected]"}]
name = "acore"
version = "0.1.2"
dynamic = ["version"]
description = "A Python package with statistical functions to analyse multimodal molecular data"
license = { text = "GNU General Public License v3" }
readme = "README.rst"
Expand Down Expand Up @@ -68,9 +68,11 @@ Documentation = "https://analytics-core.readthedocs.io/"


[build-system]
requires = ["setuptools"]
requires = ["setuptools>=64", "setuptools_scm>=8"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]

# [entrypoints]
# console_scripts = {
# "acore = acore.cli:main"
Expand Down
19 changes: 2 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
#!/usr/bin/env python
from setuptools import setup

"""The setup script."""

from setuptools import setup, find_packages

setup(
entry_points={
'console_scripts': [
'acore=acore.cli:main',
],
},
include_package_data=True,
keywords='acore',
packages=find_packages(include=['acore', 'acore.*']),
url='https://github.com/Multiomics-Analytics-Group/acore',
zip_safe=False,
)
setup()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
81 changes: 81 additions & 0 deletions src/acore/plotting/metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""Plot metrics for binary classification."""

import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
from njab.sklearn.types import Results, ResultsSplit

LIMITS = (-0.05, 1.05)


def plot_split_auc(
result: ResultsSplit, name: str, ax: matplotlib.axes.Axes
) -> matplotlib.axes.Axes:
"""Add receiver operation curve to ax of a split of the data."""
col_name = f"{name} (auc: {result.auc:.3f})"
roc = pd.DataFrame(result.roc, index="fpr tpr cutoffs".split()).rename(
{"tpr": col_name}
)
ax = roc.T.plot(
"fpr",
col_name,
xlabel="false positive rate",
ylabel="true positive rate",
style=".-",
ylim=LIMITS,
xlim=LIMITS,
ax=ax,
)
return ax


# ! should be roc
def plot_auc(
results: Results,
ax: matplotlib.axes.Axes = None,
label_train="train",
label_test="test",
**kwargs,
) -> matplotlib.axes.Axes:
"""Plot ROC curve for train and test data."""
if ax is None:
fig, ax = plt.subplots(1, 1, **kwargs)
ax = plot_split_auc(results.train, f"{label_train}", ax)
ax = plot_split_auc(results.test, f"{label_test}", ax)
return ax


def plot_split_prc(
result: ResultsSplit, name: str, ax: matplotlib.axes.Axes
) -> matplotlib.axes.Axes:
"""Add precision recall curve to ax of a split of the data."""
col_name = f"{name} (aps: {result.aps:.3f})"
roc = pd.DataFrame(result.prc, index="precision recall cutoffs".split()).rename(
{"precision": col_name}
)
ax = roc.T.plot(
"recall",
col_name,
xlabel="true positive rate",
ylabel="precision",
style=".-",
ylim=LIMITS,
xlim=LIMITS,
ax=ax,
)
return ax


def plot_prc(
results: ResultsSplit,
ax: matplotlib.axes.Axes = None,
label_train="train",
label_test="test",
**kwargs,
):
"""Plot precision recall curve for train and test data."""
if ax is None:
fig, ax = plt.subplots(1, 1, **kwargs)
ax = plot_split_prc(results.train, f"{label_train}", ax)
ax = plot_split_prc(results.test, f"{label_test}", ax)
return ax
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 6f08e8b

Please sign in to comment.