Skip to content

Commit

Permalink
#4607 - Bugfix (Chain.ts): Correct the definition of individual phosp…
Browse files Browse the repository at this point in the history
…hate and linker in `add(1)`
  • Loading branch information
DmitriiP-EPAM committed Jun 13, 2024
1 parent e5a8053 commit d2dacd7
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 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 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

0 comments on commit d2dacd7

Please sign in to comment.