Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into boli
Browse files Browse the repository at this point in the history
  • Loading branch information
bli25 committed Jan 20, 2024
2 parents 2e9ff31 + e5e9c34 commit 782925d
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 21 deletions.
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
# -- Project information -----------------------------------------------------

project = "Pegasus"
copyright = "2023 Genentech, Inc. All rights reserved."
copyright = "2024 Genentech, Inc. All rights reserved."
author = (
"Yiming Yang, Joshua Gould and Bo Li"
)

# The short X.Y version
version = "1.8"
version = "1.9"
# The full version, including alpha/beta/rc tags
release = "1.8.1"
release = "1.9.0"


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Release Highlights in Current Stable
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. include:: release_notes/version_1_8.rst
.. include:: release_notes/version_1_9.rst

.. toctree::
:maxdepth: 1
Expand Down
5 changes: 5 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Release Notes
.. note::
Also see the release notes of `PegasusIO <https://pegasusio.readthedocs.io/en/stable/release_notes.html>`__.

Version 1.9
~~~~~~~~~~~~~

.. include:: release_notes/version_1_9.rst

Version 1.8
~~~~~~~~~~~~~

Expand Down
15 changes: 15 additions & 0 deletions docs/release_notes/version_1_9.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
1.9.0 :small:`January 19, 2024`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

**New Feature and Improvement**

* ``calculate_z_score`` works with sparse count matrix. [PR `276 <https://github.com/lilab-bcb/pegasus/pull/276>`_ Thanks to `Jayaram Kancherla <https://github.com/jkanche>`_]
* Plotting functions (``scatter``, ``dotplot``, ``violin``, ``heatmap``) now give warnings on genes/attributes not existing in the data, and skip them in the plots.
* Improve ``heatmap``:

* Add ``show_sample_name`` parameter for cases of pseudo-bulk data, nanoString DSP data, etc.
* Use Scipy's linkage (``scipy.cluster.hierarchy.linkage``) for dendrograms to use its optimal ordering feature for better results (see ``groupby_optimal_ordering`` parameter).

* Update human lung and mouse immune markers used by ``infer_cell_types`` function.
* ``run_harmony`` can accept multiple attributes to be the batch key, by providing a list of attribute names to its ``batch`` parameter.
* Expose ``online_batch_size`` parameter in ``nmf`` and ``integrative_nmf`` functions.
1 change: 0 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ natsort
joblib
psutil
numba
importlib_metadata; python_version < '3.8'
umap-learn
forceatlas2-python
pyarrow
Expand Down
10 changes: 5 additions & 5 deletions pegasus/tools/batch_correction.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import time
import numpy as np
import pandas as pd
from typing import Union
from typing import Union, List
from pegasusio import UnimodalData, MultimodalData

from pegasus.tools import select_features, X_from_rep, check_batch_key
Expand All @@ -16,7 +16,7 @@
@timer(logger=logger)
def run_harmony(
data: Union[MultimodalData, UnimodalData],
batch: str = "Channel",
batch: Union[str, List[str]] = "Channel",
rep: str = "pca",
n_comps: int = None,
n_jobs: int = -1,
Expand All @@ -34,8 +34,8 @@ def run_harmony(
data: ``MultimodalData``.
Annotated data matrix with rows for cells and columns for genes.
batch: ``str``, optional, default: ``"Channel"``.
Which attribute in data.obs field represents batches, default is "Channel".
batch: ``str`` or ``List[str]``, optional, default: ``"Channel"``.
Which attribute in data.obs field represents batches, default is "Channel". If using multiple attributes, specify their names in a list.
rep: ``str``, optional, default: ``"pca"``.
Which representation to use as input of Harmony, default is PCA.
Expand All @@ -54,7 +54,7 @@ def run_harmony(
use_gpu: ``bool``, optional, default: ``False``.
If ``True``, use GPU if available. Otherwise, use CPU only.
max_iter_harmony: ``int``, optional, default: ``10``.
Maximum iterations on running Harmony if not converged.
Expand Down
23 changes: 14 additions & 9 deletions pegasus/tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,24 @@ def simulate_doublets(X: Union[csr_matrix, np.ndarray], sim_doublet_ratio: float
return results, doublet_indices


def check_batch_key(data: Union[MultimodalData, UnimodalData], batch: str, warning_msg: str) -> bool:
def check_batch_key(data: Union[MultimodalData, UnimodalData], batch: Union[str, List[str]], warning_msg: str) -> bool:
if batch is None:
return False

if batch not in data.obs:
logger.warning(f"Batch key {batch} does not exist. {warning_msg}")
return False
else:
if not is_categorical_dtype(data.obs[batch]):
data.obs[batch] = pd.Categorical(data.obs[batch].values)
if data.obs[batch].cat.categories.size == 1:
logger.warning(f"Batch key {batch} only contains one batch. {warning_msg}")
if isinstance(batch, str):
batch = [batch]

for bat in batch:
if bat not in data.obs:
logger.warning(f"Batch key {bat} does not exist. {warning_msg}")
return False
else:
if not is_categorical_dtype(data.obs[bat]):
data.obs[bat] = pd.Categorical(data.obs[bat].values)
if data.obs[bat].cat.categories.size == 1:
logger.warning(f"Batch key {bat} only contains one batch. {warning_msg}")
return False

return True


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ natsort
numba
numpy
pandas>=1.2.0
pegasusio>=0.5.1
pegasusio>=0.9.0
pybind11
scikit-learn>=0.23.2
scikit-misc
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
scvi=["scvi-tools"],
all=["fitsne", "louvain", "scanorama", "torch", "harmony-pytorch", "nmf-torch", "rpy2", "forceatlas2-python", "scvi-tools"]
),
python_requires="~=3.7",
python_requires="~=3.8",
package_data={
"pegasus.annotate_cluster": [
"human_immune_cell_markers.json",
Expand Down

0 comments on commit 782925d

Please sign in to comment.