# 12 Exports and Graphs

## Quick Answer
EVd3x exports both data tables and graph artifacts. Use the full analysis ZIP for statistics and reproducibility, then use per-graph PNG/SVG exports for figures. Interactive views may be capped for speed, but full exports preserve comprehensive datasets where available.

## What this does
Defines how each graph is computed, what it encodes, and how to export both the plotted view and underlying tabular data.

## Inputs
- API payloads from node, pathway, communication, disease, LR, and specificity modules
- Active filters (source, p-value cutoff, direction, detail cap, selected cells)
- Graph registry keys in frontend (`graphRegistry`)

## Outputs
- Full analysis CSV ZIP (`Export Full Analysis Bundle`)
- Graph image ZIP (`Export Graphs Bundle`)
- Per-graph popup viewer with fit/reset, drag/pan, PNG/SVG download
- Right-panel overlays (collapsible legend and PPI tree) for graph-first interpretation

## How calculated
Graphs render from analysis payloads and stateful filters. SVG charts are serialized from DOM (`svg`) and Cytoscape graphs are exported via Cytoscape image methods. For dense views, UI may apply caps; manifest metadata records truncation and limits.

## What to download
Minimum manuscript package:
- `evd3x_export_<query>_<timestamp>.zip`
- `evd3x_graphs_<query>_<timestamp>.zip`
- `99_meta/export_manifest.csv`
- `99_meta/export_warnings.csv` when present

## Known limits
- Very dense networks can reduce readability in-browser; use viewer pan/fit and download full-size SVG.
- Pathway grouped bars can be long; viewer supports vertical scroll for full content.
- UI detail caps can differ from full exported row counts by design.

## Graph-by-Graph Reference

### 1) Main Network (`network_main`)
- Answers: Which molecules are linked in the active query context?
- Inputs: Network nodes/edges from `/api/pathway` and detail expansion events.
- Encoding:
- Node color/shape by molecule type (`miRNA`, `Gene`, `Protein`)
- Edge direction reflects regulatory direction where available
- Interaction controls: pan/fit in analysis and popup viewer; PNG/SVG export.
- Pitfalls: Visual centrality is layout-dependent and is not a statistical centrality score.
- Related exports: `01_network/graph_nodes_full.csv`, `01_network/graph_edges_full.csv`.

### 1b) Right-Panel PPI Tree (`ppi_tree_panel`)
- Answers: Which one-hop protein partners are most relevant for the selected protein?
- Inputs: `/api/ppi_network` rows for selected protein, plus active UI threshold/search/cap.
- Encoding:
- Row label: partner protein
- Badge: `combined_score`
- Mini badges: selected evidence channels (`experimental`, `database`, `textmining`) when non-zero
- Controls:
- collapsed by default
- in-panel `Show On Graph` ON/OFF toggle with status badge
- `Clear Overlay` action to remove projected PPI-only nodes/edges
- `Show 20` reset and `Show +10` progressive reveal
- threshold chips (`700`, `800`, `900`)
- search filter for partner labels
- click row to focus node in graph; if missing and overlay is ON, EVd3x projects and focuses it
- Pitfalls:
- one-hop only by design for readability
- view may be capped while full table remains exportable
- overlay projection is intentionally capped for readability and performance
- Related exports:
- `09_ppi_analysis/ppi_tree_full.csv`
- `09_ppi_analysis/ppi_tree_view.csv`

### 2) Node EV Evidence Sources (`node_ev_sources`)
- Answers: Which EV evidence databases support the selected node?
- Inputs: Node `ev_evidence` rows, grouped by `Source_Database`.
- Encoding:
- X-axis: source database
- Y-axis: evidence row count
- Controls: popup viewer and PNG/SVG download.
- Pitfalls: evidence row count is not equivalent to unique study count without publication-level collapse.
- Related exports: `02_node_details/node_ev_evidence.csv`.

