Skip to content

Commit

Permalink
Merge pull request #22 from MICS-Lab/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
quentinblampey authored Sep 25, 2023
2 parents caefeb4 + b5cd347 commit 491ec29
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 62 deletions.
16 changes: 15 additions & 1 deletion docs/api/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
options:
show_root_heading: true

::: scyan.tools.palette_level
::: scyan.tools.leiden
options:
show_root_heading: true

::: scyan.tools.subcluster
options:
show_root_heading: true

::: scyan.tools.palette_level
options:
show_root_heading: true

::: scyan.tools.cell_type_ratios
options:
show_root_heading: true
Expand All @@ -25,3 +29,13 @@
- __init__
- select
- save_selection
- extract_adata

::: scyan.tools.PolygonGatingScatter
options:
show_root_heading: true
members:
- __init__
- select
- save_selection
- extract_adata
52 changes: 30 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "scyan"
version = "1.5.0"
version = "1.5.1"
description = "Single-cell Cytometry Annotation Network"
documentation = "https://mics-lab.github.io/scyan/"
homepage = "https://mics-lab.github.io/scyan/"
Expand All @@ -14,11 +14,9 @@ classifiers = [
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft :: Windows",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering"
]
packages = [
{ include = "scyan" },
"Topic :: Scientific/Engineering",
]
packages = [{ include = "scyan" }]

[tool.poetry.dependencies]
python = ">=3.8,<3.11"
Expand All @@ -32,25 +30,35 @@ FlowUtils = "^1.0.0"
fcsparser = "^0.2.4"
fcswrite = "^0.6.2"

wandb = {version = "0.13.7", optional = true}
hydra-core = {version = "^1.2.0", optional = true}
hydra-colorlog = {version = "^1.2.0", optional = true}
hydra-optuna-sweeper = {version = "^1.2.0", optional = true}
wandb = { version = "0.13.7", optional = true }
hydra-core = { version = "^1.2.0", optional = true }
hydra-colorlog = { version = "^1.2.0", optional = true }
hydra-optuna-sweeper = { version = "^1.2.0", optional = true }

pytest = {version = "^7.1.2", optional = true}
ipykernel = {version = "^6.15.0", optional = true}
ipywidgets = {version = "^7.7.1", optional = true}
isort = {version = "^5.10.1", optional = true}
black = {version = "^22.6.0", optional = true}
mkdocs-material = {version = "^8.5.0", optional = true}
mkdocstrings = {version = "^0.19.0", optional = true}
mkdocstrings-python = {version = "^0.7.1", optional = true}
mkdocs-jupyter = {version = "^0.21.0", optional = true}
pytest = { version = "^7.1.2", optional = true }
ipykernel = { version = "^6.15.0", optional = true }
ipywidgets = { version = "^7.7.1", optional = true }
isort = { version = "^5.10.1", optional = true }
black = { version = "^22.6.0", optional = true }
mkdocs-material = { version = "^8.5.0", optional = true }
mkdocstrings = { version = "^0.19.0", optional = true }
mkdocstrings-python = { version = "^0.7.1", optional = true }
mkdocs-jupyter = { version = "^0.21.0", optional = true }

leidenalg = {version = "^0.8.10", optional = true}
leidenalg = { version = "^0.8.10", optional = true }

[tool.poetry.extras]
dev = ["pytest", "ipykernel", "ipywidgets", "isort", "black", "mkdocs-material", "mkdocstrings", "mkdocstrings-python", "mkdocs-jupyter"]
dev = [
"pytest",
"ipykernel",
"ipywidgets",
"isort",
"black",
"mkdocs-material",
"mkdocstrings",
"mkdocstrings-python",
"mkdocs-jupyter",
]
hydra = ["wandb", "hydra-core", "hydra-colorlog", "hydra-optuna-sweeper"]
discovery = ["leidenalg"]

Expand All @@ -65,7 +73,7 @@ python_files = "test_*.py"
filterwarnings = [
"ignore::DeprecationWarning",
"ignore::UserWarning",
"ignore:::.*anndata*"
"ignore:::.*anndata*",
]

