Exemplo n.º 1
0
GtFeatureIndex *agn_import_canonical(int numfiles, const char **filenames,
                                     AgnLogger *logger)
{
  GtNodeStream *gff3 = gt_gff3_in_stream_new_unsorted(numfiles, filenames);
  gt_gff3_in_stream_check_id_attributes((GtGFF3InStream *)gff3);
  gt_gff3_in_stream_enable_tidy_mode((GtGFF3InStream *)gff3);

  GtFeatureIndex *features = gt_feature_index_memory_new();
  GtNodeStream *cgstream = agn_canon_gene_stream_new(gff3, logger);
  GtNodeStream *featstream = gt_feature_out_stream_new(cgstream, features);

  GtError *error = gt_error_new();
  int result = gt_node_stream_pull(featstream, error);
  if(result == -1)
  {
    agn_logger_log_error(logger, "error processing node stream: %s",
                         gt_error_get(error));
  }
  gt_error_delete(error);

  if(agn_logger_has_error(logger))
  {
    gt_feature_index_delete(features);
    features = NULL;
  }
  gt_node_stream_delete(gff3);
  gt_node_stream_delete(cgstream);
  gt_node_stream_delete(featstream);
  return features;
}
Exemplo n.º 2
0
static int gt_csa_runner(GT_UNUSED int argc, const char **argv, int parsed_args,
                         void *tool_arguments, GtError *err)
{
  GtNodeStream *gff3_in_stream, *csa_stream, *gff3_out_stream;
  CSAArguments *arguments = tool_arguments;
  int had_err;

  gt_error_check(err);
  gt_assert(arguments);

  /* create the streams */
  gff3_in_stream  = gt_gff3_in_stream_new_sorted(argv[parsed_args]);
  if (arguments->verbose && arguments->outfp)
    gt_gff3_in_stream_show_progress_bar((GtGFF3InStream*) gff3_in_stream);
  csa_stream      = gt_csa_stream_new(gff3_in_stream, arguments->join_length);
  gff3_out_stream = gt_gff3_out_stream_new(csa_stream, arguments->outfp);

  /* pull the features through the stream and free them afterwards */
  had_err = gt_node_stream_pull(gff3_out_stream, err);

  /* free */
  gt_node_stream_delete(gff3_out_stream);
  gt_node_stream_delete(csa_stream);
  gt_node_stream_delete(gff3_in_stream);

  return had_err;
}
Exemplo n.º 3
0
static int gt_bed_to_gff3_runner(GT_UNUSED int argc, const char **argv,
                                 int parsed_args, void *tool_arguments,
                                 GtError *err)
{
  GtNodeStream *bed_in_stream = NULL, *gff3_out_stream = NULL;
  BEDToGFF3Arguments *arguments = tool_arguments;
  int had_err;

  gt_error_check(err);

  /* create a BED input stream */
  bed_in_stream = gt_bed_in_stream_new(argv[parsed_args]);
  gt_bed_in_stream_set_feature_type((GtBEDInStream*) bed_in_stream,
                                    gt_str_get(arguments->feature_type));
  gt_bed_in_stream_set_thick_feature_type((GtBEDInStream*) bed_in_stream,
                                          gt_str_get(arguments
                                                     ->thick_feature_type));
  gt_bed_in_stream_set_block_type((GtBEDInStream*) bed_in_stream,
                                  gt_str_get(arguments->block_type));

  /* create a GFF3 output stream */
  /* XXX: use proper genfile */
  gff3_out_stream = gt_gff3_out_stream_new(bed_in_stream, NULL);

  /* pull the features through the stream and free them afterwards */
  had_err = gt_node_stream_pull(gff3_out_stream, err);

  /* free */
  gt_node_stream_delete(gff3_out_stream);
  gt_node_stream_delete(bed_in_stream);

  return had_err;
}
Exemplo n.º 4
0
static void infer_cds_visitor_test_data(GtQueue *queue)
{
  GtError *error = gt_error_new();
  const char *file = "data/gff3/grape-codons.gff3";
  GtNodeStream *gff3in = gt_gff3_in_stream_new_unsorted(1, &file);
  gt_gff3_in_stream_check_id_attributes((GtGFF3InStream *)gff3in);
  gt_gff3_in_stream_enable_tidy_mode((GtGFF3InStream *)gff3in);
  GtLogger *logger = gt_logger_new(true, "", stderr);
  GtNodeStream *icv_stream = agn_infer_cds_stream_new(gff3in, NULL, logger);
  GtArray *feats = gt_array_new( sizeof(GtFeatureNode *) );
  GtNodeStream *arraystream = gt_array_out_stream_new(icv_stream, feats, error);
  int pullresult = gt_node_stream_pull(arraystream, error);
  if(pullresult == -1)
  {
    fprintf(stderr, "[AgnInferCDSVisitor::infer_cds_visitor_test_data] error "
            "processing features: %s\n", gt_error_get(error));
  }
  gt_node_stream_delete(gff3in);
  gt_node_stream_delete(icv_stream);
  gt_node_stream_delete(arraystream);
  gt_logger_delete(logger);
  gt_array_sort(feats, (GtCompare)agn_genome_node_compare);
  gt_array_reverse(feats);
  while(gt_array_size(feats) > 0)
  {
    GtFeatureNode *fn = *(GtFeatureNode **)gt_array_pop(feats);
    gt_queue_add(queue, fn);
  }
  gt_array_delete(feats);
  gt_error_delete(error);
}
Exemplo n.º 5
0
int gt_gff3_to_gtf(int argc, const char **argv, GtError *err)
{
  GtNodeStream *gff3_in_stream = NULL, *gtf_out_stream = NULL;
  int parsed_args, had_err = 0;
  gt_error_check(err);

  /* option parsing */
  switch (parse_options(&parsed_args, argc, argv, err)) {
    case OPTIONPARSER_OK: break;
    case OPTIONPARSER_ERROR: return -1;
    case OPTIONPARSER_REQUESTS_EXIT: return 0;
  }

  /* create a gff3 input stream */
  gff3_in_stream = gt_gff3_in_stream_new_unsorted(argc - parsed_args,
                                                  argv + parsed_args);

  if (!gff3_in_stream)
    had_err = -1;

  if (!had_err) {
    /* create a gtf output stream */
    gtf_out_stream = gt_gtf_out_stream_new(gff3_in_stream, NULL);

    /* pull the features through the stream and free them afterwards */
    had_err = gt_node_stream_pull(gtf_out_stream, err);
  }

  /* free */
  gt_node_stream_delete(gff3_in_stream);
  gt_node_stream_delete(gtf_out_stream);

  return had_err;
}
Exemplo n.º 6
0
static int gt_mergefeat_runner(int argc, const char **argv, int parsed_args,
                          void *tool_arguments, GtError *err)
{
  InterFeatArguments *arguments = tool_arguments;
  GtNodeStream *gff3_in_stream,
               *merge_feature_stream,
               *gff3_out_stream;
  int had_err;

  gt_error_check(err);
  gt_assert(arguments);

  /* create a gff3 input stream */
  gff3_in_stream = gt_gff3_in_stream_new_unsorted(argc - parsed_args,
                                                  argv + parsed_args);

  /* create merge feature stream */
  merge_feature_stream = gt_merge_feature_stream_new(gff3_in_stream);

  /* create gff3 output stream */
  gff3_out_stream = gt_gff3_out_stream_new(merge_feature_stream,
                                           arguments->outfp);

  /* pull the features through the stream and free them afterwards */
  had_err = gt_node_stream_pull(gff3_out_stream, err);

  /* free */
  gt_node_stream_delete(gff3_out_stream);
  gt_node_stream_delete(merge_feature_stream);
  gt_node_stream_delete(gff3_in_stream);

  return had_err;
}
Exemplo n.º 7
0
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;
}
static void snp_annotator_stream_free(GtNodeStream *ns)
{
  GtUword i;
  GtSNPAnnotatorStream *sas;
  if (!ns) return;
  sas = gt_snp_annotator_stream_cast(ns);
  gt_region_mapping_delete(sas->rmap);
  while (gt_queue_size(sas->snps) > 0) {
    gt_genome_node_delete((GtGenomeNode*) gt_queue_get(sas->snps));
  }
  while (gt_queue_size(sas->outqueue) > 0) {
    gt_genome_node_delete((GtGenomeNode*) gt_queue_get(sas->outqueue));
  }
  for (i = 0; i < gt_array_size(sas->instreams); i++) {
    gt_node_stream_delete(*(GtNodeStream**) gt_array_get(sas->instreams, i));
  }
  for (i = 0; i < gt_array_size(sas->cur_gene_set); i++) {
    gt_genome_node_delete(*(GtGenomeNode**) gt_array_get(sas->cur_gene_set, i));
  }
  gt_array_delete(sas->cur_gene_set);
  gt_node_stream_delete(sas->merge_stream);
  gt_array_delete(sas->instreams);
  gt_queue_delete(sas->snps);
  gt_queue_delete(sas->outqueue);
}
Exemplo n.º 9
0
GtFeatureIndex *agn_import_simple(int numfiles, const char **filenames,
                                  char *type, AgnLogger *logger)
{
  GtFeatureIndex *features = gt_feature_index_memory_new();

  GtNodeStream *gff3 = gt_gff3_in_stream_new_unsorted(numfiles, filenames);
  gt_gff3_in_stream_check_id_attributes((GtGFF3InStream *)gff3);
  gt_gff3_in_stream_enable_tidy_mode((GtGFF3InStream *)gff3);

  GtHashmap *typestokeep = gt_hashmap_new(GT_HASH_STRING, NULL, NULL);
  gt_hashmap_add(typestokeep, type, type);
  GtNodeStream *filterstream = agn_filter_stream_new(gff3, typestokeep);

  GtNodeStream *featstream = gt_feature_out_stream_new(filterstream, features);

  GtError *error = gt_error_new();
  int result = gt_node_stream_pull(featstream, error);
  if(result == -1)
  {
    agn_logger_log_error(logger, "error processing node stream: %s",
                         gt_error_get(error));
  }
  gt_error_delete(error);

  if(agn_logger_has_error(logger))
  {
    gt_feature_index_delete(features);
    features = NULL;
  }
  gt_node_stream_delete(gff3);
  gt_node_stream_delete(filterstream);
  gt_node_stream_delete(featstream);
  return features;
}
Exemplo n.º 10
0
static void gff3_in_stream_free(GtNodeStream *ns)
{
  GtGFF3InStream *gff3_in_stream = gff3_in_stream_cast(ns);
  gt_node_stream_delete(gff3_in_stream->cds_check_stream);
  gt_node_stream_delete(gff3_in_stream->add_ids_stream);
  gt_node_stream_delete(gff3_in_stream->gff3_in_stream_plain);
  gt_node_stream_delete(gff3_in_stream->fix_region_stream);
  gt_node_stream_delete(gff3_in_stream->multi_sanitize_stream);
}
Exemplo n.º 11
0
static int gt_inlineseq_split_runner(int argc, const char **argv,
                                     int parsed_args,
                              void *tool_arguments, GtError *err)
{
  GtInlineseqSplitArguments *arguments = tool_arguments;
  GtNodeStream *gff3_in_stream = NULL,
               *gff3_out_stream = NULL,
               *split_stream = NULL,
               *last_stream = NULL;
  GtFile *seq_out_file = NULL,
         *gff3_out_file = NULL;
  int had_err = 0;

  gt_error_check(err);
  gt_assert(arguments);

  if (gt_str_length(arguments->seqoutfile) > 0) {
    seq_out_file = gt_file_new(gt_str_get(arguments->seqoutfile), "w+", err);
    if (!seq_out_file)
      had_err = -1;
  }

  if (!had_err && gt_str_length(arguments->gffoutfile) > 0) {
    gff3_out_file = gt_file_new(gt_str_get(arguments->gffoutfile), "w+", err);
    if (!gff3_out_file)
      had_err = -1;
  }

  if (!had_err) {
    last_stream = gff3_in_stream = gt_gff3_in_stream_new_unsorted(
                                                            argc - parsed_args,
                                                            argv + parsed_args);
    gt_assert(gff3_in_stream);
  }

  if (!had_err) {
    last_stream = split_stream = gt_sequence_node_out_stream_new(last_stream,
                                                                 seq_out_file,
                                                                 err);
    gt_assert(split_stream);
  }

  if (!had_err) {
    last_stream = gff3_out_stream = gt_gff3_out_stream_new(last_stream,
                                                           gff3_out_file);
    had_err = gt_node_stream_pull(last_stream, err);
  }

  gt_node_stream_delete(gff3_in_stream);
  gt_node_stream_delete(gff3_out_stream);
  gt_node_stream_delete(split_stream);
  gt_file_delete(seq_out_file);
  gt_file_delete(gff3_out_file);

  return had_err;
}
Exemplo n.º 12
0
static int gt_splicesiteinfo_runner(int argc, const char **argv,
                                    int parsed_args, void *tool_arguments,
                                    GtError *err)
{
  SpliceSiteInfoArguments *arguments = tool_arguments;
  GtNodeStream *gff3_in_stream = NULL,
               *add_introns_stream = NULL,
               *splice_site_info_stream = NULL;
  GtRegionMapping *region_mapping;
  int had_err = 0;

  gt_error_check(err);
  gt_assert(arguments);

  if (!had_err) {
    /* create gff3 input stream */
    gff3_in_stream = gt_gff3_in_stream_new_unsorted(argc - parsed_args,
                                                    argv + parsed_args);

    /* create region mapping */
    region_mapping = gt_seqid2file_region_mapping_new(arguments->s2fi, err);
    if (!region_mapping)
      had_err = -1;
  }

  if (!had_err) {
    /* create addintrons stream (if necessary) */
    if (arguments->addintrons)
      add_introns_stream = gt_add_introns_stream_new(gff3_in_stream);

    /* create extract feature stream */
    splice_site_info_stream = gt_splice_site_info_stream_new(
                                                          arguments->addintrons
                                                          ? add_introns_stream
                                                          : gff3_in_stream,
                                                          region_mapping);

    /* pull the features through the stream and free them afterwards */
    had_err = gt_node_stream_pull(splice_site_info_stream, err);
  }

  if (!had_err) {
    if (!gt_splice_site_info_stream_show(splice_site_info_stream,
                                         arguments->outfp)) {
      gt_warning("input file(s) contained no intron, use option -addintrons to "
                 "add introns automatically");
    }
  }

  /* free */
  gt_node_stream_delete(splice_site_info_stream);
  gt_node_stream_delete(add_introns_stream);
  gt_node_stream_delete(gff3_in_stream);

  return had_err;
}
Exemplo n.º 13
0
static int gt_tir_runner(GT_UNUSED int argc, GT_UNUSED const char **argv,
                         GT_UNUSED int parsed_args, void *tool_arguments,
                         GtError *err)
{
  GtTirArguments *arguments = tool_arguments;
  GtNodeStream *tir_stream = NULL,
               *gff3_out_stream = NULL,
               *last_stream = NULL;
  int had_err = 0;

  gt_error_check(err);
  gt_assert(arguments);

  tir_stream = gt_tir_stream_new(arguments->str_indexname,
                                 arguments->min_seed_length,
                                 arguments->min_TIR_length,
                                 arguments->max_TIR_length,
                                 arguments->min_TIR_distance,
                                 arguments->max_TIR_distance,
                                 arguments->arbit_scores,
                                 arguments->xdrop_belowscore,
                                 arguments->similarity_threshold,
                                 arguments->best_overlaps,
                                 arguments->no_overlaps,
                                 arguments->min_TSD_length,
                                 arguments->max_TSD_length,
                                 arguments->vicinity,
                                 err);

  if (tir_stream == NULL)
    return -1;

  last_stream = tir_stream;

  /* gff3 outstream */
  gff3_out_stream = gt_gff3_out_stream_new(last_stream, NULL);
  last_stream = gff3_out_stream;

  /* output arguments line */
  /* gt_tir_showargsline(argc, argv); */

  /* pull the features through the stream and free them afterwards */
  if (!had_err)
    had_err = gt_node_stream_pull(last_stream, err);

  /* free */
  gt_node_stream_delete(tir_stream);
  gt_node_stream_delete(gff3_out_stream);

  return had_err;
}
Exemplo n.º 14
0
int gt_chseqids(int argc, const char **argv, GtError *err)
{
  GtNodeStream *gff3_in_stream, *chseqids_stream, *sort_stream = NULL,
               *gff3_out_stream = NULL;
  ChseqidsArguments arguments;
  GtStr *chseqids;
  int parsed_args, had_err = 0;

  gt_error_check(err);

  /* option parsing */
  switch (parse_options(&parsed_args, &arguments, argc, argv, err)) {
    case GT_OPTION_PARSER_OK: break;
    case GT_OPTION_PARSER_ERROR: return -1;
    case GT_OPTION_PARSER_REQUESTS_EXIT: return 0;
  }

  /* create the streams */
  gff3_in_stream = gt_gff3_in_stream_new_sorted(argv[parsed_args + 1]);
  if (arguments.verbose && arguments.outfp)
    gt_gff3_in_stream_show_progress_bar((GtGFF3InStream*) gff3_in_stream);
  chseqids = gt_str_new_cstr(argv[parsed_args]);
  chseqids_stream = gt_chseqids_stream_new(gff3_in_stream, chseqids, err);
  if (!chseqids_stream)
    had_err = -1;
  gt_str_delete(chseqids);
  if (!had_err) {
    if (arguments.sort) {
      sort_stream = gt_sort_stream_new(chseqids_stream);
      gff3_out_stream = gt_gff3_out_stream_new(sort_stream, arguments.outfp);
    }
    else {
      gff3_out_stream = gt_gff3_out_stream_new(chseqids_stream,
                                               arguments.outfp);
    }
  }

  /* pull the features through the stream and free them afterwards */
  if (!had_err)
    had_err = gt_node_stream_pull(gff3_out_stream, err);

  /* free */
  gt_node_stream_delete(gff3_out_stream);
  gt_node_stream_delete(chseqids_stream);
  gt_node_stream_delete(sort_stream);
  gt_node_stream_delete(gff3_in_stream);
  gt_file_delete(arguments.outfp);

  return had_err;
}
Exemplo n.º 15
0
static void gv_test_calc_coverage(AgnUnitTest *test)
{
  const char *filename = "data/gff3/gaeval-stream-unit-test-1.gff3";
  GtNodeStream *align_in = gt_gff3_in_stream_new_unsorted(1, &filename);
  AgnGaevalParams params = { 0.6, 0.3, 0.05, 0.05, 400, 200, 100 };
  GtNodeVisitor *nv = agn_gaeval_visitor_new(align_in, params);
  AgnGaevalVisitor *gv = gaeval_visitor_cast(nv);
  gt_node_stream_delete(align_in);

  GtNodeStream *gff3in = gt_gff3_in_stream_new_unsorted(1, &filename);
  GtHashmap *typestokeep = gt_hashmap_new(GT_HASH_STRING, NULL, NULL);
  gt_hashmap_add(typestokeep, "mRNA", "mRNA");
  GtNodeStream *filtstream = agn_filter_stream_new(gff3in, typestokeep);

  GtError *error = gt_error_new();
  GtArray *feats = gt_array_new( sizeof(GtFeatureNode *) );
  GtNodeStream *featstream = gt_array_out_stream_new(filtstream, feats, error);
  int result = gt_node_stream_pull(featstream, error);
  if(result == -1)
  {
    fprintf(stderr, "[AgnGaevalVisitor::gv_test_calc_coverage] error "
            "processing GFF3: %s\n", gt_error_get(error));
    return;
  }
  gt_node_stream_delete(gff3in);
  gt_node_stream_delete(filtstream);
  gt_node_stream_delete(featstream);
  gt_hashmap_delete(typestokeep);

  agn_assert(gt_array_size(feats) == 3);
  GtFeatureNode *g1 = *(GtFeatureNode **)gt_array_get(feats, 0);
  GtFeatureNode *g2 = *(GtFeatureNode **)gt_array_get(feats, 1);
  GtFeatureNode *g3 = *(GtFeatureNode **)gt_array_get(feats, 2);

  double cov1 = gaeval_visitor_calculate_coverage(gv, g1, error);
  double cov2 = gaeval_visitor_calculate_coverage(gv, g2, error);
  double cov3 = gaeval_visitor_calculate_coverage(gv, g3, error);
  bool test1 = fabs(cov1 - 0.252) < 0.001 &&
               fabs(cov2 - 0.473) < 0.001 &&
               fabs(cov3 - 1.000) < 0.001;

  agn_unit_test_result(test, "calculate coverage", test1);

  gt_error_delete(error);
  gt_array_delete(feats);
  gt_genome_node_delete((GtGenomeNode *)g1);
  gt_genome_node_delete((GtGenomeNode *)g2);
  gt_genome_node_delete((GtGenomeNode *)g3);
  gt_node_visitor_delete(nv);
}
Exemplo n.º 16
0
static int gt_inlineseq_add_runner(int argc, const char **argv, int parsed_args,
                               void *tool_arguments, GtError *err)
{
  GtNodeStream *gff3_in_stream = NULL,
               *add_stream = NULL,
               *gff3_out_stream = NULL,
               *last_stream = NULL;
  GtRegionMapping *rm = NULL;
  InlineseqAddArguments *arguments = tool_arguments;
  int had_err = 0;
  gt_error_check(err);

  /* add region mapping if given */
  if (gt_seqid2file_option_used(arguments->s2fi)) {
    rm = gt_seqid2file_region_mapping_new(arguments->s2fi, err);
    if (!rm)
      had_err = -1;
  }

  if (!had_err) {
    last_stream = gff3_in_stream = gt_gff3_in_stream_new_unsorted(
                                                            argc - parsed_args,
                                                            argv + parsed_args);
    gt_assert(gff3_in_stream);
    gt_gff3_in_stream_enable_tidy_mode((GtGFF3InStream*) gff3_in_stream);

    last_stream = add_stream = gt_sequence_node_add_stream_new(last_stream, rm,
                                                               err);
    if (!add_stream) {
      had_err = -1;
    }
  }

  if (!had_err) {
    last_stream = gff3_out_stream = gt_gff3_out_stream_new(last_stream,
                                                           arguments->outfp);
  }

  if (!had_err)
    had_err = gt_node_stream_pull(last_stream, err);

  /* free */
  gt_node_stream_delete(gff3_in_stream);
  gt_node_stream_delete(add_stream);
  gt_node_stream_delete(gff3_out_stream);
  gt_region_mapping_delete(rm);

  return had_err;
}
Exemplo n.º 17
0
static void filter_stream_free(GtNodeStream *ns)
{
  AgnFilterStream *stream = filter_stream_cast(ns);
  gt_node_stream_delete(stream->in_stream);
  gt_queue_delete(stream->cache);
  gt_hashmap_delete(stream->typestokeep);
}
Exemplo n.º 18
0
GtNodeStream* gt_select_stream_new(GtNodeStream *in_stream, GtStr *seqid,
                                   GtStr *source, const GtRange *contain_range,
                                   const GtRange *overlap_range,
                                   GtStrand strand, GtStrand targetstrand,
                                   bool has_CDS, unsigned long max_gene_length,
                                   unsigned long max_gene_num,
                                   double min_gene_score, double max_gene_score,
                                   double min_average_splice_site_prob,
                                   unsigned long feature_num,
                                   GtStrArray *select_files,
                                   GtStr *select_logic, GtError *err)
{
  GtNodeStream *ns = gt_node_stream_create(gt_select_stream_class(),
                                          gt_node_stream_is_sorted(in_stream));
  GtSelectStream *select_stream = gt_select_stream_cast(ns);
  gt_assert(in_stream);
  select_stream->in_stream = gt_node_stream_ref(in_stream);
  select_stream->select_visitor =
    gt_select_visitor_new(seqid, source, contain_range, overlap_range, strand,
                          targetstrand, has_CDS, max_gene_length, max_gene_num,
                          min_gene_score, max_gene_score,
                          min_average_splice_site_prob, feature_num,
                          select_files, select_logic, err);
  if  (!select_stream->select_visitor) {
    gt_node_stream_delete(ns);
    return NULL;
  }
  return ns;
}
Exemplo n.º 19
0
int gt_feature_index_add_gff3file(GtFeatureIndex *feature_index,
                                  const char *gff3file, GtError *err)
{
  GtNodeStream *gff3_in_stream;
  GtGenomeNode *gn;
  GtArray *tmp;
  int had_err = 0;
  GtUword i;
  gt_error_check(err);
  gt_assert(feature_index && gff3file);
  tmp = gt_array_new(sizeof (GtGenomeNode*));
  gff3_in_stream = gt_gff3_in_stream_new_unsorted(1, &gff3file);
  while (!(had_err = gt_node_stream_next(gff3_in_stream, &gn, err)) && gn)
    gt_array_add(tmp, gn);
  if (!had_err) {
    GtNodeVisitor *feature_visitor = gt_feature_visitor_new(feature_index);
    for (i=0;i<gt_array_size(tmp);i++) {
      gn = *(GtGenomeNode**) gt_array_get(tmp, i);
      /* no need to lock, add_*_node() is synchronized */
      had_err = gt_genome_node_accept(gn, feature_visitor, NULL);
      gt_assert(!had_err); /* cannot happen */
    }
    gt_node_visitor_delete(feature_visitor);
  }
  gt_node_stream_delete(gff3_in_stream);
  for (i=0;i<gt_array_size(tmp);i++)
    gt_genome_node_delete(*(GtGenomeNode**) gt_array_get(tmp, i));
  gt_array_delete(tmp);
  return had_err;
}
Exemplo n.º 20
0
static int gt_extractfeat_runner(GT_UNUSED int argc, const char **argv,
                                 int parsed_args, void *tool_arguments,
                                 GtError *err)
{
  GtNodeStream *gff3_in_stream = NULL, *extract_feature_stream = NULL;
  GtExtractFeatArguments *arguments = tool_arguments;
  GtRegionMapping *region_mapping;
  int had_err = 0;

  gt_error_check(err);
  gt_assert(arguments);

  if (!had_err) {
    /* create gff3 input stream */
    gff3_in_stream = gt_gff3_in_stream_new_sorted(argv[parsed_args]);
    if (arguments->verbose)
      gt_gff3_in_stream_show_progress_bar((GtGFF3InStream*) gff3_in_stream);

    /* create region mapping */
    region_mapping = gt_seqid2file_region_mapping_new(arguments->s2fi, err);
    if (!region_mapping)
      had_err = -1;
  }

  if (!had_err) {
    /* create extract feature stream */
    extract_feature_stream =
      gt_extract_feature_stream_new(gff3_in_stream,
                                    region_mapping,
                                    gt_str_get(arguments->type),
                                    arguments->join,
                                    arguments->translate,
                                    arguments->seqid,
                                    arguments->target,
                                    arguments->width,
                                    arguments->outfp);

    /* pull the features through the stream and free them afterwards */
    had_err = gt_node_stream_pull(extract_feature_stream, err);
  }

  /* free */
  gt_node_stream_delete(extract_feature_stream);
  gt_node_stream_delete(gff3_in_stream);

  return had_err;
}
static void sequence_node_add_stream_free(GtNodeStream *ns)
{
  GtSequenceNodeAddStream *fs = gt_sequence_node_add_stream_cast(ns);
  gt_node_visitor_delete(fs->collect_vis);
  gt_cstr_table_delete(fs->seqid_table);
  gt_str_array_delete(fs->seqids);
  gt_node_stream_delete(fs->in_stream);
}
Exemplo n.º 22
0
static void buffer_stream_free(GtNodeStream *ns)
{
  GtBufferStream *bs = buffer_stream_cast(ns);
  while (gt_queue_size(bs->node_buffer))
    gt_genome_node_delete(gt_queue_get(bs->node_buffer));
  gt_queue_delete(bs->node_buffer);
  gt_node_stream_delete(bs->in_stream);
}
static void gff3_numsorted_out_stream_free(GtNodeStream *ns)
{
  GtGFF3NumsortedOutStream *gff3_out_stream =
                                             gff3_numsorted_out_stream_cast(ns);
  gt_node_stream_delete(gff3_out_stream->in_stream);
  gt_node_visitor_delete(gff3_out_stream->gff3_visitor);
  gt_array_delete(gff3_out_stream->buffer);
  gt_queue_delete(gff3_out_stream->outqueue);
}
static void targetbest_filter_stream_free(GtNodeStream *gs)
{
  GtTargetbestFilterStream *tfs = targetbest_filter_stream_cast(gs);
  for (; tfs->next != NULL; tfs->next = gt_dlistelem_next(tfs->next))
    gt_genome_node_delete(gt_dlistelem_get_data(tfs->next));
  gt_dlist_delete(tfs->trees);
  gt_hashmap_delete(tfs->target_to_elem);
  gt_node_stream_delete(tfs->in_stream);
}
Exemplo n.º 25
0
int gt_eval_runner(GT_UNUSED int argc, const char **argv, int parsed_args,
                   void *tool_arguments, GtError *err)
{
  EvalArguments *arguments = tool_arguments;
  GtNodeStream *reference_stream,
               *prediction_stream;
  GtStreamEvaluator *evaluator;
  int had_err;

  gt_error_check(err);
  gt_assert(arguments);

  /* create the reference stream */
  reference_stream = gt_gff3_in_stream_new_sorted(argv[parsed_args]);
  if (arguments->verbose)
    gt_gff3_in_stream_show_progress_bar((GtGFF3InStream*) reference_stream);

  /* create the prediction stream */
  prediction_stream = gt_gff3_in_stream_new_sorted(argv[parsed_args + 1]);
  if (arguments->verbose)
    gt_gff3_in_stream_show_progress_bar((GtGFF3InStream*) prediction_stream);

  /* create the stream evaluator */
  evaluator = gt_stream_evaluator_new(reference_stream, prediction_stream,
                                      arguments->nuceval, arguments->evalLTR,
                                      arguments->LTRdelta);

  /* compute the evaluation */
  had_err = gt_stream_evaluator_evaluate(evaluator, arguments->verbose,
                                         arguments->exondiff,
                                         arguments->exondiffcollapsed, NULL,
                                         err);

  /* show the evaluation */
  if (!had_err)
    gt_stream_evaluator_show(evaluator, arguments->outfp);

  /* free */
  gt_stream_evaluator_delete(evaluator);
  gt_node_stream_delete(prediction_stream);
  gt_node_stream_delete(reference_stream);

  return had_err;
}
Exemplo n.º 26
0
static int gt_cds_runner(GT_UNUSED int argc, const char **argv, int parsed_args,
                         void *tool_arguments, GtError *err)
{
  GtNodeStream *gff3_in_stream, *cds_stream = NULL, *gff3_out_stream = NULL;
  CDSArguments *arguments = tool_arguments;
  GtRegionMapping *region_mapping;
  int had_err = 0;

  gt_error_check(err);
  gt_assert(arguments);

  /* create gff3 input stream */
  gff3_in_stream = gt_gff3_in_stream_new_sorted(argv[parsed_args]);
  if (arguments->verbose && arguments->outfp)
    gt_gff3_in_stream_show_progress_bar((GtGFF3InStream*) gff3_in_stream);

  /* create region mapping */
  region_mapping = gt_seqid2file_region_mapping_new(arguments->s2fi, err);
  if (!region_mapping)
    had_err = -1;

  if (!had_err) {
    /* create CDS stream */
    cds_stream = gt_cds_stream_new(gff3_in_stream, region_mapping,
                                   arguments->minorflen, GT_CDS_SOURCE_TAG,
                                   arguments->start_codon,
                                   arguments->final_stop_codon,
                                   arguments->generic_start_codons);

    /* create gff3 output stream */
    gff3_out_stream = gt_gff3_out_stream_new(cds_stream, arguments->outfp);

    /* pull the features through the stream and free them afterwards */
    had_err = gt_node_stream_pull(gff3_out_stream, err);
  }

  /* free */
  gt_node_stream_delete(gff3_out_stream);
  gt_node_stream_delete(cds_stream);
  gt_node_stream_delete(gff3_in_stream);

  return had_err;
}
Exemplo n.º 27
0
static void gt_load_stream_free(GtNodeStream *ns)
{
  unsigned long i;
  GtLoadStream *load_stream = gt_load_stream_cast(ns);
  for (i = load_stream->idx; i < gt_array_size(load_stream->nodes); i++) {
    gt_genome_node_delete(*(GtGenomeNode**)
                          gt_array_get(load_stream->nodes, i));
  }
  gt_array_delete(load_stream->nodes);
  gt_node_stream_delete(load_stream->in_stream);
}
Exemplo n.º 28
0
static void gt_ltr_cluster_stream_free(GtNodeStream *ns)
{
  unsigned long i;
  GtLTRClusterStream *lcs = gt_ltr_cluster_stream_cast(ns);
  gt_node_visitor_delete((GtNodeVisitor*) lcs->lcv);
  gt_hashmap_delete(lcs->feat_to_encseq);
  gt_str_array_delete(lcs->feat_to_encseq_keys);
  for (i = 0; i < gt_array_size(lcs->nodes); i++)
    gt_genome_node_delete(*(GtGenomeNode**) gt_array_get(lcs->nodes, i));
  gt_array_delete(lcs->nodes);
  gt_node_stream_delete(lcs->in_stream);
}
Exemplo n.º 29
0
static int gt_gff3validator_runner(int argc, const char **argv, int parsed_args,
                                   void *tool_arguments, GtError *err)
{
    GFF3ValidatorArguments *arguments = tool_arguments;
    GtTypeChecker *type_checker = NULL;
    GtXRFChecker *xrf_checker = NULL;
    GtNodeStream *gff3_in_stream;
    int had_err = 0;

    gt_error_check(err);
    gt_assert(arguments);

    /* create a GFF3 input stream */
    gff3_in_stream = gt_gff3_in_stream_new_unsorted(argc - parsed_args,
                     argv + parsed_args);
    gt_gff3_in_stream_check_id_attributes((GtGFF3InStream*) gff3_in_stream);

    /* set different type checker if necessary */
    if (gt_typecheck_info_option_used(arguments->tci)) {
        type_checker = gt_typecheck_info_create_type_checker(arguments->tci, err);
        if (!type_checker)
            had_err = -1;
        if (!had_err)
            gt_gff3_in_stream_set_type_checker(gff3_in_stream, type_checker);
    }

    /* set XRF checker */
    if (gt_xrfcheck_info_option_used(arguments->xci)) {
        xrf_checker = gt_xrfcheck_info_create_xrf_checker(arguments->xci, err);
        if (!xrf_checker)
            had_err = -1;
        if (!had_err)
            gt_gff3_in_stream_set_xrf_checker(gff3_in_stream, xrf_checker);
    }
    /* enable strict mode (if necessary) */
    if (!had_err && arguments->strict)
        gt_gff3_in_stream_enable_strict_mode((GtGFF3InStream*) gff3_in_stream);

    /* pull the features through the stream and free them afterwards */
    if (!had_err)
        had_err = gt_node_stream_pull(gff3_in_stream, err);

    if (!had_err)
        printf("input is valid GFF3\n");

    /* free */
    gt_node_stream_delete(gff3_in_stream);
    gt_type_checker_delete(type_checker);
    gt_xrf_checker_delete(xrf_checker);

    return had_err;
}
Exemplo n.º 30
0
static void chseqids_stream_free(GtNodeStream *gs)
{
  GtChseqidsStream *cs;
  unsigned long i;
  cs = chseqids_stream_cast(gs);
  gt_mapping_delete(cs->chseqids_mapping);
  for (i = cs->buffer_index; i < gt_array_size(cs->gt_genome_node_buffer);
       i++) {
    gt_genome_node_delete(*(GtGenomeNode**)
                           gt_array_get(cs->gt_genome_node_buffer, i));
  }
  gt_array_delete(cs->gt_genome_node_buffer);
  gt_node_stream_delete(cs->in_stream);
}