diff --git a/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--2b33a-f-connection-between-Phosphate-and-RNA-to-SVG-2-chromium-linux.png b/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--2b33a-f-connection-between-Phosphate-and-RNA-to-SVG-2-chromium-linux.png index 6aa77ba2e1..1b2411c358 100644 Binary files a/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--2b33a-f-connection-between-Phosphate-and-RNA-to-SVG-2-chromium-linux.png and b/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--2b33a-f-connection-between-Phosphate-and-RNA-to-SVG-2-chromium-linux.png differ diff --git a/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--3c572-f-connection-between-Phosphate-and-RNA-to-SVG-1-chromium-linux.png b/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--3c572-f-connection-between-Phosphate-and-RNA-to-SVG-1-chromium-linux.png index 3d40c2670a..f5e32ceaa7 100644 Binary files a/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--3c572-f-connection-between-Phosphate-and-RNA-to-SVG-1-chromium-linux.png and b/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--3c572-f-connection-between-Phosphate-and-RNA-to-SVG-1-chromium-linux.png differ diff --git a/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--5a557-f-connection-between-Phosphate-and-RNA-to-SVG-2-chromium-linux.png b/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--5a557-f-connection-between-Phosphate-and-RNA-to-SVG-2-chromium-linux.png index 6aa77ba2e1..1b2411c358 100644 Binary files a/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--5a557-f-connection-between-Phosphate-and-RNA-to-SVG-2-chromium-linux.png and b/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--5a557-f-connection-between-Phosphate-and-RNA-to-SVG-2-chromium-linux.png differ diff --git a/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--64708-f-connection-between-Phosphate-and-RNA-to-SVG-1-chromium-linux.png b/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--64708-f-connection-between-Phosphate-and-RNA-to-SVG-1-chromium-linux.png index 3d40c2670a..f5e32ceaa7 100644 Binary files a/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--64708-f-connection-between-Phosphate-and-RNA-to-SVG-1-chromium-linux.png and b/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--64708-f-connection-between-Phosphate-and-RNA-to-SVG-1-chromium-linux.png differ diff --git a/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--ad04e-f-connection-between-Phosphate-and-RNA-to-SVG-2-chromium-linux.png b/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--ad04e-f-connection-between-Phosphate-and-RNA-to-SVG-2-chromium-linux.png index 6aa77ba2e1..1b2411c358 100644 Binary files a/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--ad04e-f-connection-between-Phosphate-and-RNA-to-SVG-2-chromium-linux.png and b/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--ad04e-f-connection-between-Phosphate-and-RNA-to-SVG-2-chromium-linux.png differ diff --git a/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--f0889-f-connection-between-Phosphate-and-RNA-to-SVG-1-chromium-linux.png b/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--f0889-f-connection-between-Phosphate-and-RNA-to-SVG-1-chromium-linux.png index 3d40c2670a..f5e32ceaa7 100644 Binary files a/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--f0889-f-connection-between-Phosphate-and-RNA-to-SVG-1-chromium-linux.png and b/ketcher-autotests/tests/Macromolecule-editor/Import-Saving-Files/saving-svg.spec.ts-snapshots/Saving-in-svg-files-Export-to-SVG-Verify-it--f0889-f-connection-between-Phosphate-and-RNA-to-SVG-1-chromium-linux.png differ diff --git a/ketcher-autotests/tests/Macromolecule-editor/Sequence-Mode/sequence-mode.spec.ts-snapshots/Sequence-Mode-Side-chain-connections-between-sugar-and-phosphate-2-chromium-linux.png b/ketcher-autotests/tests/Macromolecule-editor/Sequence-Mode/sequence-mode.spec.ts-snapshots/Sequence-Mode-Side-chain-connections-between-sugar-and-phosphate-2-chromium-linux.png index 6484c95ff8..b4b6453fe9 100644 Binary files a/ketcher-autotests/tests/Macromolecule-editor/Sequence-Mode/sequence-mode.spec.ts-snapshots/Sequence-Mode-Side-chain-connections-between-sugar-and-phosphate-2-chromium-linux.png and b/ketcher-autotests/tests/Macromolecule-editor/Sequence-Mode/sequence-mode.spec.ts-snapshots/Sequence-Mode-Side-chain-connections-between-sugar-and-phosphate-2-chromium-linux.png differ diff --git a/ketcher-autotests/tests/Macromolecule-editor/Sequence-Mode/sequence-mode.spec.ts-snapshots/Sequence-Mode-Validate-displaying-modified-nuc-b031d-types-of-connection-between-Phosphate-and-RNA-1-chromium-linux.png b/ketcher-autotests/tests/Macromolecule-editor/Sequence-Mode/sequence-mode.spec.ts-snapshots/Sequence-Mode-Validate-displaying-modified-nuc-b031d-types-of-connection-between-Phosphate-and-RNA-1-chromium-linux.png index 3d40c2670a..f5e32ceaa7 100644 Binary files a/ketcher-autotests/tests/Macromolecule-editor/Sequence-Mode/sequence-mode.spec.ts-snapshots/Sequence-Mode-Validate-displaying-modified-nuc-b031d-types-of-connection-between-Phosphate-and-RNA-1-chromium-linux.png and b/ketcher-autotests/tests/Macromolecule-editor/Sequence-Mode/sequence-mode.spec.ts-snapshots/Sequence-Mode-Validate-displaying-modified-nuc-b031d-types-of-connection-between-Phosphate-and-RNA-1-chromium-linux.png differ diff --git a/packages/ketcher-core/src/domain/entities/monomer-chains/Chain.ts b/packages/ketcher-core/src/domain/entities/monomer-chains/Chain.ts index 5cde5140a1..acf95fdd9b 100644 --- a/packages/ketcher-core/src/domain/entities/monomer-chains/Chain.ts +++ b/packages/ketcher-core/src/domain/entities/monomer-chains/Chain.ts @@ -51,24 +51,36 @@ export class Chain { public add(monomer: BaseMonomer) { this.createSubChainIfNeed(monomer); - const nextMonomer = getNextMonomerInChain(monomer); - - if (monomer instanceof Sugar && isValidNucleoside(monomer)) { - this.lastSubChain.add(Nucleoside.fromSugar(monomer)); - } else if (monomer instanceof Sugar && isValidNucleotide(monomer)) { - this.lastSubChain.add(Nucleotide.fromSugar(monomer)); - } else if (monomer instanceof Peptide) { + if (monomer instanceof Sugar) { + if (isValidNucleoside(monomer)) { + this.lastSubChain.add(Nucleoside.fromSugar(monomer)); + return; + } + if (isValidNucleotide(monomer)) { + this.lastSubChain.add(Nucleotide.fromSugar(monomer)); + return; + } + } + if (monomer instanceof Peptide) { this.lastSubChain.add(new MonomerSequenceNode(monomer)); - } else if ( + return; + } + const nextMonomer = getNextMonomerInChain(monomer); + const isNextMonomerNucleosideOrNucleotideOrPeptide = () => { + const isNucleosideOrNucleotide = + nextMonomer instanceof Sugar && + (isValidNucleotide(nextMonomer) || isValidNucleoside(nextMonomer)); + return isNucleosideOrNucleotide || nextMonomer instanceof Peptide; + }; + if ( monomer instanceof Phosphate && - (this.lastNode instanceof Nucleoside || - (nextMonomer instanceof Sugar && - (isValidNucleotide(nextMonomer) || isValidNucleotide(nextMonomer)))) + (!this.lastNode || this.lastNode instanceof Nucleoside) && + (!nextMonomer || isNextMonomerNucleosideOrNucleotideOrPeptide()) ) { this.lastSubChain.add(new MonomerSequenceNode(monomer)); - } else { - this.lastSubChain.add(new LinkerSequenceNode(monomer)); + return; } + this.lastSubChain.add(new LinkerSequenceNode(monomer)); } public addNode(node: SubChainNode) { @@ -105,7 +117,12 @@ export class Chain { return nodes; } - public get lastNode() { + public get lastNode(): + | EmptySequenceNode + | MonomerSequenceNode + | Nucleoside + | Nucleotide + | undefined { return this.lastSubChain?.lastNode; } diff --git a/packages/ketcher-core/src/domain/helpers/monomers.ts b/packages/ketcher-core/src/domain/helpers/monomers.ts index 9400fc0315..f3db941b49 100644 --- a/packages/ketcher-core/src/domain/helpers/monomers.ts +++ b/packages/ketcher-core/src/domain/helpers/monomers.ts @@ -86,22 +86,30 @@ export function isMonomerBeginningOfChain( ); } -export function isValidNucleotide(sugar: Sugar) { +export function isValidNucleotide(sugar: Sugar): boolean { + if (!getRnaBaseFromSugar(sugar)) { + return false; + } + const phosphate = getPhosphateFromSugar(sugar); - const nextMonomerAfterPhosphate = getNextMonomerInChain(phosphate); + if (!phosphate) { + return false; + } - return Boolean( - getRnaBaseFromSugar(sugar) && - getPhosphateFromSugar(sugar) && - nextMonomerAfterPhosphate, - ); + const nextMonomerAfterPhosphate = getNextMonomerInChain(phosphate); + return !!nextMonomerAfterPhosphate; } -export function isValidNucleoside(sugar: Sugar) { +export function isValidNucleoside(sugar: Sugar): boolean { + if (!getRnaBaseFromSugar(sugar)) { + return false; + } + const phosphate = getPhosphateFromSugar(sugar); - const nextMonomerAfterPhosphate = getNextMonomerInChain(phosphate); + if (!phosphate) { + return true; + } - return ( - getRnaBaseFromSugar(sugar) && (!phosphate || !nextMonomerAfterPhosphate) - ); + const nextMonomerAfterPhosphate = getNextMonomerInChain(phosphate); + return !nextMonomerAfterPhosphate; }