[tool.black]
Expand All @@ -88,4 +96,4 @@ exclude = '''

[tool.isort]
profile = "black"
skip_glob = ["*/__init__.py"]
skip_glob = ["*/__init__.py"]
18 changes: 10 additions & 8 deletions scyan/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ def _prepare_data(self) -> None:

self._n_samples = (
min(self.hparams.max_samples or self.adata.n_obs, self.adata.n_obs)
// self.hparams.batch_size
* self.hparams.batch_size
// self._batch_size
* self._batch_size
)

@_requires_fit
Expand Down Expand Up @@ -410,13 +410,17 @@ def load(self, path: str) -> None:
self.dataset = TensorDataset(self.x, self.covariates)
self._is_fitted = True

@property
def _batch_size(self):
return min(self.hparams.batch_size, self.adata.n_obs)

def train_dataloader(self):
"""PyTorch lightning `train_dataloader` implementation"""
self.dataset = TensorDataset(self.x, self.covariates)

return DataLoader(
self.dataset,
batch_size=self.hparams.batch_size,
batch_size=self._batch_size,
sampler=RandomSampler(self.adata.n_obs, self._n_samples),
num_workers=self._num_workers,
)
Expand All @@ -425,7 +429,7 @@ def predict_dataloader(self):
"""PyTorch lightning `predict_dataloader` implementation"""
return DataLoader(
self.dataset,
batch_size=self.hparams.batch_size,
batch_size=self._batch_size,
num_workers=self._num_workers,
)

Expand All @@ -449,7 +453,7 @@ def dataset_apply(self, func: Callable, data: Tuple[Tensor] = None) -> Tensor:
else:
loader = DataLoader(
TensorDataset(*data),
batch_size=self.hparams.batch_size,
batch_size=self._batch_size,
num_workers=self._num_workers,
)

Expand Down Expand Up @@ -534,9 +538,7 @@ def fit(
check_on_train_epoch_end=True,
)

log_every_n_steps = min(
log_every_n_steps, len(self.x) // self.hparams.batch_size
)
log_every_n_steps = min(log_every_n_steps, len(self.x) // self._batch_size)
trainer = pl.Trainer(
max_epochs=max_epochs,
callbacks=[esc] + (callbacks or []),
Expand Down
4 changes: 2 additions & 2 deletions scyan/plot/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def kde(
"""Plot Kernel-Density-Estimation for each provided population and for multiple markers.
Args:
adata: An `anndata` object.
adata: An `AnnData` object.
population: One population, or a list of population to be analyzed, or `None`. If not `None`, the population name(s) has to be in `adata.obs[key]`.
markers: List of markers to plot. If `None`, the list is chosen automatically.
key: Key to look for populations in `adata.obs`. By default, uses the model predictions.
Expand Down Expand Up @@ -97,7 +97,7 @@ def log_prob_threshold(adata: AnnData, show: bool = True):
To use this function, you first need to fit a `scyan.Scyan` model and use the `model.predict()` method.
Args:
adata: The `anndata` object used during the model training.
adata: The `AnnData` object used during the model training.
show: Whether or not to display the figure.
"""
assert (
Expand Down
4 changes: 2 additions & 2 deletions scyan/plot/dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def scatter(
One scatter plot is displayed for each pair of markers.
Args:
adata: An `anndata` object.
adata: An `AnnData` object.
population: One population, or a list of population to be colored, or `None`. If not `None`, the population name(s) has to be in `adata.obs[key]`.
markers: List of markers to plot. If `None`, the list is chosen automatically.
n_markers: Number of markers to choose automatically if `markers is None`.
Expand Down Expand Up @@ -79,7 +79,7 @@ def umap(
If you trained your UMAP with [scyan.tools.umap][] on a subset of cells, it will only display the desired subset of cells.
Args:
adata: An `anndata` object.
adata: An `AnnData` object.
color: Marker(s) or `obs` name(s) to color. It can be either just one string, or a list (it will plot one UMAP per element in the list).
vmax: `scanpy.pl.umap` vmax argument.
vmin: `scanpy.pl.umap` vmin argument.
Expand Down
10 changes: 5 additions & 5 deletions scyan/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def auto_logicle_transform(
We recommend it for flow cytometry or spectral flow cytometry data.
Args:
adata: An `anndata` object.
adata: An `AnnData` object.
q: See logicle article. Defaults to 0.05.
m: See logicle article. Defaults to 4.5.
"""
Expand Down Expand Up @@ -73,7 +73,7 @@ def asinh_transform(adata: AnnData, translation: float = 0, cofactor: float = 5)
"""Asinh transformation for cell-expressions: $asinh((x - translation)/cofactor)$.
Args:
adata: An `anndata` object.
adata: An `AnnData` object.
translation: Constant substracted to the marker expression before division by the cofactor.
cofactor: Scaling factor before computing the asinh.
"""
Expand All @@ -93,7 +93,7 @@ def inverse_transform(
If you scaled your data, the complete inverse consists in running [scyan.preprocess.unscale][] first, and then this function.
Args:
adata: An `anndata` object.
adata: An `AnnData` object.
obsm: Name of the anndata obsm to consider. If `None`, use `adata.X`.
obsm_names: Names of the ordered markers from obsm. It is required if obsm is not `None`, if there are less markers than in `adata.X`, and if the transformation to reverse is `logicle`. Usually, it corresponds to `model.var_names`.
transformation: Name of the transformation to inverse: one of `['logicle', 'asinh', None]`. By default, it chooses automatically depending on which transformation was previously run.
Expand Down Expand Up @@ -148,7 +148,7 @@ def scale(adata: AnnData, max_value: float = 10, center: Optional[bool] = None)
"""Tranforms the data such as (i) `std=1`, and (ii) either `0` is sent to `-1` (for CyTOF data) or `means=0` (for flow or spectral flow data); except if `center` is set (which overwrites the default behavior).
Args:
adata: An `anndata` object.
adata: An `AnnData` object.
max_value: Clip to this value after scaling.
center: If `None`, data is only centered for spectral or flow cytometry data (recommended), else, it is centered or not according to the value given.
"""
Expand All @@ -175,7 +175,7 @@ def unscale(
"""Reverse standardisation. It requires to have run [scyan.preprocess.scale][] before.
Args:
adata: An `anndata` object.
adata: An `AnnData` object.
obsm: Name of the adata obsm to consider. If `None`, use `adata.X`.
obsm_names: Names of the ordered markers from obsm. It is required if obsm is not `None`, and if there are less markers than in `adata.X`. Usually, it corresponds to `model.var_names`.
Expand Down
4 changes: 2 additions & 2 deletions scyan/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .representation import umap, subcluster
from .representation import umap, subcluster, leiden
from .biomarkers import cell_type_ratios, mean_intensities
from .gating import PolygonGatingUMAP
from .gating import PolygonGatingUMAP, PolygonGatingScatter
from .colors import palette_level
Loading

0 comments on commit 491ec29

Please sign in to comment.