Skip to content

Commit

Permalink
docs cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinblampey committed May 23, 2024
1 parent c3116c1 commit 39ef51f
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 156 deletions.
3 changes: 2 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import pytometry as pt
:toctree: generated
io.read_fcs
io.read_and_merge
```

## Preprocessing (`pp`)
Expand Down Expand Up @@ -44,7 +45,7 @@ import pytometry as pt
tl.normalize_arcsinh
tl.normalize_logicle
tl.normalize_biExp
tl.normalize_biexp
tl.normalize_autologicle
```

Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks/preprocessing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
"metadata": {},
"outputs": [],
"source": [
"adata_biex = pm.tl.normalize_biExp(adata, inplace=False)"
"adata_biex = pm.tl.normalize_biexp(adata, inplace=False)"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
"metadata": {},
"outputs": [],
"source": [
"adata_biexp = pm.tl.normalize_biExp(adata, inplace=False)"
"adata_biexp = pm.tl.normalize_biexp(adata, inplace=False)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/pytometry/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from ._readfcs import read_fcs
from ._readfcs import read_and_merge, read_fcs
45 changes: 22 additions & 23 deletions src/pytometry/io/_readfcs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

from pathlib import Path
from typing import Any

Expand All @@ -11,16 +9,16 @@
def read_fcs(path: str, reindex: bool = True) -> AnnData:
"""Read FCS file and convert into AnnData format.
Args:
path: str or Path
location of fcs file to parse
reindex: boolean
use the marker info to reindex variable names
defaults to True
Parameters
----------
path
location of fcs file to parse
reindex
use the marker info to reindex variable names
Returns
-------
an AnnData object of the fcs file
An AnnData object of the fcs file
"""
return readfcs.read(path, reindex=reindex)

Expand All @@ -34,26 +32,27 @@ def read_and_merge(
) -> AnnData:
"""Read and merge multiple FCS files into a single AnnData object.
Args:
files (str | list[str]): either a list of file paths or a directory path
sample_ids (list[Any] | None): list of sample ids to use as a column in
the AnnData object
sample_id_from_filename (bool): whether to use the filename to extract the
sample id
sample_id_index (int): which index of the filename to use as the sample id,
defaults to 0
sample_id_sep (str): separator to use when splitting the filename, defaults
to "_"
Parameters
----------
files
either a list of file paths or a directory path
sample_ids
list of sample ids to use as a column in the AnnData object
sample_id_from_filename
whether to use the filename to extract the sample id
sample_id_index
which index of the filename to use as the sample id
sample_id_sep
separator to use when splitting the filename
Returns
-------
AnnData: merged AnnData object
Merged AnnData object
"""
if isinstance(files, str):
if Path(files).is_dir():
files = [str(f) for f in Path(files).glob("*.fcs")]
else:
if not Path(files).is_dir():
raise ValueError("files must be a list of files or a directory path")
files = [str(f) for f in Path(files).glob("*.fcs")]
elif isinstance(files, list):
files = [str(Path(f)) for f in files if Path(f).suffix == ".fcs"]

Expand Down
25 changes: 15 additions & 10 deletions src/pytometry/pl/_histogram.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
from typing import Literal

import numpy as np
import seaborn as sns
from anndata import AnnData
from matplotlib import pyplot as plt
from matplotlib import rcParams

from pytometry.pp._process_data import find_indexes
from pytometry.tl._normalization import normalize_arcsinh, normalize_biExp, normalize_logicle
from pytometry.tl._normalization import (
normalize_arcsinh,
normalize_biexp,
normalize_logicle,
)


# Plot data. Choose between Area, Height both(default)
def plotdata(
adata: AnnData,
key: str = "signal_type",
option: str = "area",
normalize: str | None = None,
normalize: Literal["arcsinh", "biexp", "logicle"] | None = None,
cofactor: float | None = 10,
figsize: tuple[float, float] = (15, 6),
bins: int = 400,
Expand All @@ -28,19 +34,18 @@ def plotdata(
adata
Anndata object containing data.
key
Key in adata.var to plot. Default is 'signal_type' which is generated
Key in adata.var to plot. Default is 'signal_type', which is generated
when calling the preprocessing function :func:`~pytometry.pp.split_signal`.
normalize
Normalization type. Default is None but can be set to "arcsinh", "biExp"
or "logicle"
Normalization type.
cofactor
Cofactor for arcsinh normalization. Default is 10.
Cofactor for arcsinh normalization.
figsize
Figure size (width, height). Default is (15, 6).
Figure size (width, height).
option
Switch to choose directly between area and height data. Default is "area".
Switch to choose directly between area and height data.
bins
Number of bins for the histogram. Default is 400.
Number of bins for the histogram.
save
Path to save the figure.
**kwargs
Expand All @@ -62,7 +67,7 @@ def plotdata(
if normalize.lower().count("arcsinh") > 0:
normalize_arcsinh(adata_, cofactor)
elif normalize.lower().count("biexp") > 0:
normalize_biExp(adata_)
normalize_biexp(adata_)
elif normalize.lower().count("logicle") > 0:
normalize_logicle(adata_)
else:
Expand Down
22 changes: 8 additions & 14 deletions src/pytometry/pl/_scatter_density.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from typing import (
Literal,
)
from typing import Literal

import matplotlib.colors as mcolors
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -30,48 +28,44 @@ def scatter_density(
vmax: float | None = None,
*,
layer: str | None = None,
):
) -> None:
"""Plots the cell density across two adata.obs.
Parameters
----------
adata
AnnData object containing data.
x
adata.obs to plot on x axis. Defaults to 'FSC-A'.
adata.obs to plot on x axis.
y
adata.obs to plot on x axis. Defaults to 'SSC-A'.
adata.obs to plot on x axis.
x_label
x axis label.
y_label
y axis label.
x_scale
x axis scale type to apply. Defaults to 'linear'.
x axis scale type to apply.
y_scale
y axis scale type to apply. Defaults to 'linear'.
y axis scale type to apply.
x_lim
upper and lower limit of the x axis.
y_lim
upper and lower limit of the y axis.
ax
Axes to draw into. If None, create a new figure or use fignum to draw into an existing figure.
figsize
Figure size (width, height) if ax not provided. Defaults to (10, 10).
Figure size (width, height) if ax not provided.
bins
Number of bins for the np.histogram2d function.
cmap
For scalar aggregates, a matplotlib colormap name or instance. Alternatively, an iterable
of colors can be passed and will be converted to a colormap. Defaults to 'jet'.
of colors can be passed and will be converted to a colormap.
vmin, vmax
For scalar aggregates, the data range that the colormap covers. If vmin or vmax is None (default),
the colormap autoscales to the range of data in the area displayed, unless the corresponding
value is already set in the norm.
layer
The layer in adata to use. If None, use adata.X.
Returns
-------
Scatter plot that displays cell density
"""
ax = plt.subplots(figsize=figsize)[1] if ax is None else ax

Expand Down
32 changes: 16 additions & 16 deletions src/pytometry/pp/_process_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from typing import Literal

import numpy as np
import pandas as pd
Expand All @@ -16,7 +17,7 @@ def create_comp_mat(spillmat: pd.DataFrame, relevant_data: str = "") -> pd.DataF
spillmat
Spillover matrix as pandas dataframe.
relevant_data:
A list of channels for customized selection. Defaults to ''.
A list of channels for customized selection.
Returns
-------
Expand All @@ -36,7 +37,7 @@ def find_indexes(
adata: AnnData,
var_key: str = None,
key_added: str = "signal_type",
data_type: str = "facs",
data_type: Literal["facs", "cytof"] = "facs",
inplace: bool = True,
) -> AnnData | None:
"""Find channels of interest for computing compensation.
Expand All @@ -48,15 +49,14 @@ def find_indexes(
var_key
Key where to check if a feature is an area, height etc. type of value. Use `var_names` if None.
key_added
Key where result vector is added to the adata.var. Defaults to 'signal_type'.
Key where result vector is added to the adata.var.
data_type
Either 'facs' or 'cytof'. Defaults to 'facs'.
Type of cytometry data
inplace
Returns
-------
Depending on `inplace`, returns or updates `adata` with the following
updated field adata.var[f'{key_added}']
Depending on `inplace`, returns or updates `adata` with the following updated field `adata.var[f'{key_added}']`
"""
adata = adata if inplace else adata.copy()

Expand Down Expand Up @@ -108,15 +108,15 @@ def compensate(
adata
AnnData object.
key
Key where result vector is added to the adata.var. Defaults to 'signal_type'.
Key where result vector is added to the adata.var.
comp_matrix
A custom compensation matrix. Please note that by default we use the spillover matrix directly for numeric stability.
matrix_type
Whether to use a spillover matrix (default) or a compensation matrix. Only considered for custom compensation
matrices. Usually, custom compensation matrices are the inverse of the spillover matrix. If you want to use
a compensation matrix, not the spillover matrix, set `matrix_type` to `compensation`.
inplace
Return a copy instead of writing to adata. Defaults to True.
Return a copy instead of writing to adata.
Returns
-------
Expand Down Expand Up @@ -193,7 +193,7 @@ def split_signal(
var_key: str | None = None,
key: str = "signal_type",
option: str = "area",
data_type: str = "facs",
data_type: Literal["facs", "cytof"] = "facs",
inplace: bool = True,
) -> AnnData | None:
"""Method to filter out height or area data.
Expand All @@ -205,13 +205,13 @@ def split_signal(
var_key
Key where to check if a feature is an area, height etc. type of value. Use `var_names` if None.
key
Key for adata.var where the variable type is stored. Defaults to 'signal_type'.
Key for adata.var where the variable type is stored.
option
For choosing 'area' or 'height' in case of FACS data and 'element' for cyTOF data. Defaults to 'area'.
For choosing 'area' or 'height' in case of FACS data and 'element' for cyTOF data.
data_type
Either 'facs' or 'cytof'/'cyTOF'. Defaults to 'facs'.
Type of cytometry data
inplace
Return a copy instead of writing to adata. Defaults to True.
Return a copy instead of writing to adata.
Returns
-------
Expand Down Expand Up @@ -253,15 +253,15 @@ def split_signal(


# create test compensation matrix
def _dummy_spillover(n_rows=10, row_names=None) -> pd.DataFrame:
def _dummy_spillover(n_rows: int = 10, row_names: pd.Index | list[str] | None = None) -> pd.DataFrame:
"""Create dummy spillover matrix for testing.
Parameters
----------
n_rows
number of rows and columns. Defaults to 10.
number of rows and columns.
row_names
Index to use for the resulting dataframe. Also used as column names. Defaults to None.
Index to use for the resulting dataframe. Also used as column names.
Returns
-------
Expand Down
1 change: 1 addition & 0 deletions src/pytometry/tl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
normalize_arcsinh,
normalize_autologicle,
normalize_biExp,
normalize_biexp,
normalize_logicle,
)
from .clustering._flowsom import flowsom_clustering, meta_clustering, som_clustering
Loading

0 comments on commit 39ef51f

Please sign in to comment.