Beispiel #1
0
static int gff3_visitor_region_node(GtNodeVisitor *nv, GtRegionNode *rn,
                                    GT_UNUSED GtError *err)
{
  GtGFF3Visitor *gff3_visitor;
  gt_error_check(err);
  gff3_visitor = gff3_visitor_cast(nv);
  gt_assert(nv && rn);
  gff3_version_string(nv);
  if (!gff3_visitor->outstr) {
    gt_file_xprintf(gff3_visitor->outfp, "%s   %s "GT_WU" "GT_WU"\n",
                    GT_GFF_SEQUENCE_REGION,
                    gt_str_get(gt_genome_node_get_seqid((GtGenomeNode*) rn)),
                    gt_genome_node_get_start((GtGenomeNode*) rn),
                    gt_genome_node_get_end((GtGenomeNode*) rn));
  } else {
    gt_str_append_cstr(gff3_visitor->outstr, GT_GFF_SEQUENCE_REGION);
    gt_str_append_cstr(gff3_visitor->outstr, "   ");
    gt_str_append_cstr(gff3_visitor->outstr,
                      gt_str_get(gt_genome_node_get_seqid((GtGenomeNode*) rn)));
    gt_str_append_char(gff3_visitor->outstr, ' ');
    gt_str_append_ulong(gff3_visitor->outstr,
                                  gt_genome_node_get_start((GtGenomeNode*) rn));
    gt_str_append_char(gff3_visitor->outstr, ' ');
    gt_str_append_ulong(gff3_visitor->outstr,
                                  gt_genome_node_get_end((GtGenomeNode*) rn));
    gt_str_append_char(gff3_visitor->outstr, '\n');
  }
  return 0;
}
Beispiel #2
0
static int gff3_visitor_sequence_node(GtNodeVisitor *nv, GtSequenceNode *sn,
                                      GT_UNUSED GtError *err)
{
  GtGFF3Visitor *gff3_visitor;
  gt_error_check(err);
  gff3_visitor = gff3_visitor_cast(nv);
  gt_assert(nv && sn);
  gff3_version_string(nv);
  if (!gff3_visitor->fasta_directive_shown) {
    if (!gff3_visitor->outstr)
      gt_file_xprintf(gff3_visitor->outfp, "%s\n", GT_GFF_FASTA_DIRECTIVE);
    else {
      gt_str_append_cstr(gff3_visitor->outstr, GT_GFF_FASTA_DIRECTIVE);
      gt_str_append_char(gff3_visitor->outstr, '\n');
    }
    gff3_visitor->fasta_directive_shown = true;
  }
  if (!gff3_visitor->outstr) {
    gt_fasta_show_entry(gt_sequence_node_get_description(sn),
                        gt_sequence_node_get_sequence(sn),
                        gt_sequence_node_get_sequence_length(sn),
                        gff3_visitor->fasta_width, gff3_visitor->outfp);
  } else {
    gt_fasta_show_entry_str(gt_sequence_node_get_description(sn),
                            gt_sequence_node_get_sequence(sn),
                            gt_sequence_node_get_sequence_length(sn),
                            gff3_visitor->fasta_width, gff3_visitor->outstr);
  }
  return 0;
}
Beispiel #3
0
static int gff3_visitor_meta_node(GtNodeVisitor *nv, GtMetaNode *mn,
                                  GT_UNUSED GtError *err)
{
  GtGFF3Visitor *gff3_visitor;
  gt_error_check(err);
  gff3_visitor = gff3_visitor_cast(nv);
  gt_assert(nv && mn);
  if (!gff3_visitor->version_string_shown) {
    if (strncmp(gt_meta_node_get_directive(mn), GT_GFF_VERSION_DIRECTIVE,
                strlen(GT_GFF_VERSION_DIRECTIVE)) == 0
          || strncmp(gt_meta_node_get_directive(mn), GT_GVF_VERSION_DIRECTIVE,
                     strlen(GT_GVF_VERSION_DIRECTIVE)) == 0) {
      gff3_visitor->version_string_shown = true;
    } else {
      gff3_version_string(nv);
    }
  }
  if (!gff3_visitor->outstr) {
    gt_file_xprintf(gff3_visitor->outfp, "##%s %s\n",
                    gt_meta_node_get_directive(mn),
                    gt_meta_node_get_data(mn));

  } else {
    gt_str_append_cstr(gff3_visitor->outstr, "##");
    gt_str_append_cstr(gff3_visitor->outstr, gt_meta_node_get_directive(mn));
    gt_str_append_char(gff3_visitor->outstr, ' ');
    gt_str_append_cstr(gff3_visitor->outstr, gt_meta_node_get_data(mn));
    gt_str_append_char(gff3_visitor->outstr, '\n');
  }
  return 0;
}
Beispiel #4
0
GtNodeVisitor* gt_gff3_visitor_new_to_str(GtStr *outstr)
{
  GtNodeVisitor *nv = gt_node_visitor_create(gt_gff3_visitor_class());
  GtGFF3Visitor *gff3_visitor = gff3_visitor_cast(nv);
  gt_gff3_visitor_init(gff3_visitor);
  gff3_visitor->outfp = NULL;
  gff3_visitor->outstr = gt_str_ref(outstr);
  return nv;
}
Beispiel #5
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);
  gt_gff3_visitor_init(gff3_visitor);
  gff3_visitor->outfp = outfp;
  gff3_visitor->outstr = NULL;
  return nv;
}
static void gff3_visitor_free(GtNodeVisitor *nv)
{
  GtGFF3Visitor *gff3_visitor = gff3_visitor_cast(nv);
  gt_assert(gff3_visitor);
  gt_string_distri_delete(gff3_visitor->id_counter);
  gt_hashmap_delete(gff3_visitor->feature_node_to_id_array);
  gt_hashmap_delete(gff3_visitor->feature_node_to_unique_id_str);
  gt_cstr_table_delete(gff3_visitor->used_ids);
}
static void gff3_version_string(GtNodeVisitor *nv)
{
  GtGFF3Visitor *gff3_visitor = gff3_visitor_cast(nv);
  gt_assert(gff3_visitor);
  if (!gff3_visitor->version_string_shown) {
    gt_file_xprintf(gff3_visitor->outfp, "%s   %u\n", GT_GFF_VERSION_PREFIX,
                    GT_GFF_VERSION);
    gff3_visitor->version_string_shown = true;
  }
}
static int gff3_visitor_comment_node(GtNodeVisitor *nv, GtCommentNode *cn,
                                     GT_UNUSED GtError *err)
{
  GtGFF3Visitor *gff3_visitor;
  gt_error_check(err);
  gff3_visitor = gff3_visitor_cast(nv);
  gt_assert(nv && cn);
  gff3_version_string(nv);
  gt_file_xprintf(gff3_visitor->outfp, "#%s\n",
                  gt_comment_node_get_comment(cn));
  return 0;
}
Beispiel #9
0
static int gff3_visitor_region_node(GtNodeVisitor *nv, GtRegionNode *rn,
                                    GT_UNUSED GtError *err)
{
  GtGFF3Visitor *gff3_visitor;
  gt_error_check(err);
  gff3_visitor = gff3_visitor_cast(nv);
  gt_assert(nv && rn);
  gff3_version_string(nv);
  gt_file_xprintf(gff3_visitor->outfp, "%s   %s %lu %lu\n",
                  GT_GFF_SEQUENCE_REGION,
                  gt_str_get(gt_genome_node_get_seqid((GtGenomeNode*) rn)),
                  gt_genome_node_get_start((GtGenomeNode*) rn),
                  gt_genome_node_get_end((GtGenomeNode*) rn));
  return 0;
}
Beispiel #10
0
static void gff3_version_string(GtNodeVisitor *nv)
{
  GtGFF3Visitor *gff3_visitor = gff3_visitor_cast(nv);
  gt_assert(gff3_visitor);
  if (!gff3_visitor->version_string_shown) {
    if (!gff3_visitor->outstr) {
      gt_file_xprintf(gff3_visitor->outfp, "%s   %u\n", GT_GFF_VERSION_PREFIX,
                      GT_GFF_VERSION);
    } else {
      gt_str_append_cstr(gff3_visitor->outstr, GT_GFF_VERSION_PREFIX);
      gt_str_append_cstr(gff3_visitor->outstr, "   ");
      gt_str_append_uint(gff3_visitor->outstr, GT_GFF_VERSION);
      gt_str_append_char(gff3_visitor->outstr, '\n');
    }
    gff3_visitor->version_string_shown = true;
  }
}
Beispiel #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;
}
Beispiel #12
0
static int gff3_visitor_feature_node(GtNodeVisitor *nv, GtFeatureNode *fn,
                                     GtError *err)
{
  GtGFF3Visitor *gff3_visitor;
  int had_err;
  gt_error_check(err);
  gff3_visitor = gff3_visitor_cast(nv);

  gff3_version_string(nv);

  had_err = gt_feature_node_traverse_children(fn, gff3_visitor, store_ids, true,
                                              err);
  if (!had_err) {
    if (gt_feature_node_is_tree(fn)) {
      had_err = gt_feature_node_traverse_children(fn, gff3_visitor,
                                                  gff3_show_feature_node, true,
                                                  err);
    }
    else {
      /* got a DAG -> traverse in topologically sorted depth first fashion to
         make sure that the 'Parent' attributes are shown in correct order */
      had_err =
        gt_feature_node_traverse_children_top(fn, gff3_visitor,
                                              gff3_show_feature_node, err);
    }
  }

  /* reset hashmaps */
  gt_hashmap_reset(gff3_visitor->feature_node_to_id_array);
  gt_hashmap_reset(gff3_visitor->feature_node_to_unique_id_str);

  /* show terminator, if the feature has children (otherwise it is clear that
     the feature is complete, because no ID attribute has been shown) */
  if (gt_feature_node_has_children(fn) ||
      (gff3_visitor->retain_ids && gt_feature_node_get_attribute(fn, "ID"))) {
    if (!gff3_visitor->outstr)
      gt_file_xprintf(gff3_visitor->outfp, "%s\n", GT_GFF_TERMINATOR);
    else {
      gt_str_append_cstr(gff3_visitor->outstr, GT_GFF_TERMINATOR);
      gt_str_append_char(gff3_visitor->outstr, '\n');
    }
  }

  return had_err;
}
Beispiel #13
0
static int gff3_visitor_comment_node(GtNodeVisitor *nv, GtCommentNode *cn,
                                     GT_UNUSED GtError *err)
{
  GtGFF3Visitor *gff3_visitor;
  gt_error_check(err);
  gff3_visitor = gff3_visitor_cast(nv);
  gt_assert(nv && cn);
  gff3_version_string(nv);
  if (!gff3_visitor->outstr) {
    gt_file_xprintf(gff3_visitor->outfp, "#%s\n",
                    gt_comment_node_get_comment(cn));
  } else  {
    gt_str_append_char(gff3_visitor->outstr, '#');
    gt_str_append_cstr(gff3_visitor->outstr, gt_comment_node_get_comment(cn));
    gt_str_append_char(gff3_visitor->outstr, '\n');
  }
  return 0;
}