theislab / cellrank_notebooks

Tutorials and examples for CellRank.
https://cellrank.org
BSD 3-Clause "New" or "Revised" License
6 stars 5 forks source link

Kernel and estimator tutorial fails in several steps #42

Closed WeilerP closed 1 year ago

WeilerP commented 2 years ago

Discussion

Running the Tutorial Kernels and estimators with the latest developer version of CellRank fails in several steps:


ptk = PseudotimeKernel(adata)
ptk.compute_transition_matrix(threshold_scheme='hard', frac_to_keep=0)
ptk.plot_projection()
scv.pl.velocity_embedding_stream(adata, vkey='T_fwd')

throws the error ValueError: Transition matrix is not row stochastic, 15 rows do not sum to 1..

Traceback ``` --------------------------------------------------------------------------- ValueError Traceback (most recent call last) /var/folders/7p/j67nx0vs6j968c2w2d9pqmzryt4ryq/T/ipykernel_87197/1839256166.py in 1 ptk = PseudotimeKernel(adata) ----> 2 ptk.compute_transition_matrix(threshold_scheme='hard', frac_to_keep=0) 3 ptk.plot_projection() 4 scv.pl.velocity_embedding_stream(adata, vkey='T_fwd') ~/code/cellrank/cellrank/tl/kernels/_pseudotime_kernel.py in compute_transition_matrix(self, threshold_scheme, frac_to_keep, b, nu, check_irreducibility, n_jobs, backend, show_progress_bar, **kwargs) 170 logg.warning("Biased KNN graph is not irreducible") 171 --> 172 self.transition_matrix = biased_conn 173 logg.info(" Finish", time=start) 174 ~/code/cellrank/cellrank/tl/kernels/_base_kernel.py in transition_matrix(self, matrix) 549 @transition_matrix.setter 550 def transition_matrix(self, matrix: Any) -> None: --> 551 KernelExpression.transition_matrix.fset(self, matrix) 552 553 @property ~/code/cellrank/cellrank/tl/kernels/_base_kernel.py in transition_matrix(self, matrix) 447 if should_norm(matrix): # some rows are all 0s/contain invalid values 448 n_inv = np.sum(~np.isclose(np.asarray(matrix.sum(1)).squeeze(), 1.0, rtol=1e-12)) --> 449 raise ValueError(f"Transition matrix is not row stochastic, {n_inv} rows do not sum to 1.") 450 # fmt: on 451 ValueError: Transition matrix is not row stochastic, 15 rows do not sum to 1. ```


