Major update: Column aliases. Columns are now identified in the context

of a view by an alias that can be modified.
This commit is contained in:
Celine Mercier
2016-08-01 18:25:30 +02:00
parent 3843485a04
commit 312f50ff0f
17 changed files with 760 additions and 114 deletions

View File

@ -8,6 +8,8 @@
../../../src/dna_seq_indexer.c
../../../src/encode.h
../../../src/encode.c
../../../src/hashtable.h
../../../src/hashtable.c
../../../src/murmurhash2.h
../../../src/murmurhash2.c
../../../src/obi_align.h

View File

@ -18,7 +18,6 @@ cdef class OBIDMS_column:
cdef index_t nb_elements_per_line
cdef list elements_names
cpdef update_pointer(self)
cpdef list get_elements_names(self)
cpdef str get_data_type(self)
cpdef index_t get_nb_lines_used(self)
@ -52,6 +51,7 @@ cdef class OBIView:
cpdef add_column(self,
str column_name,
obiversion_t version_number=*,
str alias=*,
str type=*,
index_t nb_lines=*,
index_t nb_elements_per_line=*,
@ -62,6 +62,8 @@ cdef class OBIView:
str comments=*,
bint create=*
)
cpdef change_column_alias(self, str current_alias, str new_alias)
cpdef update_column_pointers(self)
cpdef select_line(self, index_t line_nb)
cpdef select_lines(self, list line_selection)
cpdef save_and_close(self)

View File

