From b46df8a5dba48b35a7d242a04a1657efb85d79cf Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Mon, 30 Oct 2006 20:49:59 +0000 Subject: [PATCH] include filename in unparsable annotation error message ticket:236 --- alg/sequence.cpp | 14 +++++++++++--- alg/test/test_sequence.cpp | 27 ++++++++++++++++++++++++++- examples/broken.annot | 4 ++++ 3 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 examples/broken.annot diff --git a/alg/sequence.cpp b/alg/sequence.cpp index 004f096..b97d395 100644 --- a/alg/sequence.cpp +++ b/alg/sequence.cpp @@ -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 parsed_annots; std::list query_seqs; - int parsed=1; + int parsed=0; bool ok = spirit::parse(data.begin(), data.end(), ( diff --git a/alg/test/test_sequence.cpp b/alg/test/test_sequence.cpp index 26b5be9..19904d0 100644 --- a/alg/test/test_sequence.cpp +++ b/alg/test/test_sequence.cpp @@ -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 index 0000000..736f666 --- /dev/null +++ b/examples/broken.annot @@ -0,0 +1,4 @@ +Mouse +1751 2000 Glorp Glorptype +>broken +AAGCGATATG$ -- 2.30.2