def _create_gpcca(*, backward: bool = False) -> Tuple[AnnData, GPCCA]: adata = _adata_medium.copy() sc.tl.paga(adata, groups="clusters") vk = VelocityKernel(adata, backward=backward).compute_transition_matrix( softmax_scale=4 ) ck = ConnectivityKernel(adata, backward=backward).compute_transition_matrix() final_kernel = 0.8 * vk + 0.2 * ck mc = GPCCA(final_kernel) mc.compute_partition() mc.compute_eigendecomposition() mc.compute_schur(method="krylov") mc.compute_metastable_states(n_states=2) mc.set_final_states_from_metastable_states() mc.compute_absorption_probabilities() mc.compute_lineage_drivers(cluster_key="clusters", use_raw=False) assert adata is mc.adata if backward: assert str(AbsProbKey.BACKWARD) in adata.obsm else: assert str(AbsProbKey.FORWARD) in adata.obsm np.testing.assert_array_almost_equal(mc.absorption_probabilities.sum(1), 1) return adata, mc
cluster_key=clusters, show=False, dpi=300, save='{}_schur.png'.format(key)) g.compute_metastable_states(n_states=1, cluster_key=clusters) g.plot_metastable_states(show=False, dpi=300, save='{}_metastable.png'.format(key)) g.plot_metastable_states(discrete=True, show=False, dpi=300, legend_fontsize=0, save='{}_discrete_metastable.pdf'.format(key), size=28) g.set_final_states_from_metastable_states() if key == "H508_EV" or key == "HT29_EV": g.compute_absorption_probabilities() g.compute_lineage_drivers() samples[key].var.to_csv(key + "_lineages.tsv", sep='\t') print(samples[key].var.columns) if key == "HT29_EV": g.plot_lineage_drivers( '17', save='{}_17_lineage_drivers.png'.format(key)) g.plot_lineage_drivers( '1', save='{}_10_lineage_drivers.png'.format(key)) g.plot_lineage_drivers('11', save='{}_1_lineage_drivers.png'.format(key)) g.plot_lineage_drivers('4', save='{}_4_lineage_drivers.png'.format(key))