Skip to content

Commit

Permalink
Raise a warning for missing harmonypy in label transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
dawe committed Aug 10, 2023
1 parent 3defa6e commit 2f2591d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions schist/tools/_affinity_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2f2591d

Please sign in to comment.