Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions docs/_templates/autosummary/class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

.. add toctree option to make autodoc generate the pages

.. autoclass:: {{ objname }}
.. autoclass:: {{ fullname }}

{% set methods = methods | select("ne", "__init__") | list %}

{% block attributes %}
{% if attributes %}
Expand All @@ -25,10 +27,8 @@ Methods table

.. autosummary::
{% for item in methods %}
{%- if item != '__init__' %}
~{{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% endfor %}
{% endif %}
{% endblock %}

Expand All @@ -51,10 +51,8 @@ Methods
~~~~~~~

{% for item in methods %}
{%- if item != '__init__' %}

.. automethod:: {{ [objname, item] | join(".") }}
{%- endif -%}
{%- endfor %}

{% endif %}
Expand Down
62 changes: 62 additions & 0 deletions docs/_templates/autosummary/module.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{ fullname | escape | underline}}

.. automodule:: {{ fullname }}

{% block attributes %}
{% if attributes %}
.. rubric:: {{ _('Module Attributes') }}

.. autosummary::
{% for item in attributes %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block functions %}
{% if functions %}
.. rubric:: {{ _('Functions') }}

.. autosummary::
:toctree:
{% for item in functions %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block classes %}
{% if classes %}
.. rubric:: {{ _('Classes') }}

.. autosummary::
:toctree:
{% for item in classes %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block exceptions %}
{% if exceptions %}
.. rubric:: {{ _('Exceptions') }}

.. autosummary::
:toctree:
{% for item in exceptions %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block modules %}
{% if modules %}
.. rubric:: Modules

.. autosummary::
:toctree:
{% for item in modules %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
35 changes: 18 additions & 17 deletions docs/api/index.md → docs/api.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
# API

```{eval-rst}
.. module:: mofaflex
```

```{eval-rst}
.. currentmodule:: mofaflex

.. toctree::
:hidden:

core.md
tools.md
plotting.md
```

## Core

```{eval-rst}
.. autosummary::
:toctree: generated

DataOptions
ModelOptions
Expand All @@ -29,11 +19,13 @@
FeatureSets
```

### Presets

### Priors
```{eval-rst}
.. automodule:: mofaflex.presets
:no-index:
.. autosummary::
:toctree: generated
:recursive:

priors
```

### Settings
Expand All @@ -43,18 +35,27 @@ An instance of the [](#_core.settings.Settings) class is available as `mofaflex.
```{eval-rst}
.. currentmodule:: mofaflex
.. autosummary::
:toctree: generated

_core.settings.Settings
```

## Tools

```{eval-rst}
.. automodsumm:: mofaflex.tl
.. autosummary::
:toctree: generated
:recursive:

tl
```

## Plotting

```{eval-rst}
.. automodsumm:: mofaflex.pl
.. autosummary::
:toctree: generated
:recursive:

pl
```
33 changes: 0 additions & 33 deletions docs/api/core.md

This file was deleted.

6 changes: 0 additions & 6 deletions docs/api/plotting.md

This file was deleted.

6 changes: 0 additions & 6 deletions docs/api/tools.md

This file was deleted.

1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
]

autosummary_generate = True
autosummary_imported_members = True
autodoc_member_order = "groupwise"
default_role = "literal"
napoleon_google_docstring = True
Expand Down
19 changes: 0 additions & 19 deletions docs/extensions/autoapisummary.py

This file was deleted.

2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
notebooks/getting_started.ipynb
tutorials.md
modeldescription.md
api/index
api.md
changelog.md
contributing.md
references.md
Expand Down
13 changes: 2 additions & 11 deletions src/mofaflex/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import logging

from . import pl, tl
from ._core import (
MOFAFLEX,
DataOptions,
FeatureSet,
FeatureSets,
ModelOptions,
SmoothOptions,
TrainingOptions,
presets,
settings,
)
from ._core import MOFAFLEX, DataOptions, FeatureSet, FeatureSets, ModelOptions, TrainingOptions, settings
from ._core.api import priors
from ._version import __version__, __version_tuple__

_logger = logging.getLogger(__name__)
Expand Down
3 changes: 1 addition & 2 deletions src/mofaflex/_core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from . import presets
from .datasets import MofaFlexDataset
from .feature_sets import FeatureSet, FeatureSets
from .mofaflex import MOFAFLEX, DataOptions, ModelOptions, SmoothOptions, TrainingOptions
from .mofaflex import MOFAFLEX, DataOptions, ModelOptions, TrainingOptions
from .pcgse import pcgse_test
from .settings import settings
1 change: 1 addition & 0 deletions src/mofaflex/_core/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import priors
76 changes: 76 additions & 0 deletions src/mofaflex/_core/api/priors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from abc import ABC, abstractmethod
from collections.abc import Sequence
from inspect import Parameter, signature
from types import MappingProxyType
from typing import Literal

from ..priors import Prior as PriorCore


class Prior(ABC):
@abstractmethod
def __call__(self, axis, names):
pass

def __init__(self, *args, **kwargs):
self._args = args
self._kwargs = MappingProxyType(kwargs)

def __eq__(self, other):
if not isinstance(other, __class__):
return NotImplemented
elif other.__class__ != self.__class__:
return False
else:
return self._args == other._args and self._kwargs == other._kwargs

def __hash__(self):
return hash((self.__class__, self._args, tuple(sorted(self._kwargs.items()))))


__all__ = []


def _init_priors():
for priorname in PriorCore.known_priors():
priorcls = PriorCore.class_(priorname)
sig = signature(priorcls.__init__)
params = [param for param in sig.parameters.values() if param.name not in ("axis", "names")]
sig = sig.replace(parameters=params)

def init(self, *args, **kwargs):
self.__init__.__signature__.bind(self, *args, **kwargs) # check for argument compatibility
super(self.__class__, self).__init__(*args, **kwargs)

if priorcls is not PriorCore:

def call(self, axis: Literal[0, 1, "samples", "features"], names: str | Sequence[str]):
return self._cls(axis, names, *self._args, **self._kwargs)
else:

def call(self, axis: Literal[0, 1, "samples", "features"], names: str | Sequence[str]):
return PriorCore(self.__class__.__name__, axis, names, *self._args, **self._kwargs)

init.__signature__ = sig
init.__annotations__ = {
param.name: param.annotation for param in params if param.annotation is not Parameter.empty
}
init.__name__ = "__init__"
init.__qualname__ = f"{priorname}.__init__"
call.__name__ = "__call__"
call.__qualname__ = f"{priorname}.__call__"
apicls = type(
priorname, (Prior,), {"_cls": priorcls, "__init__": init, "__call__": call, "__module__": __name__}
)
if priorcls is not PriorCore:
apicls.__doc__ = priorcls.__doc__

globals()[priorname] = apicls
__all__.append(priorname)


_init_priors()


def __dir__():
return __all__
Loading
Loading