示例#1
0
static int region_node_accept(GtGenomeNode *gn, GtNodeVisitor *nv, GtError *err)
{
  GtRegionNode *rn;
  gt_error_check(err);
  rn = gt_region_node_cast(gn);
  return gt_node_visitor_visit_region_node(nv, rn, err);
}
示例#2
0
static void region_node_change_seqid(GtGenomeNode *gn, GtStr *seqid)
{
  GtRegionNode *rn = gt_region_node_cast(gn);
  gt_assert(rn && seqid);
  gt_str_delete(rn->seqid);
  rn->seqid = gt_str_ref(seqid);
}
示例#3
0
static GtFeatureIndex *in_stream_test_data(GtError *error)
{
  GtFeatureIndex *fi;
  GtFeatureNode *fn;
  GtGenomeNode *gn;
  GtRegionNode *rn;
  GtStr *seqid;

  fi = gt_feature_index_memory_new();

  seqid = gt_str_new_cstr("chr1");
  gn = gt_region_node_new(seqid, 1, 100000);
  rn = gt_region_node_cast(gn);
  gt_feature_index_add_region_node(fi, rn, error);
  gt_genome_node_delete(gn);

  gn = gt_feature_node_new(seqid, "region", 500, 5000, GT_STRAND_BOTH);
  fn = gt_feature_node_cast(gn);
  gt_feature_index_add_feature_node(fi, fn, error);
  gt_genome_node_delete(gn);

  gn = gt_feature_node_new(seqid, "region", 50000, 75000, GT_STRAND_BOTH);
  fn = gt_feature_node_cast(gn);
  gt_feature_index_add_feature_node(fi, fn, error);
  gt_genome_node_delete(gn);

  gt_str_delete(seqid);
  seqid = gt_str_new_cstr("scf0001");
  gn = gt_region_node_new(seqid, 1, 10000);
  rn = gt_region_node_cast(gn);
  gt_feature_index_add_region_node(fi, rn, error);
  gt_genome_node_delete(gn);

  gn = gt_feature_node_new(seqid, "mRNA", 4000, 6000, GT_STRAND_REVERSE);
  fn = gt_feature_node_cast(gn);
  gt_feature_index_add_feature_node(fi, fn, error);
  gt_genome_node_delete(gn);

  gn = gt_feature_node_new(seqid, "mRNA", 7000, 9500, GT_STRAND_FORWARD);
  fn = gt_feature_node_cast(gn);
  gt_feature_index_add_feature_node(fi, fn, error);
  gt_genome_node_delete(gn);

  gt_str_delete(seqid);

  return fi;
}
示例#4
0
GtGenomeNode* gt_region_node_new(GtStr *seqid, unsigned long start,
                                               unsigned long end)
{
  GtGenomeNode *gn = gt_genome_node_create(gt_region_node_class());
  GtRegionNode *rn = gt_region_node_cast(gn);
  gt_assert(seqid);
  gt_assert(start <= end);
  rn->seqid = gt_str_ref(seqid);
  rn->range.start = start;
  rn->range.end   = end;
  return gn;
}
示例#5
0
static void region_node_set_range(GtGenomeNode *gn, const GtRange *range)
{
  GtRegionNode *rn = gt_region_node_cast(gn);
  rn->range = *range;
}
示例#6
0
static GtRange region_node_get_range(GtGenomeNode *gn)
{
  GtRegionNode *rn = gt_region_node_cast(gn);
  return rn->range;
}
示例#7
0
static GtStr* region_node_get_seqid(GtGenomeNode *gn)
{
  GtRegionNode *rn = gt_region_node_cast(gn);
  return rn->seqid;
}
示例#8
0
static void region_node_free(GtGenomeNode *gn)
{
  GtRegionNode *rn = gt_region_node_cast(gn);
  gt_assert(rn && rn->seqid);
  gt_str_delete(rn->seqid);
}
示例#9
0
static int chseqids_stream_next(GtNodeStream *gs, GtGenomeNode **gn,
                                GtError *err)
{
  GtChseqidsStream *cs;
  GtGenomeNode *node, **gn_a, **gn_b;
  GtFeatureNode *feature_node;
  GtStr *changed_seqid;
  unsigned long i;
  int rval, had_err = 0;
  gt_error_check(err);
  cs = chseqids_stream_cast(gs);

  if (!cs->sequence_regions_processed) {
    while (!had_err) {
      if (!(had_err = gt_node_stream_next(cs->in_stream, &node, err))) {
        if (node)
          gt_array_add(cs->gt_genome_node_buffer, node);
        else
          break;
        if (!gt_region_node_try_cast(node))
          break; /* no more sequence regions */
      }
    }
    /* now the buffer contains only sequence regions (except the last entry)
       -> change sequence ids */
    for (i = 0; !had_err && i < gt_array_size(cs->gt_genome_node_buffer); i++) {
      node = *(GtGenomeNode**) gt_array_get(cs->gt_genome_node_buffer, i);
      if (gt_genome_node_get_seqid(node)) {
        if  ((changed_seqid = gt_mapping_map_string(cs->chseqids_mapping,
                                     gt_str_get(gt_genome_node_get_seqid(node)),
                                                 err))) {
          if ((feature_node = gt_feature_node_try_cast(node))) {
            rval = gt_genome_node_traverse_children(node, changed_seqid,
                                                    change_sequence_id, true,
                                                    err);
            gt_assert(!rval); /* change_sequence_id() is sane */
          }
          else
            gt_genome_node_change_seqid(node, changed_seqid);
          gt_str_delete(changed_seqid);
        }
        else
          had_err = -1;
       }
    }
    /* sort them */
    if (!had_err)
      gt_genome_nodes_sort(cs->gt_genome_node_buffer);
    /* consolidate them */
    for (i = 1; !had_err && i + 1 < gt_array_size(cs->gt_genome_node_buffer);
         i++) {
      gn_a = gt_array_get(cs->gt_genome_node_buffer, i-1);
      gn_b = gt_array_get(cs->gt_genome_node_buffer, i);
      if (gt_genome_nodes_are_equal_region_nodes(*gn_a, *gn_b)) {
        gt_region_node_consolidate(gt_region_node_cast(*gn_b),
                                   gt_region_node_cast(*gn_a));
        gt_genome_node_delete(*gn_a);
        *gn_a = NULL;
      }
    }
    cs->sequence_regions_processed = true;
  }

  /* return non-null nodes from buffer */
  while (!had_err &&
         cs->buffer_index < gt_array_size(cs->gt_genome_node_buffer)) {
    node = *(GtGenomeNode**) gt_array_get(cs->gt_genome_node_buffer,
                                           cs->buffer_index);
    cs->buffer_index++;
    if (node) {
      *gn = node;
      return had_err;
    }
  }

  if (!had_err)
    had_err = gt_node_stream_next(cs->in_stream, gn, err);
  if (!had_err && *gn) {
    if (gt_genome_node_get_seqid(*gn)) {
      changed_seqid = gt_mapping_map_string(cs->chseqids_mapping,
                                      gt_str_get(gt_genome_node_get_seqid(*gn)),
                                         err);
      gt_assert(changed_seqid); /* is always defined, because an undefined
                                   mapping would be catched earlier */
      if ((feature_node = gt_feature_node_try_cast(*gn))) {
        rval = gt_genome_node_traverse_children(*gn, changed_seqid,
                                                change_sequence_id, true, err);
        gt_assert(!rval); /* change_sequence_id() is sane */
      }
      else
        gt_genome_node_change_seqid(*gn, changed_seqid);
      gt_str_delete(changed_seqid);
    }
  }

  return had_err;
}