Skip to content

Commit

Permalink
#4726 - Delete of nucleoside symbol turns another nucleoside to nucle…
Browse files Browse the repository at this point in the history
…otide (#4789)

- skip phosphate add/delete logic for middle/beginning of chain
- restricted entering symbols before phosphate
- updated screenshot
  • Loading branch information
rrodionov91 authored Jun 7, 2024
1 parent b4aaba9 commit 0c90461
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
moveMouseAway,
openFileAndAddToCanvasMacro,
selectSequenceLayoutModeTool,
selectSingleBondTool,
selectSnakeLayoutModeTool,
SequenceType,
startNewSequence,
Expand Down Expand Up @@ -187,37 +186,36 @@ test.describe('Sequence edit mode', () => {
await takeEditorScreenshot(page);
});

test('Bonds between existing and new nucleotides adhere to RNA monomer connection rules', async ({
test('Check that when adding new nucleotides to beginning of a row, order of chains not changes in Sequence mode', async ({
page,
}) => {
/*
Test case: #3650
Description: Phosphate R2 of first nucleotide should be connected with the sugar R1 of next nucleotide.
Test case: #4340
Description: After adding new nucleotides to beginning of a row, order of chains not changes in Sequence mode.
*/
await openFileAndAddToCanvasMacro('KET/rna-g.ket', page);
await page.getByText('G').locator('..').first().click({ button: 'right' });
await openFileAndAddToCanvasMacro('KET/atuc.ket', page);
await takeEditorScreenshot(page);
await clickOnSequenceSymbol(page, 'T', { button: 'right' });
await page.getByTestId('edit_sequence').click();
await page.keyboard.press('ArrowLeft');
await enterSequence(page, 'u');
await page.keyboard.press('Escape');
await selectSnakeLayoutModeTool(page);
await selectSingleBondTool(page);
await page.getByText('P').locator('..').nth(1).hover();
await takeEditorScreenshot(page);
});

test('Check that when adding new nucleotides to beginning of a row, order of chains not changes in Sequence mode', async ({
test('Adding symbols before separate phosphate should be restricted', async ({
page,
}) => {
/*
Test case: #4340
Description: After adding new nucleotides to beginning of a row, order of chains not changes in Sequence mode.
Github ticket: https://github.com/epam/ketcher/issues/4726
Description: It was decided to restrict adding symbols before separate phosphate to prevent adding of nucleosides
by entering symbols before the phosphate.
*/
await openFileAndAddToCanvasMacro('KET/atuc.ket', page);
await takeEditorScreenshot(page);
await clickOnSequenceSymbol(page, 'T', { button: 'right' });
await openFileAndAddToCanvasMacro('KET/rna-g.ket', page);
await page.getByText('G').locator('..').first().click({ button: 'right' });
await page.getByTestId('edit_sequence').click();
await page.keyboard.press('ArrowLeft');
await enterSequence(page, 'u');
await page.keyboard.press('Escape');
await selectSnakeLayoutModeTool(page);
await takeEditorScreenshot(page);
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
44 changes: 28 additions & 16 deletions packages/ketcher-core/src/application/editor/modes/SequenceMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,24 +430,26 @@ export class SequenceMode extends BaseMode {
}

private connectNodes(
node: SubChainNode | undefined,
nextNode: SubChainNode | undefined,
firstNodeToConnect: SubChainNode | undefined,
secondNodeToConnect: SubChainNode | undefined,
modelChanges: Command,
newNodePosition: Vec2,
nextNodeInSameChain?: SubChainNode,
) {
if (
!node ||
node instanceof EmptySequenceNode ||
!nextNode ||
nextNode instanceof EmptySequenceNode
!firstNodeToConnect ||
firstNodeToConnect instanceof EmptySequenceNode ||
!secondNodeToConnect ||
secondNodeToConnect instanceof EmptySequenceNode
) {
return;
}

const editor = CoreEditor.provideEditorInstance();
const nodeR2Bond = node.lastMonomerInNode.attachmentPointsToBonds?.R2;
const nodeR2Bond =
firstNodeToConnect.lastMonomerInNode.attachmentPointsToBonds?.R2;
const nextNodeR1Bond =
nextNode?.firstMonomerInNode?.attachmentPointsToBonds.R1;
secondNodeToConnect?.firstMonomerInNode?.attachmentPointsToBonds.R1;

if (nodeR2Bond || nextNodeR1Bond) {
editor.events.error.dispatch(
Expand All @@ -458,21 +460,23 @@ export class SequenceMode extends BaseMode {
}

if (
node instanceof Nucleoside &&
(nextNode instanceof Nucleotide || nextNode instanceof Nucleoside)
nextNodeInSameChain instanceof EmptySequenceNode &&
firstNodeToConnect instanceof Nucleoside &&
(secondNodeToConnect instanceof Nucleotide ||
secondNodeToConnect instanceof Nucleoside)
) {
modelChanges.merge(
this.bondNodesThroughNewPhosphate(
newNodePosition,
node.lastMonomerInNode,
nextNode.firstMonomerInNode,
firstNodeToConnect.lastMonomerInNode,
secondNodeToConnect.firstMonomerInNode,
),
);
} else {
modelChanges.merge(
editor.drawingEntitiesManager.createPolymerBond(
node.lastMonomerInNode,
nextNode.firstMonomerInNode,
firstNodeToConnect.lastMonomerInNode,
secondNodeToConnect.firstMonomerInNode,
AttachmentPointName.R2,
AttachmentPointName.R1,
),
Expand Down Expand Up @@ -582,8 +586,7 @@ export class SequenceMode extends BaseMode {

if (
nodeBeforeSelection instanceof Nucleoside &&
(nodeAfterSelection instanceof Nucleotide ||
nodeAfterSelection instanceof Nucleoside)
nodeAfterSelection instanceof Nucleotide
) {
modelChanges.merge(
this.bondNodesThroughNewPhosphate(
Expand Down Expand Up @@ -916,6 +919,14 @@ export class SequenceMode extends BaseMode {
const newNodePosition = this.getNewNodePosition();
let modelChanges;
const previousNodeInSameChain = SequenceRenderer.previousNodeInSameChain;

if (
currentNode instanceof MonomerSequenceNode &&
currentNode.monomer instanceof Phosphate
) {
return;
}

if (currentNode instanceof EmptySequenceNode && previousNodeInSameChain) {
if (!this.isR2Free(previousNodeInSameChain)) {
this.showMergeWarningModal(editor);
Expand Down Expand Up @@ -978,6 +989,7 @@ export class SequenceMode extends BaseMode {
firstNodeOfNewFragment,
modelChanges,
newNodePosition,
currentNode,
);

this.connectNodes(
Expand Down

0 comments on commit 0c90461

Please sign in to comment.