Skip to content

Commit

Permalink
#2615 - Export to three letter amino acid codes cause convert error.
Browse files Browse the repository at this point in the history
Fix code. Add UTs
  • Loading branch information
AliaksandrDziarkach committed Nov 6, 2024
1 parent 904d2d9 commit f65ca56
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
7 changes: 4 additions & 3 deletions api/wasm/indigo-ketcher/indigo-ketcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace indigo
{
result = _checkResultString(indigoSequence(id(), library));
}
else if (outputFormat == "sequence-3-letter" || outputFormat == "chemical/x-sequence-3-letter")
else if (outputFormat == "peptide-sequence-3-letter" || outputFormat == "chemical/x-peptide-sequence-3-letter")
{
result = _checkResultString(indigoSequence3Letter(id(), library));
}
Expand Down Expand Up @@ -541,8 +541,9 @@ namespace indigo

bool use_document = false;
if (input_format == "ket" && outputFormat.size() > 0 &&
(outputFormat == "sequence" || outputFormat == "chemical/x-sequence" || outputFormat == "fasta" || outputFormat == "chemical/x-fasta" ||
outputFormat == "idt" || outputFormat == "chemical/x-idt" || outputFormat == "helm" || outputFormat == "chemical/x-helm"))
(outputFormat == "sequence" || outputFormat == "chemical/x-sequence" || "chemical/x-peptide-sequence-3-letter" || outputFormat == "fasta" ||
outputFormat == "chemical/x-fasta" || outputFormat == "idt" || outputFormat == "chemical/x-idt" || outputFormat == "helm" ||
outputFormat == "chemical/x-helm"))
use_document = true;
IndigoKetcherObject iko = loadMoleculeOrReaction(data, options_copy, library, use_document);

Expand Down
22 changes: 22 additions & 0 deletions api/wasm/indigo-ketcher/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,28 @@ M END
});
}

{
test("PEPTIDE-3-LETTER", "basic", () => {
var fs = require('fs');
let options = new indigo.MapStringString();
const monomersLib = fs.readFileSync("monomer_library.ket");
options.set("monomerLibrary", monomersLib);
options.set("output-content-type", "application/json");
options.set("input-format", "chemical/x-peptide-sequence-3-letter");
const peptide_seq_ref = "AlaCysAspGluPheGlyHisIleLysLeuMetAsnPylProGlnArgSerArgSecValTrpTyr";
const peptide_ket = indigo.convert(peptide_seq_ref, "ket", options);
// fs.writeFileSync("peptide_ref.ket", peptide_ket);
const peptide_ket_ref = fs.readFileSync("peptide_ref.ket");
assert.equal(peptide_ket, peptide_ket_ref.toString());

options.set("input-format", "application/json");
options.set("output-content-type", "chemical/x-peptide-sequence-3-letter");
const peptide_seq = indigo.convert(peptide_ket_ref.toString(), "chemical/x-peptide-sequence-3-letter", options);
assert.equal(peptide_seq, peptide_seq_ref);
options.delete();
});
}

{
test("RNA", "basic", () => {
var fs = require('fs');
Expand Down
18 changes: 16 additions & 2 deletions utils/indigo-service/backend/service/tests/api/indigo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,9 @@ def test_headers_wrong(self):
chemical/x-daylight-smiles, chemical/x-cml, chemical/x-inchi, chemical/x-inchi-key, \
chemical/x-iupac, chemical/x-daylight-smarts, chemical/x-inchi-aux, chemical/x-chemaxon-cxsmiles, \
chemical/x-cdxml, chemical/x-cdx, chemical/x-sdf, chemical/x-rdf, chemical/x-peptide-sequence, \
chemical/x-rna-sequence, chemical/x-dna-sequence, chemical/x-sequence, chemical/x-peptide-fasta, \
chemical/x-rna-fasta, chemical/x-dna-fasta, chemical/x-fasta, chemical/x-idt, chemical/x-helm."
chemical/x-peptide-sequence-3-letter, chemical/x-rna-sequence, chemical/x-dna-sequence, chemical/x-sequence, \
chemical/x-peptide-fasta, chemical/x-rna-fasta, chemical/x-dna-fasta, chemical/x-fasta, \
chemical/x-idt, chemical/x-helm."
expected_text = (
"ValidationError: {'input_format': ['Must be one of: %s']}"
% formats
Expand Down Expand Up @@ -3277,6 +3278,18 @@ def test_convert_sequences(self):
self.url_prefix + "/convert", headers=headers, data=data
)

headers, data = self.get_headers(
{
"struct": "AlaCysGlyThrSec",
"options": {"monomerLibrary": monomer_library},
"input_format": "chemical/x-peptide-sequence-3-letter",
"output_format": "chemical/x-indigo-ket",
}
)
result_peptide_3 = requests.post(
self.url_prefix + "/convert", headers=headers, data=data
)

headers, data = self.get_headers(
{
"struct": "ACDEFGHIKLMNOPQRSRUVWY",
Expand Down Expand Up @@ -3314,6 +3327,7 @@ def test_convert_sequences(self):
with open(os.path.join(ref_path, "peptide_ref") + ".ket", "r") as file:
peptide_ref = file.read()
self.assertEqual(result_peptide.text, peptide_ref)
self.assertEqual(result_peptide_3.text, peptide_ref)

def test_convert_fasta(self):
ref_path = joinPathPy("ref/", __file__)
Expand Down
7 changes: 7 additions & 0 deletions utils/indigo-service/backend/service/v2/indigo_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ def load_moldata(
md.struct = indigo.loadSequence(molstr, "PEPTIDE", library)
md.is_rxn = False
md.is_query = False
elif input_format == "chemical/x-peptide-sequence-3-letter":
md.struct = indigo.loadSequence(molstr, "PEPTIDE-3-LETTER", library)
md.is_rxn = False
md.is_query = False
elif input_format == "chemical/x-rna-sequence":
md.struct = indigo.loadSequence(molstr, "RNA", library)
md.is_rxn = False
Expand Down Expand Up @@ -431,6 +435,8 @@ def save_moldata(
return md.struct.json()
elif output_format == "chemical/x-sequence":
return md.struct.sequence(library)
elif output_format == "chemical/x-peptide-sequence-3-letter":
return md.struct.sequence3Letter(library)
elif output_format == "chemical/x-fasta":
return md.struct.fasta(library)
elif output_format == "chemical/x-idt":
Expand Down Expand Up @@ -928,6 +934,7 @@ def convert():
"chemical/x-fasta",
"chemical/x-idt",
"chemical/x-helm",
"chemical/x-peptide-sequence-3-letter, ",
):
try_document = True

Expand Down
1 change: 1 addition & 0 deletions utils/indigo-service/backend/service/v2/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class InputFormatSchema(Schema):
"chemical/x-sdf",
"chemical/x-rdf",
"chemical/x-peptide-sequence",
"chemical/x-peptide-sequence-3-letter",
"chemical/x-rna-sequence",
"chemical/x-dna-sequence",
"chemical/x-sequence",
Expand Down

0 comments on commit f65ca56

Please sign in to comment.