示例#1
0
inline GWAS_Options get_gwas_program_options(int argc, char** argv) {
  GWAS_Options result;
  std::string appName = boost::filesystem::basename(argv[0]);
  po::options_description optDesc("Options");

  try  {
    /** Define and parse the program options
     */
    optDesc.add_options()
        ("help,h", "Print help messages")
        ("chr,c", po::value<int>(&result.chromosome)->default_value(0), "Chromosome. Default: 0")

        ("in_dat,i", po::value<std::string>(&result.inputDataFile)->required(), "Input Data File")
        ("in_lab,l", po::value<std::string>(&result.inputLabelFile)->required(), "Input Label File")
        ("mappingFile,m", po::value<std::string>(&result.mappingFile)->default_value("../example/inputs/snp_mapping.csv"), "SNP-RS Mapping File. Default: ../example/inputs/snp_mapping.csv")

        ("in_pheno,p", po::value<std::string>(&result.inputPheno)->default_value("../example/inputs/phenotype.csv"), "Input Pheno File. Default: ../example/inputs/phenotype.csv")

        ("in_bayes_vertex,v", po::value<std::string>(&result.bayesVertices)->required(), "Input Bayes File")
        ("in_bayes_dist,d", po::value<std::string>(&result.bayesDist)->required(), "Input Dist File")

        ("num_perms,n", po::value<int>(&result.permutations)->default_value(1000), "Nbr Permutations. Default: 1000")
        ("thresholdFile,r", po::value<std::string>(&result.thresholdFile)->default_value("../example/inputs/thresholds.txt"), "Thresholds. Default: ../example/inputs/thresholds.csv")

        ("test,t", po::value<int>(&result.stat_test)->default_value(0), "test: 0 (chi-square)")
        ("sep,s", po::value<char>(&result.separator)->default_value('\t'), "Output file deliminater. Default: 'tab'")
        ("outDir,o", po::value<std::string>(&result.outputDir)->default_value("./out"), "Output Dir. Default: ./out")
        ;

    po::variables_map vm;
    try {
      po::store(po::command_line_parser(argc, argv).options(optDesc).run(), vm); // throws on error
      if (vm.count("help") ) {
        samogwas::OptionPrinter::printStandardAppDesc(appName,std::cout, optDesc, NULL);
        exit(1);
      }
      po::notify(vm);

    }
    catch(boost::program_options::required_option& e) /** missing arguments **/
    {
      samogwas::OptionPrinter::formatRequiredOptionError(e);
      std::cout << e.what() << std::endl << std::endl;
      samogwas::OptionPrinter::printStandardAppDesc( appName,std::cout,
                                                     optDesc, NULL);
      exit(-1);
    }

  }
  catch(std::exception e)
  {
    std::cout << "Unhandled Exception reached the top of main: "
              << e.what() << ", application will now exit" << std::endl;

    samogwas::OptionPrinter::printStandardAppDesc(appName, std::cout, optDesc, NULL);
    exit(-1);
  }

  return result;
}
示例#2
0
inline GWAS_Options getGwasProgramOptions(int argc, char** argv) {
  GWAS_Options result;
  std::string appName = boost::filesystem::basename(argv[0]);
  po::options_description optDesc("Options");

  try  {
    /** Define and parse the program options 
     */
    optDesc.add_options()
        ("help,h", "Print help messages")
        ("chr,c", po::value<int>(&result.chromosome)->default_value(2), "chromosome")

        ("in_dat,i", po::value<std::string>(&result.inputDataFile)->required(), "Input Data File")
        ("in_lab,l", po::value<std::string>(&result.inputLabelFile)->required(), "Input Label File")        

        // ("in_imputed,i", po::value<std::string>(&result.inputDataFile)->required(), "Input Imputed Data File")

        ("in_pheno,p", po::value<std::string>(&result.inputPheno)->required(), "Input Pheno File")
        ("in_graph,g", po::value<std::string>(&result.graphFile)->required(), "Input Graph File")
        ("in_bayes_vertex,v", po::value<std::string>(&result.bayesVertices)->required(), "Input Bayes File")
        ("in_bayes_dist,d", po::value<std::string>(&result.bayesDist)->required(), "Input Dist File")


        ("permutations,n", po::value<int>(&result.permutations)->default_value(1000), "Nbr Permutations")
        ("threshold,t", po::value<double>(&result.threshold)->default_value(.005), "threshold")
        ("mappingFile,m", po::value<std::string>(&result.mappingFile)->required(), "SNP - RS Mapping File")

        ("task,k", po::value<int>(&result.task)->default_value(0), "task. 0: gwas_good_parent,  1: gwas_test")
        ("outDir,o", po::value<std::string>(&result.outputDir)->required(), "Output Dir")

        ;
    po::variables_map vm; 
    try { 
      po::store(po::command_line_parser(argc, argv).options(optDesc).run(), vm); // throws on error
      if (vm.count("help") ) {
        samogwas::OptionPrinter::printStandardAppDesc(appName,std::cout, optDesc, NULL);
        exit(1);
      }
      po::notify(vm);   	    

    } 
    catch(boost::program_options::required_option& e) /** missing arguments **/
    {
      samogwas::OptionPrinter::formatRequiredOptionError(e);
      std::cout << e.what() << std::endl << std::endl;
      samogwas::OptionPrinter::printStandardAppDesc( appName,std::cout,
                                                optDesc, NULL);

      exit(-1);
    }

  }
  catch(std::exception e)    
  {
    std::cout << "Unhandled Exception reached the top of main: "
              << e.what() << ", application will now exit" << std::endl;

    samogwas::OptionPrinter::printStandardAppDesc(appName, std::cout, optDesc, NULL);
    exit(-1);
  }

  return result;
}
int main( int argCount, char *argVec[] )
{

    //declare *default* input file, output file, and length of radial profiles
    std::string inFile;
    std::string outFile;
    const int radialProfileLength = 101;

    //options for command line input are defined here
    po::options_description optDesc("Allowed options");
    optDesc.add_options()
        ("help","produce help message")
        ("in",po::value<std::string>(&inFile)->default_value("analytic.yaml"), "input file name")
        ("out",po::value<std::string>(&outFile)->default_value("gtcInputEq.h5"), "output file name")
    ;
    po::variables_map varMap;
    po::store(po::parse_command_line(argCount, argVec, optDesc), varMap);
    po::notify(varMap);
    
    if (varMap.count("help")) {
        std::cout << optDesc << "\n";
        return 1;
    }



   //declare YAML nodes to work with input file
    YAML::Node magEq;
    YAML::Node oneDim;
    YAML::Node twoDim;

    //declare variables to hold and manipulate intermediate data
    int i; //loop index
    double psi[radialProfileLength] = {0.0};
    double dat[radialProfileLength] = {0.0};

    //declare vars to manipulate HDF5 output file
    H5::H5File outfile( outFile, H5F_ACC_TRUNC );
    hsize_t dim[1] = { (unsigned int)radialProfileLength };
    H5::DataSpace datspace1D( 1, dim );
    H5::IntType dattype( H5::PredType::NATIVE_DOUBLE );
    H5::DataSet datset; 

    //read in the YAML eq file
    magEq = YAML::LoadFile( inFile );

    //generate radial coords
    for ( i=0; i<radialProfileLength; i++ )
        psi[i] = i/(radialProfileLength - 1.0);

    //do some parsing
    //first check for 1D and 2D data in the eq file
    //if the exist, generate profiles from polynomial coefficients
    if(magEq["1D profiles"]){
        oneDim = magEq["1D profiles"];
        for(YAML::const_iterator iter=oneDim.begin(); iter!=oneDim.end(); ++iter){
            for( i=0; i<radialProfileLength; i++)
                dat[i] = iter->second[0].as<double>() 
                        + iter->second[1].as<double>()*psi[i] 
                        + iter->second[2].as<double>()*psi[i]*psi[i];
            datset = outfile.createDataSet( iter->first.as<std::string>(), dattype, datspace1D );
            datset.write( dat, H5::PredType::NATIVE_DOUBLE );
        }
    }
    if(magEq["2d profiles"]){
        twoDim = magEq["2D profiles"];
        // do some more parsing if we need this part...
    }

    return 0;
}
示例#4
0
int
main(int argc, char* argv[])
{
  Options options;
  options.freshnessPeriod = getMinimumFreshnessPeriod();
  options.shouldLimitSatisfied = false;
  options.nMaxPings = 0;
  options.shouldPrintTimestamp = false;
  options.payloadSize = 0;

  namespace po = boost::program_options;

  po::options_description visibleOptDesc("Allowed options");
  visibleOptDesc.add_options()
    ("help,h", "print this message and exit")
    ("version,V", "display version and exit")
    ("freshness,x", po::value<int>(),
                   ("set freshness period in milliseconds (minimum " +
                   std::to_string(getMinimumFreshnessPeriod().count()) + " ms)").c_str())
    ("satisfy,p", po::value<int>(&options.nMaxPings), "set maximum number of pings to be satisfied")
    ("timestamp,t", "log timestamp with responses")
    ("size,s", po::value<int>(&options.payloadSize), "specify size of response payload")
  ;
  po::options_description hiddenOptDesc("Hidden options");
  hiddenOptDesc.add_options()
    ("prefix", po::value<std::string>(), "prefix to register")
  ;

  po::options_description optDesc("Allowed options");
  optDesc.add(visibleOptDesc).add(hiddenOptDesc);

  try {
    po::positional_options_description optPos;
    optPos.add("prefix", -1);

    po::variables_map optVm;
    po::store(po::command_line_parser(argc, argv).options(optDesc).positional(optPos).run(), optVm);
    po::notify(optVm);

    if (optVm.count("help") > 0) {
      usage(visibleOptDesc);
    }

    if (optVm.count("version") > 0) {
      std::cout << "ndnpingserver " << tools::VERSION << std::endl;
      exit(0);
    }

    if (optVm.count("prefix") > 0) {
      options.prefix = Name(optVm["prefix"].as<std::string>());
    }
    else {
      std::cerr << "ERROR: No prefix specified" << std::endl;
      usage(visibleOptDesc);
    }

    if (optVm.count("freshness") > 0) {
      options.freshnessPeriod = time::milliseconds(optVm["freshness"].as<int>());

      if (options.freshnessPeriod.count() < getMinimumFreshnessPeriod().count()) {
        std::cerr << "ERROR: Specified FreshnessPeriod is less than the minimum "
                  << getMinimumFreshnessPeriod() << std::endl;
        usage(visibleOptDesc);
      }
    }

    if (optVm.count("satisfy") > 0) {
      options.shouldLimitSatisfied = true;

      if (options.nMaxPings < 1) {
        std::cerr << "ERROR: Maximum number of pings to satisfy must be greater than 0" << std::endl;
        usage(visibleOptDesc);
      }
    }

    if (optVm.count("timestamp") > 0) {
      options.shouldPrintTimestamp = true;
    }

    if (optVm.count("size") > 0) {
      if (options.payloadSize < 0) {
        std::cerr << "ERROR: Payload size must be greater than or equal to 0" << std::endl;
        usage(visibleOptDesc);
      }
    }
  }
  catch (const po::error& e) {
    std::cerr << "ERROR: " << e.what() << std::endl;
    usage(visibleOptDesc);
  }

  std::cout << "PING SERVER " << options.prefix << std::endl;
  return Runner(options).run();
}