Exemplo n.º 1
0
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
Exemplo n.º 2
0
scv.settings.figdir = outdir

for key in samples:
    vk = VelocityKernel(samples[key])
    vk.compute_transition_matrix(softmax_scale=None)
    g = GPCCA(vk)
    g.compute_schur(n_components=20)
    g.plot_spectrum(real_only=False, save="{}_eigenvalues.png".format(key))
    if key == "H508_EV" or key == "HT29_EV":
        g.plot_schur(use=4,
                     cluster_key=clusters,
                     show=False,
                     dpi=300,
                     save='{}_schur.png'.format(key))
        g.compute_metastable_states(n_states=4, cluster_key=clusters)
        g.plot_metastable_states(show=False,
                                 dpi=300,
                                 save='{}_metastable.png'.format(key))
        g.plot_metastable_states(
            same_plot=False,
            show=False,
            dpi=300,
            save='{}_individual_metastable.png'.format(key))
    elif key == "H508_LSD1_KD":
        g.plot_schur(use=2,
                     cluster_key=clusters,
                     show=False,
                     dpi=300,
                     save='{}_schur.png'.format(key))
        g.compute_metastable_states(n_states=2, cluster_key=clusters)