Skip to content

Commit

Permalink
Updated precommit.
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianBarkmann committed Jul 25, 2023
1 parent 2c99931 commit 80fe1ad
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/cansig/run/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import cansig.filesys as fs # pytype: disable=import-error
import cansig.logger as clogger # pytype: disable=import-error
import cansig.models.api as models # pytype: disable=import-error
from cansig.utils import read_anndata # pytype: disable=import-error

LOGGER = logging.getLogger(__name__)
DEFAULT_OUTPUT_BASE_PATH = pathlib.Path("./outputs/batch-integration")
Expand Down Expand Up @@ -109,7 +110,7 @@ def integrate(
fs.save_settings(settings=config, path=output_dir.integration_settings)

# Train the model and get the representations
data = anndata.read_h5ad(data_path)
data = read_anndata(data_path)
representations = integrate_adata(data=data, config=config)

# Save the representations
Expand Down
4 changes: 2 additions & 2 deletions src/cansig/run/metasignatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import logging

import anndata as ad # pytype: disable=import-error
import scanpy as sc # pytype: disable=import-error
import pandas as pd # pytype: disable=import-error
import numpy as np # pytype: disable=import-error
import pathlib as pl # pytype: disable=import-error
Expand All @@ -24,6 +23,7 @@
from scanpy.tools._rank_genes_groups import _Method # pytype: disable=import-error

from cansig.types import Pathlike # pytype: disable=import-error
from cansig.utils import read_anndata # pytype: disable=import-error

_LOGGER = logging.getLogger(__name__)
_TESTTYPE = Literal["mwu", "ttest"]
Expand Down Expand Up @@ -539,7 +539,7 @@ def run_metasignatures(
_LOGGER.info("Get the information about the signatures in the postprocessing folder.")
resdict = utils.get_runs_sig(rundir)

adata = sc.read_h5ad(data_path)
adata = read_anndata(data_path)
# make sure that even in the CanSig case, we don't use the healthy cells
obs_names = list(pd.concat(resdict["cluster_memb"], axis=1).index)
adata = adata[obs_names, :].copy()
Expand Down
5 changes: 2 additions & 3 deletions src/cansig/run/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from typing import Union # pytype: disable=import-error

import anndata # pytype: disable=import-error
import pandas as pd # pytype: disable=import-error

import cansig.cluster.api as cluster # pytype: disable=import-error
Expand All @@ -14,7 +13,7 @@
import cansig.logger as clogger # pytype: disable=import-error
import cansig.plotting.plotting as plotting # pytype: disable=import-error
from cansig.gsea import Method # pytype: disable=import-error

from cansig.utils import read_anndata # pytype: disable=import-error

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -146,7 +145,7 @@ def postprocess(
# Read the anndata and add the cluster labels
# TODO(Pawel, Florian, Josephine): Apply preprocessing, e.g., selecting HVGs?
# Or maybe this should be in the GEX object?
adata = anndata.read_h5ad(data_path)
adata = read_anndata(data_path)
adata = adata[labels.index, :].copy()
adata.obs[_CLUSTER_COL] = labels

Expand Down
9 changes: 9 additions & 0 deletions src/cansig/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import scanpy as sc # pytype: disable=import-error
from cansig.types import Pathlike # pytype: disable=import-error


def read_anndata(path: Pathlike) -> sc.AnnData:
# Workaround for a bug in scanpy.
adata = sc.read_h5ad(path)
adata.uns["log1p"] = {"base": None}
return adata

0 comments on commit 80fe1ad

Please sign in to comment.