Exemple #1
0
int DataLoader::loadPhenotype(const std::string& pheno,
                              const std::string& mpheno,
                              const std::string& phenoName) {
  this->FLAG_pheno = pheno;
  this->FLAG_mpheno = mpheno;
  this->FLAG_phenoName = phenoName;
  // this->FLAG_imputePheno = imputePheno;

  std::map<std::string, double> phenotype;
  std::string label;

  if (FLAG_pheno.empty()) {
    logger->error("Cannot do association when phenotype is missing!");
    return -1;
  }

  // check if alternative phenotype columns are used
  if (!FLAG_mpheno.empty() && !FLAG_phenoName.empty()) {
    logger->error("Please specify either --mpheno or --pheno-name");
    return -1;
  }
  if (!FLAG_mpheno.empty()) {
    label = "P" + toString(FLAG_mpheno);
    int col = atoi(FLAG_mpheno);
    int ret = loadPedPhenotypeByColumn(FLAG_pheno.c_str(), &phenotype, col);
    if (ret < 0) {
      logger->error("Loading phenotype failed!");
      return -1;
    }
  } else if (!FLAG_phenoName.empty()) {
    label = FLAG_phenoName;
    int ret = loadPedPhenotypeByHeader(FLAG_pheno.c_str(), &phenotype,
                                       FLAG_phenoName.c_str());
    if (ret < 0) {
      logger->error("Loading phenotype failed!");
      return -1;
    }
  } else {
    label = "P1";
    int col = 1;  // default use the first phenotype
    int ret = loadPedPhenotypeByColumn(FLAG_pheno.c_str(), &phenotype, col);
    if (ret < 0) {
      logger->error("Loading phenotype failed!");
      return -1;
    }
  }

  std::vector<std::string> keys;
  std::vector<double> vals;
  extractMap(phenotype, &keys, &vals);
  this->phenotype.appendCol(vals, label);
  this->phenotype.setRowName(keys);

  logger->info("Loaded [ %zu ] sample pheontypes", phenotype.size());
  return 0;
}
int main(int argc, char** argv)
{
	mq::MapSite::StrVec args(argv + 1, argv + argc);	// "+ 1" to skip first arg. It's the name of the program

	if(args.size() < 1)
	{
		std::cout << "[ERROR]: Not enough arguments. Type at least something to search for after the exe name.\n";
		return 3;
	}

	std::string searchStr = args[0];

	for(auto i = 1u; i < args.size(); i++)
		searchStr.append(" " + args[i]);

	mq::BattlezoneOneCom bz1server;

	if(!bz1server.isServerGood())
	{
		std::cout << "[ERROR]: Cannot contact server. Exiting.\n";
		return 1;
	}

	mq::MapSite::StrMap results = bz1server.getMaps(searchStr);

	if(results.empty())
	{
		std::cout << "No results found for \"" << searchStr << "\"!\n";
		return 0;
	}

	for(auto it = results.begin(); it != results.end(); it++)
	{
		std::cout << std::distance(results.begin(), it) << ") " << it->first << " : " << it->second << '\n';
	}

	bool badInput = true;
	std::string input;
	std::vector<unsigned int> choices(1);

	while(badInput)
	{
		std::cout << "\nEnter the number(s) of the map to download (\"-1\" to cancel): ";
		std::getline(std::cin, input);

		if(input == "-1")
			return 0;

		std::stringstream ss(input);

		badInput = false;
		try
		{
			while(ss >> choices.back())
				choices.emplace_back();

			choices.erase(--choices.end());	// get rid of extra item

			for(auto& c : choices)
				if(c >= results.size())
					throw 0;
		}
		catch(...)
		{
			badInput = true;
			choices.resize(1);
			std::cout << "[ERROR]: Bad input. Try again!\n";
		}
	}

	std::string installLocation = getBZinstallDir();

	if(installLocation.empty())
		installLocation = getExePath();

	installLocation += "addon/";

	for(auto& c : choices)
	{
		auto choiceIter = std::next(results.begin(), c);

		std::string resFileName = bz1server.downloadMap(choiceIter->second, installLocation);

		if(resFileName.empty())
		{
			std::cout << "[ERROR]: Download failed for \"" << choiceIter->first << "\". Exiting.\n";
			return 2;
		}

		extractMap(resFileName);
	}

	return 0;
}