Skip to content

Transfer_labels error #4

@RijndertAriese

Description

@RijndertAriese

Hi,

Thanks for this great resource, both on the paper and the package! Very useful (and perfectly timed for my needs:) ).

I've downloaded the HNOCA data and the scPoli model from the HNOCA github and loaded them together with my query_adata. Subsequently I've trained the model using map_query and computed wknn. However, now I want to transfer the annotation from the atlas to my data, but this throws an error

TypeError
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[55], line 1
----> 1 mapper.transfer_labels(label_key='snapseed_pca_rss_level_1')

File /hpc/pmc_rios/2.personal/rariese/miniconda/envs/scanpy/lib/python3.10/site-packages/hnoca/map/mapper.py:266, in AtlasMapper.transfer_labels(self, label_key)
    263 if self.wknn is None:
    264     raise AttributeError("WKNN needs to be computed first.")
--> 266 scores = transfer_labels(
    267     self.ref_adata,
    268     self.query_adata,
    269     self.wknn,
    270     label_key=label_key,
    271 )
    273 return scores

File /hpc/pmc_rios/2.personal/rariese/miniconda/envs/scanpy/lib/python3.10/site-packages/hnoca/map/wknn.py:273, in transfer_labels(ref_adata, query_adata, wknn, label_key)
    267 scores = pd.DataFrame(
    268     wknn @ pd.get_dummies(ref_adata.obs[label_key]),
    269     columns=pd.get_dummies(ref_adata.obs[label_key]).columns,
    270     index=query_adata.obs_names,
    271 )
    272 scores["best_label"] = scores.idxmax(1)
--> 273 scores["best_score"] = scores.max(1)
    274 return scores

File /hpc/pmc_rios/2.personal/rariese/miniconda/envs/scanpy/lib/python3.10/site-packages/pandas/core/frame.py:11643, in DataFrame.max(self, axis, skipna, numeric_only, **kwargs)
  11635 @doc(make_doc("max", ndim=2))
  11636 def max(
  11637     self,
   (...)
  11641     **kwargs,
  11642 ):
> 11643     result = super().max(axis, skipna, numeric_only, **kwargs)
  11644     if isinstance(result, Series):
  11645         result = result.__finalize__(self, method="max")

File /hpc/pmc_rios/2.personal/rariese/miniconda/envs/scanpy/lib/python3.10/site-packages/pandas/core/generic.py:12401, in NDFrame.max(self, axis, skipna, numeric_only, **kwargs)
  12394 def max(
  12395     self,
  12396     axis: Axis | None = 0,
   (...)
  12399     **kwargs,
  12400 ):
> 12401     return self._stat_function(
  12402         "max",
  12403         nanops.nanmax,
  12404         axis,
  12405         skipna,
  12406         numeric_only,
  12407         **kwargs,
  12408     )

File /hpc/pmc_rios/2.personal/rariese/miniconda/envs/scanpy/lib/python3.10/site-packages/pandas/core/generic.py:12374, in NDFrame._stat_function(self, name, func, axis, skipna, numeric_only, **kwargs)
  12370 nv.validate_func(name, (), kwargs)
  12372 validate_bool_kwarg(skipna, "skipna", none_allowed=False)
> 12374 return self._reduce(
  12375     func, name=name, axis=axis, skipna=skipna, numeric_only=numeric_only
  12376 )

File /hpc/pmc_rios/2.personal/rariese/miniconda/envs/scanpy/lib/python3.10/site-packages/pandas/core/frame.py:11549, in DataFrame._reduce(self, op, name, axis, skipna, numeric_only, filter_type, **kwds)
  11545     df = df.T
  11547 # After possibly _get_data and transposing, we are now in the
  11548 #  simple case where we can use BlockManager.reduce
> 11549 res = df._mgr.reduce(blk_func)
  11550 out = df._constructor_from_mgr(res, axes=res.axes).iloc[0]
  11551 if out_dtype is not None and out.dtype != "boolean":

