コード例 #1
0
ファイル: type_graph.c プロジェクト: AnnSeidel/genometools
bool gt_type_graph_is_partof(GtTypeGraph *type_graph, const char *parent_type,
                             const char *child_type)
{
  const char *parent_id, *child_id;
  GtTypeNode *parent_node, *child_node;
  gt_assert(type_graph && parent_type && child_type);
  /* make sure graph is built */
  if (!type_graph->ready) {
    create_vertices(type_graph);
    type_graph->ready = true;
  }
  /* get parent ID, if the type is not mappable to an ID, assume it is the ID */
  if (!(parent_id = gt_hashmap_get(type_graph->name2id, parent_type)))
    parent_id = parent_type;
  /* get child ID, if the type is not mappable to an ID, assmue it is the ID */
  if (!(child_id = gt_hashmap_get(type_graph->name2id, child_type)))
    child_id = child_type;
  /* get parent node */
  parent_node = gt_hashmap_get(type_graph->nodemap, parent_id);
  gt_assert(parent_node);
  /* get child node */
  child_node = gt_hashmap_get(type_graph->nodemap, child_id);
  gt_assert(child_node);
  /* check for parent */
  return gt_type_node_has_parent(child_node, parent_node,
                                 type_graph->part_of_out_edges,
                                 type_graph->part_of_in_edges,
                                 type_graph->nodes, type_graph->id2name, 0);
}
コード例 #2
0
static GtFeatureNode* find_root(const GtFeatureInfo *fi, const char *id)
{
  const char *delim, *parents;
  GtFeatureNode *this_feature, *parent_pseudo_feature;
  gt_assert(fi && id);
  /* get feature */
  delim = strchr(id, ';');
  if (delim) {
    char *first_parent = gt_cstr_dup_nt(id, delim - id);
    this_feature = gt_hashmap_get(fi->id_to_genome_node, first_parent);
    parent_pseudo_feature = gt_hashmap_get(fi->id_to_pseudo_parent,
                                           first_parent);
    gt_free(first_parent);
  }
  else {
    this_feature = gt_hashmap_get(fi->id_to_genome_node, id);
    parent_pseudo_feature = gt_hashmap_get(fi->id_to_pseudo_parent, id);
  }
  gt_assert(this_feature);
  /* recursion */
  parents = gt_feature_node_get_attribute(this_feature, GT_GFF_PARENT);
  if (parents)
    return find_root(fi, parents);
  else if (parent_pseudo_feature)
    return parent_pseudo_feature;
  return this_feature;
}
コード例 #3
0
ファイル: ma.c プロジェクト: AlexWoroschilow/uni_hamburg
void gt_free_mem(void *ptr, GT_UNUSED const char *src_file,
                 GT_UNUSED int src_line)
{
  MAInfo *mainfo;
  gt_assert(ma);
  if (ptr == NULL) return;
  if (ma->bookkeeping) {
    gt_mutex_lock(bookkeeping_lock);
#ifndef NDEBUG
    if (!gt_hashmap_get(ma->allocated_pointer, ptr)) {
      fprintf(stderr, "bug: double free() attempted on line %d in file "
              "\"%s\"\n", src_line, src_file);
      exit(GT_EXIT_PROGRAMMING_ERROR);
    }
#endif
    mainfo = gt_hashmap_get(ma->allocated_pointer, ptr);
    gt_assert(mainfo);
    subtract_size(ma, mainfo->size);
    gt_hashmap_remove(ma->allocated_pointer, ptr);
    free(ptr);
    gt_mutex_unlock(bookkeeping_lock);
  }
  else {
    free(ptr);
  }
}
コード例 #4
0
ファイル: type_graph.c プロジェクト: AnnSeidel/genometools
static void create_vertices(GtTypeGraph *type_graph)
{
  GtUword i, j;
  GtTypeNode *parent;
  const char *id;
  gt_assert(type_graph && !type_graph->ready);
  /* iterate over nodes */
  for (i = 0; i < gt_array_size(type_graph->nodes); i++) {
    GtTypeNode *node = *(GtTypeNode**) gt_array_get(type_graph->nodes, i);
    /* process is_a parents */
    for (j = 0; j < gt_type_node_is_a_size(node); j++) {
      id = gt_type_node_is_a_get(node, j);
      parent = gt_hashmap_get(type_graph->nodemap, id);
      gt_assert(parent);
      gt_type_node_add_is_a_vertex(node, parent);
    }
    /* process part_of parents */
    for (j = 0; j < gt_type_node_part_of_size(node); j++) {
      id = gt_type_node_part_of_get(node, j);
      parent = gt_hashmap_get(type_graph->nodemap, id);
      gt_assert(parent);
      gt_bool_matrix_set(type_graph->part_of_out_edges, gt_type_node_num(node),
                         gt_type_node_num(parent), true);
      gt_bool_matrix_set(type_graph->part_of_in_edges, gt_type_node_num(parent),
                         gt_type_node_num(node), true);
    }
  }
}
コード例 #5
0
static int gt_orf_finder_visitor_feature_node(GtNodeVisitor *gv,
                                              GtFeatureNode *gf,
                                              GtError *err)
{
  GtORFFinderVisitor *lv;
  const char *gft = NULL;
  GtFeatureNodeIterator *gfi;
  GtFeatureNode *curnode = NULL;
  int had_err = 0;
  GtRange rng;

  lv = gt_orf_finder_visitor_cast(gv);
  gt_assert(lv);
  gt_error_check(err);

  gfi = gt_feature_node_iterator_new(gf);

  while (!had_err && (curnode = gt_feature_node_iterator_next(gfi))) {
    gft = gt_feature_node_get_type(curnode);

    if (gt_hashmap_get(lv->types, (void*) gft) != NULL ||
                       gt_hashmap_get(lv->types,
                                      (void*) "all") == (void*) 1) {
      if (!had_err) {
        rng = gt_genome_node_get_range((GtGenomeNode*) curnode);
        had_err = run_orffinder(lv->rmap, curnode, rng.start - 1, rng.end - 1,
                                lv->min, lv->max, lv->all, err);
        if (gt_hashmap_get(lv->types,
                           (void*) "all") == (void*) 1) {
          break;
        }
        else if (gt_feature_node_has_children(curnode)) {
          GtFeatureNode *tmpnode = NULL;
          GtFeatureNodeIterator *tmpgfi = gt_feature_node_iterator_new(curnode);
          (void) gt_feature_node_iterator_next(tmpgfi);
          while ((tmpnode = gt_feature_node_iterator_next(tmpgfi))) {
            gft = gt_feature_node_get_type(tmpnode);
            if (strcmp(gft, (const char*) GT_ORF_TYPE) == 0) {
              continue;
            }
            /* curnode = gt_feature_node_iterator_next(gfi); */
          }
          gt_feature_node_iterator_delete(tmpgfi);
        }
      }
    }
  }

  gt_feature_node_iterator_delete(gfi);

  return had_err;
}
コード例 #6
0
ファイル: diagram.c プロジェクト: AlexWoroschilow/uni_hamburg
static GtBlock* nodeinfo_find_block(NodeInfoElement* ni, const char *gft,
                                    GtFeatureNode *fn)
{
  PerTypeInfo *type_struc = NULL;
  GtBlockTuple *bt = NULL;
  gt_assert(ni);
  if (!(type_struc = gt_hashmap_get(ni->type_index, gft)))
    return NULL;
  if (!(bt = gt_hashmap_get(type_struc->rep_index, fn)))
    return NULL;
  gt_assert(bt);
  return bt->block;
}
コード例 #7
0
static int gff3_show_feature_node(GtFeatureNode *fn, void *data,
                                  GT_UNUSED GtError *err)
{
  bool part_shown = false;
  GtGFF3Visitor *gff3_visitor = (GtGFF3Visitor*) data;
  GtArray *parent_features = NULL;
  ShowAttributeInfo info;
  GtUword i;
  GtStr *id;

  gt_error_check(err);
  gt_assert(fn && gff3_visitor);

  /* output leading part */
  gt_gff3_output_leading(fn, gff3_visitor->outfp);

  /* show unique id part of attributes */
  if ((id = gt_hashmap_get(gff3_visitor->feature_node_to_unique_id_str, fn))) {
    gt_file_xprintf(gff3_visitor->outfp, "%s=%s", GT_GFF_ID, gt_str_get(id));
    part_shown = true;
  }

  /* show parent part of attributes */
  parent_features = gt_hashmap_get(gff3_visitor->feature_node_to_id_array, fn);
  if (gt_array_size(parent_features)) {
    if (part_shown)
      gt_file_xfputc(';', gff3_visitor->outfp);
    gt_file_xprintf(gff3_visitor->outfp, "%s=", GT_GFF_PARENT);
    for (i = 0; i < gt_array_size(parent_features); i++) {
      if (i)
        gt_file_xfputc(',', gff3_visitor->outfp);
      gt_file_xprintf(gff3_visitor->outfp, "%s",
                      *(char**) gt_array_get(parent_features, i));
    }
    part_shown = true;
  }

  /* show missing part of attributes */
  info.attribute_shown = &part_shown;
  info.outfp = gff3_visitor->outfp;
  gt_feature_node_foreach_attribute(fn, show_attribute, &info);

  /* show dot if no attributes have been shown */
  if (!part_shown)
    gt_file_xfputc('.', gff3_visitor->outfp);

  /* show terminal newline */
  gt_file_xfputc('\n', gff3_visitor->outfp);

  return 0;
}
コード例 #8
0
ファイル: vang.c プロジェクト: jfdenton/AEGeAn
int main(int argc, char **argv)
{
  if(argc != 2)
  {
    fputs("usage: vang schema.file\n", stderr);
    return 1;
  }

  gt_lib_init();

  char *schemafile = argv[1];
  FILE *schema = fopen(schemafile, "r");
  if(schema == NULL)
  {
    fprintf(stderr, "error: unable to open schema file '%s'\n", schemafile);
    return 1;
  }

  GtArray *entry_datatypes = gt_array_new( sizeof(char *) );
  GtHashmap *entries = gt_hashmap_new( GT_HASH_STRING, NULL,
                                       (GtFree)vang_schema_entry_delete );
  VangSchemaEntry *entry;
  while( (entry = vang_schema_entry_next(schema)) != NULL )
  {
    char *datatype = (char *)vang_schema_entry_get_datatype(entry);
    VangSchemaEntry *testentry = gt_hashmap_get(entries, datatype);
    if(testentry != NULL)
    {
      fprintf( stderr, "warning: already have an entry for data type '%s'; "
               "replacing\n", datatype );
      vang_schema_entry_delete(testentry);
    }
    gt_hashmap_add(entries, datatype, entry);
    gt_array_add(entry_datatypes, datatype);
  }

  unsigned long i;
  for(i = 0; i < gt_array_size(entry_datatypes); i++)
  {
    const char *type = *(const char **)gt_array_get(entry_datatypes, i);
    VangSchemaEntry *entry = gt_hashmap_get(entries, type);
    vang_schema_entry_to_string(entry, stdout);
    puts("");
  }
  gt_array_delete(entry_datatypes);
  gt_hashmap_delete(entries);

  gt_lib_clean();

  return 0;
}
コード例 #9
0
static GtHpolProcessorAddToHashResult gt_hpol_processor_add_segment_to_hashmap(
    GtHpolProcessor *hpp, GtAlignedSegment *as)
{
  GtAlignedSegment *stored_as;
  if ((stored_as = gt_hashmap_get(hpp->processed_segments,
          gt_aligned_segment_description(as))) != NULL)
  {
    hpp->nof_multihits++;
    if (!gt_aligned_segment_seq_edited(stored_as) &&
        gt_aligned_segment_seq_edited(as))
    {
      hpp->nof_replaced++;
      /* change with newly edited as */
      gt_hashmap_remove(hpp->processed_segments,
          (void*)gt_aligned_segment_description(as));
      gt_hashmap_add(hpp->processed_segments,
          (void*)gt_aligned_segment_description(as), as);
      return GT_HPOL_PROCESSOR_REPLACED;
    }
    /* otherwise discard (todo: implement combination of edits) */
    else
    {
      return GT_HPOL_PROCESSOR_NOT_REPLACED;
    }
  }
  else
  {
    gt_hashmap_add(hpp->processed_segments,
        (void*)gt_aligned_segment_description(as), as);
    return GT_HPOL_PROCESSOR_NEW_RECORD;
  }
}
コード例 #10
0
ファイル: ma.c プロジェクト: AlexWoroschilow/uni_hamburg
void* gt_realloc_mem(void *ptr, size_t size, const char *src_file, int src_line)
{
  MAInfo *mainfo;
  void *mem;
  gt_assert(ma);
  if (ma->bookkeeping) {
    gt_mutex_lock(bookkeeping_lock);
    ma->mallocevents++;
    if (ptr) {
      mainfo = gt_hashmap_get(ma->allocated_pointer, ptr);
      gt_assert(mainfo);
      subtract_size(ma, mainfo->size);
      gt_hashmap_remove(ma->allocated_pointer, ptr);
    }
    mainfo = xmalloc(sizeof *mainfo, ma->current_size, src_file, src_line);
    mainfo->size = size;
    mainfo->src_file = src_file;
    mainfo->src_line = src_line;
    mem = xrealloc(ptr, size, ma->current_size, src_file, src_line);
    gt_hashmap_add(ma->allocated_pointer, mem, mainfo);
    add_size(ma, size);
    gt_mutex_unlock(bookkeeping_lock);
    return mem;
  }
  return xrealloc(ptr, size, ma->current_size, src_file, src_line);
}
コード例 #11
0
ファイル: toolbox.c プロジェクト: simongog/genometools
bool gt_toolbox_has_tool(const GtToolbox *tb, const char *toolname)
{
  gt_assert(tb && tb->tools);
  if (gt_hashmap_get(tb->tools, toolname))
    return true;
  return false;
}
コード例 #12
0
static int gt_regioncov_visitor_feature_node(GtNodeVisitor *nv,
                                             GtFeatureNode *fn,
                                             GT_UNUSED GtError *err)
{
  GtRange *old_range_ptr, old_range, new_range;
  GtArray *ranges;
  GtRegionCovVisitor *regioncov_visitor;
  gt_error_check(err);
  regioncov_visitor = gt_regioncov_visitor_cast(nv);
  ranges = gt_hashmap_get(regioncov_visitor->region2rangelist,
                       gt_str_get(gt_genome_node_get_seqid((GtGenomeNode*)
                                                           fn)));
  gt_assert(ranges);
  new_range = gt_genome_node_get_range((GtGenomeNode*) fn);
  if (!gt_array_size(ranges))
    gt_array_add(ranges, new_range);
  else {
    old_range_ptr = gt_array_get_last(ranges);
    old_range = *old_range_ptr;
    old_range.end += regioncov_visitor->max_feature_dist;
    if (gt_range_overlap(&old_range, &new_range)) {
      old_range_ptr->end = MAX(old_range_ptr->end, new_range.end);
    }
    else
      gt_array_add(ranges, new_range);
  }
  return 0;
}
コード例 #13
0
ファイル: type_graph.c プロジェクト: AnnSeidel/genometools
void gt_type_graph_add_stanza(GtTypeGraph *type_graph,
                              const GtOBOStanza *stanza)
{
  const char *id_value, *name_value;
  GtUword i, size;
  GtTypeNode *node;
  GtStr *buf;
  gt_assert(type_graph && stanza && !type_graph->ready);
  gt_assert(gt_obo_stanza_size(stanza, "id") == 1);
  gt_assert(gt_obo_stanza_size(stanza, "name") == 1);
  id_value = gt_symbol(gt_obo_stanza_get_value(stanza, "id", 0));
  name_value = gt_symbol(gt_obo_stanza_get_value(stanza, "name", 0));
  gt_assert(id_value);
  gt_assert(name_value);
  gt_assert(!gt_hashmap_get(type_graph->nodemap, id_value));
  node = gt_type_node_new(gt_array_size(type_graph->nodes), id_value);
  gt_hashmap_add(type_graph->name2id, (char*) name_value, (char*) id_value);
  gt_hashmap_add(type_graph->id2name, (char*) id_value, (char*) name_value);
  gt_hashmap_add(type_graph->nodemap, (char*) id_value, node);
  gt_array_add(type_graph->nodes, node);
  buf = gt_str_new();
  /* store is_a entries in node, if necessary */
  if ((size = gt_obo_stanza_size(stanza, "is_a"))) {
    for (i = 0; i < size; i++) {
      const char *id = gt_obo_stanza_get_value(stanza, "is_a", i);
      gt_str_reset(buf);
      gt_str_append_cstr_nt(buf, id, strcspn(id, " \n"));
      gt_type_node_is_a_add(node, gt_symbol(gt_str_get(buf)));
    }
  }
  /* store part_of entries in node, if necessary */
  if ((size = gt_obo_stanza_size(stanza, "relationship"))) {
    for (i = 0; i < size; i++) {
      const char *rel = gt_obo_stanza_get_value(stanza, "relationship", i);
      gt_str_reset(buf);
      /* match part_of */
      if (!strncmp(rel, PART_OF, strlen(PART_OF))) {
        const char *part_of = rel + strlen(PART_OF) + 1;
        gt_str_append_cstr_nt(buf, part_of, strcspn(part_of, " \n"));
        gt_type_node_part_of_add(node, gt_symbol(gt_str_get(buf)));
        continue;
      }
      /* match member_of */
      if (!strncmp(rel, MEMBER_OF, strlen(MEMBER_OF))) {
        const char *member_of = rel + strlen(MEMBER_OF) + 1;
        gt_str_append_cstr_nt(buf, member_of, strcspn(member_of, " \n"));
        gt_type_node_part_of_add(node, gt_symbol(gt_str_get(buf)));
        continue;
      }
      /* match integral_part_of */
      if (!strncmp(rel, INTEGRAL_PART_OF, strlen(INTEGRAL_PART_OF))) {
        const char *integral_part_of = rel + strlen(INTEGRAL_PART_OF) + 1;
        gt_str_append_cstr_nt(buf, integral_part_of,
                              strcspn(integral_part_of, " \n"));
        gt_type_node_part_of_add(node, gt_symbol(gt_str_get(buf)));
      }
    }
  }
  gt_str_delete(buf);
}
コード例 #14
0
ファイル: toolbox.c プロジェクト: simongog/genometools
GtTool* gt_toolbox_get_tool(GtToolbox *tb, const char *toolname)
{
  GtToolinfo *toolinfo;
  gt_assert(tb && tb->tools);
  toolinfo = gt_hashmap_get(tb->tools, toolname);
  if (toolinfo)
    return toolinfo->tool;
  return NULL;
}
コード例 #15
0
const char* gt_xrf_abbr_entry_get_value(const GtXRFAbbrEntry *abbr_entry,
                                        const char *entry_key)
{
  GtStr *s;
  gt_assert(abbr_entry);
  if ((s = gt_hashmap_get(abbr_entry->content, entry_key)))
    return gt_str_get(s);
  return NULL;
}
コード例 #16
0
void gt_xrf_abbr_entry_add(GtXRFAbbrEntry *abbr_entry, const char *tag,
                           const char *value)
{
  GtStr *s;
  gt_assert(abbr_entry && tag && value);
  if (!(s = gt_hashmap_get(abbr_entry->content, tag))) {
    s = gt_str_new_cstr(value);
    gt_hashmap_add(abbr_entry->content, gt_cstr_dup(tag), s);
  }
}
コード例 #17
0
static void gt_hmmer_parse_status_mark_frame_finished(GtHMMERParseStatus *s)
{
  GtHMMERModelHit *mh;
  gt_assert(s && s->models);
  mh = gt_hashmap_get(s->models, gt_str_get(s->cur_model));
  if (mh != NULL) {
    mh->last_array_size_fwd = gt_array_size(mh->fwd_hits);
    mh->last_array_size_rev = gt_array_size(mh->rev_hits);
  }
}
コード例 #18
0
ファイル: AgnFilterStream.c プロジェクト: jfdenton/AEGeAn
static int filter_stream_next(GtNodeStream *ns, GtGenomeNode **gn,
                              GtError *error)
{
  AgnFilterStream *stream;
  GtFeatureNode *fn;
  int had_err;
  gt_error_check(error);
  stream = filter_stream_cast(ns);

  if(gt_queue_size(stream->cache) > 0)
  {
    *gn = gt_queue_get(stream->cache);
    return 0;
  }

  while(1)
  {
    had_err = gt_node_stream_next(stream->in_stream, gn, error);
    if(had_err)
      return had_err;
    if(!*gn)
      return 0;

    fn = gt_feature_node_try_cast(*gn);
    if(!fn)
      return 0;

    GtFeatureNode *current;
    GtFeatureNodeIterator *iter = gt_feature_node_iterator_new(fn);
    for(current  = gt_feature_node_iterator_next(iter);
        current != NULL;
        current  = gt_feature_node_iterator_next(iter))
    {
      const char *type = gt_feature_node_get_type(current);
      bool keepfeature = false;
      if(gt_hashmap_get(stream->typestokeep, type) != NULL)
        keepfeature = true;

      if(keepfeature)
      {
        gt_genome_node_ref((GtGenomeNode *)current);
        gt_queue_add(stream->cache, current);
      }
    }
    gt_feature_node_iterator_delete(iter);
    gt_genome_node_delete((GtGenomeNode *)fn);
    if(gt_queue_size(stream->cache) > 0)
    {
      *gn = gt_queue_get(stream->cache);
      return 0;
    }
  }

  return 0;
}
コード例 #19
0
static int handle_description(GtSeqid2SeqnumMapping *mapping, const char *desc,
                              GtUword seqnum, GtUword filenum,
                              GtError *err)
{
  GtRange descrange;
  GtUword j;
  int had_err = 0;
  SeqidInfo *seqid_info;
  if (gt_parse_description_range(desc, &descrange)) {
    /* no offset could be parsed -> store description as sequence id */
    descrange.start = 1;
    descrange.end = GT_UNDEF_UWORD;
    if ((seqid_info = gt_hashmap_get(mapping->map, desc))) {
      had_err = seqid_info_add(seqid_info, seqnum, filenum,
                               &descrange, mapping->filename, desc, err);
      gt_assert(had_err); /* adding a seqid without range should fail */
    }
    else {
      seqid_info = seqid_info_new(seqnum, filenum, &descrange);
      gt_hashmap_add(mapping->map, gt_cstr_dup(desc), seqid_info);
    }
  } else {
    char *dup;
    /* offset could be parsed -> store description up to ':' as sequence id */
    j = 0;
    while (desc[j] != ':')
      j++;
    dup = gt_malloc((j + 1) * sizeof *dup);
    strncpy(dup, desc, j);
    dup[j] = '\0';
    if ((seqid_info = gt_hashmap_get(mapping->map, dup))) {
      had_err = seqid_info_add(seqid_info, seqnum, filenum, &descrange,
                               mapping->filename, dup, err);
      gt_free(dup);
    }
    else {
      seqid_info = seqid_info_new(seqnum, filenum, &descrange);
      gt_hashmap_add(mapping->map, dup, seqid_info);
    }
  }
  return had_err;
}
コード例 #20
0
ファイル: bed_parser.c プロジェクト: AnnSeidel/genometools
static GtStr* get_seqid(GtBEDParser *bed_parser)
{
  GtStr *seqid = gt_hashmap_get(bed_parser->seqid_to_str_mapping,
                                gt_str_get(bed_parser->word));
  if (!seqid) {
    seqid = gt_str_new_cstr(gt_str_get(bed_parser->word));
    gt_hashmap_add(bed_parser->seqid_to_str_mapping, gt_str_get(seqid), seqid);
  }
  gt_assert(seqid);
  return seqid;
}
コード例 #21
0
ファイル: diagram.c プロジェクト: AlexWoroschilow/uni_hamburg
static NodeInfoElement* nodeinfo_get(GtDiagram *d, GtFeatureNode *node)
{
  NodeInfoElement *ni;
  gt_assert(d && node);
  if (!(ni = gt_hashmap_get(d->nodeinfo, node))) {
    ni = gt_calloc(1, sizeof (NodeInfoElement));
    ni->type_index  = gt_hashmap_new(GT_HASH_STRING, NULL, gt_free_func);
    ni->types       = gt_str_array_new();
    gt_hashmap_add(d->nodeinfo, node, ni);
  }
  return ni;
}
コード例 #22
0
ファイル: md5_tab.c プロジェクト: AlexWoroschilow/uni_hamburg
GtUword gt_md5_tab_map(GtMD5Tab *md5_tab, const char *md5)
{
  const char *value;
  gt_assert(md5_tab && md5);
  if (!md5_tab->md5map)
    build_md5map(md5_tab);
  gt_assert(md5_tab->md5map);
  value = gt_hashmap_get(md5_tab->md5map, md5);
  if (value)
    return ((GtUword) value) - 1;
  return GT_UNDEF_UWORD;
}
コード例 #23
0
ファイル: gff3_visitor.c プロジェクト: ggonnella/genometools
static int add_id(GtFeatureNode *fn, void *data, GT_UNUSED GtError *err)
{
  AddIDInfo *info = (AddIDInfo*) data;
  GtArray *parent_features = NULL;
  gt_error_check(err);
  gt_assert(fn && info && info->gt_feature_node_to_id_array && info->id);
  parent_features = gt_hashmap_get(info->gt_feature_node_to_id_array, fn);
  if (!parent_features) {
    parent_features = gt_array_new(sizeof (char*));
    gt_hashmap_add(info->gt_feature_node_to_id_array, fn, parent_features);
  }
  gt_array_add(parent_features, info->id);
  return 0;
}
コード例 #24
0
bool gt_line_breaker_bases_is_line_occupied(GtLineBreaker* lb, GtLine *line,
                                            GtBlock *block)
{
  GtLineBreakerBases *lbb;
  GtRange r;
  GtIntervalTree *t;
  gt_assert(lb && block && line);
  r = gt_block_get_range(block);
  lbb = gt_line_breaker_bases_cast(lb);
  if (!(t = gt_hashmap_get(lbb->itrees, line)))
    return false;
  else
    return (gt_interval_tree_find_first_overlapping(t, r.start, r.end));
}
コード例 #25
0
static int check_cds_phases_if_necessary(GtFeatureNode *fn,
                                         GtCDSCheckVisitor *v,
                                         bool second_pass, GtError *err)
{
  GtFeatureNodeIterator *fni;
  GtFeatureNode *node;
  GtArray *cds_features = NULL;
  GtHashmap *multi_features = NULL;
  int had_err = 0;
  gt_error_check(err);
  gt_assert(fn);
  fni = gt_feature_node_iterator_new_direct(fn);
  while ((node = gt_feature_node_iterator_next(fni))) {
    if (gt_feature_node_has_type(node, gt_ft_CDS)) {
      if (gt_feature_node_is_multi(node)) {
        GtArray *features;
        if (!multi_features)
          multi_features = gt_hashmap_new(GT_HASH_DIRECT, NULL,
                                          (GtFree) gt_array_delete);
        if ((features =
                gt_hashmap_get(multi_features,
                             gt_feature_node_get_multi_representative(node)))) {
          gt_array_add(features, node);
        }
        else {
          GtFeatureNode *representative;
          features = gt_array_new(sizeof (GtFeatureNode*));
          representative = gt_feature_node_get_multi_representative(node);
          gt_array_add(features, representative);
          gt_hashmap_add(multi_features, representative, features);
        }
      }
      else {
        if (!cds_features)
          cds_features = gt_array_new(sizeof (GtFeatureNode*));
        gt_array_add(cds_features, node);
      }
    }
  }
  if (cds_features)
    had_err = check_cds_phases(cds_features, v, false, second_pass, err);
  if (!had_err && multi_features)
    had_err = gt_hashmap_foreach(multi_features, check_cds_phases_hm, v, err);
  gt_array_delete(cds_features);
  gt_hashmap_delete(multi_features);
  gt_feature_node_iterator_delete(fni);
  return had_err;
}
コード例 #26
0
ファイル: gtr.c プロジェクト: yesimon/genometools
static int run_tests(GtR *gtr, GtError *err)
{
  int test_err = 0, had_err = 0;
  char* key;
  void* value;
  gt_error_check(err);
  gt_assert(gtr);

  /* The following type assumptions are made in the GenomeTools library. */
  gt_ensure(sizeof (char) == 1);
  gt_ensure(sizeof (unsigned char) == 1);
  gt_ensure(sizeof (short) == 2);
  gt_ensure(sizeof (unsigned short) == 2);
  gt_ensure(sizeof (int) == 4);
  gt_ensure(sizeof (unsigned int) == 4);
  gt_ensure(sizeof (GtWord) == 4 || sizeof (GtWord) == 8);
  gt_ensure(sizeof (GtUword) == 4 || sizeof (GtUword) == 8);
  gt_ensure(sizeof (GtUword) >= sizeof (size_t));
  gt_ensure(sizeof (GtInt64) == 8);
  gt_ensure(sizeof (GtUint64) == 8);

  /* show seed */
  printf("seed=%u\n", gtr->seed);
  gt_hashmap_unit_test(err);
  if (gtr->unit_tests) {
    if (gt_str_length(gtr->test_only) > 0) {
      key = gt_str_get(gtr->test_only);
      value = gt_hashmap_get(gtr->unit_tests, key);
      if (value) {
        had_err = gt_unit_test_run(key, value, &test_err, err);
        gt_assert(!had_err); /* cannot happen, gt_unit_test_run() is sane */
      }
      else {
        gt_error_set(err, "Test \"%s\" not found", key);
        return EXIT_FAILURE;
      }
    }
    else {
      had_err = gt_hashmap_foreach_in_key_order(gtr->unit_tests,
                                                gt_unit_test_run, &test_err,
                                                err);
      gt_assert(!had_err); /* cannot happen, gt_unit_test_run() is sane */
    }
  }
  if (test_err)
    return EXIT_FAILURE;
  return EXIT_SUCCESS;
}
コード例 #27
0
int gt_line_breaker_bases_is_line_occupied(GtLineBreaker* lb, bool *result,
                                           GtLine *line, GtBlock *block,
                                           GT_UNUSED GtError *err)
{
  GtLineBreakerBases *lbb;
  GtRange r;
  GtIntervalTree *t;
  gt_assert(lb && block && line);
  r = gt_block_get_range(block);
  lbb = gt_line_breaker_bases_cast(lb);
  if (!(t = gt_hashmap_get(lbb->itrees, line)))
    *result = false;
  else
    *result = (gt_interval_tree_find_first_overlapping(t, r.start, r.end));
  return 0; /* gt_line_breaker_bases_is_line_occupied() is sane */
}
コード例 #28
0
ファイル: gff3_visitor.c プロジェクト: ggonnella/genometools
static int store_ids(GtFeatureNode *fn, void *data, GtError *err)
{
  GtGFF3Visitor *gff3_visitor = (GtGFF3Visitor*) data;
  AddIDInfo add_id_info;
  int had_err = 0;
  GtStr *id;

  gt_error_check(err);
  gt_assert(fn && gff3_visitor);

  if (gt_feature_node_has_children(fn) || gt_feature_node_is_multi(fn) ||
      (gff3_visitor->retain_ids && gt_feature_node_get_attribute(fn, "ID"))) {
    if (gt_feature_node_is_multi(fn)) {
      id = gt_hashmap_get(gff3_visitor->feature_node_to_unique_id_str,
                          gt_feature_node_get_multi_representative(fn));
      if (!id) {
        /* the representative does not have its own id yet -> create it */
        if (gff3_visitor->retain_ids) {
          id = make_id_unique(gff3_visitor,
                              gt_feature_node_get_multi_representative(fn));
        }
        else {
          id = create_unique_id(gff3_visitor,
                                gt_feature_node_get_multi_representative(fn));
        }
      }
      /* store id for feature, if the feature was not the representative */
      if (gt_feature_node_get_multi_representative(fn) != fn) {
        gt_hashmap_add(gff3_visitor->feature_node_to_unique_id_str, fn,
                       gt_str_ref(id));
      }
    }
    else {
      if (gff3_visitor->retain_ids)
        id = make_id_unique(gff3_visitor, fn);
      else
        id = create_unique_id(gff3_visitor, fn);
    }
    /* for each child -> store the parent feature in the hash map */
    add_id_info.gt_feature_node_to_id_array =
      gff3_visitor->feature_node_to_id_array,
    add_id_info.id = gt_str_get(id);
    had_err = gt_feature_node_traverse_direct_children(fn, &add_id_info, add_id,
                                                       err);
  }
  return had_err;
}
コード例 #29
0
ファイル: diagram.c プロジェクト: AlexWoroschilow/uni_hamburg
static int get_caption_display_status(GtDiagram *d, const char *gft,
                                      bool *result, GtError *err)
{
  bool *status;
  gt_assert(d && gft);
  status = (bool*) gt_hashmap_get(d->caption_display_status, gft);
  if (!status)
  {
    GtUword threshold = GT_UNDEF_UWORD;
    double tmp = GT_UNDEF_DOUBLE;
    status = gt_malloc(sizeof (bool));
    *status = true;
    if (gt_style_get_bool(d->style, "format", "show_block_captions", status,
                          NULL, err) == GT_STYLE_QUERY_ERROR) {
      gt_free(status);
      return -1;
    }
    if (*status)
    {
      GtStyleQueryStatus rval;
      rval = gt_style_get_num(d->style,
                              gft, "max_capt_show_width",
                              &tmp, NULL, err);
      switch (rval) {
        case GT_STYLE_QUERY_ERROR:
          gt_free(status);
          return -1;
          break; /* should never reach this */
        case GT_STYLE_QUERY_NOT_SET:
          *status = true;
          break;
        default:
          gt_assert(tmp != GT_UNDEF_DOUBLE);
          threshold = tmp;
          gt_assert(tmp != GT_UNDEF_UWORD);
          *status = (gt_range_length(&d->range) <= threshold);
          break;
      }
        *status = (gt_range_length(&d->range) <= threshold);
    }
    gt_hashmap_add(d->caption_display_status, (void*) gft, status);
  }
  *result = *status;
  return 0;
}
コード例 #30
0
static GtHMMERSingleHit* gt_hmmer_parse_status_get_hit(GtHMMERParseStatus *s,
                                                       GtUword i)
{
  GtHMMERModelHit *mh;
  gt_assert(s && s->models);
  mh = gt_hashmap_get(s->models, gt_str_get(s->cur_model));
  if (mh != NULL) {
    if (s->strand == GT_STRAND_FORWARD) {
      i += mh->last_array_size_fwd;
      gt_assert(i < gt_array_size(mh->fwd_hits));
      return *(GtHMMERSingleHit**) gt_array_get(mh->fwd_hits, i);
    } else {
      i += mh->last_array_size_rev;
      gt_assert(i < gt_array_size(mh->rev_hits));
      return *(GtHMMERSingleHit**) gt_array_get(mh->rev_hits, i);
    }
  } else return NULL;
}