include filename in unparsable annotation error message
authorDiane Trout <diane@caltech.edu>
Mon, 30 Oct 2006 20:49:59 +0000 (20:49 +0000)
committerDiane Trout <diane@caltech.edu>
Mon, 30 Oct 2006 20:49:59 +0000 (20:49 +0000)
ticket:236

alg/sequence.cpp
alg/test/test_sequence.cpp
examples/broken.annot [new file with mode: 0644]

index 004f096a5c519ee55048db93bd9f661000d2484d..b97d3950121630d130c095a2ae86838e38b79950 100644 (file)
@@ -329,8 +329,16 @@ Sequence::load_annot(fs::path file_path, int start_index, int end_index)
     data.push_back(c);
   }
   data_stream.close();
-        
-  parse_annot(data, start_index, end_index);
+
+  try {  
+    parse_annot(data, start_index, end_index);
+  } catch(annotation_load_error e) {
+    std::ostringstream msg;
+    msg << file_path.native_file_string()
+        << " "
+        << e.what();
+    throw annotation_load_error(msg.str());
+  }
 }
 
 /* If this works, yikes, this is some brain hurting code.
@@ -429,7 +437,7 @@ Sequence::parse_annot(std::string data, int start_index, int end_index)
   std::string seq;
   std::list<annot> parsed_annots;
   std::list<Sequence> query_seqs;
-  int parsed=1;
+  int parsed=0;
 
   bool ok = spirit::parse(data.begin(), data.end(),
               (
index 26b5be981ec1078a001f3eb01361fc8a22ba1efa..19904d0df26e700d867dd2944fd2bfca2f805f5c 100644 (file)
@@ -178,7 +178,7 @@ BOOST_AUTO_TEST_CASE( sequence_load )
                                     "5' flank");
 }
 
-BOOST_AUTO_TEST_CASE( sequence_load_error )
+BOOST_AUTO_TEST_CASE( sequence_load_fasta_error )
 {
   fs::path seq_path(fs::path(EXAMPLE_DIR, fs::native)/"seq");
   seq_path /= "broken.fa";
@@ -199,6 +199,31 @@ BOOST_AUTO_TEST_CASE( sequence_load_error )
   BOOST_CHECK_EQUAL(seq_path.native_file_string(), exception_filename);
 }
 
+BOOST_AUTO_TEST_CASE( sequence_load_annot_error )
+{
+  fs::path seq_path(fs::path(EXAMPLE_DIR, fs::native)/"seq");
+  seq_path /= "mouse_mck_pro.fa";
+  fs::path annot_path(fs::path(EXAMPLE_DIR, fs::native));
+  annot_path /= "broken.annot";
+  bool exception_thrown = false;
+  Sequence s;
+  s.load_fasta(seq_path);
+
+  std::string exception_filename;
+  try {
+    s.load_annot(annot_path, 0, 0);
+  } catch(annotation_load_error e) {
+    exception_thrown = true;
+    std:string estr(e.what());
+    size_t native_string_size = annot_path.native_file_string().size();
+    BOOST_REQUIRE(estr.size() > native_string_size);
+    std::copy(estr.begin(), estr.begin()+native_string_size,
+              std::back_inserter(exception_filename));
+  }
+  BOOST_CHECK_EQUAL(exception_thrown, true);
+  BOOST_CHECK_EQUAL(annot_path.native_file_string(), exception_filename);
+}
+
 BOOST_AUTO_TEST_CASE( sequence_load_dna_reduced )
 {
   std::string reduced_dna_fasta_string(">foo\nAAGGCCTTNN\n");
diff --git a/examples/broken.annot b/examples/broken.annot
new file mode 100644 (file)
index 0000000..736f666
--- /dev/null
@@ -0,0 +1,4 @@
+Mouse
+1751 2000 Glorp Glorptype
+>broken
+AAGCGATATG$