LouisFaure/scFates

Error in sci.pl.single_trend

PaulJonasJost opened this issue · 1 comments

Hi,

thanks for creating such a great tool. I was following the tutorial and I had an error occur in scf.pl.single_trend: IndexError: single positional indexer is out-of-bounds

I did some digging and it seems, that it expects there to be a segment one, even though in data.obs["seg"] none are assigned to seg 1. Can you tell me what I did wrong or how I could fix this?

tyvm :)

here is the full traceback:

IndexError                                Traceback (most recent call last)
Cell In [83], line 3
      1 sc.set_figure_params(figsize=(.8,4),frameon=False)
      2 scf.set_figure_pubready()
----> 3 scf.pl.single_trend(adata3,"Maf",basis="dendro",wspace=-.25,save="_E1.pdf")

File ~/Documents/Promotion/Projects/TFH_new/venvTFH/lib/python3.10/site-packages/scFates/plot/features.py:750, in single_trend(adata, feature, root_milestone, milestones, module, branch, basis, ylab, color_exp, alpha_expr, size_expr, fitted_linewidth, layer, cmap_seg, cmap_cells, plot_emb, wspace, figsize, ax_trend, ax_emb, show, save, **kwargs)
    741     tolink = adata.uns["graph"]["pp_seg"].loc[int(s), "to"]
    742     for next_s in adata.uns["graph"]["pp_seg"].n.iloc[
    743         np.argwhere(
    744             adata.uns["graph"]["pp_seg"].loc[:, "from"].isin([tolink]).values
    745         ).flatten()
    746     ]:
    747         ax_trend.plot(
    748             [
    749                 df.loc[df.seg == s, "t"].iloc[-1],
--> 750                 df.loc[df.seg == next_s, "t"].iloc[0],
    751             ],
    752             [
    753                 df.loc[df.seg == s, "fitted"].iloc[-1],
    754                 df.loc[df.seg == next_s, "fitted"].iloc[0],
    755             ],
    756             c=adata.uns["seg_colors"][
    757                 np.argwhere(adata.obs.seg.cat.categories == next_s)[0][0]
    758             ],
    759             linewidth=fitted_linewidth,
    760         )
    761 else:
    762     ax_trend.scatter(
    763         df.loc[df.seg == s, "t"],
    764         df.loc[df.seg == s, "expression"],
   (...)
    768         rasterized=True,
    769     )

File ~/Documents/Promotion/Projects/TFH_new/venvTFH/lib/python3.10/site-packages/pandas/core/indexing.py:967, in _LocationIndexer.__getitem__(self, key)
    964 axis = self.axis or 0
    966 maybe_callable = com.apply_if_callable(key, self.obj)
--> 967 return self._getitem_axis(maybe_callable, axis=axis)

File ~/Documents/Promotion/Projects/TFH_new/venvTFH/lib/python3.10/site-packages/pandas/core/indexing.py:1520, in _iLocIndexer._getitem_axis(self, key, axis)
   1517     raise TypeError("Cannot index by location index with a non-integer key")
   1519 # validate the location
-> 1520 self._validate_integer(key, axis)
   1522 return self.obj._ixs(key, axis=axis)

File ~/Documents/Promotion/Projects/TFH_new/venvTFH/lib/python3.10/site-packages/pandas/core/indexing.py:1452, in _iLocIndexer._validate_integer(self, key, axis)
   1450 len_axis = len(self.obj._get_axis(axis))
   1451 if key >= len_axis or key < -len_axis:
-> 1452     raise IndexError("single positional indexer is out-of-bounds")

IndexError: single positional indexer is out-of-bounds

Hey @PaulJonasJost ,

Indeed, pl.trends blindly asssumes that all segments are populated by cells when plotting, hence the error.

I could loosen this aspect by completely allowing empty segments (which is already the case actually when calculating pseudotime, until plotting throws errors), but I think this goes against the idea what a tree should be:

All segments should be biologically relevant, meaning if no cells are not assigned to one, then the tree structure is likely wrong. I would rather ask myself what is the reason segment 1 is empty in the first place, and maybe retry running the tree learning process to make sure to get all segment assigned by cells.

I hope that helps! Let me know if you have any other questions