Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4607 - Inconsistent display of a separate phosphate in the sequence representation in the Sequence mode #4766

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;
}
Loading