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

#1188 HELM ver 1 scope: support multiple sequences and connection tables (import and export) #2040

Merged
merged 2 commits into from
Jul 1, 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_molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ CEXPORT int indigoLoadHelm(int source)
std::unique_ptr<IndigoMolecule> molptr = std::make_unique<IndigoMolecule>();

Molecule& mol = molptr->mol;
// loader.loadHelm(mol);
loader.loadHELM(mol);
return self.addObject(molptr.release());
}
INDIGO_END(-1);
Expand Down
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 @@ -649,7 +649,7 @@ CEXPORT int indigoSaveHelm(int item, int output)
{
SequenceSaver saver(out);
BaseMolecule& mol = obj.getBaseMolecule();
// saver.saveMolecule(mol, SequenceSaver::SeqFormat::HELM);
saver.saveMolecule(mol, SequenceSaver::SeqFormat::HELM);
out.flush();
return 1;
}
Expand Down
7 changes: 7 additions & 0 deletions api/tests/integration/ref/formats/helm_to_ket.py.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*** HELM to KET ***
helm_annotations.ket:SUCCEED
helm_chem_peptide.ket:SUCCEED
helm_multi_char_rna.ket:SUCCEED
helm_peptide.ket:SUCCEED
helm_simple_rna.ket:SUCCEED
Test 'PEPTIDE1{A'2'}$$$$V2.0': got expected error 'Repeating do not supported now.'
6 changes: 6 additions & 0 deletions api/tests/integration/ref/formats/ket_to_helm.py.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*** KET to HELM ***
helm_annotations.ket:SUCCEED
helm_chem_peptide.ket:SUCCEED
helm_multi_char_rna.ket:SUCCEED
helm_peptide.ket:SUCCEED
helm_simple_rna.ket:SUCCEED
71 changes: 71 additions & 0 deletions api/tests/integration/tests/formats/helm_to_ket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import difflib
import os
import sys


def find_diff(a, b):
return "\n".join(difflib.unified_diff(a.splitlines(), b.splitlines()))


sys.path.append(
os.path.normpath(
os.path.join(os.path.abspath(__file__), "..", "..", "..", "common")
)
)
from env_indigo import ( # noqa
Indigo,
IndigoException,
getIndigoExceptionText,
joinPathPy,
)

indigo = Indigo()
indigo.setOption("json-saving-pretty", True)
indigo.setOption("ignore-stereochemistry-errors", True)

print("*** HELM to KET ***")

root = joinPathPy("molecules/", __file__)
ref_path = joinPathPy("ref/", __file__)

helm_data = {
"helm_simple_rna": "RNA1{R(U)P.R(T)P.R(G)P.R(C)P.R(A)}$$$$V2.0",
"helm_multi_char_rna": "RNA1{R(U)P.R(T)P.R(G)P.R(C)P.R([daA])}$$$$V2.0",
"helm_peptide": "PEPTIDE1{A.[meA].C}$$$$V2.0",
"helm_chem_peptide": "CHEM1{[PEG2]}|PEPTIDE1{W.N.D.[Pen].G.[Orn].D.A.D.G.S.G.[Cap]}$CHEM1,PEPTIDE1,1:R1-1:R1$$$V2.0",
"helm_annotations": 'BLOB1{BEAD}"Animated Polystyrene"|CHEM1{[hxy]"Annotation"}|RNA1{R(A"mutation")P.R(U)P.R(G)P}$$$$V2.0',
}

lib = indigo.loadMoleculeFromFile(
os.path.join(ref_path, "monomer_library.ket")
)

for filename in sorted(helm_data.keys()):
mol = indigo.loadHelm(helm_data[filename])
# with open(os.path.join(ref_path, filename) + ".ket", "w") as file:
# file.write(mol.json())
with open(os.path.join(ref_path, filename) + ".ket", "r") as file:
ket_ref = file.read()
ket = mol.json()
diff = find_diff(ket_ref, ket)
if not diff:
print(filename + ".ket:SUCCEED")
else:
print(filename + ".ket:FAILED")
print(diff)

helm_errors = {"PEPTIDE1{A'2'}$$$$V2.0": "Repeating do not supported now."}
for helm_seq in sorted(helm_errors.keys()):
error = helm_errors[helm_seq]
try:
mol = indigo.loadHelm(helm_seq)
print("Test %s failed: exception expected." % helm_seq)
except IndigoException as e:
text = getIndigoExceptionText(e)
if error in text:
print("Test '%s': got expected error '%s'" % (helm_seq, error))
else:
print(
"Test '%s': expected error '%s' but got '%s'"
% (helm_seq, error, text)
)
73 changes: 73 additions & 0 deletions api/tests/integration/tests/formats/ket_to_helm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import difflib
import os
import sys


def find_diff(a, b):
return "\n".join(difflib.unified_diff(a.splitlines(), b.splitlines()))


sys.path.append(
os.path.normpath(
os.path.join(os.path.abspath(__file__), "..", "..", "..", "common")
)
)
from env_indigo import ( # noqa
Indigo,
IndigoException,
getIndigoExceptionText,
joinPathPy,
)

indigo = Indigo()
indigo.setOption("ignore-stereochemistry-errors", True)

print("*** KET to HELM ***")

root = joinPathPy("molecules/", __file__)
ref = joinPathPy("ref/", __file__)

indigo.loadMoleculeFromFile(os.path.join(ref, "monomer_library.ket"))

# same ref ket files used to check idt-to-ket and to check ket-to-idt
helm_data = {
"helm_simple_rna": "RNA1{R(U)P.R(T)P.R(G)P.R(C)P.R(A)}$$$$V2.0",
"helm_multi_char_rna": "RNA1{R(U)P.R(T)P.R(G)P.R(C)P.R([daA])}$$$$V2.0",
"helm_peptide": "PEPTIDE1{A.[meA].C}$$$$V2.0",
"helm_chem_peptide": "CHEM1{[PEG2]}|PEPTIDE1{W.N.D.[Pen].G.[Orn].D.A.D.G.S.G.[Cap]}$CHEM1,PEPTIDE1,1:R1-1:R1$$$V2.0",
"helm_annotations": "CHEM1{[hxy]}|RNA1{R(A)P.R(U)P.R(G)P}$$$$V2.0",
}

for filename in sorted(helm_data.keys()):
mol = indigo.loadMoleculeFromFile(os.path.join(ref, filename + ".ket"))
idt = mol.helm()
idt_ref = helm_data[filename]
if idt_ref == idt:
print(filename + ".ket:SUCCEED")
else:
print(
"%s.idt FAILED : expected '%s', got '%s'"
% (filename, idt_ref, idt)
)

helm_errors = {}
for filename in sorted(helm_errors.keys()):
error = helm_errors[filename]
try:
mol = indigo.loadMoleculeFromFile(
os.path.join(root, filename + ".ket")
)
idt = mol.idt()
print(
"Test %s failed: exception expected but got next idt - '%s'."
% (filename, idt)
)
except IndigoException as e:
text = getIndigoExceptionText(e)
if error in text:
print("Test %s: got expected error '%s'" % (filename, error))
else:
print(
"Test %s: expected error '%s' but got '%s'"
% (filename, error, text)
)
Loading
Loading