コード例 #1
0
ファイル: main.cpp プロジェクト: Debian/pbbam
static
bam2sam::Settings fromCommandLine(optparse::OptionParser& parser,
                                    int argc, char* argv[])
{
    bam2sam::Settings settings;

    const optparse::Values options = parser.parse_args(argc, argv);

    // input
    const std::vector<std::string> positionalArgs = parser.args();
    const size_t numPositionalArgs = positionalArgs.size();
    if (numPositionalArgs == 0)
        settings.inputFilename_ = "-"; // stdin
    else if (numPositionalArgs == 1)
        settings.inputFilename_ = parser.args().front();
    else {
        assert(numPositionalArgs > 1);
        settings.errors_.push_back("bam2sam does not support more than one input file per run");
    }

    // header options
    if (options.is_set("no_header"))
        settings.noHeader_ = options.get("no_header");
    if (options.is_set("header_only"))
        settings.printHeaderOnly_ = options.get("header_only");

    if (settings.noHeader_ && settings.printHeaderOnly_)
        settings.errors_.push_back("conflicting arguments requested: --no-header and --header-only");

    return settings;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: Debian/pbbam
static
pbindexdump::Settings fromCommandLine(optparse::OptionParser& parser,
                                      int argc,
                                      char* argv[])
{
    const optparse::Values options = parser.parse_args(argc, argv);
    pbindexdump::Settings settings;

    // input
    const vector<string> positionalArgs = parser.args();
    const size_t numPositionalArgs = positionalArgs.size();
    if (numPositionalArgs == 0)
        settings.inputPbiFilename_ = "-"; // stdin
    else if (numPositionalArgs == 1)
        settings.inputPbiFilename_ = parser.args().front();
    else {
        assert(numPositionalArgs > 1);
        settings.errors_.push_back("pbindexdump does not support more than one input file per run");
    }

    // output format
    if (options.is_set("format"))
        settings.format_ = options["format"];

    // JSON options
    if (settings.format_ == "json") {
        if (options.is_set("json_indent_level"))
            settings.jsonIndentLevel_ = options.get("json_indent_level");
        if (options.is_set("json_raw"))
            settings.jsonRaw_ = options.get("json_raw");
    } else {
        if (options.is_set("json_indent_level") ||
            options.is_set("json_raw"))
        {
            settings.errors_.push_back("JSON formatting options not valid on non-JSON output");
        }
    }

    return settings;
}
コード例 #3
0
ファイル: Settings.cpp プロジェクト: bnbowman/blasr
Settings Settings::FromCommandLine(optparse::OptionParser& parser,
                                   int argc,
                                   char *argv[],
                                   bool forcePulseMode)
{
    Settings settings;

    // general program info
    settings.program = parser.prog();
    settings.description = parser.description();
    settings.version = parser.version();
    for (int i = 1; i < argc; ++i) {
        settings.args.append(argv[i]);
        settings.args.append(" ");
    }

    const optparse::Values options = parser.parse_args(argc, argv);

    // mode
    settings.ignoreQV = options.is_set(Settings::Option::ignoreQV_);

    const bool isBaseMode = 
        options.is_set(Settings::Option::baseMode_) ? options.get(Settings::Option::baseMode_) : false;

    const bool isPulseMode = 
        options.is_set(Settings::Option::pulseMode_) ? options.get(Settings::Option::pulseMode_) : false;

    int modeCount = 0;
    if (isBaseMode)  modeCount++;
    if (isPulseMode) modeCount++;

    if (modeCount == 0)
        settings.mode = Settings::BaseMode;
    else if (modeCount == 1) 
        if (isBaseMode)  
            settings.mode = Settings::BaseMode;
        else 
            settings.mode = Settings::PulseMode;
    else
        settings.errors_.push_back("Unknown modes selected.");

    if (forcePulseMode) settings.mode = Settings::PulseMode;

    // BaseMap
    if (not options[Settings::Option::baseMap_].empty()) {
        settings.baseMap = options[Settings::Option::baseMap_];
        std::transform(settings.baseMap.begin(), settings.baseMap.end(), settings.baseMap.begin(), ::toupper);
        cout << settings.baseMap << endl;
        std::string _baseMap = settings.baseMap;
        std::sort(_baseMap.begin(), _baseMap.end());
        if (_baseMap != "ACGT") { settings.errors_.push_back("Bad basemap."); }
    }

    // input
    settings.inputBamFilenames = parser.args();
    if (settings.inputBamFilenames.size() == 1) {
        settings.polymeraseBamFilename = settings.inputBamFilenames[0];
        if (settings.polymeraseBamFilename.find("polymerase.bam") == std::string::npos)
            settings.errors_.push_back("missing input *.polymerase.bam.");
    } else if (settings.inputBamFilenames.size() == 2) {
        settings.subreadsBamFilename = settings.inputBamFilenames[0];
        settings.scrapsBamFilename   = settings.inputBamFilenames[1];
        if (settings.subreadsBamFilename.find("subreads.bam") == std::string::npos)
            settings.errors_.push_back("missing input *.subreads.bam.");
        if (settings.scrapsBamFilename.find("scraps.bam") == std::string::npos)
            settings.errors_.push_back("missing input *.scraps.bam.");
    } else {
        settings.errors_.push_back("missing input (polymerase.bam or subreads+scraps.bam.");
    }

    // output 
    settings.outputBaxPrefix = options[Settings::Option::output_];
    if (settings.outputBaxPrefix.empty()) { // if output prefix not set.
        if (not settings.subreadsBamFilename.empty()) {
            settings.outputBaxPrefix = internal::GetMovienameFromFilename(settings.subreadsBamFilename);
        } else if (not settings.polymeraseBamFilename.empty()) {
            settings.outputBaxPrefix = internal::GetMovienameFromFilename(settings.polymeraseBamFilename);
        }
    }

    if (settings.mode == Settings::BaseMode) 
        settings.outputBaxFilename = settings.outputBaxPrefix + ".bax.h5";
    else if (settings.mode == Settings::PulseMode)
        settings.outputBaxFilename = settings.outputBaxPrefix + ".plx.h5";
    settings.outputRgnFilename = settings.outputBaxPrefix + ".rgn.h5";

    // movie
    settings.movieName = internal::GetMovienameFromFilename(settings.outputBaxPrefix);

    if (options.is_set(Settings::Option::metadata_)) {
        // metadata.xml will be placed at upper directory of bax.h5
        settings.outputMetadataFilename = internal::DirectoryPath(settings.outputBaxPrefix) + "/../" + 
                                          settings.movieName + ".metadata.xml";
        settings.outputAnalysisDirname = internal::ParentDirectoryName(internal::DirectoryPath(settings.outputBaxPrefix));
    }

#ifdef DEBUG_SETTINGS
    string modeString = "Unknown";
    if (settings.mode == Settings::BaseMode)
        modeString = "base";
    else if (settings.mode == Settings::PulseMode)
        modeString = "pulse";

    cerr << "CommandLine: " << settings.program << " " << settings.args << endl
         << "Description: " << settings.description << endl
         << "Version    : " << settings.version << endl
         << "Mode       : " << modeString << endl
         << "BaseMap    : " << settings.baseMap << endl
         << "Movie name : " << settings.movieName << endl
         << "Input files: " << endl;
    if (not settings.subreadsBamFilename.empty())
         cerr << " subreads  : " << settings.subreadsBamFilename << endl;
    if (not settings.scrapsBamFilename.empty())
         cerr << " scraps    : " << settings.scrapsBamFilename << endl;
    if (not settings.polymeraseBamFilename.empty())
         cerr << " polymerase: " << settings.polymeraseBamFilename << endl;
    cerr << "Output h5  : " << settings.outputBaxFilename << endl
         << "Output xml : " << settings.outputMetadataFilename << endl;

#endif

    return settings;
}