more error messages for loading an annotation.
[mussa.git] / alg / sequence.cpp
index b97d3950121630d130c095a2ae86838e38b79950..452f5f98f204d37bf0f85f173eb1f42fc2a07313 100644 (file)
@@ -22,6 +22,7 @@
 //                           ---------- sequence.cc -----------
 //                        ----------------------------------------
 #include <boost/filesystem/fstream.hpp>
+#include <boost/filesystem/operations.hpp>
 namespace fs = boost::filesystem;
 
 #include <boost/spirit/core.hpp>
@@ -313,10 +314,18 @@ void Sequence::set_filtered_sequence(const std::string &in_seq,
 void
 Sequence::load_annot(fs::path file_path, int start_index, int end_index)
 {
+  if (not fs::exists(file_path)) {
+    throw mussa_load_error("Annotation File " + file_path.string() + " was not found");
+  }
+  if (fs::is_directory(file_path)) {
+    throw mussa_load_error(file_path.string() +
+            " is a directory, please provide a file for annotations."
+          );
+  }    
   fs::fstream data_stream(file_path, std::ios::in);
   if (!data_stream)
   {
-    throw mussa_load_error("Sequence File: " + file_path.string() + " not found");
+    throw mussa_load_error("Error loading annotation file " + file_path.string());
   }
 
   // so i should probably be passing the parse function some iterators
@@ -752,6 +761,30 @@ bool Sequence::empty() const
   return (seq_count == 0) ? true : false;
 }
 
+Sequence::size_type Sequence::find_first_not_of(
+  const std::string& query, 
+  Sequence::size_type index)
+{
+  typedef std::set<std::string::value_type> sequence_set;
+  sequence_set match_set;
+  
+  for(const_iterator query_item = query.begin();
+      query_item != query.end();
+      ++query_item)
+  {
+    match_set.insert(*query_item);
+  }  
+  for(const_iterator base = begin();
+      base != end();
+      ++base)
+  {
+    if(match_set.find(*base) == match_set.end()) {
+      return base-begin();
+    } 
+  }
+  return Sequence::npos;
+}
 Sequence::size_type Sequence::start() const
 {
   if (parent)