string read_sequence_from_file (string filename) { ifstream fileReader (filename.c_str()); if (fileReader == 0) { // couldn't open file throw(stacktrace() + "\n\nCould not open " + filename + "\n"); } string mySequence; char c_line [MAX_LINE_LENGTH]; fileReader.getline(c_line, MAX_LINE_LENGTH); while (! fileReader.eof() ) { if (c_line[0] != '>') { string s_line (c_line); for (unsigned int i = 0; i < strlen(c_line); i++) { char c = tolower(c_line[i]); if (c == ' ' || c == '\t' || c == '\n') { continue;} mySequence += c; } } fileReader.getline(c_line, MAX_LINE_LENGTH); } return (mySequence); }
std::array<ublas::matrix<double>, 3> get_iris(std::string filename){ std::ifstream fs(filename); ASSERT(!fs.bad() && fs.good(), "Failed to open the file."); std::array<ublas::matrix<double>, 3> datas; for (int i = 0; i < 3; ++i){ datas[i] = ublas::matrix<double>(4, 50); for (int j = 0; j < 50; ++j){ char *line = new char[100]; fs.getline(line, 100); std::vector<string> nums; string s_line(line); boost::split(nums, s_line, boost::is_any_of(",")); delete[] line; ASSERT(nums.size() == 5, "Failed to parse the date."); for (int k = 0; k < 4; ++k){ datas[i](k, j) = boost::lexical_cast<double, string>(nums[k]); } } } return datas; }