From: Diane Trout Date: Tue, 6 Jun 2006 00:21:45 +0000 (+0000) Subject: keep track of how far through a seqcomp we've gotten X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=mussa.git;a=commitdiff_plain;h=a7f4b71a7d7de34dd2b1cd51d0ac1051885f87d3 keep track of how far through a seqcomp we've gotten --- diff --git a/alg/flp.cpp b/alg/flp.cpp index 56a0a08..8c425d5 100644 --- a/alg/flp.cpp +++ b/alg/flp.cpp @@ -40,14 +40,18 @@ ostream &operator<<(ostream& out, const FLPs::match& m) FLPs::FLPs() : window_size(0), hard_threshold(0), - all_matches(0) + all_matches(0), + seqcomp_i(seqcomp_not_running), + seqcomp_end(seqcomp_not_running) { } FLPs::FLPs(const FLPs& o) : window_size(o.window_size), hard_threshold(o.hard_threshold), - all_matches(o.all_matches) + all_matches(o.all_matches), + seqcomp_i(o.seqcomp_i), + seqcomp_end(o.seqcomp_end) { } @@ -281,3 +285,11 @@ FLPs::load(fs::path file_path) } +float FLPs::progress() const +{ + if (seqcomp_end == FLPs::seqcomp_not_running) { + return FLPs::seqcomp_not_running; + } else { + return static_cast(seqcomp_i)/static_cast(seqcomp_end); + } +} diff --git a/alg/flp.hpp b/alg/flp.hpp index 4951213..75298a4 100644 --- a/alg/flp.hpp +++ b/alg/flp.hpp @@ -63,6 +63,11 @@ public: void save(boost::filesystem::path save_file_path); //! Load a vector of a lists of FLPs void load(boost::filesystem::path file_path); + + //! how far we are through current seqcomp + float progress() const; + + const static int seqcomp_not_running = -1; private: //! the number of base pairs in the sliding window int window_size; @@ -85,6 +90,10 @@ public: */ void alloc_matches(std::string::size_type len1=0); - + //! current loop index + int seqcomp_i; + //! end seqcomp index (when terminating, seqcomp_i == seqcomp_end. + //! when not running seqcomp_i == seqcomp_end == seqcomp_not_running + int seqcomp_end; }; #endif diff --git a/alg/flp_seqcomp.cpp b/alg/flp_seqcomp.cpp index 003d3fb..1df9582 100644 --- a/alg/flp_seqcomp.cpp +++ b/alg/flp_seqcomp.cpp @@ -12,6 +12,7 @@ // ---------- flp_seqcomp.cc ----------- // ---------------------------------------- +#include "mussa_exceptions.hpp" #include "alg/flp.hpp" #include using namespace std; @@ -33,7 +34,6 @@ FLPs::add(int seq1_i, int seq2_i, int a_score, int i2_offset) { match a_match; - if (a_score >= hard_threshold) { a_match.index = seq2_i + i2_offset; @@ -59,17 +59,19 @@ FLPs::seqcomp(string sseq1, string sseq2, bool is_RC) seq1 = (char *) sseq1.c_str(); seq2 = (char *) sseq2.c_str(); - if (is_RC) i2_offset = window_size - sseq2.size(); else i2_offset = 0; + // I'm not sure why we're -2 instead of -1, but I experimentally + // determined that I need to -2 to get seqcomp_i to == seqcomp_end + seqcomp_end = size() + seq2_win_num -2; // this does the "upper diagonals" of the search // loop thru the start positions for sequence 1 - for(start_i = 0; start_i != size(); start_i++) + for(start_i = 0; start_i != size(); ++start_i, ++seqcomp_i) { matches = 0; // compare initial window @@ -107,11 +109,10 @@ FLPs::seqcomp(string sseq1, string sseq2, bool is_RC) } // end of loop thru the current offset sequence } // end of loop thru the start positions of seq1 sequence - // this does the "lower diagonals" of the search // loop thru the start positions for sequence 1 - for(start_i = 1; start_i < seq2_win_num; start_i++) + for(start_i = 1; start_i != seq2_win_num; ++start_i, ++seqcomp_i) { matches = 0; @@ -147,4 +148,10 @@ FLPs::seqcomp(string sseq1, string sseq2, bool is_RC) seq2_i = seq2_i + 1; // increment seq2_i to next window } // end of loop thru the current offset sequence } // end of loop thru the start positions of seq2 sequence + + if (seqcomp_i != seqcomp_end) { + clog << "seqcomp_i " << seqcomp_i << " " << seqcomp_end << endl; + //throw mussa_error("internal error with seqcomp seqcomp_i != seqcomp_end"); + } + seqcomp_i = seqcomp_end = FLPs::seqcomp_not_running; } diff --git a/alg/test/test_flp.cpp b/alg/test/test_flp.cpp index cc8500b..4706e8d 100644 --- a/alg/test/test_flp.cpp +++ b/alg/test/test_flp.cpp @@ -17,7 +17,13 @@ BOOST_AUTO_TEST_CASE( flp_simple ) { FLPs f; f.setup(5, 4); + // when we first setup progress should be equal to -1 + // aka FLPs::seqcomp_not_running + BOOST_CHECK_EQUAL( f.progress(), -1 ); f.seqcomp("AAGGTAAGGT", "AAGGTAAGGT", false); + // now that we're done we should be equal to not running again. + // yeah it'd be nice to make a thread test + BOOST_CHECK_EQUAL( f.progress(), -1 ); // are the match_locations correct? for (int i=0; i != f.size(); i++)