bioneuralnet.metrics.plot

Functions

cast(typ, val)

Cast a value to a type.

cluster_pca_correlation(cluster_df, pheno)

Computes the Pearson correlation coefficient between PC1 of a cluster and phenotype.

compare_clusters(clusters1, clusters2, pheno)

Compare two cluster sets via phenotype correlation.

find_omics_modality(mapping_df, dfs[, ...])

Maps features in the mapping DataFrame to their omics source based on provided dataframes.

get_logger(name)

Retrieves a global logger configured to write to 'bioneuralnet.log'.

plot_embeddings(embeddings[, node_labels, ...])

Plot the embeddings in 2D space using t-SNE.

plot_multiple_metrics(metrics[, title_map, ...])

Plot multiple grouped performance metrics as side-by-side bar plots.

plot_network(adjacency_matrix[, ...])

Plots a network graph from an adjacency matrix with improved visualization.

plot_performance(embedding_result, raw_rf_acc)

A minimal bar plot comparing two performance metrics.

plot_performance_three(raw_score, gnn_score, ...)

Bar plot comparing performance for raw omics, GNN-enriched omics, and one other method.

plot_variance_by_feature(df)

Plot the variance for each feature against its index or name.

plot_variance_distribution(df[, bins])

Compute the variance for each feature (column) in the DataFrame and plot a histogram of these variances.

Classes

Path(*args, **kwargs)

PurePath subclass that can make system calls.

TSNE([n_components, perplexity, ...])

T-distributed Stochastic Neighbor Embedding.

bioneuralnet.metrics.plot.compare_clusters(clusters1: list, clusters2: list, pheno: DataFrame, label1: str = 'Method 1', label2: str = 'Method 2') DataFrame[source]

Compare two cluster sets via phenotype correlation.

Clusters for each method are sorted by size (number of columns), the top min(len(clusters1), len(clusters2)) are paired by rank, and phenotype correlation is computed for each using cluster_correlation. A line plot of correlation vs. cluster index is displayed for both methods.

Parameters:
  • clusters1 (list[pd.DataFrame]) – Clusters for the first method; one DataFrame per cluster (samples x features).

  • clusters2 (list[pd.DataFrame]) – Clusters for the second method; same format as clusters1.

  • pheno (pd.DataFrame) – Phenotype data; the first column is used as the target.

  • label1 (str) – Label for the first method (used in legend and result columns).

  • label2 (str) – Label for the second method (used in legend and result columns).

Returns:

One row per paired cluster with cluster index, sizes and correlations for both methods.

Return type:

pd.DataFrame

bioneuralnet.metrics.plot.find_omics_modality(mapping_df, dfs, source_names=None)[source]

Maps features in the mapping DataFrame to their omics source based on provided dataframes.

Parameters:
  • mapping_df (pd.DataFrame) – DataFrame with an “Omic” column listing feature names.

  • dfs (list[pd.DataFrame]) – List of DataFrames, each representing an omics modality.

  • source_names (list[str], optional) – Names corresponding to each DataFrame in dfs. If None, default names will be used.

Returns:

Updated mapping DataFrame with an additional “Source” column.

Return type:

pd.DataFrame

bioneuralnet.metrics.plot.plot_embeddings(embeddings, node_labels=None, legend_labels=None)[source]

Plot the embeddings in 2D space using t-SNE.

Parameters:
  • embeddings (array-like) – High-dimensional embedding data.

  • node_labels (array-like or DataFrame, optional) – Labels for the nodes to color the points.

  • legend_labels (list, optional) – Labels for the legend corresponding to unique node labels.

bioneuralnet.metrics.plot.plot_multiple_metrics(metrics: dict[str, dict[str, tuple[float, float]]], title_map: dict[str, str] | None = None, ylabel_map: dict[str, str] | None = None, filename: str | Path | None = None) None[source]

Plot multiple grouped performance metrics as side-by-side bar plots.

Parameters:
  • metrics (dict) – A nested dictionary of the form:{metric_name: {group_name: (mean, std)}}.

  • title_map (dict, optional) – Maps each metric name to a custom plot title.

  • ylabel_map (dict, optional) – Maps each metric name to a Y-axis label.

  • filename (str or Path, optional) – If provided, saves the figure to this path.

Returns:

None. Displays or shows a matplotlib figure with grouped metric comparisons.

bioneuralnet.metrics.plot.plot_network(adjacency_matrix, weight_threshold=0.0, show_labels=False, show_edge_weights=False, layout='kamada')[source]

Plots a network graph from an adjacency matrix with improved visualization. Also adds a summary table mapping node indexes to actual gene names.

Parameters:
  • adjacency_matrix (pd.DataFrame) – The adjacency matrix of the network.

  • weight_threshold (float) – Minimum weight to keep an edge (default: 0.0).

  • show_labels (bool) – Whether to show node labels.

  • show_edge_weights (bool) – Whether to show edge weights

Returns:

Mapping of node indexes to actual gene names.

Return type:

pd.DataFrame

bioneuralnet.metrics.plot.plot_performance(embedding_result, raw_rf_acc, title='Performance Comparison', filename=None, metric_name='Accuracy', labels=None)[source]

A minimal bar plot comparing two performance metrics. e.g., raw vs embeddings based performance.

Parameters:
  • embedding_result – tuple or dict containing (mean, std) of the metric for the model using embeddings.

  • raw_rf_acc – tuple or dict containing (mean, std) of the metric for the baseline model.

  • title – string, title of the plot.

  • filename – string or Path, if provided, the plot will be saved to this file.

  • metric_name – string, name of the metric to display on the Y-axis (e.g., “Accuracy”).

  • labels – iterable of two strings (default: [“Label 1”, “Label 2”]).

Returns:

None. Displays (and optionally saves) the bar plot.

bioneuralnet.metrics.plot.plot_performance_three(raw_score, gnn_score, other_score, labels=['Raw', 'GNN', 'Other'], title='Performance Comparison', filename=None)[source]

Bar plot comparing performance for raw omics, GNN-enriched omics, and one other method.

bioneuralnet.metrics.plot.plot_variance_by_feature(df: DataFrame)[source]

Plot the variance for each feature against its index or name.

Parameters:

df (pd.DataFrame) – Input data.

Returns:

Generated figure.

Return type:

matplotlib.figure.Figure

bioneuralnet.metrics.plot.plot_variance_distribution(df: DataFrame, bins: int = 50)[source]

Compute the variance for each feature (column) in the DataFrame and plot a histogram of these variances.

Parameters:
  • df (pd.DataFrame) – Input data.

  • bins (int) – Number of bins for the histogram.

Returns:

Generated figure.

Return type:

matplotlib.figure.Figure