Created
February 2, 2009 21:46
-
-
Save brentp/57121 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/extended/gff3_visitor.c b/src/extended/gff3_visitor.c | |
index 8246680..9e87612 100644 | |
--- a/src/extended/gff3_visitor.c | |
+++ b/src/extended/gff3_visitor.c | |
@@ -197,32 +197,52 @@ static int store_ids(GtGenomeNode *gn, void *data, GtError *err) | |
AddIDInfo add_id_info; | |
int had_err = 0; | |
GtStr *id; | |
+ /* Q: is this const ok? */ | |
+ const char *idstring; | |
+ int has_id = 0; | |
gt_error_check(err); | |
gt_assert(gn && gf && gff3_visitor); | |
+ idstring = gt_feature_node_get_attribute(gf, "ID"); | |
- if (gt_genome_node_has_children(gn) || gt_feature_node_is_multi(gf)) { | |
- if (gt_feature_node_is_multi(gf)) { | |
- id = gt_hashmap_get(gff3_visitor->gt_feature_node_to_unique_id_str, | |
+ if (idstring) { | |
+ id = gt_str_new_cstr(idstring); | |
+ has_id = 1; | |
+ } | |
+ else { | |
+ if (gt_feature_node_is_multi(gf) || gt_genome_node_has_children(gn) ) { | |
+ if (gt_feature_node_get_multi_representative(gf) != gf) { | |
+ id = gt_hashmap_get(gff3_visitor->gt_feature_node_to_unique_id_str, | |
gt_feature_node_get_multi_representative(gf)); | |
- if (!id) { /* the representative does not have its own id */ | |
- id = create_unique_id(gff3_visitor, | |
- gt_feature_node_get_multi_representative(gf)); | |
+ has_id = 1; | |
} | |
- if (gt_feature_node_get_multi_representative(gf) != gf) { | |
- gt_hashmap_add(gff3_visitor->gt_feature_node_to_unique_id_str, gf, | |
- gt_str_ref(id)); | |
+ /* | |
+ else { | |
+ id = create_unique_id(gff3_visitor, gf); | |
+ has_id = 1; | |
} | |
+ */ | |
} | |
- else | |
- id = create_unique_id(gff3_visitor, gf); | |
+ /* if it has a parent, get id from parent */ | |
+ /* Q: better way to test for parent ? */ | |
+ else if ( ! gt_feature_node_get_attribute(gf, "Parent")) { | |
+ id = create_unique_id(gff3_visitor, gf); | |
+ has_id = 1; | |
+ } | |
+ | |
+ } | |
+ if (has_id == 1) { | |
+ gt_hashmap_add(gff3_visitor->gt_feature_node_to_unique_id_str, gf, | |
+ gt_str_ref(id)); | |
/* for each child -> store the parent feature in the hash map */ | |
add_id_info.gt_feature_node_to_id_array = | |
- gff3_visitor->gt_feature_node_to_id_array, | |
+ gff3_visitor->gt_feature_node_to_id_array, | |
add_id_info.id = gt_str_get(id); | |
had_err = gt_genome_node_traverse_direct_children(gn, &add_id_info, add_id, | |
err); | |
+ /* Q: needed? */ | |
+ gt_str_delete(id); | |
} | |
return had_err; | |
} | |
@@ -262,8 +282,8 @@ static int gff3_visitor_feature_node(GtNodeVisitor *gv, GtFeatureNode *fn, | |
/* 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_genome_node_has_children((GtGenomeNode*) fn)) | |
- gt_genfile_xprintf(gff3_visitor->outfp, "%s\n", GFF_TERMINATOR); | |
+ /* if (gt_genome_node_has_children((GtGenomeNode*) fn)) */ | |
+ gt_genfile_xprintf(gff3_visitor->outfp, "%s\n", GFF_TERMINATOR); | |
return had_err; | |
} | |
diff --git a/testsuite/gt_gff3_include.rb b/testsuite/gt_gff3_include.rb | |
index 89d6e41..5e589b9 100644 | |
--- a/testsuite/gt_gff3_include.rb | |
+++ b/testsuite/gt_gff3_include.rb | |
@@ -15,6 +15,7 @@ end | |
Name "gt gff3 short test (stdin)" | |
Keywords "gt_gff3" | |
Test do | |
+ puts "#{$bin}gt gff3 < #{$testdata}gff3_file_1_short.txt" | |
run_test "#{$bin}gt gff3 < #{$testdata}gff3_file_1_short.txt" | |
run "env LC_ALL=C sort #{$last_stdout}" | |
run "diff #{$last_stdout} #{$testdata}gff3_file_1_short_sorted.txt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment