File size: 1,723 Bytes
dd079af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
 * Transition fidelity labels, binned from structural similarity
 * (see the pipeline's step 10b):
 *   sim ≥ 0.95 identical · 0.70–0.95 low · 0.50–0.70 medium · ≤ 0.50 high
 * "Fidelity" grows with the size of the conformational change.
 */
export const FIDELITY_ORDER = ['identical', 'low', 'medium', 'high'] as const;

export const FIDELITY_INFO: Record<string, { label: string; range: string; blurb: string }> = {
  identical: { label: 'Identical', range: 'similarity ≥ 0.95', blurb: 'Same conformation' },
  low: { label: 'Low', range: '0.70 – 0.95', blurb: 'Subtle rearrangement' },
  medium: { label: 'Medium', range: '0.50 – 0.70', blurb: 'Clear conformational change' },
  high: { label: 'High', range: 'similarity ≤ 0.50', blurb: 'Large-scale transition' },
  NA: { label: 'N/A', range: 'not computable', blurb: 'Similarity unavailable' },
};

export function fidelityKey(f: string | null | undefined): string {
  if (!f || f === '<NA>' || f === 'NA') return 'NA';
  return f in FIDELITY_INFO ? f : 'NA';
}

export function fidelityColor(f: string | null | undefined): string {
  return `var(--fid-${fidelityKey(f) === 'NA' ? 'na' : fidelityKey(f)})`;
}

export function fidelityRank(f: string | null | undefined): number {
  const i = (FIDELITY_ORDER as readonly string[]).indexOf(fidelityKey(f));
  return i === -1 ? -1 : i;
}

/** Heatmap color for a similarity in [0, 1] (darker = more similar). */
export function similarityColor(sim: number | null | undefined): string {
  if (sim == null || !Number.isFinite(sim)) return 'var(--surface-3)';
  const steps = [0.5, 0.7, 0.85, 0.95, 0.98];
  const idx = steps.findIndex((s) => sim < s);
  return `var(--seq-${idx === -1 ? 5 : idx})`;
}