- getline(para_file,file_data_line);
- split_index = file_data_line.find(" ");
- param = file_data_line.substr(0,split_index);
- value = file_data_line.substr(split_index+1);
-
- while (!para_file.eof())
- {
- did_seq = false;
- if (param == "ANA_NAME")
- analysis_name = value;
- else if (param == "APPEND_WIN")
- win_append = true;
- else if (param == "APPEND_THRES")
- thres_append = true;
- else if (param == "SEQUENCE_NUM")
- ; // ignore sequence_num now
- else if (param == "WINDOW")
- window = atoi(value.c_str());
- else if (param == "THRESHOLD")
- threshold = atoi(value.c_str());
- else if (param == "SEQUENCE")
- {
- fs::path seq_file = file_path_base / value;
- //cout << "seq_file_name " << seq_files.back() << endl;
- fasta_index = 1;
- annot_file = "";
- sub_seq_start = 0;
- sub_seq_end = 0;
- seq_params = true;
-
- while ((!para_file.eof()) && seq_params)
- {
- getline(para_file,file_data_line);
- split_index = file_data_line.find(" ");
- param = file_data_line.substr(0,split_index);
- value = file_data_line.substr(split_index+1);
-
- if (param == "FASTA_INDEX")
- fasta_index = atoi(value.c_str());
- else if (param == "ANNOTATION")
- annot_file = file_path_base / value;
- else if (param == "SEQ_START")
- sub_seq_start = atoi(value.c_str());
- else if (param == "SEQ_END")
- {
- sub_seq_end = atoi(value.c_str());
- }
- //ignore empty lines or that start with '#'
- else if ((param == "") || (param == "#")) {}
- else seq_params = false;
- }
+ multiplatform_getline(para_file, line);
+ // strip leading/trailing whitespace
+ boost::trim(line);
+ // ignore commented out or blank lines
+ if ( line.size() == 0 or line[0] == '#' ) {
+ continue;
+ }
+
+ // split the line on white spance
+ boost::split(tokens, line, boost::is_space());
+ // do we have a name/value pair?
+ if (tokens.size() != 2) {
+ std::stringstream errmsg;
+ errmsg << "Error parsing MUPA file line: "
+ << line_count << std::endl
+ << line;
+ throw mussa_load_error(errmsg.str());
+ }
+
+ boost::to_upper(tokens[0]);
+ // Parameters only useful after a sequence block
+ if (parsing_state == INSEQUENCE) {
+ // in the following if blocks, if we do
+ // successfully match a token we should continue
+ // on to the next token
+ // but if we don't match a token we want to
+ // fall through to the top level parsing
+
+ if (tokens[0] == "FASTA_INDEX") {
+ fasta_index = atoi(tokens[1].c_str());
+ continue;
+ } else if (tokens[0] == "ANNOTATION") {
+ annot_file = file_path_base / tokens[1];
+ continue;
+ } else if (tokens[0] == "SEQ_START") {
+ sub_seq_start = atoi(tokens[1].c_str());
+ continue;
+ } else if (tokens[0] == "SEQ_END") {
+ sub_seq_end = atoi(tokens[1].c_str());
+ continue;
+ } else {
+ // any other token means we're done with this
+ // sequence so we should load it
+ // (and let the "unknown" token fall through into the
+ // top level token parser)