Cython classes for nucleotide sequences (outside or in the context of a

view)
This commit is contained in:
Celine Mercier
2016-02-29 16:33:30 +01:00
parent b350ea0393
commit e323d8e702
4 changed files with 151 additions and 10 deletions

View File

@ -1,7 +1,5 @@
#cython: language_level=3
from pathlib import Path
from obitools3.utils cimport bytes2str, str2bytes
from .capi.obidms cimport obi_dms, \
@ -23,9 +21,12 @@ from .capi.obitypes cimport const_char_p, \
name_data_type, \
only_ATGC # discuss
from ._obidms cimport OBIDMS
from ._obidms cimport OBIDMS_column
from ._obidms cimport OBIView_line
from ._obidms cimport OBIDMS, \
OBIDMS_column, \
OBIView, \
OBIView_line
from ._obiseq cimport OBI_Nuc_Seq, OBI_Nuc_Seq_Stored
from ._obidmscolumn_int cimport OBIDMS_column_int, \
OBIDMS_column_multi_elts_int
@ -45,8 +46,6 @@ from ._obidmscolumn_str cimport OBIDMS_column_str, \
from ._obidmscolumn_seq cimport OBIDMS_column_seq, \
OBIDMS_column_multi_elts_seq
from ._obidms cimport OBIView, OBIView_line
from .capi.obiview cimport Obiview_p, \
Obiviews_infos_all_p, \
Obiview_infos_p, \
@ -414,7 +413,7 @@ cdef class OBIView :
# Declarations
cdef index_t lines_used
cdef index_t line_nb
cdef OBIView_line line
cdef OBIView_line line # TODO for NUC SEQS View
# Yield each line TODO line class
lines_used = (self.pointer).line_count
@ -563,6 +562,18 @@ cdef class OBIView_NUC_SEQS(OBIView):
for column_n in self.columns :
(self.columns[column_n]).update_pointer()
def __getitem__(self, object item) :
if type(item) == str :
return (self.columns)[item]
elif type(item) == int : # TODO int?
return OBI_Nuc_Seq_Stored(self, item)
def __setitem__(self, index_t line_idx, OBI_Nuc_Seq sequence_obj) :
for key in sequence_obj :
self[line_idx][key] = sequence_obj[key]
#############################################
@ -644,7 +655,7 @@ cdef class OBIDMS :
view_infos = self.read_view_infos(view_name)
if view_infos["view_type"] == bytes2str(VIEW_TYPE_NUC_SEQS) : # TODO not gonna work
if view_infos["view_type"] == bytes2str(VIEW_TYPE_NUC_SEQS) :
view_class = OBIView_NUC_SEQS
else :
view_class = OBIView
@ -657,7 +668,7 @@ cdef class OBIDMS :
cdef object view_class
if view_type is not None :
if view_type == bytes2str(VIEW_TYPE_NUC_SEQS) : # TODO not gonna work
if view_type == bytes2str(VIEW_TYPE_NUC_SEQS) :
view_class = OBIView_NUC_SEQS
else :
view_class = OBIView