Skip to content

Commit

Permalink
#1426 Import sequence format for RNA, DNA and PEPTIDES (#1462)
Browse files Browse the repository at this point in the history
  • Loading branch information
even1024 authored Jan 4, 2024
1 parent ef5dd99 commit 940d5e0
Show file tree
Hide file tree
Showing 49 changed files with 14,083 additions and 563 deletions.
4 changes: 4 additions & 0 deletions api/c/indigo/indigo.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ CEXPORT int indigoLoadSmartsFromString(const char* string);
CEXPORT int indigoLoadSmartsFromFile(const char* filename);
CEXPORT int indigoLoadSmartsFromBuffer(const char* buffer, int size);

CEXPORT int indigoLoadSequence(int source, const char* seq_type);
CEXPORT int indigoLoadSequenceFromString(const char* string, const char* seq_type);
CEXPORT int indigoLoadSequenceFromFile(const char* filename, const char* seq_type);

CEXPORT int indigoSaveMolfile(int molecule, int output);
CEXPORT int indigoSaveMolfileToFile(int molecule, const char* filename);
CEXPORT const char* indigoMolfile(int molecule);
Expand Down
77 changes: 42 additions & 35 deletions api/c/indigo/src/indigo_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "layout/molecule_cleaner_2d.h"
#include "layout/molecule_layout.h"
#include "layout/reaction_layout.h"
#include "layout/sequence_layout.h"
#include "reaction/base_reaction.h"
#include <algorithm>
#include <vector>
Expand All @@ -48,48 +49,54 @@ CEXPORT int indigoLayout(int object)
f.unhide(submol.vertices[i]);
}
}
MoleculeLayout ml(*mol, self.smart_layout);

if (obj.type == IndigoObject::SUBMOLECULE)
// experimantal layout for sequences
// SequenceLayout sl(*mol);
// sl.make();
if (mol->tgroups.getTGroupCount() == 0)
{
ml.filter = &f;
}
MoleculeLayout ml(*mol, self.smart_layout);

ml.max_iterations = self.layout_max_iterations;
ml.bond_length = MoleculeLayout::DEFAULT_BOND_LENGTH;
ml.layout_orientation = (layout_orientation_value)self.layout_orientation;
if (self.layout_preserve_existing || mol->hasAtropoStereoBonds())
ml.respect_existing_layout = true;

TimeoutCancellationHandler cancellation(self.cancellation_timeout);
ml.setCancellationHandler(&cancellation);
ml.make();

if (obj.type != IndigoObject::SUBMOLECULE)
{
mol->clearBondDirections();
try
if (obj.type == IndigoObject::SUBMOLECULE)
{
mol->markBondsStereocenters();
mol->markBondsAlleneStereo();
ml.filter = &f;
}
catch (Exception e)
{
}
for (i = 1; i <= mol->rgroups.getRGroupCount(); i++)
{
RGroup& rgp = mol->rgroups.getRGroup(i);

for (int j = rgp.fragments.begin(); j != rgp.fragments.end(); j = rgp.fragments.next(j))
ml.max_iterations = self.layout_max_iterations;
ml.bond_length = MoleculeLayout::DEFAULT_BOND_LENGTH;
ml.layout_orientation = (layout_orientation_value)self.layout_orientation;
if (self.layout_preserve_existing || mol->hasAtropoStereoBonds())
ml.respect_existing_layout = true;

TimeoutCancellationHandler cancellation(self.cancellation_timeout);
ml.setCancellationHandler(&cancellation);
ml.make();

if (obj.type != IndigoObject::SUBMOLECULE)
{
mol->clearBondDirections();
try
{
rgp.fragments[j]->clearBondDirections();
try
{
rgp.fragments[j]->markBondsStereocenters();
rgp.fragments[j]->markBondsAlleneStereo();
}
catch (Exception e)
mol->markBondsStereocenters();
mol->markBondsAlleneStereo();
}
catch (Exception e)
{
}
for (i = 1; i <= mol->rgroups.getRGroupCount(); i++)
{
RGroup& rgp = mol->rgroups.getRGroup(i);

for (int j = rgp.fragments.begin(); j != rgp.fragments.end(); j = rgp.fragments.next(j))
{
rgp.fragments[j]->clearBondDirections();
try
{
rgp.fragments[j]->markBondsStereocenters();
rgp.fragments[j]->markBondsAlleneStereo();
}
catch (Exception e)
{
}
}
}
}
Expand Down
51 changes: 51 additions & 0 deletions api/c/indigo/src/indigo_molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "molecule/molecule_name_parser.h"
#include "molecule/molecule_savers.h"
#include "molecule/query_molecule.h"
#include "molecule/sequence_loader.h"
#include "molecule/smiles_loader.h"
#include "molecule/smiles_saver.h"

Expand Down Expand Up @@ -525,6 +526,56 @@ CEXPORT int indigoLoadQueryMolecule(int source)
INDIGO_END(-1);
}

CEXPORT int indigoLoadSequence(int source, const char* seq_type)
{
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.loadSequence(mol, seq_type);
return self.addObject(molptr.release());
}
INDIGO_END(-1);
}

CEXPORT int indigoLoadSequenceFromString(const char* string, const char* seq_type)
{
INDIGO_BEGIN
{
int source = indigoReadString(string);
int result;

if (source <= 0)
return -1;

result = indigoLoadSequence(source, seq_type);
indigoFree(source);
return result;
}
INDIGO_END(-1);
}

