Spaces:
Running
Running
feat: add PNG/TSV/JSON/CSV/FASTA export to all 8 tool components
Browse files- Shared export utility (export-utils.ts): downloadTsv, downloadJson, copyText, exportSvgPng
- DomainArchitecture: Export PNG (SVG canvas), Export TSV (domain table)
- PhyloTreeViewer: Export PNG
- ConservationTrack: Export PNG
- StructureComparison: Export PNG (TM-score bars), Export TSV (metrics)
- UniProt page: Export JSON, Export CSV (header fields)
- PrimerDesigner: Export TSV (all primer pairs)
- PathwayEnrichment: Copy links, Export TSV (pathway table)
- BlastPanel: Export CSV (hit table), Export FASTA (sequences)
- bioai-platform/frontend/src/app/(dashboard)/analyze/uniprot/page.tsx +34 -12
- bioai-platform/frontend/src/components/alignment/ConservationTrack.tsx +6 -1
- bioai-platform/frontend/src/components/domains/DomainArchitecture.tsx +14 -3
- bioai-platform/frontend/src/components/phylo/PhyloTreeViewer.tsx +9 -3
- bioai-platform/frontend/src/components/primers/PrimerDesigner.tsx +22 -12
- bioai-platform/frontend/src/components/results/BlastPanel.tsx +20 -1
- bioai-platform/frontend/src/components/results/PathwayEnrichment.tsx +20 -4
- bioai-platform/frontend/src/components/structure/StructureComparison.tsx +14 -3
- bioai-platform/frontend/src/lib/export-utils.ts +38 -0
bioai-platform/frontend/src/app/(dashboard)/analyze/uniprot/page.tsx
CHANGED
|
@@ -3,11 +3,12 @@
|
|
| 3 |
import { useState } from 'react';
|
| 4 |
import { useRouter } from 'next/navigation';
|
| 5 |
import { motion } from 'framer-motion';
|
| 6 |
-
import { Search, ArrowLeft, LoaderCircle, Globe, Dna, Beaker, ChevronRight, ExternalLink, BookOpen } from 'lucide-react';
|
| 7 |
import { fadeUp } from '@/lib/animations';
|
| 8 |
import { searchUniprot, getUniprotDetail } from '@/lib/api';
|
| 9 |
import { extractErrorMessage } from '@/lib/errors';
|
| 10 |
import type { UniprotSummary } from '@/types/pipeline';
|
|
|
|
| 11 |
|
| 12 |
type SearchResult = {
|
| 13 |
accession: string;
|
|
@@ -270,17 +271,38 @@ export default function UniprotLookupPage() {
|
|
| 270 |
</div>
|
| 271 |
)}
|
| 272 |
|
| 273 |
-
<div className="px-6 py-4 flex items-center justify-between">
|
| 274 |
-
<
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
<button
|
| 285 |
onClick={() => handleSendToBlast(detail.accession, detail.sequence)}
|
| 286 |
className="btn-primary py-2 px-4 text-sm flex items-center gap-2"
|
|
|
|
| 3 |
import { useState } from 'react';
|
| 4 |
import { useRouter } from 'next/navigation';
|
| 5 |
import { motion } from 'framer-motion';
|
| 6 |
+
import { Search, ArrowLeft, LoaderCircle, Globe, Dna, Beaker, ChevronRight, ExternalLink, BookOpen, Download } from 'lucide-react';
|
| 7 |
import { fadeUp } from '@/lib/animations';
|
| 8 |
import { searchUniprot, getUniprotDetail } from '@/lib/api';
|
| 9 |
import { extractErrorMessage } from '@/lib/errors';
|
| 10 |
import type { UniprotSummary } from '@/types/pipeline';
|
| 11 |
+
import { downloadJson, downloadTsv } from '@/lib/export-utils';
|
| 12 |
|
| 13 |
type SearchResult = {
|
| 14 |
accession: string;
|
|
|
|
| 271 |
</div>
|
| 272 |
)}
|
| 273 |
|
| 274 |
+
<div className="px-6 py-4 flex items-center justify-between flex-wrap gap-2">
|
| 275 |
+
<div className="flex items-center gap-2">
|
| 276 |
+
<a
|
| 277 |
+
href={`https://www.uniprot.org/uniprotkb/${detail.accession}`}
|
| 278 |
+
target="_blank"
|
| 279 |
+
rel="noopener noreferrer"
|
| 280 |
+
className="text-xs text-text-muted hover:text-accent-cyan transition flex items-center gap-1"
|
| 281 |
+
>
|
| 282 |
+
<BookOpen className="w-3 h-3" />
|
| 283 |
+
View on UniProt
|
| 284 |
+
<ExternalLink className="w-3 h-3" />
|
| 285 |
+
</a>
|
| 286 |
+
<button onClick={() => downloadJson(detail, `uniprot-${detail.accession}.json`)}
|
| 287 |
+
className="btn-ghost text-xs px-2 py-1 flex items-center gap-1">
|
| 288 |
+
<Download className="w-3 h-3" /> JSON
|
| 289 |
+
</button>
|
| 290 |
+
<button onClick={() => {
|
| 291 |
+
const headers = ["Accession", "Gene", "Organism", "Length", "Function", "Keywords", "Subcellular Location"];
|
| 292 |
+
const rows = [[
|
| 293 |
+
detail.accession,
|
| 294 |
+
detail.gene_names.join("; "),
|
| 295 |
+
detail.organism,
|
| 296 |
+
String(detail.sequence_length),
|
| 297 |
+
detail.functions.join("; ").replace(/"/g, '""'),
|
| 298 |
+
detail.keywords.join("; "),
|
| 299 |
+
detail.subcellular_locations.join("; "),
|
| 300 |
+
]];
|
| 301 |
+
downloadTsv(headers, rows, `uniprot-${detail.accession}.tsv`);
|
| 302 |
+
}} className="btn-ghost text-xs px-2 py-1 flex items-center gap-1">
|
| 303 |
+
<Download className="w-3 h-3" /> CSV
|
| 304 |
+
</button>
|
| 305 |
+
</div>
|
| 306 |
<button
|
| 307 |
onClick={() => handleSendToBlast(detail.accession, detail.sequence)}
|
| 308 |
className="btn-primary py-2 px-4 text-sm flex items-center gap-2"
|
bioai-platform/frontend/src/components/alignment/ConservationTrack.tsx
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
"use client";
|
|
|
|
|
|
|
| 2 |
|
| 3 |
const GROUPS: Record<string, string[]> = {
|
| 4 |
polar_positive: ["K", "R", "H"],
|
|
@@ -35,6 +37,7 @@ interface Props {
|
|
| 35 |
}
|
| 36 |
|
| 37 |
export function ConservationTrack({ alignedSeqs }: Props) {
|
|
|
|
| 38 |
if (!alignedSeqs.length) return null;
|
| 39 |
const L = alignedSeqs[0].length;
|
| 40 |
|
|
@@ -57,6 +60,8 @@ export function ConservationTrack({ alignedSeqs }: Props) {
|
|
| 57 |
<div className="space-y-3">
|
| 58 |
<div className="flex items-center justify-between">
|
| 59 |
<h3 className="text-text-primary font-semibold">Conservation Analysis</h3>
|
|
|
|
|
|
|
| 60 |
<div className="flex gap-4 text-xs text-text-muted">
|
| 61 |
<span>Avg: <span className="text-text-secondary">{avgConservation}%</span></span>
|
| 62 |
<span>Fully conserved: <span className="text-accent-cyan">{highlyConserved} positions</span></span>
|
|
@@ -64,7 +69,7 @@ export function ConservationTrack({ alignedSeqs }: Props) {
|
|
| 64 |
</div>
|
| 65 |
|
| 66 |
<div className="bg-surface-1 rounded-xl p-3 border border-glass-border overflow-x-auto">
|
| 67 |
-
<svg viewBox={`0 0 ${L * 4} 60`} className="w-full" style={{ minWidth: L * 4 }}>
|
| 68 |
{scores.map((s, i) => (
|
| 69 |
<rect key={i} x={i * 4} y={60 - s * 55} width={3} height={s * 55}
|
| 70 |
fill={scoreColor(s)} rx={1} />
|
|
|
|
| 1 |
"use client";
|
| 2 |
+
import { useRef } from "react";
|
| 3 |
+
import { exportSvgPng } from "@/lib/export-utils";
|
| 4 |
|
| 5 |
const GROUPS: Record<string, string[]> = {
|
| 6 |
polar_positive: ["K", "R", "H"],
|
|
|
|
| 37 |
}
|
| 38 |
|
| 39 |
export function ConservationTrack({ alignedSeqs }: Props) {
|
| 40 |
+
const svgRef = useRef<SVGSVGElement>(null);
|
| 41 |
if (!alignedSeqs.length) return null;
|
| 42 |
const L = alignedSeqs[0].length;
|
| 43 |
|
|
|
|
| 60 |
<div className="space-y-3">
|
| 61 |
<div className="flex items-center justify-between">
|
| 62 |
<h3 className="text-text-primary font-semibold">Conservation Analysis</h3>
|
| 63 |
+
<button onClick={() => exportSvgPng(svgRef.current, "conservation.png")}
|
| 64 |
+
className="btn-ghost text-xs px-2 py-1">Export PNG</button>
|
| 65 |
<div className="flex gap-4 text-xs text-text-muted">
|
| 66 |
<span>Avg: <span className="text-text-secondary">{avgConservation}%</span></span>
|
| 67 |
<span>Fully conserved: <span className="text-accent-cyan">{highlyConserved} positions</span></span>
|
|
|
|
| 69 |
</div>
|
| 70 |
|
| 71 |
<div className="bg-surface-1 rounded-xl p-3 border border-glass-border overflow-x-auto">
|
| 72 |
+
<svg ref={svgRef} viewBox={`0 0 ${L * 4} 60`} className="w-full" style={{ minWidth: L * 4 }}>
|
| 73 |
{scores.map((s, i) => (
|
| 74 |
<rect key={i} x={i * 4} y={60 - s * 55} width={3} height={s * 55}
|
| 75 |
fill={scoreColor(s)} rx={1} />
|
bioai-platform/frontend/src/components/domains/DomainArchitecture.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
"use client";
|
| 2 |
-
import { useEffect, useState } from "react";
|
|
|
|
| 3 |
|
| 4 |
const DB_COLORS: Record<string, string> = {
|
| 5 |
PFAM: "#00F5D4",
|
|
@@ -18,6 +19,7 @@ export function DomainArchitecture({ accession }: { accession: string }) {
|
|
| 18 |
const [loading, setLoading] = useState(true);
|
| 19 |
const [tooltip, setTooltip] = useState<{ domain: Domain; x: number; y: number } | null>(null);
|
| 20 |
const [error, setError] = useState<string | null>(null);
|
|
|
|
| 21 |
|
| 22 |
useEffect(() => {
|
| 23 |
setLoading(true);
|
|
@@ -43,7 +45,16 @@ export function DomainArchitecture({ accession }: { accession: string }) {
|
|
| 43 |
<div className="space-y-4 relative">
|
| 44 |
<div className="flex items-center justify-between">
|
| 45 |
<h3 className="text-text-primary font-semibold">Domain Architecture</h3>
|
| 46 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
</div>
|
| 48 |
|
| 49 |
<div className="flex flex-wrap gap-3">
|
|
@@ -56,7 +67,7 @@ export function DomainArchitecture({ accession }: { accession: string }) {
|
|
| 56 |
</div>
|
| 57 |
|
| 58 |
<div className="overflow-x-auto">
|
| 59 |
-
<svg viewBox={`0 0 ${W + 40} 70`} className="w-full min-w-[400px]">
|
| 60 |
<rect x={20} y={30} width={W} height={8} rx={4} fill="rgba(255,255,255,0.08)" />
|
| 61 |
|
| 62 |
{[0, 0.25, 0.5, 0.75, 1].map(t => (
|
|
|
|
| 1 |
"use client";
|
| 2 |
+
import { useEffect, useState, useRef } from "react";
|
| 3 |
+
import { downloadTsv, exportSvgPng } from "@/lib/export-utils";
|
| 4 |
|
| 5 |
const DB_COLORS: Record<string, string> = {
|
| 6 |
PFAM: "#00F5D4",
|
|
|
|
| 19 |
const [loading, setLoading] = useState(true);
|
| 20 |
const [tooltip, setTooltip] = useState<{ domain: Domain; x: number; y: number } | null>(null);
|
| 21 |
const [error, setError] = useState<string | null>(null);
|
| 22 |
+
const svgRef = useRef<SVGSVGElement>(null);
|
| 23 |
|
| 24 |
useEffect(() => {
|
| 25 |
setLoading(true);
|
|
|
|
| 45 |
<div className="space-y-4 relative">
|
| 46 |
<div className="flex items-center justify-between">
|
| 47 |
<h3 className="text-text-primary font-semibold">Domain Architecture</h3>
|
| 48 |
+
<div className="flex items-center gap-2">
|
| 49 |
+
<button onClick={() => exportSvgPng(svgRef.current, `domains-${accession}.png`)}
|
| 50 |
+
className="btn-ghost text-xs px-2 py-1">Export PNG</button>
|
| 51 |
+
<button onClick={() => downloadTsv(
|
| 52 |
+
["Accession", "Name", "DB", "Start", "End"],
|
| 53 |
+
domains.map(d => [d.accession, d.name, d.source_db, String(d.start), String(d.end)]),
|
| 54 |
+
`domains-${accession}.tsv`
|
| 55 |
+
)} className="btn-ghost text-xs px-2 py-1">Export TSV</button>
|
| 56 |
+
<span className="text-text-muted text-xs">{seqLen} aa · {domains.length} annotations</span>
|
| 57 |
+
</div>
|
| 58 |
</div>
|
| 59 |
|
| 60 |
<div className="flex flex-wrap gap-3">
|
|
|
|
| 67 |
</div>
|
| 68 |
|
| 69 |
<div className="overflow-x-auto">
|
| 70 |
+
<svg ref={svgRef} viewBox={`0 0 ${W + 40} 70`} className="w-full min-w-[400px]">
|
| 71 |
<rect x={20} y={30} width={W} height={8} rx={4} fill="rgba(255,255,255,0.08)" />
|
| 72 |
|
| 73 |
{[0, 0.25, 0.5, 0.75, 1].map(t => (
|
bioai-platform/frontend/src/components/phylo/PhyloTreeViewer.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
"use client";
|
| 2 |
-
import { useEffect, useState } from "react";
|
|
|
|
| 3 |
|
| 4 |
type TreeNode = { name: string; length: number; children: TreeNode[] };
|
| 5 |
|
|
@@ -83,6 +84,7 @@ export function PhyloTreeViewer({ jobId, newick: propNewick }: { jobId?: string;
|
|
| 83 |
const [newick, setNewick] = useState<string | null>(propNewick ?? null);
|
| 84 |
const [loading, setLoading] = useState(!propNewick);
|
| 85 |
const [error, setError] = useState<string | null>(null);
|
|
|
|
| 86 |
|
| 87 |
useEffect(() => {
|
| 88 |
if (propNewick) { setNewick(propNewick); setLoading(false); return; }
|
|
@@ -104,9 +106,13 @@ export function PhyloTreeViewer({ jobId, newick: propNewick }: { jobId?: string;
|
|
| 104 |
|
| 105 |
return (
|
| 106 |
<div className="space-y-3">
|
| 107 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
<div className="glass-card overflow-hidden p-2">
|
| 109 |
-
<svg viewBox={`0 0 ${W} ${H}`} className="w-full">
|
| 110 |
{nodes.map((n, i) =>
|
| 111 |
n.children.map((child, j) => (
|
| 112 |
<g key={`${i}-${j}`}>
|
|
|
|
| 1 |
"use client";
|
| 2 |
+
import { useEffect, useState, useRef } from "react";
|
| 3 |
+
import { exportSvgPng } from "@/lib/export-utils";
|
| 4 |
|
| 5 |
type TreeNode = { name: string; length: number; children: TreeNode[] };
|
| 6 |
|
|
|
|
| 84 |
const [newick, setNewick] = useState<string | null>(propNewick ?? null);
|
| 85 |
const [loading, setLoading] = useState(!propNewick);
|
| 86 |
const [error, setError] = useState<string | null>(null);
|
| 87 |
+
const svgRef = useRef<SVGSVGElement>(null);
|
| 88 |
|
| 89 |
useEffect(() => {
|
| 90 |
if (propNewick) { setNewick(propNewick); setLoading(false); return; }
|
|
|
|
| 106 |
|
| 107 |
return (
|
| 108 |
<div className="space-y-3">
|
| 109 |
+
<div className="flex items-center justify-between">
|
| 110 |
+
<h3 className="text-text-primary font-semibold">Phylogenetic Tree</h3>
|
| 111 |
+
<button onClick={() => exportSvgPng(svgRef.current, "phylotree.png")}
|
| 112 |
+
className="btn-ghost text-xs px-2 py-1">Export PNG</button>
|
| 113 |
+
</div>
|
| 114 |
<div className="glass-card overflow-hidden p-2">
|
| 115 |
+
<svg ref={svgRef} viewBox={`0 0 ${W} ${H}`} className="w-full">
|
| 116 |
{nodes.map((n, i) =>
|
| 117 |
n.children.map((child, j) => (
|
| 118 |
<g key={`${i}-${j}`}>
|
bioai-platform/frontend/src/components/primers/PrimerDesigner.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
"use client";
|
| 2 |
import { useState } from "react";
|
| 3 |
-
import { LoaderCircle } from "lucide-react";
|
|
|
|
| 4 |
|
| 5 |
type PrimerPair = {
|
| 6 |
pair_index: number;
|
|
@@ -94,17 +95,26 @@ export function PrimerDesigner() {
|
|
| 94 |
|
| 95 |
{pairs.length > 0 && (
|
| 96 |
<div className="space-y-4">
|
| 97 |
-
<div className="flex
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
</div>
|
| 109 |
|
| 110 |
{selectedPair !== null && (() => {
|
|
|
|
| 1 |
"use client";
|
| 2 |
import { useState } from "react";
|
| 3 |
+
import { LoaderCircle, Download } from "lucide-react";
|
| 4 |
+
import { downloadTsv } from "@/lib/export-utils";
|
| 5 |
|
| 6 |
type PrimerPair = {
|
| 7 |
pair_index: number;
|
|
|
|
| 95 |
|
| 96 |
{pairs.length > 0 && (
|
| 97 |
<div className="space-y-4">
|
| 98 |
+
<div className="flex items-center justify-between">
|
| 99 |
+
<div className="flex gap-2 flex-wrap">
|
| 100 |
+
{pairs.map(p => (
|
| 101 |
+
<button key={p.pair_index} onClick={() => setSelectedPair(p.pair_index)}
|
| 102 |
+
className={`px-3 py-1 rounded-full text-xs border transition ${
|
| 103 |
+
selectedPair === p.pair_index
|
| 104 |
+
? "border-accent-cyan bg-accent-cyan/10 text-accent-cyan"
|
| 105 |
+
: "border-glass-border text-text-muted hover:border-white/20"
|
| 106 |
+
}`}>
|
| 107 |
+
Pair {p.pair_index + 1} · {p.product_size}bp
|
| 108 |
+
</button>
|
| 109 |
+
))}
|
| 110 |
+
</div>
|
| 111 |
+
<button onClick={() => downloadTsv(
|
| 112 |
+
["Pair", "Forward seq", "Fwd Tm", "Fwd GC%", "Fwd Pos", "Fwd Len", "Reverse seq", "Rev Tm", "Rev GC%", "Rev Pos", "Rev Len", "Product size", "Penalty"],
|
| 113 |
+
pairs.map(p => [String(p.pair_index + 1), p.left_seq, p.left_tm.toFixed(1), p.left_gc.toFixed(1), String(p.left_pos), String(p.left_len), p.right_seq, p.right_tm.toFixed(1), p.right_gc.toFixed(1), String(p.right_pos), String(p.right_len), String(p.product_size), p.penalty.toFixed(3)]),
|
| 114 |
+
"primers.tsv"
|
| 115 |
+
)} className="btn-ghost text-xs px-2 py-1 flex items-center gap-1">
|
| 116 |
+
<Download className="w-3 h-3" /> Export TSV
|
| 117 |
+
</button>
|
| 118 |
</div>
|
| 119 |
|
| 120 |
{selectedPair !== null && (() => {
|
bioai-platform/frontend/src/components/results/BlastPanel.tsx
CHANGED
|
@@ -2,9 +2,10 @@
|
|
| 2 |
|
| 3 |
import { useState } from 'react';
|
| 4 |
import { motion } from 'framer-motion';
|
| 5 |
-
import { ChevronDown, ChevronUp, ExternalLink } from 'lucide-react';
|
| 6 |
import type { BlastHitSummary } from '@/types/pipeline';
|
| 7 |
import { AlignmentView } from './AlignmentView';
|
|
|
|
| 8 |
import { fadeUp, stagger, cardHover } from '@/lib/animations';
|
| 9 |
|
| 10 |
interface BlastPanelProps {
|
|
@@ -41,6 +42,24 @@ export function BlastPanel({ hits, count, source }: BlastPanelProps) {
|
|
| 41 |
BLAST Hits
|
| 42 |
<span className="text-xs text-text-muted ml-2 font-normal">({count} found{source ? ` via ${source}` : ''})</span>
|
| 43 |
</h2>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
</div>
|
| 45 |
<motion.div variants={stagger} className="divide-y divide-glass-border">
|
| 46 |
{safeHits.length === 0 ? (
|
|
|
|
| 2 |
|
| 3 |
import { useState } from 'react';
|
| 4 |
import { motion } from 'framer-motion';
|
| 5 |
+
import { ChevronDown, ChevronUp, ExternalLink, Download } from 'lucide-react';
|
| 6 |
import type { BlastHitSummary } from '@/types/pipeline';
|
| 7 |
import { AlignmentView } from './AlignmentView';
|
| 8 |
+
import { downloadTsv } from '@/lib/export-utils';
|
| 9 |
import { fadeUp, stagger, cardHover } from '@/lib/animations';
|
| 10 |
|
| 11 |
interface BlastPanelProps {
|
|
|
|
| 42 |
BLAST Hits
|
| 43 |
<span className="text-xs text-text-muted ml-2 font-normal">({count} found{source ? ` via ${source}` : ''})</span>
|
| 44 |
</h2>
|
| 45 |
+
<div className="flex items-center gap-2">
|
| 46 |
+
<button onClick={() => downloadTsv(
|
| 47 |
+
["Accession", "Description", "E-value", "Identity%", "Score", "Confidence"],
|
| 48 |
+
safeHits.map(h => [h.accession, h.description, h.evalue_raw || String(h.evalue), String(h.identity_pct), String(h.bit_score), confidenceBand(h.evalue).label]),
|
| 49 |
+
"blast-hits.tsv"
|
| 50 |
+
)} className="btn-ghost text-xs px-2 py-1 flex items-center gap-1">
|
| 51 |
+
<Download className="w-3 h-3" /> Export CSV
|
| 52 |
+
</button>
|
| 53 |
+
<button onClick={() => {
|
| 54 |
+
const fasta = safeHits.map(h => `>${h.accession} ${h.description}\n${h.midline || ""}`).join("\n");
|
| 55 |
+
const a = document.createElement("a");
|
| 56 |
+
a.download = "blast-hits.fasta";
|
| 57 |
+
a.href = "data:text/fasta;charset=utf-8," + encodeURIComponent(fasta);
|
| 58 |
+
a.click();
|
| 59 |
+
}} className="btn-ghost text-xs px-2 py-1 flex items-center gap-1">
|
| 60 |
+
<Download className="w-3 h-3" /> FASTA
|
| 61 |
+
</button>
|
| 62 |
+
</div>
|
| 63 |
</div>
|
| 64 |
<motion.div variants={stagger} className="divide-y divide-glass-border">
|
| 65 |
{safeHits.length === 0 ? (
|
bioai-platform/frontend/src/components/results/PathwayEnrichment.tsx
CHANGED
|
@@ -2,9 +2,10 @@
|
|
| 2 |
|
| 3 |
import { useState } from 'react';
|
| 4 |
import { motion, AnimatePresence } from 'framer-motion';
|
| 5 |
-
import { GitBranch, ChevronDown, ChevronRight, ExternalLink, AlertCircle } from 'lucide-react';
|
| 6 |
import { fadeUp } from '@/lib/animations';
|
| 7 |
import type { PathwayEnrichment as PathwayEnrichmentData } from '@/types/pipeline';
|
|
|
|
| 8 |
import PathwayDiagram from './PathwayDiagram';
|
| 9 |
|
| 10 |
interface Props {
|
|
@@ -18,9 +19,24 @@ export function PathwayEnrichment({ data }: Props) {
|
|
| 18 |
|
| 19 |
return (
|
| 20 |
<motion.div variants={fadeUp} initial="hidden" animate="show" className="glass-card p-5">
|
| 21 |
-
<div className="flex items-center
|
| 22 |
-
<
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
</div>
|
| 25 |
<p className="text-xs text-text-muted mb-4">
|
| 26 |
{data.pathways.length} enriched pathway{data.pathways.length !== 1 ? 's' : ''} found · Sorted by FDR
|
|
|
|
| 2 |
|
| 3 |
import { useState } from 'react';
|
| 4 |
import { motion, AnimatePresence } from 'framer-motion';
|
| 5 |
+
import { GitBranch, ChevronDown, ChevronRight, ExternalLink, AlertCircle, Download } from 'lucide-react';
|
| 6 |
import { fadeUp } from '@/lib/animations';
|
| 7 |
import type { PathwayEnrichment as PathwayEnrichmentData } from '@/types/pipeline';
|
| 8 |
+
import { downloadTsv, copyText } from '@/lib/export-utils';
|
| 9 |
import PathwayDiagram from './PathwayDiagram';
|
| 10 |
|
| 11 |
interface Props {
|
|
|
|
| 19 |
|
| 20 |
return (
|
| 21 |
<motion.div variants={fadeUp} initial="hidden" animate="show" className="glass-card p-5">
|
| 22 |
+
<div className="flex items-center justify-between mb-4">
|
| 23 |
+
<div className="flex items-center gap-2">
|
| 24 |
+
<GitBranch className="w-5 h-5 text-accent-cyan" />
|
| 25 |
+
<h3 className="text-lg font-semibold text-text-primary">Pathway Enrichment</h3>
|
| 26 |
+
</div>
|
| 27 |
+
<div className="flex items-center gap-2">
|
| 28 |
+
<button onClick={() => copyText(data.pathways.map(p => `https://reactome.org/content/detail/${p.stId}`).join("\n"))}
|
| 29 |
+
className="btn-ghost text-xs px-2 py-1 flex items-center gap-1">
|
| 30 |
+
<Download className="w-3 h-3" /> Copy links
|
| 31 |
+
</button>
|
| 32 |
+
<button onClick={() => downloadTsv(
|
| 33 |
+
["ID", "Name", "Species", "Found/Total", "FDR"],
|
| 34 |
+
data.pathways.map(p => [p.stId, p.name, p.species, `${p.entitiesFound}/${p.entitiesTotal}`, p.entitiesFDR.toExponential(2)]),
|
| 35 |
+
"pathways.tsv"
|
| 36 |
+
)} className="btn-ghost text-xs px-2 py-1 flex items-center gap-1">
|
| 37 |
+
<Download className="w-3 h-3" /> Export TSV
|
| 38 |
+
</button>
|
| 39 |
+
</div>
|
| 40 |
</div>
|
| 41 |
<p className="text-xs text-text-muted mb-4">
|
| 42 |
{data.pathways.length} enriched pathway{data.pathways.length !== 1 ? 's' : ''} found · Sorted by FDR
|
bioai-platform/frontend/src/components/structure/StructureComparison.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
"use client";
|
| 2 |
-
import { useEffect, useState } from "react";
|
|
|
|
| 3 |
|
| 4 |
type StructureMatch = {
|
| 5 |
pdb_id: string; chain: string; description: string;
|
|
@@ -10,6 +11,7 @@ export function StructureComparison({ pdbId, chain = "A" }: { pdbId: string; cha
|
|
| 10 |
const [matches, setMatches] = useState<StructureMatch[]>([]);
|
| 11 |
const [loading, setLoading] = useState(true);
|
| 12 |
const [error, setError] = useState<string | null>(null);
|
|
|
|
| 13 |
|
| 14 |
useEffect(() => {
|
| 15 |
fetch(`/api/backend/api/structure_analysis/compare/${pdbId}?chain=${chain}`)
|
|
@@ -26,10 +28,19 @@ export function StructureComparison({ pdbId, chain = "A" }: { pdbId: string; cha
|
|
| 26 |
<div className="space-y-4">
|
| 27 |
<div className="flex items-center justify-between">
|
| 28 |
<h3 className="text-text-primary font-semibold">Structural Homologs</h3>
|
| 29 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
</div>
|
| 31 |
|
| 32 |
-
<div className="space-y-1">
|
| 33 |
<div className="flex justify-between text-xs text-text-muted mb-2">
|
| 34 |
<span>TM-score (0→1)</span>
|
| 35 |
<span>TM > 0.5 = same fold</span>
|
|
|
|
| 1 |
"use client";
|
| 2 |
+
import { useEffect, useState, useRef } from "react";
|
| 3 |
+
import { downloadTsv, exportSvgPng } from "@/lib/export-utils";
|
| 4 |
|
| 5 |
type StructureMatch = {
|
| 6 |
pdb_id: string; chain: string; description: string;
|
|
|
|
| 11 |
const [matches, setMatches] = useState<StructureMatch[]>([]);
|
| 12 |
const [loading, setLoading] = useState(true);
|
| 13 |
const [error, setError] = useState<string | null>(null);
|
| 14 |
+
const svgRef = useRef<SVGSVGElement>(null);
|
| 15 |
|
| 16 |
useEffect(() => {
|
| 17 |
fetch(`/api/backend/api/structure_analysis/compare/${pdbId}?chain=${chain}`)
|
|
|
|
| 28 |
<div className="space-y-4">
|
| 29 |
<div className="flex items-center justify-between">
|
| 30 |
<h3 className="text-text-primary font-semibold">Structural Homologs</h3>
|
| 31 |
+
<div className="flex items-center gap-2">
|
| 32 |
+
<button onClick={() => exportSvgPng(svgRef.current, `compare-${pdbId}.png`)}
|
| 33 |
+
className="btn-ghost text-xs px-2 py-1">Export PNG</button>
|
| 34 |
+
<button onClick={() => downloadTsv(
|
| 35 |
+
["PDB", "Chain", "RMSD", "Seq ID%", "Aligned", "TM-score", "Description"],
|
| 36 |
+
matches.map(m => [m.pdb_id, m.chain, m.rmsd.toFixed(2), (m.seq_identity * 100).toFixed(1), String(m.aligned_length), m.tm_score.toFixed(3), m.description]),
|
| 37 |
+
`compare-${pdbId}.tsv`
|
| 38 |
+
)} className="btn-ghost text-xs px-2 py-1">Export TSV</button>
|
| 39 |
+
<span className="text-text-muted text-xs">{matches.length} hits · PDBeFold</span>
|
| 40 |
+
</div>
|
| 41 |
</div>
|
| 42 |
|
| 43 |
+
<div className="space-y-1" ref={svgRef as any}>
|
| 44 |
<div className="flex justify-between text-xs text-text-muted mb-2">
|
| 45 |
<span>TM-score (0→1)</span>
|
| 46 |
<span>TM > 0.5 = same fold</span>
|
bioai-platform/frontend/src/lib/export-utils.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export function downloadTsv(headers: string[], rows: string[][], filename: string) {
|
| 2 |
+
const tsv = [headers.join("\t"), ...rows.map(r => r.join("\t"))].join("\n");
|
| 3 |
+
const a = document.createElement("a");
|
| 4 |
+
a.download = filename;
|
| 5 |
+
a.href = "data:text/tab-separated-values;charset=utf-8," + encodeURIComponent(tsv);
|
| 6 |
+
a.click();
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
export function downloadJson(data: unknown, filename: string) {
|
| 10 |
+
const a = document.createElement("a");
|
| 11 |
+
a.download = filename;
|
| 12 |
+
a.href = "data:application/json;charset=utf-8," + encodeURIComponent(JSON.stringify(data, null, 2));
|
| 13 |
+
a.click();
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
export function copyText(text: string, done?: () => void) {
|
| 17 |
+
navigator.clipboard.writeText(text).then(done);
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
export function exportSvgPng(svgEl: SVGSVGElement | null, filename: string) {
|
| 21 |
+
if (!svgEl) return;
|
| 22 |
+
const svgStr = new XMLSerializer().serializeToString(svgEl);
|
| 23 |
+
const canvas = document.createElement("canvas");
|
| 24 |
+
const ctx = canvas.getContext("2d")!;
|
| 25 |
+
const img = new window.Image();
|
| 26 |
+
img.onload = () => {
|
| 27 |
+
canvas.width = img.width;
|
| 28 |
+
canvas.height = img.height;
|
| 29 |
+
ctx.fillStyle = "#04040A";
|
| 30 |
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
| 31 |
+
ctx.drawImage(img, 0, 0);
|
| 32 |
+
const a = document.createElement("a");
|
| 33 |
+
a.download = filename;
|
| 34 |
+
a.href = canvas.toDataURL("image/png");
|
| 35 |
+
a.click();
|
| 36 |
+
};
|
| 37 |
+
img.src = "data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(svgStr)));
|
| 38 |
+
}
|