Column rewriter and optimized View getter
This commit is contained in:
@ -3,12 +3,14 @@
|
|||||||
|
|
||||||
from ..capi.obiview cimport Obiview_p
|
from ..capi.obiview cimport Obiview_p
|
||||||
|
|
||||||
from ..capi.obitypes cimport index_t
|
from ..capi.obitypes cimport index_t, obitype_t
|
||||||
|
|
||||||
from ..object cimport OBIWrapper
|
from ..object cimport OBIWrapper
|
||||||
|
|
||||||
from ..dms cimport DMS
|
from ..dms cimport DMS
|
||||||
|
|
||||||
|
from ..column.column cimport Column
|
||||||
|
|
||||||
|
|
||||||
cdef dict __OBIDMS_VIEW_CLASS__
|
cdef dict __OBIDMS_VIEW_CLASS__
|
||||||
|
|
||||||
@ -25,7 +27,13 @@ cdef class View(OBIWrapper):
|
|||||||
cpdef rename_column(self,
|
cpdef rename_column(self,
|
||||||
object current_name,
|
object current_name,
|
||||||
object new_name)
|
object new_name)
|
||||||
|
|
||||||
|
cpdef Column rewrite_column_with_diff_attributes(self,
|
||||||
|
object column_name,
|
||||||
|
obitype_t new_data_type=*,
|
||||||
|
index_t new_nb_elements_per_line=*,
|
||||||
|
list new_elements_names=*)
|
||||||
|
|
||||||
cpdef Line_selection new_selection(self,
|
cpdef Line_selection new_selection(self,
|
||||||
list lines=*)
|
list lines=*)
|
||||||
|
|
||||||
|
@ -17,19 +17,17 @@ from ..capi.obiview cimport Alias_column_pair_p, \
|
|||||||
|
|
||||||
from ..capi.obidmscolumn cimport OBIDMS_column_p
|
from ..capi.obidmscolumn cimport OBIDMS_column_p
|
||||||
from ..capi.obidms cimport OBIDMS_p
|
from ..capi.obidms cimport OBIDMS_p
|
||||||
from ..capi.obitypes cimport obitype_t
|
|
||||||
|
|
||||||
from obitools3.utils cimport tobytes, \
|
from obitools3.utils cimport tobytes, \
|
||||||
str2bytes, \
|
str2bytes, \
|
||||||
bytes2str
|
bytes2str
|
||||||
|
|
||||||
from ..object cimport OBIObjectClosedInstance
|
from ..object cimport OBIObjectClosedInstance
|
||||||
|
|
||||||
from ..column.column cimport Column
|
|
||||||
|
|
||||||
from obitools3.dms.view import typed_view
|
from obitools3.dms.view import typed_view
|
||||||
|
|
||||||
from ..capi.obitypes cimport only_ATGC, \
|
from ..capi.obitypes cimport is_a_DNA_seq, \
|
||||||
|
OBI_VOID, \
|
||||||
OBI_BOOL, \
|
OBI_BOOL, \
|
||||||
OBI_CHAR, \
|
OBI_CHAR, \
|
||||||
OBI_FLOAT, \
|
OBI_FLOAT, \
|
||||||
@ -191,10 +189,10 @@ cdef class View(OBIWrapper) :
|
|||||||
|
|
||||||
def get_column(self,
|
def get_column(self,
|
||||||
object column_name):
|
object column_name):
|
||||||
|
|
||||||
if not self.active() :
|
if not self.active() :
|
||||||
raise OBIObjectClosedInstance()
|
raise OBIObjectClosedInstance()
|
||||||
|
|
||||||
return Column.open(self, column_name)
|
return Column.open(self, column_name)
|
||||||
|
|
||||||
|
|
||||||
@ -214,8 +212,6 @@ cdef class View(OBIWrapper) :
|
|||||||
if obi_view_delete_column(self.pointer(), column_name_b) < 0 :
|
if obi_view_delete_column(self.pointer(), column_name_b) < 0 :
|
||||||
raise Exception("Problem deleting column %s from a view",
|
raise Exception("Problem deleting column %s from a view",
|
||||||
bytes2str(column_name_b))
|
bytes2str(column_name_b))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cpdef rename_column(self,
|
cpdef rename_column(self,
|
||||||
@ -236,7 +232,45 @@ cdef class View(OBIWrapper) :
|
|||||||
bytes2str(current_name_b),
|
bytes2str(current_name_b),
|
||||||
bytes2str(new_name_b)))
|
bytes2str(new_name_b)))
|
||||||
|
|
||||||
|
|
||||||
|
# TODO warning, not multithreading compliant
|
||||||
|
cpdef Column rewrite_column_with_diff_attributes(self,
|
||||||
|
object column_name,
|
||||||
|
obitype_t new_data_type=<obitype_t>OBI_VOID,
|
||||||
|
index_t new_nb_elements_per_line=0,
|
||||||
|
list new_elements_names=None) :
|
||||||
|
|
||||||
|
cdef Column old_column
|
||||||
|
cdef Column new_column
|
||||||
|
cdef index_t length = len(self)
|
||||||
|
|
||||||
|
old_column = self.get_column(column_name)
|
||||||
|
|
||||||
|
if new_data_type == 0 :
|
||||||
|
new_data_type = old_column.data_type
|
||||||
|
|
||||||
|
if new_nb_elements_per_line == 0 :
|
||||||
|
new_nb_elements_per_line = old_column.nb_elements_per_line
|
||||||
|
|
||||||
|
if new_elements_names is None :
|
||||||
|
new_elements_names = old_column.elements_names
|
||||||
|
|
||||||
|
new_column = Column.new_column(self, old_column.pointer().header.name, new_data_type,
|
||||||
|
nb_elements_per_line=new_nb_elements_per_line, elements_names=new_elements_names,
|
||||||
|
comments=old_column.comments, alias=tobytes(column_name)+tobytes('___new___'))
|
||||||
|
|
||||||
|
for i in range(length) :
|
||||||
|
new_column[i] = old_column[i]
|
||||||
|
|
||||||
|
# Remove old column from view
|
||||||
|
self.delete_column(column_name)
|
||||||
|
|
||||||
|
# Rename new
|
||||||
|
new_column.name = column_name
|
||||||
|
|
||||||
|
return new_column
|
||||||
|
|
||||||
|
|
||||||
cpdef Line_selection new_selection(self,list lines=None):
|
cpdef Line_selection new_selection(self,list lines=None):
|
||||||
return Line_selection(self, lines)
|
return Line_selection(self, lines)
|
||||||
|
|
||||||
@ -255,10 +289,10 @@ cdef class View(OBIWrapper) :
|
|||||||
|
|
||||||
|
|
||||||
def __getitem__(self, object item) :
|
def __getitem__(self, object item) :
|
||||||
if type(item) == str :
|
if type(item) == int :
|
||||||
return self.get_column(item) # TODO hyper lent dans la pratique
|
|
||||||
elif type(item) == int :
|
|
||||||
return Line(self, item)
|
return Line(self, item)
|
||||||
|
else : # TODO assume str or bytes for optimization?
|
||||||
|
return self.get_column(item) # TODO hyper lent dans la pratique
|
||||||
|
|
||||||
|
|
||||||
def __contains__(self, str column_name):
|
def __contains__(self, str column_name):
|
||||||
@ -341,7 +375,7 @@ cdef class Line :
|
|||||||
value_b = str2bytes(value)
|
value_b = str2bytes(value)
|
||||||
else :
|
else :
|
||||||
value_b = value
|
value_b = value
|
||||||
if only_ATGC(value_b) : # TODO detect IUPAC
|
if is_a_DNA_seq(value_b) :
|
||||||
value_obitype = OBI_SEQ
|
value_obitype = OBI_SEQ
|
||||||
elif len(value) == 1 :
|
elif len(value) == 1 :
|
||||||
value_obitype = OBI_CHAR
|
value_obitype = OBI_CHAR
|
||||||
|
Reference in New Issue
Block a user