Skip to content

Commit

Permalink
#1588 Import of standard IDT monomers (#1904)
Browse files Browse the repository at this point in the history
Co-authored-by: even1024 <roman.porozhnetov@gmail.com>
Co-authored-by: Aliakasndr Dziarkach <Aliakasndr.Dziarkach@gmail.com>
  • Loading branch information
3 people authored Apr 9, 2024
1 parent 6761533 commit cc1b0d1
Show file tree
Hide file tree
Showing 28 changed files with 4,299 additions and 137 deletions.
4 changes: 4 additions & 0 deletions api/c/indigo/indigo.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ CEXPORT int indigoLoadFasta(int source, const char* seq_type);
CEXPORT int indigoLoadFastaFromString(const char* string, const char* seq_type);
CEXPORT int indigoLoadFastaFromFile(const char* filename, const char* seq_type);

CEXPORT int indigoLoadIDT(int source);
CEXPORT int indigoLoadIDTFromString(const char* string);
CEXPORT int indigoLoadIDTFromFile(const char* filename);

CEXPORT int indigoSaveMolfile(int molecule, int output);
CEXPORT int indigoSaveMolfileToFile(int molecule, const char* filename);
CEXPORT const char* indigoMolfile(int molecule);
Expand Down
50 changes: 50 additions & 0 deletions api/c/indigo/src/indigo_molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,56 @@ CEXPORT int indigoLoadFastaFromFile(const char* filename, const char* seq_type)
INDIGO_END(-1);
}

CEXPORT int indigoLoadIDT(int source)
{
INDIGO_BEGIN
{
IndigoObject& obj = self.getObject(source);
SequenceLoader loader(IndigoScanner::get(obj));

std::unique_ptr<IndigoMolecule> molptr = std::make_unique<IndigoMolecule>();

Molecule& mol = molptr->mol;
loader.loadIDT(mol);
return self.addObject(molptr.release());
}
INDIGO_END(-1);
}

CEXPORT int indigoLoadIDTFromString(const char* string)
{
INDIGO_BEGIN
{
int source = indigoReadString(string);
int result;

if (source <= 0)
return -1;

result = indigoLoadIDT(source);
indigoFree(source);
return result;
}
INDIGO_END(-1);
}

CEXPORT int indigoLoadIDTFromFile(const char* filename)
{
INDIGO_BEGIN
{
int source = indigoReadFile(filename);
int result;

if (source < 0)
return -1;

result = indigoLoadIDT(source);
indigoFree(source);
return result;
}
INDIGO_END(-1);
}

CEXPORT int indigoLoadSmarts(int source)
{
INDIGO_BEGIN
Expand Down
12 changes: 12 additions & 0 deletions api/dotnet/src/Indigo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,12 @@ public IndigoObject loadFasta(string str, string seq_type)
return new IndigoObject(this, checkResult(IndigoLib.indigoLoadFastaFromString(str, seq_type)));
}

public IndigoObject loadIDT(string str)
{
setSessionID();
return new IndigoObject(this, checkResult(IndigoLib.indigoLoadIDTFromString(str)));
}

public IndigoObject loadSmarts(byte[] buf)
{
setSessionID();
Expand All @@ -478,6 +484,12 @@ public IndigoObject loadFastaFromFile(string path, string seq_type)
return new IndigoObject(this, checkResult(IndigoLib.indigoLoadFastaFromFile(path, seq_type)));
}

public IndigoObject loadIDTFromFile(string path)
{
setSessionID();
return new IndigoObject(this, checkResult(IndigoLib.indigoLoadIDTFromFile(path)));
}

