Changed the cython API to create new views so as to have different
functions for the different cases
This commit is contained in:
@ -77,7 +77,7 @@ def run(config):
|
|||||||
selection.append(i)
|
selection.append(i)
|
||||||
|
|
||||||
# Create output view with the line selection
|
# Create output view with the line selection
|
||||||
oview = d.new_view(config['obi']['outputview'], line_selection=selection, comments="obi grep: "+str(config['grep']['predicates'])+"\n")
|
oview = d.clone_view_with_line_selection(config['obi']['outputview'], selection, comments="obi grep: "+str(config['grep']['predicates'])+"\n")
|
||||||
|
|
||||||
#print("\n")
|
#print("\n")
|
||||||
#print(repr(oview))
|
#print(repr(oview))
|
||||||
|
@ -8,7 +8,7 @@ import string
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
|
|
||||||
VIEW_TYPES = [None, "NUC_SEQS_VIEW"]
|
VIEW_TYPES = ["", "NUC_SEQS_VIEW"]
|
||||||
COL_TYPES = ["OBI_BOOL", "OBI_CHAR", "OBI_FLOAT", "OBI_INT", "OBI_SEQ", "OBI_STR"]
|
COL_TYPES = ["OBI_BOOL", "OBI_CHAR", "OBI_FLOAT", "OBI_INT", "OBI_SEQ", "OBI_STR"]
|
||||||
NUC_SEQUENCE_COLUMN = "NUC_SEQ"
|
NUC_SEQUENCE_COLUMN = "NUC_SEQ"
|
||||||
ID_COLUMN = "ID"
|
ID_COLUMN = "ID"
|
||||||
@ -212,13 +212,12 @@ def fill_view(config, infos):
|
|||||||
def random_new_view(config, infos, first=False):
|
def random_new_view(config, infos, first=False):
|
||||||
v_to_clone = None
|
v_to_clone = None
|
||||||
line_selection = None
|
line_selection = None
|
||||||
clone = False
|
|
||||||
quality_col = False # TODO
|
quality_col = False # TODO
|
||||||
if not first:
|
if not first:
|
||||||
infos['view_names'].append(infos['view'].name)
|
infos['view_names'].append(infos['view'].name)
|
||||||
infos['view'].close()
|
infos['view'].close()
|
||||||
v_to_clone = infos['dms'].open_view(random.choice(infos["view_names"]))
|
v_to_clone = infos['dms'].open_view(random.choice(infos["view_names"]))
|
||||||
v_type = None
|
v_type = ""
|
||||||
print_test(config, "View to clone: ")
|
print_test(config, "View to clone: ")
|
||||||
print_test(config, repr(v_to_clone))
|
print_test(config, repr(v_to_clone))
|
||||||
create_line_selection = random_bool(config)
|
create_line_selection = random_bool(config)
|
||||||
@ -230,12 +229,14 @@ def random_new_view(config, infos, first=False):
|
|||||||
#print_test(config, "New line selection: "+str(line_selection))
|
#print_test(config, "New line selection: "+str(line_selection))
|
||||||
else :
|
else :
|
||||||
v_type = random_view_type()
|
v_type = random_view_type()
|
||||||
infos['view'] = infos['dms'].new_view(random_unique_name(infos),
|
|
||||||
view_to_clone=v_to_clone,
|
if line_selection is not None :
|
||||||
line_selection=line_selection,
|
infos['view'] = infos['dms'].clone_view_with_line_selection(random_unique_name(infos), line_selection, comments=random_str_with_max_len(config['test']['commentsmaxlen']))
|
||||||
view_type=v_type,
|
elif v_to_clone is not None :
|
||||||
comments=random_str_with_max_len(config['test']['commentsmaxlen']),
|
infos['view'] = infos['dms'].clone_view(random_unique_name(infos), v_to_clone, comments=random_str_with_max_len(config['test']['commentsmaxlen']))
|
||||||
quality_column=quality_col)
|
else :
|
||||||
|
infos['view'] = infos['dms'].new_view(random_unique_name(infos), view_type=v_type, comments=random_str_with_max_len(config['test']['commentsmaxlen']), quality_column=quality_col)
|
||||||
|
|
||||||
print_test(config, repr(infos['view']))
|
print_test(config, repr(infos['view']))
|
||||||
if v_to_clone is not None :
|
if v_to_clone is not None :
|
||||||
if line_selection is None:
|
if line_selection is None:
|
||||||
|
@ -63,6 +63,8 @@ cdef class OBIView:
|
|||||||
cpdef change_column_alias(self, str current_alias, str new_alias)
|
cpdef change_column_alias(self, str current_alias, str new_alias)
|
||||||
cpdef update_column_pointers(self)
|
cpdef update_column_pointers(self)
|
||||||
cpdef close(self)
|
cpdef close(self)
|
||||||
|
@staticmethod
|
||||||
|
cdef object get_view_subclass(str view_type)
|
||||||
|
|
||||||
|
|
||||||
cdef class OBIView_NUC_SEQS(OBIView):
|
cdef class OBIView_NUC_SEQS(OBIView):
|
||||||
@ -96,7 +98,11 @@ cdef class OBIDMS:
|
|||||||
cpdef close(self)
|
cpdef close(self)
|
||||||
cpdef OBI_Taxonomy open_taxonomy(self, str taxo_name)
|
cpdef OBI_Taxonomy open_taxonomy(self, str taxo_name)
|
||||||
cpdef OBIView open_view(self, str view_name)
|
cpdef OBIView open_view(self, str view_name)
|
||||||
cpdef OBIView new_view(self, str view_name, object view_to_clone=*, OBIView_line_selection line_selection=*, str view_type=*, str comments=*, bint quality_column=*)
|
|
||||||
|
cpdef OBIView new_view(self, str view_name, str view_type=*, bint quality_column=*, str comments=*)
|
||||||
|
cpdef OBIView clone_view(self, str view_name, object view_to_clone, str comments=*)
|
||||||
|
cpdef OBIView clone_view_with_line_selection(self, str view_name, OBIView_line_selection line_selection, str comments=*)
|
||||||
|
|
||||||
cpdef dict read_view_infos(self, str view_name)
|
cpdef dict read_view_infos(self, str view_name)
|
||||||
# cpdef dict read_views(self) TODO
|
# cpdef dict read_views(self) TODO
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ cdef class OBIDMS_column_line :
|
|||||||
|
|
||||||
cdef class OBIView :
|
cdef class OBIView :
|
||||||
|
|
||||||
def __init__(self, OBIDMS dms, str view_name, bint new=False, object view_to_clone=None, OBIView_line_selection line_selection=None, str comments="", bint quality_column=False, str view_type=None):
|
def __init__(self, OBIDMS dms, str view_name, bint new=False, object view_to_clone=None, OBIView_line_selection line_selection=None, str comments="", bint quality_column=False, str view_type=""):
|
||||||
|
|
||||||
cdef index_t* line_selection_p = NULL
|
cdef index_t* line_selection_p = NULL
|
||||||
cdef int i
|
cdef int i
|
||||||
@ -300,13 +300,13 @@ cdef class OBIView :
|
|||||||
self._columns[col_alias] = subclass(self, col_alias)
|
self._columns[col_alias] = subclass(self, col_alias)
|
||||||
|
|
||||||
|
|
||||||
cdef Obiview_p _open_or_create_view(self, OBIDMS dms, str view_name, bint new=False, object view_to_clone=None, index_t* line_selection_p=NULL, str comments="", bint quality_column=False, str view_type=None):
|
cdef Obiview_p _open_or_create_view(self, OBIDMS dms, str view_name, bint new=False, object view_to_clone=None, index_t* line_selection_p=NULL, str comments="", bint quality_column=False, str view_type=""):
|
||||||
|
|
||||||
cdef Obiview_p view = NULL
|
cdef Obiview_p view = NULL
|
||||||
|
|
||||||
# Create the view if needed, with the right type
|
# Create the view if needed, with the right type
|
||||||
if new :
|
if new :
|
||||||
if view_type is None :
|
if view_type == "" :
|
||||||
if view_to_clone is not None :
|
if view_to_clone is not None :
|
||||||
if type(view_to_clone) == str :
|
if type(view_to_clone) == str :
|
||||||
view = obi_new_view_cloned_from_name(dms._pointer, str2bytes(view_name), str2bytes(view_to_clone), line_selection_p, str2bytes(comments))
|
view = obi_new_view_cloned_from_name(dms._pointer, str2bytes(view_name), str2bytes(view_to_clone), line_selection_p, str2bytes(comments))
|
||||||
@ -507,6 +507,16 @@ cdef class OBIView :
|
|||||||
# TODO setter that concatenates new comments?
|
# TODO setter that concatenates new comments?
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
cdef object get_view_subclass(str view_type) :
|
||||||
|
cdef object subclass
|
||||||
|
if view_type == bytes2str(VIEW_TYPE_NUC_SEQS) :
|
||||||
|
view_class = OBIView_NUC_SEQS
|
||||||
|
else :
|
||||||
|
view_class = OBIView
|
||||||
|
return view_class
|
||||||
|
|
||||||
|
|
||||||
######################################################################################################
|
######################################################################################################
|
||||||
|
|
||||||
|
|
||||||
@ -685,39 +695,35 @@ cdef class OBIDMS :
|
|||||||
|
|
||||||
|
|
||||||
cpdef OBIView open_view(self, str view_name) :
|
cpdef OBIView open_view(self, str view_name) :
|
||||||
|
|
||||||
cdef object view_class
|
cdef object view_class
|
||||||
cdef dict view_infos
|
view_class = OBIView.get_view_subclass(self.read_view_infos(view_name)["view_type"])
|
||||||
|
|
||||||
view_infos = self.read_view_infos(view_name)
|
|
||||||
|
|
||||||
if view_infos["view_type"] == bytes2str(VIEW_TYPE_NUC_SEQS) :
|
|
||||||
view_class = OBIView_NUC_SEQS
|
|
||||||
else :
|
|
||||||
view_class = OBIView
|
|
||||||
|
|
||||||
return view_class(self, view_name)
|
return view_class(self, view_name)
|
||||||
|
|
||||||
|
|
||||||
cpdef OBIView new_view(self, str view_name, object view_to_clone=None, OBIView_line_selection line_selection=None, str view_type=None, str comments="", bint quality_column=False) :
|
cpdef OBIView new_view(self, str view_name, str view_type="", bint quality_column=False, str comments="") :
|
||||||
|
|
||||||
cdef object view_class
|
cdef object view_class
|
||||||
|
|
||||||
# Get right subclass depending on view type
|
# Get right subclass depending on view type
|
||||||
if view_type is not None :
|
view_class = OBIView.get_view_subclass(view_type)
|
||||||
if view_type == bytes2str(VIEW_TYPE_NUC_SEQS) :
|
return view_class(self, view_name, new=True, comments=comments, quality_column=quality_column, view_type=view_type)
|
||||||
view_class = OBIView_NUC_SEQS
|
|
||||||
else :
|
|
||||||
view_class = OBIView
|
|
||||||
# Check the type of the view to clone if there is one # TODO make generic for future other view types
|
|
||||||
if (view_to_clone is not None and \
|
|
||||||
((type(view_to_clone) == str and self.read_view_infos(view_to_clone)["view_type"] == bytes2str(VIEW_TYPE_NUC_SEQS)) or \
|
|
||||||
(type(view_to_clone) != str and view_to_clone.type == bytes2str(VIEW_TYPE_NUC_SEQS)))) or \
|
|
||||||
(line_selection is not None and (line_selection._view.type == bytes2str(VIEW_TYPE_NUC_SEQS))) :
|
|
||||||
view_type = bytes2str(VIEW_TYPE_NUC_SEQS)
|
|
||||||
view_class = OBIView_NUC_SEQS
|
|
||||||
|
|
||||||
return view_class(self, view_name, new=True, view_to_clone=view_to_clone, line_selection=line_selection, comments=comments, quality_column=quality_column, view_type=view_type)
|
|
||||||
|
cpdef OBIView clone_view(self, str view_name, object view_to_clone, str comments="") :
|
||||||
|
cdef object view_class
|
||||||
|
cdef str view_type
|
||||||
|
# Get right subclass depending on view type
|
||||||
|
if type(view_to_clone) == str :
|
||||||
|
view_type = self.read_view_infos(view_to_clone)["view_type"]
|
||||||
|
else :
|
||||||
|
view_type = view_to_clone.type
|
||||||
|
view_class = OBIView.get_view_subclass(view_type)
|
||||||
|
return view_class(self, view_name, new=True, view_to_clone=view_to_clone, comments=comments, view_type=view_type)
|
||||||
|
|
||||||
|
|
||||||
|
cpdef OBIView clone_view_with_line_selection(self, str view_name, OBIView_line_selection line_selection, str comments="") :
|
||||||
|
cdef object view_class
|
||||||
|
# Get right subclass depending on view type
|
||||||
|
view_class = OBIView.get_view_subclass(line_selection._view.type)
|
||||||
|
return view_class(self, view_name, new=True, view_to_clone=line_selection._view, line_selection=line_selection, comments=comments)
|
||||||
|
|
||||||
|
|
||||||
cpdef dict read_view_infos(self, str view_name) :
|
cpdef dict read_view_infos(self, str view_name) :
|
||||||
|
Reference in New Issue
Block a user