Traceback ``` --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /var/folders/7p/j67nx0vs6j968c2w2d9pqmzryt4ryq/T/ipykernel_87197/2479001957.py in ----> 1 g.plot_absorption_probabilities(state='Alpha') ~/code/cellrank/cellrank/tl/estimators/mixins/_utils.py in wrapper(wrapped, instance, args, kwargs) 413 _colors = getattr(instance, colors, None) 414 --> 415 return wrapped( 416 *args, 417 _data=data, ~/opt/miniconda3/envs/cellrank/lib/python3.8/site-packages/scanpy/_utils/__init__.py in func_wrapper(*args, **kwargs) 117 # reset filter 118 warnings.simplefilter('default', DeprecationWarning) --> 119 return func(*args, **kwargs) 120 121 return func_wrapper ~/code/cellrank/cellrank/tl/estimators/mixins/_utils.py in _plot_dispatcher(self, states, color, discrete, mode, time_key, same_plot, title, cmap, **kwargs) 340 ) 341 --> 342 return _plot_continuous( 343 self, 344 states=states, ~/code/cellrank/cellrank/tl/estimators/mixins/_utils.py in _plot_continuous(self, _data, _colors, _title, states, color, mode, time_key, title, same_plot, cmap, **kwargs) 276 _ = kwargs.pop("color_gradients", None) 277 --> 278 scv.pl.scatter( 279 self.adata, 280 title=title, ~/code/scvelo/scvelo/plotting/scatter.py in scatter(adata, basis, x, y, vkey, color, use_raw, layer, color_map, colorbar, palette, size, alpha, linewidth, linecolor, perc, groups, sort_order, components, projection, legend_loc, legend_loc_lines, legend_fontsize, legend_fontweight, legend_fontoutline, legend_align_text, xlabel, ylabel, title, fontsize, figsize, xlim, ylim, add_density, add_assignments, add_linfit, add_polyfit, add_rug, add_text, add_text_pos, add_margin, add_outline, outline_width, outline_color, n_convolve, smooth, normalize_data, rescale_color, color_gradients, dpi, frameon, zorder, ncols, nrows, wspace, hspace, show, save, ax, **kwargs) 292 _adata = adata[c_bool] if np.sum(~c_bool) > 0 else adata 293 mkwargs["color"] = c_vals[c_bool] --> 294 ax = scatter( 295 _adata, ax=ax, **mkwargs, **scatter_kwargs, **kwargs 296 ) ~/code/scvelo/scvelo/plotting/scatter.py in scatter(adata, basis, x, y, vkey, color, use_raw, layer, color_map, colorbar, palette, size, alpha, linewidth, linecolor, perc, groups, sort_order, components, projection, legend_loc, legend_loc_lines, legend_fontsize, legend_fontweight, legend_fontoutline, legend_align_text, xlabel, ylabel, title, fontsize, figsize, xlim, ylim, add_density, add_assignments, add_linfit, add_polyfit, add_rug, add_text, add_text_pos, add_margin, add_outline, outline_width, outline_color, n_convolve, smooth, normalize_data, rescale_color, color_gradients, dpi, frameon, zorder, ncols, nrows, wspace, hspace, show, save, ax, **kwargs) 612 613 marker = kwargs.pop("marker", ".") --> 614 smp = ax.scatter( 615 x, y, c=c, alpha=alpha, marker=marker, zorder=zorder, **kwargs 616 ) ~/opt/miniconda3/envs/cellrank/lib/python3.8/site-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs) 1359 def inner(ax, *args, data=None, **kwargs): 1360 if data is None: -> 1361 return func(ax, *map(sanitize_sequence, args), **kwargs) 1362 1363 bound = new_sig.bind(ax, *args, **kwargs) ~/opt/miniconda3/envs/cellrank/lib/python3.8/site-packages/matplotlib/axes/_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, edgecolors, plotnonfinite, **kwargs) 4595 ) 4596 collection.set_transform(mtransforms.IdentityTransform()) -> 4597 collection.update(kwargs) 4598 4599 if colors is None: ~/opt/miniconda3/envs/cellrank/lib/python3.8/site-packages/matplotlib/artist.py in update(self, props) 1060 func = getattr(self, f"set_{k}", None) 1061 if not callable(func): -> 1062 raise AttributeError(f"{type(self).__name__!r} object " 1063 f"has no property {k!r}") 1064 ret.append(func(v)) AttributeError: 'PathCollection' object has no property 'state' ```

alpha_drivers = g.compute_lineage_drivers(lineages="Alpha", return_drivers=True)
alpha_drivers.sort_values(by="Alpha corr", ascending=False)

results in KeyError: 'Alpha corr'

Traceback ``` --------------------------------------------------------------------------- KeyError Traceback (most recent call last) /var/folders/7p/j67nx0vs6j968c2w2d9pqmzryt4ryq/T/ipykernel_87197/2472769031.py in 1 alpha_drivers = g.compute_lineage_drivers(lineages="Alpha", return_drivers=True) ----> 2 alpha_drivers.sort_values(by="Alpha corr", ascending=False) ~/opt/miniconda3/envs/cellrank/lib/python3.8/site-packages/pandas/util/_decorators.py in wrapper(*args, **kwargs) 309 stacklevel=stacklevel, 310 ) --> 311 return func(*args, **kwargs) 312 313 return wrapper ~/opt/miniconda3/envs/cellrank/lib/python3.8/site-packages/pandas/core/frame.py in sort_values(self, by, axis, ascending, inplace, kind, na_position, ignore_index, key) 6252 6253 by = by[0] -> 6254 k = self._get_label_or_level_values(by, axis=axis) 6255 6256 # need to rewrap column in Series to apply key function ~/opt/miniconda3/envs/cellrank/lib/python3.8/site-packages/pandas/core/generic.py in _get_label_or_level_values(self, key, axis) 1774 values = self.axes[axis].get_level_values(key)._values 1775 else: -> 1776 raise KeyError(key) 1777 1778 # Check for duplicates ```

Versions:

cellrank==1.5.1+g10479a98.d20211116 scanpy==1.8.1 anndata==0.7.6 numpy==1.21.1 numba==0.52.0 scipy==1.7.0 pandas==1.3.1 pygpcca==1.0.2 scikit-learn==0.24.2 statsmodels==0.12.2 python-igraph==0.9.8 scvelo==0.2.5.dev81+g64c76b2.d20220202 pygam==0.8.0 matplotlib==3.4.2 seaborn==0.11.1

michalk8 commented 1 year ago

closed as completed