File /hpc/pmc_rios/2.personal/rariese/miniconda/envs/scanpy/lib/python3.10/site-packages/pandas/core/internals/managers.py:1500, in BlockManager.reduce(self, func)
   1498 res_blocks: list[Block] = []
   1499 for blk in self.blocks:
-> 1500     nbs = blk.reduce(func)
   1501     res_blocks.extend(nbs)
   1503 index = Index([None])  # placeholder

File /hpc/pmc_rios/2.personal/rariese/miniconda/envs/scanpy/lib/python3.10/site-packages/pandas/core/internals/blocks.py:404, in Block.reduce(self, func)
    398 @final
    399 def reduce(self, func) -> list[Block]:
    400     # We will apply the function and reshape the result into a single-row
    401     #  Block with the same mgr_locs; squeezing will be done at a higher level
    402     assert self.ndim == 2
--> 404     result = func(self.values)
    406     if self.values.ndim == 1:
    407         res_values = result

File /hpc/pmc_rios/2.personal/rariese/miniconda/envs/scanpy/lib/python3.10/site-packages/pandas/core/frame.py:11468, in DataFrame._reduce.<locals>.blk_func(values, axis)
  11466         return np.array([result])
  11467 else:
> 11468     return op(values, axis=axis, skipna=skipna, **kwds)

File /hpc/pmc_rios/2.personal/rariese/miniconda/envs/scanpy/lib/python3.10/site-packages/pandas/core/nanops.py:147, in bottleneck_switch.__call__.<locals>.f(values, axis, skipna, **kwds)
    145         result = alt(values, axis=axis, skipna=skipna, **kwds)
    146 else:
--> 147     result = alt(values, axis=axis, skipna=skipna, **kwds)
    149 return result

File /hpc/pmc_rios/2.personal/rariese/miniconda/envs/scanpy/lib/python3.10/site-packages/pandas/core/nanops.py:404, in _datetimelike_compat.<locals>.new_func(values, axis, skipna, mask, **kwargs)
    401 if datetimelike and mask is None:
    402     mask = isna(values)
--> 404 result = func(values, axis=axis, skipna=skipna, mask=mask, **kwargs)
    406 if datetimelike:
    407     result = _wrap_results(result, orig_values.dtype, fill_value=iNaT)

File /hpc/pmc_rios/2.personal/rariese/miniconda/envs/scanpy/lib/python3.10/site-packages/pandas/core/nanops.py:1098, in _nanminmax.<locals>.reduction(values, axis, skipna, mask)
   1093     return _na_for_min_count(values, axis)
   1095 values, mask = _get_values(
   1096     values, skipna, fill_value_typ=fill_value_typ, mask=mask
   1097 )
-> 1098 result = getattr(values, meth)(axis)
   1099 result = _maybe_null_out(result, axis, mask, values.shape)
   1100 return result

File /hpc/pmc_rios/2.personal/rariese/miniconda/envs/scanpy/lib/python3.10/site-packages/numpy/core/_methods.py:41, in _amax(a, axis, out, keepdims, initial, where)
     39 def _amax(a, axis=None, out=None, keepdims=False,
     40           initial=_NoValue, where=True):
---> 41     return umr_maximum(a, axis, None, out, keepdims, initial, where)

TypeError: '>=' not supported between instances of 'float' and 'str'

A snippet of my code

query_adata_hvg.obs["snapseed_pca_rss_level_1"] = "unknown"
mapper = mapping.AtlasMapper(scpoli_model)
mapper.map_query(
    query_adata_hvg,
    retrain="partial",
    max_epochs=20,
    batch_size=1024,
    unlabeled_prototype_training=False,
    n_epochs=100,
    pretraining_epochs=90,
    early_stopping_kwargs=early_stopping_kwargs,
    eta=10,
    alpha_epoch_anneal=10,
)
mapper.compute_wknn(k=100)
mapper.transfer_labels(label_key='snapseed_pca_rss_level_1')

Am I missing something? Could you maybe give me some pointers on how to properly transfer the labels?

Thanks!

Rijndert

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions