Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions gui/src/client/src/components/MotifName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import React from "react";
import Box from "@mui/material/Box";
import { isLinkToken } from "../features/reconstruction/types";

// Renders a monomer name like "A2^R" or "C^E2", superscripting the trailing stereo marker.
// The link token (joining two merged primary sequence paths, see LINK_TOKEN) isn't a real
// building block -- render it as a muted glyph instead of a name, everywhere a monomer
// name would otherwise be rendered (sequence chips, alignment grid cells, ...).
// Stereo markers mxn.yml appends after "^": R/S (PK alpha/beta carbons), E/Z (PK
// alkene geometry), L/D (NRPS amino acid alpha carbons, e.g. "alanine^L").
const STEREO_MARKER = /^\^[A-Za-z]+$/;

// Renders a monomer name like "A2^R" or "C^E2" or "alanine^L", superscripting the
// trailing stereo marker(s). The link token (joining two merged primary sequence
// paths, see LINK_TOKEN) isn't a real building block -- render it as a muted glyph
// instead of a name, everywhere a monomer name would otherwise be rendered (sequence
// chips, alignment grid cells, ...).
export function MotifName({ name }: { name: string }) {
if (isLinkToken(name)) {
return (
Expand All @@ -15,12 +20,12 @@ export function MotifName({ name }: { name: string }) {
);
}

const parts = name.split(/(\^[SREZ])/g);
const parts = name.split(/(\^[A-Za-z]+)/g);

return (
<>
{parts.map((part, i) => {
if (part === "^S" || part === "^R" || part === "^E" || part === "^Z") {
if (STEREO_MARKER.test(part)) {
return (
<Box
key={i}
Expand Down
15 changes: 9 additions & 6 deletions gui/src/client/src/components/workspace/alignmentSvgExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,23 @@ function escapeXml(value: string): string {
.replace(/'/g, "&apos;");
}

// Splits a name like "A2^R" or "C^E2" into plain/superscript runs, matching MotifName's convention.
// The link token renders as the same muted glyph MotifName uses instead of its literal text.
// Stereo markers mxn.yml appends after "^": R/S (PK alpha/beta carbons), E/Z (PK
// alkene geometry), L/D (NRPS amino acid alpha carbons, e.g. "alanine^L").
const STEREO_MARKER = /^\^[A-Za-z]+$/;

// Splits a name like "A2^R" or "C^E2" or "alanine^L" into plain/superscript runs,
// matching MotifName's convention. The link token renders as the same muted glyph
// MotifName uses instead of its literal text.
function splitStereoMarkers(name: string): { text: string; sup: boolean }[] {
if (name === LINK_TOKEN) {
return [{ text: "⋮", sup: false }];
}

return name
.split(/(\^[SREZ])/g)
.split(/(\^[A-Za-z]+)/g)
.filter((part) => part !== "")
.map((part) =>
part === "^S" || part === "^R" || part === "^E" || part === "^Z"
? { text: part.slice(1), sup: true }
: { text: part, sup: false }
STEREO_MARKER.test(part) ? { text: part.slice(1), sup: true } : { text: part, sup: false }
);
}

Expand Down
Loading
Loading