### 3) Target Confidence Distribution (`node_target_confidence`)
- Answers: How strong are miRNA-target confidences for the selected miRNA?
- Inputs: node-level `graph_elements` with target edges and `Confidence_Score`.
- Encoding:
- X-axis: target rank/bin (implementation dependent)
- Y-axis: confidence score
- Controls: popup viewer and PNG/SVG download.
- Pitfalls: scores are integrated confidence values; compare within the same query context.
- Related exports: `01_network/graph_edges_full.csv`, `07_pathway_analysis/pathways_full.csv`.

### 4) Cell Communication Heatmap (`cellcomm_heatmap`)
- Answers: Which source-target cell pairs show strongest communication support?
- Inputs: `/api/cell_communication_v2` heatmap matrix and selected cell sets.
- Encoding:
- X-axis: target cell
- Y-axis: source cell
- Color: communication score
- Controls: click cell to open detailed interaction table; popup export.
- Pitfalls: displayed detail interactions may be capped; inspect manifest + full export for totals.
- Related exports:
- `05_cell_communication/heatmap_matrix_full.csv`
- `05_cell_communication/interactions_full.csv`
- `05_cell_communication/interactions_selected_pair_view.csv`

### 5) L-R Bipartite (`lr_bipartite`)
- Answers: How do query genes map onto ligand/receptor partner genes?
- Inputs: `/api/ligand_receptor_analysis` result tables.
- Encoding:
- Left partition: query molecules with LR role
- Right partition: partner molecules
- Link: ligand->receptor relation
- Controls: popup viewer, drag/pan, fit/reset, PNG/SVG export.
- Pitfalls: dense systems can exceed label readability; increase focus using filters and exports.
- Related exports: `06_lr_analysis/query_as_ligands.csv`, `06_lr_analysis/query_as_receptors.csv`.

### 6) Pathway Grouped Bars (`pathway_bars`)
- Answers: Which pathways are most enriched within each pathway category?
- Inputs: filtered pathway enrichment results from `/api/pathway_enrichment`.
- Encoding:
- Group: pathway category
- Bars: pathways within category
- Value: enrichment signal (rank/statistic as rendered)
- Controls: full-content viewer with vertical scrolling, PNG/SVG export.
- Pitfalls: this chart follows active filters (source and p-value); compare only within same filter state.
- Related exports: `07_pathway_analysis/pathways_filtered_view.csv`, `07_pathway_analysis/pathways_full.csv`.

### 7) Disease Treemap (`disease_treemap`)
- Answers: Which disease groups dominate evidence for the current query/system?
- Inputs: grouped disease associations keyed by `Disease_ID`.
- Encoding:
- Rectangle size: relative evidence count/weight
- Rectangle color: disease category group
- Controls: popup viewer and image export.
- Pitfalls: category names are display-normalized; canonical key remains `Disease_ID`.
- Related exports:
- `08_disease_analysis/disease_bubble_summary_full.csv`
- `08_disease_analysis/disease_associations_full.csv`
- `08_disease_analysis/disease_associations_filtered_view.csv`

### 8) Cell Specificity Lollipop (`cellspec_lollipop`)
- Answers: Which cell types rank highest for the query set?
- Inputs: `/api/cell_specificity` ranked table.
- Encoding:
- X-axis: specificity score
- Y-axis: cell type (top-ranked)
- Controls: viewer export and table cross-check.
- Pitfalls: rank stability depends on query composition and source coverage.
- Related exports: `04_cell_specificity/cell_specificity_ranking_full.csv`.

### 9) Cell Specificity by System (`cellspec_system`)
- Answers: Which organ/system groups contribute most to specificity signal?
- Inputs: aggregated cell specificity output by system labels.
- Encoding:
- X-axis: system
- Y-axis: aggregate score/coverage
- Controls: viewer export.
- Pitfalls: systems are curated grouping labels, not independent biological ontologies.
- Related exports: `04_cell_specificity/cell_specificity_selected_cells.csv`.

## Figure Mode (Phase 6)

EVd3x includes a **Figure Mode** toggle in the top header bar (camera icon, labelled "Figure").

