Beispiel #1
0
void BayesGraphLoad::set_data( Graph& graph,
                               const std::string cndFileName,
                               const std::string dataVecFileName ) const {

  std::ifstream obsFile(dataVecFileName.c_str());
  assert(obsFile); // todo: throws instead
  samogwas::CSVIterator<int> obsLine(obsFile);
  size_t index = 0;
  for( ; obsLine != samogwas::CSVIterator<int>(); ++obsLine ) {
    auto row = std::make_shared<Vec>(obsLine->size(), 0);
    for (unsigned i = 0; i < obsLine->size(); ++i) {
      (*row)[i] = obsLine->at(i);
    }
    graph[index++].set_data_vec(row, true);
  }
  obsFile.close();

  std::ifstream cndFile(cndFileName.c_str());
  if (cndFile) {
    samogwas::CSVIterator<double> cndLine(cndFile);
    for( ; cndLine != samogwas::CSVIterator<double>(); ++cndLine ) {
      auto row = std::make_shared<RealVec>(cndLine->size(), 0);
      for (unsigned i = 0; i < cndLine->size(); ++i) {
        (*row)[i] = cndLine->at(i);
      }
      graph[index++].set_cnd_obs_vec(row, false);
    }
    cndFile.close();
  }

}
void Observation::loadObservations(string filename){

	cout << "load Observations start\n";

	string obsFilename = filename + ".input";
	ifstream obsFile(obsFilename.c_str());

	char * buffer = new char[2];
	vector <unsigned int>* currentSeq = new vector<unsigned int>();
	sequences.push_back(currentSeq);

	char peek = obsFile.peek();

	while (!obsFile.eof()){

		while (peek != '\n' && !obsFile.eof()){

			if (isWhiteSpace(peek)){
				if (peek != '\n'){
					obsFile.read(buffer, 1); // consume whitespace
				}
			}

			else{
				string s;
				obsFile >> s;
				int i = mapObsToInt(s);
				currentSeq->push_back(i);
				//cout << t << " " << i << "\n";


			}

			peek = obsFile.peek();
		}

		int size = currentSeq->size();

		obsFile.read(buffer, 1); // consume newline
		peek = obsFile.peek();

		if (!obsFile.eof()){
			currentSeq = new vector<unsigned int>();
			sequences.push_back(currentSeq);
		}


	}

	obsFile.close();

	cout << "load Observations end\n";
}