File size: 2,450 Bytes
fe94734
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/** Modified residues (phosphorylation, methylation, …) of an observation. */

/** '197:TPO' or {pos, comp} -> label like 'T197 · TPO' using the canonical sequence letter. */
function label(pos: number, comp: string, sequence?: string) {
  const aa = sequence?.[pos - 1];
  return `${aa ?? ''}${pos} · ${comp}`;
}

function parse(items: string[] = []) {
  return items
    .map((s) => {
      const [p, comp] = s.split(':');
      return { pos: Number(p), comp, key: s };
    })
    .filter((m) => Number.isFinite(m.pos) && m.comp);
}

/** Chips for one chain; with `home`, sites missing there are marked gained and its extra sites counted as lost. */
export function ModChips({
  mods = [],
  sequence,
  home,
  max = 8,
}: {
  mods?: string[];
  sequence?: string;
  home?: string[];
  max?: number;
}) {
  const homeSet = home ? new Set(home) : null;
  const lost = home ? home.filter((k) => !mods.includes(k)) : [];
  const list = parse(mods);
  if (!list.length && !lost.length) return <span className="muted">—</span>;
  return (
    <span
      className="pchips pchips--stacked"
      title={lost.length ? `Modified in this chain but not here: ${parse(lost).map((m) => label(m.pos, m.comp, sequence)).join(', ')}` : undefined}
    >
      {list.slice(0, max).map((m) => (
        <span key={m.key} className={`pchip pchip--mod ${homeSet && !homeSet.has(m.key) ? 'is-gained' : ''}`}>
          {label(m.pos, m.comp, sequence)}
        </span>
      ))}
      {list.length > max && <span className="pchip pchip--more">+{list.length - max}</span>}
      {!list.length && <span className="muted small">none</span>}
      {lost.length > 0 && <span className="pchip pchip--lost">−{lost.length}</span>}
    </span>
  );
}

/** Inline list for the chain page: types, then every site. */
export function ModificationList({
  mods,
  types,
  sequence,
}: {
  mods: Array<{ pos: number; comp: string }>;
  types: string[];
  sequence: string;
}) {
  if (!mods.length) return null;
  return (
    <div className="mods">
      <span className="mods__head">
        Modified residues <span className="muted">({types.join(', ')})</span>
      </span>
      <span className="mods__list">
        {mods.map((m) => (
          <span key={`${m.pos}${m.comp}`} className="pchip pchip--mod" title={`SEQRES position ${m.pos}, residue ${m.comp}`}>
            {label(m.pos, m.comp, sequence)}
          </span>
        ))}
      </span>
    </div>
  );
}