From fc5a12bad7a7992d5676cd4681e658b280f6b13e Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Mon, 29 Feb 2016 17:56:55 +0100 Subject: [PATCH] Closes #34 --- python/obitools3/obidms/_obidms.pxd | 3 ++- python/obitools3/obidms/_obidms.pyx | 24 +++++++++++++----------- python/obitools3/obidms/_obiseq.cfiles | 4 ++++ python/obitools3/obidms/capi/obiview.pxd | 10 ++++++---- src/obiview.c | 19 +++++++++++-------- src/obiview.h | 18 ++++++++++++------ 6 files changed, 48 insertions(+), 30 deletions(-) diff --git a/python/obitools3/obidms/_obidms.pxd b/python/obitools3/obidms/_obidms.pxd index d7df7d0..92ff1e2 100644 --- a/python/obitools3/obidms/_obidms.pxd +++ b/python/obitools3/obidms/_obidms.pxd @@ -43,6 +43,7 @@ cdef class OBIView: cdef Obiview_p pointer cdef str name + cdef str comments cdef dict columns cdef dict columns_pp # TODO this dict might be unnecessary cdef OBIDMS dms @@ -86,7 +87,7 @@ cdef class OBIDMS: cpdef close(self) cpdef OBIView open_view(self, str view_name) - cpdef OBIView new_view(self, str view_name, object view_to_clone=*, list line_selection=*, str view_type=*) + cpdef OBIView new_view(self, str view_name, object view_to_clone=*, list line_selection=*, str view_type=*, str comments=*) cpdef dict read_view_infos(self, str view_name) cpdef dict read_views(self) diff --git a/python/obitools3/obidms/_obidms.pyx b/python/obitools3/obidms/_obidms.pyx index a2ec7f5..aed4743 100644 --- a/python/obitools3/obidms/_obidms.pyx +++ b/python/obitools3/obidms/_obidms.pyx @@ -231,7 +231,7 @@ cdef class OBIDMS_column_line : cdef class OBIView : - def __init__(self, OBIDMS dms, str view_name, bint new=False, object view_to_clone=None, list line_selection=None): + def __init__(self, OBIDMS dms, str view_name, bint new=False, object view_to_clone=None, list line_selection=None, str comments=""): cdef Obiview_p view = NULL cdef int i @@ -256,11 +256,11 @@ cdef class OBIView : if new : if view_to_clone is not None : if type(view_to_clone) == str : - view = obi_new_view_cloned_from_name(dms.pointer, str2bytes(view_name), str2bytes(view_to_clone), line_selection_p) + view = obi_new_view_cloned_from_name(dms.pointer, str2bytes(view_name), str2bytes(view_to_clone), line_selection_p, str2bytes(comments)) else : - view = obi_new_view(dms.pointer, str2bytes(view_name), ( view_to_clone).pointer, line_selection_p) + view = obi_new_view(dms.pointer, str2bytes(view_name), ( view_to_clone).pointer, line_selection_p, str2bytes(comments)) elif view_to_clone is None : - view = obi_new_view(dms.pointer, str2bytes(view_name), NULL, line_selection_p) + view = obi_new_view(dms.pointer, str2bytes(view_name), NULL, line_selection_p, str2bytes(comments)) elif not new : if view_name is not None : view = obi_open_view(dms.pointer, str2bytes(view_name)) @@ -300,7 +300,7 @@ cdef class OBIView : cdef OBIDMS_column_p column_p s = self.name - s = s + ", " + str(self.pointer.line_count) + " lines" + s = s + ", " + self.comments + ", " + str(self.pointer.line_count) + " lines" for column_name in self.columns : # TODO make function in OBIDMS_column class column = self.columns[column_name] column_p = (column.pointer)[0] @@ -461,7 +461,7 @@ cdef class OBIView : cdef class OBIView_NUC_SEQS(OBIView): - def __init__(self, OBIDMS dms, str view_name, bint new=False, object view_to_clone=None, list line_selection=None): + def __init__(self, OBIDMS dms, str view_name, bint new=False, object view_to_clone=None, list line_selection=None, str comments=""): cdef Obiview_p view = NULL cdef int i @@ -486,11 +486,11 @@ cdef class OBIView_NUC_SEQS(OBIView): if new : if view_to_clone is not None : if type(view_to_clone) == str : - view = obi_new_view_nuc_seqs_cloned_from_name(dms.pointer, str2bytes(view_name), str2bytes(view_to_clone), line_selection_p) + view = obi_new_view_nuc_seqs_cloned_from_name(dms.pointer, str2bytes(view_name), str2bytes(view_to_clone), line_selection_p, str2bytes(comments)) else : - view = obi_new_view_nuc_seqs(dms.pointer, str2bytes(view_name), ( view_to_clone).pointer, line_selection_p) + view = obi_new_view_nuc_seqs(dms.pointer, str2bytes(view_name), ( view_to_clone).pointer, line_selection_p, str2bytes(comments)) elif view_to_clone is None : - view = obi_new_view_nuc_seqs(dms.pointer, str2bytes(view_name), NULL, line_selection_p) + view = obi_new_view_nuc_seqs(dms.pointer, str2bytes(view_name), NULL, line_selection_p, str2bytes(comments)) elif not new : if view_name is not None : view = obi_open_view(dms.pointer, str2bytes(view_name)) @@ -502,6 +502,7 @@ cdef class OBIView_NUC_SEQS(OBIView): self.pointer = view self.name = bytes2str(view.name) + self.comments = bytes2str(view.comments) # go through columns to build list and open python object (TODO make separate function?) self.columns = {} @@ -663,7 +664,7 @@ cdef class OBIDMS : return view_class(self, view_name) - cpdef OBIView new_view(self, str view_name, object view_to_clone=None, list line_selection=None, str view_type=None) : + cpdef OBIView new_view(self, str view_name, object view_to_clone=None, list line_selection=None, str view_type=None, str comments="") : cdef object view_class @@ -673,7 +674,7 @@ cdef class OBIDMS : else : view_class = OBIView - return view_class(self, view_name, new=True, view_to_clone=view_to_clone, line_selection=line_selection) + return view_class(self, view_name, new=True, view_to_clone=view_to_clone, line_selection=line_selection, comments=comments) cpdef dict read_view_infos(self, str view_name) : @@ -700,6 +701,7 @@ cdef class OBIDMS : view_p = ( (all_views_p.view_infos)) + i view_name = bytes2str(view_p.name) views[view_name] = {} + views[view_name]["comments"] = bytes2str(view_p.comments) views[view_name]["view_type"] = bytes2str(view_p.view_type) views[view_name]["column_count"] = view_p.column_count views[view_name]["line_count"] = view_p.line_count diff --git a/python/obitools3/obidms/_obiseq.cfiles b/python/obitools3/obidms/_obiseq.cfiles index c92a0c5..b5b7b4f 100644 --- a/python/obitools3/obidms/_obiseq.cfiles +++ b/python/obitools3/obidms/_obiseq.cfiles @@ -16,3 +16,7 @@ ../../../src/private_at_functions.c ../../../src/obiavl.h ../../../src/obiavl.c +../../../src/encode.h +../../../src/encode.c +../../../src/obidmscolumn_idx.h +../../../src/obidmscolumn_idx.c diff --git a/python/obitools3/obidms/capi/obiview.pxd b/python/obitools3/obidms/capi/obiview.pxd index 3733eed..29d9f37 100644 --- a/python/obitools3/obidms/capi/obiview.pxd +++ b/python/obitools3/obidms/capi/obiview.pxd @@ -33,6 +33,7 @@ cdef extern from "obiview.h" nogil: Column_reference_t line_selection_reference index_t line_count int column_count + const_char_p comments ctypedef Obiview_t* Obiview_p @@ -48,6 +49,7 @@ cdef extern from "obiview.h" nogil: Column_reference_t line_selection Column_reference_p column_references const_char_p view_type + const_char_p comments ctypedef Obiview_infos_t* Obiview_infos_p @@ -67,13 +69,13 @@ cdef extern from "obiview.h" nogil: ctypedef Obiviews_infos_all_t* Obiviews_infos_all_p - Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const_char_p view_name, Obiview_p view_to_clone, index_t* line_selection) + Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const_char_p view_name, Obiview_p view_to_clone, index_t* line_selection, const_char_p comments) - Obiview_p obi_new_view(OBIDMS_p dms, const_char_p view_name, Obiview_p view_to_clone, index_t* line_selection) + Obiview_p obi_new_view(OBIDMS_p dms, const_char_p view_name, Obiview_p view_to_clone, index_t* line_selection, const_char_p comments) - Obiview_p obi_new_view_cloned_from_name(OBIDMS_p dms, const_char_p view_name, const_char_p view_to_clone_name, index_t* line_selection) + Obiview_p obi_new_view_cloned_from_name(OBIDMS_p dms, const_char_p view_name, const_char_p view_to_clone_name, index_t* line_selection, const_char_p comments) - Obiview_p obi_new_view_nuc_seqs_cloned_from_name(OBIDMS_p dms, const_char_p view_name, const_char_p view_to_clone_name, index_t* line_selection) + Obiview_p obi_new_view_nuc_seqs_cloned_from_name(OBIDMS_p dms, const_char_p view_name, const_char_p view_to_clone_name, index_t* line_selection, const_char_p comments) Obiview_p obi_open_view(OBIDMS_p dms, const_char_p view_name) diff --git a/src/obiview.c b/src/obiview.c index f51c024..a5410dd 100644 --- a/src/obiview.c +++ b/src/obiview.c @@ -209,7 +209,7 @@ int create_obiview_file(int dms_file_descriptor) **********************************************************************/ -Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const char* view_name, Obiview_p view_to_clone, index_t* line_selection) +Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const char* view_name, Obiview_p view_to_clone, index_t* line_selection, const char* comments) { Obiview_p view; @@ -223,7 +223,7 @@ Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const char* view_name, Obiview_p v } } - view = obi_new_view(dms, view_name, view_to_clone, line_selection); + view = obi_new_view(dms, view_name, view_to_clone, line_selection, comments); strcpy(view->view_type, VIEW_TYPE_NUC_SEQS); @@ -253,7 +253,7 @@ Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const char* view_name, Obiview_p v } -Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_clone, index_t* line_selection) +Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_clone, index_t* line_selection, const char* comments) { Obiview_p view; int i; @@ -278,7 +278,7 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl return NULL; } - view->dms = dms; + view->dms = dms; view->column_count = view_to_clone->column_count; if ((view_to_clone->line_selection != NULL) && (line_selection == NULL)) // reorder conditions { @@ -359,13 +359,14 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl } strcpy(view->name, view_name); + strcpy(view->comments, comments); view->read_only = 0; return view; } -Obiview_p obi_new_view_cloned_from_name(OBIDMS_p dms, const char* view_name, const char* view_to_clone_name, index_t* line_selection) +Obiview_p obi_new_view_cloned_from_name(OBIDMS_p dms, const char* view_name, const char* view_to_clone_name, index_t* line_selection, const char* comments) { Obiview_p view; Obiview_p view_to_clone; @@ -373,7 +374,7 @@ Obiview_p obi_new_view_cloned_from_name(OBIDMS_p dms, const char* view_name, con view_to_clone = obi_open_view(dms, view_to_clone_name); if (view_to_clone == NULL) return NULL; - view = obi_new_view(dms, view_name, view_to_clone, line_selection); + view = obi_new_view(dms, view_name, view_to_clone, line_selection, comments); obi_close_view(view_to_clone); @@ -381,7 +382,7 @@ Obiview_p obi_new_view_cloned_from_name(OBIDMS_p dms, const char* view_name, con } -Obiview_p obi_new_view_nuc_seqs_cloned_from_name(OBIDMS_p dms, const char* view_name, const char* view_to_clone_name, index_t* line_selection) +Obiview_p obi_new_view_nuc_seqs_cloned_from_name(OBIDMS_p dms, const char* view_name, const char* view_to_clone_name, index_t* line_selection, const char* comments) { Obiview_p view; Obiview_p view_to_clone; @@ -389,7 +390,7 @@ Obiview_p obi_new_view_nuc_seqs_cloned_from_name(OBIDMS_p dms, const char* view_ view_to_clone = obi_open_view(dms, view_to_clone_name); if (view_to_clone == NULL) return NULL; - view = obi_new_view_nuc_seqs(dms, view_name, view_to_clone, line_selection); + view = obi_new_view_nuc_seqs(dms, view_name, view_to_clone, line_selection, comments); obi_close_view(view_to_clone); @@ -532,6 +533,7 @@ Obiview_p obi_open_view(OBIDMS_p dms, const char* view_name) strcpy(view->created_from, view_infos->created_from); strcpy(view->name, view_infos->name); strcpy(view->view_type, view_infos->view_type); + strcpy(view->comments, view_infos->comments); // Open the columns to read for (i=0; i<(view_infos->column_count); i++) @@ -1033,6 +1035,7 @@ int obi_save_view(Obiview_p view) strcpy(view_infos->created_from, view->created_from); strcpy(view_infos->name, view->name); strcpy(view_infos->view_type, view->view_type); + strcpy(view_infos->comments, view->comments); // Store reference for the line selection associated with that view if (view->new_line_selection != NULL) diff --git a/src/obiview.h b/src/obiview.h index 2f5eb89..9241dbc 100644 --- a/src/obiview.h +++ b/src/obiview.h @@ -26,8 +26,10 @@ #include "obierrno.h" -#define OBIVIEW_NAME_MAX_LENGTH (10239) /**< The maximum length of an OBIDMS view name. - */ +#define OBIVIEW_NAME_MAX_LENGTH (1000) /**< The maximum length of an OBIDMS view name. + */ +#define OBIVIEW_COMMENTS_MAX_LENGTH (10000) + #define OBIVIEW_FILE_NAME "obiviews" #define VIEW_TYPE_MAX_NAME (1024) @@ -84,6 +86,8 @@ typedef struct Obiview { char view_type[VIEW_TYPE_MAX_NAME+1]; + char comments[OBIVIEW_COMMENTS_MAX_LENGTH+1]; + } Obiview_t, *Obiview_p; @@ -111,6 +115,8 @@ typedef struct Obiview_infos { char view_type[VIEW_TYPE_MAX_NAME+1]; + char comments[OBIVIEW_COMMENTS_MAX_LENGTH+1]; + } Obiview_infos_t, *Obiview_infos_p; @@ -135,13 +141,13 @@ typedef struct Obiviews_infos_all { } Obiviews_infos_all_t, *Obiviews_infos_all_p; -Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const char* view_name, Obiview_p view_to_clone, index_t* line_selection); +Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const char* view_name, Obiview_p view_to_clone, index_t* line_selection, const char* comments); -Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_clone, index_t* line_selection); +Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_clone, index_t* line_selection, const char* comments); -Obiview_p obi_new_view_cloned_from_name(OBIDMS_p dms, const char* view_name, const char* view_to_clone_name, index_t* line_selection); +Obiview_p obi_new_view_cloned_from_name(OBIDMS_p dms, const char* view_name, const char* view_to_clone_name, index_t* line_selection, const char* comments); -Obiview_p obi_new_view_nuc_seqs_cloned_from_name(OBIDMS_p dms, const char* view_name, const char* view_to_clone_name, index_t* line_selection); +Obiview_p obi_new_view_nuc_seqs_cloned_from_name(OBIDMS_p dms, const char* view_name, const char* view_to_clone_name, index_t* line_selection, const char* comments); Obiview_p obi_open_view(OBIDMS_p dms, const char* view_name);