예제 #1
0
void
parseChromDepthOptions(
    const illumina::Program& prog,
    int argc, char* argv[],
    ChromDepthOptions& opt)
{
    namespace po = boost::program_options;
    po::options_description req("configuration");
    req.add_options()
    ("align-file", po::value(&opt.alignmentFilename),
     "alignment file in BAM or CRAM format")
    ("chrom", po::value<chroms_t>(),
     "chromosome name. May be supplied more than once. At least one entry required.")
    ("output-file", po::value(&opt.outputFilename),
     "write stats to filename (default: stdout)")
    ("ref", po::value(&opt.referenceFilename),
     "fasta reference sequence (required)")
    ;

    po::options_description help("help");
    help.add_options()
    ("help,h","print this message");

    po::options_description visible("options");
    visible.add(req).add(help);

    bool po_parse_fail(false);
    po::variables_map vm;
    try
    {
        po::store(po::parse_command_line(argc, argv, visible,
                                         po::command_line_style::unix_style ^ po::command_line_style::allow_short), vm);
        po::notify(vm);
    }
    catch (const boost::program_options::error& e)     // todo:: find out what is the more specific exception class thrown by program options
    {
        log_os << "\nERROR: Exception thrown by option parser: " << e.what() << "\n";
        po_parse_fail=true;
    }

    if ((argc<=1) || (vm.count("help")) || po_parse_fail)
    {
        usage(log_os,prog,visible);
        log_os << "\n" << prog.name() << ": get chromosome depth from alignment file\n\n";
        log_os << "version: " << prog.version() << "\n\n";
        log_os << "usage: " << prog.name() << " [options] > stats\n\n";
        log_os << visible << "\n";
        exit(EXIT_FAILURE);
    }

    std::string errorMsg;
    if (parseOptions(vm, opt, errorMsg))
    {
        usage(log_os, prog, visible, errorMsg.c_str());
    }
}
예제 #2
0
void
usage(
    std::ostream& os,
    const illumina::Program& prog,
    const boost::program_options::options_description& visible,
    const char* desc,
    const char* afteropts,
    const char* msg)
{
    os << "\n" << prog.name() << ": " << desc << "\n\n";
    os << "version: " << prog.version() << "\n";
    os << "compiler: " << prog.compiler() << "\n";
    os << "build-time: " << prog.buildTime() << "\n\n";
    os << "usage: " << prog.name() << " [options]" << afteropts << "\n\n";
    os << visible << "\n\n";

    if (nullptr != msg)
    {
        os << msg << "\n\n";
    }
    exit(2);
}