From 022dce886cdbb495b75e1a8767af5f19a02cefe3 Mon Sep 17 00:00:00 2001 From: Dmitrii Polovnev Date: Wed, 5 Jun 2024 18:13:35 +0300 Subject: [PATCH] #4607 - Bugfix (monomers.ts): Correct `isValidNucleoside(1)`, `isValidNucleotide(1)` --- .../src/domain/helpers/monomers.ts | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/packages/ketcher-core/src/domain/helpers/monomers.ts b/packages/ketcher-core/src/domain/helpers/monomers.ts index 9400fc0315..a99a435986 100644 --- a/packages/ketcher-core/src/domain/helpers/monomers.ts +++ b/packages/ketcher-core/src/domain/helpers/monomers.ts @@ -86,22 +86,38 @@ export function isMonomerBeginningOfChain( ); } -export function isValidNucleotide(sugar: Sugar) { +export function isValidNucleotide(sugar: Sugar): boolean { + if (!getRnaBaseFromSugar(sugar)) { + return false; + } + const phosphate = getPhosphateFromSugar(sugar); + if (!phosphate) { + return false; + } + const nextMonomerAfterPhosphate = getNextMonomerInChain(phosphate); + if (!(nextMonomerAfterPhosphate instanceof Sugar)) { + return false; + } - return Boolean( - getRnaBaseFromSugar(sugar) && - getPhosphateFromSugar(sugar) && - nextMonomerAfterPhosphate, - ); + return !!getRnaBaseFromSugar(nextMonomerAfterPhosphate); } -export function isValidNucleoside(sugar: Sugar) { +export function isValidNucleoside(sugar: Sugar): boolean { + if (!getRnaBaseFromSugar(sugar)) { + return false; + } + const phosphate = getPhosphateFromSugar(sugar); + if (!phosphate) { + return true; + } + const nextMonomerAfterPhosphate = getNextMonomerInChain(phosphate); + if (!(nextMonomerAfterPhosphate instanceof Sugar)) { + return true; + } - return ( - getRnaBaseFromSugar(sugar) && (!phosphate || !nextMonomerAfterPhosphate) - ); + return !getRnaBaseFromSugar(nextMonomerAfterPhosphate); }