int gt_hcr_decoder_decode_range(GtHcrDecoder *hcr_dec, const char *name, GtUword start, GtUword end, GtTimer *timer, GtError *err) { char qual[BUFSIZ] = {0}, seq[BUFSIZ] = {0}; GtStr *desc = gt_str_new(); int had_err = 0; GtUword cur_width, cur_read; size_t i; FILE *output; GT_UNUSED GtHcrSeqDecoder *seq_dec; gt_error_check(err); gt_assert(hcr_dec && name); seq_dec = hcr_dec->seq_dec; gt_assert(start <= end); gt_assert(start < seq_dec->num_of_reads && end < seq_dec->num_of_reads); if (timer != NULL) gt_timer_show_progress(timer, "decode hcr", stdout); output = gt_fa_fopen_with_suffix(name, HCRFILEDECODEDSUFFIX, "w", err); if (output == NULL) had_err = -1; for (cur_read = start; had_err == 0 && cur_read <= end; cur_read++) { if (gt_hcr_decoder_decode(hcr_dec, cur_read, seq, qual, desc, err) != 0) had_err = -1; else { gt_xfputc(HCR_DESCSEPSEQ, output); if (hcr_dec->encdesc != NULL) gt_xfputs(gt_str_get(desc), output); else fprintf(output, ""GT_WU"", cur_read); gt_xfputc('\n', output); for (i = 0, cur_width = 0; i < strlen(seq); i++, cur_width++) { if (cur_width == HCR_LINEWIDTH) { cur_width = 0; gt_xfputc('\n', output); } gt_xfputc(seq[i], output); } gt_xfputc('\n', output); gt_xfputc(HCR_DESCSEPQUAL, output); gt_xfputc('\n', output); for (i = 0, cur_width = 0; i < strlen(qual); i++, cur_width++) { if (cur_width == HCR_LINEWIDTH) { cur_width = 0; gt_xfputc('\n', output); } gt_xfputc(qual[i], output); } gt_xfputc('\n', output); } } gt_fa_xfclose(output); gt_str_delete(desc); return had_err; }
static int gt_compreads_decompress_benchmark(GtHcrDecoder *hcrd, unsigned long amount, GtTimer *timer, GtError *err) { char qual[BUFSIZ] = {0}, seq[BUFSIZ] = {0}; int had_err = 0; unsigned long rand, max_rand = gt_hcr_decoder_num_of_reads(hcrd) - 1, count; GtStr *timer_comment = gt_str_new_cstr("extracting "); GtStr *desc = gt_str_new(); gt_str_append_ulong(timer_comment, amount); gt_str_append_cstr(timer_comment, " reads of "); gt_str_append_ulong(timer_comment, max_rand + 1); gt_str_append_cstr(timer_comment, "!"); if (timer == NULL) { timer = gt_timer_new_with_progress_description("extract random reads"); gt_timer_start(timer); } else { gt_timer_show_progress(timer, "extract random reads", stdout); } gt_log_log("%s",gt_str_get(timer_comment)); for (count = 0; count < amount; count++) { if (!had_err) { rand = gt_rand_max(max_rand); gt_log_log("get read: %lu", rand); had_err = gt_hcr_decoder_decode(hcrd, rand, seq, qual, desc, err); gt_log_log("%s",gt_str_get(desc)); gt_log_log("%s",seq); gt_log_log("%s",qual); } } gt_str_delete(timer_comment); gt_str_delete(desc); if (!gt_showtime_enabled()) gt_timer_delete(timer); return had_err; }