public IndigoObject loadReaction(string str)
{
setSessionID();
Expand Down
6 changes: 6 additions & 0 deletions api/dotnet/src/IndigoLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,18 @@ public unsafe class IndigoLib
[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern int indigoLoadFastaFromString(string str, string seq_type);

[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern int indigoLoadIDTFromString(string str);

[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern int indigoLoadSequenceFromFile(string filename, string seq_type);

[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern int indigoLoadFastaFromFile(string filename, string seq_type);

[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern int indigoLoadIDTFromFile(string filename);

[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern int indigoLoadSmartsFromBuffer(byte[] buffer, int size);

Expand Down
10 changes: 10 additions & 0 deletions api/java/indigo/src/main/java/com/epam/indigo/Indigo.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,16 @@ public IndigoObject loadFastaFromFile(String path, String seq_type) {
return new IndigoObject(this, checkResult(this, lib.indigoLoadFastaFromFile(path, seq_type)));
}

public IndigoObject loadIDT(String str) {
setSessionID();
return new IndigoObject(this, checkResult(this, lib.indigoLoadIDTFromString(str)));
}

public IndigoObject loadIDTFromFile(String path) {
setSessionID();
return new IndigoObject(this, checkResult(this, lib.indigoLoadIDTFromFile(path)));
}

public IndigoObject loadReaction(String str) {
setSessionID();
return new IndigoObject(this, checkResult(this, lib.indigoLoadReactionFromString(str)));
Expand Down
6 changes: 6 additions & 0 deletions api/java/indigo/src/main/java/com/epam/indigo/IndigoLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ public interface IndigoLib extends Library {

int indigoLoadFastaFromFile(String filename, String seq_type);

int indigoLoadIDT(int source);

int indigoLoadIDTFromString(String str);

int indigoLoadIDTFromFile(String filename);

int indigoLoadStructureFromString(String str, String params);

int indigoLoadStructureFromFile(String filename, String params);
Expand Down
40 changes: 40 additions & 0 deletions api/python/indigo/indigo/indigo.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,46 @@ def loadFastaFromFile(self, filename, seq_type):
),
)

def loadIDT(self, string):
"""Loads molecule from IDT string
Args:
string (str): sequence string
Returns:
IndigoObject: loaded query molecular structure
Raises:
IndigoException: Exception if structure format is incorrect
"""

return IndigoObject(
self,
IndigoLib.checkResult(
self._lib().indigoLoadIDTFromString(string.encode())
),
)

def loadIDTFromFile(self, filename):
"""Loads query molecule from file in IDT sequence format
Args:
filename (str): full path to the file with sequence string
Returns:
IndigoObject: loaded query molecular structure
Raises:
IndigoException: Exception if structure format is incorrect
"""

return IndigoObject(
self,
IndigoLib.checkResult(
self._lib().indigoLoadIDTFromFile(filename.encode())
),
)

def loadReaction(self, string):
"""Loads reaction from string. Format will be automatically recognized.
Expand Down
4 changes: 4 additions & 0 deletions api/python/indigo/indigo/indigo_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ def __init__(self) -> None:
c_char_p,
c_char_p,
]
IndigoLib.lib.indigoLoadIDTFromString.restype = c_int
IndigoLib.lib.indigoLoadIDTFromString.argtypes = [c_char_p]
IndigoLib.lib.indigoLoadIDTFromFile.restype = c_int
IndigoLib.lib.indigoLoadIDTFromFile.argtypes = [c_char_p]
IndigoLib.lib.indigoLoadReactionFromString.restype = c_int
IndigoLib.lib.indigoLoadReactionFromString.argtypes = [c_char_p]
IndigoLib.lib.indigoLoadReactionFromFile.restype = c_int
Expand Down
3 changes: 3 additions & 0 deletions api/tests/integration/ref/formats/idt_to_ket.py.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*** IDT to KET ***
idt_acg.ket:SUCCEED
idt_maxmgc.ket:SUCCEED
43 changes: 43 additions & 0 deletions api/tests/integration/tests/formats/idt_to_ket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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 Indigo, joinPathPy # noqa

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

print("*** IDT to KET ***")

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

fasta_files = [
"idt_acg",
"idt_maxmgc",
]

for filename in fasta_files:
mol = indigo.loadIDTFromFile(os.path.join(root, filename + ".idt"))
# 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)
1 change: 1 addition & 0 deletions api/tests/integration/tests/formats/molecules/idt_acg.idt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ACG
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mA*mGC
Loading

0 comments on commit cc1b0d1

Please sign in to comment.