Update mussa to build on ubuntu 10.04 with qt 4.6.2 +boost 1.40.0.1
[mussa.git] / alg / test / test_mussa.cpp
index 74f8a9c658e55047f7a8b2e24e4502eafd99e423..5255fe26d7a309130c99b0369bbb8749fba7298a 100644 (file)
@@ -1,4 +1,7 @@
-#include <boost/test/auto_unit_test.hpp>
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE test_mussa
+#include <boost/test/unit_test.hpp>
+
 #include <boost/filesystem/path.hpp>
 #include <boost/filesystem/operations.hpp>
 namespace fs = boost::filesystem;
@@ -109,6 +112,58 @@ BOOST_AUTO_TEST_CASE ( empty_mussa_set_threshold )
   m.nway();
 }
 
+BOOST_AUTO_TEST_CASE( mussa_load_mupa_crlf )
+{
+  fs::path example_path(EXAMPLE_DIR, fs::native);
+  fs::path seq_path(example_path / "seq" / "mouse_mck_pro.fa");
+  fs::path annot_path(example_path / "mm_mck3test.annot");
+
+  std::string mupa(
+    "# hello\015\012"
+    "ANA_NAME load_mupa_crlf\015\012");
+  mupa += "SEQUENCE " + seq_path.native_file_string() + "\015\012";
+  mupa += "ANNOTATION " + annot_path.native_file_string() + "\015\012";
+  
+  istringstream mupa_stream(mupa);
+  Mussa m;
+  fs::path base;
+  m.load_mupa_stream( mupa_stream, base );
+  // Should run with no exceptions
+}
+
+BOOST_AUTO_TEST_CASE( mussa_load_mupa_comment_character )
+{
+  fs::path mupa_path(EXAMPLE_DIR, fs::native);
+  fs::path seq_path = fs::initial_path() / "seq" / "mouse_mck_pro.fa";
+  fs::path annot_path = fs::initial_path() / "mm_mck3test.annot";
+
+  std::string mupa(
+    "# hello\015\012"
+    "ANA_NAME load_mupa_crlf\015\012");
+  mupa += "#SEQUENCE " + seq_path.native_file_string() + "\015\012";
+  mupa += "#ANNOTATION " + annot_path.native_file_string() + "\015\012";
+  
+  istringstream mupa_stream(mupa);
+  Mussa m;
+  fs::path base;
+  m.load_mupa_stream( mupa_stream, base );
+  // Should run with no exceptions
+}
+
+BOOST_AUTO_TEST_CASE( mussa_load_mupa_exception )
+{
+  std::string mupa(
+    "# hello\015\012"
+    "ANA_NAME load_mupa_crlf\015\012"
+    "mwahhaha I broke you!\n"
+  );
+  
+  istringstream mupa_stream(mupa);
+  Mussa m;
+  fs::path base;
+  BOOST_CHECK_THROW(m.load_mupa_stream( mupa_stream, base ), mussa_load_error);
+}
+
 BOOST_AUTO_TEST_CASE( mussa_load_mupa )
 {
   fs::path mupa_path(EXAMPLE_DIR, fs::native);
@@ -151,6 +206,17 @@ BOOST_AUTO_TEST_CASE( mussa_load_full_path )
   BOOST_CHECK_EQUAL( m1.is_dirty(), true);
   BOOST_CHECK_EQUAL( m1.get_analysis_path().string(), "");
 }
+  
+BOOST_AUTO_TEST_CASE( mussa_valid_motifs_in_new_analysis )
+{
+  Mussa m1;
+  fs::path full_path(fs::path(EXAMPLE_DIR, fs::native) / "mck3test.mupa");
+  m1.load_mupa_file( full_path );
+  m1.analyze();
+  // check motifs
+  BOOST_CHECK( m1.sequences().size() > 0 );
+  BOOST_CHECK_EQUAL( m1.sequences()[0]->motifs().size(), 0 );  
+}
 
 // make sure we know that mupa files cannot be directories 
 BOOST_AUTO_TEST_CASE( mussa_mupa_is_file_not_directory )
@@ -160,6 +226,14 @@ BOOST_AUTO_TEST_CASE( mussa_mupa_is_file_not_directory )
   BOOST_CHECK_THROW(m1.load_mupa_file( curdir ), mussa_load_error );
 }
 
+// catch error if annotation isn't a file
+BOOST_AUTO_TEST_CASE( mussa_annotation_is_not_file )
+{
+  Mussa m1;
+  fs::path full_path(fs::path(EXAMPLE_DIR, fs::native) / "directory.mupa");
+  BOOST_CHECK_THROW( m1.load_mupa_file( full_path ), mussa_load_error );
+}
+
 BOOST_AUTO_TEST_CASE( mussa_load_analysis )
 {
   fs::path example_dir(EXAMPLE_DIR, fs::native);
@@ -462,7 +536,6 @@ BOOST_AUTO_TEST_CASE( three_way_local_alignment )
       result_i != result.end();
       ++result_i)
   {
-    std::cout << "path ";
     ConservedPath::path_element first_element = *(result_i->begin());
     for (ConservedPath::path_type::iterator element_i = result_i->begin();
          element_i != result_i->end();
@@ -472,12 +545,23 @@ BOOST_AUTO_TEST_CASE( three_way_local_alignment )
       BOOST_CHECK_EQUAL( s0[*element_i], s1[*element_i] );
       BOOST_CHECK_EQUAL( s1[*element_i], s2[*element_i] );
       BOOST_CHECK_EQUAL( s0[*element_i], s2[*element_i] );
-      std::cout << *element_i << " " << s0[*element_i];
     }
-    std::cout << std::endl;
   }   
 }
 
+BOOST_AUTO_TEST_CASE( mussa_window_larger_than_sequence )
+{
+  string s0("AGCAGGG");
+  string s1("CAGCGGG");
+  
+  Mussa analysis;
+  analysis.append_sequence(s0);
+  analysis.append_sequence(s1);
+  analysis.set_threshold(23);
+  analysis.set_window(30);
+  BOOST_CHECK_THROW(analysis.analyze(), seqcomp_error);
+}
+
 BOOST_AUTO_TEST_CASE( subanalysis )
 {
   Sequence s1("AATGAAGATTTTAATGCTTTAATTTTGTTTTGTAAACTTCGAATTTCCAAAATTTGAAA");