Indicator gene plots
This submodule visualises the results of indicator_genes. The plot takes the results table
as input, so the permutation test only has to be run once.
Indicator gene heatmap
Description
Shows the strongest indicator genes of each group as rows and the groups as columns. Each cell is the fraction of the group's samples that carry the gene. Colour strips on the left indicate each metadata group, The cell for a gene's own group is its fidelity (B); how pale the rest of the row is reflects its specificity (A).
Function
heatmap
Plot the presence frequency of the top indicator genes in every group.
Rows are the strongest indicator genes of each group, columns are the groups, and each cell is the fraction of that group's samples carrying the gene. Genes are grouped by the group they indicate, so a good indicator shows as a dark cell in its own group's column and pale cells elsewhere. The cell in a gene's own group equals its fidelity B. A colour strip on the left marks each row's indicator group, using the same colours as the other group plots.
For each group, genes with q_value < q_max are ranked by stat (then by
p_value and B to break ties) and the first top_n are shown. Groups with
fewer significant genes show the ones they have.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pm
|
PavMatrix
|
A PavMatrix instance. |
required |
indicators
|
DataFrame
|
The DataFrame returned by
|
required |
column
|
str
|
The discrete metadata column the indicators were computed for. |
required |
top_n
|
int
|
Maximum number of genes shown per group. Defaults to 10. |
10
|
q_max
|
float
|
Genes are shown only if their q-value is below this. Defaults to 0.05. |
0.05
|
show_gene_labels
|
bool
|
If True, label rows with gene IDs. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
Figure
|
A Plotly Figure. Call .show() to display or .write_html() to export. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If column is not a discrete metadata column, if |
Warns:
| Type | Description |
|---|---|
UserWarning
|
If some groups have no gene with |
Example
from pavvis import PavMatrix
from pavvis.stats.indicator import indicator_genes
import pavvis.plots.indicator as indicator_plots
pm = PavMatrix("path/to/pav.csv", "path/to/metadata.csv")
res = indicator_genes(pm, "clade", permutations=999, random_state=0)
indicator_plots.heatmap(pm, res, "clade", top_n=5).show()
Interpretation
A row dark in its own column and white elsewhere is a gene restricted to that group and carried by most of
its samples. A row that is dark in its own column but also dark in others indicates a gene enriched in, but not
restricted to, the group. A row that is pale everywhere but darkest in its own column is a rare but group-specific
gene. Gene IDs can be long; set show_gene_labels=False for a compact overview when gene IDs do not mean anything.
Specificity vs fidelity
Description
Plots the two components of the indicator value against each other for every significant indicator gene, with one panel per group. Specificity (A) is on the x-axis and fidelity (B) on the y-axis. Grey curves join points of equal IndVal.g statistic, so genes beyond the outer curve are the strongest indicators. Where the heatmap shows only the top genes, this plot shows all of them.
Function
specificity_fidelity
Plot specificity (A) against fidelity (B) of the significant indicator genes.
One panel per group shows the genes with q_value < q_max assigned to that
group. Genes in the upper right are carried by most of the group's samples and
are rare elsewhere; high A with low B marks rare but group-restricted genes, and
high B with lower A marks genes common in the group but shared with others.
Grey curves mark equal IndVal.g statistic, sqrt(A * B) = level, and are
labelled in the first panel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pm
|
PavMatrix
|
A PavMatrix instance. |
required |
indicators
|
DataFrame
|
The DataFrame returned by
|
required |
column
|
str
|
The discrete metadata column the indicators were computed for. |
required |
q_max
|
float
|
Genes are shown only if their q-value is below this. Defaults to 0.05. |
0.05
|
levels
|
tuple[float, ...]
|
IndVal.g values drawn as reference curves. Pass |
(0.5, 0.7, 0.9)
|
cols
|
int
|
Number of panels per row. Defaults to 4. |
4
|
Returns:
| Type | Description |
|---|---|
Figure
|
A Plotly Figure. Call .show() to display or .write_html() to export. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If column is not a discrete metadata column, if |
Warns:
| Type | Description |
|---|---|
UserWarning
|
If some groups have no gene with |
Example
Interpretation
Genes in the upper right are carried by most samples of the group and rarely occur elsewhere. Genes on the right but low down on the plot are rare, yet almost restricted to the group. Genes at the top of the plot but further left are common in the group and also common in others. A group whose cloud sits far to the right has a distinctive gene content.