Commit e323d8e7 authored by Celine Mercier's avatar Celine Mercier

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

view)
parent b350ea03
#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
......
../../../src/obidms.h
../../../src/obidms.c
../../../src/obiview.h
../../../src/obiview.c
../../../src/obidmscolumn.h
../../../src/obidmscolumn.c
../../../src/obidmscolumndir.h
../../../src/obidmscolumndir.c
../../../src/obierrno.h
../../../src/obierrno.c
../../../src/obilittlebigman.h
../../../src/obilittlebigman.c
../../../src/obitypes.h
../../../src/obitypes.c
../../../src/private_at_functions.h
../../../src/private_at_functions.c
../../../src/obiavl.h
../../../src/obiavl.c
#cython: language_level=3
from ._obidms cimport OBIView_line
cdef class OBI_Seq(dict) :
cdef str id
cdef str description
cdef str sequence
cpdef set_id(self, str id)
cpdef get_id(self)
cpdef set_description(self, str description)
cpdef get_description(self)
cpdef get_sequence(self)
cdef class OBI_Nuc_Seq(OBI_Seq) :
#cpdef str reverse_complement(self)
cpdef set_sequence(self, str sequence)
cdef class OBI_Nuc_Seq_Stored(OBIView_line) :
cdef str id
cdef str description
cdef str sequence
cpdef set_id(self, str id)
cpdef get_id(self)
cpdef set_description(self, str description)
cpdef get_description(self)
cpdef set_sequence(self, str sequence)
cpdef get_sequence(self)
# cpdef str reverse_complement(self)
#cython: language_level=3
from obitools3.utils cimport bytes2str, str2bytes
from .capi.obiview cimport NUC_SEQUENCE_COLUMN, \
ID_COLUMN, \
DESCRIPTION_COLUMN
cdef class OBI_Seq(dict) :
def __init__(self, str id, str seq, str description=None) :
self.set_id(id)
self.set_sequence(seq)
if description is not None :
self.set_description(description)
cpdef set_id(self, str id) :
self.id = id
self[bytes2str(ID_COLUMN)] = id
cpdef get_id(self) :
return self.id
cpdef set_description(self, str description) :
self.description = description
self[bytes2str(DESCRIPTION_COLUMN)] = description
cpdef get_description(self) :
return self.description
cpdef get_sequence(self) :
return self.sequence
def __str__(self) :
return self.sequence # or not
cdef class OBI_Nuc_Seq(OBI_Seq) :
cpdef set_sequence(self, str sequence) :
self.sequence = sequence
self[bytes2str(NUC_SEQUENCE_COLUMN)] = sequence
# cpdef str reverse_complement(self) : TODO in C ?
# pass
cdef class OBI_Nuc_Seq_Stored(OBIView_line) :
cpdef set_id(self, str id) :
self.id = id
self[bytes2str(ID_COLUMN)] = id
cpdef get_id(self) :
return self.id
cpdef set_description(self, str description) :
self.description = description
self[bytes2str(DESCRIPTION_COLUMN)] = description
cpdef get_description(self) :
return self.description
cpdef set_sequence(self, str sequence) :
self.sequence = sequence
self[bytes2str(NUC_SEQUENCE_COLUMN)] = sequence
cpdef get_sequence(self) :
return self.sequence
def __str__(self) :
return self.sequence # or not
# cpdef str reverse_complement(self) : TODO in C ?
# pass
# TODO static method to import?
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment