Skip to content

Commit

Permalink
update docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
Sichao25 committed May 1, 2023
1 parent 6ef8fec commit 15d896d
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 192 deletions.
23 changes: 8 additions & 15 deletions dynamo/plot/sctransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def sctransform_plot_fit(
Args:
adata: annotated data matrix after sctransform.
xaxis: the gene expression metric is plotted on the x-axis.
fig: Matplotlib figure object to use for the plot. If not provided,
a new figure is created.
fig: Matplotlib figure object to use for the plot. If not provided, a new figure is created.
Returns:
The matplotlib figure object containing the plot.
Expand Down Expand Up @@ -99,27 +98,21 @@ def plot_residual_var(
label_genes: bool = True,
ax: Optional[Axes] = None,
) -> Figure:
"""Plot the relationship between the mean and variance of gene expression
across cells, highlighting the genes with the highest residual variance.
"""Plot the relationship between the mean and variance of gene expression across cells, highlighting the genes with
the highest residual variance.
Args:
adata: annotated data matrix after sctransform.
topngenes: the number of genes with the highest residual variance to
highlight in the plot.
label_genes: whether to label the highlighted genes in the plot. If
`topngenes` is large, labeling genes may lead to plotting error
because of the space limitation.
ax: the axes on which to draw the plot. If None, a new figure and axes
are created.
topngenes: the number of genes with the highest residual variance to highlight in the plot.
label_genes: whether to label the highlighted genes in the plot. If `topngenes` is large, labeling genes may
lead to plotting error because of the space limitation.
ax: the axes on which to draw the plot. If None, a new figure and axes are created.
Returns:
The Figure object if `ax` is not given, else None.
"""
def vars(a, axis=None):
"""Helper function to calculate variance of sparse matrix by following
equation:
var = mean(a**2) - mean(a)**2
"""
"""Helper function to calculate variance of sparse matrix by equation: var = mean(a**2) - mean(a)**2"""
a_squared = a.copy()
a_squared.data **= 2
return a_squared.mean(axis) - np.square(a.mean(axis))
Expand Down
26 changes: 11 additions & 15 deletions dynamo/preprocessing/external/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def integrate(
fill_value: Scalar value to fill newly missing values in arrays with.
Returns:
The concatenated AnnData, where adata.obs[batch_key] stores a
categorical variable labeling the batch.
The concatenated AnnData, where adata.obs[batch_key] stores a categorical variable labeling the batch.
"""

batch_ca = [adata.obs[batch_key][0] for adata in adatas]
Expand Down Expand Up @@ -89,25 +88,22 @@ def harmony_debatch(
) -> Optional[AnnData]:
"""Use harmonypy [Korunsky19]_ to remove batch effects.
This function should be run after performing PCA but before computing the
neighbor graph. Original Code Repository: https://github.com/slowkow/harmonypy
Interesting example: https://slowkow.com/notes/harmony-animation/
This function should be run after performing PCA but before computing the neighbor graph. Original Code Repository
is https://github.com/slowkow/harmonypy. Interesting example: https://slowkow.com/notes/harmony-animation/
Args:
adata: An Anndata object.
key: The name of the column in ``adata.obs`` that differentiates among
experiments/batches.
basis: The name of the field in ``adata.obsm`` where the PCA table is
stored.
adjusted_basis: The name of the field in ``adata.obsm`` where the
adjusted PCA table will be stored after running this function.
max_iter_harmony: Maximum number of rounds to run Harmony. One round of
Harmony involves one clustering and one correction step.
key: The name of the column in ``adata.obs`` that differentiates among experiments/batches.
basis: The name of the field in ``adata.obsm`` where the PCA table is stored.
adjusted_basis: The name of the field in ``adata.obsm`` where the adjusted PCA table will be stored after
running this function.
max_iter_harmony: Maximum number of rounds to run Harmony. One round of Harmony involves one clustering and one
correction step.
copy: Whether to copy `adata` or modify it inplace.
Returns:
Updates adata with the field ``adata.obsm[adjusted_basis]``, containing
principal components adjusted by Harmony.
Updates adata with the field ``adata.obsm[adjusted_basis]``, containing principal components adjusted by
Harmony.
"""
try:
import harmonypy
Expand Down
Loading

0 comments on commit 15d896d

Please sign in to comment.