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; }
virtual int init( int argc, const char *argv[] ) { optparse::Values &values = parser.parse_args(argc, argv); auto args = parser.args(); for(size_t i=1; i<args.size(); ++i) { loadKeyList(rootHashes, args[i].c_str()); } if(0==rootHashes.size()) { const char *addr = "1dice8EMZmqKvrGE4Qc9bUFf9PX3xaYDp"; warning("no addresses specified, using satoshi's dice address %s", addr); loadKeyList(rootHashes, addr); } addrMap.setEmptyKey(gEmptyKey); addrMap.resize(15 * 1000 * 1000); allAddrs.reserve(15 * 1000 * 1000); info("Building address equivalence graph ..."); startTime = usecs(); return 0; }
virtual int init( int argc, const char *argv[] ) { nbDumped = 0; isDone = false; optparse::Values &values = parser.parse_args(argc, argv); auto args = parser.args(); for(size_t i=1; i<args.size(); ++i) { loadHash256List(rootHashes, args[i].c_str()); } if(0<rootHashes.size()) { info("dumping %d transactions\n", (int)rootHashes.size()); } else { const char *defaultTX = "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d"; // Expensive pizza warning("no TX hashes specified, using the famous 10K pizza TX"); loadHash256List(rootHashes, defaultTX); } static uint8_t empty[kSHA256ByteSize] = { 0x42 }; txMap.setEmptyKey(empty); for(auto const &txHash : rootHashes) { txMap[txHash.v] = 1; } return 0; }
virtual int init( int argc, const char *argv[] ) { optparse::Values &values = parser.parse_args(argc, argv); auto args = parser.args(); for(size_t i=1; i<args.size(); ++i) { loadKeyList(rootHashes, args[i].c_str()); } if(0==rootHashes.size()) { const char *addr = getInterestingAddr(); loadKeyList(rootHashes, addr); } addrMap.setEmptyKey(gEmptyKey); addrMap.resize(15 * 1000 * 1000); allAddrs.reserve(15 * 1000 * 1000); info("Building address equivalence graph ..."); startTime = usecs(); return 0; }
virtual int init( int argc, const char *argv[] ) { optparse::Values &values = parser.parse_args(argc, argv); bool longHelp = values.get("long"); longHelp = longHelp || ( argv[1] && 'm'==argv[1][0] && 'a'==argv[1][1] && 'n'==argv[1][2] ); longHelp = longHelp || ( argv[1] && 'd'==argv[1][0] && 'o'==argv[1][1] && 'c'==argv[1][2] ); auto args = parser.args(); if(1<args.size()) { for(size_t i=1; i<args.size(); ++i) { // O(N^2), but short lists auto arg = args[i]; Callback::showHelpFor( arg.c_str(), longHelp ); } } else { printf("\n"); printf("General Usage: parser <command> <options> <command arguments>\n"); printf("\n"); printf(" Where <command> can be any of:\n"); Callback::find("", true); printf("\n"); printf(" NOTE: use \"parser help <command>\" or \"parser <command> --help\" to get detailed\n"); printf(" help for a specific command.\n"); printf("\n"); printf(" NOTE: <command> may have multiple aliases and can also be abbreviated. For\n"); printf(" example, \"parser tx\", \"parser tr\", and \"parser transactions\" are equivalent.\n"); printf("\n"); printf(" NOTE: whenever specifying a list of things (e.g. a list of addresses), you can\n"); printf(" instead enter \"file:list.txt\" and the list will be read from the file.\n"); printf("\n"); printf(" NOTE: whenever specifying a list file, you can use \"file:-\" and blockparser\n"); printf(" will read the list directly from stdin.\n"); printf("\n"); printf("\n"); if(longHelp) { printf("Every available command and its specific usage follows:\n"); printf("\n"); Callback::showAllHelps(false); } } return 0; }
virtual int init( int argc, const char *argv[] ) { offset = 0; curBlock = 0; lastBlock = 0; firstBlock = 0; addrMap.setEmptyKey(emptyKey); addrMap.resize(15 * 1000 * 1000); allAddrs.reserve(15 * 1000 * 1000); optparse::Values &values = parser.parse_args(argc, argv); cutoffBlock = values.get("atBlock"); showAddr = values.get("withAddr"); detailed = values.get("detailed"); limit = values.get("limit"); auto args = parser.args(); for(size_t i=1; i<args.size(); ++i) { loadKeyList(restricts, args[i].c_str()); } if(0<=cutoffBlock) { info("only taking into account transactions before block %" PRIu64 "\n", cutoffBlock); } if(0!=restricts.size()) { info( "restricting output to %" PRIu64 " addresses ...\n", (uint64_t)restricts.size() ); auto e = restricts.end(); auto i = restricts.begin(); restrictMap.setEmptyKey(emptyKey); while(e!=i) { const uint160_t &h = *(i++); restrictMap[h.v] = 1; } } else { if(detailed) { warning("asking for --detailed for *all* addresses in the blockchain will be *very* slow"); warning("as a matter of fact, it likely won't ever finish unless you have *lots* of RAM"); } } info("analyzing blockchain ..."); return 0; }
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; }
static pbindex::Settings fromCommandLine(optparse::OptionParser& parser, int argc, char* argv[]) { const optparse::Values options = parser.parse_args(argc, argv); (void)options; pbindex::Settings settings; // get input filename const vector<string> positionalArgs = parser.args(); const size_t numPositionalArgs = positionalArgs.size(); if (numPositionalArgs == 0) settings.errors_.push_back("pbindex requires an input BAM filename"); else if (numPositionalArgs == 1) settings.inputBamFilename_ = parser.args().front(); else { assert(numPositionalArgs > 1); settings.errors_.push_back("pbindex does not support more than one input file per run"); } return settings; }
virtual int init( int argc, const char *argv[] ) { nbDumped = 0; optparse::Values &values = parser.parse_args(argc, argv); auto args = parser.args(); for(size_t i=1; i<args.size(); ++i) { loadHash256List(rootHashes, args[i].c_str()); } if(0<rootHashes.size()) { info("dumping %d transactions\n", (int)rootHashes.size()); } else { #if defined(PEERCOIN) const char *defaultTX = "19093c85669bf82c9baa70eb437e2f319409f40b54b2c5ebc4dd334ab610fbe6"; warning("no TX hashes specified, using a random proof of stake peercoin transaction"); #else const char *defaultTX = "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d"; // Expensive pizza warning("no TX hashes specified, using the infamous 10K pizza TX"); #endif loadHash256List(rootHashes, defaultTX); } static uint8_t empty[kSHA256ByteSize] = { 0x42 }; txMap.setEmptyKey(empty); for(auto it = rootHashes.begin(); it != rootHashes.end(); it++) { auto const &txHash = *it; txMap[txHash.v] = 1; } //for(auto const &txHash : rootHashes) { // txMap[txHash.v] = 1; //} return 0; }
virtual int init( int argc, const char *argv[] ) { threshold = 1e-20; optparse::Values &values = parser.parse_args(argc, argv); auto args = parser.args(); for(size_t i=1; i<args.size(); ++i) { loadHash256List(rootHashes, args[i].c_str()); } if(0<rootHashes.size()) { info("computing taint from %d source transactions\n", (int)rootHashes.size()); } else { warning("no TX hashes specified, using the infamous 10K pizza TX"); //const char *defaultTX = "34b84108a142ad7b6c36f0f3549a3e83dcdbb60e0ba0df96cd48f852da0b1acb"; // Linode slush hack const char *defaultTX = "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d"; // Expensive pizza loadHash256List(rootHashes, defaultTX); } static uint8_t empty[kSHA256ByteSize] = { 0x42 }; static unsigned int sz = 15 * 1000 * 1000; srcTxMap.setEmptyKey(empty); taintMap.setEmptyKey(empty); taintMap.resize(sz); auto i = rootHashes.begin(); auto e = rootHashes.end(); while(e!=i) { const uint256_t &txHash = *(i++); taintMap[txHash.v] = 1.0; srcTxMap[txHash.v] = 1; } return 0; }
virtual int init( int argc, const char *argv[] ) { sum = 0; adds = 0; subs = 0; nbTX = 0; optparse::Values &values = parser.parse_args(argc, argv); csv = values.get("csv"); auto args = parser.args(); for(size_t i=1; i<args.size(); ++i) { loadKeyList(rootHashes, args[i].c_str()); } if(0==rootHashes.size()) { #if defined(LITECOIN) const char *addr = "LKvTVnkK2rAkJXfgPdkaDRgvEGvazxWS9o"; warning("no addresses specified, using popular address %s", addr); #else const char *addr = "1dice8EMZmqKvrGE4Qc9bUFf9PX3xaYDp"; warning("no addresses specified, using satoshi's dice address %s", addr); #endif loadKeyList(rootHashes, addr); } auto e = rootHashes.end(); auto i = rootHashes.begin(); addrMap.setEmptyKey(emptyKey); while(e!=i) { const uint160_t &h = *(i++); addrMap[h.v] = 1; } return 0; }
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; }