From 2f2591d4794255283e9322afac528a9739a820ba Mon Sep 17 00:00:00 2001 From: Cittaro Davide Date: Thu, 10 Aug 2023 11:17:15 +0200 Subject: [PATCH] Raise a warning for missing harmonypy in label transfer --- schist/tools/_affinity_tools.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/schist/tools/_affinity_tools.py b/schist/tools/_affinity_tools.py index 0ff221c..7528844 100644 --- a/schist/tools/_affinity_tools.py +++ b/schist/tools/_affinity_tools.py @@ -429,7 +429,12 @@ def label_transfer( if adata_ref: from scanpy.tools import pca from scanpy.preprocessing import neighbors - from scanpy.external.pp import harmony_integrate + try: + from scanpy.external.pp import harmony_integrate + has_harmonypy = True + except ModuleNotFoundError: + logg.warning('Harmonypy has not been installed, this will severly affect results') + has_harmonypy = False # we have to create a merged dataset and integrate # before that check that the labels are not in the recipient, in case drop @@ -474,12 +479,15 @@ def label_transfer( if not use_rep: pca(adata_merge, **pca_args) use_rep = 'X_pca' - h_rep = f'{use_rep}_harmony' - harmony_integrate(adata_merge, + if has_harmonypy: + h_rep = f'{use_rep}_harmony' + harmony_integrate(adata_merge, key='_label_transfer', basis=use_rep, adjusted_basis=h_rep, **harmony_args) + else: + h_rep = 'X_pca' # now calculate the kNN graph n_neighbors = int(np.sqrt(adata_merge.shape[0])/2) key_added = neighbors_key