New Cython API: compile but doesn't work
This commit is contained in:
@ -90,7 +90,7 @@ def addOptions(parser):
|
||||
|
||||
# TODO: Handling of NA values
|
||||
def run(config):
|
||||
pb = ProgressBar(10000, config, seconde=5) # TODO should be number of records in file
|
||||
pb = ProgressBar(35000000, config, seconde=5) # TODO should be number of records in file
|
||||
|
||||
inputs = uopen(config['import']['filename'])
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
from .capi.obidms cimport OBIDMS_p
|
||||
from .capi.obidmscolumn cimport OBIDMS_column_p
|
||||
from .capi.obiview cimport Obiview_p
|
||||
from .capi.obitypes cimport obiversion_t, OBIType_t, index_t
|
||||
from .capi.obitypes cimport index_t
|
||||
from ._obitaxo cimport OBI_Taxonomy
|
||||
from ._obiview cimport OBIView, OBIView_line_selection
|
||||
|
||||
|
||||
cdef class OBIDMS_column:
|
||||
@ -28,20 +28,6 @@ cdef class OBIDMS_column_line:
|
||||
|
||||
cdef OBIDMS_column _column
|
||||
cdef index_t _index
|
||||
|
||||
|
||||
|
||||
|
||||
cdef class OBIView_line :
|
||||
|
||||
cdef index_t _index
|
||||
cdef OBIView _view
|
||||
|
||||
|
||||
cdef class OBIView_line_selection(list):
|
||||
|
||||
cdef OBIView _view
|
||||
cdef str _view_name
|
||||
|
||||
|
||||
cdef class OBIDMS:
|
||||
@ -50,11 +36,3 @@ cdef class OBIDMS:
|
||||
|
||||
cpdef close(self)
|
||||
cpdef OBI_Taxonomy open_taxonomy(self, str taxo_name)
|
||||
|
||||
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_views(self) TODO
|
||||
|
||||
|
@ -6,7 +6,6 @@ from .capi.obidms cimport obi_dms, \
|
||||
obi_close_dms
|
||||
|
||||
from .capi.obidmscolumn cimport obi_close_column, \
|
||||
OBIDMS_column_p, \
|
||||
OBIDMS_column_header_p, \
|
||||
obi_get_elements_names
|
||||
|
||||
@ -21,16 +20,11 @@ from .capi.obitypes cimport const_char_p, \
|
||||
OBI_QUAL, \
|
||||
OBI_STR, \
|
||||
OBI_SEQ, \
|
||||
name_data_type, \
|
||||
only_ATGC # discuss
|
||||
|
||||
from ._obidms cimport OBIDMS, \
|
||||
OBIDMS_column, \
|
||||
OBIView, \
|
||||
OBIView_line
|
||||
|
||||
from ._obitaxo cimport OBI_Taxonomy
|
||||
name_data_type
|
||||
|
||||
from .capi.obiview cimport Obiview_p, \
|
||||
obi_view_get_pointer_on_column_in_view
|
||||
|
||||
from ._obidmscolumn_int cimport OBIDMS_column_int, \
|
||||
OBIDMS_column_multi_elts_int
|
||||
|
||||
@ -51,32 +45,8 @@ from ._obidmscolumn_str cimport OBIDMS_column_str, \
|
||||
|
||||
from ._obidmscolumn_seq cimport OBIDMS_column_seq, \
|
||||
OBIDMS_column_multi_elts_seq
|
||||
|
||||
from .capi.obiview cimport Obiview_p, \
|
||||
Obiview_infos_p, \
|
||||
Alias_column_pair_p, \
|
||||
obi_new_view_nuc_seqs, \
|
||||
obi_new_view, \
|
||||
obi_new_view_cloned_from_name, \
|
||||
obi_new_view_nuc_seqs_cloned_from_name, \
|
||||
obi_view_map_file, \
|
||||
obi_view_unmap_file, \
|
||||
obi_open_view, \
|
||||
obi_view_delete_column, \
|
||||
obi_view_add_column, \
|
||||
obi_view_create_column_alias, \
|
||||
obi_view_get_column, \
|
||||
obi_view_get_pointer_on_column_in_view, \
|
||||
obi_save_and_close_view, \
|
||||
VIEW_TYPE_NUC_SEQS, \
|
||||
NUC_SEQUENCE_COLUMN, \
|
||||
ID_COLUMN, \
|
||||
DEFINITION_COLUMN, \
|
||||
QUALITY_COLUMN
|
||||
|
||||
from libc.stdlib cimport malloc, free
|
||||
|
||||
|
||||
from libc.stdlib cimport free
|
||||
|
||||
|
||||
cdef class OBIDMS_column :
|
||||
@ -93,7 +63,7 @@ cdef class OBIDMS_column :
|
||||
# Fill structure
|
||||
self._alias = column_alias
|
||||
self._pointer = column_pp
|
||||
self._view = view
|
||||
self._view = view
|
||||
|
||||
def __setitem__(self, index_t line_nb, object value):
|
||||
self.set_line(line_nb, value)
|
||||
@ -269,88 +239,6 @@ cdef class OBIDMS_column_line :
|
||||
######################################################################################################
|
||||
|
||||
|
||||
cdef class OBIView_line :
|
||||
|
||||
def __init__(self, OBIView view, index_t line_nb) :
|
||||
self._index = line_nb
|
||||
self._view = view
|
||||
|
||||
def __getitem__(self, str column_name) :
|
||||
return ((self._view)._columns)[column_name][self._index]
|
||||
|
||||
def __setitem__(self, str column_name, object value):
|
||||
# TODO detect multiple elements (dict type)? put somewhere else? but more risky (in get)
|
||||
# TODO OBI_QUAL ?
|
||||
cdef type value_type
|
||||
cdef str value_obitype
|
||||
cdef bytes value_b
|
||||
|
||||
if column_name not in self._view :
|
||||
if value == None :
|
||||
raise Exception("Trying to create a column from a None value (can't guess type)")
|
||||
value_type = type(value)
|
||||
if value_type == int :
|
||||
value_obitype = 'OBI_INT'
|
||||
elif value_type == float :
|
||||
value_obitype = 'OBI_FLOAT'
|
||||
elif value_type == bool :
|
||||
value_obitype = 'OBI_BOOL'
|
||||
elif value_type == str or value_type == bytes :
|
||||
if value_type == str :
|
||||
value_b = str2bytes(value)
|
||||
else :
|
||||
value_b = value
|
||||
if only_ATGC(value_b) : # TODO detect IUPAC
|
||||
value_obitype = 'OBI_SEQ'
|
||||
elif len(value) == 1 :
|
||||
value_obitype = 'OBI_CHAR'
|
||||
elif (len(value) > 1) :
|
||||
value_obitype = 'OBI_STR'
|
||||
else :
|
||||
raise Exception("Could not guess the type of a value to create a new column")
|
||||
self._view.add_column(column_name, type=value_obitype)
|
||||
|
||||
(((self._view)._columns)[column_name]).set_line(self._index, value)
|
||||
|
||||
def __iter__(self):
|
||||
for column_name in ((self._view)._columns) :
|
||||
yield column_name
|
||||
|
||||
def __contains__(self, str column_name):
|
||||
return (column_name in self._view._columns)
|
||||
|
||||
def __repr__(self):
|
||||
cdef dict line
|
||||
cdef str column_name
|
||||
line = {}
|
||||
for column_name in self._view._columns :
|
||||
line[column_name] = self[column_name]
|
||||
return str(line)
|
||||
|
||||
|
||||
######################################################################################################
|
||||
|
||||
|
||||
cdef class OBIView_line_selection(list):
|
||||
|
||||
def __init__(self, OBIView view) :
|
||||
if view._pointer == NULL:
|
||||
raise Exception("Error: trying to create a line selection with an invalidated view")
|
||||
self._view = view
|
||||
self._view_name = view.name
|
||||
|
||||
def append(self, index_t idx) :
|
||||
if idx >= self._view.line_count :
|
||||
raise Exception("Error: trying to select a line beyond the line count of a view")
|
||||
# if idx in self : # TODO discuss. Discuss order too
|
||||
# pass
|
||||
# else :
|
||||
super(OBIView_line_selection, self).append(idx)
|
||||
|
||||
|
||||
######################################################################################################
|
||||
|
||||
|
||||
cdef class OBIDMS :
|
||||
|
||||
def __init__(self, str dms_name) :
|
||||
@ -380,115 +268,4 @@ cdef class OBIDMS :
|
||||
|
||||
cpdef OBI_Taxonomy open_taxonomy(self, str taxo_name) :
|
||||
return OBI_Taxonomy(self, taxo_name)
|
||||
|
||||
|
||||
cpdef OBIView new_view(self, str view_name, str view_type="", bint quality_column=False, str comments="") :
|
||||
cdef object view_class
|
||||
# Get right subclass depending on view type
|
||||
view_class = OBIView.get_view_subclass(view_type)
|
||||
return view_class(self, view_name, new=True, 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 # @DuplicatedSignature
|
||||
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 # @DuplicatedSignature
|
||||
# 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) :
|
||||
|
||||
cdef Obiview_infos_p view_infos_p
|
||||
cdef dict view_infos_d
|
||||
cdef Alias_column_pair_p column_refs
|
||||
cdef int i, j
|
||||
cdef str column_name
|
||||
|
||||
view_infos_p = obi_view_map_file(self._pointer, str2bytes(view_name), True)
|
||||
view_infos_d = {}
|
||||
view_infos_d["name"] = bytes2str(view_infos_p.name)
|
||||
view_infos_d["comments"] = bytes2str(view_infos_p.comments)
|
||||
view_infos_d["view_type"] = bytes2str(view_infos_p.view_type)
|
||||
view_infos_d["column_count"] = <int> view_infos_p.column_count
|
||||
view_infos_d["line_count"] = <int> view_infos_p.line_count
|
||||
view_infos_d["created_from"] = bytes2str(view_infos_p.created_from)
|
||||
view_infos_d["creation_date"] = bytes2str(obi_format_date(view_infos_p.creation_date))
|
||||
if (view_infos_p.all_lines) :
|
||||
view_infos_d["line_selection"] = None
|
||||
else :
|
||||
view_infos_d["line_selection"] = {}
|
||||
view_infos_d["line_selection"]["column_name"] = bytes2str((view_infos_p.line_selection).column_name)
|
||||
view_infos_d["line_selection"]["version"] = <int> (view_infos_p.line_selection).version
|
||||
view_infos_d["column_references"] = {}
|
||||
column_references = view_infos_p.column_references
|
||||
for j in range(view_infos_d["column_count"]) :
|
||||
column_name = bytes2str((column_references[j]).alias)
|
||||
view_infos_d["column_references"][column_name] = {}
|
||||
view_infos_d["column_references"][column_name]["original_name"] = bytes2str((column_references[j]).column_refs.column_name)
|
||||
view_infos_d["column_references"][column_name]["version"] = (column_references[j]).column_refs.version
|
||||
|
||||
obi_view_unmap_file(self._pointer, view_infos_p)
|
||||
|
||||
return view_infos_d
|
||||
|
||||
|
||||
# cpdef dict read_views(self) : # TODO function that prints the dic nicely and function that prints 1 view nicely. Add column type in col ref
|
||||
#
|
||||
# cdef Obiviews_infos_all_p all_views_p
|
||||
# cdef Obiview_infos_p view_p
|
||||
# cdef Column_reference_p column_refs
|
||||
# cdef int nb_views
|
||||
# cdef int i, j
|
||||
# cdef str view_name
|
||||
# cdef str column_name
|
||||
# cdef dict views
|
||||
# cdef bytes name_b
|
||||
#
|
||||
# views = {}
|
||||
# all_views_p = obi_read_view_infos(self._pointer)
|
||||
# if all_views_p == NULL :
|
||||
# raise Exception("No views to read")
|
||||
# nb_views = <int> (all_views_p.header).view_count
|
||||
# for i in range(nb_views) :
|
||||
# view_p = (<Obiview_infos_p> (all_views_p.view_infos)) + i
|
||||
# view_name = bytes2str(view_p.name)
|
||||
# views[view_name] = {}
|
||||
# views[view_name]["comments"] = bytes2str(view_p.comments)
|
||||
# views[view_name]["view_type"] = bytes2str(view_p.view_type)
|
||||
# views[view_name]["column_count"] = <int> view_p.column_count
|
||||
# views[view_name]["line_count"] = <int> view_p.line_count
|
||||
# views[view_name]["view_number"] = <int> view_p.view_number
|
||||
# views[view_name]["created_from"] = bytes2str(view_p.created_from)
|
||||
# views[view_name]["creation_date"] = bytes2str(obi_format_date(view_p.creation_date))
|
||||
# if (view_p.all_lines) :
|
||||
# views[view_name]["line_selection"] = None
|
||||
# else :
|
||||
# views[view_name]["line_selection"] = {}
|
||||
# views[view_name]["line_selection"]["column_name"] = bytes2str((view_p.line_selection).column_name)
|
||||
# views[view_name]["line_selection"]["version"] = <int> (view_p.line_selection).version
|
||||
# views[view_name]["column_references"] = {}
|
||||
# column_refs = view_p.column_references
|
||||
# for j in range(views[view_name]["column_count"]) :
|
||||
# column_name = bytes2str((column_refs[j]).column_name)
|
||||
# views[view_name]["column_references"][column_name] = {}
|
||||
# views[view_name]["column_references"][column_name]["version"] = column_refs[j].version
|
||||
#
|
||||
# obi_close_view_infos(all_views_p);
|
||||
#
|
||||
# return views
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -75,3 +75,4 @@ cdef class OBIDMS_column_multi_elts_bool(OBIDMS_column_multi_elts):
|
||||
value = OBIBool_NA
|
||||
if obi_set_bool_with_elt_name_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, str2bytes(element_name), <obibool_t> value) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from ._obidms cimport OBIView_line
|
||||
from ._obiview cimport OBIView_line
|
||||
|
||||
|
||||
cdef class OBI_Seq(dict) :
|
||||
|
@ -6,7 +6,6 @@ from .capi.obiview cimport NUC_SEQUENCE_COLUMN, \
|
||||
ID_COLUMN, \
|
||||
DEFINITION_COLUMN, \
|
||||
QUALITY_COLUMN
|
||||
from docutils.nodes import definition
|
||||
|
||||
|
||||
cdef str __str__ID_COLUMN__ = bytes2str(ID_COLUMN)
|
||||
|
@ -1,27 +1,33 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from ._obidms cimport OBIDMS
|
||||
|
||||
from .capi.obiview cimport Obiview_p
|
||||
from .capi.obitypes cimport obiversion_t, index_t
|
||||
|
||||
|
||||
cdef class OBIView:
|
||||
|
||||
cdef Obiview_p _pointer
|
||||
cdef dict _columns
|
||||
|
||||
cdef __init_columns__(self):
|
||||
cdef __init_columns__(self)
|
||||
|
||||
cpdef OBIView clone(self,
|
||||
str view_name,
|
||||
OBIView_line_selection line_selection=*,
|
||||
str comments=*)
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView new(OBIDMS dms,
|
||||
cdef OBIView new(OBIDMS dms,
|
||||
str view_name,
|
||||
str comments=*)
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView open(OBIDMS dms,
|
||||
cdef OBIView open(OBIDMS dms,
|
||||
str view_name)
|
||||
|
||||
cpdef delete_column(self, str column_name)
|
||||
|
||||
cpdef add_column(self,
|
||||
str column_name,
|
||||
obiversion_t version_number=*,
|
||||
@ -36,18 +42,28 @@ cdef class OBIView:
|
||||
str comments=*,
|
||||
bint create=*
|
||||
)
|
||||
|
||||
cpdef change_column_alias(self, str current_alias, str new_alias)
|
||||
|
||||
cpdef update_column_pointers(self)
|
||||
|
||||
cpdef OBIView_line_selection new_selection(self,
|
||||
list lines=*)
|
||||
|
||||
|
||||
cdef class OBIView_line :
|
||||
|
||||
cdef index_t _index
|
||||
cdef OBIView _view
|
||||
|
||||
|
||||
cdef class OBIView_line_selection(list):
|
||||
|
||||
cdef OBIView _view
|
||||
cdef str _view_name
|
||||
|
||||
cdef index_t* __build_binary_list__(self)
|
||||
|
||||
cpdef OBIView materialize(self,
|
||||
str view_name,
|
||||
str comments=*)
|
||||
|
@ -1,5 +1,33 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from obitools3.utils cimport bytes2str, str2bytes
|
||||
|
||||
from .capi.obitypes cimport OBI_INT, \
|
||||
OBI_FLOAT, \
|
||||
OBI_BOOL, \
|
||||
OBI_CHAR, \
|
||||
OBI_QUAL, \
|
||||
OBI_STR, \
|
||||
OBI_SEQ, \
|
||||
only_ATGC
|
||||
|
||||
from .capi.obiview cimport Obiview_p, \
|
||||
obi_new_view, \
|
||||
obi_open_view, \
|
||||
obi_view_delete_column, \
|
||||
obi_view_add_column, \
|
||||
obi_view_create_column_alias, \
|
||||
obi_view_get_column, \
|
||||
obi_view_get_pointer_on_column_in_view, \
|
||||
obi_save_and_close_view
|
||||
|
||||
from .capi.obidmscolumn cimport OBIDMS_column_p
|
||||
|
||||
from ._obidms cimport OBIDMS, \
|
||||
OBIDMS_column
|
||||
|
||||
from libc.stdlib cimport malloc
|
||||
|
||||
|
||||
cdef class OBIView :
|
||||
|
||||
@ -8,7 +36,8 @@ cdef class OBIView :
|
||||
raise RuntimeError('OBIView constructor cannot be called directly')
|
||||
self._pointer = NULL
|
||||
self._columns = {}
|
||||
|
||||
|
||||
|
||||
cdef __init_columns__(self):
|
||||
cdef size_t i
|
||||
cdef str col_alias
|
||||
@ -42,12 +71,13 @@ cdef class OBIView :
|
||||
view_name)
|
||||
)
|
||||
|
||||
view.__init_columns__(self)
|
||||
view.__init_columns__()
|
||||
|
||||
return view
|
||||
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView new(OBIDMS dms,
|
||||
cdef OBIView new(OBIDMS dms,
|
||||
str view_name,
|
||||
str comments=""):
|
||||
|
||||
@ -62,12 +92,13 @@ cdef class OBIView :
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot create view %s" % view_name)
|
||||
|
||||
view.__init_columns__(self)
|
||||
view.__init_columns__()
|
||||
|
||||
return view
|
||||
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView open(OBIDMS dms,
|
||||
cdef OBIView open(OBIDMS dms,
|
||||
str view_name):
|
||||
|
||||
cdef OBIView view = OBIView(987654) # @DuplicatedSignature
|
||||
@ -78,10 +109,11 @@ cdef class OBIView :
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot open view %s" % view_name)
|
||||
|
||||
view.__init_columns__(self)
|
||||
view.__init_columns__()
|
||||
|
||||
return view
|
||||
|
||||
|
||||
def __dealloc__(self):
|
||||
if (obi_save_and_close_view(self._pointer) < 0) :
|
||||
raise Exception("Problem closing a view")
|
||||
@ -187,9 +219,11 @@ cdef class OBIView :
|
||||
column = self._columns[column_n]
|
||||
column._pointer = <OBIDMS_column_p*> obi_view_get_pointer_on_column_in_view(self._pointer, str2bytes(column_n))
|
||||
|
||||
|
||||
cpdef OBIView_line_selection new_selection(self,list lines=None):
|
||||
return OBIView_line_selection(self,lines)
|
||||
|
||||
|
||||
def __iter__(self):
|
||||
# Iteration on each line of all columns
|
||||
|
||||
@ -254,6 +288,70 @@ cdef class OBIView :
|
||||
# TODO setter that concatenates new comments?
|
||||
|
||||
|
||||
cdef class OBIView_line :
|
||||
|
||||
def __init__(self, OBIView view, index_t line_nb) :
|
||||
self._index = line_nb
|
||||
self._view = view
|
||||
|
||||
|
||||
def __getitem__(self, str column_name) :
|
||||
return ((self._view)._columns)[column_name][self._index]
|
||||
|
||||
|
||||
def __setitem__(self, str column_name, object value):
|
||||
# TODO detect multiple elements (dict type)? put somewhere else? but more risky (in get)
|
||||
# TODO OBI_QUAL ?
|
||||
cdef type value_type
|
||||
cdef str value_obitype
|
||||
cdef bytes value_b
|
||||
|
||||
if column_name not in self._view :
|
||||
if value == None :
|
||||
raise Exception("Trying to create a column from a None value (can't guess type)")
|
||||
value_type = type(value)
|
||||
if value_type == int :
|
||||
value_obitype = 'OBI_INT'
|
||||
elif value_type == float :
|
||||
value_obitype = 'OBI_FLOAT'
|
||||
elif value_type == bool :
|
||||
value_obitype = 'OBI_BOOL'
|
||||
elif value_type == str or value_type == bytes :
|
||||
if value_type == str :
|
||||
value_b = str2bytes(value)
|
||||
else :
|
||||
value_b = value
|
||||
if only_ATGC(value_b) : # TODO detect IUPAC
|
||||
value_obitype = 'OBI_SEQ'
|
||||
elif len(value) == 1 :
|
||||
value_obitype = 'OBI_CHAR'
|
||||
elif (len(value) > 1) :
|
||||
value_obitype = 'OBI_STR'
|
||||
else :
|
||||
raise Exception("Could not guess the type of a value to create a new column")
|
||||
self._view.add_column(column_name, type=value_obitype)
|
||||
|
||||
(((self._view)._columns)[column_name]).set_line(self._index, value)
|
||||
|
||||
|
||||
def __iter__(self):
|
||||
for column_name in ((self._view)._columns) :
|
||||
yield column_name
|
||||
|
||||
|
||||
def __contains__(self, str column_name):
|
||||
return (column_name in self._view._columns)
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
cdef dict line
|
||||
cdef str column_name
|
||||
line = {}
|
||||
for column_name in self._view._columns :
|
||||
line[column_name] = self[column_name]
|
||||
return str(line)
|
||||
|
||||
|
||||
cdef class OBIView_line_selection(list):
|
||||
|
||||
def __init__(self, OBIView view, lines=None) :
|
||||
@ -264,7 +362,8 @@ cdef class OBIView_line_selection(list):
|
||||
|
||||
if lines is not None:
|
||||
self.extend(lines)
|
||||
|
||||
|
||||
|
||||
def extend(self, iterable):
|
||||
cdef index_t i
|
||||
cdef index_t max_i = self._view.line_count
|
||||
@ -277,28 +376,31 @@ cdef class OBIView_line_selection(list):
|
||||
self._view_name)
|
||||
)
|
||||
list.append(self,i)
|
||||
|
||||
|
||||
|
||||
def append(self, index_t idx) :
|
||||
if idx >= self._view.line_count :
|
||||
raise RuntimeError("Error: trying to select line %d beyond the line count %d of view %s" %
|
||||
(i,
|
||||
max_i,
|
||||
(idx,
|
||||
self._view.line_count,
|
||||
self._view_name)
|
||||
)
|
||||
list.append(self,idx)
|
||||
|
||||
|
||||
|
||||
cdef index_t* __build_binary_list__(self):
|
||||
cdef index_t* line_selection_p = NULL
|
||||
cdef int i
|
||||
cdef size_t l_selection = len(self)
|
||||
cdef size_t len_selection = len(self)
|
||||
|
||||
line_selection_p = <index_t*> malloc((l_selection + 1) * sizeof(index_t)) # +1 for the -1 flagging the end of the array
|
||||
for i in range(l_selection) :
|
||||
line_selection_p[i] = line_selection[i]
|
||||
line_selection_p[l_selection] = -1 # flagging the end of the array
|
||||
line_selection_p = <index_t*> malloc((len_selection + 1) * sizeof(index_t)) # +1 for the -1 flagging the end of the array
|
||||
for i in range(len_selection) :
|
||||
line_selection_p[i] = self[i]
|
||||
line_selection_p[len_selection] = -1 # flagging the end of the array
|
||||
|
||||
return line_selection_p
|
||||
|
||||
|
||||
|
||||
cpdef OBIView materialize(self,
|
||||
str view_name,
|
||||
str comments=""):
|
||||
@ -312,12 +414,12 @@ cdef class OBIView_line_selection(list):
|
||||
str2bytes(comments))
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot clone view %s into view %s"
|
||||
raise RuntimeError("Error: Cannot clone view %s into view %s"
|
||||
% (str(self.name),
|
||||
view_name)
|
||||
)
|
||||
|
||||
view.__init_columns__(self)
|
||||
view.__init_columns__()
|
||||
|
||||
return view
|
||||
|
||||
|
@ -1,25 +1,29 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from ._obidms cimport OBIView
|
||||
from ._obiseq cimport OBI_Nuc_Seq, OBI_Nuc_Seq_Stored
|
||||
from ._obidms cimport OBIDMS
|
||||
from ._obiview cimport OBIView, OBIView_line_selection
|
||||
|
||||
|
||||
cdef class OBIView_NUC_SEQS_QUAL(OBIView_NUC_SEQS):
|
||||
cdef class OBIView_NUC_SEQS(OBIView):
|
||||
|
||||
cpdef OBIView clone(self,
|
||||
str view_name,
|
||||
OBIView_line_selection line_selection=*,
|
||||
str new_view_name,
|
||||
str comments=*)
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView new(OBIDMS dms,
|
||||
str view_name,
|
||||
str comments=*)
|
||||
cpdef OBIView_line_selection new_selection(self, list lines=*)
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView open(OBIDMS dms,
|
||||
str view_name)
|
||||
cdef OBIView new(OBIDMS dms,
|
||||
str view_name,
|
||||
str comments=*)
|
||||
|
||||
@staticmethod
|
||||
cdef OBIView open(OBIDMS dms,
|
||||
str view_name)
|
||||
|
||||
|
||||
cdef class OBIView_NUC_SEQS_line_selection(OBIView_line_selection):
|
||||
|
||||
cpdef OBIView materialize(self,
|
||||
str view_name,
|
||||
str comments=*)
|
||||
|
@ -2,17 +2,24 @@
|
||||
|
||||
from .capi.obitypes cimport index_t
|
||||
|
||||
from ._obiseq cimport OBI_Nuc_Seq, OBI_Nuc_Seq_Stored
|
||||
|
||||
from .capi.obiview cimport obi_new_view_nuc_seqs, \
|
||||
obi_open_view
|
||||
|
||||
from obitools3.utils cimport str2bytes
|
||||
|
||||
|
||||
cdef class OBIView_NUC_SEQS(OBIView):
|
||||
|
||||
cpdef OBIView clone(self,
|
||||
str view_name,
|
||||
str comments=""):
|
||||
str new_view_name,
|
||||
str comments=""):
|
||||
|
||||
cdef OBIView view = OBIView_NUC_SEQS(987654)
|
||||
|
||||
view._pointer = obi_new_view_nuc_seqs(self._pointer.dms,
|
||||
str2bytes(view_name),
|
||||
str2bytes(new_view_name),
|
||||
self._pointer,
|
||||
NULL,
|
||||
str2bytes(comments),
|
||||
@ -20,18 +27,17 @@ cdef class OBIView_NUC_SEQS(OBIView):
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot clone view %s into view %s"
|
||||
% (str(self.name),
|
||||
view_name)
|
||||
)
|
||||
% (str(self.name), new_view_name))
|
||||
|
||||
view.__init_columns__(self)
|
||||
view.__init_columns__()
|
||||
|
||||
return view
|
||||
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView new(OBIDMS dms,
|
||||
str view_name,
|
||||
str comments=""):
|
||||
cdef OBIView new(OBIDMS dms,
|
||||
str view_name,
|
||||
str comments=""):
|
||||
|
||||
cdef OBIView view = OBIView_NUC_SEQS(987654) # @DuplicatedSignature
|
||||
|
||||
@ -45,13 +51,14 @@ cdef class OBIView_NUC_SEQS(OBIView):
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot create view %s" % view_name)
|
||||
|
||||
view.__init_columns__(self)
|
||||
view.__init_columns__()
|
||||
|
||||
return view
|
||||
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView open(OBIDMS dms,
|
||||
str view_name):
|
||||
cdef OBIView open(OBIDMS dms,
|
||||
str view_name):
|
||||
|
||||
cdef OBIView view = OBIView_NUC_SEQS(987654) # @DuplicatedSignature
|
||||
|
||||
@ -61,12 +68,14 @@ cdef class OBIView_NUC_SEQS(OBIView):
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot open view %s" % view_name)
|
||||
|
||||
view.__init_columns__(self)
|
||||
view.__init_columns__()
|
||||
|
||||
return view
|
||||
|
||||
cpdef OBIView_line_selection new_selection(self,list lines=None):
|
||||
return OBIView_NUC_SEQS_line_selection(self,lines)
|
||||
|
||||
cpdef OBIView_line_selection new_selection(self, list lines=None):
|
||||
return OBIView_NUC_SEQS_line_selection(self, lines)
|
||||
|
||||
|
||||
def __getitem__(self, object item) :
|
||||
if type(item) == str :
|
||||
@ -88,18 +97,17 @@ cdef class OBIView_NUC_SEQS_line_selection(OBIView_line_selection):
|
||||
|
||||
cdef OBIView view = OBIView_NUC_SEQS(987654)
|
||||
|
||||
view._pointer = obi_new_view(self._view._pointer.dms,
|
||||
str2bytes(view_name),
|
||||
self._view._pointer,
|
||||
self.__build_binary_list__(),
|
||||
str2bytes(comments))
|
||||
view._pointer = obi_new_view_nuc_seqs(self._view._pointer.dms,
|
||||
str2bytes(view_name),
|
||||
self._view._pointer,
|
||||
self.__build_binary_list__(),
|
||||
str2bytes(comments),
|
||||
False)
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot clone view %s into view %s"
|
||||
% (str(self.name),
|
||||
view_name)
|
||||
)
|
||||
% (str(self.name), view_name))
|
||||
|
||||
view.__init_columns__(self)
|
||||
view.__init_columns__()
|
||||
|
||||
return view
|
||||
|
@ -1,23 +1,26 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from ._obidms cimport OBIView
|
||||
from ._obiseq cimport OBI_Nuc_Seq, OBI_Nuc_Seq_Stored
|
||||
from .capi.obitypes cimport index_t
|
||||
|
||||
from ._obidms cimport OBIDMS
|
||||
from ._obiview cimport OBIView
|
||||
from ._obiview_nuc_seq cimport OBIView_NUC_SEQS, OBIView_NUC_SEQS_line_selection
|
||||
|
||||
|
||||
cdef class OBIView_NUC_SEQS_QUAL(OBIView_NUC_SEQS):
|
||||
cpdef OBIView clone(self,
|
||||
str view_name,
|
||||
OBIView_line_selection line_selection=*,
|
||||
str comments=*)
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView new(OBIDMS dms,
|
||||
str view_name,
|
||||
str comments=*)
|
||||
cdef OBIView new(OBIDMS dms,
|
||||
str view_name,
|
||||
str comments=*)
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView open(OBIDMS dms,
|
||||
str view_name)
|
||||
cdef OBIView open(OBIDMS dms,
|
||||
str view_name)
|
||||
|
||||
|
||||
cdef class OBIView_NUC_SEQS_QUAL_line_selection(OBIView_NUC_SEQS_line_selection):
|
||||
cpdef OBIView materialize(self,
|
||||
|
@ -2,12 +2,17 @@
|
||||
|
||||
from .capi.obitypes cimport index_t
|
||||
|
||||
from .capi.obiview cimport obi_new_view_nuc_seqs, \
|
||||
obi_open_view
|
||||
|
||||
from obitools3.utils cimport bytes2str, str2bytes
|
||||
|
||||
|
||||
cdef class OBIView_NUC_SEQS_QUAL(OBIView_NUC_SEQS):
|
||||
|
||||
cpdef OBIView clone(self,
|
||||
str view_name,
|
||||
str comments=""):
|
||||
str view_name,
|
||||
str comments=""):
|
||||
|
||||
cdef OBIView view = OBIView_NUC_SEQS_QUAL(987654)
|
||||
|
||||
@ -20,18 +25,17 @@ cdef class OBIView_NUC_SEQS_QUAL(OBIView_NUC_SEQS):
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot clone view %s into view %s"
|
||||
% (str(self.name),
|
||||
view_name)
|
||||
)
|
||||
% (str(self.name), view_name))
|
||||
|
||||
view.__init_columns__(self)
|
||||
view.__init_columns__()
|
||||
|
||||
return view
|
||||
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView new(OBIDMS dms,
|
||||
str view_name,
|
||||
str comments=""):
|
||||
cdef OBIView new(OBIDMS dms,
|
||||
str view_name,
|
||||
str comments=""):
|
||||
|
||||
cdef OBIView view = OBIView_NUC_SEQS_QUAL(987654) # @DuplicatedSignature
|
||||
|
||||
@ -43,15 +47,16 @@ cdef class OBIView_NUC_SEQS_QUAL(OBIView_NUC_SEQS):
|
||||
True)
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot create view %s" % view_name)
|
||||
raise RuntimeError("Error: Cannot create view %s" % view_name)
|
||||
|
||||
view.__init_columns__(self)
|
||||
view.__init_columns__()
|
||||
|
||||
return view
|
||||
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView open(OBIDMS dms,
|
||||
str view_name):
|
||||
cdef OBIView open(OBIDMS dms,
|
||||
str view_name):
|
||||
|
||||
cdef OBIView view = OBIView_NUC_SEQS_QUAL(987654) # @DuplicatedSignature
|
||||
|
||||
@ -59,12 +64,13 @@ cdef class OBIView_NUC_SEQS_QUAL(OBIView_NUC_SEQS):
|
||||
str2bytes(view_name))
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot open view %s" % view_name)
|
||||
raise RuntimeError("Error: Cannot open view %s" % view_name)
|
||||
|
||||
view.__init_columns__(self)
|
||||
view.__init_columns__()
|
||||
|
||||
return view
|
||||
|
||||
|
||||
|
||||
cdef class OBIView_NUC_SEQS_QUAL_line_selection(OBIView_NUC_SEQS_line_selection):
|
||||
|
||||
cpdef OBIView materialize(self,
|
||||
@ -73,11 +79,12 @@ cdef class OBIView_NUC_SEQS_QUAL_line_selection(OBIView_NUC_SEQS_line_selection)
|
||||
|
||||
cdef OBIView view = OBIView_NUC_SEQS_QUAL(987654)
|
||||
|
||||
view._pointer = obi_new_view(self._view._pointer.dms,
|
||||
str2bytes(view_name),
|
||||
self._view._pointer,
|
||||
self.__build_binary_list__(),
|
||||
str2bytes(comments))
|
||||
view._pointer = obi_new_view_nuc_seqs(self._view._pointer.dms,
|
||||
str2bytes(view_name),
|
||||
self._view._pointer,
|
||||
self.__build_binary_list__(),
|
||||
str2bytes(comments),
|
||||
True)
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot clone view %s into view %s"
|
||||
@ -85,6 +92,6 @@ cdef class OBIView_NUC_SEQS_QUAL_line_selection(OBIView_NUC_SEQS_line_selection)
|
||||
view_name)
|
||||
)
|
||||
|
||||
view.__init_columns__(self)
|
||||
view.__init_columns__()
|
||||
|
||||
return view
|
||||
|
Reference in New Issue
Block a user