extend annotation names and types to allow punctuation
authorDiane Trout <diane@caltech.edu>
Tue, 20 Jun 2006 20:52:42 +0000 (20:52 +0000)
committerDiane Trout <diane@caltech.edu>
Tue, 20 Jun 2006 20:52:42 +0000 (20:52 +0000)
I tweaked the spirit grammar so the name & type fields are letter followed
by "non-space printing characters"

alg/sequence.cpp
alg/test/test_sequence.cpp

index 077908e1c3e2ad414f32ee24e74b566cd4774228..c99f3a68f7892f10d023360a9d94e79cdb8ea406 100644 (file)
@@ -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)]
index 1d9051010ac6486a23f3d76e691b97bc16304f09..f98f236394099793b9050784bef6a830668a2fda 100644 (file)
@@ -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<annot> annots_list = seq.annotations();
   std::vector<annot> 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
 }