paircomp used the string find_first_not_of
authorDiane Trout <diane@caltech.edu>
Thu, 4 Jan 2007 22:28:08 +0000 (22:28 +0000)
committerDiane Trout <diane@caltech.edu>
Thu, 4 Jan 2007 22:28:08 +0000 (22:28 +0000)
so i needed to add it to my sequence class. (I'm trying to keep
my sequence class to look like an immutable string).

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

index b97d3950121630d130c095a2ae86838e38b79950..147fdce3b7e2c015eb20741964327954f70a924a 100644 (file)
@@ -752,6 +752,30 @@ bool Sequence::empty() const
   return (seq_count == 0) ? true : false;
 }
 
+Sequence::size_type Sequence::find_first_not_of(
+  const std::string& query, 
+  Sequence::size_type index)
+{
+  typedef std::set<std::string::value_type> sequence_set;
+  sequence_set match_set;
+  
+  for(const_iterator query_item = query.begin();
+      query_item != query.end();
+      ++query_item)
+  {
+    match_set.insert(*query_item);
+  }  
+  for(const_iterator base = begin();
+      base != end();
+      ++base)
+  {
+    if(match_set.find(*base) == match_set.end()) {
+      return base-begin();
+    } 
+  }
+  return Sequence::npos;
+}
 Sequence::size_type Sequence::start() const
 {
   if (parent)
index 6365ea71966c77cd39e15eb77842c33f73a4967f..5c8983cc2cc1cf2195071ff0ca85c064ceb268f4 100644 (file)
@@ -156,6 +156,8 @@ public:
   const_iterator end() const;
   //! is our sequence empty?
   bool empty() const;
+  //! find first 
+  size_type find_first_not_of(const std::string&, size_type index=0); 
   //! how many base pairs are there in our sequence
   size_type size() const;
   //! alias for size (used by string)
index 15e11ed8d016ceeb100e204de5e19f10eb453007..c6f9e386f6edae79a4f28c2efa29579bafceac2f 100644 (file)
@@ -27,6 +27,17 @@ BOOST_AUTO_TEST_CASE( sequence_get_sequence )
        BOOST_CHECK_EQUAL(s.get_sequence(), std::string() );
 }
 
+BOOST_AUTO_TEST_CASE( sequence_find_first_not_of )
+{
+  std::string str1("AAAAT");
+  Sequence seq1(str1);
+  BOOST_CHECK_EQUAL(seq1.find_first_not_of("A"), str1.find_first_not_of("A"));
+  
+  std::string str2("AATTGGCC");
+  Sequence seq2(str2);
+  BOOST_CHECK_EQUAL(seq2.find_first_not_of("qwer"), str2.find_first_not_of("qwer"));
+}
+
 //! when we try to load a missing file, do we get an error?
 BOOST_AUTO_TEST_CASE( sequence_load_exception )
 {