switch to using boost::filesystem
[mussa.git] / alg / sequence.cpp
index 439fcb9ecf53ee17196547de4d559692f47493e9..7e7468b3f2ad3feaba2d3a1453ceb51039292ea7 100644 (file)
@@ -21,6 +21,7 @@
 //                        ----------------------------------------
 //                           ---------- sequence.cc -----------
 //                        ----------------------------------------
+#include <boost/filesystem/fstream.hpp>
 
 #include "alg/sequence.hpp"
 #include "mussa_exceptions.hpp"
@@ -28,6 +29,7 @@
 #include <string>
 #include <iostream>
 
+namespace fs = boost::filesystem;
 using namespace std;
 
 annot::annot() 
@@ -103,10 +105,10 @@ ostream& operator<<(ostream& out, const Sequence& seq)
  * \return error message, empty string if no error. (gag!)
  */
 void
-Sequence::load_fasta(string file_path, int seq_num, 
+Sequence::load_fasta(fs::path file_path, int seq_num, 
                      int start_index, int end_index)
 {
-  fstream data_file;
+  fs::fstream data_file;
   string file_data_line;
   int header_counter = 0;
   bool read_seq = true;
@@ -114,14 +116,14 @@ Sequence::load_fasta(string file_path, int seq_num,
   string sequence_raw;
   string seq_tmp;             // holds sequence during basic filtering
 
-  data_file.open(file_path.c_str(), ios::in);
+  data_file.open(file_path, ios::in);
 
   if (seq_num == 0) {
     throw mussa_load_error("fasta sequence number is 1 based (can't be 0)");
   }
   if (!data_file)
   {    
-    throw mussa_load_error("Sequence File: " + file_path + " not found"); 
+    throw mussa_load_error("Sequence File: " + file_path.string() + " not found"); 
   }
   // if file opened okay, read it
   else
@@ -203,9 +205,9 @@ void Sequence::set_filtered_sequence(const string &old_seq,
 
 
 void
-Sequence::load_annot(string file_path, int start_index, int end_index)
+Sequence::load_annot(fs::path file_path, int start_index, int end_index)
 {
-  fstream data_file;
+  fs::fstream data_file;
   string file_data_line;
   annot an_annot;
   string::size_type space_split_i;
@@ -215,11 +217,11 @@ Sequence::load_annot(string file_path, int start_index, int end_index)
 
 
   annots.clear();
-  data_file.open(file_path.c_str(), ios::in);
+  data_file.open(file_path, ios::in);
 
   if (!data_file)
   {
-    throw mussa_load_error("Sequence File: " + file_path + " not found");
+    throw mussa_load_error("Sequence File: " + file_path.string() + " not found");
   }
   // if file opened okay, read it
   else
@@ -285,8 +287,7 @@ Sequence::load_annot(string file_path, int start_index, int end_index)
           an_annot.end -= start_index;
           annots.push_back(an_annot);
         }
-        else
-          cout << "FAILED!!!!!!\n";
+        // else no (or bogus) annotations
       }
     }
 
@@ -448,7 +449,7 @@ Sequence::clear()
 }
 
 void
-Sequence::save(fstream &save_file)
+Sequence::save(fs::fstream &save_file)
                //string save_file_path)
 {
   //fstream save_file;
@@ -475,9 +476,9 @@ Sequence::save(fstream &save_file)
 }
 
 void
-Sequence::load_museq(string load_file_path, int seq_num)
+Sequence::load_museq(fs::path load_file_path, int seq_num)
 {
-  fstream load_file;
+  fs::fstream load_file;
   string file_data_line;
   int seq_counter;
   annot an_annot;
@@ -485,7 +486,7 @@ Sequence::load_museq(string load_file_path, int seq_num)
   string annot_value;
 
   annots.clear();
-  load_file.open(load_file_path.c_str(), ios::in);
+  load_file.open(load_file_path, ios::in);
 
   seq_counter = 0;
   // search for the seq_num-th sequence