GtOrphanage* gt_orphanage_new(void)
{
  GtOrphanage *o = gt_malloc(sizeof *o);
  o->orphans = gt_queue_new();
  o->missing_parents = gt_cstr_table_new();
  o->orphan_ids = gt_cstr_table_new();
  return o;
}
GthRegionFactory* gth_region_factory_new(bool use_desc_ranges)
{
    GthRegionFactory *srf = gt_calloc(1, sizeof *srf);
    srf->used_seqids = gt_cstr_table_new();
    srf->use_desc_ranges = use_desc_ranges;
    return srf;
}
Exemple #3
0
GtNodeVisitor* gt_stat_visitor_new(bool gene_length_distri,
                                   bool gene_score_distri,
                                   bool exon_length_distri,
                                   bool exon_number_distri,
                                   bool intron_length_distri,
                                   bool cds_length_distri,
                                   bool used_sources)
{
    GtNodeVisitor *nv = gt_node_visitor_create(gt_stat_visitor_class());
    GtStatVisitor *sv = stat_visitor_cast(nv);
    if (gene_length_distri)
        sv->gene_length_distribution = gt_disc_distri_new();
    if (gene_score_distri)
        sv->gene_score_distribution = gt_disc_distri_new();
    if (exon_length_distri)
        sv->exon_length_distribution = gt_disc_distri_new();
    if (exon_number_distri)
        sv->exon_number_distribution = gt_disc_distri_new();
    if (intron_length_distri)
        sv->intron_length_distribution = gt_disc_distri_new();
    if (cds_length_distri)
        sv->cds_length_distribution = gt_disc_distri_new();
    if (used_sources)
        sv->used_sources = gt_cstr_table_new();
    return nv;
}
static int gt_seqids_runner(GT_UNUSED int argc, const char **argv,
                                  int parsed_args,
                                  GT_UNUSED void *tool_arguments, GtError *err)
{
  GtNodeStream *in_stream, *v_stream;
  GtCstrTable *cst;
  int had_err = 0;
  gt_error_check(err);

  cst = gt_cstr_table_new();
  in_stream = gt_gff3_in_stream_new_unsorted(argc - parsed_args,
                                             argv + parsed_args);
  v_stream = gt_visitor_stream_new(in_stream, gt_collect_ids_visitor_new(cst));

  had_err = gt_node_stream_pull(v_stream, err);
  if (!had_err) {
    GtStrArray *seqids;
    GtUword i;
    seqids = gt_cstr_table_get_all(cst);
    for (i = 0; i < gt_str_array_size(seqids); i++) {
      printf("%s\n", gt_str_array_get(seqids, i));
    }
    gt_str_array_delete(seqids);
  }

  gt_node_stream_delete(v_stream);
  gt_node_stream_delete(in_stream);
  gt_cstr_table_delete(cst);
  return had_err;
}
Exemple #5
0
void gt_symbol_init(void)
{
  if (!symbols)
    symbols = gt_cstr_table_new();
  if (!symbol_mutex)
    symbol_mutex = gt_mutex_new();
}
static GtCstrTable* gt_rdb_mysql_get_indexes(GtRDB *rdb, GtError *err)
{
  GT_UNUSED GtRDBMySQL *rdbm;
  GtRDBStmt *stmt;
  GtCstrTable *tab;
  int rval = 0;
  gt_assert(rdb);
  gt_error_check(err);
  rdbm = gt_rdb_mysql_cast(rdb);
  /* TODO: implement a way to do this in MySQL 4 */
  if ((stmt = gt_rdb_prepare(rdb, "SELECT DISTINCT INDEX_NAME "
                                  "FROM INFORMATION_SCHEMA.STATISTICS ",
                                  0,
                                  err)) == NULL)
    return NULL;
  tab = gt_cstr_table_new();
  while (!rval) {
    GtStr *key;
    rval = gt_rdb_stmt_exec(stmt, err);
    if (rval) break;
    key = gt_str_new();
    gt_rdb_stmt_get_string(stmt, 0, key, err);
    gt_cstr_table_add(tab, gt_str_get(key));
    gt_str_delete(key);
  }
  if (rval < 0) {
    gt_cstr_table_delete(tab);
    gt_rdb_stmt_delete(stmt);
    return NULL;
  }
  gt_rdb_stmt_delete(stmt);
  return tab;
}
static GtCstrTable* gt_rdb_mysql_get_tables(GtRDB *rdb, GtError *err)
{
  GtRDBMySQL *rdbm;
  MYSQL_RES *res;
  MYSQL_ROW row;
  GtCstrTable *tab;
  gt_assert(rdb);
  gt_error_check(err);
  rdbm = gt_rdb_mysql_cast(rdb);
  gt_assert(&rdbm->conn);
  res = mysql_list_tables(&rdbm->conn, NULL); /* NULL means 'all tables' */
  if (!res) {
    gt_error_set(err, "error trying to list tables: %s",
                 mysql_error(&rdbm->conn));
    return NULL;
  }
  tab = gt_cstr_table_new();
  while ((row = mysql_fetch_row(res))) {
    char buf[BUFSIZ];
    GtUword *lengths;
    memset(buf, 0, BUFSIZ);
    lengths = mysql_fetch_lengths(res);
    (void) snprintf(buf, MIN(BUFSIZ, lengths[0])*sizeof (char), "%s",
                    (char*) row[0] ? (char*) row[0] : "NULL");
    gt_cstr_table_add(tab, buf);
  }
  mysql_free_result(res);
  return tab;
}
GtNodeVisitor* gt_add_ids_visitor_new(bool ensure_sorting)
{
  GtNodeVisitor *nv = gt_node_visitor_create(gt_add_ids_visitor_class());
  GtAddIDsVisitor *add_ids_visitor = add_ids_visitor_cast(nv);
  add_ids_visitor->node_buffer = gt_queue_new();
  add_ids_visitor->defined_seqids = gt_cstr_table_new();
  add_ids_visitor->undefined_sequence_regions =
    gt_hashmap_new(GT_HASH_STRING, NULL,
                   (GtFree) automatic_sequence_region_delete);
  add_ids_visitor->ensure_sorting = ensure_sorting;
  return nv;
}
Exemple #9
0
static void gt_gff3_visitor_init(GtGFF3Visitor *gff3_visitor)
{
  gff3_visitor->version_string_shown = false;
  gff3_visitor->fasta_directive_shown = false;
  gff3_visitor->id_counter = gt_string_distri_new();
  gff3_visitor->feature_node_to_id_array =
    gt_hashmap_new(GT_HASH_DIRECT, NULL, (GtFree) gt_array_delete);
  gff3_visitor->feature_node_to_unique_id_str =
    gt_hashmap_new(GT_HASH_DIRECT, NULL, (GtFree) gt_str_delete);
  gff3_visitor->fasta_width = 0;
  gff3_visitor->used_ids = gt_cstr_table_new();
  /* XXX */
  gff3_visitor->retain_ids = getenv("GT_RETAINIDS") ? true : false;
  gff3_visitor->allow_nonunique_ids = false;
}
GtNodeStream* gt_sequence_node_add_stream_new(GtNodeStream *in_stream,
                                              GtRegionMapping *rm,
                                              GT_UNUSED GtError *err)
{
  GtNodeStream *ns = gt_node_stream_create(gt_sequence_node_add_stream_class(),
                                           gt_node_stream_is_sorted(in_stream));
  GtSequenceNodeAddStream *s = gt_sequence_node_add_stream_cast(ns);
  gt_assert(in_stream);
  s->rm = rm;
  s->in_stream = gt_node_stream_ref(in_stream);
  s->seqid_table = gt_cstr_table_new();
  s->seqids = NULL;
  s->cur_seqid = 0;
  s->collect_vis = gt_collect_ids_visitor_new(s->seqid_table);
  return ns;
}
Exemple #11
0
GtNodeVisitor* gt_gff3_visitor_new(GtFile *outfp)
{
  GtNodeVisitor *nv = gt_node_visitor_create(gt_gff3_visitor_class());
  GtGFF3Visitor *gff3_visitor = gff3_visitor_cast(nv);
  gff3_visitor->version_string_shown = false;
  gff3_visitor->fasta_directive_shown = false;
  gff3_visitor->id_counter = gt_string_distri_new();
  gff3_visitor->feature_node_to_id_array =
    gt_hashmap_new(GT_HASH_DIRECT, NULL, (GtFree) gt_array_delete);
  gff3_visitor->feature_node_to_unique_id_str =
    gt_hashmap_new(GT_HASH_DIRECT, NULL, (GtFree) gt_str_delete);
  gff3_visitor->fasta_width = 0;
  gff3_visitor->outfp = outfp;
  gff3_visitor->used_ids = gt_cstr_table_new();
  gff3_visitor->retain_ids = false;
  return nv;
}
Exemple #12
0
/* takes ownership of <files> */
static GtNodeStream* gff3_in_stream_plain_new(GtStrArray *files,
                                              bool ensure_sorting)
{
  GtNodeStream *ns = gt_node_stream_create(gt_gff3_in_stream_plain_class(),
                                           ensure_sorting);
  GtGFF3InStreamPlain *gff3_in_stream_plain = gff3_in_stream_plain_cast(ns);
  gff3_in_stream_plain->next_file          = 0;
  gff3_in_stream_plain->files              = files;
  gff3_in_stream_plain->stdinstr           = gt_str_new_cstr("stdin");
  gff3_in_stream_plain->ensure_sorting     = ensure_sorting;
  gff3_in_stream_plain->stdin_argument     = false;
  gff3_in_stream_plain->file_is_open       = false;
  gff3_in_stream_plain->fpin               = NULL;
  gff3_in_stream_plain->line_number        = 0;
  gff3_in_stream_plain->genome_node_buffer = gt_queue_new();
  gff3_in_stream_plain->checkids           = false;
  gff3_in_stream_plain->checkregions       = false;
  gff3_in_stream_plain->gff3_parser        = gt_gff3_parser_new(NULL);
  gff3_in_stream_plain->used_types         = gt_cstr_table_new();
  gff3_in_stream_plain->progress_bar       = false;
  return ns;
}