diff --git a/src/aevol_create.cpp b/src/aevol_create.cpp index ff5f3b98cacd279320aad65f60ea143aefc150d7..638cc002856775dd85b9f5cf5a69f0df27c813e1 100644 --- a/src/aevol_create.cpp +++ b/src/aevol_create.cpp @@ -48,6 +48,7 @@ using namespace aevol; // Helper functions void print_help(char* prog_path); void interpret_cmd_line_options(int argc, char* argv[]); +std::list<std::string> read_sequence_file(const std::string& chromosome_file_name); // Command-line option variables static std::string param_file_name; @@ -65,27 +66,16 @@ int main(int argc, char* argv[]) { // Initialize the experiment manager exp_manager = new ExpManager(); - // Initialize the simulation from the parameter file - std::list<std::string> chromosomes; - + // Initialize the simulation from the parameter file (and the provided sequences if any) if (chromosome_file_name.length() != 0) { - std::ifstream chromosome_file(chromosome_file_name); - if (not chromosome_file) { - Utils::ExitWithUsrMsg(std::string("failed to open source chromosome file ") + chromosome_file_name); - } - - std::string chromosome; - std::getline(chromosome_file, chromosome); - if (not chromosome_file or chromosome.length() == 0) { - Utils::ExitWithUsrMsg(std::string("failed to read from chromosome file ") + chromosome_file_name); - } - chromosomes.push_back(std::move(chromosome)); - + auto chromosomes = read_sequence_file(chromosome_file_name); std::cout << "Loading chromosome from text file " << chromosome_file_name << " (" << chromosomes.front().length() << " base pairs)" << std::endl; + ParamLoader::load(param_values, exp_manager, chromosomes, true); + } + else { + ParamLoader::load(param_values, exp_manager, true); } - - ParamLoader::load(param_values, exp_manager, chromosomes, true); // 8) Save the experiment exp_manager->Save(true); @@ -185,3 +175,23 @@ void interpret_cmd_line_options(int argc, char* argv[]) { param_file_name = DEFAULT_PARAM_FILE_NAME; } } + +std::list<std::string> read_sequence_file(const std::string& chromosome_file_name) { + assert(chromosome_file_name.length() != 0); + + std::list<std::string> chromosomes; + + std::ifstream chromosome_file(chromosome_file_name); + if (not chromosome_file) { + Utils::ExitWithUsrMsg(std::string("failed to open source chromosome file ") + chromosome_file_name); + } + + std::string chromosome; + std::getline(chromosome_file, chromosome); + if (not chromosome_file or chromosome.length() == 0) { + Utils::ExitWithUsrMsg(std::string("failed to read from chromosome file ") + chromosome_file_name); + } + chromosomes.push_back(std::move(chromosome)); + + return chromosomes; +}