Column rewriter and optimized View getter
This commit is contained in:
@ -3,12 +3,14 @@
|
||||
|
||||
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 ..dms cimport DMS
|
||||
|
||||
from ..column.column cimport Column
|
||||
|
||||
|
||||
cdef dict __OBIDMS_VIEW_CLASS__
|
||||
|
||||
@ -26,6 +28,12 @@ cdef class View(OBIWrapper):
|
||||
object current_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,
|
||||
list lines=*)
|
||||
|
||||
|
@ -17,7 +17,6 @@ from ..capi.obiview cimport Alias_column_pair_p, \
|
||||
|
||||
from ..capi.obidmscolumn cimport OBIDMS_column_p
|
||||
from ..capi.obidms cimport OBIDMS_p
|
||||
from ..capi.obitypes cimport obitype_t
|
||||
|
||||
from obitools3.utils cimport tobytes, \
|
||||
str2bytes, \
|
||||
@ -25,11 +24,10 @@ from obitools3.utils cimport tobytes, \
|
||||
|
||||
from ..object cimport OBIObjectClosedInstance
|
||||
|
||||
from ..column.column cimport Column
|
||||
|
||||
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_CHAR, \
|
||||
OBI_FLOAT, \
|
||||
@ -216,8 +214,6 @@ cdef class View(OBIWrapper) :
|
||||
bytes2str(column_name_b))
|
||||
|
||||
|
||||
|
||||
|
||||
cpdef rename_column(self,
|
||||
object current_name,
|
||||
object new_name):
|
||||
@ -237,6 +233,44 @@ cdef class View(OBIWrapper) :
|
||||
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):
|
||||
return Line_selection(self, lines)
|
||||
|
||||
@ -255,10 +289,10 @@ cdef class View(OBIWrapper) :
|
||||
|
||||
|
||||
def __getitem__(self, object item) :
|
||||
if type(item) == str :
|
||||
return self.get_column(item) # TODO hyper lent dans la pratique
|
||||
elif type(item) == int :
|
||||
if type(item) == int :
|
||||
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):
|
||||
@ -341,7 +375,7 @@ cdef class Line :
|
||||
value_b = str2bytes(value)
|
||||
else :
|
||||
value_b = value
|
||||
if only_ATGC(value_b) : # TODO detect IUPAC
|
||||
if is_a_DNA_seq(value_b) :
|
||||
value_obitype = OBI_SEQ
|
||||
elif len(value) == 1 :
|
||||
value_obitype = OBI_CHAR
|
||||
|
Reference in New Issue
Block a user