theislab / cellrank

CellRank: dynamics from multi-view single-cell data
https://cellrank.org
BSD 3-Clause "New" or "Revised" License
341 stars 47 forks source link

Running `compute_macrostates` fails when using most recent msmtools version #464

Closed Marius1311 closed 3 years ago

Marius1311 commented 3 years ago

I updated msmtools to the most recent version of the fork of Bernhard. I run python-vendorize etc. to make sure the update takes place. Now, when I try to run estimator.compute_macrostates, I get

Computing `4` macrostates
INFO: Using pre-computed schur decomposition
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-29-8a0a5a67338c> in <module>
      2 n_cells = 3
      3 
----> 4 g_cr.compute_macrostates(n_states=n_states, n_cells=n_cells, cluster_key='clusters')

~/Projects/cellrank/cellrank/tl/estimators/_gppca.py in compute_macrostates(self, n_states, n_cells, use_min_chi, cluster_key, en_cutoff, p_thresh)
    211 
    212         # careful here, in case computing the stat. dist failed
--> 213         if self._gpcca.coarse_grained_stationary_probability is not None:
    214             self._set(
    215                 A.COARSE_STAT_D,

~/Projects/cellrank/cellrank/_vendor/msmtools/analysis/dense/gpcca.py in coarse_grained_stationary_probability(self)
   1392     @property
   1393     def coarse_grained_stationary_probability(self):
-> 1394         return self._pi_coarse
   1395 
   1396     @property

AttributeError: 'GPCCA' object has no attribute '_pi_coarse'

Did we forget something when changing msmtools?

Marius1311 commented 3 years ago

Ok, my mistake, I know why this is failing: I'm trying this on a reducible example where the stationary distribution is not unique, so it's okay for the algorithm to tell me that the stationary distribution does not exist in this case. However, it does not need to fail for that reason, a simple warning would be enough.

This warning should tell me that the stationary distribution could not be computed, most likely because the transition matrix was reducible, i.e. there are disconnected clusters.

michalk8 commented 3 years ago

@Marius1311 I've made PR which fixes this (in pyGPCCA it's already fixed), you might want to include it in your local copy or wait + change the hash + vendorize again

Marius1311 commented 3 years ago

Fantastic, thanks @michalk8