featuremap.features =================== .. py:module:: featuremap.features .. autoapi-nested-parse:: Created on Wed Nov 1 13:52:14 2023 Functions --------- .. autoapisummary:: featuremap.features.create_adata featuremap.features.pseudotime_mst featuremap.features.quiver_autoscale featuremap.features.plot_gauge featuremap.features.plot_gauge_both featuremap.features.local_intrinsic_dim featuremap.features.feature_variation featuremap.features.feature_variation_one_feature featuremap.features.feature_projection featuremap.features.feature_gradient featuremap.features.feature_gradient_projection featuremap.features.plot_feature featuremap.features.plot_one_feature featuremap.features.plot_multiple_features featuremap.features.plot_one_feature_by_all_cells featuremap.features.plot_multiple_features_by_all_cells featuremap.features.plot_multiple_features_by_all_cells_given_clusters featuremap.features.variation_feature_pp featuremap.features.feature_variation_embedding featuremap.features.featuremap_var_3d Module Contents --------------- .. py:function:: create_adata(X, emb_featuremap, obs=None, var=None) Create an AnnData object for plotting :param X: Data matrix. :type X: np.ndarray :param emb_featuremap: Featuremap object. :type emb_featuremap: object :param obs: :type obs: pd.DataFrame :param var: :type var: pd.DataFrame :returns: **adata** -- Annotated data matrix. :rtype: AnnData .. py:function:: pseudotime_mst(adata, random_state, start_point_index) Given a staring point, compute the pseudotime by distance to all other points on the MST :param adata: Annotated data matrix. :type adata: AnnData :param random_state: Random seed. :type random_state: int :param start_point_index: Starting point index. :type start_point_index: int :returns: pseudotime_mst : np.ndarray. Pseudotime based on MST. :rtype: adata.obs['feat_pseudotime'] = pseudotime_mst .. py:function:: quiver_autoscale(X_emb, V_emb) Autoscale the arrow plot :param X_emb: Embedding matrix. :type X_emb: np.ndarray :param V_emb: Variation embedding matrix. :type V_emb: np.ndarray :returns: Scale factor for quiver plot. :rtype: Q.scale / scale_factor * 5 .. py:function:: plot_gauge(adata: anndata.AnnData, embedding='X_featmap', vkey='gauge_v1_emb', density=1, smooth=0.5, n_neighbors=None, min_mass=1, autoscale=True) Plot the gauge embedding to visualize the eigengene (or frame for feature loadings) :param adata: An annotated data matrix. :type adata: AnnData :param embedding: Embedding background for feature plot. The default is 'X_featmap'. :type embedding: string :param vkey: Variation key. The default is 'gauge_v1_emb'. :type vkey: string :param density: Grid desity for plot. The default is 1. :type density: float :param smooth: For kde estimation. The default is 0.5. :type smooth: float :param n_neighbors: Number of neighbours for kde. The default is None. :type n_neighbors: int :param min_mass: Minumum denstiy to show the grid plot. The default is 1. :type min_mass: float :param autoscale: Scale the arrow plot. The default is True. :type autoscale: bool .. py:function:: plot_gauge_both(adata: anndata.AnnData, embedding='X_featmap', vkey_1='gauge_v1_emb', vkey_2='gauge_v2_emb', density=1, smooth=0.5, n_neighbors=None, min_mass=1, autoscale=True, scale_quiver=1) Plot the gauge embedding to visualize the eigengene (or frame for feature loadings) :param adata: An annotated data matrix. :type adata: AnnData :param embedding: Embedding background for feature plot. The default is 'X_featmap'. :type embedding: string :param density: Grid desity for plot. The default is 1. :type density: float :param smooth: For kde estimation. The default is 0.5. :type smooth: float :param n_neighbors: Number of neighbours for kde. The default is None. :type n_neighbors: int :param min_mass: Minumum denstiy to show the grid plot. The default is 1. :type min_mass: float :param autoscale: Scale the arrow plot. The default is True. :type autoscale: bool .. py:function:: local_intrinsic_dim(adata: anndata.AnnData, threshold=0.9, plot: bool = False) Compute the intrinsic dimensionality locally based on local SVD. :param adata: An annotated data matrix. :type adata: AnnData :param threshold: Threshold for proportion of variance contributions. The default is 0.9. :type threshold: float :param plot: If True, plot a histogram of the intrinsic dimensionality. Default False. :type plot: bool :returns: **intrinsic_dim** -- Intrinsic dimensionality. :rtype: np.ndarray .. py:function:: feature_variation(adata: anndata.AnnData, threshold=0.5) Compute the feature variation and feature loadings based on local SVD. :param adata: An annotated data matrix. :type adata: AnnData .. py:function:: feature_variation_one_feature(adata: anndata.AnnData, feature='', threshold=0.9, feature_key='variation_feature') Compute the feature variation and feature loadings based on local SVD. :param adata: An annotated data matrix. :type adata: AnnData .. py:function:: feature_projection(adata: anndata.AnnData, feature='', vkey='VH_embedding') Compute the feature variation and feature loadings based on local SVD. :param adata: An annotated data matrix. :type adata: AnnData :param feature: Feature name to be plotted. :type feature: string .. py:function:: feature_gradient(adata: anndata.AnnData, feature='') Compute the feature variation and feature loadings based on local SVD. :param adata: An annotated data matrix. :type adata: AnnData :param feature: Feature name to be plotted. :type feature: string .. py:function:: feature_gradient_projection(adata: anndata.AnnData, feature='', random_state=42) .. py:function:: plot_feature(adata: anndata.AnnData, feature='', feature_loading_emb='feature_loading_embedding', embedding='X_featmap', cluster_key='clusters', plot_within_cluster=[], pseudotime_adjusted=False, pseudotime='dpt_pseudotime', trend='positive', ratio=0.2, density=1, smooth=0.5, n_neighbors=None, min_mass=1, autoscale=True) Plot a given feature (e.g., gene) in two dimensional visualization :param adata: An annotated data matrix. :type adata: AnnData :param feature: Feature name to be plotted. :type feature: string :param embedding: Embedding background for feature plot. The default is 'X_featmap'. :type embedding: string :param cluster_key: Cluster name indicator. The default is 'clusters'. :type cluster_key: string :param plot_within_cluster: A list of clusters in which the feaure is to plot. The default is []. :type plot_within_cluster: list :param pseudotime_adjusted: Whether to adjust the feature direction by pseudotime. The default is False. :type pseudotime_adjusted: bool :param pseudotime: Pseudotime indicator. The default is 'dpt_pseudotime'. :type pseudotime: string :param trend: The direction along pseudotime. The default is 'positive'. :type trend: string of {'positive','negative'} :param ratio: Filtering ratio by expression to filter varition by low expression. The default is 0.5. :type ratio: float :param density: Grid desity for plot. The default is 1. :type density: float :param smooth: For kde estimation. The default is 0.5. :type smooth: float :param n_neighbors: Number of neighbours for kde. The default is None. :type n_neighbors: int :param min_mass: Minumum denstiy to show the grid plot. The default is 1. :type min_mass: float :param autoscale: Scale the arrow plot. The default is True. :type autoscale: bool .. py:function:: plot_one_feature(adata: anndata.AnnData, feature='', embedding='X_featmap', cluster_key='clusters', plot_within_cluster=[], pseudotime_adjusted=False, pseudotime='dpt_pseudotime', trend='positive', ratio=0.2, density=1, smooth=0.5, n_neighbors=None, min_mass=1, autoscale=True, scale_quiver=1.0, output_v_grid=False, scale_by_variation=False, ax=None) Plot a given feature (e.g., gene) in two dimensional visualization :param adata: An annotated data matrix. :type adata: AnnData :param feature: Feature name to be plotted. :type feature: string :param embedding: Embedding background for feature plot. The default is 'X_featmap'. :type embedding: string :param cluster_key: Cluster name indicator. The default is 'clusters'. :type cluster_key: string :param plot_within_cluster: A list of clusters in which the feaure is to plot. The default is []. :type plot_within_cluster: list :param pseudotime_adjusted: Whether to adjust the feature direction by pseudotime. The default is False. :type pseudotime_adjusted: bool :param pseudotime: Pseudotime indicator. The default is 'dpt_pseudotime'. :type pseudotime: string :param trend: The direction along pseudotime. The default is 'positive'. :type trend: string of {'positive','negative'} :param ratio: Filtering ratio by expression to filter varition by low expression. The default is 0.5. :type ratio: float :param density: Grid desity for plot. The default is 1. :type density: float :param smooth: For kde estimation. The default is 0.5. :type smooth: float :param n_neighbors: Number of neighbours for kde. The default is None. :type n_neighbors: int :param min_mass: Minumum denstiy to show the grid plot. The default is 1. :type min_mass: float :param autoscale: Scale the arrow plot. The default is True. :type autoscale: bool :param output_v_grid: Output the grid velocity. The default is False. :type output_v_grid: bool :param scale_by_variation: Scale the arrow plot by feature variation. The default is True. :type scale_by_variation: bool :param ax: The axis to plot the feature. The default is None. :type ax: matplotlib axis .. py:function:: plot_multiple_features(adata: anndata.AnnData, features=[], embedding='X_featmap', cluster_key='clusters', plot_within_cluster=[], pseudotime_adjusted=False, pseudotime='dpt_pseudotime', trend='positive', ratio=0.2, density=1, smooth=0.5, n_neighbors=None, min_mass=1, autoscale=True, scale_by_variation=True) Plot a given feature (e.g., gene) in two dimensional visualization :param adata: An annotated data matrix. :type adata: AnnData :param feature: Feature name to be plotted. :type feature: string :param embedding: Embedding background for feature plot. The default is 'X_featmap'. :type embedding: string :param cluster_key: Cluster name indicator. The default is 'clusters'. :type cluster_key: string :param plot_within_cluster: A list of clusters in which the feaure is to plot. The default is []. :type plot_within_cluster: list :param pseudotime_adjusted: Whether to adjust the feature direction by pseudotime. The default is False. :type pseudotime_adjusted: bool :param pseudotime: Pseudotime indicator. The default is 'dpt_pseudotime'. :type pseudotime: string :param trend: The direction along pseudotime. The default is 'positive'. :type trend: string of {'positive','negative'} :param ratio: Filtering ratio by expression to filter varition by low expression. The default is 0.5. :type ratio: float :param density: Grid desity for plot. The default is 1. :type density: float :param smooth: For kde estimation. The default is 0.5. :type smooth: float :param n_neighbors: Number of neighbours for kde. The default is None. :type n_neighbors: int :param min_mass: Minumum denstiy to show the grid plot. The default is 1. :type min_mass: float :param autoscale: Scale the arrow plot. The default is True. :type autoscale: bool :param output_v_grid: Output the grid velocity. The default is False. :type output_v_grid: bool :param scale_by_variation: Scale the arrow plot by feature variation. The default is True. :type scale_by_variation: bool .. py:function:: plot_one_feature_by_all_cells(adata: anndata.AnnData, feature='', embedding='X_featmap', cluster_key='clusters', plot_within_cluster=[], pseudotime_adjusted=False, pseudotime='dpt_pseudotime', trend='positive', ratio=0.2, density=1, smooth=0.5, n_neighbors=None, min_mass=1, autoscale=True, output_v_grid=False, scale_by_variation=True, scale_quiver=1.0) Plot a given feature (e.g., gene) in two dimensional visualization :param adata: An annotated data matrix. :type adata: AnnData :param feature: Feature name to be plotted. :type feature: string :param embedding: Embedding background for feature plot. The default is 'X_featmap'. :type embedding: string :param cluster_key: Cluster name indicator. The default is 'clusters'. :type cluster_key: string :param plot_within_cluster: A list of clusters in which the feaure is to plot. The default is []. :type plot_within_cluster: list :param pseudotime_adjusted: Whether to adjust the feature direction by pseudotime. The default is False. :type pseudotime_adjusted: bool :param pseudotime: Pseudotime indicator. The default is 'dpt_pseudotime'. :type pseudotime: string :param trend: The direction along pseudotime. The default is 'positive'. :type trend: string of {'positive','negative'} :param ratio: Filtering ratio by expression to filter varition by low expression. The default is 0.5. :type ratio: float :param density: Grid desity for plot. The default is 1. :type density: float :param smooth: For kde estimation. The default is 0.5. :type smooth: float :param n_neighbors: Number of neighbours for kde. The default is None. :type n_neighbors: int :param min_mass: Minumum denstiy to show the grid plot. The default is 1. :type min_mass: float :param autoscale: Scale the arrow plot. The default is True. :type autoscale: bool .. py:function:: plot_multiple_features_by_all_cells(adata: anndata.AnnData, features=[], embedding='X_featmap', cluster_key='clusters', plot_within_cluster=[], pseudotime_adjusted=False, pseudotime='dpt_pseudotime', trend='positive', ratio=0.2, density=1, smooth=0.5, n_neighbors=None, min_mass=1, autoscale=True, output_v_grid=False, scale_by_variation=True) Plot a given feature (e.g., gene) in two dimensional visualization :param adata: An annotated data matrix. :type adata: AnnData :param feature: Feature name to be plotted. :type feature: string :param embedding: Embedding background for feature plot. The default is 'X_featmap'. :type embedding: string :param cluster_key: Cluster name indicator. The default is 'clusters'. :type cluster_key: string :param plot_within_cluster: A list of clusters in which the feaure is to plot. The default is []. :type plot_within_cluster: list :param pseudotime_adjusted: Whether to adjust the feature direction by pseudotime. The default is False. :type pseudotime_adjusted: bool :param pseudotime: Pseudotime indicator. The default is 'dpt_pseudotime'. :type pseudotime: string :param trend: The direction along pseudotime. The default is 'positive'. :type trend: string of {'positive','negative'} :param ratio: Filtering ratio by expression to filter varition by low expression. The default is 0.5. :type ratio: float :param density: Grid desity for plot. The default is 1. :type density: float :param smooth: For kde estimation. The default is 0.5. :type smooth: float :param n_neighbors: Number of neighbours for kde. The default is None. :type n_neighbors: int :param min_mass: Minumum denstiy to show the grid plot. The default is 1. :type min_mass: float :param autoscale: Scale the arrow plot. The default is True. :type autoscale: bool .. py:function:: plot_multiple_features_by_all_cells_given_clusters(adata: anndata.AnnData, features=[], embedding='X_featmap', cluster_key='clusters', plot_within_cluster=[], pseudotime_adjusted=True, pseudotime='feat_pseudotime', trend='positive', ratio=0.2, density=1, smooth=0.5, n_neighbors=None, min_mass=1, autoscale=True, scale_by_variation=True, feature_key='', scale_quiver=1.0) Plot a given feature (e.g., gene) in two dimensional visualization :param adata: An annotated data matrix. :type adata: AnnData :param feature: Feature name to be plotted. :type feature: string :param embedding: Embedding background for feature plot. The default is 'X_featmap'. :type embedding: string :param cluster_key: Cluster name indicator. The default is 'clusters'. :type cluster_key: string :param plot_within_cluster: A list of clusters in which the feaure is to plot. The default is []. :type plot_within_cluster: list :param pseudotime_adjusted: Whether to adjust the feature direction by pseudotime. The default is False. :type pseudotime_adjusted: bool :param pseudotime: Pseudotime indicator. The default is 'dpt_pseudotime'. :type pseudotime: string :param trend: The direction along pseudotime. The default is 'positive'. :type trend: string of {'positive','negative'} :param ratio: Filtering ratio by expression to filter varition by low expression. The default is 0.5. :type ratio: float :param density: Grid desity for plot. The default is 1. :type density: float :param smooth: For kde estimation. The default is 0.5. :type smooth: float :param n_neighbors: Number of neighbours for kde. The default is None. :type n_neighbors: int :param min_mass: Minumum denstiy to show the grid plot. The default is 1. :type min_mass: float :param autoscale: Scale the arrow plot. The default is True. :type autoscale: bool .. py:function:: variation_feature_pp(adata) Preprocess the variation feature for DGV analysis :param adata: An annotated data matrix. :type adata: AnnData .. py:function:: feature_variation_embedding(adata, n_components=2, layer='variation_feature', variation_preprocess_flag=False, random_state=42) Compute the feature variation embedding based on all features based on local SVD. :param adata: An annotated data matrix. :type adata: AnnData :param n_components: Number of components for embedding. The default is 2. :type n_components: int :param layer: Layer for variation feature. The default is 'variation_feature'. :type layer: string :param variation_preprocess_flag: Whether to preprocess the variation feature. The default is False. :type variation_preprocess_flag: bool :param random_state: Random state. The default is 42. :type random_state: int :returns: **adata_var** -- Annotated data matrix with variation matrix and variation embedding. :rtype: AnnData .. py:function:: featuremap_var_3d(emb_var_3d, color=None, symbol=None, marker_size=3) Plot the feature variation embedding in 3D. :param emb_var_3d: 3D embedding of feature variation. :type emb_var_3d: np.ndarray :param color: Color indicator. The default is None. :type color: string :param symbol: Symbol indicator. The default is None. :type symbol: string :param marker_size: Marker size. The default is 3. :type marker_size: int