phylovelo.ana_utils =================== .. py:module:: phylovelo.ana_utils Functions --------- .. autoapisummary:: phylovelo.ana_utils.loadtree phylovelo.ana_utils.logNormalize phylovelo.ana_utils.plot_tree phylovelo.ana_utils.get_weight phylovelo.ana_utils.generate_grid phylovelo.ana_utils.velocity_embedding_to_grid phylovelo.ana_utils.velocity_plot phylovelo.ana_utils.plot_tree phylovelo.ana_utils.mullerplot phylovelo.ana_utils.label_name phylovelo.ana_utils.corr_plot Module Contents --------------- .. py:function:: loadtree(file) Reformat tree file from simulation data Args: file(str): File path generated by simulation code Returns: Bio.Phylo.Tree: biopython's phylo tree list[str]: cell types of leave nodes .. py:function:: logNormalize(data, scaling=1) Log normalize data Arg: data(pandas.DataFrame, numpy.array): expression data scaling(int): Normalization scale Return: normalized data .. py:function:: plot_tree(tree: Bio.Phylo.tree, colors, ax, stain='all') Plot the simulated phylogenetic tree. Args: tree (Bio.Phylo.tree): Loaded from loadtree function ax (matplotlib.axes): Axes to return tree plot colors (list): Loaded from loadtree is_show (bool): Show the figure or return an axes stain ('all', 'terminals'): 'all': color all branches; 'terminals': color leave only Return: matplotlib.axes .. py:function:: get_weight(x: list, distance: list, scale, length: int) Weight sum the velocity to grid Args: x: neighbors distance: List of distance to neighbors scale: Scale factor length: Length of neighbors Return: Weighted velocities .. py:function:: generate_grid(xlim=(-1, 1), ylim=(-1, 1), density: int = 20) Generate grid to project velocities. Args: xlim: Grid bound on x axis ylim: Grid bound on y axis density: How much grid to split Return: grid_X, grid_Y, grid_XY .. py:function:: velocity_embedding_to_grid(pts: numpy.array, vel: numpy.array, nn: str:knn, radius = 'radius', grid_density: int = 20, n_neighbors: int = 4, radius: float = 2, xlim=(None, None), ylim=(None, None)) Project velocities to grid Args: pts: UMAP/tSNE coordinates vel: Velocity vector nn: knn or radius neighbors to use grid_density: density of the grid n_neighbors: How much neighbors, works when nn=='knn' radius: How large radius, works when nn='radius' xlim: Grid bound on x axis ylim: Grid bound on y axis Return: .. py:function:: velocity_plot(pts, vel, ax, figtype: str:stream, grid, point = 'grid', nn: str:knn, radius = 'radius', grid_density: int = 20, n_neighbors: int = 4, radius: float = 2, streamdensity: float = 1.5, xlim=(None, None), ylim=(None, None), **kwargs) Project velocities into embedding Args: pts: UMAP/tSNE coordinates vel: Velocity vector ax: matplotlib.axes figtype: 'stream', 'grid' or 'point'(single cell) nn: knn or radius neighbors to use grid_density: density of the grid n_neighbors: How much neighbors, works when nn=='knn' radius: How large radius, works when nn='radius' streamdensity: Density of streamplot, works when figtype==stream xlim: Grid bound on x axis ylim: Grid bound on y axis Return: matplotlib.axes .. py:function:: plot_tree(tree, colors, ax: matplotlib.axes, colortab: list = ['gray', 'blue', 'green', 'orange', 'purple'], stain: str: 'all' or 'terminals' = 'all') Draw phylogenetic tree Args: tree: Load from loadtree colors: Load from loadtree ax: matplotlib axes to draw on colortab: A list of colors to paint different cell types stain: 'all' for color all branches, 'terminals' for color only terminals branches Return: matplotlib.axes .. py:function:: mullerplot(data: numpy.ndarray, label: list, color: list, absolute: bool = 0, alpha: float = 0.8, ax: matplotlib.axes = None) Draw mullerplot Args: data: Population size array. rows for cell type, columns for time point label: Cell type names color: Colors list absolute: False: show frequency; True: show cell number alpha: [0-1], transparent ax: axes to draw mullerplot Return: matplotlib.axes .. py:function:: label_name(loc, cell_types, ax, fontsize=12, font='DejaVu Sans') Label cell type names on figures. Args: loc: x, y locations in embedding cell_types: Cell type names ax: axes to label cell type name fontsize: fontsize font: font Return: matplotlib.axes .. py:function:: corr_plot(x, y, ax, stats='pearson', r0_x=None, r0_y=None, r1_x=None, r1_y=None, fontsize=10) Draw a scatter plot of the two sets of data and show their correlation coefficients Args: x: data1 y: data2 ax: axes to draw scatter on stats: pearson or spearman r0_x, r0_y, r1_x, r1_y: locations to label the correlation coefficient and the p-value fontsize: fontsize Return: matplotlib.axes