Fixed major bug: when setting all the columns of a view to the same

number of lines, columns are now cloned before being enlarged if needed
+ predicate functions now print error messages if the predicates are not
respected
This commit is contained in:
Celine Mercier
2016-09-05 12:37:36 +02:00
parent ba84ef4847
commit 668696fc5a

View File

@ -657,12 +657,29 @@ int update_lines(Obiview_p view, index_t line_count)
{
int i;
// Check that the view is not read-only
if (view->read_only)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError trying to update the line count of all columns in a read-only view");
return -1;
}
for (i=0; i<((view->infos)->column_count); i++)
{
while (line_count > (((view->columns)[i])->header)->line_count)
{ // The column needs to be enlarged
// Clone it first if needed
if (!(((view->columns)[i])->writable))
{
if (clone_column_in_view(view, (((view->infos)->column_references)[i]).alias) < 0)
{
obidebug(1, "\nError cloning a column in a view when updating its line count");
return -1;
}
}
// Enlarge the column
if (obi_enlarge_column((view->columns)[i]) < 0)
if (obi_enlarge_column(((view->columns)[i])) < 0)
return -1;
(((view->columns)[i])->header)->lines_used = line_count;
}
@ -758,6 +775,15 @@ int prepare_to_set_value_in_column(Obiview_p view, OBIDMS_column_p* column_pp, i
return -1;
}
/* // If there is a new line selection being created, columns can't be modified // TODO investigate this
if (view->new_line_selection != NULL)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError trying to set a value in a column in a view with a new line selection being created");
return -1;
}
*/
// If there is a line selection associated with the view or if the column
// is read-only, all columns or this column respectively must be cloned
if ((view->line_selection != NULL) || (!((*column_pp)->writable)))
@ -833,8 +859,11 @@ char* view_has_nuc_sequence_column(Obiview_p view)
if (obi_view_get_column(view, NUC_SEQUENCE_COLUMN) != NULL)
return predicate;
else
{
obidebug(1, "\nError checking the predicate: %s", predicate);
return NULL;
}
}
char* view_has_quality_column(Obiview_p view)
@ -854,8 +883,11 @@ char* view_has_quality_column(Obiview_p view)
if (obi_view_get_column(view, QUALITY_COLUMN) != NULL)
return predicate;
else
{
obidebug(1, "\nError checking the predicate: %s", predicate);
return NULL;
}
}
char* view_has_id_column(Obiview_p view)
@ -875,9 +907,11 @@ char* view_has_id_column(Obiview_p view)
if (obi_view_get_column(view, ID_COLUMN) != NULL)
return predicate;
else
{
obidebug(1, "\nError checking the predicate: %s", predicate);
return NULL;
}
}
char* view_has_definition_column(Obiview_p view)
{
@ -896,8 +930,11 @@ char* view_has_definition_column(Obiview_p view)
if (obi_view_get_column(view, DEFINITION_COLUMN) != NULL)
return predicate;
else
{
obidebug(1, "\nError checking the predicate: %s", predicate);
return NULL;
}
}
char* view_check_quality_matches_seq_column(Obiview_p view) // TODO Print error if there is one?
@ -923,7 +960,10 @@ char* view_check_quality_matches_seq_column(Obiview_p view) // TODO Print error
qual_column = obi_view_get_column(view, QUALITY_COLUMN);
if (qual_column == NULL)
{
obidebug(1, "\nError checking the predicate: %s", predicate);
return NULL;
}
seq_column = obi_view_get_column(view, ((qual_column->header)->associated_column).column_name);
//seq_column = obi_open_column(view->dms, ((qual_column->header)->associated_column).column_name, ((qual_column->header)->associated_column).version);
@ -931,12 +971,18 @@ char* view_check_quality_matches_seq_column(Obiview_p view) // TODO Print error
// TODO if outside of view, make function that opens a column from a column reference structure?
if (seq_column == NULL)
{
obidebug(1, "\nError checking the predicate: %s", predicate);
return NULL;
}
nb_elements_per_line = (qual_column->header)->nb_elements_per_line;
// Check that the quality and the sequence columns have the same number of elements per line
if (nb_elements_per_line != (seq_column->header)->nb_elements_per_line)
{
obidebug(1, "\nError checking the predicate: %s", predicate);
return NULL;
}
for (i=0; i < (view->infos)->line_count; i++)
{
@ -948,13 +994,19 @@ char* view_check_quality_matches_seq_column(Obiview_p view) // TODO Print error
{
// Test that the lengths of the quality and the sequence are equal
if (qual_len != (int)strlen(seq))
{
obidebug(1, "\nError checking the predicate: %s", predicate);
return NULL;
}
}
// Test if one value is NA and not the other
else if (((qual == OBIQual_int_NA) && (seq != OBISeq_NA)) || ((qual != OBIQual_int_NA) && (seq == OBISeq_NA)))
{
obidebug(1, "\nError checking the predicate: %s", predicate);
return NULL;
}
}
}
//obi_close_column(seq_column);
@ -1947,7 +1999,10 @@ int obi_save_and_close_view(Obiview_p view)
{
predicates = view_check_all_predicates(view);
if (predicates == NULL)
{
obidebug(1, "\nView predicates not respected");
return -1; // TODO reverse view (delete files)
}
else
{
write_comments_to_view_file(view, predicates);