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

Backmerge: #2615 - Export to three letter amino acid codes cause convert error. #2619

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/c/indigo/src/indigo_savers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ CEXPORT int indigoSaveSequence3Letter(int item, int output, int library)
out.flush();
return 1;
}
throw IndigoError("indigoSaveSequence(): expected molecule, got %s", obj.debugInfo());
throw IndigoError("indigoSaveSequence3Letter(): expected document, got %s", obj.debugInfo());
}
INDIGO_END(-1);
}
Expand Down
9 changes: 5 additions & 4 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 @@ -540,9 +540,10 @@ namespace indigo
input_format = it->second;

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"))
if ((input_format == "ket" || input_format == "application/json") && outputFormat.size() > 0 &&
(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
1 change: 1 addition & 0 deletions api/wasm/indigo-ketcher/test/peptide_ref_3_letter.ket

Large diffs are not rendered by default.

26 changes: 24 additions & 2 deletions api/wasm/indigo-ketcher/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ M END
var fs = require('fs');
const cdx_data = fs.readFileSync("test64.cdx");
const ket = indigo.convert(cdx_data, "ket", options);
const ket_data = indigo.convert(fs.readFileSync("test64.ket"), "ket", options);
fs.writeFileSync("test64a.ket", ket);
const ket_data = fs.readFileSync("test64.ket").toString();
fs.writeFileSync("test64a1.ket", ket_data);
assert.equal(ket, ket_data);
options.delete();
});
Expand Down 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 = JSON.parse(indigo.convert(peptide_seq_ref, "ket", options)).struct;
// fs.writeFileSync("peptide_ref_3_letter.ket", peptide_ket);
const peptide_ket_ref = fs.readFileSync("peptide_ref_3_letter.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
33 changes: 31 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,33 @@ def test_convert_sequences(self):
self.url_prefix + "/convert", headers=headers, data=data
)

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

headers, data = self.get_headers(
{
"struct": json.loads(result_ket_3.text)["struct"],
"options": {"monomerLibrary": monomer_library},
"output_format": "chemical/x-peptide-sequence-3-letter",
}
)
result_peptide_3 = requests.post(
self.url_prefix + "/convert", headers=headers, data=data
)
self.assertEqual(
json.loads(result_peptide_3.text)["struct"], peptide_3
)

headers, data = self.get_headers(
{
"struct": "ACDEFGHIKLMNOPQRSRUVWY",
Expand Down Expand Up @@ -3314,6 +3342,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_ket_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
Loading