Exemplo n.º 1
0
int gt_hcr_decoder_decode(GtHcrDecoder *hcr_dec, GtUword readnum,
                          char *seq, char *qual, GtStr *desc, GtError *err)
{
    GtUword nearestsample = 0,
            reads_to_read = 0,
            idx,
            current_read = hcr_dec->seq_dec->cur_read ;
    size_t startofnearestsample = 0;
    GtSampling *sampling;
    HcrHuffDataIterator *data_iter;
    GtHuffmanDecoder *huff_dec;

    gt_error_check(err);
    gt_assert(hcr_dec);
    gt_assert(readnum < hcr_dec->seq_dec->num_of_reads);
    gt_assert(seq != NULL && qual != NULL);

    if (current_read == readnum) {
        if (hcr_next_seq_qual(hcr_dec->seq_dec, seq, qual, err) == -1) {
            gt_assert(gt_error_is_set(err));
            return -1;
        }
    }
    else {
        sampling = hcr_dec->seq_dec->sampling;
        data_iter = hcr_dec->seq_dec->data_iter;
        huff_dec = hcr_dec->seq_dec->huff_dec;

        if (sampling != NULL) {
            gt_sampling_get_page(sampling,
                                 readnum,
                                 &nearestsample,
                                 &startofnearestsample);
            /* nearestsample <= cur_read < readnum: current sample is the right one */
            if (nearestsample <= current_read && current_read <= readnum)
                reads_to_read = readnum - current_read;
            else { /* reset decoder to new sample */
                reset_data_iterator_to_pos(data_iter, startofnearestsample);
                (void) gt_huffman_decoder_get_new_mem_chunk(huff_dec, err);
                if (gt_error_is_set(err))
                    return -1;
                reads_to_read = readnum - nearestsample;
                hcr_dec->seq_dec->cur_read = nearestsample;
            }
            gt_log_log("reads to read: "GT_WU", nearest sample: "GT_WU"",
                       reads_to_read,nearestsample);
            gt_log_log("start of nearest: "GT_WU"", (GtUword) startofnearestsample);
        }
        else {
            if (current_read <= readnum)
                reads_to_read = readnum - current_read;
            else {
                reset_data_iterator_to_start(data_iter);
                (void) gt_huffman_decoder_get_new_mem_chunk(huff_dec, err);
                if (gt_error_is_set(err))
                    return -1;
                reads_to_read = readnum;
                hcr_dec->seq_dec->cur_read = 0;
            }
        }

        for (idx = 0; idx < reads_to_read; idx++) {
            if (hcr_next_seq_qual(hcr_dec->seq_dec, seq,qual, err) == -1) {
                gt_assert(gt_error_is_set(err));
                return -1;
            }
            gt_log_log("seq:\n%s\nqual:\n%s", seq, qual);
        }

        if (hcr_next_seq_qual(hcr_dec->seq_dec, seq, qual, err) == -1) {
            gt_assert(gt_error_is_set(err));
            return -1;
        }
    }

    if (hcr_dec->encdesc != NULL) {
        if (gt_encdesc_decode(hcr_dec->encdesc, readnum, desc, err) == -1) {
            gt_error_set(err, "cannot retrieve description with number "GT_WU"."
                         "(%d)", readnum, __LINE__);
            return -1;
        }
    }
    return 0;
}
Exemplo n.º 2
0
int gt_hcr_decoder_decode(GtHcrDecoder *hcr_dec, GtUword readnum,
                          char *seq, char *qual, GtStr *desc, GtError *err)
{
  int had_err = 0;
  GtUword nearestsample = 0,
                reads_to_read = 0,
                idx,
                current_read = hcr_dec->seq_dec->cur_read ;
  size_t startofnearestsample = 0;
  GtSampling *sampling;
  HcrHuffDataIterator *data_iter;
  GtHuffmanDecoder *huff_dec;

  gt_error_check(err);
  gt_assert(hcr_dec);
  gt_assert(readnum < hcr_dec->seq_dec->num_of_reads);
  gt_assert(seq != NULL && qual != NULL);

  if (current_read == readnum)
    had_err = hcr_next_seq_qual(hcr_dec->seq_dec, seq, qual, err) == -1 ?
      -1 : 0;
  else {
    sampling = hcr_dec->seq_dec->sampling;
    data_iter = hcr_dec->seq_dec->data_iter;
    huff_dec = hcr_dec->seq_dec->huff_dec;

    if (sampling != NULL) {
      gt_sampling_get_page(sampling,
                           readnum,
                           &nearestsample,
                           &startofnearestsample);
      /* nearestsample <= cur_read < readnum: current sample is the right one */
      if (nearestsample <= current_read && current_read <= readnum)
        reads_to_read = readnum - current_read;
      else { /* reset decoder to new sample */
        reset_data_iterator_to_pos(data_iter, startofnearestsample);
        had_err = gt_huffman_decoder_get_new_mem_chunk(huff_dec, err);
        reads_to_read = readnum - nearestsample;
        hcr_dec->seq_dec->cur_read = nearestsample;
      }
      gt_log_log("reads to read: "GT_WU", nearest sample: "GT_WU"",
                 reads_to_read,nearestsample);
      gt_log_log("start of nearest: "GT_WU"", (GtUword) startofnearestsample);
    }
    else {
      if (current_read <= readnum)
        reads_to_read = readnum - current_read;
      else {
        reset_data_iterator_to_start(data_iter);
        had_err = gt_huffman_decoder_get_new_mem_chunk(huff_dec, err);
        reads_to_read = readnum;
        hcr_dec->seq_dec->cur_read = 0;
      }
    }

    for (idx = 0; !had_err && idx < reads_to_read; idx++)
      had_err = hcr_next_seq_qual(hcr_dec->seq_dec, seq,qual, err) == -1 ?
        -1 : 0;

    if (!had_err)
      had_err = hcr_next_seq_qual(hcr_dec->seq_dec, seq, qual, err) == -1 ?
        -1 : 0;
  }
  if (had_err)
    gt_assert(gt_error_is_set(err));

  if (!had_err && hcr_dec->encdesc != NULL)
    had_err = gt_encdesc_decode(hcr_dec->encdesc, readnum, desc, err);
  if (had_err)
    gt_assert(gt_error_is_set(err));

  return had_err;
}