Visualization¶
Plotting utilities exposed by the visualization package.
- snputils.visualization.scatter(dimredobj, labels_file, abbreviation_inside_dots=True, arrows_for_titles=False, dots=True, legend=True, color_palette=None, show=True, save_path=None)[source]¶
Plot a scatter plot with centroids for each group, with options for labeling and display styles.
- Parameters:
dimredobj (np.ndarray) – Reduced dimensionality data; expected to have (n_haplotypes, 2) shape.
labels_file (str) – Path to a TSV file with columns ‘indID’ and ‘label’, providing labels for coloring and annotating points.
abbreviation_inside_dots (bool) – If True, displays abbreviated labels (first 3 characters) inside the centroid markers.
arrows_for_titles (bool) – If True, adds arrows pointing to centroids with group labels displayed near the centroids.
legend (bool) – If True, includes a legend indicating each group label.
color_palette (optional) – Color map or list of colors to use for unique labels. Defaults to ‘tab10’ if None.
show (bool, optional) – Whether to display the plot. Defaults to False.
save_path (str, optional) – Path to save the plot image. If None, the plot is not saved.
- Returns:
None
- snputils.visualization.lai.plot_lai(laiobj, colors, sort=True, figsize=None, legend=False, title=None, fontsize=None, scale=2)[source]¶
Plot LAI (Local Ancestry Inference) data with customizable options. Each row represents the ancestry of a sample at the window level, distinguishing between maternal and paternal strands. Whitespace is used to separate individual samples.
- Parameters:
laiobj – A LocalAncestryObject containing LAI data.
colors – A dictionary with ancestry-color mapping.
sort – If True, sort samples based on the most frequent ancestry. Samples are displayed with the most predominant ancestry first, followed by the second most predominant, and so on. Defaults to True.
figsize – Figure size. If is None, the figure is displayed with a default size of (25, 25). Defaults to None.
legend – If True, display a legend. If
sort==True, ancestries in the legend are sorted based on their total frequency in descending order. Defaults to False.title – Title for the plot. If None, no title is displayed. Defaults to None.
fontsize – Font sizes for various plot elements. If None, default font sizes are used. Defaults to None.
scale – Number of times to duplicate rows for enhanced vertical visibility. Defaults to 2.
- snputils.visualization.admixture.reorder_admixture(Q_mat)[source]¶
Reorder Q_mat rows so that rows are grouped by each sample’s dominant ancestry, and columns are sorted by descending average ancestry proportion.
- snputils.visualization.admixture.plot_admixture(ax, Q_mat_sorted, boundary_list, col_order=None, colors=None, show_boundaries=True, show_axes_labels=True, show_ticks=True, set_limits=True, minimal=False)[source]¶
Plot a structure-style bar chart of Q_mat_sorted in the given Axes ax. If colors is not None, it should be a list or array of length K. If col_order is not None, colors are reordered according to col_order.
Optional controls: - show_boundaries (bool): draw vertical lines at group boundaries. Default True. - show_axes_labels (bool): set X/Y axis labels. Default True. - show_ticks (bool): show axis ticks. Default True. - set_limits (bool): set xlim and ylim to [0, n_samples-1] and [0,1]. Default True. - minimal (bool): if True, overrides to disable boundaries, labels, ticks, limits and hides spines.
- snputils.visualization.admixture_manhattan_plot.manhattan_plot(input_file, colors, significance_threshold=0.05, figsize=None, title=None, fontsize=None, save=None, output_filename=None)[source]¶
Generates a Manhattan plot from an input file the results of an admixture mapping association. The plot is highly customizable, allowing users to specify colors for each chromosome and apply bonferroni correction for p-values.
- Parameters:
input_file – Path to the input file containing columns ‘#CHROM’, ‘POS’, and ‘P’. default plik2 output files are supported.
colors – List of colors to apply to each chromosome. the chromosome number is used as an index to select the color.
significance_threshold – Significance threshold for p-values. Default is 0.05.
figsize – Optional tuple to specify figure dimensions (width, height).
title – Plot title. If None, no title is shown.
fontsize – Dictionary with font sizes for title, labels, and legend.
save – If True, saves the plot to a file. If None, the plot is not saved.
output_filename – Filename for saving the plot (PNG).
- snputils.visualization.admixture_viz.pong_viz(folder_runs, output_dir, k=None, min_k=None, max_k=None, runs=None, run_prefix='train', ind2pop_path=None, pop_names_path=None, color_list_path=None, verbose=False)[source]¶
Executes Pong visualization with the specified parameters.
- snputils.visualization.admixture_viz.create_filemap(folder, k=None, min_k=None, max_k=None, runs=None, run_prefix='train_demo')[source]¶
Creates a filemap for training files organized by k values and runs and saves it to a file.
- Parameters:
folder (str) – Base folder path
k (Optional[int]) – Single k value to process. If specified, min_k and max_k are ignored
min_k (Optional[int]) – Minimum k value for range processing
max_k (Optional[int]) – Maximum k value for range processing
runs (List[int]) – List of run numbers
run_prefix (str) – Prefix for the run files (default: ‘train_demo’)
- Returns:
str – Path to saved file
- Raises:
FileMapError – If invalid parameters are provided or if configuration is incorrect