From a4e078e9172610b3c28ef8ac3a9983ce0290cf3a Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Tue, 20 Jun 2006 20:52:42 +0000 Subject: [PATCH] extend annotation names and types to allow punctuation I tweaked the spirit grammar so the name & type fields are letter followed by "non-space printing characters" --- alg/sequence.cpp | 20 +++++++++++++------- alg/test/test_sequence.cpp | 11 ++++++++--- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/alg/sequence.cpp b/alg/sequence.cpp index 077908e..c99f3a6 100644 --- a/alg/sequence.cpp +++ b/alg/sequence.cpp @@ -343,7 +343,7 @@ struct push_back_annot { void operator()(std::string::const_iterator, std::string::const_iterator) const { - //std::cout << "adding annot: " << begin << " " << end << " " << name << " " << type << std::endl; + //std::cout << "adding annot: " << begin << "|" << end << "|" << name << "|" << type << std::endl; annot_list.push_back(annot(begin, end, name, type)); }; }; @@ -402,12 +402,18 @@ Sequence::parse_annot(std::string data, int start_index, int end_index) +spirit::space_p >> spirit::uint_p[spirit::assign_a(end)] >> +spirit::space_p >> - (*(spirit::alpha_p|spirit::digit_p))[spirit::assign_a(name)] >> - // optional type - !( - +spirit::space_p >> - (*(spirit::alpha_p))[spirit::assign_a(type)] - ) + ( + spirit::alpha_p >> + *spirit::graph_p + )[spirit::assign_a(name)] >> + // optional type + !( + +spirit::space_p >> + ( + spirit::alpha_p >> + *spirit::graph_p + )[spirit::assign_a(type)] + ) // to understand how this group gets set // read the comment above struct push_back_annot )[push_back_annot(annots, start, end, type, name)] diff --git a/alg/test/test_sequence.cpp b/alg/test/test_sequence.cpp index 1d90510..f98f236 100644 --- a/alg/test/test_sequence.cpp +++ b/alg/test/test_sequence.cpp @@ -106,6 +106,7 @@ BOOST_AUTO_TEST_CASE( annotation_load ) "GCT\n" "gCTn\n" "75\t90\tname2\ttype2\n" + "100 120 name-asdf type!@#$%\n" ; string s(100, 'A'); s += "GCTGCTAATT"; @@ -115,7 +116,7 @@ BOOST_AUTO_TEST_CASE( annotation_load ) seq.parse_annot(annot_data, 0, 0); std::list annots_list = seq.annotations(); std::vector annots(annots_list.begin(), annots_list.end()); - BOOST_REQUIRE_EQUAL( annots.size(), 7); + BOOST_REQUIRE_EQUAL( annots.size(), 8); BOOST_CHECK_EQUAL( annots[0].start, 0 ); BOOST_CHECK_EQUAL( annots[0].end, 10 ); BOOST_CHECK_EQUAL( annots[0].type, "type"); @@ -126,10 +127,14 @@ BOOST_AUTO_TEST_CASE( annotation_load ) BOOST_CHECK_EQUAL( annots[4].name, "backward"); BOOST_CHECK_EQUAL( annots[5].name, "name2"); BOOST_CHECK_EQUAL( annots[5].end, 90); + BOOST_CHECK_EQUAL( annots[6].start, 100); + BOOST_CHECK_EQUAL( annots[6].end, 120); + BOOST_CHECK_EQUAL( annots[6].name, "name-asdf"); + BOOST_CHECK_EQUAL( annots[6].type, "type!@#$%"); // sequence defined annotations will always be after the // absolute positions - BOOST_CHECK_EQUAL( annots[6].name, "ident3 asdf"); - BOOST_CHECK_EQUAL( annots[6].start, 100); + BOOST_CHECK_EQUAL( annots[7].name, "ident3 asdf"); + BOOST_CHECK_EQUAL( annots[7].start, 100); //BOOST_CHECK_EQUAL( annots } -- 2.30.2