bio-data-visualization-interactive-visualization
$
npx mdskill add GPTomics/bioSkills/bio-data-visualization-interactive-visualizationGenerate interactive HTML plots for exploratory data analysis and dashboards.
- Builds zoomable, hoverable visualizations for omics datasets and web sharing.
- Integrates Python libraries plotly, bokeh, and altair with R tools.
- Adapts code dynamically by introspecting installed package APIs.
- Delivers results as executable HTML files or in-browser interactive displays.
SKILL.md
.github/skills/bio-data-visualization-interactive-visualizationView on GitHub ↗
---
name: bio-data-visualization-interactive-visualization
description: Create interactive HTML plots with plotly and bokeh for exploratory data analysis and web-based sharing of omics visualizations. Use when building zoomable, hoverable plots for data exploration or web dashboards.
tool_type: mixed
primary_tool: plotly
---
## Version Compatibility
Reference examples tested with: ggplot2 3.5+, pandas 2.2+
Before using code patterns, verify installed versions match. If versions differ:
- Python: `pip show <package>` then `help(module.function)` to check signatures
- R: `packageVersion('<pkg>')` then `?function_name` to verify parameters
If code throws ImportError, AttributeError, or TypeError, introspect the installed
package and adapt the example to match the actual API rather than retrying.
# Interactive Visualization
**"Create interactive plots"** → Build zoomable, hoverable visualizations for exploring large datasets in notebooks or HTML reports.
- Python: `plotly.express`, `bokeh`, `altair`
- R: `plotly::ggplotly()`, `htmlwidgets`
## plotly (Python)
```python
import plotly.express as px
import plotly.graph_objects as go
import pandas as pd
# Scatter plot
fig = px.scatter(df, x='PC1', y='PC2', color='condition', hover_data=['sample'],
title='PCA Plot')
fig.write_html('pca_interactive.html')
fig.show()
```
## Interactive Volcano Plot
**Goal:** Create a zoomable, hoverable volcano plot for exploring differential expression results.
**Approach:** Compute significance categories, build a plotly scatter with gene names on hover and metadata tooltips, add threshold reference lines, and export as standalone HTML.
```python
import plotly.express as px
df['neg_log_pval'] = -np.log10(df['pvalue'])
df['significant'] = (df['padj'] < 0.05) & (abs(df['log2FoldChange']) > 1)
fig = px.scatter(df, x='log2FoldChange', y='neg_log_pval',
color='significant', hover_name='gene',
hover_data=['baseMean', 'padj'],
color_discrete_map={True: 'red', False: 'grey'},
title='Interactive Volcano Plot')
fig.add_hline(y=-np.log10(0.05), line_dash='dash', line_color='grey')
fig.add_vline(x=-1, line_dash='dash', line_color='grey')
fig.add_vline(x=1, line_dash='dash', line_color='grey')
fig.update_layout(xaxis_title='Log2 Fold Change', yaxis_title='-Log10 P-value')
fig.write_html('volcano_interactive.html')
```
## Interactive Heatmap
```python
import plotly.express as px
fig = px.imshow(df, color_continuous_scale='RdBu_r', aspect='auto',
labels=dict(x='Samples', y='Genes', color='Expression'))
fig.update_xaxes(tickangle=45)
fig.write_html('heatmap_interactive.html')
```
## plotly with Subplots
```python
from plotly.subplots import make_subplots
import plotly.graph_objects as go
fig = make_subplots(rows=1, cols=2, subplot_titles=('PCA', 'Volcano'))
fig.add_trace(go.Scatter(x=df['PC1'], y=df['PC2'], mode='markers',
marker=dict(color=df['condition'].map({'Control': 'blue', 'Treatment': 'red'})),
text=df['sample'], name='PCA'), row=1, col=1)
fig.add_trace(go.Scatter(x=de['log2FC'], y=-np.log10(de['pvalue']), mode='markers',
marker=dict(color=de['significant'].map({True: 'red', False: 'grey'})),
text=de['gene'], name='Volcano'), row=1, col=2)
fig.update_layout(height=500, width=1000, showlegend=False)
fig.write_html('combined_interactive.html')
```
## plotly (R)
```r
library(plotly)
# From ggplot2
p <- ggplot(df, aes(PC1, PC2, color = condition, text = sample)) +
geom_point()
ggplotly(p)
# Native plotly
plot_ly(df, x = ~PC1, y = ~PC2, color = ~condition, text = ~sample,
type = 'scatter', mode = 'markers') %>%
layout(title = 'PCA Plot')
```
## Interactive MA Plot
```r
library(plotly)
de_results$text <- paste0('Gene: ', de_results$gene, '<br>',
'baseMean: ', round(de_results$baseMean, 2), '<br>',
'log2FC: ', round(de_results$log2FoldChange, 2), '<br>',
'padj: ', formatC(de_results$padj, format = 'e', digits = 2))
plot_ly(de_results, x = ~log10(baseMean), y = ~log2FoldChange,
color = ~(padj < 0.05), colors = c('grey', 'red'),
text = ~text, hoverinfo = 'text',
type = 'scatter', mode = 'markers', marker = list(size = 5, opacity = 0.6)) %>%
layout(title = 'MA Plot',
xaxis = list(title = 'Log10 Mean Expression'),
yaxis = list(title = 'Log2 Fold Change'))
```
## Linked Brushing
```python
import plotly.express as px
from plotly.subplots import make_subplots
fig = px.scatter_matrix(df, dimensions=['PC1', 'PC2', 'PC3'], color='condition')
fig.write_html('scatter_matrix.html')
```
## bokeh (Python)
```python
from bokeh.plotting import figure, output_file, save
from bokeh.models import ColumnDataSource, HoverTool
output_file('pca_bokeh.html')
source = ColumnDataSource(df)
p = figure(title='PCA Plot', x_axis_label='PC1', y_axis_label='PC2',
tools='pan,wheel_zoom,box_zoom,reset,hover,save')
p.circle('PC1', 'PC2', source=source, size=10, alpha=0.6,
color='color', legend_field='condition')
hover = p.select(dict(type=HoverTool))
hover.tooltips = [('Sample', '@sample'), ('Condition', '@condition')]
save(p)
```
## bokeh with Widgets
```python
from bokeh.layouts import column
from bokeh.models import Select
from bokeh.io import curdoc
select = Select(title='Color by:', value='condition',
options=['condition', 'batch', 'cluster'])
def update(attr, old, new):
p.circle.glyph.fill_color = new
select.on_change('value', update)
curdoc().add_root(column(select, p))
```
## Save Interactive Plots
```python
# plotly
fig.write_html('plot.html')
fig.write_json('plot.json')
# bokeh
from bokeh.io import save, export_png
save(p, filename='plot.html')
export_png(p, filename='plot.png') # requires selenium
```
## Embed in Jupyter
```python
# plotly - works automatically in Jupyter
fig.show()
# bokeh
from bokeh.io import output_notebook, show
output_notebook()
show(p)
```
## Related Skills
- data-visualization/ggplot2-fundamentals - Static plots
- data-visualization/specialized-omics-plots - Omics-specific plots
- reporting/quarto-reports - Embed in reports
More from GPTomics/bioSkills
- bio-admet-predictionPredicts ADMET properties using ADMETlab 3.0 API or DeepChem models. Estimates bioavailability, CYP inhibition, hERG liability, and 119 toxicity endpoints with uncertainty quantification. Filters for PAINS and other structural alerts. Use when filtering compounds for drug-likeness or prioritizing leads by predicted safety.
- bio-alignment-amplicon-clippingTrim PCR primers from aligned reads in amplicon-panel BAMs using samtools ampliconclip. Use when processing SARS-CoV-2 ARTIC, hereditary cancer panels, ctDNA hot-spot panels, or any amplicon assay where primer-derived bases would falsely confirm reference at primer footprints.
- bio-alignment-filteringFilter alignments by flags, mapping quality, and regions using samtools view and pysam. Use when extracting specific reads, removing low-quality alignments, or subsetting to target regions.
- bio-alignment-indexingCreate and use BAI/CSI indices for BAM/CRAM files using samtools and pysam. Use when enabling random access to alignment files or fetching specific genomic regions.
- bio-alignment-ioRead, write, and convert multiple sequence alignment files using Biopython Bio.AlignIO. Supports Clustal, PHYLIP, Stockholm, FASTA, Nexus, and other alignment formats for phylogenetics and conservation analysis. Use when reading, writing, or converting alignment file formats.
- bio-alignment-msa-parsingParse and analyze multiple sequence alignments using Biopython. Extract sequences, identify conserved regions, analyze gaps, work with annotations, and manipulate alignment data for downstream analysis. Use when parsing or manipulating multiple sequence alignments.
- bio-alignment-msa-statisticsCalculate alignment statistics including sequence identity, conservation scores, substitution matrices, and similarity metrics. Use when comparing alignment quality, measuring sequence divergence, and analyzing evolutionary patterns.
- bio-alignment-multiplePerform multiple sequence alignment using MAFFT, MUSCLE5, ClustalOmega, or T-Coffee. Guides tool and algorithm selection based on dataset size, sequence divergence, and downstream application. Use when aligning three or more homologous sequences for phylogenetics, conservation analysis, or evolutionary studies.
- bio-alignment-pairwisePerform pairwise sequence alignment using Biopython Bio.Align.PairwiseAligner. Use when comparing two sequences, finding optimal alignments, scoring similarity, and identifying local or global matches between DNA, RNA, or protein sequences.
- bio-alignment-sortingSort alignment files by coordinate or read name using samtools and pysam. Use when preparing BAM files for indexing, variant calling, or paired-end analysis.