update the annotation grammer to make species name optional
authorDiane Trout <diane@caltech.edu>
Thu, 29 Jun 2006 01:18:28 +0000 (01:18 +0000)
committerDiane Trout <diane@caltech.edu>
Thu, 29 Jun 2006 01:18:28 +0000 (01:18 +0000)
alg/sequence.cpp
alg/test/test_sequence.cpp

index 3863346358c3cb1ba65154213f67dbf32c9d38fa..6a29c13fe7cffa554a89c8c476d4badd627f55cb 100644 (file)
@@ -392,9 +392,14 @@ Sequence::parse_annot(std::string data, int start_index, int end_index)
 
   bool status = spirit::parse(data.begin(), data.end(),
                 (
-                //begin grammar
-                (+(spirit::alpha_p))[spirit::assign_a(species)] >> 
-                 +(spirit::space_p) >>
+                 //begin grammar
+                   !(
+                      (
+                        spirit::alpha_p >> 
+                        +(spirit::graph_p)
+                      )[spirit::assign_a(species)] >> 
+                      +(spirit::space_p)
+                    ) >>
                     *(
                       ( // parse an absolute location name
                        (spirit::uint_p[spirit::assign_a(start)] >> 
index f98f236394099793b9050784bef6a830668a2fda..1f3256ee3997bec9e32d767dfb4614aac61c9cf5 100644 (file)
@@ -139,6 +139,33 @@ BOOST_AUTO_TEST_CASE( annotation_load )
   //BOOST_CHECK_EQUAL( annots
 }
 
+BOOST_AUTO_TEST_CASE( annotation_load_no_species_name )
+{
+  string annot_data = "0 10 name   type\n"
+                      "10 20 myf7\n"
+                      "20 30 myod\n"
+                      "50\t55 anothername\n"
+                      "60 50 backward\n"
+                      ">ident3 asdf\n"
+                      "GCT\n"
+                      "gCTn\n"
+                      "75\t90\tname2\ttype2\n"
+                      "100 120 name-asdf type!@#$%\n"
+                      ;
+  string s(100, 'A');
+  s += "GCTGCTAATT";
+  Sequence seq(s);
+                     
+  //istringstream annot_stream(annot_data);
+  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(), 8);
+  BOOST_CHECK_EQUAL( annots[0].start, 0 );
+  BOOST_CHECK_EQUAL( annots[0].end, 10 );
+  BOOST_CHECK_EQUAL( annots[0].type, "type");
+}
+
 // ticket:83 when you try to load a sequence from a file that doesn't
 // have fasta headers it crashes. 
 BOOST_AUTO_TEST_CASE( sequence_past_end )