From: Diane Trout Date: Fri, 7 Apr 2006 02:10:30 +0000 (+0000) Subject: switch to using boost::filesystem X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=mussa.git;a=commitdiff_plain;h=2a85276d85824ce48b938178dc22ccab2e7ab1fd switch to using boost::filesystem I changed the loading code to use boost::filesystem, and also updated the build system to hardcode the location of the example data in the unittest program. The result of this is I can now use easier filesystem handling code and my unittests will work even when we build the app out of source --- diff --git a/alg/flp.cpp b/alg/flp.cpp index 3076e7b..88ff209 100644 --- a/alg/flp.cpp +++ b/alg/flp.cpp @@ -12,14 +12,18 @@ // ---------- flp.cc ----------- // ---------------------------------------- +#include +#include +namespace fs = boost::filesystem; + #include "alg/flp.hpp" -#include #include #include #include #include +#include "mussa_exceptions.hpp" using namespace std; bool operator==(const FLPs::match& a, const FLPs::match& b) @@ -168,13 +172,13 @@ FLPs::thres_matches(int index, int thres) const } void -FLPs::save(string save_file_path) +FLPs::save(fs::path save_file_path) { if (all_matches == 0) throw runtime_error("please call FLPs.seqcomp first"); - fstream save_file; - save_file.open(save_file_path.c_str(), ios::out); + fs::fstream save_file; + save_file.open(save_file_path, ios::out); save_file << "") - { - tag_open = false; - } - // parse line of matches - else if (file_data_line == "") - { - //cout << "empty line\n"; - all_matches->push_back(a_match_list); - } - else + // parse seqcomp open tag and parameters + // eg + // if parse successful... + tag_open = true; + + while ((data_file.good()) && tag_open) { - split_index = file_data_line.find(" "); - - while (split_index != string::npos) - { - pair_data = file_data_line.substr(0,split_index); - file_data_line = file_data_line.substr(split_index+1); - //cout << "pair_data = " << pair_data << "..."; - // parse out the 2 pieces of data, index and score of pair match - comma_index = pair_data.find(","); - index_data = pair_data.substr(0, comma_index); - a_match.index = atoi(index_data.c_str() ); - score_data = pair_data.substr(comma_index+1); - a_match.score = atoi(score_data.c_str() ); - //cout << a_match.index << "," << a_match.score << " "; - - a_match_list.push_back(a_match); + // intialize list to empty + a_match_list.clear(); + getline(data_file,file_data_line); + if (file_data_line == "") + { + tag_open = false; + } + // parse line of matches + else if (file_data_line == "") + { + //cout << "empty line\n"; + all_matches->push_back(a_match_list); + } + else + { split_index = file_data_line.find(" "); + + while (split_index != string::npos) + { + pair_data = file_data_line.substr(0,split_index); + file_data_line = file_data_line.substr(split_index+1); + //cout << "pair_data = " << pair_data << "..."; + // parse out the 2 pieces of data, index and score of pair match + comma_index = pair_data.find(","); + index_data = pair_data.substr(0, comma_index); + a_match.index = atoi(index_data.c_str() ); + score_data = pair_data.substr(comma_index+1); + a_match.score = atoi(score_data.c_str() ); + //cout << a_match.index << "," << a_match.score << " "; + + a_match_list.push_back(a_match); + + split_index = file_data_line.find(" "); + } + all_matches->push_back(a_match_list); + //cout << all_matches->size() << "\n"; } - all_matches->push_back(a_match_list); - //cout << all_matches->size() << "\n"; } + //cout << "windows in flp = " << all_matches->size() << endl; + data_file.close(); + } else { + throw mussa_load_error(file_path.string() + "was not found"); } - //cout << "windows in flp = " << all_matches->size() << endl; - data_file.close(); + } diff --git a/alg/flp.hpp b/alg/flp.hpp index ed9c02b..0f5f892 100644 --- a/alg/flp.hpp +++ b/alg/flp.hpp @@ -14,6 +14,8 @@ // ---------- flp.hh ----------- // ---------------------------------------- +#include + #include #include #include @@ -58,9 +60,9 @@ class FLPs */ int size() const; //! Save all the FLPs to save_file_path - void save(std::string save_file_path); + void save(boost::filesystem::path save_file_path); //! Load a vector of a lists of FLPs - void load(std::string file_path); + void load(boost::filesystem::path file_path); private: //! the number of base pairs in the sliding window int window_size; diff --git a/alg/mussa.cpp b/alg/mussa.cpp index e713f52..e432b58 100644 --- a/alg/mussa.cpp +++ b/alg/mussa.cpp @@ -11,8 +11,10 @@ // ---------------------------------------- // ---------- mussa_class.cc ----------- // ---------------------------------------- +#include +#include +namespace fs = boost::filesystem; -#include #include #include @@ -166,24 +168,24 @@ Mussa::sequences() const return the_seqs; } -void Mussa::load_sequence(string seq_file, string annot_file, int fasta_index, - int sub_seq_start, int sub_seq_end) +void Mussa::load_sequence(fs::path seq_file, fs::path annot_file, + int fasta_index, int sub_seq_start, int sub_seq_end) { Sequence aseq; aseq.load_fasta(seq_file, fasta_index, sub_seq_start, sub_seq_end); - if (annot_file.size() > 0) { + if ( not annot_file.empty() ) { aseq.load_annot(annot_file, sub_seq_start, sub_seq_end); } the_seqs.push_back(aseq); } void -Mussa::load_mupa_file(string para_file_path) +Mussa::load_mupa_file(fs::path para_file_path) { - string file_path_base; - ifstream para_file; + fs::ifstream para_file; string file_data_line; - string param, value, annot_file; + string param, value; + fs::path annot_file; int split_index, fasta_index; int sub_seq_start, sub_seq_end; bool seq_params, did_seq; @@ -194,24 +196,13 @@ Mussa::load_mupa_file(string para_file_path) // initialize values clear(); - para_file.open(para_file_path.c_str(), ios::in); - // if file was opened, read the parameter values - if (para_file) + if (fs::exists(para_file_path)) { - // need to find the path to the .mupa file - parsing_path = true; - dir_index = 0; - while (parsing_path) - { - new_index = (para_file_path.substr(dir_index)).find("/"); - if (new_index != string::npos) - dir_index += new_index + 1; - else - parsing_path = false; - } + para_file.open(para_file_path, ios::in); - file_path_base = para_file_path.substr(0,dir_index); + // what directory is the mupa file in? + fs::path file_path_base = para_file_path.branch_path(); // setup loop by getting file's first line getline(para_file,file_data_line); @@ -236,7 +227,7 @@ Mussa::load_mupa_file(string para_file_path) threshold = atoi(value.c_str()); else if (param == "SEQUENCE") { - string seq_file = file_path_base + value; + fs::path seq_file = file_path_base / value; //cout << "seq_file_name " << seq_files.back() << endl; fasta_index = 1; annot_file = ""; @@ -254,7 +245,7 @@ Mussa::load_mupa_file(string para_file_path) if (param == "FASTA_INDEX") fasta_index = atoi(value.c_str()); else if (param == "ANNOTATION") - annot_file = file_path_base + value; + annot_file = file_path_base / value; else if (param == "SEQ_START") sub_seq_start = atoi(value.c_str()); else if (param == "SEQ_END") @@ -297,7 +288,7 @@ Mussa::load_mupa_file(string para_file_path) // no file was loaded, signal error else { - throw mussa_load_error("Config File: " + para_file_path + " not found"); + throw mussa_load_error("Config File: " + para_file_path.string() + " not found"); } } @@ -424,93 +415,74 @@ Mussa::nway() void Mussa::save() { - string save_name, save_path, create_dir_cmd, flp_filepath; - fstream save_file; + string save_name; + fs::path flp_filepath; + fs::fstream save_file; ostringstream append_info; int dir_create_status; + if (not analysis_name.empty()) { + // not sure why, but gotta close file each time since can't pass + // file streams + save_name = analysis_name; - // not sure why, but gotta close file each time since can't pass file streams - - save_name = analysis_name; - - // gotta do bit with adding win & thres if to be appended - if (win_append) - { - append_info.str(""); - append_info << "_w" << window; - save_name += append_info.str(); - } - - if (thres_append) - { - append_info.str(""); - append_info << "_t" << threshold; - save_name += append_info.str(); - } + // gotta do bit with adding win & thres if to be appended + if (win_append) + { + append_info.str(""); + append_info << "_w" << window; + save_name += append_info.str(); + } -//#include - // ******* use appropriate for os ------- 1 of 4 - // the additions for osX make it more sane where it saves the analysis - // will come up with a cleaner sol'n later... - create_dir_cmd = "mkdir " + save_name; //linux - //create_dir_cmd = "mkdir " + file_path_base + save_name; //osX + if (thres_append) + { + append_info.str(""); + append_info << "_t" << threshold; + save_name += append_info.str(); + } + fs::path save_path( save_name); - dir_create_status = system( (const char*) create_dir_cmd.c_str()); - //cout << "action: " << dir_create_status << endl; + if (not fs::exists(save_path)) { + fs::create_directory(save_path); + } + // save sequence and annots to a special mussa file + save_file.open(save_path / (save_name+".museq"), ios::out); + save_file << "" << endl; - // save sequence and annots to a special mussa file + for(vector::size_type i = 0; i < the_seqs.size(); i++) + { + the_seqs[i].save(save_file); + } - // ******** use appropriate for OS ---------- 2 of 4 - save_path = save_name + "/" + save_name + ".museq"; //linux - //save_path = file_path_base + save_name + "/" + save_name + ".museq"; //osX + save_file << "" << endl; + save_file.close(); - save_file.open(save_path.c_str(), ios::out); - save_file << "" << endl; - //save_file.close(); + // save nway paths to its mussa save file + the_paths.save(save_path / (save_name + ".muway")); - for(vector::size_type i = 0; i < the_seqs.size(); i++) - { - the_seqs[i].save(save_file); + for(vector::size_type i = 0; i < the_seqs.size(); i++) + for(vector::size_type i2 = i+1; i2 < the_seqs.size(); i2++) + { + append_info.str(""); + append_info << "_sp_" << i << "v" << i2; + all_comps[i][i2].save(save_path/(save_name+append_info.str()+".flp")); + } } - - //save_file.open(save_path.c_str(), ios::app); - save_file << "" << endl; - save_file.close(); - - // save nway paths to its mussa save file - - // ******** use appropriate for OS -------- 3 of 4 - save_path = save_name + "/" + save_name + ".muway"; //linux - //save_path = file_path_base + save_name + "/" + save_name + ".muway"; //os X - the_paths.save(save_path); - - for(vector::size_type i = 0; i < the_seqs.size(); i++) - for(vector::size_type i2 = i+1; i2 < the_seqs.size(); i2++) - { - append_info.str(""); - append_info << "_sp_" << i << "v" << i2; - // ******** use appropriate for OS --------- 4 of 4 - //linux - save_path = save_name + "/" + save_name + append_info.str() + ".flp"; - //osX - //save_path = file_path_base + save_name + "/" + save_name + append_info.str() + ".flp"; - all_comps[i][i2].save(save_path); - } } void -Mussa::save_muway(string save_path) +Mussa::save_muway(fs::path save_path) { the_paths.save(save_path); } void -Mussa::load(string ana_file) +Mussa::load(fs::path ana_file) { int i, i2; - string::size_type start_index, end_index; - string file_path_base, a_file_path, ana_path; + fs::path file_path_base; + fs::path a_file_path; + fs::path ana_path(ana_file); bool parsing_path; Sequence tmp_seq; string err_msg; @@ -518,27 +490,12 @@ Mussa::load(string ana_file) vector empty_FLP_vector; FLPs dummy_comp; - //cout << "ana_file name " << ana_file << endl; - ana_path = ana_file; - parsing_path = true; - end_index = ana_path.size()-1; - if (ana_path[end_index] == '/') { - --end_index; - } - start_index = ana_path.rfind('/', end_index); - if (start_index == string::npos) { - // no / to be found - start_index = 0; - } else { - // skip the / we found - ++start_index; - } - analysis_name = ana_path.substr(start_index, end_index-start_index+1); + //cout << "ana_file name " << ana_file.string() << endl; + analysis_name = ana_path.leaf(); //cout << " ana_name " << analysis_name << endl; - file_path_base = ana_path.substr(0, start_index) + analysis_name - + "/" + analysis_name; - a_file_path = file_path_base + ".muway"; - //cout << " loading museq: " << a_file_path << endl; + file_path_base = ana_path.branch_path() / analysis_name; + a_file_path = file_path_base / (analysis_name + ".muway"); + //cout << " loading museq: " << a_file_path.string() << endl; the_paths.load(a_file_path); // perhaps this could be more elegent, but at least this'll let // us know what our threshold and window sizes were when we load a muway @@ -548,13 +505,13 @@ Mussa::load(string ana_file) int seq_num = the_paths.sequence_count(); - a_file_path = file_path_base + ".museq"; + a_file_path = file_path_base / (analysis_name + ".museq"); // this is a bit of a hack due to C++ not acting like it should with files for (i = 1; i <= seq_num; i++) { tmp_seq.clear(); - //cout << "mussa_class: loading museq frag... " << a_file_path << endl; + //cout << "mussa_class: loading museq frag... " << a_file_path.string() << endl; tmp_seq.load_museq(a_file_path, i); the_seqs.push_back(tmp_seq); } @@ -572,9 +529,10 @@ Mussa::load(string ana_file) for(i2 = i+1; i2 < seq_num; i2++) { append_info.str(""); - append_info << "_sp_" << i << "v" << i2; + append_info << analysis_name << "_sp_" << i << "v" << i2 << ".flp"; //cout << append_info.str() << endl; - a_file_path = file_path_base + append_info.str() + ".flp"; + a_file_path = file_path_base / append_info.str(); + //cout << "path " << a_file_path.string() << endl; all_comps[i][i2].load(a_file_path); //cout << "real size = " << all_comps[i][i2].size() << endl; } @@ -585,9 +543,9 @@ Mussa::load(string ana_file) void Mussa::save_old() { - fstream save_file; + fs::fstream save_file; - save_file.open(analysis_name.c_str(), ios::out); + save_file.open(analysis_name, ios::out); for(vector::size_type i = 0; i < the_seqs.size(); i++) save_file << the_seqs[i].get_seq() << endl; @@ -720,10 +678,10 @@ void Mussa::load_motifs(std::istream &in) update_sequences_motifs(); } -void Mussa::load_motifs(string filename) +void Mussa::load_motifs(fs::path filename) { - ifstream f; - f.open(filename.c_str(), ifstream::in); + fs::ifstream f; + f.open(filename, ifstream::in); load_motifs(f); } diff --git a/alg/mussa.hpp b/alg/mussa.hpp index b4a6e26..675658d 100644 --- a/alg/mussa.hpp +++ b/alg/mussa.hpp @@ -13,6 +13,7 @@ // ---------------------------------------- // ---------- mussa_class.hh ----------- // ---------------------------------------- +#include #include #include @@ -37,15 +38,16 @@ class Mussa Mussa(const Mussa &); void save(); - void save_muway(std::string save_path); + //! save the nway comparison + void save_muway(boost::filesystem::path save_path); //! load a saved analysis directory - void load(std::string ana_path); + void load(boost::filesystem::path ana_path); //! clear parameters and initialize data lists void clear(); - // set parameters from a file - 'mupa' ~ mussa parameters - void load_mupa_file(std::string para_file_path); + //! set parameters from a file - 'mupa' ~ mussa parameters + void load_mupa_file(boost::filesystem::path para_file_path); // set parameters individually (eg from user input into gui classes) //! set analysis name @@ -105,7 +107,8 @@ class Mussa * \param[in] sub_seq_end ending slice index to select a subsequence * use 0 to go to the end. */ - void load_sequence(std::string seq_file, std::string annot_file, + void load_sequence(boost::filesystem::path seq_file, + boost::filesystem::path annot_file, int fasta_index, int sub_seq_start=0, int sub_seq_end=0); //! allow examining the sequences we have loaded const std::vector& sequences() const; @@ -132,7 +135,7 @@ class Mussa */ void load_motifs(std::istream &); //! load a list of motifs from a file named filename - void load_motifs(std::string filename); + void load_motifs(boost::filesystem::path filename); //! return our motifs; const std::set& motifs() const; diff --git a/alg/nway_paths.cpp b/alg/nway_paths.cpp index a71bda6..6c2acdf 100644 --- a/alg/nway_paths.cpp +++ b/alg/nway_paths.cpp @@ -12,11 +12,13 @@ // ---------- mussa_nway.cc ----------- // ---------------------------------------- +#include +namespace fs = boost::filesystem; + #include "alg/nway_paths.hpp" #include "alg/conserved_path.hpp" #include "mussa_exceptions.hpp" -#include #include #include @@ -130,12 +132,12 @@ NwayPaths::add_path(ConservedPath loaded_path) void -NwayPaths::save(string save_file_path) +NwayPaths::save(fs::path save_file_path) { - fstream save_file; + fs::fstream save_file; list::iterator path_i, paths_end; - save_file.open(save_file_path.c_str(), ios::out); + save_file.open(save_file_path, ios::out); save_file << " > all_comparisons) void -NwayPaths::save_old(string save_file_path) +NwayPaths::save_old(fs::path save_file_path) { - fstream save_file; + fs::fstream save_file; list::iterator path_i, paths_end; size_t i; - save_file.open(save_file_path.c_str(), ios::app); + save_file.open(save_file_path, ios::app); path_i = pathz.begin(); paths_end = pathz.end(); diff --git a/alg/nway_paths.hpp b/alg/nway_paths.hpp index 1a2b002..01c4be0 100644 --- a/alg/nway_paths.hpp +++ b/alg/nway_paths.hpp @@ -13,6 +13,7 @@ // ---------------------------------------- // ---------- mussa_nway.hh ----------- // ---------------------------------------- +#include #include #include @@ -55,9 +56,9 @@ class NwayPaths void path_search(std::vector > all_comparisons, ConservedPath path, size_t depth); void simple_refine(); - void save(std::string save_file_path); + void save(boost::filesystem::path save_file_path); //! load a muway file, \throws mussa_load_error - void load(std::string load_file_path); + void load(boost::filesystem::path load_file_path); void add_path(int threshold, std::vector& loaded_path); void add_path(ConservedPath loaded_path); //! how many sequences are in our comparison @@ -66,7 +67,7 @@ class NwayPaths void find_paths(std::vector > all_comparisons); void refine(); - void save_old(std::string save_file_path); + void save_old(boost::filesystem::path save_file_path); void print(std::list >&); std::list::iterator pbegin() { return pathz.begin() ; } diff --git a/alg/sequence.cpp b/alg/sequence.cpp index 439fcb9..7e7468b 100644 --- a/alg/sequence.cpp +++ b/alg/sequence.cpp @@ -21,6 +21,7 @@ // ---------------------------------------- // ---------- sequence.cc ----------- // ---------------------------------------- +#include #include "alg/sequence.hpp" #include "mussa_exceptions.hpp" @@ -28,6 +29,7 @@ #include #include +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 diff --git a/alg/sequence.hpp b/alg/sequence.hpp index 85fd692..06dd3fa 100644 --- a/alg/sequence.hpp +++ b/alg/sequence.hpp @@ -14,8 +14,8 @@ // ---------- sequence.hh ----------- // ---------------------------------------- - -#include +#include +#include #include #include #include @@ -83,12 +83,12 @@ class Sequence //! load sequence AGCT from fasta file /*! \throws mussa_load_error */ - void load_fasta(const std::string file_path, int seq_num=1, + void load_fasta(const boost::filesystem::path file_path, int seq_num=1, int start_index=0, int end_index=0); //! load sequence annotations /*! \throws mussa_load_error */ - void load_annot(const std::string file_path, int start_index, int end_index); + void load_annot(const boost::filesystem::path file_path, int start_index, int end_index); const std::list& annotations() const; const std::list& motifs() const; const std::string& get_species() const; @@ -127,7 +127,7 @@ class Sequence /*! \throws motif_normalize_error if there is an invalid symbol */ static std::string motif_normalize(std::string a_motif); - void save(std::fstream &save_file); - void load_museq(std::string load_file_path, int seq_num); + void save(boost::filesystem::fstream &save_file); + void load_museq(boost::filesystem::path load_file_path, int seq_num); }; #endif diff --git a/alg/test/CMakeLists.txt b/alg/test/CMakeLists.txt index ecbd3aa..3e1e43b 100644 --- a/alg/test/CMakeLists.txt +++ b/alg/test/CMakeLists.txt @@ -2,11 +2,18 @@ SET(SOURCES test_annotation_color.cpp test_color.cpp test_conserved_path.cpp test_flp.cpp test_glseqbrowser.cpp test_glsequence.cpp test_main.cpp test_mussa.cpp test_nway.cpp test_sequence.cpp) +# dont you love the number of \ you need to make sure the " shows up in +# the C compiler? +SET(EXAMPLE_DIR ${CMAKE_SOURCE_DIR}/examples) +SET_SOURCE_FILES_PROPERTIES(${SOURCES} + COMPILE_FLAGS "-DEXAMPLE_DIR=\\\"${EXAMPLE_DIR}\\\"" + ) + FIND_PACKAGE(OpenGL) INCLUDE(FindBoost) ADD_EXECUTABLE(unittest ${SOURCES}) -ADD_TEST(core_test ${EXECUTABLE_OUTPUT_PATH}/alg/test/unittest) +ADD_TEST(core_test ${CMAKE_BINARY_DIR}/alg/test/unittest) LINK_DIRECTORIES(${MUSSA_BINARY_DIR}/alg}) TARGET_LINK_LIBRARIES(unittest ${BOOST_UNIT_TEST_LIB} diff --git a/alg/test/test_flp.cpp b/alg/test/test_flp.cpp index c3c9437..cc8500b 100644 --- a/alg/test/test_flp.cpp +++ b/alg/test/test_flp.cpp @@ -4,12 +4,15 @@ #include #include #include +namespace fs = boost::filesystem; #include "alg/flp.hpp" #include "alg/sequence.hpp" #include #include +#include "mussa_exceptions.hpp" + BOOST_AUTO_TEST_CASE( flp_simple ) { FLPs f; @@ -96,3 +99,10 @@ BOOST_AUTO_TEST_CASE( flp_reverse_compliment ) // FIXME: should we test the individual lists? } } + +BOOST_AUTO_TEST_CASE( flp_file_check ) +{ + fs::path filename = "Thy_micturations_are_to_me_as_plurdled_gabbleblotchits"; + FLPs f1; + BOOST_CHECK_THROW( f1.load(filename), mussa_load_error); +} diff --git a/alg/test/test_mussa.cpp b/alg/test/test_mussa.cpp index 852d2fd..04886a0 100644 --- a/alg/test/test_mussa.cpp +++ b/alg/test/test_mussa.cpp @@ -1,4 +1,6 @@ #include +#include +namespace fs = boost::filesystem; #include #include @@ -75,22 +77,21 @@ BOOST_AUTO_TEST_CASE ( empty_mussa_set_threshold ) m.nway(); } -#include BOOST_AUTO_TEST_CASE( mussa_load_mupa ) { + fs::path mupa_path(EXAMPLE_DIR); + mupa_path /= "mck3test.mupa"; + Mussa m1; - chdir( "examples" ); - m1.load_mupa_file( "mck3test.mupa" ); + m1.load_mupa_file( mupa_path ); m1.analyze(0, 0); BOOST_CHECK_EQUAL( m1.get_name(), std::string("mck3test") ); BOOST_CHECK( m1.size() > 0 ); Mussa m2; - std::string saved_analysis_path("mck3test_w30_t20"); - m2.load( saved_analysis_path ); - chdir( ".." ); - - BOOST_CHECK_EQUAL( m2.get_name(), saved_analysis_path ); + fs::path result_path = fs::initial_path() / "mck3test_w30_t20"; + m2.load( result_path ); + BOOST_CHECK_EQUAL( m2.get_name(), result_path.leaf() ); BOOST_CHECK_EQUAL( m1.size(), m2.size() ); } @@ -98,14 +99,8 @@ BOOST_AUTO_TEST_CASE( mussa_load_mupa ) BOOST_AUTO_TEST_CASE( mussa_load_full_path ) { Mussa m1; - chdir( "examples" ); - const int bufsize = 1024; - char path_buf[bufsize]; - getcwd(path_buf, bufsize); - std::string path(path_buf); - chdir( ".." ); - path += "/mck3test.mupa"; - m1.load_mupa_file( path ); + fs::path full_path(fs::path(EXAMPLE_DIR) / "mck3test.mupa"); + m1.load_mupa_file( full_path ); m1.analyze(0, 0); BOOST_CHECK( m1.size() > 0); @@ -115,18 +110,13 @@ BOOST_AUTO_TEST_CASE( mussa_load_full_path ) BOOST_AUTO_TEST_CASE( mussa_load_analysis ) { + fs::path example_dir(EXAMPLE_DIR); Mussa m1; - chdir( "examples" ); - const int bufsize = 1024; - char path_buf[bufsize]; - getcwd(path_buf, bufsize); - std::string base_path(path_buf); - chdir( ".." ); - m1.load_mupa_file( base_path + "/mck3test.mupa" ); + m1.load_mupa_file( example_dir / "mck3test.mupa" ); m1.analyze(0, 0); Mussa m2; - m2.load(base_path + "/mck3test_w30_t20"); + m2.load( example_dir / "mck3test_w30_t20"); BOOST_CHECK_EQUAL( m1.size(), m2.size() ); BOOST_CHECK_EQUAL( m1.get_window(), m2.get_window() ); diff --git a/alg/test/test_nway.cpp b/alg/test/test_nway.cpp index 53508df..49be7e5 100644 --- a/alg/test/test_nway.cpp +++ b/alg/test/test_nway.cpp @@ -1,4 +1,6 @@ #include +#include +namespace fs = boost::filesystem; #include #include @@ -55,11 +57,12 @@ BOOST_AUTO_TEST_CASE( nway_test ) } } -#include BOOST_AUTO_TEST_CASE( nway_refine ) { + fs::path mupa_path( EXAMPLE_DIR ); + mupa_path /= "mck3test.mupa"; Mussa m1; - m1.load_mupa_file( "examples/mck3test.mupa" ); + m1.load_mupa_file( mupa_path ); m1.analyze(0, 0); const NwayPaths& npath = m1.paths(); BOOST_CHECK_EQUAL (npath.path_size(), npath.refined_path_size()); diff --git a/alg/test/test_sequence.cpp b/alg/test/test_sequence.cpp index bbc5068..1a4e9ac 100644 --- a/alg/test/test_sequence.cpp +++ b/alg/test/test_sequence.cpp @@ -1,4 +1,8 @@ #include +#include +#include +namespace fs=boost::filesystem; + #include #include @@ -49,8 +53,10 @@ BOOST_AUTO_TEST_CASE( sequence_filter ) //! Can we load data from a file BOOST_AUTO_TEST_CASE( sequence_load ) { + fs::path seq_path(fs::path(EXAMPLE_DIR)/ "seq" ); + seq_path /= "human_mck_pro.fa"; Sequence s; - s.load_fasta("examples/seq/human_mck_pro.fa"); + s.load_fasta(seq_path); BOOST_CHECK_EQUAL(s.subseq(0, 5), "GGATC"); // first few chars of fasta file BOOST_CHECK_EQUAL(s.get_header(), "gi|180579|gb|M21487.1|HUMCKMM1 Human " "muscle creatine kinase gene (CKMM), " diff --git a/qui/CMakeLists.txt b/qui/CMakeLists.txt index 56d7990..c085ca4 100644 --- a/qui/CMakeLists.txt +++ b/qui/CMakeLists.txt @@ -62,5 +62,6 @@ TARGET_LINK_LIBRARIES(mussagl ${QT_QTOPENGL_LIBRARY} ${OPENGL_gl_LIBRARY} ${BOOST_PROGRAM_OPTIONS_LIB} + ${BOOST_FILESYSTEM_LIB} ) diff --git a/qui/mussagl.cpp b/qui/mussagl.cpp index 656c9a2..28f7bc5 100644 --- a/qui/mussagl.cpp +++ b/qui/mussagl.cpp @@ -1,3 +1,6 @@ +#include +using namespace boost::filesystem; + #include #include "qui/MussaWindow.hpp" @@ -5,6 +8,9 @@ int main(int argc, char **argv) { + // let boost::filesystem store the path we were initially launched in + initial_path(); + QApplication app(argc, argv); Q_INIT_RESOURCE(icons); Mussa *analysis = initialize_mussa(argc, argv);