def lineage_drivers( adata: AnnData, lineage: str, backward: bool = False, n_genes: int = 8, ncols: Optional[int] = None, use_raw: bool = False, title_fmt: str = "{gene} qval={qval:.4e}", **kwargs, ) -> None: """ Plot lineage drivers that were uncovered using :func:`cellrank.tl.lineage_drivers`. Parameters ---------- %(adata)s %(backward)s %(plot_lineage_drivers.parameters)s Returns ------- %(just_plots)s """ pk = DummyKernel(adata, backward=backward) mc = GPCCA(pk, read_from_adata=True, write_to_adata=False) if use_raw and adata.raw is None: logg.warning("No raw attribute set. Using `adata.var` instead") use_raw = False direction = DirPrefix.BACKWARD if backward else DirPrefix.FORWARD needle = f"{direction} {lineage} corr" haystack = adata.raw.var if use_raw else adata.var if needle not in haystack: raise RuntimeError( f"Unable to find lineage drivers in " f"`{'adata.raw.var' if use_raw else 'adata.var'}[{needle!r}]`. " f"Compute lineage drivers first as `cellrank.tl.lineage_drivers(lineages={lineage!r}, " f"use_raw={use_raw}, backward={backward}).`") drivers = pd.DataFrame(haystack[[needle, f"{direction} {lineage} qval"]]) drivers.columns = [f"{lineage} corr", f"{lineage} qval"] mc._set(A.LIN_DRIVERS, drivers) mc.plot_lineage_drivers( lineage, n_genes=n_genes, use_raw=use_raw, ncols=ncols, title_fmt=title_fmt, **kwargs, )
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)) if key == "H508_EV": g.plot_lineage_drivers( '10', save='{}_10_lineage_drivers.png'.format(key)) g.plot_lineage_drivers( '17', save='{}_17_lineage_drivers.png'.format(key)) g.plot_lineage_drivers('1', save='{}_1_lineage_drivers.png'.format(key)) g.plot_lineage_drivers(