/** 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 —; return ( label(m.pos, m.comp, sequence)).join(', ')}` : undefined} > {list.slice(0, max).map((m) => ( {label(m.pos, m.comp, sequence)} ))} {list.length > max && +{list.length - max}} {!list.length && none} {lost.length > 0 && −{lost.length}} ); } /** 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 (