len(mussa.paths()) should equal the number of found paths
authorDiane Trout <diane@caltech.edu>
Thu, 14 Dec 2006 21:17:25 +0000 (21:17 +0000)
committerDiane Trout <diane@caltech.edu>
Thu, 14 Dec 2006 21:17:25 +0000 (21:17 +0000)
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
alg/nway_paths.hpp
alg/test/test_nway.cpp
py/nway_paths.cpp
py/test/TestMussa.py

index df2cf2e0d9794e788341a7c3c6da10d2e7596d58..e7a8474b9ce062d7cafd47cdbe88855d81f3405b 100644 (file)
@@ -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<vector<FLPs> > all_comparisons, ConservedPath path, size_t depth)
+NwayPaths::path_search(vector<vector<FLPs> > all_comparisons, ConservedPath path, size_type depth)
 {
   list<int> new_nodes, trans_check_nodes;
   list<int>::iterator new_nodes_i, new_nodes_end;
@@ -309,7 +312,7 @@ NwayPaths::path_search(vector<vector<FLPs> > 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<ConservedPath >::iterator path_i, paths_end;
-  size_t i;
+  size_type i;
 
   save_file.open(save_file_path, ios::app);
 
index 8725432a7880f78f95d0777651183fc59b4b4e34..686e27f524602521efc24af61d1fe08a22795299 100644 (file)
@@ -35,6 +35,7 @@ signals:
   void progress(const QString& description, int cur, int max);
 
 public:
+    typedef size_t size_type;
     typedef std::list<ConservedPath> ConservedPaths;
     
     NwayPaths();
@@ -62,7 +63,7 @@ public:
 
   // old recursive transitive nway ... has issues checking all links?
     void find_paths_r(std::vector<std::vector<FLPs> > all_comparisons);
-    void path_search(std::vector<std::vector<FLPs> > all_comparisons, ConservedPath path, size_t depth);
+    void path_search(std::vector<std::vector<FLPs> > 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<int>& 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<std::vector<FLPs> > 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<char *> c_sequences; //used by entropy_path_search
-
 };
 #endif
index 6c4704cc9c18cf45f18974710965154c9e9e154a..cfeef259b7e71a3ee75a558a0b68a0ece7983b81 100644 (file)
@@ -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<ConservedPath >::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<ConservedPath >::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);
 
index 6ca2f20e0a7ecce7507c49f15045ca61be353faa..ba605d9d76c2ad3aef76122368b2b95a378949c9 100644 (file)
@@ -20,13 +20,18 @@ void export_nway_paths()
   ;*/
  
    py::class_<NwayPaths>("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")
    ;
 }
 
index 84062ae747eda7b5722219e688281df71cea55ca..953b334cbb412d6a056505416b29626c478a9dc9 100644 (file)
@@ -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'))