Store Sequence sequence location in a shared_ptr class
[mussa.git] / alg / flp_seqcomp.cpp
index 73150280c16235b0d40b0e9d7a03809a09896657..1a1ea89c93bec9ee6917a91a40cbc3cd57e3e9eb 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "mussa_exceptions.hpp"
 #include "alg/flp.hpp"
+#include "alg/sequence.hpp"
 #include <cassert>
 #include <sstream>
 using namespace std;
@@ -44,16 +45,30 @@ FLPs::add(int seq1_i, int seq2_i, int a_score, int i2_offset)
   }
 }
 
+void FLPs::validate_sequence(const Sequence& seq) const
+{
+  if (seq.size() < window_size) {
+    ostringstream msg;
+    msg << "Sequence " << seq.get_name() << " of length " << seq.size()
+        << " must be longer than window size " << window_size;
+    throw seqcomp_error(msg.str());
+  }
+}
 
 void
-FLPs::seqcomp(string sseq1, string sseq2, bool is_RC)
+FLPs::seqcomp(const Sequence& sseq1, const Sequence& sseq2, bool is_RC)
 {
   int start_i, seq1_i, seq2_i, win_i;      // loop variables
   int matches;                    // number of matches in to a window
   int i2_offset;
-  char * seq1, * seq2;
-  int seq1_win_num = sseq1.size() - window_size + 1;
-  int seq2_win_num = sseq2.size() - window_size + 1;
+  const char *seq1 = sseq1.data();
+  const char *seq2 = sseq2.data();
+
+  validate_sequence(sseq1);
+  validate_sequence(sseq2);
+  
+  size_type seq1_win_num = sseq1.size() - window_size + 1;
+  size_type seq2_win_num = sseq2.size() - window_size + 1;
   alloc_matches(sseq1.size());
   if (seq1_win_num != size()) {
     ostringstream msg;
@@ -62,9 +77,6 @@ FLPs::seqcomp(string sseq1, string sseq2, bool is_RC)
     throw mussa_error(msg.str());
   }
 
-  seq1 = (char *) sseq1.c_str();
-  seq2 = (char *) sseq2.c_str();
-
   if (is_RC)
     i2_offset = window_size - sseq2.size();
   else