Changeset: a619931666d3 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a619931666d3
Modified Files:
sql/backends/monet5/bam/bamloader.c
Branch: DVframework_bam
Log Message:
Added somewhat better naming conventions
diffs (truncated from 1084 to 300 lines):
diff --git a/sql/backends/monet5/bam/bamloader.c
b/sql/backends/monet5/bam/bamloader.c
--- a/sql/backends/monet5/bam/bamloader.c
+++ b/sql/backends/monet5/bam/bamloader.c
@@ -10,7 +10,7 @@
typedef struct {
bat *column_bats; /* keeps bats of the columns: lower array */
str *column_names; /* names of columns that are kept in the higher
array */
-} temp_subcontainer;
+} _temp_subcontainer;
/*
* NOTE: Copied directly from miniseed/registrar.c
@@ -19,11 +19,11 @@ typedef struct {
*/
typedef struct {
str schema_name; /* schema or vault name */
- temp_subcontainer *tables_columns; /* keeps tables: higher array */
+ _temp_subcontainer *tables_columns; /* keeps tables: higher array */
str *table_names; /* names of tables that are kept in the higher array
*/
int *num_columns; /* number of columns in each table in the higher
array */
int num_tables;
-} temp_container;
+} _temp_container;
/*
* File format specific structures
@@ -31,74 +31,75 @@ typedef struct {
typedef struct {
char tag[3];
str value;
-} bam_header_option;
+} _bam_header_option;
typedef struct {
char header_tag[3];
- bam_header_option *options;
+ _bam_header_option *options;
int num_options;
-} bam_header_line;
+} _bam_header_line;
/* Global vars */
-FILE *logfile = NULL; /* keep logfile file opened in this global var while the
bam code runs, */
+FILE *_logfile = NULL; /* keep _logfile file opened in this global var while
the bam code runs, */
/* since opening and closing every time something has
to be written turned out to be very slow */
/* SQL schema details that are common to every schema */
-int num_col_files = 5;
-int num_col_sq = 7;
-int num_col_rg = 13;
-int num_col_pg = 6;
-int num_col_alignments_extra = 5;
+int _num_col_files = 5;
+int _num_col_sq = 7;
+int _num_col_rg = 13;
+int _num_col_pg = 6;
+int _num_col_alignments_extra = 5;
-str coln_files[] = {"file_id", "file_location", "format_version",
"sorting_order", "comments"};
-int colt_files[] = {TYPE_sht , TYPE_str , TYPE_flt , TYPE_str
, TYPE_str };
+str _coln_files[] = {"file_id", "file_location", "format_version",
"sorting_order", "comments"};
+int _colt_files[] = {TYPE_sht , TYPE_str , TYPE_flt , TYPE_str
, TYPE_str };
-str coln_sq[] = {"sn" , "file_id", "ln" , "as" , "m5" , "sp" ,
"ur" };
-int colt_sq[] = {TYPE_str, TYPE_sht , TYPE_int, TYPE_int, TYPE_str, TYPE_str,
TYPE_str};
+str _coln_sq[] = {"sn" , "file_id", "ln" , "as" , "m5" , "sp"
, "ur" };
+int _colt_sq[] = {TYPE_str, TYPE_sht , TYPE_int, TYPE_int, TYPE_str,
TYPE_str, TYPE_str};
-str coln_rg[] = {"id" , "file_id", "cn" , "ds" , "dt" , "fo" ,
"ks" , "lb" , "pg" , "pi" , "pl" , "pu" , "sm" };
-int colt_rg[] = {TYPE_str, TYPE_sht , TYPE_str, TYPE_str, TYPE_int, TYPE_str,
TYPE_str, TYPE_str, TYPE_str, TYPE_int, TYPE_str, TYPE_str, TYPE_str};
+str _coln_rg[] = {"id" , "file_id", "cn" , "ds" , "dt" , "fo"
, "ks" , "lb" , "pg" , "pi" , "pl" , "pu" , "sm" };
+int _colt_rg[] = {TYPE_str, TYPE_sht , TYPE_str, TYPE_str, TYPE_int,
TYPE_str, TYPE_str, TYPE_str, TYPE_str, TYPE_int, TYPE_str, TYPE_str, TYPE_str};
-str coln_pg[] = {"id" , "file_id", "pn" , "cl" , "pp" , "vn"
};
-int colt_pg[] = {TYPE_str, TYPE_sht , TYPE_str, TYPE_str, TYPE_str, TYPE_str
};
+str _coln_pg[] = {"id" , "file_id", "pn" , "cl" , "pp" , "vn"
};
+int _colt_pg[] = {TYPE_str, TYPE_sht , TYPE_str, TYPE_str, TYPE_str, TYPE_str
};
-str coln_alignments_extra[] = {"tag" , "virtual_offset", "file_id", "type"
, "value" };
-int colt_alignments_extra[] = {TYPE_str, TYPE_lng , TYPE_sht ,
TYPE_str, TYPE_str};
+str _coln_alignments_extra[] = {"tag" , "virtual_offset", "file_id", "type"
, "value" };
+int _colt_alignments_extra[] = {TYPE_str, TYPE_lng , TYPE_sht ,
TYPE_str, TYPE_str};
/* File format specific functions */
-static str init_temp_container_simple(temp_container *ret_tc);
-static str loadfile(str filepath, temp_container *ret_tc); /* load file and
add contents to tc */
-static str process_bam_header(int file_id, str header, temp_container *ret_tc);
-static int append_option_to_bat_cond_str(temp_container *ret_tc,
bam_header_option *opt, str cmp, int table, int col, int *appendErr, int *flag);
-static int append_option_to_bat_cond_lng(temp_container *ret_tc,
bam_header_option *opt, str cmp, int table, int col, int *appendErr, int *flag);
-static int append_option_to_bat_cond_flt(temp_container *ret_tc,
bam_header_option *opt, str cmp, int table, int col, int *appendErr, int *flag);
-static int append_option_to_bat_cond_tms(temp_container *ret_tc,
bam_header_option *opt, str cmp, int table, int col, int *appendErr, int *flag);
-static int append_option_to_bat(temp_container *ret_tc, ptr value, int table,
int col, int *appendErr, int *flag);
-static str read_bam_header_line(str *header, bam_header_line *ret_hl, int
*eof);
-static void free_bam_header_line(bam_header_line *hl);
-static str process_bam_alignment(int file_id, lng virtual_offset, bam_header_t
*header, bam1_t *alignment, temp_container *ret_tc, int schema);
-static int parse_alignment_str(str *sam_alig, str *dest);
-static int parse_alignment_lng(str *sam_alig, lng *dest);
+static str _init_temp_container_simple(_temp_container *ret_tc);
+static str _loadfile(str filepath, _temp_container *ret_tc); /* load file and
add contents to tc */
+static str _process_bam_header(int file_id, str header, _temp_container
*ret_tc);
+static int _append_option_to_bat_cond_str(_temp_container *ret_tc,
_bam_header_option *opt, str cmp, int table, int col, int *appendErr, int
*flag);
+static int _append_option_to_bat_cond_lng(_temp_container *ret_tc,
_bam_header_option *opt, str cmp, int table, int col, int *appendErr, int
*flag);
+static int _append_option_to_bat_cond_flt(_temp_container *ret_tc,
_bam_header_option *opt, str cmp, int table, int col, int *appendErr, int
*flag);
+static int _append_option_to_bat_cond_tms(_temp_container *ret_tc,
_bam_header_option *opt, str cmp, int table, int col, int *appendErr, int
*flag);
+static int _append_option_to_bat(_temp_container *ret_tc, ptr value, int
table, int col, int *appendErr, int *flag);
+static str _read_bam_header_line(str *header, _bam_header_line *ret_hl, int
*eof);
+static void _free_bam_header_line(_bam_header_line *hl);
+static str _process_bam_alignment(int file_id, lng virtual_offset,
bam_header_t *header, bam1_t *alignment, _temp_container *ret_tc, int schema);
+static int _parse_alignment_str(str *sam_alig, str *dest);
+static int _parse_alignment_lng(str *sam_alig, lng *dest);
/* Generic functions */
-static str init_temp_subcontainer(temp_subcontainer *ret_tsc, str *col_names,
int *col_types, int num_cols);
-static str append_to_bat(bat cb, ptr val);
-static str insert_into_vault(Client cntxt, temp_container* tc);
-static int read_string_until_delim(str *src, str *ret, char *delims, int
num_delims);
-static int parse_lng(str *src, lng *i);
-static void append_to_log(str mssg);
-static void free_temp_container(temp_container* tc);
+static str _init_temp_subcontainer(_temp_subcontainer *ret_tsc, str
*col_names, int *col_types, int num_cols);
+static str _append_to_bat(bat cb, ptr val);
+static str _insert_into_vault(Client cntxt, _temp_container* tc);
+static int _read_string_until_delim(str *src, str *ret, char *delims, int
num_delims);
+static int _parse_lng(str *src, lng *i);
+static void _append_to_log(str mssg);
+static void _free_temp_container(_temp_container* tc);
/* File format specific functions */
-str bamloader(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+str
+bamloader(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
/* TODO: This function is now called for BAM files, eventually there will
have to be one generic */
/* function that e.g. receives the file format for which a DV should be
initialized as an argument */
@@ -108,18 +109,18 @@ str bamloader(Client cntxt, MalBlkPtr mb
int num_threads = *(int*) getArgReference(stk,pci,pci->retc+2); /* arg
3: 1: no threads, >1: multi-threaded */
str err1 = NULL, err2 = NULL;
- temp_container *tc = (temp_container *)GDKmalloc(sizeof(temp_container));
+ _temp_container *tc = (_temp_container
*)GDKmalloc(sizeof(_temp_container));
if(tc == NULL)
throw(MAL, "bamloader", MAL_MALLOC_FAIL);
- else if((err1 = init_temp_container_simple(tc)) != MAL_SUCCEED)
- err2 = "Error while creating temp_container: %s\n";
- else if((err1 = loadfile(*repo_path, tc)) != MAL_SUCCEED)
+ else if((err1 = _init_temp_container_simple(tc)) != MAL_SUCCEED)
+ err2 = "Error while creating _temp_container: %s\n";
+ else if((err1 = _loadfile(*repo_path, tc)) != MAL_SUCCEED)
err2 = "Error while loading BAM file: %s\n";
- else if((err1 = insert_into_vault(cntxt, tc)) != MAL_SUCCEED)
+ else if((err1 = _insert_into_vault(cntxt, tc)) != MAL_SUCCEED)
err2 = "Error inserting data into database: %s\n";
- free_temp_container(tc);
+ _free_temp_container(tc);
if(err2 != NULL)
throw(MAL, "bamloader", err2, err1);
@@ -131,17 +132,18 @@ str bamloader(Client cntxt, MalBlkPtr mb
return MAL_SUCCEED;
}
-str init_temp_container_simple(temp_container *ret_tc)
+static str
+_init_temp_container_simple(_temp_container *ret_tc)
{
str err = NULL;
int num_tables = 6;
int num_col_alignments = 13;
- temp_subcontainer *tscs =
(temp_subcontainer*)GDKmalloc(num_tables*sizeof(temp_subcontainer));
+ _temp_subcontainer *tscs =
(_temp_subcontainer*)GDKmalloc(num_tables*sizeof(_temp_subcontainer));
str table_names[] = {"files" , "sq" , "rg" , "pg" ,
"alignments" , "alignments_extra" };
- int num_cols[] = {num_col_files, num_col_sq, num_col_rg, num_col_pg,
num_col_alignments, num_col_alignments_extra};
+ int num_cols[] = {_num_col_files, _num_col_sq, _num_col_rg,
_num_col_pg, num_col_alignments, _num_col_alignments_extra};
int t; /* for loop var */
@@ -155,14 +157,14 @@ str init_temp_container_simple(temp_cont
ret_tc->schema_name = "bam";
/* set tables_columns */
- if((err = init_temp_subcontainer((tscs+0), coln_files, colt_files,
num_col_files)) != MAL_SUCCEED
- || (err = init_temp_subcontainer((tscs+1), coln_sq, colt_sq, num_col_sq))
!= MAL_SUCCEED
- || (err = init_temp_subcontainer((tscs+2), coln_rg, colt_rg, num_col_rg))
!= MAL_SUCCEED
- || (err = init_temp_subcontainer((tscs+3), coln_pg, colt_pg, num_col_pg))
!= MAL_SUCCEED
- || (err = init_temp_subcontainer((tscs+4), coln_alignments,
colt_alignments, num_col_alignments)) != MAL_SUCCEED
- || (err = init_temp_subcontainer((tscs+5), coln_alignments_extra,
colt_alignments_extra, num_col_alignments_extra)) != MAL_SUCCEED
+ if((err = _init_temp_subcontainer((tscs+0), _coln_files, _colt_files,
_num_col_files)) != MAL_SUCCEED
+ || (err = _init_temp_subcontainer((tscs+1), _coln_sq, _colt_sq,
_num_col_sq)) != MAL_SUCCEED
+ || (err = _init_temp_subcontainer((tscs+2), _coln_rg, _colt_rg,
_num_col_rg)) != MAL_SUCCEED
+ || (err = _init_temp_subcontainer((tscs+3), _coln_pg, _colt_pg,
_num_col_pg)) != MAL_SUCCEED
+ || (err = _init_temp_subcontainer((tscs+4), coln_alignments,
colt_alignments, num_col_alignments)) != MAL_SUCCEED
+ || (err = _init_temp_subcontainer((tscs+5), _coln_alignments_extra,
_colt_alignments_extra, _num_col_alignments_extra)) != MAL_SUCCEED
)
- throw(MAL, "init_temp_container", "Error while creating
temp_subcontainer: %s\n", err);
+ throw(MAL, "init_temp_container", "Error while creating
_temp_subcontainer: %s\n", err);
ret_tc->tables_columns = tscs;
@@ -186,7 +188,8 @@ str init_temp_container_simple(temp_cont
return MAL_SUCCEED;
}
-str loadfile(str filepath, temp_container *ret_tc)
+static str
+_loadfile(str filepath, _temp_container *ret_tc)
{
bamFile input;
bam_header_t *header;
@@ -205,7 +208,7 @@ str loadfile(str filepath, temp_containe
bufsize = 256;
buf = GDKmalloc(bufsize*sizeof(char));
snprintf(buf, bufsize, "Opening file %s...", filepath);
- append_to_log(buf);
+ _append_to_log(buf);
/* first try to open file */
input = bam_open(filepath, "r");
@@ -213,12 +216,12 @@ str loadfile(str filepath, temp_containe
throw(MAL, "loadfile", "Cannot read %s \n", filepath);
/* file is valid, store file_id and filepath in bat */
- if((err = append_to_bat(ret_tc->tables_columns[0].column_bats[0], (ptr)
&file_id)) != MAL_SUCCEED)
+ if((err = _append_to_bat(ret_tc->tables_columns[0].column_bats[0], (ptr)
&file_id)) != MAL_SUCCEED)
throw(MAL, "loadfile", "Error appending file_id to files BAT: %s\n",
err);
- if((err = append_to_bat(ret_tc->tables_columns[0].column_bats[1], (ptr)
filepath)) != MAL_SUCCEED)
+ if((err = _append_to_bat(ret_tc->tables_columns[0].column_bats[1], (ptr)
filepath)) != MAL_SUCCEED)
throw(MAL, "loadfile", "Error appending filepath to files BAT: %s\n",
err);
- append_to_log("Processing BAM file header...");
+ _append_to_log("Processing BAM file header...");
/* now retrieve header */
start = GDKms();
@@ -226,30 +229,30 @@ str loadfile(str filepath, temp_containe
if(header == NULL)
throw(MAL, "loadfile", "Error reading header of %s \n", filepath);
headertext_consumable = header->text;
- if((err = process_bam_header(file_id, headertext_consumable, ret_tc))
!= MAL_SUCCEED)
+ if((err = _process_bam_header(file_id, headertext_consumable, ret_tc))
!= MAL_SUCCEED)
{
bam_header_destroy(header);
throw(MAL, "loadfile", "Error processing bam header: %s\n", err);
}
duration_sec = (GDKms() - start) / 1000.0f;
snprintf(buf, bufsize, "Processed bam header in %f seconds = %f minutes =
%f hours", duration_sec, duration_sec/60, duration_sec/3600);
- append_to_log(buf);
+ _append_to_log(buf);
/* now retrieve and process all alignments */
- append_to_log("Processing alignments...");
+ _append_to_log("Processing alignments...");
start = GDKms();
voffset = bam_tell(input);
alignment = bam_init1();
while((alignment_bytes_read = bam_read1(input, alignment)) >= 0)
{
- if((err = process_bam_alignment(file_id, voffset, header, alignment,
ret_tc, SCHEMA_SIMPLE)) != MAL_SUCCEED)
+ if((err = _process_bam_alignment(file_id, voffset, header, alignment,
ret_tc, SCHEMA_SIMPLE)) != MAL_SUCCEED)
throw(MAL, "loadfile", "Error processing bam alignment: %s\n",
err);
num_alignments++;
voffset = bam_tell(input);
}
duration_sec = (GDKms() - start) / 1000.0f;
snprintf(buf, bufsize, "Processed %d alignments in %f seconds = %f minutes
= %f hours", num_alignments, duration_sec, duration_sec/60, duration_sec/3600);
- append_to_log(buf);
+ _append_to_log(buf);
bam_header_destroy(header);
bam_destroy1(alignment);
bam_close(input);
@@ -257,10 +260,11 @@ str loadfile(str filepath, temp_containe
return MAL_SUCCEED;
}
-str process_bam_header(int file_id, str header, temp_container *ret_tc)
+static str
+_process_bam_header(int file_id, str header, _temp_container *ret_tc)
{
/* TODO: consider checking whether or not floating point conversions
succeeded */
- bam_header_line *hl;
+ _bam_header_line *hl;
int i, o;
str err = NULL;
@@ -280,21 +284,21 @@ str process_bam_header(int file_id, str
while(TRUE)
{
/* reserve new memory for this header line */
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list