{ "cells": [ { "cell_type": "markdown", "id": "cc669ef4-e158-4cf8-86a9-c20baadf8b89", "metadata": {}, "source": [ "# Getting Start" ] }, { "cell_type": "markdown", "id": "6ff81890-f861-4b70-8d97-c5a57920a0b4", "metadata": {}, "source": [ "Examples of PhyloVelo and steps are provided in Jupyter Notebook under notebooks folder. For start, please refer to records analyzing simulation, C.elegans and KPTracer datasets." ] }, { "cell_type": "markdown", "id": "335d702f-0540-40ae-9968-2a89263b80eb", "metadata": {}, "source": [ "## PhyloVelo on New Dataset" ] }, { "cell_type": "markdown", "id": "7bdc0ba4-e857-4e94-a856-4e237ed0bea7", "metadata": {}, "source": [ "PhyloVelo provides an integrated function for phylogenetic velocity analysis by default whilst specific configurations might need to be adjusted accordingly." ] }, { "cell_type": "markdown", "id": "42d2d9c7-3137-4bb1-ba45-f9d44b614f20", "metadata": {}, "source": [ "### 1. import pacakge" ] }, { "cell_type": "markdown", "id": "0fd06f38-24b5-4c85-a8e0-d65bc75e8a26", "metadata": {}, "source": [ "```import phylovelo as pv```" ] }, { "cell_type": "markdown", "id": "431f43bf-6b75-4e51-abc1-675f46432758", "metadata": {}, "source": [ "### 2. import data, filter, normalize and dimensionality reduction" ] }, { "cell_type": "markdown", "id": "d71fb1c7-4bad-4c45-9320-a975d170fd01", "metadata": {}, "source": [ "```\n", "sd = pv.scData(count=xx, phylo_tree=xx)\n", "sd.drop_duplicate_genes()\n", "sd.normalize_filter(min_count=20)\n", "sd.dimensionality_reduction(target='x_normed', method='umap')\n", "```" ] }, { "cell_type": "markdown", "id": "d4f8ab5c-eb42-411a-929c-5e1bbc5a0c11", "metadata": {}, "source": [ "### 3. Run model" ] }, { "cell_type": "markdown", "id": "115360eb-2df3-48c2-83c6-47188ebb78f0", "metadata": {}, "source": [ "```\n", "depths = [tree.get_depth(sd.phylo_tree.find_any(name=i)) for i in sd.x_normed.index]\n", "pv.velocity_inference(sd, depths, cutoff=0.95, target='x_normed')\n", "```" ] }, { "cell_type": "markdown", "id": "7c8cf7cb-6ce2-4463-9a0c-bf8484842df1", "metadata": {}, "source": [ "### 4. Porject velocity into embedding and visualization" ] }, { "cell_type": "markdown", "id": "0ce878fe-51fc-4a33-b929-bd6cfee7f044", "metadata": {}, "source": [ "```\n", "pv.velocity_embedding(sd, target='x_normed')\n", "fig, ax = plt.subplots()\n", "ax.scatter(sd.Xdr.iloc[:,0], sd.Xdr.iloc[:,1], c=depths, s=100, alpha=0.3)\n", "ax = pv.velocity_plot(sd.Xdr.to_numpy(), sd.velocity_embeded, ax, 'stream', radius=0.8, lw_coef=100, arrowsize=2)\n", "```" ] }, { "cell_type": "markdown", "id": "487cf0dd-e133-42e1-bd8d-7c86e03ac02d", "metadata": {}, "source": [ "### 5. PhyloVelo pseudotime analysis\n", "\n", "PhyloVelo supports two pseudotime estimators. The default graph-based method uses the projected velocity field in the embedding, while the MEG expression method directly scores cells from robustly oriented MEG expression. Both methods store a `[0, 1]` normalized result in `sd.phylo_pseudotime`." ] }, { "cell_type": "markdown", "id": "de8af8e5-d66d-4f67-b608-e047bd8453df", "metadata": {}, "source": [ "```\n", "# Graph-based pseudotime from the projected velocity field.\n", "pv.calc_phylo_pseudotime(sd, n_neighbors=100, r_sample=0.8, random_state=0)\n", "\n", "# Alternatively, estimate pseudotime directly from MEG expression.\n", "# pv.calc_meg_pseudotime(sd, target='x_normed')\n", "# pv.calc_phylo_pseudotime(sd, method='meg', target='x_normed')\n", "\n", "fig, ax = plt.subplots(figsize=(8,8))\n", "scatter = ax.scatter(sd.Xdr.iloc[:,0],sd.Xdr.iloc[:,1], c=sd.phylo_pseudotime,cmap='plasma', s=60)\n", "cbaxes = inset_axes(ax, width=\"3%\", height=\"30%\", loc='lower left') \n", "plt.colorbar(scatter, cax=cbaxes, orientation='vertical')\n", "```" ] }, { "cell_type": "code", "execution_count": null, "id": "bc2caa34-e679-43c6-b6da-f0554b5856b0", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.12" } }, "nbformat": 4, "nbformat_minor": 5 }