Skip to content

Commit

Permalink
#4607 - Inconsistent display of a separate phosphate in the sequence …
Browse files Browse the repository at this point in the history
…representation in the Sequence mode (#4766)

- correct isValidNucleoside() and isValidNucleotide()
- correct the definition of individual phosphate and linker
  • Loading branch information
DmitriiP-EPAM authored Jun 14, 2024
1 parent 081cff9 commit 22ad484
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 26 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 31 additions & 14 deletions packages/ketcher-core/src/domain/entities/monomer-chains/Chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -105,7 +117,12 @@ export class Chain {
return nodes;
}

public get lastNode() {
public get lastNode():
| EmptySequenceNode
| MonomerSequenceNode
| Nucleoside
| Nucleotide
| undefined {
return this.lastSubChain?.lastNode;
}

Expand Down
32 changes: 20 additions & 12 deletions packages/ketcher-core/src/domain/helpers/monomers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 22ad484

Please sign in to comment.