### Select Start Cells by Cell Type Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/01.ST_data_of_axolotl_brain_regeneration_after_injury.ipynb Defines starting cells by specifying a known cell type. ```python # start_cells=spt.set_start_cells(adata,select_way='cell_type',cell_type='reaEGC') # fig, axs = plt.subplots(figsize=(5,5)) # plt.scatter(adata.obsm['X_spatial'][:,0],adata.obsm['X_spatial'][:,1],c='#D3D3D3',s=8) # plt.scatter(adata.obsm['X_spatial'][start_cells][:,0],adata.obsm['X_spatial'][start_cells][:,1],c='orange',s=8) ``` -------------------------------- ### Install spaTrack via pip Source: https://github.com/yzf072/spatrack/blob/main/README.md Install the package using pip. Requires Python version 3.7 to 3.9. ```shell pip install spaTrack ``` -------------------------------- ### Select Start Cells by Coordinates Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/01.ST_data_of_axolotl_brain_regeneration_after_injury.ipynb Manually defines starting cells based on specific spatial coordinates and a neighborhood radius. ```python start_cells = spt.set_start_cells(adata, select_way='coordinates', cell_type='reaEGC', start_point=[-1050,3850], n_neigh=30) fig, axs = plt.subplots(figsize=(5,5)) plt.scatter(adata.obsm['X_spatial'][:,0], adata.obsm['X_spatial'][:,1], c='#D3D3D3', s=8) plt.scatter(adata.obsm['X_spatial'][start_cells][:,0], adata.obsm['X_spatial'][start_cells][:,1], c='orange', s=8) ``` -------------------------------- ### Assess Start Cluster Entropy Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/02.ST_data_of_Intrahepatic_cholangiocarcinoma_cancer.ipynb Calculates and sorts clusters by entropy value to identify potential starting regions. ```python adata = spt.assess_start_cluster(adata) ``` -------------------------------- ### Select Start Cells via Lasso Tool Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/01.ST_data_of_axolotl_brain_regeneration_after_injury.ipynb Uses an interactive lasso tool to manually select cells of interest for the trajectory start. ```python # L=spt.Lasso(adata) # L.vi_plot(basis='X_spatial',cell_type='reaEGC') ``` ```python # start_cells=L.sub_cells # fig, axs = plt.subplots(figsize=(5, 5)) # plt.scatter(adata.obsm['X_spatial'][:,0],adata.obsm['X_spatial'][:,1],c='#D3D3D3',s=8) # plt.scatter(adata.obsm['X_spatial'][start_cells][:,0],adata.obsm['X_spatial'][start_cells][:,1],c='orange',s=8) ``` -------------------------------- ### Set Start Cells via K-Means Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/02.ST_data_of_Intrahepatic_cholangiocarcinoma_cancer.ipynb Identifies aggregation points within a specific cluster using k-means and selects neighbor cells as starting points for trajectory inference. ```python fig, axs = plt.subplots(figsize=(6, 9)) start_cells=spt.set_start_cells(adata,select_way='cell_type',split=True,cell_type='P0',n_neigh=100,n_clusters=4) plt.scatter(adata.obsm['X_spatial'][:,0],adata.obsm['X_spatial'][:,1],c='#D3D3D3',s=20) plt.scatter(adata.obsm['X_spatial'][start_cells][:,0],adata.obsm['X_spatial'][start_cells][:,1],c='orange',s=25) ``` -------------------------------- ### Set starting cells for trajectory analysis Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/05.scRNAseq_data_of_HSC.ipynb Defines the starting cluster for trajectory inference and visualizes the selected cells on a UMAP plot. ```python start_cells=spt.set_start_cells(adata,select_way='cell_type',cell_type='HSC') plt.scatter(adata.obsm['X_UMAP'][:,0],adata.obsm['X_UMAP'][:,1],c='#D3D3D3',s=20) plt.scatter(adata.obsm['X_UMAP'][start_cells][:,0],adata.obsm['X_UMAP'][start_cells][:,1],c='orange',s=25) ``` -------------------------------- ### Select start and end points for LAP Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/05.scRNAseq_data_of_HSC.ipynb Identifies the nearest neighbor cells for specified coordinates to serve as start and end points for the Least Action Path. ```python fig, ax = plt.subplots(figsize=(5, 5)) LAP_start_point=[-20,10] LAP_end_point=[-30,-10] LAP_start_cell=spt.nearest_neighbors(LAP_start_point,adata.obsm['X_UMAP'])[0][0] LAP_end_cell=spt.nearest_neighbors(LAP_end_point,adata.obsm['X_UMAP'])[0][0] plt.scatter(*adata.obsm["X_UMAP"].T,c='#D3D3D3',s=3) plt.scatter(*adata[LAP_start_cell].obsm['X_UMAP'].T,s=20) plt.scatter(*adata[LAP_end_cell].obsm['X_UMAP'].T,s=20) ``` -------------------------------- ### Identify Start and End Cells Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/01.ST_data_of_axolotl_brain_regeneration_after_injury.ipynb Locates the nearest cells to specified spatial coordinates to serve as start and end points for the LAP algorithm. ```python fig, ax = plt.subplots(figsize=(6, 6)) LAP_start_point=[-1050,3900] LAP_end_point=[-625,3000] LAP_start_cell=spt.nearest_neighbors(LAP_start_point,adata.obsm['X_spatial'])[0][0] LAP_end_cell=spt.nearest_neighbors(LAP_end_point,adata.obsm['X_spatial'])[0][0] plt.scatter(*adata.obsm["X_spatial"].T,c='#D3D3D3',s=15) plt.scatter(*adata[LAP_start_cell].obsm['X_spatial'].T,s=20) plt.scatter(*adata[LAP_end_cell].obsm['X_spatial'].T,s=20) ``` -------------------------------- ### spaTrack.set_start_cells Source: https://github.com/yzf072/spatrack/blob/main/docs/source/api_velocity.rst Sets the starting cells for trajectory inference. ```APIDOC ## spaTrack.set_start_cells ### Description Sets the starting cells for the trajectory inference process. ``` -------------------------------- ### Plot Cluster Entropy Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/02.ST_data_of_Intrahepatic_cholangiocarcinoma_cancer.ipynb Visualizes the entropy values of clusters to assist in manual selection of the starting cluster. ```python spt.assess_start_cluster_plot(adata) ``` -------------------------------- ### Calculate cell pseudotime Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/05.scRNAseq_data_of_HSC.ipynb Infers pseudotime values for cells based on the previously calculated OT matrix and defined start cells. ```python adata.obs['ptime']=spt.get_ptime(adata,start_cells) ``` -------------------------------- ### Calculate Least Action Path Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/05.scRNAseq_data_of_HSC.ipynb Computes the least action path between defined start and target cells using the vector field. ```python lap=spt.least_action(adata, init_cells=adata.obs_names[LAP_start_cell], target_cells=adata.obs_names[LAP_end_cell], vecfld=VecFld, basis='UMAP', adj_key='X_UMAP_distances', EM_steps=10, n_points=20 ) ``` -------------------------------- ### Visualize UMAP embeddings and trajectories Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/05.scRNAseq_data_of_HSC.ipynb Generates UMAP plots to visualize clusters, start cells, pseudotime, and inferred vector field trajectories. ```python fig, axs = plt.subplots(ncols=2, nrows=1, figsize=(10, 5)) sc.pl.embedding(adata, basis='X_UMAP', color='cluster', size=20, legend_loc='on data', ax=axs[0], legend_fontoutline=3, show=False, s=100) start_points = sc.pl.embedding(adata, basis='X_UMAP',ax=axs[1], show=False, title='start cells') points = adata.obsm['X_UMAP'][adata.obs['cluster'] == 'HSC'] start_points.scatter(points[:, 0], points[:, 1], s=15, color='orange') ``` ```python fig, axs = plt.subplots(ncols=2, nrows=1, figsize=(10, 4)) sc.pl.embedding(adata, basis='X_UMAP', color='ptime', show=False, ax=axs[0], color_map='Reds', title='ptime') vf_velocity = sc.pl.embedding(adata, basis='X_UMAP', show=False, ax=axs[1],color='cluster',title='streamplot', legend_loc=None, alpha=0.4, size=120) vf_velocity.streamplot(adata.uns['E_grid'][0], adata.uns['E_grid'][1], adata.uns['V_grid'][0], adata.uns['V_grid'][1], color='black', linewidth=1.5,density=1.8,arrowsize=1.2,) ``` -------------------------------- ### Initialize environment Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/04.ST_data_of_mouse midbrain_with_multiple_times.ipynb Import necessary libraries and configure scanpy and matplotlib settings. ```python import spaTrack as spt import scanpy as sc import pandas as pd import matplotlib.pyplot as plt sc.settings.verbosity = 0 plt.rcParams['figure.dpi'] = 200 #分辨率 ``` -------------------------------- ### Import libraries and configure settings Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/05.scRNAseq_data_of_HSC.ipynb Initializes spaTrack, scanpy, and plotting parameters for the analysis. ```python import spaTrack as spt import scanpy as sc import pandas as pd import numpy as np import matplotlib.pyplot as plt sc.settings.verbosity = 0 plt.rcParams['figure.dpi'] = 200 #分辨率 ``` -------------------------------- ### Configure Environment and Imports Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/03.ST_data_of_axolotl_brain_slides_with_multiple_times.ipynb Initializes the environment by suppressing warnings and importing necessary libraries for spatial analysis and plotting. ```python import warnings warnings.filterwarnings("ignore") ``` ```python import spaTrack as spt import scanpy as sc import pandas as pd import numpy as np import matplotlib.pyplot as plt sc.settings.verbosity = 0 plt.rcParams['figure.dpi'] = 200 #分辨率 ``` -------------------------------- ### Import Dependencies and Configure Environment Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/01.ST_data_of_axolotl_brain_regeneration_after_injury.ipynb Load necessary libraries for data manipulation, visualization, and spatial analysis, and set global plotting parameters. ```python import matplotlib.pyplot as plt import matplotlib.ticker as ticker import numpy as np import pandas as pd import scanpy as sc import spaTrack as spt sc.settings.verbosity = 0 plt.rcParams["figure.dpi"] = 200 # 分辨率 ``` -------------------------------- ### Train the regulatory network model Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/04.ST_data_of_mouse midbrain_with_multiple_times.ipynb Initialize the Trainer with spatial data paths and TF lists, then execute the training process. ```python gr = spt.Trainer( data_type='2_time', expression_matrix_path=['./E12.5.adata.h5ad','./E14.5.adata.h5ad'], cell_mapping_path='./cell_mapping.csv', tfs_path='../../../../data/mouse.midbrain.three.time/ms.TF.tsv', min_cells=[50,20], #recommend maintaining gene expression in ~ 3% of cells. cell_generate_per_time=10000, cell_select_per_time=50 ) gr.run(training_times=10,iter_times=30) ``` -------------------------------- ### Load and prepare data Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/04.ST_data_of_mouse midbrain_with_multiple_times.ipynb Load expression and metadata files, then assign spatial coordinates and cell identifiers to the AnnData object. ```python adata_all=sc.read('../../../../data/mouse.midbrain.three.time/mouse midbrain.three.time.point.ST.exp.tsv') df_annot=pd.read_table('../../../../data/mouse.midbrain.three.time/meta.tsv',sep='\t',index_col=[0]) adata_all.obs=df_annot adata_all.obs.index=list(df_annot.index) adata_all.obsm['spatial']=adata_all.obs[['x','y']].values adata_all.obs['CellID']=adata_all.obs.index ``` -------------------------------- ### Calculate and filter transition probabilities Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/04.ST_data_of_mouse midbrain_with_multiple_times.ipynb Maps data between two sections and provides a commented-out workflow for filtering transition probabilities based on a cutoff. ```python pi_df=spt.map_data(pi12,adata1_sub,adata2_sub) ``` ```python # import seaborn as sns # sns.displot(pi_df['pi_value'],bins=200) # pi_df_new=pi_df.loc[pi_df['pi_value']>cutoff_value] ``` -------------------------------- ### Inspect transition probability dataframe Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/04.ST_data_of_mouse midbrain_with_multiple_times.ipynb Displays the first few rows of the integrated transition probability dataframe. ```python pi_matrix_coord.head() ``` -------------------------------- ### Compute Least Action Path Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/01.ST_data_of_axolotl_brain_regeneration_after_injury.ipynb Calculates the optimal transition path between two cells by minimizing the action integral using an Expectation-Maximization algorithm. ```python lap=spt.least_action(adata, init_cells=adata.obs_names[LAP_start_cell], target_cells=adata.obs_names[LAP_end_cell], vecfld=VecFld, basis='spatial', adj_key='X_spatial_distances', EM_steps=5, n_points=20 ) ``` -------------------------------- ### Prepare data for 3D visualization Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/04.ST_data_of_mouse midbrain_with_multiple_times.ipynb Concatenates observation data from multiple sections and prepares the cell mapping matrix. ```python df_adata_1=adata1_sub.obs[['CellID','annotation','x','y']] df_adata_1['batch']='slice1' df_adata_2=adata2_sub.obs[['CellID','annotation','x','y']] df_adata_2['batch']='slice2' df_adata_3=adata3_sub.obs[['CellID','annotation','x','y']] df_adata_3['batch']='slice3' df_concat=pd.concat([df_adata_1,df_adata_2,df_adata_3]) df_mapping_cell=pi_matrix_coord[['slice1','slice2','slice3']] ``` ```python df_mapping_cell.head() ``` -------------------------------- ### Inspect data Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/04.ST_data_of_mouse midbrain_with_multiple_times.ipynb Display the first few rows of the observation metadata. ```python adata_all.obs.head() ``` -------------------------------- ### Initialize VectorField object Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/02.ST_data_of_Intrahepatic_cholangiocarcinoma_cancer.ipynb Creates a VectorField instance for the spatial basis. ```python VecFld = spt.VectorField(adata, basis="spatial") ``` -------------------------------- ### Initialize Vector Field Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/05.scRNAseq_data_of_HSC.ipynb Initializes the VectorField object required for path analysis. ```python VecFld=spt.VectorField(adata,basis='UMAP') ``` -------------------------------- ### Visualize Least Action Path Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/02.ST_data_of_Intrahepatic_cholangiocarcinoma_cancer.ipynb Plots the inferred path overlaid on the spatial embedding with pseudotime coloring. ```python LAP_ptime,LAP_nbrs=spt.lap.map_cell_to_LAP(adata) sub_adata=adata[LAP_nbrs,:] sub_adata.obs['ptime']=LAP_ptime sub_adata=sub_adata[np.argsort(sub_adata.obs["ptime"].values), :].copy() fig, ax = plt.subplots(figsize=(6,8)) plt.axis('off') ax = sc.pl.embedding(adata, basis='X_spatial',color='cluster',show=False,ax=ax,frameon=False,legend_loc=None,alpha=0.4,size=150) ax.streamplot(adata.uns['E_grid'][0], adata.uns['E_grid'][1], adata.uns['V_grid'][0], adata.uns['V_grid'][1],density=1.2,color='black',linewidth=2.5,arrowsize=1.5,minlength=0.1,maxlength=0.8) ax = spt.plot_least_action_path(adata,basis='spatial',ax=ax,point_size=120,linewidth=5) sc.pl.embedding(sub_adata, basis='X_spatial',ax=ax, color="ptime", cmap="Purples",frameon=True,size=150,title=' ') ``` -------------------------------- ### Load and Prepare ST Data Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/03.ST_data_of_axolotl_brain_slides_with_multiple_times.ipynb Reads gene expression data and metadata, then populates the scanpy adata object with cluster, time, spatial, and UMAP coordinates. ```python adata = sc.read('../../../../data/03.multiple.ST.slices.axolotl.brain/cell.exp.tsv') df_annot=pd.read_table('../../../../data/03.multiple.ST.slices.axolotl.brain/cell.meta.tsv') adata.obs["cluster"] = df_annot['cluster'].values adata.obs["Time"] = df_annot['Time'].values adata.obsm["X_spatial"] = df_annot[['x','y']].values adata.obsm["X_umap"] = df_annot[['UMAP_1','UMAP_2']].values ``` -------------------------------- ### spaTrack.plot_least_action_path Source: https://github.com/yzf072/spatrack/blob/main/docs/source/api_LAP.rst Visualizes the calculated least action path. ```APIDOC ## spaTrack.plot_least_action_path ### Description Generates a plot representing the least action path for analysis. ``` -------------------------------- ### Visualize 3D mapping across three sections Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/04.ST_data_of_mouse midbrain_with_multiple_times.ipynb Renders a 3D visualization of cell transitions across three sections with connecting lines. ```python spt.visual_3D_mapping_3(df_concat,df_mapping_cell,point_size=0.8,line_width=0.06,cell_color_list=['#9A154C', '#F3754E', '#5B58A7']) ``` -------------------------------- ### Map Cells to Pseudotime and Visualize Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/01.ST_data_of_axolotl_brain_regeneration_after_injury.ipynb Assigns pseudotime values to cells along the trajectory and visualizes the path over the spatial embedding. ```python LAP_ptime,LAP_nbrs=spt.map_cell_to_LAP(adata,cell_neighbors=80) sub_adata=adata[LAP_nbrs,:] sub_adata.obs['ptime']=LAP_ptime sub_adata=sub_adata[np.argsort(sub_adata.obs["ptime"].values), :].copy() fig, ax = plt.subplots(figsize=(6,5)) plt.axis('off') ax = sc.pl.embedding(adata, basis='X_spatial',color='cluster',show=False,ax=ax,frameon=False,legend_loc=None,alpha=0.6,size=150) ax.streamplot(adata.uns['E_grid'][0], adata.uns['E_grid'][1], adata.uns['V_grid'][0], adata.uns['V_grid'][1],density=1.2,color='black',linewidth=2,arrowsize=1.2) ax = spt.plot_least_action_path(adata,basis='spatial',ax=ax,point_size=120,linewidth=5) sc.pl.embedding(sub_adata, basis='X_spatial',ax=ax, color="ptime", cmap="YlGnBu",frameon=True,size=150,title=' ') ``` -------------------------------- ### Calculate cell transition probability matrix Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/01.ST_data_of_axolotl_brain_regeneration_after_injury.ipynb Computes the transition probability matrix using optimal transport with spatial information integration. ```python adata.obsp["trans"] = spt.get_ot_matrix(adata, data_type="spatial",alpha1=0.6,alpha2=0.4) ``` -------------------------------- ### Visualize TF-target relationships Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/04.ST_data_of_mouse midbrain_with_multiple_times.ipynb Generate a scatter plot to visualize the relationship between transcription factors and target genes. ```python gr.plot_scatter() ``` -------------------------------- ### Calculate cell-transition probability and velocity Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/03.ST_data_of_axolotl_brain_slides_with_multiple_times.ipynb Iterates through time points to compute optimal transport matrices, pseudotime, and cell velocity for spatial transcriptomics data. ```python time_and_start = {"D5": "reaEGC", "D10": "reaEGC", "D15": "reaEGC", "D20": "rIPC"} alpha = { "D5": [0.693, 0.307], "D10": [0.7, 0.3], "D15": [0.75, 0.25], "D20": [0.704, 0.296], } P_all = V_all = np.array([]).reshape(0, 2) for time_point in time_and_start.keys(): print(time_point) subadata = adata[adata.obs["Time"] == time_point] subadata.obsp["trans"] = spt.get_ot_matrix(subadata, data_type="spatial",alpha1=alpha[time_point][0],alpha2=alpha[time_point][1]) start_cluster = time_and_start[time_point] start_cells = spt.set_start_cells( subadata, select_way="cell_type", cell_type=start_cluster ) subadata.obs["ptime"] = spt.get_ptime(subadata, start_cells) _, _ = spt.get_velocity(subadata, basis="umap", n_neigh_pos=80, n_neigh_gene=0) P_all = np.vstack((P_all, subadata.obsm["X_umap"])) V_all = np.vstack((V_all, subadata.obsm["velocity_umap"])) ``` -------------------------------- ### Calculate cell transition probability Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/02.ST_data_of_Intrahepatic_cholangiocarcinoma_cancer.ipynb Estimates the transition matrix using gene expression and spatial distance parameters. ```python adata.obsp['trans']=spt.get_ot_matrix(adata,data_type='spatial',alpha1=0.587,alpha2=0.413) ``` -------------------------------- ### Load and Format Spatial Data Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/01.ST_data_of_axolotl_brain_regeneration_after_injury.ipynb Read gene expression and annotation files, then map them into a scanpy AnnData object structure required by spaTrack. ```python adata = sc.read("../../../../data/axolotl brain regeneration.ST/D15_4.ST.exp.tsv") df_annot = pd.read_table("../../../../data/axolotl brain regeneration.ST/D15_4.ST.annot.tsv") adata.obs["cluster"] = df_annot["cluster"].values adata.obsm["X_spatial"] = df_annot[["x", "y"]].values adata.layers["counts"] = adata.X ``` -------------------------------- ### Save spatial data to disk Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/04.ST_data_of_mouse midbrain_with_multiple_times.ipynb Export subsetted AnnData objects to h5ad format for use in the regulatory network construction pipeline. ```python adata1_sub.write('./E12.5.adata.h5ad') adata2_sub.write('./E14.5.adata.h5ad') ``` -------------------------------- ### Prepare ICC AnnData object Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/02.ST_data_of_Intrahepatic_cholangiocarcinoma_cancer.ipynb Load expression counts and annotation data from TSV files, then populate the AnnData object with spatial coordinates and cluster information. ```python adata = sc.read("../../../../data/ICC.ST.data/ICC.primary.ST.exp_count.tsv", cache=True) anno = pd.read_table("../../../../data/ICC.ST.data/ICC.primary.ST.annot.tsv") adata.obs.index = anno["ID"].values adata.obs["cluster"] = anno["cluster"].values adata.obsm["X_spatial"] = anno[["x", "y"]].values adata.layers["counts"] = adata.X ``` -------------------------------- ### Generate integrated transition probability data Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/04.ST_data_of_mouse midbrain_with_multiple_times.ipynb Integrates transition probability results across multiple sections into a single dataframe and exports it to a CSV file. ```python pi_matrix_coord = spt.generate_animate_input(pi_list=[pi12,pi23], adata_list=[adata1_sub,adata2_sub,adata3_sub],time ='Time point',annotation='annotation') # pi_matrix_coord=pi_matrix_coord.loc[(pi_matrix_coord['pi_value1']> value1) & (pi_matrix_coord['pi_value1']> value2) ] pi_matrix_coord.to_csv("./cell.transfer.csv") ``` -------------------------------- ### spaTrack.Lasso Source: https://github.com/yzf072/spatrack/blob/main/docs/source/api_velocity.rst Lasso class for trajectory analysis. ```APIDOC ## spaTrack.Lasso ### Description A class used for Lasso-based trajectory analysis. ``` -------------------------------- ### spaTrack.least_action Source: https://github.com/yzf072/spatrack/blob/main/docs/source/api_LAP.rst Calculates the least action path between specified points. ```APIDOC ## spaTrack.least_action ### Description Calculates the least action path based on the defined vector field and constraints. ``` -------------------------------- ### Calculate cell pseudotime Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/01.ST_data_of_axolotl_brain_regeneration_after_injury.ipynb Assigns pseudotime values between 0 and 1 based on the sorted sum of transition probabilities from initial cells. ```python adata.obs["ptime"] = spt.get_ptime(adata, start_cells) ``` -------------------------------- ### spaTrack.get_ot_matrix Source: https://github.com/yzf072/spatrack/blob/main/docs/source/api_velocity.rst Calculates the optimal transport matrix. ```APIDOC ## spaTrack.get_ot_matrix ### Description Computes the optimal transport matrix used for trajectory inference. ``` -------------------------------- ### Plot Least Action Path Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/05.scRNAseq_data_of_HSC.ipynb Visualizes the computed least action path overlaid on the UMAP embedding and vector field. ```python LAP_ptime,LAP_nbrs=spt.lap.map_cell_to_LAP(adata,basis='UMAP') sub_adata=adata[LAP_nbrs,:] sub_adata.obs['ptime']=LAP_ptime sub_adata=sub_adata[np.argsort(sub_adata.obs["ptime"].values), :].copy() fig, ax = plt.subplots(figsize=(8,8)) plt.axis('off') ax = sc.pl.embedding(adata, basis='X_UMAP',color='cluster',show=False,ax=ax,frameon=False,legend_loc=None,alpha=0.8,size=150) ax.streamplot(adata.uns['E_grid'][0], adata.uns['E_grid'][1], adata.uns['V_grid'][0], adata.uns['V_grid'][1],density=1.2,color='black',linewidth=2.5,arrowsize=1.5,minlength=0.1,maxlength=0.8) ax = spt.plot_least_action_path(adata,basis='UMAP',ax=ax,point_size=120,linewidth=5) sc.pl.embedding(sub_adata, basis='X_UMAP',ax=ax, color="ptime", cmap="Purples",frameon=True,size=150,title=' ') ``` -------------------------------- ### Suppress warnings Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/05.scRNAseq_data_of_HSC.ipynb Configures the environment to ignore warnings during execution. ```python import warnings warnings.filterwarnings("ignore") ``` -------------------------------- ### Subset data by time point Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/04.ST_data_of_mouse midbrain_with_multiple_times.ipynb Split the main AnnData object into subsets based on time points and define annotation colors. ```python adata1_sub=adata_all[adata_all.obs['Time point']=='E12.5'] adata2_sub=adata_all[adata_all.obs['Time point']=='E14.5'] adata3_sub=adata_all[adata_all.obs['Time point']=='E16.5'] adata_all.uns['annotation_colors']=['#9A154C', '#F3754E', '#5B58A7'] ``` -------------------------------- ### Preprocess and visualize data Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/05.scRNAseq_data_of_HSC.ipynb Filters genes, normalizes counts, and generates a UMAP embedding plot colored by cluster. ```python sc.pp.filter_genes(adata,min_cells=30) sc.pp.normalize_total(adata,target_sum=1e4) sc.pp.log1p(adata) fig, axs = plt.subplots(figsize=(6, 6)) ax = sc.pl.embedding(adata, basis='X_UMAP',show=False,color='cluster',ax=axs,frameon=False,title=' ',palette='tab20b',size=150, legend_fontsize=20) ``` -------------------------------- ### Load and format HSC data Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/05.scRNAseq_data_of_HSC.ipynb Reads expression and UMAP coordinate files, then populates the AnnData object with cluster annotations and UMAP embeddings. ```python adata = sc.read("../../../../data/HSPC.Sc-RNA.data/HSPC.sc.expression.tsv") anno = pd.read_table("../../../../data/HSPC.Sc-RNA.data/UMAP_coor.annot.tsv",) adata.obs.index = anno["Cell_id"].values adata.obs["cluster"] = anno["Annot"].values adata.obsm["X_UMAP"] = anno[['UMAP_1','UMAP_2']].values adata.var_names_make_unique() ``` -------------------------------- ### Visualize 3D mapping between two sections Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/04.ST_data_of_mouse midbrain_with_multiple_times.ipynb Renders a 3D visualization of cell transfer between two specific sections. ```python spt.visual_3D_mapping_2(df_concat,pi_df[['slice1','slice2']],point_size=1,line_width=0.05,cell_color_list=['#9A154C', '#F3754E', '#5B58A7']) ``` -------------------------------- ### Fit GAM model for pseudotime genes Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/02.ST_data_of_Intrahepatic_cholangiocarcinoma_cancer.ipynb Apply a generalized additive model to identify genes associated with pseudotime. ```python df_res = spt.ptime_gene_GAM(sub_adata_path,core_number=5) ``` -------------------------------- ### Visualize pseudotime distribution Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/01.ST_data_of_axolotl_brain_regeneration_after_injury.ipynb Plots the pseudotime values on the spatial embedding using a red color map. ```python fig, axs = plt.subplots(figsize=(5, 5)) sc.pl.embedding(adata, basis='spatial', color='ptime', show=False, ax=axs, color_map='Reds', title='ptime', size=100) axs.xaxis.set_major_locator(ticker.MultipleLocator(500)) axs.yaxis.set_major_locator(ticker.MultipleLocator(500)) ``` -------------------------------- ### Preprocess and visualize spatial data Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/02.ST_data_of_Intrahepatic_cholangiocarcinoma_cancer.ipynb Filter genes, normalize data, and generate a spatial embedding plot colored by cluster. ```python sc.pp.filter_genes(adata,min_cells=10) sc.pp.normalize_total(adata,target_sum=1e4) sc.pp.log1p(adata) fig, axs = plt.subplots(figsize=(6, 9)) ax = sc.pl.embedding(adata, basis='X_spatial', show=False, color='cluster', ax=axs, frameon=False, title=' ', palette='tab20c', size=150, legend_fontsize=20) ``` -------------------------------- ### spaTrack.get_ptime Source: https://github.com/yzf072/spatrack/blob/main/docs/source/api_velocity.rst Calculates pseudotime. ```APIDOC ## spaTrack.get_ptime ### Description Calculates the pseudotime values for the cells. ``` -------------------------------- ### Visualize spatial data Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/04.ST_data_of_mouse midbrain_with_multiple_times.ipynb Generate a spatial embedding plot to visualize cell annotations across the time points. ```python fig, axs = plt.subplots(ncols=1, nrows=1, figsize=(12, 6)) sc.pl.embedding(adata_all, basis='spatial', color='annotation', size=50, legend_loc='right margin', legend_fontsize=20,ax=axs, legend_fontoutline=3, show=False, s=80) axs.set_title('spatial',fontsize=18) ``` -------------------------------- ### Perform Quality Control and Normalization Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/01.ST_data_of_axolotl_brain_regeneration_after_injury.ipynb Filter low-abundance genes and normalize expression data to prepare for downstream trajectory inference. ```python sc.pp.filter_genes(adata, min_cells=10) sc.pp.normalize_total(adata, target_sum=1e4) sc.pp.log1p(adata) sc.pp.calculate_qc_metrics(adata, percent_top=None, log1p=False, inplace=True) ``` -------------------------------- ### Visualize trajectory gene heatmap Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/05.scRNAseq_data_of_HSC.ipynb Orders genes by trajectory and generates a heatmap of their expression. ```python sort_exp_sig = spt.order_trajectory_genes(sub_adata,df_sig_res,cell_number=30) spt.plot_trajectory_gene_heatmap(sort_exp_sig,smooth_length=200,gene_label_size=15,cmap_name='twilight_shifted') ``` -------------------------------- ### Visualize cell pseudotime and trajectory Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/02.ST_data_of_Intrahepatic_cholangiocarcinoma_cancer.ipynb Plots the embedding of cells colored by pseudotime and overlays the inferred vector field trajectory. ```python fig, axs = plt.subplots(ncols=2, nrows=1, figsize=(9, 6)) sc.pl.embedding(adata, basis='X_spatial', color='ptime', show=False, ax=axs[0], color_map='Reds', title='Ptime',size=120) vf_velocity = sc.pl.embedding(adata, basis='X_spatial', show=False, ax=axs[1],color='cluster', legend_loc=None, frameon=False, title='Trajectory', alpha=0.6, size=120) vf_velocity.streamplot(adata.uns['E_grid'][0], adata.uns['E_grid'][1], adata.uns['V_grid'][0], adata.uns['V_grid'][1], color='black', linewidth=2,density=1.2,arrowsize=1.2) ``` -------------------------------- ### Plot gene expression vs pseudotime Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/05.scRNAseq_data_of_HSC.ipynb Plots the expression of a specific gene against pseudotime. ```python spt.plot_trajectory_gene(sub_adata_path,gene_name='VIM',show_cell_type=False) ``` -------------------------------- ### Map cells between time points Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/04.ST_data_of_mouse midbrain_with_multiple_times.ipynb Compute cell mapping between two time points and save the result to a CSV file. ```python pi_df=spt.map_data(pi12,adata1_sub,adata2_sub) pi_df.to_csv('./cell_mapping.csv') ``` -------------------------------- ### Retrieve network weights Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/04.ST_data_of_mouse midbrain_with_multiple_times.ipynb Access the DataFrame containing the inferred weights between transcription factors and target genes. ```python gr.network_df ``` -------------------------------- ### Calculate transfer matrices between ST sections Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/04.ST_data_of_mouse midbrain_with_multiple_times.ipynb Computes the transfer matrix between pairs of spatial transcriptomics sections using an unbalanced and structured optimal transport algorithm. ```python pi12 = spt.transfer_matrix(adata1_sub,adata2_sub,epsilon=0.01,alpha=0.5) pi23 = spt.transfer_matrix(adata2_sub,adata3_sub,epsilon=0.01,alpha=0.5) ``` -------------------------------- ### spaTrack.map_cell_to_LAP Source: https://github.com/yzf072/spatrack/blob/main/docs/source/api_LAP.rst Maps individual cells to their corresponding least action path. ```APIDOC ## spaTrack.map_cell_to_LAP ### Description Maps cell data to the calculated least action path trajectories. ``` -------------------------------- ### Plot individual pseudotime-dependent genes Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/02.ST_data_of_Intrahepatic_cholangiocarcinoma_cancer.ipynb Visualize the expression of specific genes along the pseudotime trajectory. ```python spt.plot_trajectory_gene(sub_adata_path,gene_name='AQP1') ``` ```python spt.plot_trajectory_gene(sub_adata_path,gene_name='ITGA3') ``` -------------------------------- ### Calculate Velocity Grid Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/03.ST_data_of_axolotl_brain_slides_with_multiple_times.ipynb Converts cell-level velocity data into a grid-based representation for trajectory analysis. ```python P_grid, V_grid = spt.velocity.get_velocity_grid( adata, P=P_all, V=V_all ) ``` -------------------------------- ### Identify pseudotime-dependent genes Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/05.scRNAseq_data_of_HSC.ipynb Fits gene expression to pseudotime using a GAM and filters results by model fit and FDR. ```python df_res=spt.ptime_gene_GAM(sub_adata_path,core_number=5) df_sig_res = df_res.loc[(df_res['model_fit']>0.4) & (df_res['fdr']<0.05)] ``` -------------------------------- ### Visualize Spatial and UMAP Embeddings Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/03.ST_data_of_axolotl_brain_slides_with_multiple_times.ipynb Plots the integrated data across spatial coordinates and UMAP space to observe batch-corrected distributions. ```python fig, axs = plt.subplots(ncols=2, nrows=1, figsize=(18, 6)) sc.pl.embedding(adata, basis='X_spatial', color='Time', size=50, legend_fontsize=15,legend_loc='on data', ax=axs[0], legend_fontoutline=3, show=False, s=40) axs[0].set_title('spatial',fontsize=18) sc.pl.umap(adata,color='cluster',ax=axs[1],legend_loc='on data',size=50,legend_fontoutline=3, legend_fontsize=15,palette='tab20b',show=False,s=60) axs[1].set_title('UMAP',fontsize=18) ``` -------------------------------- ### Visualize Spatial Cell Clusters Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/01.ST_data_of_axolotl_brain_regeneration_after_injury.ipynb Generate a spatial embedding plot to visualize cell type distribution across the tissue sample. ```python fig, axs = plt.subplots(figsize=(7, 7)) ax = sc.pl.embedding(adata, basis='X_spatial', show=False, color='cluster', ax=axs, frameon=False, title=' ', palette='tab20c', size=100) ``` -------------------------------- ### Plot Cell Clusters on Spatial Slides Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/03.ST_data_of_axolotl_brain_slides_with_multiple_times.ipynb Sets custom colors for clusters and visualizes them on the spatial embedding. ```python adata.uns['cluster_colors']=['#5254a3', '#8c6d31','#EEDC82','#d6616b'] ``` ```python fig, axs = plt.subplots(ncols=1, nrows=1, figsize=(12, 6)) sc.pl.embedding(adata, basis='X_spatial', color='cluster', size=50, legend_loc='right margin', legend_fontsize=20,ax=axs, legend_fontoutline=3, show=False, s=80) axs.set_title('spatial',fontsize=18) ``` -------------------------------- ### Animate cell transfer across ST sections Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/04.ST_data_of_mouse midbrain_with_multiple_times.ipynb Generates an HTML animation showing cell transfer between multiple spatial transcriptomics sections. ```python spt.animate_transfer(adata_list=[adata1_sub,adata2_sub,adata3_sub], transfer_path='./cell.transfer.csv', fig_title = " Cell transfer from E12.5 E14.5 to E16.5", time ='Time point', color=['#5B58A7', '#9A154C', '#F3754E'], annotation='annotation', save_path='./cell.transfer.animation.html', times=['E12.5','E14.5','E16.5']) ``` -------------------------------- ### spaTrack.get_velocity Source: https://github.com/yzf072/spatrack/blob/main/docs/source/api_velocity.rst Calculates trajectory velocity. ```APIDOC ## spaTrack.get_velocity ### Description Computes the velocity of the trajectory. ``` -------------------------------- ### Plot gene regulatory network Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/04.ST_data_of_mouse midbrain_with_multiple_times.ipynb Visualize the gene regulatory network with optional filtering for minimum weight and node count. ```python gr.plot_gene_regulation(min_weight=0.012,min_node_num=10) ``` -------------------------------- ### Calculate cell transition probability Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/05.scRNAseq_data_of_HSC.ipynb Computes the optimal transport (OT) matrix between cells. If PCA coordinates are missing, the function automatically performs PCA. ```python adata.obsp['trans']=spt.get_ot_matrix(adata,data_type='single-cell') ``` -------------------------------- ### Compute spatial neighbors Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/02.ST_data_of_Intrahepatic_cholangiocarcinoma_cancer.ipynb Calculates the neighbor graph based on spatial coordinates. ```python sc.pp.neighbors(adata, use_rep="X_spatial", key_added="X_spatial", n_neighbors=100) ``` -------------------------------- ### Calculate vector field velocity Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/05.scRNAseq_data_of_HSC.ipynb Computes the vector field velocity on a grid for trajectory visualization. ```python adata.uns['E_grid'],adata.uns['V_grid']=spt.get_velocity(adata,basis='UMAP',n_neigh_pos=100,n_neigh_gene=0) ``` -------------------------------- ### Plot single gene expression along pseudotime Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/01.ST_data_of_axolotl_brain_regeneration_after_injury.ipynb Visualizes the expression of a specific gene across pseudotime points. ```python spt.plot_trajectory_gene(sub_adata,gene_name='VIM',point_size=80) ``` ```python spt.plot_trajectory_gene(sub_adata,gene_name='SYP',point_size=80) ``` -------------------------------- ### Filter cells and genes for trajectory analysis Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/02.ST_data_of_Intrahepatic_cholangiocarcinoma_cancer.ipynb Select specific clusters and filter genes based on minimum expression proportion and high variability. ```python sub_adata_path = sub_adata[sub_adata.obs["cluster"].isin(["P0", "P3", "P4"])] sub_adata_path = spt.filter_gene(sub_adata_path, min_exp_prop=0.1, hvg_gene=5000) ``` -------------------------------- ### Reconstruct Vector Field Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/01.ST_data_of_axolotl_brain_regeneration_after_injury.ipynb Reconstructs the grid-level vector field into a cell-level format for trajectory analysis. ```python VecFld=spt.VectorField(adata,basis='spatial') ``` -------------------------------- ### Filter genes for LAP analysis Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/05.scRNAseq_data_of_HSC.ipynb Selects specific cell types and filters genes based on expression proportion and variability. ```python sub_adata_path=sub_adata[sub_adata.obs['cluster'].isin(['HSC','BMEP','MKP'])] sub_adata_path=spt.filter_gene(sub_adata_path,min_exp_prop=0.1,hvg_gene=5000) ``` -------------------------------- ### Filter and order significant trajectory genes Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/02.ST_data_of_Intrahepatic_cholangiocarcinoma_cancer.ipynb Filter genes by model fit and FDR thresholds, then order them based on trajectory expression. ```python df_sig_res = df_res.loc[(df_res['model_fit']>0.15) & (df_res['fdr']<0.05)] sort_exp_sig = spt.order_trajectory_genes(sub_adata_path,df_sig_res,cell_number=20) ``` -------------------------------- ### Visualize Trajectory on UMAP Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/03.ST_data_of_axolotl_brain_slides_with_multiple_times.ipynb Generates a UMAP embedding plot overlaid with a streamplot representing the calculated velocity grid. ```python fig,axs=plt.subplots(ncols=1,nrows=1,figsize=(8,6)) ax = sc.pl.embedding(adata, basis ='X_umap',show=False,color='cluster',ax=axs,legend_loc='on data',frameon=False,title=' ',legend_fontsize=20, legend_fontoutline =3,legend_fontweight='bold',alpha=0.5,size=300) ax.streamplot(adata.uns['P_grid'][0], adata.uns['P_grid'][1], adata.uns['V_grid'][0], adata.uns['V_grid'][1],density=2,color='black',linewidth=3,arrowsize=2,minlength=0.2,maxlength=0.8) plt.tight_layout() ``` -------------------------------- ### spaTrack.VectorField Source: https://github.com/yzf072/spatrack/blob/main/docs/source/api_LAP.rst Computes the vector field for the given data. ```APIDOC ## spaTrack.VectorField ### Description Computes the vector field for the provided data structure. ``` -------------------------------- ### Visualize cell quiver plot Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/01.ST_data_of_axolotl_brain_regeneration_after_injury.ipynb Displays the velocity field as a quiver plot over the spatial embedding, with arrow length controlled by the scale parameter. ```python fig, axs = plt.subplots(figsize=(5, 5)) sc.pl.embedding(adata, basis='spatial',show=False,title=' ',color='cluster',ax=axs,frameon=False,palette='tab20b',legend_fontweight='normal',alpha=0.1,size=600) axs.quiver(adata.uns['E_grid'][0],adata.uns['E_grid'][1],adata.uns['V_grid'][0],adata.uns['V_grid'][1],scale=0.008) ``` -------------------------------- ### Visualize cell trajectory streamplot Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/01.ST_data_of_axolotl_brain_regeneration_after_injury.ipynb Generates a streamline plot to visualize the inferred cell differentiation trajectory. ```python fig,axs=plt.subplots(ncols=1,nrows=1,figsize=(6,6)) ax = sc.pl.embedding(adata, basis='spatial',show=False,title=' ',color='cluster',ax=axs,frameon=False,palette='tab20b',legend_fontweight='normal',alpha=0.8,size=150) ax.streamplot(adata.uns['E_grid'][0], adata.uns['E_grid'][1], adata.uns['V_grid'][0], adata.uns['V_grid'][1],density=1.8,color='black',linewidth=2.5,arrowsize=1.5) ``` -------------------------------- ### spaTrack.plot_trajectory_gene_heatmap Source: https://github.com/yzf072/spatrack/blob/main/docs/source/api_Pgene.rst Generates a heatmap of gene expression along a trajectory. ```APIDOC ## spaTrack.plot_trajectory_gene_heatmap ### Description Visualizes the expression of trajectory-dependent genes using a heatmap. ``` -------------------------------- ### spaTrack.ptime_gene_GAM Source: https://github.com/yzf072/spatrack/blob/main/docs/source/api_Pgene.rst Calculates pseudotime-dependent gene expression using Generalized Additive Models (GAM). ```APIDOC ## spaTrack.ptime_gene_GAM ### Description Fits a Generalized Additive Model to gene expression data relative to pseudotime. ``` -------------------------------- ### Calculate vector field velocity Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/02.ST_data_of_Intrahepatic_cholangiocarcinoma_cancer.ipynb Computes the vector field velocity by averaging velocities of cells and their spatial neighbors. ```python adata.uns['E_grid'],adata.uns['V_grid']=spt.get_velocity(adata,basis='spatial',n_neigh_pos=100) ``` -------------------------------- ### spaTrack.order_trajectory_genes Source: https://github.com/yzf072/spatrack/blob/main/docs/source/api_Pgene.rst Orders genes based on their expression patterns along a trajectory. ```APIDOC ## spaTrack.order_trajectory_genes ### Description Sorts genes according to their dynamic expression changes across the inferred trajectory. ``` -------------------------------- ### Display significant genes Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/05.scRNAseq_data_of_HSC.ipynb Displays the dataframe containing significant pseudotime-dependent genes. ```python df_sig_res ``` -------------------------------- ### Calculate cell velocity field Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/01.ST_data_of_axolotl_brain_regeneration_after_injury.ipynb Computes the velocity field based on spatial coordinates and pseudotime, storing results in the AnnData object. ```python adata.uns["E_grid"], adata.uns["V_grid"] = spt.get_velocity(adata, basis="spatial", n_neigh_pos=50) ``` -------------------------------- ### Filter significant pseudotime-dependent genes Source: https://github.com/yzf072/spatrack/blob/main/docs/source/notebooks/01.ST_data_of_axolotl_brain_regeneration_after_injury.ipynb Filters results based on model fit R2 value and FDR threshold. ```python df_sig_res = df_res.loc[(df_res['model_fit']>0.2) & (df_res['fdr']<0.05)] ``` -------------------------------- ### spaTrack.filter_gene Source: https://github.com/yzf072/spatrack/blob/main/docs/source/api_Pgene.rst Filters genes based on specified criteria. ```APIDOC ## spaTrack.filter_gene ### Description Filters genes from the dataset based on provided criteria. ``` -------------------------------- ### spaTrack.plot_trajectory_gene Source: https://github.com/yzf072/spatrack/blob/main/docs/source/api_Pgene.rst Plots the expression of a specific gene along a trajectory. ```APIDOC ## spaTrack.plot_trajectory_gene ### Description Creates a plot showing the expression trend of a selected gene over pseudotime. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.