Ejemplo n.º 1
0
GtAlphabet* gt_alphabet_new_from_string(const char *alphadef, unsigned long len,
                                        GtError *err)
{
  unsigned long i, j;
  GtStrArray *sa;
  GtAlphabet *alpha;
  gt_assert(alphadef && len > 0);
  gt_error_check(err);

  alpha = gt_alphabet_new_empty();
  gt_assert(alphadef);

  sa = gt_str_array_new();
  j = 0;
  for (i = 0; i < len; i++) {
    if (alphadef[i] == '\n' || i == len - 1) {
      gt_str_array_add_cstr_nt(sa, alphadef+j, i - j);
      j = i+1;
    }
  }
  if (read_symbolmap_from_lines(alpha, NULL, sa, err) != 0) {
    gt_str_array_delete(sa);
    gt_assert(gt_error_is_set(err));
    return NULL;
  }
  gt_str_array_delete(sa);
  return alpha;
}
Ejemplo n.º 2
0
GtStrArray* agn_seq_union(GtFeatureIndex *refrfeats, GtFeatureIndex *predfeats,
                          AgnLogger *logger)
{
  // Fetch seqids from reference and prediction annotations
  GtError *e = gt_error_new();
  GtStrArray *refrseqids = gt_feature_index_get_seqids(refrfeats, e);
  if(gt_error_is_set(e))
  {
    agn_logger_log_error(logger, "error fetching seqids for reference: %s",
                         gt_error_get(e));
    gt_error_unset(e);
  }
  GtStrArray *predseqids = gt_feature_index_get_seqids(predfeats, e);
  if(gt_error_is_set(e))
  {
    agn_logger_log_error(logger, "error fetching seqids for prediction: %s",
                         gt_error_get(e));
    gt_error_unset(e);
  }
  gt_error_delete(e);
  if(agn_logger_has_error(logger))
  {
    gt_str_array_delete(refrseqids);
    gt_str_array_delete(predseqids);
    return NULL;
  }
  GtStrArray *seqids = agn_gt_str_array_union(refrseqids, predseqids);

  gt_str_array_delete(refrseqids);
  gt_str_array_delete(predseqids);
  return seqids;
}
Ejemplo n.º 3
0
static void gt_matstat_arguments_delete(void *tool_arguments)
{
  Gfmsubcallinfo *arguments = tool_arguments;
  if (!arguments) return;
  gt_str_array_delete(arguments->queryfilenames);
  gt_str_array_delete(arguments->flagsoutputoption);
  gt_str_delete(arguments->indexname);
  gt_free(arguments);
}
Ejemplo n.º 4
0
static void freesimpleoption(Cmppairwiseopt *cmppairwise)
{
  gt_str_array_delete(cmppairwise->strings);
  gt_str_array_delete(cmppairwise->files);
  gt_str_delete(cmppairwise->text);
  if (cmppairwise->charlistlen != NULL)
  {
    gt_str_delete(cmppairwise->charlistlen->charlist);
    gt_free(cmppairwise->charlistlen);
  }
}
Ejemplo n.º 5
0
static void gt_linspace_align_arguments_delete(void *tool_arguments)
{
  GtLinspaceArguments *arguments = tool_arguments;
  if (arguments != NULL) {
    gt_str_delete(arguments->outputfile);
    gt_str_array_delete(arguments->strings);
    gt_str_array_delete(arguments->files);
    gt_str_array_delete(arguments->linearcosts);
    gt_str_array_delete(arguments->affinecosts);
    gt_str_array_delete(arguments->diagonalbonds);
    gt_free(arguments);
  }
}
Ejemplo n.º 6
0
static void gt_tyr_search_arguments_delete(void *tool_arguments)
{
  Tyr_search_options *arguments = tool_arguments;

  if (!arguments)
  {
    return;
  }
  gt_str_delete(arguments->str_inputindex);
  gt_str_delete(arguments->strandspec);
  gt_str_array_delete(arguments->queryfilenames);
  gt_str_array_delete(arguments->showmodespec);
  gt_free(arguments);
}
Ejemplo n.º 7
0
static void gt_tyr_occratio_arguments_delete(void *tool_arguments)
{
  Tyr_occratio_options *arguments = tool_arguments;

  if (!arguments)
  {
    return;
  }
  gt_str_array_delete(arguments->mersizesstrings);
  gt_str_array_delete(arguments->outputspec);
  gt_str_delete(arguments->str_inputindex);
  gt_option_delete(arguments->refoptionmersizes);
  gt_free(arguments->outputvector);
  gt_free(arguments);
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
0
static void gt_extracttarget_arguments_delete(void *tool_arguments)
{
  ExtractTargetArguments *arguments = tool_arguments;
  if (!arguments) return;
  gt_str_array_delete(arguments->seqfiles);
  gt_free(arguments);
}
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);
}
Ejemplo n.º 11
0
void gt_index_options_delete(GtIndexOptions *oi)
{
  if (oi == NULL) return;
  gt_str_delete(oi->kysargumentstring);
  gt_str_delete(oi->indexname);
  gt_str_delete(oi->dir);
  gt_str_delete(oi->memlimit);
  gt_str_array_delete(oi->algbounds);
  gt_free(oi);
}
Ejemplo n.º 12
0
void gt_sfxoptions_delete(Suffixeratoroptions *so)
{
  /* no checking if error occurs, since errors have been output before */
  gt_index_options_delete(so->idxopts);
  gt_encseq_options_delete(so->encopts);
  gt_encseq_options_delete(so->loadopts);
  gt_str_delete(so->indexname);
  gt_str_delete(so->inputindex);
  gt_str_array_delete(so->db);
}
static void gt_compreads_compress_arguments_delete(void *tool_arguments)
{
  GtCsrHcrEncodeArguments *arguments = tool_arguments;
  if (!arguments) return;
  gt_str_delete(arguments->name);
  gt_str_array_delete(arguments->files);
  gt_str_delete(arguments->smap);
  gt_str_delete(arguments->method);
  gt_free(arguments);
}
Ejemplo n.º 14
0
static int construct_bioseq_files(GtBioseq *bs, GtStr *bioseq_indexname,
                                  GtError *err)
{
  GtStr *sequence_filename;
  GtEncseqEncoder *ee;
  GtStrArray *indexfn;
  int had_err = 0;

  gt_error_check(err);

  /* register the signal handler to remove incomplete files upon termination */
  if (!bs->use_stdin) {
    gt_bioseq_index_filename = gt_str_get(bs->sequence_file);
    gt_sig_register_all(remove_bioseq_files);
  }

  /* if stdin is used as input, we need to create a tempfile containing the
     sequence as GtEncseq cannot be built from stdin directly */
  if (bs->use_stdin) {
    GtStr *tmpfilename;
    FILE *tmpfile = NULL;
    int i;
    char buf[BUFSIZ];
    tmpfilename = gt_str_new();
    tmpfile = gt_xtmpfp(tmpfilename);
    gt_assert(tmpfile);
    i = 1;
    while (i > 0) {
      i = fread(buf, 1, BUFSIZ, stdin);
      if (i > 0) fwrite(buf, 1, i, tmpfile);
    }
    gt_fa_xfclose(tmpfile);
    sequence_filename = tmpfilename;
  } else {
    sequence_filename = gt_str_ref(bs->sequence_file);
  }
  gt_assert(gt_str_length(sequence_filename) > 0);
  ee = gt_encseq_encoder_new();
  gt_encseq_encoder_enable_description_support(ee);
  gt_encseq_encoder_enable_md5_support(ee);
  gt_encseq_encoder_enable_multiseq_support(ee);
  gt_encseq_encoder_enable_lossless_support(ee);
  indexfn = gt_str_array_new();
  gt_str_array_add(indexfn, sequence_filename);
  gt_str_delete(sequence_filename);
  had_err = gt_encseq_encoder_encode(ee, indexfn,
                                     gt_str_get(bioseq_indexname), err);
  /* unregister the signal handler */
   if (!bs->use_stdin)
    gt_sig_unregister_all();

  gt_str_array_delete(indexfn);
  gt_encseq_encoder_delete(ee);
  return had_err;
}
Ejemplo n.º 15
0
static void feature_in_stream_free(GtNodeStream *ns)
{
  GtFeatureInStream *stream = feature_in_stream_cast(ns);
  gt_str_array_delete(stream->seqids);
  while (gt_queue_size(stream->regioncache) > 0)
  {
    GtGenomeNode *gn = gt_queue_get(stream->regioncache);
    gt_genome_node_delete(gn);
  }
  gt_queue_delete(stream->regioncache);
}
Ejemplo n.º 16
0
static void gt_tir_arguments_delete(void *tool_arguments)
{
  GtTirArguments *arguments = tool_arguments;
  if (!arguments) return;
  gt_str_delete(arguments->str_indexname);
  gt_str_delete(arguments->cutoffs);
  gt_str_delete(arguments->str_overlaps);
  gt_str_array_delete(arguments->hmm_files);
  gt_option_delete(arguments->optionoverlaps);
  gt_free(arguments);
}
Ejemplo n.º 17
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);
}
Ejemplo n.º 18
0
static int feature_index_lua_get_seqids(lua_State *L)
{
  GtFeatureIndex **feature_index;
  GtStrArray *seqids;
  feature_index = check_feature_index(L, 1);
  seqids = gt_feature_index_get_seqids(*feature_index);
  gt_assert(seqids);
  /* push table containing sequence ids onto the stack */
  gt_lua_push_strarray_as_table(L, seqids);
  gt_str_array_delete(seqids);
  return 1;
}
Ejemplo n.º 19
0
static int encseq_encoder_lua_encode(lua_State *L)
{
  GtEncseqEncoder **encoder;
  GtStrArray *seqfiles = gt_str_array_new();
  GtError *err;
  const char *indexname;
  encoder = check_encseq_encoder(L, 1);
  err = gt_error_new();
  if (gt_lua_get_table_as_strarray(L, 2, seqfiles, err) != 0) {
    gt_str_array_delete(seqfiles);
    gt_lua_error(L, err);
  }
  indexname = luaL_checkstring(L, 3);
  gt_assert(*encoder);
  if (gt_encseq_encoder_encode(*encoder, seqfiles, indexname, err) != 0) {
    gt_str_array_delete(seqfiles);
    gt_lua_error(L, err);
  }
  gt_str_array_delete(seqfiles);
  gt_error_delete(err);
  return 0;
}
Ejemplo n.º 20
0
static void gt_repfind_arguments_delete(void *tool_arguments)
{
  Maxpairsoptions *arguments = tool_arguments;

  if (!arguments)
  {
    return;
  }
  gt_str_delete(arguments->indexname);
  gt_str_array_delete(arguments->queryfiles);
  gt_option_delete(arguments->refforwardoption);
  gt_free(arguments);
}
Ejemplo n.º 21
0
static void gt_ltrdigest_arguments_delete(void *tool_arguments)
{
  GtLTRdigestOptions *arguments = tool_arguments;
  if (!arguments) return;
  gt_str_delete(arguments->trna_lib);
  gt_str_delete(arguments->prefix);
  gt_str_delete(arguments->cutoffs);
  gt_str_array_delete(arguments->hmm_files);
  gt_file_delete(arguments->outfp);
  gt_output_file_info_delete(arguments->ofi);
  gt_seqid2file_info_delete(arguments->s2fi);
  gt_free(arguments);
}
Ejemplo n.º 22
0
static void gt_genomediff_arguments_delete(void *tool_arguments)
{
    GtGenomediffArguments *arguments = tool_arguments;
    if (!arguments) return;
    gt_str_delete(arguments->indexname);
    gt_str_delete(arguments->unitfile);
    gt_str_delete(arguments->indextype);
    gt_str_array_delete(arguments->filenames);
    gt_option_delete(arguments->ref_unitfile);
    gt_encseq_options_delete(arguments->loadopts);
    gt_index_options_delete(arguments->idxopts);
    gt_free(arguments);
}
Ejemplo n.º 23
0
static void gt_cge_spacedseed_arguments_delete(void *tool_arguments)
{
  Cge_spacedseed_options *arguments = tool_arguments;

  if (!arguments)
  {
    return;
  }
  gt_str_delete(arguments->str_inputindex);
  gt_str_array_delete(arguments->queryfilenames);
  gt_option_delete(arguments->refoptionpckindex);
  gt_option_delete(arguments->refoptionesaindex);
  gt_free(arguments);
}
Ejemplo n.º 24
0
static void gt_idxlocali_arguments_delete (void *tool_arguments)
{
  IdxlocaliOptions *arguments = tool_arguments;

  if (!arguments)
  {
    return;
  }
  gt_str_delete (arguments->indexname);
  gt_str_array_delete (arguments->queryfiles);
  gt_option_delete (arguments->refoptionesaindex);
  gt_option_delete (arguments->refoptionpckindex);
  gt_free (arguments);
}
Ejemplo n.º 25
0
static int extract_feature_visitor_feature_node(GtNodeVisitor *nv,
                                                GtFeatureNode *fn, GtError *err)
{
  GtExtractFeatureVisitor *efv;
  GtFeatureNodeIterator *fni;
  GtFeatureNode *child;
  GtStrArray *target_ids = NULL;
  GtStr *seqid = NULL,
        *description,
        *sequence;
  int had_err = 0;
  gt_error_check(err);
  efv = gt_extract_feature_visitor_cast(nv);
  gt_assert(efv->region_mapping);
  fni = gt_feature_node_iterator_new(fn);
  if (efv->target)
    target_ids = gt_str_array_new();
  if (efv->seqid)
    seqid = gt_str_new();
  description = gt_str_new();
  sequence = gt_str_new();
  while (!had_err && (child = gt_feature_node_iterator_next(fni))) {
    if (seqid)
      gt_str_reset(seqid);
    if (target_ids)
      gt_str_array_reset(target_ids);
    if (gt_extract_feature_sequence(sequence, (GtGenomeNode*) child, efv->type,
                                    efv->join, seqid, target_ids,
                                    efv->region_mapping, err)) {
      had_err = -1;
    }

    if (!had_err && gt_str_length(sequence)) {
      efv->fastaseq_counter++;
      construct_description(description, efv->type, efv->fastaseq_counter,
                            efv->join, efv->translate, seqid, target_ids);
      had_err = show_entry(description, sequence, efv->translate, efv->width,
                           efv->outfp);
      gt_str_reset(description);
      gt_str_reset(sequence);
    }

  }
  gt_str_delete(sequence);
  gt_str_delete(description);
  gt_str_delete(seqid);
  gt_str_array_delete(target_ids);
  gt_feature_node_iterator_delete(fni);
  return had_err;
}
Ejemplo n.º 26
0
static void gt_ltrdigest_arguments_delete(void *tool_arguments)
{
  GtLTRdigestOptions *arguments = tool_arguments;
  if (!arguments) return;
#ifdef HAVE_HMMER
  gt_str_array_delete(arguments->pdom_opts.hmm_files);
#endif
  gt_str_delete(arguments->trna_lib);
  gt_str_delete(arguments->prefix);
  gt_str_delete(arguments->cutoffs);
  gt_file_delete(arguments->outfp);
  gt_outputfileinfo_delete(arguments->ofi);
  gt_free(arguments);
}
Ejemplo n.º 27
0
static void gff3_in_stream_plain_free(GtNodeStream *ns)
{
  GtGFF3InStreamPlain *gff3_in_stream_plain = gff3_in_stream_plain_cast(ns);
  gt_str_array_delete(gff3_in_stream_plain->files);
  gt_str_delete(gff3_in_stream_plain->stdinstr);
  while (gt_queue_size(gff3_in_stream_plain->genome_node_buffer)) {
    gt_genome_node_delete(gt_queue_get(gff3_in_stream_plain
                                       ->genome_node_buffer));
  }
  gt_queue_delete(gff3_in_stream_plain->genome_node_buffer);
  gt_gff3_parser_delete(gff3_in_stream_plain->gff3_parser);
  gt_cstr_table_delete(gff3_in_stream_plain->used_types);
  gt_file_delete(gff3_in_stream_plain->fpin);
}
Ejemplo n.º 28
0
static void gt_select_arguments_delete(void *tool_arguments)
{
  SelectArguments *arguments = tool_arguments;
  if (!arguments) return;
  gt_file_delete(arguments->outfp);
  gt_output_file_info_delete(arguments->ofi);
  gt_str_delete(arguments->targetgt_strand_char);
  gt_str_delete(arguments->gt_strand_char);
  gt_str_delete(arguments->source);
  gt_str_delete(arguments->seqid);
  gt_str_array_delete(arguments->filter_files);
  gt_str_delete(arguments->filter_logic);
  gt_str_delete(arguments->dropped_file);
  gt_free(arguments);
}
Ejemplo n.º 29
0
static int read_symbolmap(GtAlphabet *alpha,const char *mapfile,GtError *err)
{
  bool haserr = false;
  GtStrArray *lines;

  gt_error_check(err);
  lines = gt_str_array_new_file(mapfile);
  gt_assert(lines != NULL);
  if (read_symbolmap_from_lines(alpha,mapfile,lines,err) != 0)
  {
    haserr = true;
  }
  gt_str_array_delete(lines);
  return haserr ? -1 : 0;
}
Ejemplo n.º 30
0
static int feature_index_lua_get_seqids(lua_State *L)
{
  GtFeatureIndex **feature_index;
  GtStrArray *seqids;
  GtError *err;
  feature_index = check_feature_index(L, 1);
  err = gt_error_new();
  seqids = gt_feature_index_get_seqids(*feature_index, err);
  if (!seqids)
    return gt_lua_error(L, err);
  gt_error_delete(err);
  /* push table containing sequence ids onto the stack */
  gt_lua_push_strarray_as_table(L, seqids);
  gt_str_array_delete(seqids);
  return 1;
}