Ejemplo n.º 1
0
static int gtf_in_stream_process_file(GtGTFInStream *gtf_in_stream,
                                      GtError *err)
{
  GtGTFParser *gtf_parser;
  GtStr *filenamestr;
  FILE *fpin;
  int had_err;
  gt_error_check(err);
  gt_assert(gtf_in_stream);

  gtf_parser = gt_gtf_parser_new(gtf_in_stream->type_checker);

  /* open input file */
  if (gtf_in_stream->filename)
    fpin = gt_fa_xfopen(gtf_in_stream->filename, "r");
  else
    fpin = stdin;

  /* parse input file */
  filenamestr = gt_str_new_cstr(gtf_in_stream->filename
                                ? gtf_in_stream->filename : "stdin");
  had_err = gt_gtf_parser_parse(gtf_parser, gtf_in_stream->genome_node_buffer,
                                filenamestr, fpin, gtf_in_stream->tidy, err);
  gt_str_delete(filenamestr);

  /* close input file, if necessary */
  if (gtf_in_stream->filename)
    gt_fa_xfclose(fpin);

  /* free */
  gt_gtf_parser_delete(gtf_parser);

  return had_err;
}
Ejemplo n.º 2
0
int gth_bssm_param_save(GthBSSMParam *bssm_param, const char *filename,
                        GtError *err)
{
    FILE *file;
    int had_err = 0;

    gt_error_check(err);

    file = gt_fa_xfopen(filename, "w");
    gt_assert(file);

    /* check if at least one model is set */
    if (!bssm_param->gt_donor_model_set &&
            !bssm_param->gc_donor_model_set &&
            !bssm_param->ag_acceptor_model_set) {
        gt_error_set(err, "BSSM parameter to write contain no model");
        had_err = -1;
    }

    if (!had_err)
        bssm_param_plain_write(bssm_param, file);

    gt_fa_xfclose(file);

    return had_err;
}
Ejemplo n.º 3
0
GtFile* gt_file_xopen_file_mode(GtFileMode file_mode, const char *path,
                                const char *mode)
{
  GtFile *file;
  gt_assert(mode);
  file = gt_calloc(1, sizeof (GtFile));
  file->mode = file_mode;
  file->reference_count = 0;
  if (path) {
    switch (file_mode) {
      case GT_FILE_MODE_UNCOMPRESSED:
        file->fileptr.file = gt_fa_xfopen(path, mode);
        break;
      case GT_FILE_MODE_GZIP:
        file->fileptr.gzfile = gt_fa_xgzopen(path, mode);
        break;
      case GT_FILE_MODE_BZIP2:
        file->fileptr.bzfile = gt_fa_xbzopen(path, mode);
        file->orig_path = gt_cstr_dup(path);
        file->orig_mode = gt_cstr_dup(path);
        break;
      default: gt_assert(0);
    }
  }
  else {
    gt_assert(file_mode == GT_FILE_MODE_UNCOMPRESSED);
    file->fileptr.file = stdin;
    file->is_stdin = true;
  }
  return file;
}
Ejemplo n.º 4
0
static void enable_logging(const char *debugfp, FILE **logfp)
{
  gt_log_enable();
  if (!strcmp(debugfp, "stdout"))
    gt_log_set_fp(stdout);
  else if (!strcmp(debugfp, "stderr"))
    gt_log_set_fp(stderr);
  else {
    *logfp = gt_fa_xfopen(debugfp, "w");
    gt_log_set_fp(*logfp);
  }
}
Ejemplo n.º 5
0
static void write_fingerprints(char **md5_fingerprints,
                               GtUword num_of_md5s,
                               GtStr *fingerprints_filename,
                               bool use_file_locking)
{
  FILE *fingerprints_file;
  gt_assert(md5_fingerprints && num_of_md5s && fingerprints_filename);
  fingerprints_file = gt_fa_xfopen(gt_str_get(fingerprints_filename), "w");
  if (use_file_locking)
    gt_fa_lock_exclusive(fingerprints_file);
  dump_md5_fingerprints(md5_fingerprints, num_of_md5s, fingerprints_file);
  if (use_file_locking)
    gt_fa_unlock(fingerprints_file);
  gt_fa_xfclose(fingerprints_file);
}
Ejemplo n.º 6
0
/* The following function processes a file. That is, it checkes if the file with
   name <filename> is already contained in the array <files>. If so, the index
   refering to this array is returned. Otherwise, the hash of the file content
   is compared with the hash <filehash>. If the hashes are the same, the
   filename is added to the array and the index is returned. Otherwise, the
   function calls exit(). */
static GtUword process_file(GthInput *input, char *filename,
                                  char *filehash, bool isreferencefile,
                                  GthAlphatype alphatype)
{
  GtWord fileindex;
  FILE *fp;

  if (isreferencefile)
    fileindex = gth_input_determine_reference_file_index(input, filename);
  else
    fileindex = gth_input_determine_genomic_file_index(input, filename);

  if (fileindex == -1) {
    /* file is not contained in array yet -> open file */
    fp = gt_fa_xfopen(filename, "r");

    /* check the hash */
    if (!hashes_are_the_same(filehash, fp)) {
      fprintf(stderr, "apparently file \"%s\" has changed\n", filename);
      exit(EXIT_FAILURE);
    }

    /* hashes equal -> store new file in array and return index number */
    gt_fa_xfclose(fp);
    if (isreferencefile) {
      gth_input_add_reference_file(input, filename, alphatype);
      fileindex = gth_input_num_of_ref_files(input) - 1;
    }
    else {
      gth_input_add_genomic_file(input, filename);
      fileindex = gth_input_num_of_gen_files(input) - 1;
    }
    return fileindex;
  }

  /* file is already contained in array -> return index number */
  return fileindex;
}
Ejemplo n.º 7
0
static bool read_fingerprints(GtMD5Tab *md5_tab,
                              const char *fingerprints_filename,
                              bool use_file_locking)
{
  bool reading_succeeded = true;
  size_t len;
  gt_assert(md5_tab && fingerprints_filename);
  /* open file */
  gt_assert(gt_file_exists(fingerprints_filename));
  if (use_file_locking) {
    md5_tab->fingerprints_file = gt_fa_xfopen(fingerprints_filename, "r");
    gt_fa_lock_shared(md5_tab->fingerprints_file);
  }
  md5_tab->fingerprints = gt_fa_xmmap_read(fingerprints_filename, &len);
  if (len != md5_tab->num_of_md5s * 33) {
    gt_fa_xmunmap(md5_tab->fingerprints);
    md5_tab->fingerprints = NULL;
    gt_fa_unlock(md5_tab->fingerprints_file);
    gt_fa_xfclose(md5_tab->fingerprints_file);
    md5_tab->fingerprints_file = NULL;
    reading_succeeded = false;
  }
  return reading_succeeded;
}