phylovelo.ana_utils
Module Contents
Functions
|
Reformat tree file from simulation data |
|
Log normalize data |
|
Plot the simulated phylogenetic tree. |
|
Weight sum the velocity to grid |
|
Generate grid to project velocities. |
|
Project velocities to grid |
|
Project velocities into embedding |
|
Plot the simulated phylogenetic tree. |
|
Draw mullerplot |
|
Label cell type names on figures. |
|
Draw a scatter plot of the two sets of data and show their correlation coefficients |
- 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
- logNormalize(data, scaling=1)
Log normalize data
- Arg:
- data(pandas.DataFrame, numpy.array):
expression data
- scaling(int):
Normalization scale
- Return:
normalized data
- 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
- 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
- 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
- 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:
- 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
- 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
- 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
- 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
- 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