Added DMS method to create a DMS if it doesn't already exists, otherwise

opens it
This commit is contained in:
Celine Mercier
2017-07-28 09:55:43 +02:00
parent da48a9d1af
commit adf5cbef97
3 changed files with 27 additions and 19 deletions

View File

@ -147,11 +147,8 @@ def run(config):
inputs = uopen(config['import']['filename'])
# Create or open DMS
try:
d = DMS.test_open(config['obi']['defaultdms'])
except :
d = DMS.new(config['obi']['defaultdms'])
d = DMS.open_or_new(config['obi']['defaultdms'])
get_quality = False
NUC_SEQS_view = False
if config['import']['seqinformat']=='fasta':

View File

@ -12,6 +12,7 @@ cdef extern from "obidms.h" nogil:
OBIDMS_p obi_open_dms(const_char_p dms_path)
OBIDMS_p obi_test_open_dms(const_char_p dms_path)
OBIDMS_p obi_create_dms(const_char_p dms_path)
int obi_dms_exists(const char* dms_path)
int obi_close_dms(OBIDMS_p dms)
char* obi_dms_get_dms_path(OBIDMS_p dms)
char* obi_dms_get_full_path(OBIDMS_p dms, const_char_p path_name)

View File

@ -5,9 +5,9 @@ from libc.stdlib cimport free
from cpython.list cimport PyList_Size
from .capi.obidms cimport obi_open_dms, \
obi_test_open_dms, \
obi_create_dms, \
obi_close_dms, \
obi_dms_exists, \
obi_dms_get_full_path
from .capi.obitypes cimport const_char_p
@ -29,6 +29,29 @@ cdef class DMS(OBIWrapper):
cdef inline OBIDMS_p pointer(self):
return <OBIDMS_p>(self._pointer)
@staticmethod
def open_or_new(object dms_name) :
cdef OBIDMS_p pointer
cdef DMS dms
cdef bytes dms_name_b = tobytes(dms_name)
if DMS.exists(dms_name_b) :
pointer = obi_open_dms(<const_char_p> dms_name_b)
else :
pointer = obi_create_dms(<const_char_p> dms_name_b)
if pointer == NULL :
raise Exception("Failed opening or creating an OBIDMS")
dms = OBIWrapper.new_wrapper(DMS, pointer)
return dms
@staticmethod
def exists(object dms_name):
cdef bytes dms_name_b = tobytes(dms_name)
cdef int rep
rep = obi_dms_exists(dms_name_b)
if rep < 0 :
raise RuntimeError("Error checking if a DMS exists")
else :
return bool(rep)
@staticmethod
def new(object dms_name) :
@ -52,19 +75,6 @@ cdef class DMS(OBIWrapper):
raise Exception("Failed opening an OBIDMS")
dms = OBIWrapper.new_wrapper(DMS, pointer)
return dms
@staticmethod
def test_open(object dms_name) :
cdef OBIDMS_p pointer
cdef DMS dms
cdef bytes dms_name_b = tobytes(dms_name)
pointer = obi_test_open_dms(<const_char_p> dms_name_b)
if pointer != NULL :
dms = OBIWrapper.new_wrapper(DMS, pointer)
else :
dms = None
return dms
def close(self) :