Added Obiviews specialized for the handling of nucleotide sequences

This commit is contained in:
Celine Mercier
2016-02-25 09:43:27 +01:00
parent ffc68d448f
commit 4df313c54a
5 changed files with 434 additions and 19 deletions

View File

@ -209,6 +209,50 @@ int create_obiview_file(int dms_file_descriptor)
**********************************************************************/
Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const char* view_name, Obiview_p view_to_clone, index_t* line_selection)
{
Obiview_p view;
if (view_to_clone != NULL)
{ // TODO check that the view to clone is already a NUC_SEQS view (discuss possibility of transforming type of a view)
if (strcmp(view_to_clone->view_type, VIEW_TYPE_NUC_SEQS))
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "Trying to clone a non-NUC SEQS view to create a NUC SEQS view");
return NULL;
}
}
view = obi_new_view(dms, view_name, view_to_clone, line_selection);
strcpy(view->view_type, VIEW_TYPE_NUC_SEQS);
if (view_to_clone == NULL)
{
// Adding sequence column
if (obi_view_add_column(view, NUC_SEQUENCE_COLUMN, -1, OBI_SEQ, 0, 1, NUC_SEQUENCE_COLUMN, NUC_SEQUENCE_AVL, "Nucleotide sequences", true) < 0)
{
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, OBI_STR, 0, 1, ID_COLUMN, ID_AVL, "Ids", true) < 0)
{
obidebug(1, "Error adding an obligatory column in a nucleotide sequences view");
return NULL;
}
// Adding description column
if (obi_view_add_column(view, DESCRIPTION_COLUMN, -1, OBI_STR, 0, 1, DESCRIPTION_COLUMN, DESCRIPTION_AVL, "Descriptions", true) < 0)
{
obidebug(1, "Error adding an obligatory column in a nucleotide sequences view");
return NULL;
}
}
return view;
}
Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_clone, index_t* line_selection)
{
Obiview_p view;
@ -297,6 +341,7 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl
}
}
strcpy(view->view_type, view_to_clone->view_type);
strcpy(view->created_from, view_to_clone->name);
view->new_line_selection = NULL;
}
@ -308,8 +353,9 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl
view->line_count = 0;
view->line_selection = NULL;
view->new_line_selection = NULL;
(view->created_from)[0] = '\0';
//view->columns = NULL; TODO
(view->created_from)[0] = '\0';
(view->view_type)[0] = '\0';
//view->columns = NULL; TODO
}
strcpy(view->name, view_name);
@ -328,6 +374,25 @@ Obiview_p obi_new_view_cloned_from_name(OBIDMS_p dms, const char* view_name, con
if (view_to_clone == NULL)
return NULL;
view = obi_new_view(dms, view_name, view_to_clone, line_selection);
obi_close_view(view_to_clone);
return view;
}
Obiview_p obi_new_view_nuc_seqs_cloned_from_name(OBIDMS_p dms, const char* view_name, const char* view_to_clone_name, index_t* line_selection)
{
Obiview_p view;
Obiview_p view_to_clone;
view_to_clone = obi_open_view(dms, view_to_clone_name);
if (view_to_clone == NULL)
return NULL;
view = obi_new_view_nuc_seqs(dms, view_name, view_to_clone, line_selection);
obi_close_view(view_to_clone);
return view;
}
@ -466,6 +531,7 @@ Obiview_p obi_open_view(OBIDMS_p dms, const char* view_name)
view->line_count = view_infos->line_count;
strcpy(view->created_from, view_infos->created_from);
strcpy(view->name, view_infos->name);
strcpy(view->view_type, view_infos->view_type);
// Open the columns to read
for (i=0; i<(view_infos->column_count); i++)
@ -493,6 +559,91 @@ Obiview_p obi_open_view(OBIDMS_p dms, const char* view_name)
}
Obiviews_infos_all_p obi_read_views(OBIDMS_p dms)
{
char* view_file_name;
int obiview_file_descriptor;
size_t header_size;
Obiviews_header_p header;
Obiview_infos_p view_infos;
Obiviews_infos_all_p views;
view_file_name = build_obiview_file_name();
if (view_file_name == NULL)
return NULL;
// Open view file, read header size and map header and views
obiview_file_descriptor = openat(dms->dir_fd, view_file_name, O_RDWR, 0777);
if (obiview_file_descriptor < 0)
{ // No views yet
free(view_file_name);
return NULL;
}
free(view_file_name);
// Read the header size
if (read(obiview_file_descriptor, &header_size, sizeof(size_t)) < ((ssize_t) sizeof(size_t)))
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError reading the header size of an obiview file (trying to open a view when there are none?)");
close(obiview_file_descriptor);
return NULL;
}
// Map the header
header = mmap(NULL,
header_size,
PROT_READ | PROT_WRITE,
MAP_SHARED,
obiview_file_descriptor,
0
);
if (header == MAP_FAILED)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError mmapping an obiview file header");
close(obiview_file_descriptor);
return NULL;
}
// Map the views
view_infos = mmap(NULL,
header->views_size,
PROT_READ | PROT_WRITE,
MAP_SHARED,
obiview_file_descriptor,
header_size
);
if (view_infos == MAP_FAILED)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError mmapping the views from an obiview file");
munmap(header, header_size);
close(obiview_file_descriptor);
return NULL;
}
views = (Obiviews_infos_all_p) malloc(sizeof(Obiviews_infos_all_t));
if (views == NULL)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError mmapping the views from an obiview file");
munmap(view_infos, header->views_size);
munmap(header, header_size);
close(obiview_file_descriptor);
return NULL;
}
views->header = header;
views->view_infos = view_infos;
close(obiview_file_descriptor);
return views;
}
int obi_view_add_column(Obiview_p view,
const char* column_name,
obiversion_t version_number,
@ -605,6 +756,8 @@ int obi_view_delete_column(Obiview_p view, const char* column_name)
int i;
bool found;
// TODO check that not deleting an obligatory column?
// Check that the view is not read-only
if (view->read_only)
{
@ -879,6 +1032,8 @@ int obi_save_view(Obiview_p view)
view_infos->creation_date = time(NULL);
strcpy(view_infos->created_from, view->created_from);
strcpy(view_infos->name, view->name);
strcpy(view_infos->view_type, view->view_type);
// Store reference for the line selection associated with that view
if (view->new_line_selection != NULL)
{

View File

@ -30,6 +30,19 @@
*/
#define OBIVIEW_FILE_NAME "obiviews"
#define VIEW_TYPE_MAX_NAME (1024)
#define VIEW_TYPE_NUC_SEQS "NUC_SEQS_VIEW"
#define NUC_SEQUENCE_COLUMN "NUC_SEQ"
#define NUC_SEQUENCE_AVL "NUC_SEQ_AVL"
#define ID_COLUMN "ID"
#define ID_AVL "ID_AVL"
#define DESCRIPTION_COLUMN "DESCRIPTION"
#define DESCRIPTION_AVL "DESCRIPTION_AVL"
#define LINES_COLUMN_NAME "LINES"
@ -69,6 +82,8 @@ typedef struct Obiview {
int view_number;
char view_type[VIEW_TYPE_MAX_NAME+1];
} Obiview_t, *Obiview_p;
@ -94,6 +109,8 @@ typedef struct Obiview_infos {
Column_reference_t column_references[MAX_NB_OPENED_COLUMNS];
char view_type[VIEW_TYPE_MAX_NAME+1];
} Obiview_infos_t, *Obiview_infos_p;
@ -110,20 +127,26 @@ typedef struct Obiviews_header {
/**
* @brief .
*/
typedef struct Obiviews { // not used
typedef struct Obiviews_infos_all {
Obiviews_header_p header;
Obiview_infos_p views;
Obiview_infos_p view_infos;
} Obiviews_t, *Obiviews_p;
} Obiviews_infos_all_t, *Obiviews_infos_all_p;
Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const char* view_name, Obiview_p view_to_clone, index_t* line_selection);
Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_clone, index_t* line_selection);
Obiview_p obi_new_view_cloned_from_name(OBIDMS_p dms, const char* view_name, const char* view_to_clone_name, index_t* line_selection);
Obiview_p obi_new_view_nuc_seqs_cloned_from_name(OBIDMS_p dms, const char* view_name, const char* view_to_clone_name, index_t* line_selection);
Obiview_p obi_open_view(OBIDMS_p dms, const char* view_name);
Obiviews_infos_all_p obi_read_views(OBIDMS_p dms);
int obi_view_add_column(Obiview_p view,
const char* column_name,
obiversion_t version_number,