Added tuple columns containing immutable indexed data arrays of any type
This commit is contained in:
73
src/array_indexer.c
Normal file
73
src/array_indexer.c
Normal file
@ -0,0 +1,73 @@
|
||||
/****************************************************************************
|
||||
* Array indexing functions *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file array_indexer.c
|
||||
* @author Celine Mercier
|
||||
* @date October 5th 2017
|
||||
* @brief Functions handling the indexing and retrieval of arrays of any type.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "obiblob.h"
|
||||
#include "obiblob_indexer.h"
|
||||
#include "obidebug.h"
|
||||
#include "obitypes.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
|
||||
|
||||
index_t obi_index_array(Obi_indexer_p indexer, const void* value, uint8_t elt_size, int value_length)
|
||||
{
|
||||
Obi_blob_p value_b;
|
||||
index_t idx;
|
||||
int32_t length_bytes;
|
||||
|
||||
// fprintf(stderr, "\nelt size in C: %u", elt_size);
|
||||
|
||||
// for (int i=0; i<value_length; i++)
|
||||
// fprintf(stderr, "\nvalue %d", ((obibool_t*)value)[i]);
|
||||
|
||||
length_bytes = value_length * elt_size;
|
||||
|
||||
// Encode value
|
||||
value_b = obi_blob((byte_t*)value, elt_size, length_bytes, length_bytes);
|
||||
if (value_b == NULL)
|
||||
return -1;
|
||||
|
||||
// for (int i=0; i<value_length; i++)
|
||||
// fprintf(stderr, "\nin blob: value %d", ((obibool_t*)(value_b->value))[i]);
|
||||
|
||||
// Add in the indexer
|
||||
idx = obi_indexer_add(indexer, value_b);
|
||||
|
||||
free(value_b);
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
|
||||
const void* obi_retrieve_array(Obi_indexer_p indexer, index_t idx, int* value_length_p)
|
||||
{
|
||||
Obi_blob_p value_b;
|
||||
|
||||
// Get encoded value
|
||||
value_b = obi_indexer_get(indexer, idx);
|
||||
|
||||
// Store array length
|
||||
*value_length_p = (value_b->length_decoded_value) / (value_b->element_size);
|
||||
|
||||
// for (int i=0; i<*value_length_p; i++)
|
||||
// fprintf(stderr, "\nvalue %d", ((obibool_t*)(value_b->value))[i]);
|
||||
|
||||
// Return pointer on mapped array
|
||||
return ((void*) (value_b->value));
|
||||
}
|
||||
|
60
src/array_indexer.h
Normal file
60
src/array_indexer.h
Normal file
@ -0,0 +1,60 @@
|
||||
/****************************************************************************
|
||||
* Array indexer header file *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file array_indexer.h
|
||||
* @author Celine Mercier
|
||||
* @date October 5th 2017
|
||||
* @brief Header file for the functions handling the indexing of arrays of any type.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ARRAY_INDEXER_H_
|
||||
#define ARRAY_INDEXER_H_
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "obidms.h"
|
||||
#include "obitypes.h"
|
||||
#include "obiblob.h"
|
||||
#include "obiblob_indexer.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief Stores an array of elements of any type in an indexer and returns the index.
|
||||
*
|
||||
* @param indexer The indexer structure.
|
||||
* @param value The array to index.
|
||||
* @param elt_size The size in bits of one element.
|
||||
* @param value_length The length (number of elements) of the array to index.
|
||||
*
|
||||
* @returns The index referring to the stored array in the indexer.
|
||||
*
|
||||
* @since October 2017
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
index_t obi_index_array(Obi_indexer_p indexer, const void* value, uint8_t elt_size, int32_t value_length);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Retrieves an array from an indexer.
|
||||
*
|
||||
* @warning The array returned is mapped.
|
||||
*
|
||||
* @param indexer The indexer structure.
|
||||
* @param idx The index referring to the array to retrieve in the indexer.
|
||||
* @param value_length A pointer on an integer to store the length of the array retrieved.
|
||||
*
|
||||
* @returns A pointer on the array.
|
||||
*
|
||||
* @since October 2017
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
const void* obi_retrieve_array(Obi_indexer_p indexer, index_t idx, int32_t* value_length_p);
|
||||
|
||||
|
||||
#endif /* ARRAY_INDEXER_H_ */
|
||||
|
@ -154,35 +154,35 @@ static int create_alignment_output_columns(Obiview_p output_view,
|
||||
bool normalize, int reference, bool similarity_mode)
|
||||
{
|
||||
// Create the column for the ids of the 1st sequence aligned
|
||||
if (obi_view_add_column(output_view, ID1_COLUMN_NAME, -1, NULL, OBI_STR, 0, 1, NULL, id1_indexer_name, NULL, -1, ID1_COLUMN_COMMENTS, true) < 0)
|
||||
if (obi_view_add_column(output_view, ID1_COLUMN_NAME, -1, NULL, OBI_STR, 0, 1, NULL, false, id1_indexer_name, NULL, -1, ID1_COLUMN_COMMENTS, true) < 0)
|
||||
{
|
||||
obidebug(1, "\nError creating the first column for the sequence ids when aligning");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create the column for the ids of the 2nd sequence aligned
|
||||
if (obi_view_add_column(output_view, ID2_COLUMN_NAME, -1, NULL, OBI_STR, 0, 1, NULL, id2_indexer_name, NULL, -1, ID2_COLUMN_COMMENTS, true) < 0)
|
||||
if (obi_view_add_column(output_view, ID2_COLUMN_NAME, -1, NULL, OBI_STR, 0, 1, NULL, false, id2_indexer_name, NULL, -1, ID2_COLUMN_COMMENTS, true) < 0)
|
||||
{
|
||||
obidebug(1, "\nError creating the second column for the sequence ids when aligning");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create the column for the index (in the input view) of the first sequences aligned
|
||||
if (obi_view_add_column(output_view, IDX1_COLUMN_NAME, -1, NULL, OBI_INT, 0, 1, NULL, NULL, NULL, -1, IDX1_COLUMN_COMMENTS, true) < 0)
|
||||
if (obi_view_add_column(output_view, IDX1_COLUMN_NAME, -1, NULL, OBI_INT, 0, 1, NULL, false, NULL, NULL, -1, IDX1_COLUMN_COMMENTS, true) < 0)
|
||||
{
|
||||
obidebug(1, "\nError creating the first column for the sequence indices when aligning");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create the column for the index (in the input view) of the second sequences aligned
|
||||
if (obi_view_add_column(output_view, IDX2_COLUMN_NAME, -1, NULL, OBI_INT, 0, 1, NULL, NULL, NULL, -1, IDX2_COLUMN_COMMENTS, true) < 0)
|
||||
if (obi_view_add_column(output_view, IDX2_COLUMN_NAME, -1, NULL, OBI_INT, 0, 1, NULL, false, NULL, NULL, -1, IDX2_COLUMN_COMMENTS, true) < 0)
|
||||
{
|
||||
obidebug(1, "\nError creating the second column for the sequence indices when aligning");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create the column for the LCS length
|
||||
if (obi_view_add_column(output_view, LCS_LENGTH_COLUMN_NAME, -1, NULL, OBI_INT, 0, 1, NULL, NULL, NULL, -1, LCS_LENGTH_COLUMN_COMMENTS, true) < 0)
|
||||
if (obi_view_add_column(output_view, LCS_LENGTH_COLUMN_NAME, -1, NULL, OBI_INT, 0, 1, NULL, false, NULL, NULL, -1, LCS_LENGTH_COLUMN_COMMENTS, true) < 0)
|
||||
{
|
||||
obidebug(1, "\nError creating the column for the LCS length when aligning");
|
||||
return -1;
|
||||
@ -191,7 +191,7 @@ static int create_alignment_output_columns(Obiview_p output_view,
|
||||
// Create the column for the alignment length if it is computed
|
||||
if ((reference == ALILEN) && (normalize || !similarity_mode))
|
||||
{
|
||||
if (obi_view_add_column(output_view, ALI_LENGTH_COLUMN_NAME, -1, NULL, OBI_INT, 0, 1, NULL, NULL, NULL, -1, ALI_LENGTH_COLUMN_COMMENTS, true) < 0)
|
||||
if (obi_view_add_column(output_view, ALI_LENGTH_COLUMN_NAME, -1, NULL, OBI_INT, 0, 1, NULL, false, NULL, NULL, -1, ALI_LENGTH_COLUMN_COMMENTS, true) < 0)
|
||||
{
|
||||
obidebug(1, "\nError creating the column for the alignment length when aligning");
|
||||
return -1;
|
||||
@ -200,7 +200,7 @@ static int create_alignment_output_columns(Obiview_p output_view,
|
||||
// Create the column for the alignment score
|
||||
if (normalize)
|
||||
{
|
||||
if (obi_view_add_column(output_view, SCORE_COLUMN_NAME, -1, NULL, OBI_FLOAT, 0, 1, NULL, NULL, NULL, -1, SCORE_COLUMN_NAME, true) < 0)
|
||||
if (obi_view_add_column(output_view, SCORE_COLUMN_NAME, -1, NULL, OBI_FLOAT, 0, 1, NULL, false, NULL, NULL, -1, SCORE_COLUMN_NAME, true) < 0)
|
||||
{
|
||||
obidebug(1, "\nError creating the column for the score when aligning");
|
||||
return -1;
|
||||
@ -208,7 +208,7 @@ static int create_alignment_output_columns(Obiview_p output_view,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (obi_view_add_column(output_view, SCORE_COLUMN_NAME, -1, NULL, OBI_INT, 0, 1, NULL, NULL, NULL, -1, SCORE_COLUMN_NAME, true) < 0)
|
||||
if (obi_view_add_column(output_view, SCORE_COLUMN_NAME, -1, NULL, OBI_INT, 0, 1, NULL, false, NULL, NULL, -1, SCORE_COLUMN_NAME, true) < 0)
|
||||
{
|
||||
obidebug(1, "\nError creating the column for the score when aligning");
|
||||
return -1;
|
||||
@ -218,14 +218,14 @@ static int create_alignment_output_columns(Obiview_p output_view,
|
||||
if (print_seq)
|
||||
{
|
||||
// Create the column for the first sequences aligned
|
||||
if (obi_view_add_column(output_view, SEQ1_COLUMN_NAME, -1, NULL, OBI_SEQ, 0, 1, NULL, seq1_indexer_name, NULL, -1, SEQ1_COLUMN_COMMENTS, true) < 0)
|
||||
if (obi_view_add_column(output_view, SEQ1_COLUMN_NAME, -1, NULL, OBI_SEQ, 0, 1, NULL, false, seq1_indexer_name, NULL, -1, SEQ1_COLUMN_COMMENTS, true) < 0)
|
||||
{
|
||||
obidebug(1, "\nError creating the first column for the sequences when aligning");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create the column for the second sequences aligned
|
||||
if (obi_view_add_column(output_view, SEQ2_COLUMN_NAME, -1, NULL, OBI_SEQ, 0, 1, NULL, seq2_indexer_name, NULL, -1, SEQ2_COLUMN_COMMENTS, true) < 0)
|
||||
if (obi_view_add_column(output_view, SEQ2_COLUMN_NAME, -1, NULL, OBI_SEQ, 0, 1, NULL, false, seq2_indexer_name, NULL, -1, SEQ2_COLUMN_COMMENTS, true) < 0)
|
||||
{
|
||||
obidebug(1, "\nError creating the second column for the sequences when aligning");
|
||||
return -1;
|
||||
@ -234,14 +234,14 @@ static int create_alignment_output_columns(Obiview_p output_view,
|
||||
// if (print_count) // TODO count columns not implemented yet
|
||||
// {
|
||||
// // Create the column for the count of the first sequences aligned
|
||||
// if (obi_view_add_column(output_view, COUNT1_COLUMN_NAME, -1, NULL, OBI_INT, 0, 1, NULL, NULL, NULL, -1, COUNT1_COLUMN_COMMENTS, true) < 0)
|
||||
// if (obi_view_add_column(output_view, COUNT1_COLUMN_NAME, -1, NULL, OBI_INT, 0, 1, NULL, false, NULL, NULL, -1, COUNT1_COLUMN_COMMENTS, true) < 0)
|
||||
// {
|
||||
// obidebug(1, "\nError creating the first column for the sequence counts when aligning");
|
||||
// return -1;
|
||||
// }
|
||||
//
|
||||
// // Create the column for the count of the second sequences aligned
|
||||
// if (obi_view_add_column(output_view, COUNT2_COLUMN_NAME, -1, NULL, OBI_INT, 0, 1, NULL, NULL, NULL, -1, COUNT2_COLUMN_COMMENTS, true) < 0)
|
||||
// if (obi_view_add_column(output_view, COUNT2_COLUMN_NAME, -1, NULL, OBI_INT, 0, 1, NULL, false, NULL, NULL, -1, COUNT2_COLUMN_COMMENTS, true) < 0)
|
||||
// {
|
||||
// obidebug(1, "\nError creating the second column for the sequence counts when aligning");
|
||||
// return -1;
|
||||
|
@ -924,7 +924,7 @@ obiversion_t obi_import_column(const char* dms_path_1, const char* dms_path_2, c
|
||||
|
||||
// Create new column
|
||||
column_2 = obi_create_column(dms_2, column_name, header_1->returned_data_type, header_1->line_count,
|
||||
header_1->nb_elements_per_line, header_1->elements_names, true,
|
||||
header_1->nb_elements_per_line, header_1->elements_names, true, header_1->tuples,
|
||||
new_avl_name, (header_1->associated_column).column_name, (header_1->associated_column).version,
|
||||
header_1->comments);
|
||||
|
||||
@ -1142,6 +1142,7 @@ int obi_import_view(const char* dms_path_1, const char* dms_path_2, const char*
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
false,
|
||||
NULL,
|
||||
NULL,
|
||||
-1,
|
||||
|
@ -890,6 +890,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
index_t nb_elements_per_line,
|
||||
char* elements_names,
|
||||
bool elt_names_formatted,
|
||||
bool tuples,
|
||||
const char* indexer_name,
|
||||
const char* associated_column_name,
|
||||
obiversion_t associated_column_version,
|
||||
@ -957,7 +958,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
}
|
||||
|
||||
// Build the indexer name if needed
|
||||
if ((data_type == OBI_STR) || (data_type == OBI_SEQ) || (data_type == OBI_QUAL))
|
||||
if ((data_type == OBI_STR) || (data_type == OBI_SEQ) || (data_type == OBI_QUAL) || tuples)
|
||||
{
|
||||
if ((indexer_name == NULL) || (*indexer_name == 0))
|
||||
{
|
||||
@ -973,7 +974,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
}
|
||||
|
||||
returned_data_type = data_type;
|
||||
if ((data_type == OBI_STR) || (data_type == OBI_SEQ) || (data_type == OBI_QUAL))
|
||||
if ((data_type == OBI_STR) || (data_type == OBI_SEQ) || (data_type == OBI_QUAL) || tuples)
|
||||
// stored data is indices referring to data stored elsewhere
|
||||
stored_data_type = OBI_IDX;
|
||||
else
|
||||
@ -1105,6 +1106,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
header->nb_elements_per_line = nb_elements_per_line;
|
||||
header->stored_data_type = stored_data_type;
|
||||
header->returned_data_type = returned_data_type;
|
||||
header->tuples = tuples;
|
||||
header->creation_date = time(NULL);
|
||||
header->version = version_number;
|
||||
header->cloned_from = -1;
|
||||
@ -1146,7 +1148,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
}
|
||||
|
||||
// If the data type is OBI_STR, OBI_SEQ or OBI_QUAL, the associated obi_indexer is opened or created
|
||||
if ((returned_data_type == OBI_STR) || (returned_data_type == OBI_SEQ) || (returned_data_type == OBI_QUAL))
|
||||
if ((returned_data_type == OBI_STR) || (returned_data_type == OBI_SEQ) || (returned_data_type == OBI_QUAL) || tuples)
|
||||
{
|
||||
new_column->indexer = obi_indexer(dms, final_indexer_name);
|
||||
if (new_column->indexer == NULL)
|
||||
@ -1377,6 +1379,7 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
nb_elements_per_line,
|
||||
(column_to_clone->header)->elements_names,
|
||||
true,
|
||||
(column_to_clone->header)->tuples,
|
||||
(column_to_clone->header)->indexer_name,
|
||||
((column_to_clone->header)->associated_column).column_name,
|
||||
((column_to_clone->header)->associated_column).version,
|
||||
|
@ -86,6 +86,8 @@ typedef struct OBIDMS_column_header {
|
||||
OBIType_t stored_data_type; /**< Type of the data that is actually stored in the data
|
||||
* part of the column.
|
||||
*/
|
||||
bool tuples; /**< A boolean indicating whether the column contains indices referring to indexed tuples.
|
||||
*/
|
||||
time_t creation_date; /**< Date of creation of the file.
|
||||
*/
|
||||
obiversion_t version; /**< Version of the column.
|
||||
@ -100,7 +102,7 @@ typedef struct OBIDMS_column_header {
|
||||
*/
|
||||
Column_reference_t associated_column; /**< If there is one, the reference to the associated column.
|
||||
*/
|
||||
bool finished; /**< A boolean indicating whether the column was properly closed by the view that created it. TODO
|
||||
bool finished; /**< A boolean indicating whether the column was properly closed by the view that created it.
|
||||
*/
|
||||
char comments[COMMENTS_MAX_LENGTH+1]; /**< Comments stored as a classical zero end C string.
|
||||
*/
|
||||
@ -239,6 +241,7 @@ size_t obi_get_platform_header_size();
|
||||
* @param elements_names The names of the elements with ';' as separator (no terminal ';'),
|
||||
* NULL or "" if the default names are to be used ("0\01\02\0...\0n").
|
||||
* @param elt_names_formatted Whether the separator for the elements names is ';' (false), or '\0' (true, as formatted by format_elements_names()).
|
||||
* @param tuples A boolean indicating whether the column should contain indices referring to indexed tuples.
|
||||
* @param indexer_name The name of the indexer if there is one associated with the column.
|
||||
* If NULL or "", the indexer name is set as the column name.
|
||||
* @param associated_column_name The name of the associated column if there is one (otherwise NULL or "").
|
||||
@ -258,6 +261,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
index_t nb_elements_per_line,
|
||||
char* elements_names,
|
||||
bool elt_names_formatted,
|
||||
bool tuples,
|
||||
const char* indexer_name,
|
||||
const char* associated_column_name,
|
||||
obiversion_t associated_column_version,
|
||||
|
85
src/obidmscolumn_array.c
Normal file
85
src/obidmscolumn_array.c
Normal file
@ -0,0 +1,85 @@
|
||||
/****************************************************************************
|
||||
* OBIDMS_column_array functions *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obidsmcolumn_array.c
|
||||
* @author Celine Mercier
|
||||
* @date October 27th 2017
|
||||
* @brief Functions handling OBIColumns containing data arrays of any type.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "obidmscolumn.h"
|
||||
#include "obitypes.h"
|
||||
#include "array_indexer.h"
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
*
|
||||
* D E F I N I T I O N O F T H E P U B L I C F U N C T I O N S
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
|
||||
int obi_column_set_array(OBIDMS_column_p column, index_t line_nb, const void* value, uint8_t elt_size, int32_t value_length)
|
||||
{
|
||||
index_t idx;
|
||||
|
||||
if (obi_column_prepare_to_set_value(column, line_nb, 0) < 0)
|
||||
return -1;
|
||||
|
||||
if (value == OBITuple_NA)
|
||||
{
|
||||
idx = OBIIdx_NA;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add the value in the indexer
|
||||
idx = obi_index_array(column->indexer, value, elt_size, value_length);
|
||||
if (idx == -1) // An error occurred
|
||||
{
|
||||
if (obi_errno == OBI_READ_ONLY_INDEXER_ERROR)
|
||||
{
|
||||
// If the error is that the indexer is read-only, clone it
|
||||
if (obi_clone_column_indexer(column) < 0)
|
||||
return -1;
|
||||
obi_set_errno(0);
|
||||
|
||||
// Add the value in the new indexer
|
||||
idx = obi_index_array(column->indexer, value, elt_size, value_length);
|
||||
if (idx == -1)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the value's index in the column
|
||||
*(((index_t*) (column->data)) + line_nb) = idx;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const void* obi_column_get_array(OBIDMS_column_p column, index_t line_nb, int32_t* value_length_p)
|
||||
{
|
||||
index_t idx;
|
||||
|
||||
if (obi_column_prepare_to_get_value(column, line_nb) < 0)
|
||||
return OBITuple_NA;
|
||||
|
||||
idx = *(((index_t*) (column->data)) + line_nb);
|
||||
|
||||
// Check NA
|
||||
if (idx == OBIIdx_NA)
|
||||
return OBITuple_NA;
|
||||
|
||||
return obi_retrieve_array(column->indexer, idx, value_length_p);
|
||||
}
|
||||
|
||||
|
64
src/obidmscolumn_array.h
Normal file
64
src/obidmscolumn_array.h
Normal file
@ -0,0 +1,64 @@
|
||||
/****************************************************************************
|
||||
* Array columns header file *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obidsmcolumn_array.h
|
||||
* @author Celine Mercier
|
||||
* @date October 30th 2017
|
||||
* @brief Header file for the functions handling OBIColumns containing data in the form of indices referring to data arrays.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OBIDMSCOLUMN_ARRAY_H_
|
||||
#define OBIDMSCOLUMN_ARRAY_H_
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "obidmscolumn.h"
|
||||
#include "obitypes.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to arrays handled by an indexer.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_column().
|
||||
* @param line_nb The number of the line where the value should be set.
|
||||
* @param value A pointer on the array.
|
||||
* @param elt_size The size in bits of one element.
|
||||
* @param value_length The length (number of elements) of the array to index.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since October 2017
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_column_set_array(OBIDMS_column_p column, index_t line_nb, const void* value, uint8_t elt_size, int32_t value_length);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to arrays handled by an indexer.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column().
|
||||
* @param line_nb The number of the line where the value should be recovered.
|
||||
* @param value_length A pointer on an integer to store the length of the array retrieved.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval OBITuple_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @since October 2017
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
const void* obi_column_get_array(OBIDMS_column_p column, index_t line_nb, int32_t* value_length_p);
|
||||
|
||||
|
||||
#endif /* OBIDMSCOLUMN_ARRAY_H_ */
|
||||
|
@ -27,7 +27,7 @@
|
||||
#define OBIBlob_NA (NULL) /**< NA value for the type Obiblobs */ // TODO discuss
|
||||
#define OBIQual_char_NA (NULL) /**< NA value for the type OBI_QUAL if the quality is in character string format */
|
||||
#define OBIQual_int_NA (NULL) /**< NA value for the type OBI_QUAL if the quality is in integer format */
|
||||
|
||||
#define OBITuple_NA (NULL) /**< NA value for tuples of any type */
|
||||
|
||||
/**
|
||||
* @brief enum for the boolean OBIType.
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "obidmscolumn_qual.h"
|
||||
#include "obidmscolumn_seq.h"
|
||||
#include "obidmscolumn_str.h"
|
||||
#include "obidmscolumn_array.h"
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
#include "obilittlebigman.h"
|
||||
@ -1643,7 +1644,7 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl
|
||||
// If there is a new line selection, build it by combining it with the one from the view to clone if there is one
|
||||
else if (line_selection != NULL)
|
||||
{
|
||||
view->line_selection = obi_create_column(view->dms, LINES_COLUMN_NAME, OBI_IDX, 0, 1, NULL, false, NULL, NULL, -1, NULL);
|
||||
view->line_selection = obi_create_column(view->dms, LINES_COLUMN_NAME, OBI_IDX, 0, 1, NULL, false, false, NULL, NULL, -1, NULL);
|
||||
if ((view->line_selection) == NULL)
|
||||
{
|
||||
obidebug(1, "\nError creating a column corresponding to a line selection");
|
||||
@ -1795,6 +1796,7 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
false,
|
||||
NULL,
|
||||
NULL,
|
||||
-1,
|
||||
@ -1862,19 +1864,19 @@ Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const char* view_name, Obiview_p v
|
||||
if (view_to_clone == NULL)
|
||||
{
|
||||
// Adding sequence column
|
||||
if (obi_view_add_column(view, NUC_SEQUENCE_COLUMN, -1, NULL, OBI_SEQ, 0, 1, NULL, NULL, NULL, -1, "Nucleotide sequences", true) < 0) // discuss using same indexer "NUC_SEQ_INDEXER"
|
||||
if (obi_view_add_column(view, NUC_SEQUENCE_COLUMN, -1, NULL, OBI_SEQ, 0, 1, NULL, false, NULL, NULL, -1, "Nucleotide sequences", true) < 0) // discuss using same indexer "NUC_SEQ_INDEXER"
|
||||
{
|
||||
obidebug(1, "Error adding an obligatory column in a nucleotide sequences view");
|
||||
return NULL;
|
||||
}
|
||||
// Adding id column
|
||||
if (obi_view_add_column(view, ID_COLUMN, -1, NULL, OBI_STR, 0, 1, NULL, NULL, NULL, -1, "Sequence identifiers", true) < 0)
|
||||
if (obi_view_add_column(view, ID_COLUMN, -1, NULL, OBI_STR, 0, 1, NULL, false, NULL, NULL, -1, "Sequence identifiers", true) < 0)
|
||||
{
|
||||
obidebug(1, "Error adding an obligatory column in a nucleotide sequences view");
|
||||
return NULL;
|
||||
}
|
||||
// Adding definition column
|
||||
if (obi_view_add_column(view, DEFINITION_COLUMN, -1, NULL, OBI_STR, 0, 1, NULL, NULL, NULL, -1, "Definitions", true) < 0)
|
||||
if (obi_view_add_column(view, DEFINITION_COLUMN, -1, NULL, OBI_STR, 0, 1, NULL, false, NULL, NULL, -1, "Definitions", true) < 0)
|
||||
{
|
||||
obidebug(1, "Error adding an obligatory column in a nucleotide sequences view");
|
||||
return NULL;
|
||||
@ -1883,7 +1885,7 @@ Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const char* view_name, Obiview_p v
|
||||
if (quality_column)
|
||||
{
|
||||
associated_nuc_column = obi_view_get_column(view, NUC_SEQUENCE_COLUMN);
|
||||
if (obi_view_add_column(view, QUALITY_COLUMN, -1, NULL, OBI_QUAL, 0, 1, NULL, NULL, (associated_nuc_column->header)->name, (associated_nuc_column->header)->version, "Sequence qualities", true) < 0) // TODO discuss automatic association
|
||||
if (obi_view_add_column(view, QUALITY_COLUMN, -1, NULL, OBI_QUAL, 0, 1, NULL, false, NULL, (associated_nuc_column->header)->name, (associated_nuc_column->header)->version, "Sequence qualities", true) < 0) // TODO discuss automatic association
|
||||
{
|
||||
obidebug(1, "Error adding an obligatory column in a nucleotide sequences view");
|
||||
return NULL;
|
||||
@ -2211,6 +2213,7 @@ int obi_view_add_column(Obiview_p view,
|
||||
index_t nb_lines,
|
||||
index_t nb_elements_per_line,
|
||||
char* elements_names,
|
||||
bool tuples,
|
||||
const char* indexer_name,
|
||||
const char* associated_column_name,
|
||||
obiversion_t associated_column_version,
|
||||
@ -2289,7 +2292,7 @@ int obi_view_add_column(Obiview_p view,
|
||||
// Open or create the column
|
||||
if (create)
|
||||
{ // Create column
|
||||
column = obi_create_column(view->dms, column_name, data_type, nb_lines, nb_elements_per_line, elements_names, false, indexer_name, associated_column_name, associated_column_version, comments);
|
||||
column = obi_create_column(view->dms, column_name, data_type, nb_lines, nb_elements_per_line, elements_names, false, tuples, indexer_name, associated_column_name, associated_column_version, comments);
|
||||
if (column == NULL)
|
||||
{
|
||||
obidebug(1, "\nError creating a column to add to a view");
|
||||
@ -2796,7 +2799,7 @@ int obi_create_auto_count_column(Obiview_p view)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (obi_view_add_column(view, COUNT_COLUMN, -1, NULL, OBI_INT, 0, 1, NULL, NULL, NULL, -1, "Sequence counts", true) < 0)
|
||||
if (obi_view_add_column(view, COUNT_COLUMN, -1, NULL, OBI_INT, 0, 1, NULL, false, NULL, NULL, -1, "Sequence counts", true) < 0)
|
||||
{
|
||||
obidebug(1, "Error adding an automatic count column in a view");
|
||||
return -1;
|
||||
@ -2848,7 +2851,7 @@ int obi_create_auto_id_column(Obiview_p view, const char* prefix)
|
||||
}
|
||||
|
||||
// Create the new ID column
|
||||
if (obi_view_add_column(view, ID_COLUMN, -1, NULL, OBI_STR, 0, 1, NULL, NULL, NULL, -1, "Sequence identifiers", true) < 0)
|
||||
if (obi_view_add_column(view, ID_COLUMN, -1, NULL, OBI_STR, 0, 1, NULL, false, NULL, NULL, -1, "Sequence identifiers", true) < 0)
|
||||
{
|
||||
obidebug(1, "Error adding an automatic ID column in a view");
|
||||
return -1;
|
||||
@ -3623,3 +3626,42 @@ index_t obi_get_index_with_elt_name_and_col_name_in_view(Obiview_p view, const c
|
||||
|
||||
/****************************************/
|
||||
|
||||
|
||||
/*********** FOR ARRAY COLUMNS ***********/
|
||||
|
||||
int obi_set_array_with_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const void* value, uint8_t elt_size, int32_t value_length)
|
||||
{
|
||||
if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0)
|
||||
return -1;
|
||||
return obi_column_set_array(column, line_nb, value, elt_size, value_length);
|
||||
}
|
||||
|
||||
|
||||
const void* obi_get_array_with_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, int32_t* value_length_p)
|
||||
{
|
||||
if (prepare_to_get_value_from_column(view, &line_nb) < 0)
|
||||
return OBITuple_NA;
|
||||
return obi_column_get_array(column, line_nb, value_length_p);
|
||||
}
|
||||
|
||||
|
||||
int obi_set_array_with_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const void* value, uint8_t elt_size, int32_t value_length)
|
||||
{
|
||||
OBIDMS_column_p column_p;
|
||||
column_p = obi_view_get_column(view, column_name);
|
||||
if (column_p == NULL)
|
||||
return -1;
|
||||
return obi_set_array_with_col_p_in_view(view, column_p, line_nb, value, elt_size, value_length);
|
||||
}
|
||||
|
||||
|
||||
const void* obi_get_array_with_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, int32_t* value_length_p)
|
||||
{
|
||||
OBIDMS_column_p column_p;
|
||||
column_p = obi_view_get_column(view, column_name);
|
||||
if (column_p == NULL)
|
||||
return OBITuple_NA;
|
||||
return obi_get_array_with_col_p_in_view(view, column_p, line_nb, value_length_p);
|
||||
}
|
||||
|
||||
/****************************************/
|
||||
|
@ -361,6 +361,7 @@ Obiview_p obi_open_view(OBIDMS_p dms, const char* view_name);
|
||||
* @param nb_elements_per_line The number of elements per line, if the column is created.
|
||||
* @param elements_names The names of the elements with ';' as separator (no terminal ';'),
|
||||
* if the column is created; NULL or "" if the default names are to be used ("0\01\02\0...\0n").
|
||||
* @param tuples A boolean indicating whether the column should contain indices referring to indexed tuples.
|
||||
* @param indexer_name The name of the indexer if there is one associated with the column, if the column is created.
|
||||
* If NULL or "", the indexer name is set as the column name.
|
||||
* @param associated_column_name The name of the associated column if there is one (otherwise NULL or ""), if the column is created.
|
||||
@ -383,6 +384,7 @@ int obi_view_add_column(Obiview_p view,
|
||||
index_t nb_lines,
|
||||
index_t nb_elements_per_line,
|
||||
char* elements_names,
|
||||
bool tuples,
|
||||
const char* indexer_name,
|
||||
const char* associated_column_name,
|
||||
obiversion_t associated_column_version,
|
||||
@ -2207,4 +2209,88 @@ index_t obi_get_index_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_col
|
||||
index_t obi_get_index_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name);
|
||||
|
||||
|
||||
/*********** FOR ARRAY COLUMNS ***********/
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing indices referring to indexed arrays,
|
||||
* using the column pointer, in the context of a view.
|
||||
*
|
||||
* Note: If the column is read-only or if there is a line selection associated with the view (making columns non-writable), it is cloned.
|
||||
*
|
||||
* @param view A pointer on the opened writable view.
|
||||
* @param column_p A pointer on the column.
|
||||
* @param line_nb The number of the line where the value should be set.
|
||||
* @param value The value that should be set.
|
||||
* @param elt_size The size in bits of one element.
|
||||
* @param value_length The length (number of elements) of the array to index.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since October 2017
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_set_array_with_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const void* value, uint8_t elt_size, int32_t value_length);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing indices referring to indexed arrays,
|
||||
* using the column pointer, in the context of a view.
|
||||
*
|
||||
* @param view A pointer on the opened view.
|
||||
* @param column_p A pointer on the column.
|
||||
* @param line_nb The number of the line where the value should be recovered.
|
||||
* @param value_length_p A pointer on an int where the length of the value (number of elements in the array) will be stored.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval OBITuple_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @since October 2017
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
const void* obi_get_array_with_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, int32_t* value_length_p);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing indices referring to indexed arrays,
|
||||
* using the column name, in the context of a view.
|
||||
*
|
||||
* Note: If the column is read-only or if there is a line selection associated with the view (making columns non-writable), it is cloned.
|
||||
*
|
||||
* @param view A pointer on the opened writable view.
|
||||
* @param column_name The name of the column.
|
||||
* @param line_nb The number of the line where the value should be set.
|
||||
* @param value The value that should be set.
|
||||
* @param elt_size The size in bits of one element.
|
||||
* @param value_length The length (number of elements) of the array to index.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since October 2017
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_set_array_with_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const void* value, uint8_t elt_size, int32_t value_length);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing indices referring to indexed arrays,
|
||||
* using the column name, in the context of a view.
|
||||
*
|
||||
* @param view A pointer on the opened view.
|
||||
* @param column_name The name of the column.
|
||||
* @param line_nb The number of the line where the value should be recovered.
|
||||
* @param value_length_p A pointer on an int where the length of the value (number of elements in the array) will be stored.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval OBITuple_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @since October 2017
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
const void* obi_get_array_with_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, int32_t* value_length_p);
|
||||
|
||||
|
||||
#endif /* OBIVIEW_H_ */
|
||||
|
Reference in New Issue
Block a user