From b34b06e3737e3ceb6ce85705c2861cb51d898628 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Thu, 14 Dec 2006 21:17:25 +0000 Subject: [PATCH] len(mussa.paths()) should equal the number of found paths ticket:244 for some reason I was returning the number of sequences instead, that is available as sequence_count. Renamed size_t in NwayPaths to NwayPaths::size_type Also I exported the various types of path size counts to the python layer --- alg/nway_paths.cpp | 17 ++++++++++------- alg/nway_paths.hpp | 13 +++++++------ alg/test/test_nway.cpp | 15 ++++++++++++++- py/nway_paths.cpp | 7 ++++++- py/test/TestMussa.py | 13 ++++++++----- 5 files changed, 45 insertions(+), 20 deletions(-) diff --git a/alg/nway_paths.cpp b/alg/nway_paths.cpp index df2cf2e..e7a8474 100644 --- a/alg/nway_paths.cpp +++ b/alg/nway_paths.cpp @@ -185,7 +185,7 @@ NwayPaths::save(fs::path save_file_path) //cout << a_path.size() << endl; //first entry is the window length of the windows in the path save_file << a_path.window_size << ":"; - for(size_t i = 0; i != sequence_count(); ++i) + for(size_type i = 0; i != sequence_count(); ++i) { save_file << a_path[i]; if (i != sequence_count()) @@ -200,8 +200,7 @@ NwayPaths::save(fs::path save_file_path) } -size_t -NwayPaths::sequence_count() +NwayPaths::size_type NwayPaths::sequence_count() const { if (refined_pathz.begin() == refined_pathz.end() ) return 0; @@ -209,6 +208,10 @@ NwayPaths::sequence_count() return refined_pathz.begin()->size(); } +NwayPaths::size_type NwayPaths::size() const +{ + return pathz.size(); +} void NwayPaths::load(fs::path load_file_path) @@ -274,7 +277,7 @@ NwayPaths::load(fs::path load_file_path) // whats our window size? path_width = file_data_line.substr(0,colon_split_i); file_data_line = file_data_line.substr(colon_split_i+1); - for(size_t i = 0; i < species_num; i++) + for(size_type i = 0; i < species_num; i++) { comma_split_i = file_data_line.find(","); path_node = file_data_line.substr(0, comma_split_i); @@ -295,7 +298,7 @@ NwayPaths::load(fs::path load_file_path) void -NwayPaths::path_search(vector > all_comparisons, ConservedPath path, size_t depth) +NwayPaths::path_search(vector > all_comparisons, ConservedPath path, size_type depth) { list new_nodes, trans_check_nodes; list::iterator new_nodes_i, new_nodes_end; @@ -309,7 +312,7 @@ NwayPaths::path_search(vector > all_comparisons, ConservedPath path //cout << " * species " << depth << " node: " << *new_nodes_i << endl; // check transitivity with previous nodes in path trans_check_good = true; - for(size_t i = 0; i < depth - 1; i++) + for(size_type i = 0; i < depth - 1; i++) { trans_check_nodes = all_comparisons[i][depth].match_locations(path[i]); if ( (trans_check_nodes.end() == find(trans_check_nodes.begin(), @@ -381,7 +384,7 @@ NwayPaths::save_old(fs::path save_file_path) { fs::fstream save_file; list::iterator path_i, paths_end; - size_t i; + size_type i; save_file.open(save_file_path, ios::app); diff --git a/alg/nway_paths.hpp b/alg/nway_paths.hpp index 8725432..686e27f 100644 --- a/alg/nway_paths.hpp +++ b/alg/nway_paths.hpp @@ -35,6 +35,7 @@ signals: void progress(const QString& description, int cur, int max); public: + typedef size_t size_type; typedef std::list ConservedPaths; NwayPaths(); @@ -62,7 +63,7 @@ public: // old recursive transitive nway ... has issues checking all links? void find_paths_r(std::vector > all_comparisons); - void path_search(std::vector > all_comparisons, ConservedPath path, size_t depth); + void path_search(std::vector > all_comparisons, ConservedPath path, size_type depth); void simple_refine(); void save(boost::filesystem::path save_file_path); @@ -71,7 +72,7 @@ public: void add_path(int threshold, std::vector& loaded_path); void add_path(ConservedPath loaded_path); //! how many sequences are in our comparison - size_t sequence_count(); + size_type sequence_count() const; void find_paths(std::vector > all_comparisons); void refine(); @@ -83,11 +84,12 @@ public: // they'll have problems when being called from within a const object ConservedPaths::iterator pbegin() { return pathz.begin() ; } ConservedPaths::iterator pend() { return pathz.end() ; } - size_t path_size() const { return refined_pathz.size(); } + size_type path_size() const { return pathz.size(); } ConservedPaths::iterator rpbegin() { return refined_pathz.begin() ; } ConservedPaths::iterator rpend() { return refined_pathz.end() ; } - size_t refined_path_size() const { return refined_pathz.size(); } + size_type refined_path_size() const { return refined_pathz.size(); } + size_type size() const; // these probably shouldn't be public, but lets start // simple ConservedPaths pathz; @@ -95,11 +97,10 @@ public: protected: int threshold; - size_t win_size; + size_type win_size; int soft_thres; double ent_thres; std::vector c_sequences; //used by entropy_path_search - }; #endif diff --git a/alg/test/test_nway.cpp b/alg/test/test_nway.cpp index 6c4704c..cfeef25 100644 --- a/alg/test/test_nway.cpp +++ b/alg/test/test_nway.cpp @@ -26,6 +26,11 @@ BOOST_AUTO_TEST_CASE( nway_null ) analysis.set_threshold(3); analysis.analyze(); NwayPaths npath = analysis.paths(); + // we added 3 sequences, but none-matched + BOOST_CHECK_EQUAL( npath.sequence_count(), 0); + BOOST_CHECK_EQUAL( npath.size(), 0 ); + BOOST_CHECK_EQUAL( npath.path_size(), 0 ); + BOOST_CHECK_EQUAL( npath.refined_path_size(), 0 ); // there should be no paths for these sequences for (std::list::iterator pathz_i = npath.pathz.begin(); pathz_i != npath.pathz.end(); @@ -48,6 +53,10 @@ BOOST_AUTO_TEST_CASE( nway_test ) analysis.set_threshold(3); analysis.analyze(); NwayPaths npath = analysis.paths(); + BOOST_CHECK_EQUAL( npath.sequence_count(), 2); + BOOST_CHECK_EQUAL( npath.size(), 2 ); + BOOST_CHECK_EQUAL( npath.path_size(), 2 ); + BOOST_CHECK_EQUAL( npath.refined_path_size(), 2 ); for (std::list::iterator pathz_i = npath.pathz.begin(); pathz_i != npath.pathz.end(); ++pathz_i) @@ -69,13 +78,17 @@ BOOST_AUTO_TEST_CASE( nway_refine ) m1.load_mupa_file( mupa_path ); m1.analyze(); const NwayPaths& npath = m1.paths(); - BOOST_CHECK_EQUAL (npath.path_size(), npath.refined_path_size()); + //BOOST_CHECK_EQUAL (npath.path_size(), npath.refined_path_size()); + // FIXME: shouldn't these be equal to start with? + BOOST_CHECK(npath.path_size() > npath.refined_path_size()); size_t first_refined_size = npath.refined_path_size(); BOOST_CHECK( first_refined_size > 0 ); // we're using a window size 30 (threshold 20) example m1.set_soft_threshold(22); m1.nway(); + BOOST_CHECK_EQUAL( npath.path_size(), npath.size() ); + BOOST_CHECK( npath.path_size() > 0 ); BOOST_CHECK( npath.refined_path_size() > 0); BOOST_CHECK( npath.refined_path_size() < first_refined_size); diff --git a/py/nway_paths.cpp b/py/nway_paths.cpp index 6ca2f20..ba605d9 100644 --- a/py/nway_paths.cpp +++ b/py/nway_paths.cpp @@ -20,13 +20,18 @@ void export_nway_paths() ;*/ py::class_("NwayPaths") - .def("__len__", &NwayPaths::sequence_count) + .def("__len__", &NwayPaths::size, "number of paths") + .def("sequence_count", &NwayPaths::sequence_count, + "number of sequences in this analysis") .def("clear", &NwayPaths::clear, "remove all paths") .add_property("threshold", &NwayPaths::get_threshold, "Get hard threshold") .add_property("soft_threshold", &NwayPaths::get_soft_threshold, &NwayPaths::set_soft_threshold) .add_property("window_size", &NwayPaths::get_window) .add_property("pathz", py::range(&NwayPaths::pbegin, &NwayPaths::pend)) + .def("path_size", &NwayPaths::path_size, "number of nway paths") .add_property("refinedPathz", py::range(&NwayPaths::rpbegin, &NwayPaths::rpend)) + .def("refined_path_size", &NwayPaths::refined_path_size, + "number of paths that match the soft threshold") ; } diff --git a/py/test/TestMussa.py b/py/test/TestMussa.py index 84062ae..953b334 100644 --- a/py/test/TestMussa.py +++ b/py/test/TestMussa.py @@ -10,20 +10,23 @@ import mussa class TestMussa(unittest.TestCase): def testSimple(self): s1 = mussa.Sequence("A"*10) - s2 = mussa.Sequence("GG"+"A"*8+"GG") - s3 = mussa.Sequence("T"*10) + s2 = mussa.Sequence("GG"+"A"*10) + s3 = mussa.Sequence("A"*10) m = mussa.Mussa() m.window = 10 - m.threshold = 8 + m.threshold = 10 m.add_sequence(s1) m.add_sequence(s2) m.add_sequence(s3) m.analyze() # this could probably be a more thorough test - self.failUnless( len(m.paths()), 3 ) + paths = m.paths() + self.failUnlessEqual( len(paths), 1 ) + pathz_list = [ x for x in paths.pathz ] + self.failUnlessEqual( len(paths), len(pathz_list) ) def suite(): return unittest.makeSuite(TestMussa, 'test') if __name__ == "__main__": - sys.exit(unittest.main(defaultTest='suite')) \ No newline at end of file + sys.exit(unittest.main(defaultTest='suite')) -- 2.30.2