When Figure Mode is ON:
- A metadata bar appears below the header showing current query, mode, direction, Top-N, active lens filters, selected cells, and communication scoring context.
- The **Copy Methods Snippet** button generates a structured text block with all active filter settings, database credits, and scoring parameters, ready to paste into figure legends or methods sections.
- Non-essential chrome is reduced for cleaner figure captures.
- Graph legend and export controls are more prominent.

Figure Mode does **not** change any scientific calculations. It is a presentation/export overlay only.

## Graph Viewer Export Notes (Phase 6)

When opening any graph in the viewer, a context note is shown above the plot with:
- Current query and mode
- Active p-value cutoff (for pathway views)
- Truncation warning if cell communication view was capped

**Export format guidance:**
- **SVG**: recommended for publication because it is vector, scalable, and editable in Illustrator or Inkscape.
- **PNG**: quick preview and slide use; resolution depends on screen density.

Always use **Fit to View** before exporting to ensure no content is clipped.

## Export bundle contents (Phase 6)

The full analysis ZIP now includes:
- `00_metadata/session_metadata.csv`: query, mode, direction, Top-N, timestamp, app version.
- `00_metadata/figure_settings.csv`: snapshot of all active lens filters at export time, including pathway p-value, sources, link cap, keyword, disease filters, selected cells, communication scoring, and PPI settings.
- `99_meta/figure_settings` in manifest: same settings in manifest row format.
- `99_meta/processing_notes`: backend processing details such as canonicalization, grouping keys, and motif rule version.

## Canonical Demo Workflow (Manuscript Figures)

Use these query sets for reproducible manuscript figures:

**Figure 1: Alzheimer natural-language entry:**
- Query: `early onset Alzheimer's disease with behavioral disturbance`
- Mode: disease-first natural-language route
- Visible first-pass state: PSEN1 mRNA, PSEN1 protein, hsa-miR-4496, hsa-miR-107, hsa-miR-4677-3p
- Note: the 25 molecule value is an interactive processing guard, not a biological target.

**Figure 2: PSEN1 selected-node evidence:**
- Selected node: `PSEN1 protein`
- Surfaces: main graph, node details, EV evidence, EV-TRACK-linked publication context, localization, PPI neighborhood
- Note: EV evidence rows are reported detections, not functional transfer claims.

**Figure 3: Alzheimer disease convergence:**
- Query state: PSEN1-centered Alzheimer analysis state
- Surfaces: disease categories, ranked disease groups, selected disease evidence rows
- Note: report disease rows as association evidence, not diagnosis.

**Figure 4: Pathway analyses:**
- Query state: direct seeds plus expanded target and network-neighbor genes
- Surfaces: pathway category map and pathway detail table
- Filters: hypergeometric `p <= 0.05`, BH-FDR `q <= 0.10`; record source resources and link cap.

**Figure 5: Cell specificity + communication + LR:**
- Query state: Alzheimer analysis state
- Surfaces: cell specificity ranking, nervous-system focus, oligodendrocyte to astrocyte communication, PSEN1-NOTCH examples
- Note: record selected cells and communication relevance formula.

**Figure 6: LR, miRNA-target, and PPI bridges:**
- Selected interaction: PSEN1-centered LR/PPI bridge state, including PSEN1 to CTNNB1
- Surfaces: LR arcs, direct miRNA-target overlap, shared target bridges, high-confidence STRING neighborhood
- Note: record miRNA bridge class, support count, mean/max confidence, and PPI threshold `combined_score >= 700`.

## Processing transparency checks
Before interpretation or publication:
1. Confirm if view is truncated (`total_rows` vs `returned_rows`, manifest notes).
2. Use Figure Mode → Copy Methods Snippet to capture all active filter settings.
3. Check `00_metadata/figure_settings.csv` to verify what was active at export time.
4. Use CSV files for quantitative analysis; treat charts as visual summaries.
5. Include source provenance fields (`Source_Database`, `Pathway_Source`, `Source`) in downstream analysis.
6. For right-panel PPI interpretation, report active threshold and view cap from export manifest notes.
7. SVG exports are the recommended archival format for all publication figures.
