From 3e6aecc63591ad3ea2c20943f91938b9b583e4c4 Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Tue, 11 Jul 2017 16:44:23 +0200 Subject: [PATCH] Added a C function to add a COUNT column to a view with all lines set to 1 --- src/obiview.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- src/obiview.h | 20 ++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/obiview.c b/src/obiview.c index e2d7543..e84d506 100644 --- a/src/obiview.c +++ b/src/obiview.c @@ -1188,8 +1188,6 @@ static int prepare_to_set_value_in_column(Obiview_p view, OBIDMS_column_p* colum } } - // TODO add line_max - if (((*line_nb_p)+1) > (view->infos)->line_count) { if (update_lines(view, ((*line_nb_p)+1)) < 0) @@ -2160,6 +2158,7 @@ Obiview_p obi_open_view(OBIDMS_p dms, const char* view_name) } +// TODO return a pointer on the column? int obi_view_add_column(Obiview_p view, const char* column_name, obiversion_t version_number, @@ -2458,6 +2457,47 @@ int obi_save_and_close_view(Obiview_p view) } +int obi_create_auto_count_column(Obiview_p view) +{ + index_t i; + OBIDMS_p column; + + // Check that the view is not read-only + if (view->read_only) + { + obi_set_errno(OBIVIEW_ERROR); + obidebug(1, "\nError trying to create an automatic count column in a read-only view"); + return -1; + } + + if (obi_view_add_column(view, COUNT_COLUMN, -1, NULL, OBI_INT, 0, 1, NULL, NULL, NULL, NULL, "Sequence counts", true) < 0) + { + obidebug(1, "Error adding an automatic count column in a view"); + return -1; + } + + column = obi_view_get_column(view, COUNT_COLUMN); + if (column == NULL) + { + obidebug(1, "Error adding an automatic count column in a view"); + return -1; + } + + // Fill the column with 1s + for (i=0; i < (view->infos)->line_count; i++) + { + if (obi_column_set_obiint_with_elt_idx(column, i, 0, 1) < 0) + { + obidebug(1, "Error adding an automatic count column in a view"); + return -1; + } + } + + return 0; +} + + +// TODO Move to another file? /*********** FOR BLOB COLUMNS ***********/ Obi_blob_p obi_get_blob_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx) diff --git a/src/obiview.h b/src/obiview.h index 0a1c447..7a4bef8 100644 --- a/src/obiview.h +++ b/src/obiview.h @@ -51,6 +51,9 @@ */ #define QUALITY_COLUMN "QUALITY" /**< The name of the column containing the sequence qualities * in NUC_SEQS_VIEW views. + */ +#define COUNT_COLUMN "COUNT" /**< The name of the column containing the sequence counts + * in NUC_SEQS_VIEW views. */ @@ -507,6 +510,23 @@ int obi_select_lines(Obiview_p view, index_t* line_nbs); int obi_save_and_close_view(Obiview_p view); +/** + * @brief Creates an OBI_INT column with the line count of the view it belongs to, and sets all lines to 1. + * + * @warning The number of lines set corresponds to the line count of the view. + * + * @param view A pointer on the view. + * + * @returns A value indicating the success of the operation. + * @retval 0 if the operation was successfully completed. + * @retval -1 if an error occurred. + * + * @since July 2017 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int obi_create_auto_count_column(Obiview_p view); + + /** * @brief Recovers an obiblob from an OBIDMS column containing indices referring to obiblobs, * using the index of the element in the line, and the column pointer, in the context of a view.