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); }
static void select_visitor_free(GtNodeVisitor *nv) { GtSelectVisitor *select_visitor = select_visitor_cast(nv); gt_str_delete(select_visitor->source); gt_str_delete(select_visitor->seqid); gt_queue_delete(select_visitor->node_buffer); }
static void add_ids_visitor_free(GtNodeVisitor *nv) { GtAddIDsVisitor *add_ids_visitor = add_ids_visitor_cast(nv); gt_hashmap_delete(add_ids_visitor->undefined_sequence_regions); gt_cstr_table_delete(add_ids_visitor->defined_seqids); gt_queue_delete(add_ids_visitor->node_buffer); }
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); }
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 gtf_in_stream_free(GtNodeStream *ns) { GtGTFInStream *gtf_in_stream = gtf_in_stream_cast(ns); gt_free(gtf_in_stream->filename); gt_type_checker_delete(gtf_in_stream->type_checker); while (gt_queue_size(gtf_in_stream->genome_node_buffer)) gt_genome_node_delete(gt_queue_get(gtf_in_stream->genome_node_buffer)); gt_queue_delete(gtf_in_stream->genome_node_buffer); }
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); }
void gt_orphanage_delete(GtOrphanage *o) { if (!o) return; gt_cstr_table_delete(o->orphan_ids); gt_cstr_table_delete(o->missing_parents); while (gt_queue_size(o->orphans)) gt_genome_node_delete(gt_queue_get(o->orphans)); gt_queue_delete(o->orphans); gt_free(o); }
void gt_desc_buffer_delete(GtDescBuffer *db) { if (!db) return; if (db->reference_count) { db->reference_count--; return; } gt_free(db->buf); gt_queue_delete(db->startqueue); gt_free(db); }
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); }
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); }
void gt_bed_parser_delete(GtBEDParser *bed_parser) { if (!bed_parser) return; gt_free(bed_parser->block_type); gt_free(bed_parser->thick_feature_type); gt_free(bed_parser->feature_type); gt_str_delete(bed_parser->another_word); gt_str_delete(bed_parser->word); gt_hashmap_delete(bed_parser->seqid_to_str_mapping); while (gt_queue_size(bed_parser->feature_nodes)) gt_genome_node_delete(gt_queue_get(bed_parser->feature_nodes)); gt_queue_delete(bed_parser->feature_nodes); gt_region_node_builder_delete(bed_parser->region_node_builder); gt_free(bed_parser); }
GtNodeVisitor* agn_gaeval_visitor_new(GtNodeStream *astream, AgnGaevalParams gparams) { agn_assert(astream); // Create the node visitor GtNodeVisitor *nv = gt_node_visitor_create(gaeval_visitor_class()); AgnGaevalVisitor *v = gaeval_visitor_cast(nv); v->alignments = gt_feature_index_memory_new(); v->tsvout = NULL; v->params = gparams; // Check that sum of weights is 1.0 double weights_total = gparams.alpha + gparams.beta + gparams.gamma + gparams.epsilon; if(fabs(weights_total - 1.0) > 0.0001) { fprintf(stderr, "[AgnGaevalVisitor::agn_gaeval_visitor_new] warning: " "sum of weights is not 1.0 %.3lf; integrity calculations will be " "incorrect\n", weights_total); } // Set up node stream to load alignment features into memory GtQueue *streams = gt_queue_new(); GtNodeStream *stream, *last_stream; GtHashmap *typestokeep = gt_hashmap_new(GT_HASH_STRING, NULL, NULL); gt_hashmap_add(typestokeep, "cDNA_match", "cDNA_match"); gt_hashmap_add(typestokeep, "EST_match", "EST_match"); gt_hashmap_add(typestokeep, "nucleotide_match", "nucleotide_match"); stream = agn_filter_stream_new(astream, typestokeep); gt_queue_add(streams, stream); last_stream = stream; stream = gt_feature_out_stream_new(last_stream, v->alignments); gt_queue_add(streams, stream); last_stream = stream; stream = gt_inter_feature_stream_new(last_stream, "cDNA_match", "match_gap"); gt_queue_add(streams, stream); last_stream = stream; stream = gt_inter_feature_stream_new(last_stream, "EST_match", "match_gap"); gt_queue_add(streams, stream); last_stream = stream; stream = gt_inter_feature_stream_new(last_stream, "nucleotide_match", "match_gap"); gt_queue_add(streams, stream); last_stream = stream; // Process the node stream GtError *error = gt_error_new(); int result = gt_node_stream_pull(last_stream, error); if(result == -1) { fprintf(stderr, "[AEGeAn::AgnGaevalStream] error parsing alignments: %s\n", gt_error_get(error)); gt_node_visitor_delete(nv); return NULL; } gt_error_delete(error); gt_hashmap_delete(typestokeep); while(gt_queue_size(streams) > 0) { stream = gt_queue_get(streams); gt_node_stream_delete(stream); } gt_queue_delete(streams); return nv; }
bool agn_infer_cds_visitor_unit_test(AgnUnitTest *test) { GtQueue *queue = gt_queue_new(); infer_cds_visitor_test_data(queue); agn_assert(gt_queue_size(queue) == 4); GtFeatureNode *fn = gt_queue_get(queue); GtArray *cds = agn_typecheck_select(fn, agn_typecheck_cds); bool grape1 = (gt_array_size(cds) == 4); if(grape1) { GtGenomeNode *cds2 = *(GtGenomeNode **)gt_array_get(cds, 1); GtRange range = gt_genome_node_get_range(cds2); grape1 = (range.start == 349 && range.end == 522); } agn_unit_test_result(test, "grape test sans UTRs", grape1); gt_genome_node_delete((GtGenomeNode *)fn); gt_array_delete(cds); fn = gt_queue_get(queue); cds = agn_typecheck_select(fn, agn_typecheck_cds); bool grape2 = (gt_array_size(cds) == 1); if(grape2) { GtGenomeNode *cds1 = *(GtGenomeNode **)gt_array_get(cds, 0); GtRange range = gt_genome_node_get_range(cds1); GtStrand strand = gt_feature_node_get_strand((GtFeatureNode *)cds1); grape2 = (range.start == 10747 && range.end == 11577 && strand == GT_STRAND_REVERSE); } agn_unit_test_result(test, "grape test with UTRs, strand check", grape2); gt_genome_node_delete((GtGenomeNode *)fn); gt_array_delete(cds); fn = gt_queue_get(queue); cds = agn_typecheck_select(fn, agn_typecheck_cds); bool grape3 = (gt_array_size(cds) == 2); if(grape3) { GtGenomeNode *cds2 = *(GtGenomeNode **)gt_array_get(cds, 1); GtRange range = gt_genome_node_get_range(cds2); grape3 = (range.start == 22651 && range.end == 23022); } agn_unit_test_result(test, "grape test 3", grape3); gt_genome_node_delete((GtGenomeNode *)fn); gt_array_delete(cds); fn = gt_queue_get(queue); cds = agn_typecheck_select(fn, agn_typecheck_cds); bool grape4 = (gt_array_size(cds) == 12); if(grape4) { GtGenomeNode *cds7 = *(GtGenomeNode **)gt_array_get(cds, 6); GtRange range = gt_genome_node_get_range(cds7); grape4 = (range.start == 27956 && range.end == 27996); } agn_unit_test_result(test, "grape test 4", grape4); gt_genome_node_delete((GtGenomeNode *)fn); gt_array_delete(cds); while(gt_queue_size(queue) > 0) { GtGenomeNode *cds_n = gt_queue_get(queue); gt_genome_node_delete(cds_n); } gt_queue_delete(queue); return agn_unit_test_success(test); }
// Main method int main(int argc, char * const *argv) { GtError *error; GtLogger *logger; GtQueue *streams; GtNodeStream *stream, *last_stream; CanonGFF3Options options = { NULL, NULL, false }; gt_lib_init(); error = gt_error_new(); canon_gff3_parse_options(argc, argv + 0, &options, error); streams = gt_queue_new(); logger = gt_logger_new(true, "", stderr); stream = gt_gff3_in_stream_new_unsorted(argc - optind, (const char **) argv+optind); gt_gff3_in_stream_check_id_attributes((GtGFF3InStream *)stream); gt_gff3_in_stream_enable_tidy_mode((GtGFF3InStream *)stream); gt_queue_add(streams, stream); last_stream = stream; if(options.infer) { GtHashmap *type_parents = gt_hashmap_new(GT_HASH_STRING, gt_free_func, gt_free_func); gt_hashmap_add(type_parents, gt_cstr_dup("mRNA"), gt_cstr_dup("gene")); gt_hashmap_add(type_parents, gt_cstr_dup("tRNA"), gt_cstr_dup("gene")); stream = agn_infer_parent_stream_new(last_stream, type_parents); gt_hashmap_delete(type_parents); gt_queue_add(streams, stream); last_stream = stream; } stream = agn_gene_stream_new(last_stream, logger); gt_queue_add(streams, stream); last_stream = stream; if(options.source != NULL) { GtNodeVisitor *ssv = gt_set_source_visitor_new(options.source); stream = gt_visitor_stream_new(last_stream, ssv); gt_queue_add(streams, stream); last_stream = stream; } stream = gt_gff3_out_stream_new(last_stream, options.outstream); if(!options.infer) gt_gff3_out_stream_retain_id_attributes((GtGFF3OutStream *)stream); gt_queue_add(streams, stream); last_stream = stream; if(gt_node_stream_pull(last_stream, error) == -1) { fprintf(stderr, "[CanonGFF3] error processing node stream: %s", gt_error_get(error)); } while(gt_queue_size(streams) > 0) { stream = gt_queue_get(streams); gt_node_stream_delete(stream); } gt_queue_delete(streams); if(options.source != NULL) gt_str_delete(options.source); if(options.outstream != NULL) gt_file_delete(options.outstream); gt_error_delete(error); gt_logger_delete(logger); gt_lib_clean(); return 0; }
int gt_queue_unit_test(GtError *err) { long check_counter = 0, check_counter_reverse = 1023; unsigned long i; int had_err = 0; GtQueue *q; gt_error_check(err); /* without wraparound */ q = gt_queue_new(); gt_ensure(had_err, !gt_queue_size(q)); for (i = 0; !had_err && i < 1024; i++) { gt_queue_add(q, (void*) i); gt_ensure(had_err, gt_queue_size(q) == i + 1); } if (!had_err) had_err = gt_queue_iterate(q, check_queue, &check_counter, err); if (!had_err) { had_err = gt_queue_iterate_reverse(q, check_queue_reverse, &check_counter_reverse, err); } gt_ensure(had_err, gt_queue_iterate(q, fail_func, NULL, NULL)); gt_ensure(had_err, gt_queue_iterate_reverse(q, fail_func, NULL, NULL)); if (!had_err) { gt_queue_remove(q, (void*) 0); gt_ensure(had_err, gt_queue_size(q) == 1023); } for (i = 1; !had_err && i < 1024; i++) { gt_ensure(had_err, gt_queue_head(q) == (void*) i); gt_ensure(had_err, gt_queue_get(q) == (void*) i); gt_ensure(had_err, gt_queue_size(q) == 1024 - i - 1); } gt_ensure(had_err, !gt_queue_size(q)); gt_queue_delete(q); /* with wraparound (without full queue) */ if (!had_err) { q = gt_queue_new(); gt_ensure(had_err, !gt_queue_size(q)); for (i = 0; !had_err && i < 1024; i++) { gt_queue_add(q, (void*) i); gt_ensure(had_err, gt_queue_size(q) == i + 1); } check_counter = 0; check_counter_reverse = 1023; if (!had_err) had_err = gt_queue_iterate(q, check_queue, &check_counter, err); gt_ensure(had_err, gt_queue_iterate(q, fail_func, NULL, NULL)); gt_ensure(had_err, gt_queue_iterate_reverse(q, fail_func, NULL, NULL)); if (!had_err) { had_err = gt_queue_iterate_reverse(q, check_queue_reverse, &check_counter_reverse, err); } for (i = 0; !had_err && i < 512; i++) { gt_ensure(had_err, gt_queue_head(q) == (void*) i); gt_ensure(had_err, gt_queue_get(q) == (void*) i); gt_ensure(had_err, gt_queue_size(q) == 1024 - i - 1); } for (i = 0; !had_err && i < 512; i++) { gt_queue_add(q, (void*) (i + 1024)); gt_ensure(had_err, gt_queue_size(q) == 512 + i + 1); } check_counter = 512; check_counter_reverse = 1535; if (!had_err) had_err = gt_queue_iterate(q, check_queue, &check_counter, err); if (!had_err) { had_err = gt_queue_iterate_reverse(q, check_queue_reverse, &check_counter_reverse, err); } gt_ensure(had_err, gt_queue_iterate(q, fail_func, NULL, NULL)); gt_ensure(had_err, gt_queue_iterate_reverse(q, fail_func, NULL, NULL)); if (!had_err) { gt_queue_remove(q, (void*) 512); gt_ensure(had_err, gt_queue_size(q) == 1023); } for (i = 1; !had_err && i < 1024; i++) { gt_ensure(had_err, gt_queue_head(q) == (void*) (512 + i)); gt_ensure(had_err, gt_queue_get(q) == (void*) (512 + i)); gt_ensure(had_err, gt_queue_size(q) == 1024 - i - 1); } gt_ensure(had_err, !gt_queue_size(q)); gt_queue_delete(q); } /* with wraparound (with full queue) */ if (!had_err) { q = gt_queue_new(); gt_ensure(had_err, !gt_queue_size(q)); for (i = 0; !had_err && i < 1024; i++) { gt_queue_add(q, (void*) i); gt_ensure(had_err, gt_queue_size(q) == i + 1); } check_counter = 0; check_counter_reverse = 1023; if (!had_err) had_err = gt_queue_iterate(q, check_queue, &check_counter, err); if (!had_err) { had_err = gt_queue_iterate_reverse(q, check_queue_reverse, &check_counter_reverse, err); } gt_ensure(had_err, gt_queue_iterate(q, fail_func, NULL, NULL)); gt_ensure(had_err, gt_queue_iterate_reverse(q, fail_func, NULL, NULL)); for (i = 0; !had_err && i < 512; i++) { gt_ensure(had_err, gt_queue_head(q) == (void*) i); gt_ensure(had_err, gt_queue_get(q) == (void*) i); gt_ensure(had_err, gt_queue_size(q) == 1024 - i - 1); } for (i = 0; !had_err && i < 1024; i++) { gt_queue_add(q, (void*) (i + 1024)); gt_ensure(had_err, gt_queue_size(q) == 512 + i + 1); } check_counter = 512; check_counter_reverse = 2047; if (!had_err) had_err = gt_queue_iterate(q, check_queue, &check_counter, err); if (!had_err) { had_err = gt_queue_iterate_reverse(q, check_queue_reverse, &check_counter_reverse, err); } gt_ensure(had_err, gt_queue_iterate(q, fail_func, NULL, NULL)); gt_ensure(had_err, gt_queue_iterate_reverse(q, fail_func, NULL, NULL)); if (!had_err) { gt_queue_remove(q, (void*) 512); gt_ensure(had_err, gt_queue_size(q) == 1535); } for (i = 1; !had_err && i < 1536; i++) { gt_ensure(had_err, gt_queue_head(q) == (void*) (512 + i)); gt_ensure(had_err, gt_queue_get(q) == (void*) (512 + i)); gt_ensure(had_err, gt_queue_size(q) == 1536 - i - 1); } gt_ensure(had_err, !gt_queue_size(q)); gt_queue_delete(q); } /* test a corner case */ if (!had_err) { q = gt_queue_new(); gt_queue_add(q, (void*) 1); gt_ensure(had_err, gt_queue_size(q) == 1); if (!had_err) gt_queue_add(q, (void*) 1); gt_ensure(had_err, gt_queue_size(q) == 2); gt_ensure(had_err, gt_queue_get(q)); gt_ensure(had_err, gt_queue_size(q) == 1); if (!had_err) gt_queue_add(q, (void*) 1); gt_ensure(had_err, gt_queue_size(q) == 2); gt_ensure(had_err, gt_queue_get(q)); gt_ensure(had_err, gt_queue_size(q) == 1); if (!had_err) gt_queue_add(q, (void*) 1); gt_ensure(had_err, gt_queue_size(q) == 2); gt_ensure(had_err, gt_queue_get(q)); gt_ensure(had_err, gt_queue_size(q) == 1); gt_ensure(had_err, gt_queue_get(q)); gt_ensure(had_err, gt_queue_size(q) == 0); if (!had_err) gt_queue_add(q, (void*) 1); gt_ensure(had_err, gt_queue_size(q) == 1); gt_ensure(had_err, gt_queue_get(q)); gt_ensure(had_err, gt_queue_size(q) == 0); gt_queue_delete(q); } /* gt_queue_remove() corner case */ if (!had_err) { q = gt_queue_new(); gt_queue_add(q, (void*) 1); gt_ensure(had_err, gt_queue_size(q) == 1); gt_queue_remove(q, (void*) 1); gt_ensure(had_err, gt_queue_size(q) == 0); gt_queue_delete(q); } /* gt_queue_remove() corner case */ if (!had_err) { q = gt_queue_new(); gt_queue_add(q, (void*) 0); gt_queue_add(q, (void*) 1); gt_queue_add(q, (void*) 2); gt_queue_add(q, (void*) 3); gt_ensure(had_err, gt_queue_get(q) == (void*) 0); gt_ensure(had_err, gt_queue_get(q) == (void*) 1); gt_queue_add(q, (void*) 4); gt_queue_add(q, (void*) 5); gt_queue_remove(q, (void*) 4); gt_queue_remove(q, (void*) 2); gt_queue_remove(q, (void*) 5); gt_queue_remove(q, (void*) 3); gt_ensure(had_err, gt_queue_size(q) == 0); gt_queue_delete(q); } /* delete with contents */ if (!had_err) { q = gt_queue_new(); gt_ensure(had_err, !gt_queue_size(q)); if (!had_err) gt_queue_add(q, gt_calloc(1, 16)); gt_ensure(had_err, gt_queue_size(q) == 1); if (!had_err) gt_queue_add(q, gt_calloc(1, 32)); gt_ensure(had_err, gt_queue_size(q) == 2); gt_queue_delete_with_contents(q); } return had_err; }