CEXPORT int indigoLoadSequenceFromFile(const char* filename, const char* seq_type)
{
INDIGO_BEGIN
{
int source = indigoReadFile(filename);
int result;

if (source < 0)
return -1;

result = indigoLoadSequence(source, seq_type);
indigoFree(source);
return result;
}
INDIGO_END(-1);
}

CEXPORT int indigoLoadSmarts(int source)
{
INDIGO_BEGIN
Expand Down
6 changes: 6 additions & 0 deletions api/cpp/src/IndigoSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ IndigoQueryMolecule IndigoSession::loadSmarts(const std::string& data)
return {_checkResult(indigoLoadSmartsFromString(data.c_str())), shared_from_this()};
}

IndigoMolecule IndigoSession::loadSequence(const std::string& data, const std::string& seq_type)
{
setSessionId();
return {_checkResult(indigoLoadSequenceFromString(data.c_str(), seq_type.c_str())), shared_from_this()};
}

IndigoWriteBuffer IndigoSession::writeBuffer()
{
setSessionId();
Expand Down
2 changes: 1 addition & 1 deletion api/cpp/src/IndigoSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace indigo_cpp

IndigoQueryMolecule loadQueryMolecule(const std::string& data);
IndigoQueryMolecule loadSmarts(const std::string& data);

IndigoMolecule loadSequence(const std::string& data, const std::string& seq_type);
IndigoReaction loadReaction(const std::string& data);

IndigoReaction loadQueryReaction(const std::string& data);
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 @@ -442,6 +442,12 @@ public IndigoObject loadSmarts(string str)
return new IndigoObject(this, checkResult(IndigoLib.indigoLoadSmartsFromString(str)));
}

public IndigoObject loadSequence(string str, string seq_type)
{
setSessionID();
return new IndigoObject(this, checkResult(IndigoLib.indigoLoadSequenceFromString(str, seq_type)));
}

public IndigoObject loadSmarts(byte[] buf)
{
setSessionID();
Expand All @@ -454,6 +460,12 @@ public IndigoObject loadSmartsFromFile(string path)
return new IndigoObject(this, checkResult(IndigoLib.indigoLoadSmartsFromFile(path)));
}

public IndigoObject loadSequenceFromFile(string path, string seq_type)
{
setSessionID();
return new IndigoObject(this, checkResult(IndigoLib.indigoLoadSequenceFromFile(path, seq_type)));
}

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 @@ -128,6 +128,12 @@ public unsafe class IndigoLib
[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern int indigoLoadSmartsFromFile(string filename);

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

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

[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 @@ -360,6 +360,16 @@ public IndigoObject loadSmartsFromFile(String path) {
return new IndigoObject(this, checkResult(this, lib.indigoLoadSmartsFromFile(path)));
}

public IndigoObject loadSequence(String str, String seq_type) {
setSessionID();
return new IndigoObject(this, checkResult(this, lib.indigoLoadSequenceFromString(str, seq_type)));
}

public IndigoObject loadSequenceFromFile(String path, String seq_type) {
setSessionID();
return new IndigoObject(this, checkResult(this, lib.indigoLoadSequenceFromFile(path, seq_type)));
}

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 @@ -117,6 +117,12 @@ public interface IndigoLib extends Library {

int indigoLoadSmartsFromBuffer(byte[] buffer, int size);

int indigoLoadSequence(int source, String seq_type);

int indigoLoadSequenceFromString(String str, String seq_type);

int indigoLoadSequenceFromFile(String filename, String seq_type);

int indigoLoadStructureFromString(String str, String params);

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

def loadSequence(self, string, seq_type):
"""Loads molecule from DNA/RNA/PEPTIDE sequence string
Args:
string (str): sequence string
seq_type (str): sequence type (RNA/DNA/PEPTIDE)
Returns:
IndigoObject: loaded query molecular structure
Raises:
IndigoException: Exception if structure format is incorrect
"""

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

def loadSequenceFromFile(self, filename, seq_type):
"""Loads query molecule from file in sequence format
Args:
filename (str): full path to the file with sequence string
seq_type (str): sequence type (RNA/DNA/PEPTIDE)
Returns:
IndigoObject: loaded query molecular structure
Raises:
IndigoException: Exception if structure format is incorrect
"""

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

def loadReaction(self, string):
"""Loads reaction from string. Format will be automatically recognized.
Expand Down
10 changes: 10 additions & 0 deletions api/python/indigo/indigo/indigo_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ def __init__(self) -> None:
IndigoLib.lib.indigoLoadSmartsFromString.argtypes = [c_char_p]
IndigoLib.lib.indigoLoadSmartsFromFile.restype = c_int
IndigoLib.lib.indigoLoadSmartsFromFile.argtypes = [c_char_p]
IndigoLib.lib.indigoLoadSequenceFromString.restype = c_int
IndigoLib.lib.indigoLoadSequenceFromString.argtypes = [
c_char_p,
c_char_p,
]
IndigoLib.lib.indigoLoadSequenceFromFile.restype = c_int
IndigoLib.lib.indigoLoadSequenceFromFile.argtypes = [
c_char_p,
c_char_p,
]
IndigoLib.lib.indigoLoadReactionFromString.restype = c_int
IndigoLib.lib.indigoLoadReactionFromString.argtypes = [c_char_p]
IndigoLib.lib.indigoLoadReactionFromFile.restype = c_int
Expand Down
4 changes: 4 additions & 0 deletions api/tests/integration/ref/formats/seq_to_ket.py.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*** SEQUENCE to KET ***
all_aminoacids.ket:SUCCEED
rna_acgtu.ket:SUCCEED
dna_acgtu.ket:SUCCEED
Loading

0 comments on commit 940d5e0

Please sign in to comment.