/*generic IO function for one condenseq unique entry*/
static int condenseq_uniqueentry_io(GtCondenseqUnique* unique,
                                    FILE* fp,
                                    GtIOFunc io_func,
                                    GtError *err)
{
  int had_err = 0;
  gt_assert (unique != NULL);
  had_err = gt_condenseq_io_one(unique->orig_startpos);
  if (!had_err)
    had_err = gt_condenseq_io_one(unique->len);
  return had_err;
}
/*generic IO function for one condenseq link entry*/
static int condenseq_linkentry_io(GtCondenseqLink* link,
                                  FILE* fp,
                                  GtIOFunc io_func,
                                  GtError *err)
{
  int had_err = 0;
  gt_assert (link != NULL);
  had_err = gt_condenseq_io_one(link->orig_startpos);
  if (!had_err)
    had_err = gt_condenseq_io_one(link->len);
  if (!had_err)
    had_err = gt_condenseq_io_one(link->unique_id);
  if (!had_err)
    had_err = gt_condenseq_io_one(link->unique_offset);
  if (!had_err) {
    link->editscript = gt_editscript_io(link->editscript, fp, err);
    if (link->editscript == NULL) {
      had_err = 1;
    }
  }
  return had_err;
}
/*generic IO function for condenseq data structure*/
static int condenseq_io(GtCondenseq *condenseq,
                        FILE* fp,
                        GtIOFunc io_func,
                        GtError *err)
{
  int had_err = 0;
  int file_format = GT_CONDENSEQ_VERSION;
  GtUword idx;
  had_err = gt_condenseq_io_one(condenseq->orig_length);
  if (!had_err)
    had_err = gt_condenseq_io_one(file_format);
  if (!had_err && file_format != GT_CONDENSEQ_VERSION) {
    gt_error_set(err, "condenseq index is format version %d, current is "
                 "%d -- please re-encode",
                 file_format, GT_CONDENSEQ_VERSION);
    had_err = -1;
  }
  if (!had_err)
    had_err = gt_condenseq_io_one(condenseq->orig_num_seq);
  if (!had_err)
    had_err = gt_condenseq_io_one(condenseq->ldb_nelems);
  if (!had_err) {
    gt_assert(condenseq->ldb_nelems > 0);
    if (condenseq->links == NULL) {
      condenseq->links = gt_calloc((size_t) condenseq->ldb_nelems,
                                   sizeof (*condenseq->links));
      condenseq->ldb_allocated = condenseq->ldb_nelems;
    }

    had_err = gt_condenseq_io_one(condenseq->udb_nelems);
  }

  if (!had_err) {
    gt_assert(condenseq->udb_nelems > 0);

    if (condenseq->uniques == NULL) {
      condenseq->uniques = gt_malloc(sizeof (*condenseq->uniques) *
                                     condenseq->udb_nelems );
      condenseq->udb_allocated = condenseq->udb_nelems;
    }
  }

  for (idx = 0; !had_err && idx < condenseq->ldb_nelems; idx++) {
    had_err = condenseq_linkentry_io(&condenseq->links[idx], fp, io_func, err);
  }

  for (idx = 0; !had_err && idx < condenseq->udb_nelems; idx++) {
    had_err = condenseq_uniqueentry_io(&condenseq->uniques[idx], fp, io_func,
                                       err);
  }
  if (!had_err && condenseq->orig_num_seq > (GtUword) 1) {
    condenseq->ssptab = gt_intset_io(condenseq->ssptab, fp, err);
    if (condenseq->ssptab == NULL)
      had_err = 1;
  }
  if (!had_err)
    had_err = gt_condenseq_io_one(condenseq->id_len);
  if (!had_err) {
    if (condenseq->id_len == GT_UNDEF_UWORD) {
      condenseq->sdstab = gt_intset_io(condenseq->sdstab, fp, err);
      if (condenseq->sdstab == NULL)
        had_err = 1;
    }
  }
  if (!had_err)
    had_err = gt_condenseq_io_one(condenseq->ids_total_len);
  if (!had_err) {
    condenseq->orig_ids = gt_realloc(condenseq->orig_ids,
                                     (size_t) condenseq->ids_total_len);
    had_err = io_func(condenseq->orig_ids, sizeof (*condenseq->orig_ids),
                      (size_t) condenseq->ids_total_len, fp, err);
  }
  return had_err;
}
Esempio n. 4
0
static int condenseq_io(GtCondenseq *condenseq,
                        FILE* fp,
                        GtIOFunc io_func,
                        GtError *err)
{
  int had_err = 0;
  int file_format = GT_CONDENSEQ_VERSION;
  GtUword idx;
  had_err = gt_condenseq_io_one(condenseq->orig_length);
  if (!had_err)
    had_err = gt_condenseq_io_one(file_format);
  if (!had_err && file_format != GT_CONDENSEQ_VERSION) {
    gt_error_set(err, "condenseq index is format version %d, current is "
                 "%d -- please re-encode",
                 file_format, GT_CONDENSEQ_VERSION);
    had_err = -1;
  }
  if (!had_err)
    had_err = gt_condenseq_io_one(condenseq->orig_num_seq);
  if (!had_err)
    had_err = gt_condenseq_io_one(condenseq->ldb_nelems);
  if (!had_err) {
    if (condenseq->ldb_nelems == 0) {
      gt_warning("compression of condenseq did not succeed in finding any "
                 "compressable similarities, maybe the input is to small or "
                 "the chosen parameters should be reconsidered.");
    }
    if (condenseq->links == NULL) {
      condenseq->links = gt_calloc((size_t) condenseq->ldb_nelems,
                                   sizeof (*condenseq->links));
      condenseq->ldb_allocated = condenseq->ldb_nelems;
    }

    had_err = gt_condenseq_io_one(condenseq->udb_nelems);
  }

  if (!had_err) {
    gt_assert(condenseq->udb_nelems > 0);

    if (condenseq->uniques == NULL) {
      condenseq->uniques = gt_malloc(sizeof (*condenseq->uniques) *
                                     condenseq->udb_nelems );
      condenseq->udb_allocated = condenseq->udb_nelems;
    }
  }

  for (idx = 0; !had_err && idx < condenseq->ldb_nelems; idx++) {
    had_err = condenseq_linkentry_io(&condenseq->links[idx], fp, io_func, err);
  }

  for (idx = 0; !had_err && idx < condenseq->udb_nelems; idx++) {
    had_err = condenseq_uniqueentry_io(&condenseq->uniques[idx], fp, io_func,
                                       err);
  }
  if (!had_err && condenseq->orig_num_seq > (GtUword) 1) {
    condenseq->ssptab = gt_intset_io(condenseq->ssptab, fp, err);
    if (condenseq->ssptab == NULL)
      had_err = 1;
  }
  if (!had_err)
    had_err = gt_condenseq_io_one(condenseq->id_len);
  if (!had_err) {
    if (condenseq->id_len == GT_UNDEF_UWORD) {
      condenseq->sdstab = gt_intset_io(condenseq->sdstab, fp, err);
      if (condenseq->sdstab == NULL)
        had_err = 1;
    }
  }
  if (!had_err)
    had_err = gt_condenseq_io_one(condenseq->ids_total_len);
  if (!had_err) {
    condenseq->orig_ids = gt_realloc(condenseq->orig_ids,
                                     (size_t) condenseq->ids_total_len);
    had_err = io_func(condenseq->orig_ids, sizeof (*condenseq->orig_ids),
                      (size_t) condenseq->ids_total_len, fp, err);
  }
  return had_err;
}