diff --git a/utils/indigo-service/backend/service/tests/api/indigo_test.py b/utils/indigo-service/backend/service/tests/api/indigo_test.py index 855c5511f0..193276cdff 100644 --- a/utils/indigo-service/backend/service/tests/api/indigo_test.py +++ b/utils/indigo-service/backend/service/tests/api/indigo_test.py @@ -479,7 +479,7 @@ def test_headers_wrong(self): 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-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-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 @@ -3493,6 +3493,55 @@ def test_convert_idt(self): result_idt = json.loads(result.text)["struct"] self.assertEqual(idt, result_idt) + def test_convert_helm(self): + fname = "helm_ambiguous" + + lib_file = "monomer_library.ket" + lib_path = os.path.join(joinPathPy("structures/", __file__), lib_file) + with open(lib_path, "r") as file: + monomer_library = file.read() + + helm_struct = "PEPTIDE1{(D,N,I)}|PEPTIDE2{(D+N+I)}$$$$V2.0" + # HELM to ket + headers, data = self.get_headers( + { + "struct": helm_struct, + "options": {"monomerLibrary": monomer_library}, + "input_format": "chemical/x-helm", + "output_format": "chemical/x-indigo-ket", + } + ) + + result = requests.post( + self.url_prefix + "/convert", headers=headers, data=data + ) + result_ket = json.loads(result.text)["struct"] + + ref_prefix = os.path.join(joinPathPy("ref/", __file__), fname) + # write references + # with open(ref_prefix + ".ket", "w") as file: + # file.write(result_ket) + + # check + with open(ref_prefix + ".ket", "r") as file: + self.assertEqual(result_ket, file.read()) + + # Ket to HELM + headers, data = self.get_headers( + { + "struct": result_ket, + "options": {"monomerLibrary": monomer_library}, + "input_format": "chemical/x-indigo-ket", + "output_format": "chemical/x-helm", + } + ) + + result = requests.post( + self.url_prefix + "/convert", headers=headers, data=data + ) + result_helm = json.loads(result.text)["struct"] + self.assertEqual(helm_struct, result_helm) + if __name__ == "__main__": unittest.main(verbosity=2, warnings="ignore") diff --git a/utils/indigo-service/backend/service/tests/api/ref/helm_ambiguous.ket b/utils/indigo-service/backend/service/tests/api/ref/helm_ambiguous.ket new file mode 100644 index 0000000000..7731afc320 --- /dev/null +++ b/utils/indigo-service/backend/service/tests/api/ref/helm_ambiguous.ket @@ -0,0 +1 @@ +{"root":{"nodes":[{"$ref":"ambiguousMonomer-0"},{"$ref":"ambiguousMonomer-1"}],"templates":[{"$ref":"monomerTemplate-D___Aspartic acid"},{"$ref":"monomerTemplate-N___Asparagine"},{"$ref":"monomerTemplate-I___Isoleucine"},{"$ref":"ambiguousMonomerTemplate-Var0"},{"$ref":"ambiguousMonomerTemplate-Var1"}]},"ambiguousMonomer-0":{"type":"ambiguousMonomer","id":"0","position":{"x":0.000000,"y":-0.000000},"seqid":1,"alias":"Var0","templateId":"Var0"},"ambiguousMonomer-1":{"type":"ambiguousMonomer","id":"1","position":{"x":0.000000,"y":-1.600000},"seqid":2,"alias":"Var1","templateId":"Var1"},"monomerTemplate-D___Aspartic acid":{"type":"monomerTemplate","id":"D___Aspartic acid","class":"AminoAcid","classHELM":"PEPTIDE","fullName":"Aspartic acid","alias":"D","naturalAnalogShort":"D","attachmentPoints":[{"attachmentAtom":3,"type":"left","leavingGroup":{"atoms":[4]}},{"attachmentAtom":0,"type":"right","leavingGroup":{"atoms":[9]}},{"attachmentAtom":8,"type":"side","leavingGroup":{"atoms":[10]}}],"atoms":[{"label":"C","location":[1.631000,-1.557800,0.000000]},{"label":"O","location":[1.632700,-2.739200,0.000000]},{"label":"C","location":[0.350700,-0.820100,0.000000],"stereoLabel":"abs"},{"label":"N","location":[-0.929500,-1.557800,0.000000]},{"label":"H","location":[-1.952500,-0.966900,0.000000]},{"label":"C","location":[0.348500,0.657500,0.000000]},{"label":"C","location":[-0.931700,1.395200,0.000000]},{"label":"O","location":[-1.954200,0.803200,0.000000]},{"label":"O","location":[-0.933500,2.576600,0.000000]},{"label":"O","location":[2.653400,-0.965800,0.000000]},{"label":"H","location":[0.085100,3.175100,0.000000]}],"bonds":[{"type":2,"atoms":[1,0]},{"type":1,"atoms":[0,2]},{"type":1,"atoms":[2,3]},{"type":1,"atoms":[3,4]},{"type":1,"atoms":[2,5],"stereo":1},{"type":1,"atoms":[5,6]},{"type":2,"atoms":[6,7]},{"type":1,"atoms":[6,8]},{"type":1,"atoms":[0,9]},{"type":1,"atoms":[8,10]}]},"monomerTemplate-N___Asparagine":{"type":"monomerTemplate","id":"N___Asparagine","class":"AminoAcid","classHELM":"PEPTIDE","fullName":"Asparagine","alias":"N","naturalAnalogShort":"N","attachmentPoints":[{"attachmentAtom":3,"type":"left","leavingGroup":{"atoms":[4]}},{"attachmentAtom":0,"type":"right","leavingGroup":{"atoms":[9]}},{"attachmentAtom":7,"type":"side","leavingGroup":{"atoms":[10]}}],"atoms":[{"label":"C","location":[1.892900,-1.417500,0.000000]},{"label":"O","location":[1.894700,-2.598900,0.000000]},{"label":"C","location":[0.612700,-0.679900,0.000000],"stereoLabel":"abs"},{"label":"N","location":[-0.667600,-1.417500,0.000000]},{"label":"H","location":[-1.690700,-0.826600,0.000000]},{"label":"C","location":[0.610400,0.797800,0.000000]},{"label":"C","location":[-0.669800,1.535400,0.000000]},{"label":"N","location":[-1.692200,0.943400,0.000000]},{"label":"O","location":[-0.671600,2.716800,0.000000]},{"label":"O","location":[2.915300,-0.825500,0.000000]},{"label":"H","location":[-2.534100,1.772400,0.000000]}],"bonds":[{"type":2,"atoms":[1,0]},{"type":1,"atoms":[0,2]},{"type":1,"atoms":[2,3]},{"type":1,"atoms":[3,4]},{"type":1,"atoms":[2,5],"stereo":1},{"type":1,"atoms":[5,6]},{"type":1,"atoms":[6,7]},{"type":2,"atoms":[6,8]},{"type":1,"atoms":[0,9]},{"type":1,"atoms":[7,10]}]},"monomerTemplate-I___Isoleucine":{"type":"monomerTemplate","id":"I___Isoleucine","class":"AminoAcid","classHELM":"PEPTIDE","fullName":"Isoleucine","alias":"I","naturalAnalogShort":"I","attachmentPoints":[{"attachmentAtom":3,"type":"left","leavingGroup":{"atoms":[4]}},{"attachmentAtom":5,"type":"right","leavingGroup":{"atoms":[7]}}],"atoms":[{"label":"C","location":[-1.255700,1.668100,0.000000]},{"label":"C","location":[0.024500,0.930400,0.000000],"stereoLabel":"abs"},{"label":"C","location":[0.026800,-0.547200,0.000000],"stereoLabel":"abs"},{"label":"N","location":[-1.253600,-1.284900,0.000000]},{"label":"H","location":[-2.276600,-0.694000,0.000000]},{"label":"C","location":[1.306900,-1.284900,0.000000]},{"label":"O","location":[1.308600,-2.466400,0.000000]},{"label":"O","location":[2.329400,-0.693000,0.000000]},{"label":"C","location":[1.047000,1.522300,0.000000]},{"label":"C","location":[-1.257400,2.849500,0.000000]}],"bonds":[{"type":1,"atoms":[0,1]},{"type":1,"atoms":[2,1],"stereo":1},{"type":1,"atoms":[2,3]},{"type":1,"atoms":[3,4]},{"type":1,"atoms":[2,5]},{"type":2,"atoms":[5,6]},{"type":1,"atoms":[5,7]},{"type":1,"atoms":[1,8],"stereo":6},{"type":1,"atoms":[0,9]}]},"ambiguousMonomerTemplate-Var0":{"type":"ambiguousMonomerTemplate","subtype":"alternatives","id":"Var0","alias":"Var0","options":[{"templateId":"D___Aspartic acid"},{"templateId":"N___Asparagine"},{"templateId":"I___Isoleucine"}]},"ambiguousMonomerTemplate-Var1":{"type":"ambiguousMonomerTemplate","subtype":"mixture","id":"Var1","alias":"Var1","options":[{"templateId":"D___Aspartic acid"},{"templateId":"N___Asparagine"},{"templateId":"I___Isoleucine"}]}} \ No newline at end of file diff --git a/utils/indigo-service/backend/service/v2/validation.py b/utils/indigo-service/backend/service/v2/validation.py index 2632f09b41..05ded7b01b 100644 --- a/utils/indigo-service/backend/service/v2/validation.py +++ b/utils/indigo-service/backend/service/v2/validation.py @@ -33,6 +33,7 @@ class InputFormatSchema(Schema): "chemical/x-dna-fasta", "chemical/x-fasta", "chemical/x-idt", + "chemical/x-helm", ) input_format = fields.Str(missing=None, validate=OneOf(struct_mime_types))