Changeset: b40553856fac for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b40553856fac Modified Files: clients/mapiclient/mclient.c sql/backends/monet5/bamloader/bam_db_interface.c sql/backends/monet5/bamloader/bam_db_interface.h sql/backends/monet5/bamloader/bam_loader.c sql/backends/monet5/bamloader/bam_wrapper.c Branch: bamloader Log Message:
dded SAMrenderer to mclient. Some minor changes in bam loader code. diffs (230 lines): diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c --- a/clients/mapiclient/mclient.c +++ b/clients/mapiclient/mclient.c @@ -75,6 +75,12 @@ #endif #endif +/* Samtools is not needed for the SAMrenderer, so commented out +#ifdef HAVE_SAMTOOLS +#include "bam.h" +#endif +*/ + #ifndef S_ISCHR #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) #endif @@ -116,7 +122,8 @@ enum formatters { XMLformatter, TESTformatter, CLEANformatter, - TIMERformatter + TIMERformatter, + SAMformatter }; static enum formatters formatter = NOformatter; char *output = NULL; /* output format as string */ @@ -1030,6 +1037,79 @@ TIMERrenderer(MapiHdl hdl) printf("%s\n", timerHuman()); } + +static void +SAMrenderer(MapiHdl hdl) +{ + /* Variables keeping track of which result set fields map to qname, flag etc. (-1 means that it does not occur in result set) */ + int field_qname = -1; + int field_flag = -1; + int field_rname = -1; + int field_pos = -1; + int field_mapq = -1; + int field_cigar = -1; + int field_rnext = -1; + int field_pnext = -1; + int field_tlen = -1; + int field_seq = -1; + int field_qual = -1; + + int field_count = mapi_get_field_count(hdl); + int t_fields; + + int i; + +/* Samtools is not needed for rendering to SAM, so this is commented out +#ifndef HAVE_SAMTOOLS + mnstr_printf(toConsole, "Result set can not be rendered to BAM file, since Samtools could not be found during compilation of mclient\n"); + return; +#endif +*/ + + /* First, initialize field variables properly */ + for(i=0; i<field_count; ++i) { + char *field_name = mapi_get_name(hdl, i); + if(strcmp(field_name, "qname") == 0) { field_qname = i; continue; } + if(strcmp(field_name, "flag" ) == 0) { field_flag = i; continue; } + if(strcmp(field_name, "rname") == 0) { field_rname = i; continue; } + if(strcmp(field_name, "pos" ) == 0) { field_pos = i; continue; } + if(strcmp(field_name, "mapq" ) == 0) { field_mapq = i; continue; } + if(strcmp(field_name, "cigar") == 0) { field_cigar = i; continue; } + if(strcmp(field_name, "rnext") == 0) { field_rnext = i; continue; } + if(strcmp(field_name, "pnext") == 0) { field_pnext = i; continue; } + if(strcmp(field_name, "tlen" ) == 0) { field_tlen = i; continue; } + if(strcmp(field_name, "seq" ) == 0) { field_seq = i; continue; } + if(strcmp(field_name, "qual" ) == 0) { field_qual = i; continue; } + + mnstr_printf(stderr_stream, "Unexpected column name in result set: '%s'. Data in this column is not used.\n", field_name); + } + + /* Write all alignments */ + while (!mnstr_errnr(toConsole) && (t_fields = fetch_row(hdl)) != 0) { + if (t_fields != field_count) { + mnstr_printf(stderr_stream, + "invalid tuple received from server, " + "got %d columns, expected %d, ignoring\n", t_fields, field_count); + continue; + } + + /* Write fields to SAM line */ + mnstr_printf(toConsole, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", + (field_qname == -1 ? "*" : mapi_fetch_field(hdl, field_qname)), + (field_flag == -1 ? "0" : mapi_fetch_field(hdl, field_flag )), + (field_rname == -1 ? "*" : mapi_fetch_field(hdl, field_rname)), + (field_pos == -1 ? "0" : mapi_fetch_field(hdl, field_pos )), + (field_mapq == -1 ? "255" : mapi_fetch_field(hdl, field_mapq )), + (field_cigar == -1 ? "*" : mapi_fetch_field(hdl, field_cigar)), + (field_rnext == -1 ? "*" : mapi_fetch_field(hdl, field_rnext)), + (field_pnext == -1 ? "0" : mapi_fetch_field(hdl, field_pnext)), + (field_tlen == -1 ? "0" : mapi_fetch_field(hdl, field_tlen )), + (field_seq == -1 ? "*" : mapi_fetch_field(hdl, field_seq )), + (field_qual == -1 ? "*" : mapi_fetch_field(hdl, field_qual))); + } +} + + static void SQLheader(MapiHdl hdl, int *len, int fields, char more) { @@ -1381,7 +1461,9 @@ setFormatter(char *s) formatter = TESTformatter; } else if (strcmp(s, "timer") == 0) { formatter = TIMERformatter; - } else { + } else if (strcmp(s, "sam") == 0) { + formatter = SAMformatter; + } else { mnstr_printf(toConsole, "unsupported formatter\n"); } } @@ -1599,6 +1681,9 @@ format_result(Mapi mid, MapiHdl hdl, cha case TIMERformatter: TIMERrenderer(hdl); break; + case SAMformatter: + SAMrenderer(hdl); + break; default: RAWrenderer(hdl); break; @@ -1811,7 +1896,7 @@ showCommands(void) mnstr_printf(toConsole, "\\a - disable auto commit\n"); } mnstr_printf(toConsole, "\\e - echo the query in sql formatting mode\n"); - mnstr_printf(toConsole, "\\f - format using a built-in renderer {csv,tab,raw,sql,xml}\n"); + mnstr_printf(toConsole, "\\f - format using a built-in renderer {csv,tab,raw,sql,xml,sam}\n"); mnstr_printf(toConsole, "\\w# - set maximal page width (-1=unlimited, 0=terminal width, >0=limit to num)\n"); mnstr_printf(toConsole, "\\r# - set maximum rows per page (-1=raw)\n"); mnstr_printf(toConsole, "\\L file - save client/server interaction\n"); diff --git a/sql/backends/monet5/bamloader/bam_db_interface.c b/sql/backends/monet5/bamloader/bam_db_interface.c --- a/sql/backends/monet5/bamloader/bam_db_interface.c +++ b/sql/backends/monet5/bamloader/bam_db_interface.c @@ -188,9 +188,6 @@ char buf_sql_copy_into[BUF_SIZE_COPY_INT - -/* TODO Find out if executed SQL queries get logged somewhere else already, since in that case we shouldn't log it again */ - str create_schema_if_not_exists(Client cntxt, mvc *m, str schemaname, str descr, sql_schema **ret) { sql_schema *result; diff --git a/sql/backends/monet5/bamloader/bam_db_interface.h b/sql/backends/monet5/bamloader/bam_db_interface.h --- a/sql/backends/monet5/bamloader/bam_db_interface.h +++ b/sql/backends/monet5/bamloader/bam_db_interface.h @@ -78,5 +78,4 @@ str create_alignment_storage_1(Client cn str copy_into_db(Client cntxt, bam_wrapper *bw); str drop_file(Client cntxt, str descr, lng file_id, sht dbschema); -/* TODO Consider creating something that truncates everything from the BAM schema */ #endif diff --git a/sql/backends/monet5/bamloader/bam_loader.c b/sql/backends/monet5/bamloader/bam_loader.c --- a/sql/backends/monet5/bamloader/bam_loader.c +++ b/sql/backends/monet5/bamloader/bam_loader.c @@ -155,8 +155,6 @@ bam_loader(Client cntxt, MalBlkPtr mb, s if((msg = create_table_if_not_exists(cntxt, m, s, "pg", SQL_CREATE_PG, "bam.create_pg", NULL)) != MAL_SUCCEED) goto cleanup; /* Get next file id */ - /* TODO Find out if we can indeed reserve file ids here. This is only possible if it is impossible for other MAL instructions - * to get executed in parallel to the bam loader, since then changes could be made to the files table while we're calculating */ TO_LOG("<bam_loader> Retrieving next file id..."); if((msg = next_file_id(m, files_table, &cur_file_id)) != MAL_SUCCEED) { goto cleanup; diff --git a/sql/backends/monet5/bamloader/bam_wrapper.c b/sql/backends/monet5/bamloader/bam_wrapper.c --- a/sql/backends/monet5/bamloader/bam_wrapper.c +++ b/sql/backends/monet5/bamloader/bam_wrapper.c @@ -51,7 +51,7 @@ bsopen(str filepath) { * Takes a bam_wrapper and initializes it. Note that in order for the accompanying clear function to work, the bam_wrapper * should be initialized to zero before the fields are filled in by the init function. * - * TODO: Right now, binaries will be opened in dbfarm/bam, since that is the current working directory. Make sure this is OK. + * Binaries will be opened in dbfarm/bam, since that is the current working directory. */ str init_bam_wrapper(bam_wrapper *bw, str file_location, lng file_id, sht dbschema) { @@ -862,12 +862,8 @@ process_alignment(bam_wrapper *bw, lng v } /* First save the values in the alignment struct that we have to store in additional variables anyway */ - a_out->flag = a_in->core.flag; a_out->pos = a_in->core.pos + 1; - a_out->mapq = a_in->core.qual; - a_out->pnext = a_in->core.mpos + 1; - /* TODO Try out if flag and mapq can be removed, since we would expect being able to directly access the address of something that is stored inside a struct */ - + a_out->pnext = a_in->core.mpos + 1; /* Construct cigar, seq and qual strings in the buffers provided in a_out */ if(a_in->core.n_cigar == 0) { @@ -910,7 +906,7 @@ process_alignment(bam_wrapper *bw, lng v ++bw->cnt_alignments; if(!APPEND_LNG(bw->alignments[0], virtual_offset)) WRITE_ERR_PROCESS_ALIGNMENT("virtual_offset"); if(!APPEND_STR(bw->alignments[1], bam1_qname(a_in))) WRITE_ERR_PROCESS_ALIGNMENT("qname"); - if(!APPEND_SHT(bw->alignments[2], a_out->flag)) WRITE_ERR_PROCESS_ALIGNMENT("flag"); + if(!APPEND_SHT(bw->alignments[2], a_in->core.flag)) WRITE_ERR_PROCESS_ALIGNMENT("flag"); if(a_in->core.tid < 0) { if(!APPEND_STR(bw->alignments[3], "*")) WRITE_ERR_PROCESS_ALIGNMENT("rname"); @@ -919,7 +915,7 @@ process_alignment(bam_wrapper *bw, lng v } if(!APPEND_INT(bw->alignments[4], a_out->pos)) WRITE_ERR_PROCESS_ALIGNMENT("pos"); - if(!APPEND_SHT(bw->alignments[5], a_out->mapq)) WRITE_ERR_PROCESS_ALIGNMENT("mapq"); + if(!APPEND_SHT(bw->alignments[5], a_in->core.qual)) WRITE_ERR_PROCESS_ALIGNMENT("mapq"); if(!APPEND_STR(bw->alignments[6], a_out->cigar)) WRITE_ERR_PROCESS_ALIGNMENT("cigar"); if(a_in->core.mtid < 0) { @@ -940,13 +936,14 @@ process_alignment(bam_wrapper *bw, lng v /* Complete the a_out struct */ a_out->virtual_offset = virtual_offset; strcpy(a_out->qname, bam1_qname(a_in)); + a_out->flag = a_in->core.flag; if(a_in->core.tid < 0) { a_out->rname = "*"; } else { a_out->rname = bw->header->target_name[a_in->core.tid]; } - + a_out->mapq = a_in->core.qual; if(a_in->core.mtid < 0) { a_out->rnext = "*"; } else if(a_in->core.mtid == a_in->core.tid) { _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list