Major update: New column type to store sequence qualities. Closes #41
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
* @file obidsmcolumn_qual.c
|
||||
* @author Celine Mercier
|
||||
* @date May 4th 2016
|
||||
* @brief Functions handling OBIColumns containing data in the form of indices referring to sequence quality arrays.
|
||||
* @brief Functions handling OBIColumns containing data in the form of indices referring to sequence qualities.
|
||||
*/
|
||||
|
||||
|
||||
@ -14,9 +14,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "obidmscolumn_qual.h"
|
||||
#include "obidmscolumn.h"
|
||||
#include "obitypes.h"
|
||||
#include "obidmscolumn_str.c"
|
||||
#include "uint8_indexer.h"
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
@ -26,38 +27,83 @@
|
||||
**********************************************************************/
|
||||
|
||||
int obi_column_set_obiqual_char_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value)
|
||||
{ // TODO discuss
|
||||
return obi_column_set_obistr_with_elt_idx(column, line_nb, element_idx, value);
|
||||
{
|
||||
uint8_t* int_value;
|
||||
int int_value_length;
|
||||
int i;
|
||||
int ret_value;
|
||||
|
||||
int_value_length = strlen(value);
|
||||
int_value = (uint8_t*) malloc(int_value_length * sizeof(uint8_t));
|
||||
|
||||
// Convert in uint8_t array to index in that format
|
||||
for (i=0; i<int_value_length; i++)
|
||||
int_value[i] = ((uint8_t)(value[i])) - QUALITY_ASCII_BASE;
|
||||
|
||||
ret_value = obi_column_set_obiqual_int_with_elt_idx(column, line_nb, element_idx, int_value, int_value_length);
|
||||
|
||||
free(int_value);
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
|
||||
int obi_column_set_obiqual_int_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, const uint8_t* value)
|
||||
int obi_column_set_obiqual_int_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, const uint8_t* value, int value_length)
|
||||
{
|
||||
char* value_char;
|
||||
index_t idx;
|
||||
char* new_indexer_name;
|
||||
|
||||
// Transform the int array into a char array
|
||||
// Length??
|
||||
//value_char = ;
|
||||
if (obi_column_prepare_to_set_value(column, line_nb) < 0)
|
||||
return -1;
|
||||
|
||||
obi_column_set_obiqual_char_with_elt_idx(column, line_nb, element_idx, value_char)
|
||||
// Add the value in the indexer
|
||||
idx = obi_index_uint8(column->indexer, value, 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
|
||||
new_indexer_name = obi_build_indexer_name((column->header)->name, (column->header)->version);
|
||||
if (new_indexer_name == NULL)
|
||||
return -1;
|
||||
column->indexer = obi_clone_indexer(column->indexer, new_indexer_name); // TODO Need to lock this somehow?
|
||||
// Add the value in the new indexer
|
||||
idx = obi_index_uint8(column->indexer, value, value_length);
|
||||
if (idx == -1)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
// Add the value's index in the column
|
||||
*(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = idx;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
char* obi_column_get_obiqual_char_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
|
||||
{ // TODO discuss
|
||||
char* value;
|
||||
{
|
||||
char* value;
|
||||
const uint8_t* int_value;
|
||||
int int_value_length;
|
||||
int i;
|
||||
|
||||
value = obi_column_get_obistr_with_elt_idx(column, line_nb, element_idx);
|
||||
if (strcmp(value, OBIStr_NA) == 0)
|
||||
return OBIQual_char_NA;
|
||||
int_value = obi_column_get_obiqual_int_with_elt_idx(column, line_nb, element_idx, &int_value_length);
|
||||
|
||||
value = (char*) malloc((int_value_length + 1) * sizeof(char));
|
||||
|
||||
// Encode int quality to char quality
|
||||
for (i=0; i<int_value_length; i++)
|
||||
value[i] = (char)(int_value[i] + QUALITY_ASCII_BASE);
|
||||
|
||||
value[i] = '\0';
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
uint8_t* obi_column_get_obiqual_int_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx) // TODO const? (mapped)
|
||||
const uint8_t* obi_column_get_obiqual_int_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, int* value_length)
|
||||
{
|
||||
index_t idx;
|
||||
|
||||
@ -70,7 +116,7 @@ uint8_t* obi_column_get_obiqual_int_with_elt_idx(OBIDMS_column_p column, index_t
|
||||
if (idx == OBIIdx_NA)
|
||||
return OBIQual_int_NA;
|
||||
|
||||
return obi_retrieve_quality_int(column->indexer, idx);
|
||||
return obi_retrieve_uint8(column->indexer, idx, value_length);
|
||||
}
|
||||
|
||||
|
||||
@ -84,13 +130,13 @@ int obi_column_set_obiqual_char_with_elt_name(OBIDMS_column_p column, index_t li
|
||||
}
|
||||
|
||||
|
||||
int obi_column_set_obiqual_int_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, uint8_t* value)
|
||||
int obi_column_set_obiqual_int_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, const uint8_t* value, int value_length)
|
||||
{
|
||||
index_t element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
|
||||
return obi_column_set_obiqual_int_with_elt_idx(column, line_nb, element_idx, value);
|
||||
return obi_column_set_obiqual_int_with_elt_idx(column, line_nb, element_idx, value, value_length);
|
||||
}
|
||||
|
||||
|
||||
@ -104,12 +150,12 @@ char* obi_column_get_obiqual_char_with_elt_name(OBIDMS_column_p column, index_t
|
||||
}
|
||||
|
||||
|
||||
uint8_t* obi_column_get_obiqual_int_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name) // TODO const? (mapped)
|
||||
const uint8_t* obi_column_get_obiqual_int_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, int* value_length)
|
||||
{
|
||||
index_t element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return OBIQual_int_NA;
|
||||
|
||||
return obi_column_get_obiqual_int_with_elt_idx(column, line_nb, element_idx);
|
||||
return obi_column_get_obiqual_int_with_elt_idx(column, line_nb, element_idx, value_length);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user