Exemple #1
0
void print_count_result(uint32_t *R,
                        uint32_t num_fields,
                        char *bim)
{

    struct quick_file_info qfile;
    struct output_buffer out_buf;
    size_t i=0;

    if (bim != NULL) {
    	quick_file_init(bim, &qfile);
    }

    init_out_buf(&out_buf, NULL);


    for(; i < num_fields; ++i) {
        if (bim != NULL) {
	    append_out_buf(&out_buf, qfile.lines[i], qfile.line_lens[i]);
        }
        append_out_buf(&out_buf, "\t", 1);
        append_integer_to_out_buf(&out_buf,  R[i]);
        append_out_buf(&out_buf, "\n", 1);
    }
    append_out_buf(&out_buf, "\n", 1);
    quick_file_delete(&qfile);
    free_out_buf(&out_buf);
}
Exemple #2
0
//{{{ void print_query_result_bim(uint32_t *mask,
void print_query_result_bim(uint32_t *mask,
                            uint32_t mask_len,
                            uint32_t *vids,
                            struct gqt_query *q,
                            uint32_t **counts,
                            uint32_t *id_lens,
                            uint32_t num_qs,
                            uint32_t num_fields,
                            char *bim,
                            char *full_cmd)
{
    uint32_t i,j,k,line_idx,bytes, bit_i = 0;

    struct quick_file_info qfile;
    struct output_buffer outbuf;
    char pct[50];


    init_out_buf(&outbuf, NULL);
    quick_file_init(bim, &qfile);


    append_out_buf(&outbuf,
                   qfile.main_buf,
                   qfile.header_len);

    char *info_s = NULL;;

    int r = asprintf(&info_s, 
                     "##%s_queryVersion=%s\n"
                     "##%s_queryCommand=%s\n",
                     PROGRAM_NAME, VERSION,
                     PROGRAM_NAME, full_cmd);
    if (r == -1) err(EX_OSERR, "asprintf error");
                      
    append_out_buf(&outbuf, info_s, strlen(info_s));

    for (k=0; k < num_qs; k++) {
        if ( q[k].variant_op == p_count ) {
            r = asprintf(&info_s, "##INFO=<ID=GQT_%u,Number=1,Type=Integer,"
                         "Description=\"GQT count result from query "
                         "%u\">\n",
                         k, k);
            if (r == -1) err(EX_OSERR, "asprintf error");
            append_out_buf(&outbuf, info_s, strlen(info_s));
        } else if ( q[k].variant_op == p_pct ) {
            r = asprintf(&info_s, "##INFO=<ID=GQT_%u,Number=1,Type=Float,"
                         "Description=\"GQT percent result from query "
                         "%u\">\n",
                         k, k);
            if (r == -1) err(EX_OSERR, "asprintf error");
            append_out_buf(&outbuf, info_s, strlen(info_s));
        } else if ( q[k].variant_op == p_maf ) {
            r = asprintf(&info_s, "##INFO=<ID=GQT_%u,Number=1,Type=Float,"
                         "Description=\"GQT maf result from query "
                         "%u\">\n",
                         k, k);
            if (r == -1) err(EX_OSERR, "asprintf error");
            append_out_buf(&outbuf, info_s, strlen(info_s));
        }

    }

    char last_header_line[]="#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\n";

    append_out_buf(&outbuf, last_header_line, strlen(last_header_line));



    for (i=0; i < mask_len; ++i) {
        bytes = mask[i];
	if (bytes == 0)
            continue; /* skip a bunch of ops if you can */
        for (j=0; j < 32; j++) {
            if (bytes & 1 << (31 - j)) {
	        line_idx = i*32+j;
	        append_out_buf(&outbuf,
                               qfile.lines[line_idx],
                               qfile.line_lens[line_idx]-1);
                for (k=0; k < num_qs; k++) {
                    if ( q[k].variant_op == p_count ) {
                        r = asprintf(&info_s,
                                     ";GQT_%u=%u",
                                     k,
                                     counts[k][line_idx]);
                                //counts[k][vids[line_idx]]);
                        if (r == -1) err(EX_OSERR, "asprintf error");
                        append_out_buf(&outbuf, info_s, strlen(info_s));

                    } else if (q[k].variant_op == p_pct) {
                        r = asprintf(&info_s, ";GQT_%u=%f", k,
                                //((float)counts[k][vids[line_idx]])/
                                ((float)counts[k][line_idx])/
                                ((float) id_lens[k]));
                        if (r == -1) err(EX_OSERR, "asprintf error");
                        append_out_buf(&outbuf, info_s, strlen(info_s));
                    } else if (q[k].variant_op == p_maf) {
                        r = asprintf(&info_s, ";GQT_%u=%f", k,
                                //((float)counts[k][vids[line_idx]])/
                                ((float)counts[k][line_idx])/
                                (((float) id_lens[k])*2.0));
                        if (r == -1) err(EX_OSERR, "asprintf error");
                        append_out_buf(&outbuf, info_s, strlen(info_s));
                    }

                }
                
	        append_out_buf(&outbuf,"\n",1);
            }
	    bit_i++;
	    if (bit_i == num_fields)
	        break;
        }

        if (bit_i == num_fields)
            break;
    }
    quick_file_delete(&qfile);
    free_out_buf(&outbuf);
}
Exemple #3
0
Fichier : gt.c Projet : arq5x/gqt
void print_result(unsigned int len,
                  unsigned int *R,
                  unsigned int num_fields,
                  char *bim)
{

	/* OLD WAY *********************
    unsigned int i,j, bit_i = 0;
    for(i = 0; i < len; ++i) {
        if (i!= 0)
            printf(" ");

        int *r = unpack_1_bit_ints(R[i]);

        for(j = 0; j < 32; ++j) {
            if (j!= 0)
                printf(" ");
            printf("%d", r[j]);

            bit_i += 1;
            if (bit_i == num_fields)
                break;
        }
        if (bit_i == num_fields)
            break;
        free(r);
    }
    printf("\n");


    NEW WAY */

    unsigned int i,j,line_idx,bytes, bit_i = 0;

	struct quick_file_info qfile;
	struct output_buffer outbuf;


	init_out_buf(&outbuf, NULL);
	quick_file_init(bim, &qfile);

	for (i=0; i < len; ++i) {
		bytes = R[i];
		if (bytes == 0) continue; /* skip a bunch of ops if you can */
		for (j=0; j < 32; j++) {
			if (bytes & 1 << (31 - j)) {
				line_idx = i*32+j;
				append_out_buf(&outbuf, qfile.lines[line_idx], qfile.line_lens[line_idx]);
				append_out_buf(&outbuf,"\n",1);
			}
			bit_i++;
	        if (bit_i == num_fields)
	            break;
		}
        if (bit_i == num_fields)
            break;
	}
	quick_file_delete(&qfile);
	free_out_buf(&outbuf);

}