aertslab / pySCENIC

pySCENIC is a lightning-fast python implementation of the SCENIC pipeline (Single-Cell rEgulatory Network Inference and Clustering) which enables biologists to infer transcription factors, gene regulatory networks and cell types from single-cell RNA-seq data.
http://scenic.aertslab.org
GNU General Public License v3.0
439 stars 181 forks source link

[ERROR] TypeError: invalid type promotion when doing extended post-SCENIC analysis #348

Closed cliftonlewis closed 2 years ago

cliftonlewis commented 2 years ago

Describe the bug A clear and concise description of what the bug is.

Steps to reproduce the behavior

  1. Command run when the error occurred:
    
    adata = sc.read( f_final_loom, validate=False)

drop the embeddings and extra attributes from the obs object

adata.obs.drop( ['Embedding','Embeddings_X','Embeddings_Y','RegulonsAUC'], axis=1, inplace=True )


2. Error encountered:
<!-- Please specify the **complete** error message (if applicable, otherwise delete this block): -->
```pytb
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-40-6d93a0d9e174> in <module>
      2 adata.obs.columns
      3 # drop the embeddings and extra attributes from the obs object
----> 4 adata.obs.drop( ['Embedding','Embeddings_X','Embeddings_Y','RegulonsAUC'], axis=1, inplace=True )

/home/shared/anaconda3/envs/scenic3/lib/python3.6/site-packages/pandas/core/frame.py in drop(self, labels, axis, index, columns, level, inplace, errors)
   4172             level=level,
   4173             inplace=inplace,
-> 4174             errors=errors,
   4175         )
   4176 

/home/shared/anaconda3/envs/scenic3/lib/python3.6/site-packages/pandas/core/generic.py in drop(self, labels, axis, index, columns, level, inplace, errors)
   3887         for axis, labels in axes.items():
   3888             if labels is not None:
-> 3889                 obj = obj._drop_axis(labels, axis, level=level, errors=errors)
   3890 
   3891         if inplace:

/home/shared/anaconda3/envs/scenic3/lib/python3.6/site-packages/pandas/core/generic.py in _drop_axis(self, labels, axis, level, errors)
   3922             else:
   3923                 new_axis = axis.drop(labels, errors=errors)
-> 3924             result = self.reindex(**{axis_name: new_axis})
   3925 
   3926         # Case for non-unique axis

/home/shared/anaconda3/envs/scenic3/lib/python3.6/site-packages/pandas/util/_decorators.py in wrapper(*args, **kwargs)
    307         @wraps(func)
    308         def wrapper(*args, **kwargs) -> Callable[..., Any]:
--> 309             return func(*args, **kwargs)
    310 
    311         kind = inspect.Parameter.POSITIONAL_OR_KEYWORD

/home/shared/anaconda3/envs/scenic3/lib/python3.6/site-packages/pandas/core/frame.py in reindex(self, *args, **kwargs)
   4034         kwargs.pop("axis", None)
   4035         kwargs.pop("labels", None)
-> 4036         return super().reindex(**kwargs)
   4037 
   4038     def drop(

/home/shared/anaconda3/envs/scenic3/lib/python3.6/site-packages/pandas/core/generic.py in reindex(self, *args, **kwargs)
   4443             )
   4444 
-> 4445         self._consolidate_inplace()
   4446 
   4447         # if all axes that are requested to reindex are equal, then only copy

/home/shared/anaconda3/envs/scenic3/lib/python3.6/site-packages/pandas/core/generic.py in _consolidate_inplace(self)
   5214             self._mgr = self._mgr.consolidate()
   5215 
-> 5216         self._protect_consolidate(f)
   5217 
   5218     def _consolidate(self, inplace: bool_t = False):

/home/shared/anaconda3/envs/scenic3/lib/python3.6/site-packages/pandas/core/generic.py in _protect_consolidate(self, f)
   5203         """
   5204         blocks_before = len(self._mgr.blocks)
-> 5205         result = f()
   5206         if len(self._mgr.blocks) != blocks_before:
   5207             self._clear_item_cache()

/home/shared/anaconda3/envs/scenic3/lib/python3.6/site-packages/pandas/core/generic.py in f()
   5212 
   5213         def f():
-> 5214             self._mgr = self._mgr.consolidate()
   5215 
   5216         self._protect_consolidate(f)

/home/shared/anaconda3/envs/scenic3/lib/python3.6/site-packages/pandas/core/internals/managers.py in consolidate(self)
    981         bm = type(self)(self.blocks, self.axes)
    982         bm._is_consolidated = False
--> 983         bm._consolidate_inplace()
    984         return bm
    985 

/home/shared/anaconda3/envs/scenic3/lib/python3.6/site-packages/pandas/core/internals/managers.py in _consolidate_inplace(self)
    986     def _consolidate_inplace(self) -> None:
    987         if not self.is_consolidated():
--> 988             self.blocks = tuple(_consolidate(self.blocks))
    989             self._is_consolidated = True
    990             self._known_consolidated = True

/home/shared/anaconda3/envs/scenic3/lib/python3.6/site-packages/pandas/core/internals/managers.py in _consolidate(blocks)
   1907     for (_can_consolidate, dtype), group_blocks in grouper:
   1908         merged_blocks = _merge_blocks(
-> 1909             list(group_blocks), dtype=dtype, can_consolidate=_can_consolidate
   1910         )
   1911         new_blocks = _extend_blocks(merged_blocks, new_blocks)

/home/shared/anaconda3/envs/scenic3/lib/python3.6/site-packages/pandas/core/internals/managers.py in _merge_blocks(blocks, dtype, can_consolidate)
   1929         # combination of those slices is a slice, too.
   1930         new_mgr_locs = np.concatenate([b.mgr_locs.as_array for b in blocks])
-> 1931         new_values = np.vstack([b.values for b in blocks])
   1932 
   1933         argsort = np.argsort(new_mgr_locs)

<__array_function__ internals> in vstack(*args, **kwargs)

/home/shared/anaconda3/envs/scenic3/lib/python3.6/site-packages/numpy/core/shape_base.py in vstack(tup)
    281     if not isinstance(arrs, list):
    282         arrs = [arrs]
--> 283     return _nx.concatenate(arrs, 0)
    284 
    285 

<__array_function__ internals> in concatenate(*args, **kwargs)

TypeError: invalid type promotion

Expected behavior A clear and concise description of what you expected to happen. I was hoping someone could explain this error to me as I can't seem to understand why I have gotten this. Cheers Please complete the following information:

cliftonlewis commented 2 years ago

After check back over this error again, I think this error may be due to the sc.read having the validate=False flag as it hid the fact that error was in the formatting of the integrated results loom file as just I tested it without and this the error I get.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-10-861eb679c1d3> in <module>
----> 1 adata = sc.read_loom( f_test_loom)
      2 adata.obs.columns
      3 # drop the embeddings and extra attributes from the obs object
      4 adata.obs.drop( ['Embedding','Embeddings_X','Embeddings_Y','RegulonsAUC'], axis=1, inplace=True )

/home/shared/anaconda3/envs/scenic3/lib/python3.6/site-packages/anndata/compat/__init__.py in inner_f(*args, **kwargs)
    251             extra_args = len(args) - len(all_args)
    252             if extra_args <= 0:
--> 253                 return f(*args, **kwargs)
    254 
    255             # extra_args > 0

/home/shared/anaconda3/envs/scenic3/lib/python3.6/site-packages/anndata/_io/read.py in read_loom(filename, sparse, cleanup, X_name, obs_names, obsm_names, var_names, varm_names, dtype, obsm_mapping, varm_mapping, **kwargs)
    259     from loompy import connect
    260 
--> 261     with connect(filename, "r", **kwargs) as lc:
    262         if X_name not in lc.layers.keys():
    263             X_name = ""

/home/shared/anaconda3/envs/scenic3/lib/python3.6/site-packages/loompy/loompy.py in connect(filename, mode, validate, spec_version)
   1147                 Note: if validation is requested, an exception is raised if validation fails.
   1148     """
-> 1149         return LoomConnection(filename, mode, validate=validate, spec_version=spec_version)

/home/shared/anaconda3/envs/scenic3/lib/python3.6/site-packages/loompy/loompy.py in __init__(self, filename, mode, validate, spec_version)
     83                         lv = loompy.LoomValidator(version=spec_version)
     84                         if not lv.validate(filename):
---> 85                                 raise ValueError("\n".join(lv.errors) + f"\n{filename} does not appead to be a valid Loom file according to Loom spec version '{spec_version}'")
     86 
     87                 self._file = h5py.File(filename, mode)

ValueError: Row attribute 'Regulons' dtype [('Abd-B_(+)', '<i8'), ('Abl_(+)', '<i8'), ('Antp_(+)', '<i8'), ('Argk_(+)', '<i8'), ('Atf3_(+)', '<i8'), ('Atf6_(+)', '<i8'), ('Awh_(+)', '<i8'), ('B-H1_(+)', '<i8'), ('BEAF-32_(+)', '<i8'), ('Bgb_(+)', '<i8'), ('Blimp-1_(+)', '<i8'), ('BtbVII_(+)', '<i8'), ('C15_(+)', '<i8'), ('CG10654_(+)', '<i8'), ('CG12018_(+)', '<i8'), ('CG12605_(+)', '<i8'), ('CG16779_(+)', '<i8'), ('CG17829_(+)', '<i8'), ('CG32532_(+)', '<i8'), ('CG34367_(+)', '<i8'), ('CG44247_(+)', '<i8'), ('CG5245_(+)', '<i8'), ('CG8319_(+)', '<i8'), ('Clk_(+)', '<i8'), ('CrebA_(+)', '<i8'), ('CrebB_(+)', '<i8'), ('D_(+)', '<i8'), ('D19B_(+)', '<i8'), ('Dif_(+)', '<i8'), ('Doc1_(+)', '<i8'), ('Dp_(+)', '<i8'), ('Dref_(+)', '<i8'), ('E_(bx)_(+)', '<i8'), ('E_(spl)m5-HLH_(+)', '<i8'), ('E_(spl)mbeta-HLH_(+)', '<i8'), ('E_(spl)mgamma-HLH_(+)', '<i8'), ('E2f1_(+)', '<i8'), ('E5_(+)', '<i8'), ('EcR_(+)', '<i8'), ('Ets21C_(+)', '<i8'), ('Ets65A_(+)', '<i8'), ('Ets96B_(+)', '<i8'), ('FoxK_(+)', '<i8'), ('H15_(+)', '<i8'), ('HDAC1_(+)', '<i8'), ('HLH3B_(+)', '<i8'), ('Hnf4_(+)', '<i8'), ('Hr3_(+)', '<i8'), ('Hr38_(+)', '<i8'), ('Hr78_(+)', '<i8'), ('Jra_(+)', '<i8'), ('Kdm4B_(+)', '<i8'), ('Kr_(+)', '<i8'), ('Lim1_(+)', '<i8'), ('Max_(+)', '<i8'), ('Mef2_(+)', '<i8'), ('Mitf_(+)', '<i8'), ('Mnt_(+)', '<i8'), ('Myb_(+)', '<i8'), ('Myc_(+)', '<i8'), ('NFAT_(+)', '<i8'), ('Nf-YC_(+)', '<i8'), ('Nf1_(+)', '<i8'), ('Oli_(+)', '<i8'), ('Pdp1_(+)', '<i8'), ('Psi_(+)', '<i8'), ('Ptx1_(+)', '<i8'), ('Rb97D_(+)', '<i8'), ('Rel_(+)', '<i8'), ('Rfx_(+)', '<i8'), ('Rx_(+)', '<i8'), ('SREBP_(+)', '<i8'), ('Sox102F_(+)', '<i8'), ('Sox14_(+)', '<i8'), ('SoxN_(+)', '<i8'), ('Spps_(+)', '<i8'), ('Stat92E_(+)', '<i8'), ('Su_(H)_(+)', '<i8'), ('Tet_(+)', '<i8'), ('TfIIB_(+)', '<i8'), ('Trf2_(+)', '<i8'), ('Trl_(+)', '<i8'), ('Usf_(+)', '<i8'), ('Usp39_(+)', '<i8'), ('Vsx1_(+)', '<i8'), ('Xbp1_(+)', '<i8'), ('Zif_(+)', '<i8'), ('abd-A_(+)', '<i8'), ('acj6_(+)', '<i8'), ('ap_(+)', '<i8'), ('ase_(+)', '<i8'), ('awd_(+)', '<i8'), ('bap_(+)', '<i8'), ('bi_(+)', '<i8'), ('bowl_(+)', '<i8'), ('bru3_(+)', '<i8'), ('bs_(+)', '<i8'), ('bsh_(+)', '<i8'), ('cbt_(+)', '<i8'), ('cnc_(+)', '<i8'), ('croc_(+)', '<i8'), ('crol_(+)', '<i8'), ('dimm_(+)', '<i8'), ('dpn_(+)', '<i8'), ('ems_(+)', '<i8'), ('en_(+)', '<i8'), ('eve_(+)', '<i8'), ('ey_(+)', '<i8'), ('fd96Ca_(+)', '<i8'), ('fkh_(+)', '<i8'), ('foxo_(+)', '<i8'), ('gcm_(+)', '<i8'), ('gcm2_(+)', '<i8'), ('grh_(+)', '<i8'), ('h_(+)', '<i8'), ('ham_(+)', '<i8'), ('hth_(+)', '<i8'), ('inv_(+)', '<i8'), ('kay_(+)', '<i8'), ('kn_(+)', '<i8'), ('l_(1)sc_(+)', '<i8'), ('l_(3)neo38_(+)', '<i8'), ('lbl_(+)', '<i8'), ('lola_(+)', '<i8'), ('luna_(+)', '<i8'), ('maf-S_(+)', '<i8'), ('mid_(+)', '<i8'), ('mirr_(+)', '<i8'), ('mor_(+)', '<i8'), ('nej_(+)', '<i8'), ('opa_(+)', '<i8'), ('otp_(+)', '<i8'), ('pad_(+)', '<i8'), ('pan_(+)', '<i8'), ('pb_(+)', '<i8'), ('pnr_(+)', '<i8'), ('pnt_(+)', '<i8'), ('repo_(+)', '<i8'), ('ro_(+)', '<i8'), ('scro_(+)', '<i8'), ('sd_(+)', '<i8'), ('slou_(+)', '<i8'), ('slp1_(+)', '<i8'), ('sna_(+)', '<i8'), ('so_(+)', '<i8'), ('sqz_(+)', '<i8'), ('sr_(+)', '<i8'), ('srl_(+)', '<i8'), ('srp_(+)', '<i8'), ('svp_(+)', '<i8'), ('teq_(+)', '<i8'), ('tj_(+)', '<i8'), ('tll_(+)', '<i8'), ('toe_(+)', '<i8'), ('trx_(+)', '<i8'), ('tsu_(+)', '<i8'), ('tup_(+)', '<i8'), ('unc-4_(+)', '<i8'), ('usp_(+)', '<i8'), ('wor_(+)', '<i8'), ('z_(+)', '<i8'), ('zfh2_(+)', '<i8')] is not allowed
Column attribute 'Clusterings' dtype [('0', '<i8')] is not allowed
Column attribute 'Embedding' dtype [('_X', '<f4'), ('_Y', '<f4')] is not allowed
Column attribute 'Embeddings_X' dtype [('1', '<f4'), ('2', '<f4'), ('3', '<f8'), ('4', '<f8')] is not allowed
Column attribute 'Embeddings_Y' dtype [('1', '<f4'), ('2', '<f4'), ('3', '<f8'), ('4', '<f8')] is not allowed
Column attribute 'RegulonsAUC' dtype [('Abd-B_(+)', '<f8'), ('Abl_(+)', '<f8'), ('Antp_(+)', '<f8'), ('Argk_(+)', '<f8'), ('Atf3_(+)', '<f8'), ('Atf6_(+)', '<f8'), ('Awh_(+)', '<f8'), ('B-H1_(+)', '<f8'), ('BEAF-32_(+)', '<f8'), ('Bgb_(+)', '<f8'), ('Blimp-1_(+)', '<f8'), ('BtbVII_(+)', '<f8'), ('C15_(+)', '<f8'), ('CG10654_(+)', '<f8'), ('CG12018_(+)', '<f8'), ('CG12605_(+)', '<f8'), ('CG16779_(+)', '<f8'), ('CG17829_(+)', '<f8'), ('CG32532_(+)', '<f8'), ('CG34367_(+)', '<f8'), ('CG44247_(+)', '<f8'), ('CG5245_(+)', '<f8'), ('CG8319_(+)', '<f8'), ('Clk_(+)', '<f8'), ('CrebA_(+)', '<f8'), ('CrebB_(+)', '<f8'), ('D_(+)', '<f8'), ('D19B_(+)', '<f8'), ('Dif_(+)', '<f8'), ('Doc1_(+)', '<f8'), ('Dp_(+)', '<f8'), ('Dref_(+)', '<f8'), ('E_(bx)_(+)', '<f8'), ('E_(spl)m5-HLH_(+)', '<f8'), ('E_(spl)mbeta-HLH_(+)', '<f8'), ('E_(spl)mgamma-HLH_(+)', '<f8'), ('E2f1_(+)', '<f8'), ('E5_(+)', '<f8'), ('EcR_(+)', '<f8'), ('Ets21C_(+)', '<f8'), ('Ets65A_(+)', '<f8'), ('Ets96B_(+)', '<f8'), ('FoxK_(+)', '<f8'), ('H15_(+)', '<f8'), ('HDAC1_(+)', '<f8'), ('HLH3B_(+)', '<f8'), ('Hnf4_(+)', '<f8'), ('Hr3_(+)', '<f8'), ('Hr38_(+)', '<f8'), ('Hr78_(+)', '<f8'), ('Jra_(+)', '<f8'), ('Kdm4B_(+)', '<f8'), ('Kr_(+)', '<f8'), ('Lim1_(+)', '<f8'), ('Max_(+)', '<f8'), ('Mef2_(+)', '<f8'), ('Mitf_(+)', '<f8'), ('Mnt_(+)', '<f8'), ('Myb_(+)', '<f8'), ('Myc_(+)', '<f8'), ('NFAT_(+)', '<f8'), ('Nf-YC_(+)', '<f8'), ('Nf1_(+)', '<f8'), ('Oli_(+)', '<f8'), ('Pdp1_(+)', '<f8'), ('Psi_(+)', '<f8'), ('Ptx1_(+)', '<f8'), ('Rb97D_(+)', '<f8'), ('Rel_(+)', '<f8'), ('Rfx_(+)', '<f8'), ('Rx_(+)', '<f8'), ('SREBP_(+)', '<f8'), ('Sox102F_(+)', '<f8'), ('Sox14_(+)', '<f8'), ('SoxN_(+)', '<f8'), ('Spps_(+)', '<f8'), ('Stat92E_(+)', '<f8'), ('Su_(H)_(+)', '<f8'), ('Tet_(+)', '<f8'), ('TfIIB_(+)', '<f8'), ('Trf2_(+)', '<f8'), ('Trl_(+)', '<f8'), ('Usf_(+)', '<f8'), ('Usp39_(+)', '<f8'), ('Vsx1_(+)', '<f8'), ('Xbp1_(+)', '<f8'), ('Zif_(+)', '<f8'), ('abd-A_(+)', '<f8'), ('acj6_(+)', '<f8'), ('ap_(+)', '<f8'), ('ase_(+)', '<f8'), ('awd_(+)', '<f8'), ('bap_(+)', '<f8'), ('bi_(+)', '<f8'), ('bowl_(+)', '<f8'), ('bru3_(+)', '<f8'), ('bs_(+)', '<f8'), ('bsh_(+)', '<f8'), ('cbt_(+)', '<f8'), ('cnc_(+)', '<f8'), ('croc_(+)', '<f8'), ('crol_(+)', '<f8'), ('dimm_(+)', '<f8'), ('dpn_(+)', '<f8'), ('ems_(+)', '<f8'), ('en_(+)', '<f8'), ('eve_(+)', '<f8'), ('ey_(+)', '<f8'), ('fd96Ca_(+)', '<f8'), ('fkh_(+)', '<f8'), ('foxo_(+)', '<f8'), ('gcm_(+)', '<f8'), ('gcm2_(+)', '<f8'), ('grh_(+)', '<f8'), ('h_(+)', '<f8'), ('ham_(+)', '<f8'), ('hth_(+)', '<f8'), ('inv_(+)', '<f8'), ('kay_(+)', '<f8'), ('kn_(+)', '<f8'), ('l_(1)sc_(+)', '<f8'), ('l_(3)neo38_(+)', '<f8'), ('lbl_(+)', '<f8'), ('lola_(+)', '<f8'), ('luna_(+)', '<f8'), ('maf-S_(+)', '<f8'), ('mid_(+)', '<f8'), ('mirr_(+)', '<f8'), ('mor_(+)', '<f8'), ('nej_(+)', '<f8'), ('opa_(+)', '<f8'), ('otp_(+)', '<f8'), ('pad_(+)', '<f8'), ('pan_(+)', '<f8'), ('pb_(+)', '<f8'), ('pnr_(+)', '<f8'), ('pnt_(+)', '<f8'), ('repo_(+)', '<f8'), ('ro_(+)', '<f8'), ('scro_(+)', '<f8'), ('sd_(+)', '<f8'), ('slou_(+)', '<f8'), ('slp1_(+)', '<f8'), ('sna_(+)', '<f8'), ('so_(+)', '<f8'), ('sqz_(+)', '<f8'), ('sr_(+)', '<f8'), ('srl_(+)', '<f8'), ('srp_(+)', '<f8'), ('svp_(+)', '<f8'), ('teq_(+)', '<f8'), ('tj_(+)', '<f8'), ('tll_(+)', '<f8'), ('toe_(+)', '<f8'), ('trx_(+)', '<f8'), ('tsu_(+)', '<f8'), ('tup_(+)', '<f8'), ('unc-4_(+)', '<f8'), ('usp_(+)', '<f8'), ('wor_(+)', '<f8'), ('z_(+)', '<f8'), ('zfh2_(+)', '<f8')] is not allowed
For help, see http://linnarssonlab.org/loompy/format/
drosophilalarval_scenic_integrated-output_test.loom does not appead to be a valid Loom file according to Loom spec version '2.0.1'

I'm still unsure how I would go about fixing the error even though I seem to manage to work through it by following the alternative path suggested at the start of the tutorial

cflerin commented 2 years ago

@cliftonlewis

Yes, for your second post, this is expected when turning off validation, since the loom file we create in this pipeline does not conform to loom specifications and will fail validation (due to the inclusion of the RegulonsAUC matrix, and other column attributes listed in that error). So it's necessary to turn validation off when loading the loom with Scanpy or loompy. This drop columns step just to clean up the adata obs object. If you're following the SCENIC protocols tutorial for PBMCs, then you can just skip this section; it's just a demonstration, and the adata object isn't really used for the rest of the tutorial.

I haven't seen this TypeError: invalid type promotion error before. But you have also omitted the list of package versions you have in your environment, so it makes it hard to help. Could be something with your version of Scanpy, Pandas, Loompy, etc..

cliftonlewis commented 2 years ago

Thanks @cflerin

Yeah the standard approach is fine so I'll just stick with that. Cheers