Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format docstring, use auto doc typehints #160

Merged
merged 3 commits into from
Jan 26, 2023
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
80 changes: 40 additions & 40 deletions dance/data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,43 @@ def _check_types_and_sizes(types, sizes):


class BaseData(ABC):
"""Base data object."""
"""Base data object.

_FEATURE_CONFIGS: List[str] = ["feature_mod", "feature_channel", "feature_channel_type"]
_LABEL_CONFIGS: List[str] = ["label_mod", "label_channel", "label_channel_type"]
_DATA_CHANNELS: List[str] = ["obs", "var", "obsm", "varm", "obsp", "varp", "layers", "uns"]
The ``dance`` data object is a wrapper of the :class:`~anndata.AnnData` object, with several utility methods to
help retrieving data in specific splits in specific format (see :meth:`~BaseData.get_split_idx` and
:meth:`~BaseData.get_feature`). The :class:`~anndata.AnnData` objcet is saved in the attribute ``data`` and can be
accessed directly.

def __init__(self, data: Union[AnnData, MuData], train_size: Optional[int] = None, val_size: int = 0,
test_size: int = -1):
"""Initialize data object.
Warning
-------
Since the underlying data object is a reference to the input :class:`~anndata.AnnData` object, please be extra
cautious ***NOT*** initializing two different dance ``data`` object using the same :class:`~anndata.AnnData`
object! If you are unsure, we recommend always initialize the dance ``data`` object using a ``copy`` of the input
:class:`~anndata.AnnData` object, e.g.,

The `dance` data object is a wrapper of the :class:`~anndata.AnnData` object, with several utility methods
to help retrieving data in specific splits in specific format (see :meth:`~BaseData.get_split_idx` and
:meth:`~BaseData.get_feature`). The `AnnData` objcet is saved in the attribute :attr:`data` and can be
accessed directly.
>>> adata = anndata.AnnData(...)
>>> ddata = dance.data.Data(adata.copy())

Warning
-------
Since the underlying data object is a reference to the input :class:`~anndata.AnnData` object, please be
extra cautious ***NOT*** initializing two different dance `data` object using the same `AnnData` object!
If you are unsure, we recommend always initialize the dance `data` object using a `copy` of the input
`AnnData` object, e.g.,
Parameters
----------
data
Cell data.
train_size
Number of cells to be used for training. If not specified, not splits will be generated.
val_size
Number of cells to be used for validation. If set to -1, use what's left from training and testing.
test_size
Number of cells to be used for testing. If set to -1, used what's left from training and validation.

>>> adata = anndata.AnnData(...)
>>> ddata = dance.data.Data(adata.copy())

Parameters
----------
data
Cell data.
train_size
Number of cells to be used for training. If not specified, not splits will be generated.
val_size
Number of cells to be used for validation. If set to -1, use what's left from training and testing.
test_size
Number of cells to be used for testing. If set to -1, used what's left from training and validation.
"""

"""
_FEATURE_CONFIGS: List[str] = ["feature_mod", "feature_channel", "feature_channel_type"]
_LABEL_CONFIGS: List[str] = ["label_mod", "label_channel", "label_channel_type"]
_DATA_CHANNELS: List[str] = ["obs", "var", "obsm", "varm", "obsp", "varp", "layers", "uns"]

def __init__(self, data: Union[AnnData, MuData], train_size: Optional[int] = None, val_size: int = 0,
test_size: int = -1):
super().__init__()

self._data = data
Expand Down Expand Up @@ -143,8 +143,8 @@ def config(self) -> Dict[str, Any]:

Notes
-----
The configuration dictionary is saved in the :attr:`data` attribute, which is an :class:`~anndata.AnnData`
object. Inparticular, the config will be saved in the `.uns` attribute with the key `"dance_config"`.
The configuration dictionary is saved in the ``data`` attribute, which is an :class:`~anndata.AnnData`
object. Inparticular, the config will be saved in the ``.uns`` attribute with the key ``"dance_config"``.

"""
return self._data.uns["dance_config"]
Expand All @@ -166,8 +166,8 @@ def set_config_from_dict(self, config_dict: Dict[str, Any], *, overwrite: bool =
Configuration dictionary.
overwrite
Used to determine the behaviour of resolving config conflicts. In the case of a conflict, where the config
dict passed contains a key with value that differs from an existing setting, if `overwrite` is set to
`False`, then raise a `KeyError`. Otherwise, overwrite the configuration with the new values.
dict passed contains a key with value that differs from an existing setting, if ``overwrite`` is set to
``False``, then raise a ``KeyError``. Otherwise, overwrite the configuration with the new values.

"""
# Check config key validity
Expand Down Expand Up @@ -305,14 +305,14 @@ def get_feature(self, *, split_name: Optional[str] = None, return_type: FeatType
How should the features be returned. **numpy**: return as a numpy array; **torch**: return as a torch
tensor; **anndata**: return as an anndata object.
channel
Return a particular channel as features. If `channel_type` is `obs`, then return the column named by
`channel`, similarly for `var`. If `channel_type` is `obsm`, `obsp`, `varm`, `varp`, `layers`, or `uns`,
then return the value correspond to the `channel` in the dictionary. If `channel` is not specified
(default), then return the default layer (`.X`).
Return a particular channel as features. If ``channel_type`` is ``obs``, then return the column named by
``channel``, similarly for ``var``. If ``channel_type`` is ``obsm``, ``obsp``, ``varm``, ``varp``,
``layers``, or ``uns``, then return the value correspond to the ``channel`` in the dictionary. If
``channel`` is not specified (default), then return the default layer (``.X``).
channel_type
Channel type to use, default to `obsm`.
Channel type to use, default to ``obsm``.
mod
Modality to use, default to `None`. Options other than `None` are only available when the underlying
Modality to use, default to ``None``. Options other than ``None`` are only available when the underlying
data object is :class:`~mudata.Mudata`.

"""
Expand Down
10 changes: 10 additions & 0 deletions dance/datasets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@


class BaseDataset(ABC):
"""BaseDataset abstract object.

Parameters
----------
root
Root directory of the dataset.
full_download
If set to ``True``, then attempt to download all raw files of the dataset.

"""

_DISPLAY_ATTRS: Tuple[str] = ()

Expand Down
8 changes: 4 additions & 4 deletions dance/modules/multi_modality/joint_embedding/jae.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@

Reference
---------
Liu Q, Chen S, Jiang R, et al. Simultaneous deep generative modelling and clustering of single-cell genomic data[J]. Nature machine intelligence, 2021, 3(6): 536-544.
Liu Q, Chen S, Jiang R, et al. Simultaneous deep generative modelling and clustering of single-cell genomic data[J].
Nature machine intelligence, 2021, 3(6): 536-544.

"""

import math
import os

import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torch.utils.data import DataLoader

from dance.utils import SimpleIndexDataset
Expand All @@ -34,7 +33,8 @@ class JAEWrapper:
Parameters
----------
args : argparse.Namespace
A Namespace object that contains arguments of JAE. For details of parameters in parser args, please refer to link (parser help document).
A Namespace object that contains arguments of JAE. For details of parameters in parser args, please refer to
link (parser help document).
dataset : dance.datasets.multimodality.JointEmbeddingNIPSDataset
Joint embedding dataset.

Expand Down
6 changes: 4 additions & 2 deletions dance/modules/multi_modality/match_modality/scmogcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

Reference
---------
Wen, Hongzhi, et al. "Graph Neural Networks for Multimodal Single-Cell Data Integration." arXiv preprint arXiv:2203.01884 (2022).
Wen, Hongzhi, et al. "Graph Neural Networks for Multimodal Single-Cell Data Integration." arXiv preprint
arXiv:2203.01884 (2022).

"""
import math
Expand Down Expand Up @@ -39,7 +40,8 @@ class ScMoGCNWrapper:
Parameters
----------
args : argparse.Namespace
A Namespace object that contains arguments of ScMoGCN. For details of parameters in parser args, please refer to link (parser help document).
A Namespace object that contains arguments of ScMoGCN. For details of parameters in parser args, please refer
to link (parser help document).
layers : list[int]
Specification of dimensions of hidden layers.
temp : int optional
Expand Down
25 changes: 12 additions & 13 deletions dance/modules/single_modality/cell_type_annotation/actinn.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@


class ACTINN(nn.Module):
"""The ACTINN cell-type classification model."""
"""The ACTINN cell-type classification model.

Parameters
----------
hidden_dims : :obj:`tuple` of int
Hidden layer dimensions.
lambd : float
Regularization parameter
device : str
Training device

"""

def __init__(
self,
Expand All @@ -29,18 +40,6 @@ def __init__(
lambd: float = 0.01,
device: str = "cpu",
):
"""Initialize the ACTINN model.

Parameters
----------
hidden_dims : :obj:`tuple` of int
Hidden layer dimensions.
lambd : float
Regularization parameter
device : str
Training device

"""
super().__init__()

# Save attributes
Expand Down
Loading