@ -55,7 +55,7 @@ from ._obidmscolumn_seq cimport OBIDMS_column_seq, \
from .capi.obiview cimport Obiview_p, \
Obiview_infos_p, \
Column_reference_p, \
Alias_column_pair_p, \
obi_new_view_nuc_seqs, \
obi_new_view, \
obi_new_view_cloned_from_name, \
@ -65,7 +65,7 @@ from .capi.obiview cimport Obiview_p, \
obi_open_view, \
obi_view_delete_column, \
obi_view_add_column, \
obi_view_get_column, \
obi_view_create_column_alias, \
obi_view_get_column, \
obi_view_get_pointer_on_column_in_view, \
obi_select_line, \
@ -124,9 +124,6 @@ cdef class OBIDMS_column :
for line_nb in range(lines_used):
yield self.get_line(line_nb)
cpdef update_pointer(self):
self.pointer = <OBIDMS_column_p*> obi_view_get_pointer_on_column_in_view(self.view.pointer, str2bytes(self.column_name))
cpdef list get_elements_names(self):
return self.elements_names
@ -297,16 +294,16 @@ cdef class OBIView :
for i in range(view.infos.column_count) :
column_p = <OBIDMS_column_p> (view.columns)[i]
header = (column_p).header
col_name = bytes2str(header.name)
col_name = bytes2str(view.infos.column_references[i].alias)
subclass = OBIDMS_column.get_subclass_type(column_p)
self.columns[col_name] = subclass(self, col_name)
def __repr__(self) :
cdef str s
s = str(self.name) + "\n" + str(self.comments) + "\n" + str(self.pointer.infos.line_count) + " lines\n"
for column_name in self.columns :
s = s + self.columns[column_name].__repr__() + '\n'
s = s + column_name + ": " + self.columns[column_name].__repr__() + '\n'
return s
@ -317,15 +314,15 @@ cdef class OBIView :
if obi_view_delete_column(self.pointer, str2bytes(column_name)) < 0 :
raise Exception("Problem deleting a column from a view")
# Update the dictionaries of column pointers and column objects, and update pointers in column objects (make function?):
# Update the dictionary of column objects:
(self.columns).pop(column_name)
for column_n in self.columns :
(self.columns[column_n]).update_pointer()
self.update_column_pointers()
cpdef add_column(self,
str column_name,
obiversion_t version_number=-1,
str alias='',
str type='',
index_t nb_lines=0,
index_t nb_elements_per_line=1,
@ -343,6 +340,11 @@ cdef class OBIView :
cdef OBIDMS_column_p column_p
column_name_b = str2bytes(column_name)
if alias == '' :
alias = column_name
alias_b = column_name_b
else :
alias_b = str2bytes(alias)
if nb_elements_per_line > 1 :
elements_names_b = str2bytes(';'.join(elements_names))
@ -366,8 +368,8 @@ cdef class OBIView :
data_type = OBI_SEQ
else :
raise Exception("Invalid provided data type")
if (obi_view_add_column(self.pointer, column_name_b, version_number, # TODO should return pointer on column?
if (obi_view_add_column(self.pointer, column_name_b, version_number, alias_b, # TODO should return pointer on column?
data_type, nb_lines, nb_elements_per_line,
elements_names_b, str2bytes(indexer_name),
str2bytes(associated_column_name), associated_column_version,
@ -375,12 +377,28 @@ cdef class OBIView :
raise Exception("Problem adding a column in a view")
# Get the column pointer
column_p = obi_view_get_column(self.pointer, column_name_b)
column_p = obi_view_get_column(self.pointer, alias_b)
# Open and store the subclass
subclass = OBIDMS_column.get_subclass_type(column_p)
(self.columns)[column_name] = subclass(self, column_name)
(self.columns)[alias] = subclass(self, alias)
cpdef change_column_alias(self, str current_alias, str new_alias):
if (obi_view_create_column_alias(self.pointer, str2bytes(current_alias), str2bytes(new_alias)) < 0) :
raise Exception("Problem changing a column alias")
# Update the dictionaries of column column objects
self.columns[new_alias] = self.columns[current_alias]
(self.columns).pop(current_alias)
cpdef update_column_pointers(self):
cdef str column_n
cdef OBIDMS_column column
for column_n in self.columns :
column = self.columns[column_n]
column.pointer = <OBIDMS_column_p*> obi_view_get_pointer_on_column_in_view(self.pointer, str2bytes(column_n))
cpdef save_and_close(self) :
if (obi_save_and_close_view(self.pointer) < 0) :
@ -488,7 +506,7 @@ cdef class OBIView_NUC_SEQS(OBIView):
for i in range(view.infos.column_count) :
column_p = <OBIDMS_column_p> (view.columns)[i]
header = (column_p).header
col_name = bytes2str(header.name)
col_name = bytes2str(view.infos.column_references[i].alias)
subclass = OBIDMS_column.get_subclass_type(column_p)
self.columns[col_name] = subclass(self, col_name)
@ -548,7 +566,7 @@ cdef class OBIView_line :
(((self.view).columns)[column_name]).set_line(self.index, value)
def __contains__(self, str column_name):
return (column_name in self.view)
return (column_name in self.view.columns)
def __repr__(self):
cdef dict line
@ -618,7 +636,7 @@ cdef class OBIDMS :
cdef Obiview_infos_p view_infos_p
cdef dict view_infos_d
cdef Column_reference_p column_refs
cdef Alias_column_pair_p column_refs
cdef int i, j
cdef str column_name
@ -638,11 +656,12 @@ cdef class OBIDMS :
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_refs = view_infos_p.column_references
column_references = view_infos_p.column_references
for j in range(view_infos_d["column_count"]) :
column_name = bytes2str((column_refs[j]).column_name)
column_name = bytes2str((column_references[j]).alias)
view_infos_d["column_references"][column_name] = {}
view_infos_d["column_references"][column_name]["version"] = column_refs[j].version
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)

View File

@ -8,6 +8,8 @@
../../../src/dna_seq_indexer.c
../../../src/encode.h
../../../src/encode.c
../../../src/hashtable.h
../../../src/hashtable.c
../../../src/murmurhash2.h
../../../src/murmurhash2.c
../../../src/obi_align.h

View File

@ -8,6 +8,8 @@
../../../src/dna_seq_indexer.c
../../../src/encode.h
../../../src/encode.c
../../../src/hashtable.h
../../../src/hashtable.c
../../../src/murmurhash2.h
../../../src/murmurhash2.c
../../../src/obi_align.h

View File

@ -8,6 +8,8 @@
../../../src/dna_seq_indexer.c
../../../src/encode.h
../../../src/encode.c
../../../src/hashtable.h
../../../src/hashtable.c
../../../src/murmurhash2.h
../../../src/murmurhash2.c
../../../src/obi_align.h

View File

@ -8,6 +8,8 @@
../../../src/dna_seq_indexer.c
../../../src/encode.h
../../../src/encode.c
../../../src/hashtable.h
../../../src/hashtable.c
../../../src/murmurhash2.h
../../../src/murmurhash2.c
../../../src/obi_align.h

View File

@ -8,6 +8,8 @@
../../../src/dna_seq_indexer.c
../../../src/encode.h
../../../src/encode.c
../../../src/hashtable.h
../../../src/hashtable.c
../../../src/murmurhash2.h
../../../src/murmurhash2.c
../../../src/obi_align.h

View File

@ -8,6 +8,8 @@
../../../src/dna_seq_indexer.c
../../../src/encode.h
../../../src/encode.c
../../../src/hashtable.h
../../../src/hashtable.c
../../../src/murmurhash2.h
../../../src/murmurhash2.c
../../../src/obi_align.h

View File

@ -8,6 +8,8 @@
../../../src/dna_seq_indexer.c
../../../src/encode.h
../../../src/encode.c
../../../src/hashtable.h
../../../src/hashtable.c
../../../src/murmurhash2.h
../../../src/murmurhash2.c
../../../src/obi_align.h

View File

@ -8,6 +8,8 @@
../../../src/dna_seq_indexer.c
../../../src/encode.h
../../../src/encode.c
../../../src/hashtable.h
../../../src/hashtable.c
../../../src/murmurhash2.h
../../../src/murmurhash2.c
../../../src/obi_align.h

View File

@ -8,6 +8,8 @@
../../../src/dna_seq_indexer.c
../../../src/encode.h
../../../src/encode.c
../../../src/hashtable.h
../../../src/hashtable.c
../../../src/murmurhash2.h
../../../src/murmurhash2.c
../../../src/obi_align.h

View File

@ -26,6 +26,13 @@ cdef extern from "obiview.h" nogil:
extern const_char_p QUALITY_COLUMN
struct Alias_column_pair_t :
Column_reference_t column_refs
const_char_p alias
ctypedef Alias_column_pair_t* Alias_column_pair_p
struct Obiview_infos_t :
time_t creation_date
const_char_p name
@ -35,7 +42,7 @@ cdef extern from "obiview.h" nogil:
Column_reference_t line_selection
index_t line_count
int column_count
Column_reference_p column_references
Alias_column_pair_p column_references
const_char_p comments
ctypedef Obiview_infos_t* Obiview_infos_p
@ -48,7 +55,9 @@ cdef extern from "obiview.h" nogil:
OBIDMS_column_p line_selection
OBIDMS_column_p new_line_selection
OBIDMS_column_p columns
int nb_predicates
# TODO declarations for column dictionary and predicate function array?
ctypedef Obiview_t* Obiview_p
@ -69,6 +78,7 @@ cdef extern from "obiview.h" nogil:
int obi_view_add_column(Obiview_p view,
const_char_p column_name,
obiversion_t version_number,
const_char_p alias,
OBIType_t data_type,
index_t nb_lines,
index_t nb_elements_per_line,
@ -89,6 +99,8 @@ cdef extern from "obiview.h" nogil:
OBIDMS_column_p* obi_view_get_pointer_on_column_in_view(Obiview_p view, const_char_p column_name)
int obi_view_create_column_alias(Obiview_p view, const_char_p current_name, const_char_p alias)
int obi_save_view(Obiview_p view)
int obi_close_view(Obiview_p view)