Added a C function to add a COUNT column to a view with all lines set to

1
This commit is contained in:
Celine Mercier
2017-07-11 16:44:23 +02:00
parent ced9a268a1
commit 3e6aecc635
2 changed files with 62 additions and 2 deletions

View File

@ -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)

View File

@ -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.