int main(int argc, const char **argv) { int force = 0; int num = 0; const char *path = NULL; struct argparse_option options[] = { OPT_HELP(), OPT_BOOLEAN('f', "force", &force, "force to do", NULL), OPT_STRING('p', "path", &path, "path to read", NULL), OPT_INTEGER('n', "num", &num, "selected num", NULL), OPT_END(), }; struct argparse argparse; argparse_init(&argparse, options, usage, 0); argc = argparse_parse(&argparse, argc, argv); if (force != 0) printf("force: %d\n", force); if (path != NULL) printf("path: %s\n", path); if (num != 0) printf("num: %d\n", num); if (argc != 0) { printf("argc: %d\n", argc); int i; for (i = 0; i < argc; i++) { printf("argv[%d]: %s\n", i, *(argv + i)); } } return 0; }
int main(int argc, const char *argv[]) { int RetVal; dbg_logger_stdout(); #if defined(CONF_FAMILY_UNIX) signal(SIGINT, ExitFunc); signal(SIGTERM, ExitFunc); signal(SIGQUIT, ExitFunc); signal(SIGHUP, ReloadFunc); #endif char aUsage[128]; CConfig Config; str_format(aUsage, sizeof(aUsage), "%s [options]", argv[0]); const char *pConfigFile = 0; const char *pWebDir = 0; const char *pBindAddr = 0; struct argparse_option aOptions[] = { OPT_HELP(), OPT_BOOLEAN('v', "verbose", &Config.m_Verbose, "Verbose output", 0), OPT_STRING('c', "config", &pConfigFile, "Config file to use", 0), OPT_STRING('d', "web-dir", &pWebDir, "Location of the web directory", 0), OPT_STRING('b', "bind", &pBindAddr, "Bind to address", 0), OPT_INTEGER('p', "port", &Config.m_Port, "Listen on port", 0), OPT_END(), }; struct argparse Argparse; argparse_init(&Argparse, aOptions, aUsage, 0); argc = argparse_parse(&Argparse, argc, argv); if(pConfigFile) str_copy(Config.m_aConfigFile, pConfigFile, sizeof(Config.m_aConfigFile)); if(pWebDir) str_copy(Config.m_aWebDir, pWebDir, sizeof(Config.m_aWebDir)); if(pBindAddr) str_copy(Config.m_aBindAddr, pBindAddr, sizeof(Config.m_aBindAddr)); if(Config.m_aWebDir[strlen(Config.m_aWebDir)-1] != '/') str_append(Config.m_aWebDir, "/", sizeof(Config.m_aWebDir)); if(!fs_is_dir(Config.m_aWebDir)) { dbg_msg("main", "ERROR: Can't find web directory: %s", Config.m_aWebDir); return 1; } char aTmp[1024]; str_format(aTmp, sizeof(aTmp), "%s%s", Config.m_aWebDir, Config.m_aJSONFile); str_copy(Config.m_aJSONFile, aTmp, sizeof(Config.m_aJSONFile)); CMain Main(Config); RetVal = Main.Run(); return RetVal; }
/* * This application substitues in the DNA sequence the outside ACGT chars by random ACGT symbols. */ int main(int argc, char *argv[]){ uint32_t streamSize, index, seed = 0; uint8_t value; char *bases = "ACGT"; BUF *Buffer; srand(seed); char *programName = argv[0]; struct argparse_option options[] = { OPT_HELP(), OPT_GROUP("Basic options"), OPT_BUFF('<', "input.seq", "Input sequence file (stdin)"), OPT_BUFF('>', "output.seq", "Output sequence file (stdout)"), OPT_END(), }; struct argparse argparse; char usage[250] = "\nExample: "; strcat(usage, programName); strcat(usage, " < input.seq > output.seq\n"); argparse_init(&argparse, options, NULL, programName, 0); argparse_describe(&argparse, "\nIt substitues in the DNA sequence the outside " "ACGT chars by random ACGT symbols.\nIt works in sequence file formats\n", usage); argc = argparse_parse(&argparse, argc, argv); if(argc != 0) argparse_help_cb(&argparse, options); Buffer = CreateBuffer(BUF_SIZE); while((streamSize = fread(Buffer->buf, 1, Buffer->size, stdin))) for(index = 0 ; index < streamSize ; ++index) { value = Buffer->buf[index]; if(value == '\n') continue; RandIfExtra(value, bases); } RemoveBuffer(Buffer); return EXIT_SUCCESS; }
/************************************************************************ * * mcell_argparse parses the commandline and sets the * corresponding parts of the state (seed #, logging, ...) * ************************************************************************/ int mcell_argparse(int argc, char **argv, MCELL_STATE *state) { return argparse_init(argc, argv, state); }
/* * This application substitues in the FASTQ files, the DNA sequence the outside ACGT chars by random ACGT symbols. */ int main(int argc, char *argv[]) { uint32_t streamSize, index, seed = 0; uint8_t value, line = 0; char *bases = "ACGT"; PARSER *Parser = CreateParser(); BUF *Buffer; srand(seed); char *programName = argv[0]; struct argparse_option options[] = { OPT_HELP(), OPT_GROUP("Basic options"), OPT_BUFF('<', "input.fastq", "Input FASTQ file format (stdin)"), OPT_BUFF('>', "output.fastq", "Output FASTQ file format (stdout)"), OPT_END(), }; struct argparse argparse; char usage[250] = "\nExample: "; strcat(usage, programName); strcat(usage, " < input.fastq > output.fastq\n"); argparse_init(&argparse, options, NULL, programName, 0); argparse_describe(&argparse, "\nIt substitues in the FASTQ files, the DNA sequence the outside ACGT chars by random ACGT symbols.", usage); argc = argparse_parse(&argparse, argc, argv); if(argc != 0) argparse_help_cb(&argparse, options); FileType(Parser, stdin); if(Parser->type != 2) { fprintf(stderr, "ERROR: This is not a FASTQ file!\n"); exit(1); } Buffer = CreateBuffer(BUF_SIZE); while((streamSize = fread(Buffer->buf, 1, Buffer->size, stdin))) for(index = 0 ; index < streamSize ; ++index) { value = Buffer->buf[index]; switch(line) { case 0: putchar(value); if(value == '\n') line = 1; break; case 1: if(value == '\n') { putchar('\n'); line = 2; break; } RandIfExtra(value, bases); break; case 2: putchar(value); if(value == '\n') line = 3; break; case 3: putchar(value); if(value == '\n') line = 0; break; } } RemoveBuffer(Buffer); return EXIT_SUCCESS; }
/* * This application filters the FASTQ reads with the length higher than the value defined */ int main(int argc, char *argv[]) { Read *Read = CreateRead(65536+GUARD, 65535+GUARD); uint32_t sequenceSize = 0, index; uint64_t okReads = 0, totalReads = 0; int min_read_size = 0; char *programName = argv[0]; struct argparse_option options[] = { OPT_HELP(), OPT_GROUP("Basic options"), OPT_INTEGER('s', "size", &min_read_size, "The maximum read length"), OPT_BUFF('<', "input.fastq", "Input FASTQ file format (stdin)"), OPT_BUFF('>', "output", "Output read information (stdout)"), OPT_END(), }; struct argparse argparse; char usage[250] = "\nExample: "; strcat(usage, programName); strcat(usage, " < input.fastq > output\n" "\nOutput example :\n" "<FASTQ non-filtered reads>\n" "Total reads : value\n" "Filtered reads : value\n"); argparse_init(&argparse, options, NULL, programName, 0); argparse_describe(&argparse, "\nIt filters the FASTQ reads with the length higher than the value defined. " "If present, it will erase the second header (after +).", usage); argc = argparse_parse(&argparse, argc, argv); if(argc != 0) argparse_help_cb(&argparse, options); if(min_read_size <= 0 || min_read_size > UINT_MAX) { fprintf(stderr, "\nERROR: The size value most be a positive unsigned int!\n"); argparse_help_cb(&argparse, options); exit(1); } while(GetRead(stdin, Read)) { sequenceSize = strlen((char *) Read->bases) - 1; ++totalReads; // Evaluate to discard if(sequenceSize > min_read_size) continue; // Print the read fprintf(stdout, "@"); for(index = 0 ; index < strlen((char *) Read->header1) ; ++index) fprintf(stdout, "%c", Read->header1[index]); for(index = 0 ; index < sequenceSize ; ++index) fprintf(stdout, "%c", Read->bases[index]); fprintf(stdout, "\n+\n"); for(index = 0 ; index < sequenceSize ; ++index) fprintf(stdout, "%c", Read->scores[index]); fprintf(stdout, "\n"); ++okReads; } fprintf(stderr, "Total reads : %"PRIu64"\n", totalReads); fprintf(stderr, "Filtered reads : %"PRIu64"\n", totalReads-okReads); FreeRead(Read); return EXIT_SUCCESS; }
/** * A shared entry point to OpenRCT2. The command lines must be parsed before any further action is done. Invalid command lines * will then terminate before any initialisation has even been done. * @returns 1 if the game should run, otherwise 0. */ int cmdline_run(const char **argv, int argc) { // int version = 0, headless = 0, verbose = 0, width = 0, height = 0, port = 0; char *server = NULL; char *userDataPath = NULL; argparse_option_t options[] = { OPT_HELP(), OPT_BOOLEAN('v', "version", &version, "show version information and exit"), OPT_BOOLEAN(0, "headless", &headless, "run OpenRCT2 headless"), OPT_BOOLEAN(0, "verbose", &verbose, "log verbose messages"), OPT_INTEGER('m', "mode", &sprite_mode, "the type of sprite conversion. 0 = default, 1 = simple closest pixel match, 2 = dithering"), OPT_STRING(0, "server", &server, "server to connect to"), OPT_INTEGER(0, "port", &port, "port"), OPT_STRING(0, "user-data-path", &userDataPath, "path to the user data directory (containing config.ini)"), OPT_END() }; argparse_t argparse; argparse_init(&argparse, options, usage, 0); argc = argparse_parse(&argparse, argc, argv); if (version) { print_version(); return 0; } if (headless) gOpenRCT2Headless = true; if (verbose) _log_levels[DIAGNOSTIC_LEVEL_VERBOSE] = 1; if (userDataPath != NULL) { safe_strncpy(gCustomUserDataPath, userDataPath, sizeof(gCustomUserDataPath)); } #ifndef DISABLE_NETWORK if (port != 0) { gNetworkStart = NETWORK_MODE_SERVER; gNetworkStartPort = port; } if (server != NULL) { gNetworkStart = NETWORK_MODE_CLIENT; safe_strncpy(gNetworkStartHost, server, sizeof(gNetworkStartHost)); } #endif // DISABLE_NETWORK if (argc != 0) { gExitCode = cmdline_call_action(argv, argc); if (gExitCode != 0) { return 0; } } // Headless mode requires a park to open if (gOpenRCT2Headless) { if (str_is_null_or_empty(gOpenRCT2StartupActionPath)) { printf("You must specify a park to open in headless mode.\n"); gExitCode = -1; return 0; } } if (verbose) { print_launch_information(); } return 1; }
int main(int argc, char** argv) { int maxnumit = 0; int maxrec = -1; const char *budget_type_str = NULL; const char *stage = NULL; const char *training = NULL; const char *dev = NULL; const char *path = NULL; const char * etransform_str = NULL; const char *kernel_str = NULL; const char *rbf_lambda_str = NULL; #ifdef NDEBUG log_info("ai-parse %s (Release)", VERSION); #else log_info("ai-parse %s (Debug)", VERSION); #endif struct argparse_option options[] = { OPT_HELP(), //OPT_BOOLEAN('f', "force", &force, "force to do", NULL), OPT_INTEGER('v', "verbosity", &verbosity, "Verbosity level. Minimum (Default) 0. Increasing values increase parser verbosity.", NULL), OPT_STRING('o', "modelname", &modelname, "Model name", NULL), OPT_STRING('p', "path", &path, "CoNLL base directory including sections", NULL), OPT_STRING('s', "stage", &stage, "[ optimize | train | parse ]", NULL), OPT_INTEGER('n', "maxnumit", &maxnumit, "Maximum number of iterations by perceptron. Default is 50", NULL), OPT_STRING('t', "training", &training, "Training sections for optimize and train. Apply sections for parse", NULL), OPT_STRING('d', "development", &dev, "Development sections for optimize", NULL), OPT_STRING('e', "epattern", &epattern, "Embedding Patterns", NULL), OPT_INTEGER('l', "edimension", &edimension, "Embedding dimension", NULL), OPT_INTEGER('m', "maxrec", &maxrec, "Maximum number of training instance", NULL), OPT_STRING('x', "etransform", &etransform_str, "Embedding Transformation", NULL), OPT_STRING('k', "kernel", &kernel_str, "Kernel Type", NULL), OPT_INTEGER('a', "bias", &bias, "Polynomial kernel additive term. Default is 1", NULL), OPT_INTEGER('c', "concurrency", &num_parallel_mkl_slaves, "Parallel MKL Slaves. Default is 90% of all machine cores", NULL), OPT_INTEGER('b', "degree", &polynomial_degree, "Degree of polynomial kernel. Default is 4", NULL), OPT_STRING('z', "lambda", &rbf_lambda_str, "Lambda multiplier for RBF Kernel.Default value is 0.025"), OPT_STRING('u', "budget_type", &budget_type_str, "Budget control methods. NONE|RANDOM", NULL), OPT_INTEGER('g', "budget_size", &budget_target, "Budget Target for budget based perceptron algorithms. Default 50K", NULL), OPT_END(), }; struct argparse argparse; argparse_init(&argparse, options, usage, 0); argc = argparse_parse(&argparse, argc, argv); int max_threads = mkl_get_max_threads(); log_info("There are max %d MKL threads", max_threads); if (num_parallel_mkl_slaves == -1) { num_parallel_mkl_slaves = (int) (max_threads * 0.9); if (num_parallel_mkl_slaves == 0) num_parallel_mkl_slaves = 1; } log_info("Number of MKL Slaves is set to be %d", num_parallel_mkl_slaves); mkl_set_num_threads(num_parallel_mkl_slaves); if (1 == mkl_get_dynamic()) log_info("Intel MKL may use less than %i threads for a large problem", num_parallel_mkl_slaves); else log_info("Intel MKL should use %i threads for a large problem", num_parallel_mkl_slaves); check(stage != NULL && (strcmp(stage, "optimize") == 0 || strcmp(stage, "train") == 0 || strcmp(stage, "parse") == 0), "Choose one of -s optimize, train, parse"); check(path != NULL, "Specify a ConLL base directory using -p"); check(edimension != 0, "Set embedding dimension using -l"); check(modelname != NULL, "Provide model name using -o"); if (budget_type_str != NULL) { if (strcmp(budget_type_str, "RANDOM") == 0 || strcmp(budget_type_str, "RANDOMIZED") == 0) { budget_method = RANDOMIZED; } else if (strcmp(budget_type_str, "NONE") == 0) { budget_method = NONE; } else { log_err("Unknown budget control type %s", budget_type_str); goto error; } } else { budget_method = NONE; } if (training == NULL) { log_warn("training section string is set to %s", DEFAULT_TRAINING_SECTION_STR); training = strdup(DEFAULT_TRAINING_SECTION_STR); } if (dev == NULL && (strcmp(stage, "optimize") == 0 || strcmp(stage, "train") == 0)) { log_info("development section string is set to %s", DEFAULT_DEV_SECTION_STR); dev = strdup(DEFAULT_DEV_SECTION_STR); } check(epattern != NULL, "Embedding pattern is required for -s optimize,train,parse"); if (etransform_str == NULL) { log_info("Embedding transformation is set to be QUADRATIC"); etransform = DEFAULT_EMBEDDING_TRANFORMATION; } else if (strcmp(etransform_str, "LINEAR") == 0) { etransform = LINEAR; } else if (strcmp(etransform_str, "QUADRATIC") == 0) { etransform = QUADRATIC; } else if (strcmp(etransform_str, "CUBIC") == 0) { etransform = CUBIC; } else { log_err("Unsupported transformation type for embedding %s", etransform_str); } if (strcmp(stage, "optimize") == 0 || strcmp(stage, "train") == 0) { if (maxnumit <= 0) { log_info("maxnumit is set to %d", DEFAULT_MAX_NUMIT); maxnumit = DEFAULT_MAX_NUMIT; } } if (kernel_str != NULL) { if (strcmp(kernel_str, "POLYNOMIAL") == 0) { log_info("Polynomial kernel will be used with bias %f and degree %d", bias, polynomial_degree); kernel = KPOLYNOMIAL; } else if (strcmp(kernel_str, "GAUSSIAN") == 0 || strcmp(kernel_str, "RBF") == 0) { if (rbf_lambda_str != NULL) { rbf_lambda = (float) atof(rbf_lambda_str); } log_info("RBF/GAUSSIAN kernel will be used with lambda %f ", rbf_lambda); kernel = KRBF; } else { log_err("Unsupported kernel type %s. Valid options are LINEAR, POLYNOMIAL, and RBF/GAUSSIAN", kernel_str); goto error; } } if (strcmp(stage, "optimize") == 0) { void *model = optimize(maxnumit, maxrec, path, training, dev, edimension); char* model_filename = (char*) malloc(sizeof (char) * (strlen(modelname) + 7)); check_mem(model_filename); sprintf(model_filename, "%s.model", modelname); FILE *fp = fopen(model_filename, "w"); if (kernel == KLINEAR) { PerceptronModel pmodel = (PerceptronModel) model; dump_PerceptronModel(fp, edimension, pmodel->embedding_w_best, pmodel->best_numit); PerceptronModel_free(pmodel); } else if (kernel == KPOLYNOMIAL || kernel == KRBF) { KernelPerceptron kpmodel = (KernelPerceptron) model; dump_KernelPerceptronModel(fp, kpmodel); } log_info("Model is dumped into %s file", model_filename); fclose(fp); } else if (strcmp(stage, "parse") == 0) { char* model_filename = (char*) malloc(sizeof (char) * (strlen(modelname) + 7)); check_mem(model_filename); sprintf(model_filename, "%s.model", modelname); FILE *fp = fopen(model_filename, "r"); check(fp != NULL, "%s could not be opened", model_filename); void *model; if (kernel == KLINEAR) model = load_PerceptronModel(fp); else model = load_KernelPerceptronModel(fp); fclose(fp); check(model != NULL, "Error in loading model file"); log_info("Model loaded from %s successfully", model_filename); parseall(model, path, training, edimension); } else { log_info("Waiting for implementation"); } return (EXIT_SUCCESS); error: return (EXIT_FAILURE); }
/* * This application converts a amino acid sequence to a group sequence. */ int main(int argc, char *argv[]) { int64_t streamSize, index; char value; BUF *Buffer; char *programName = argv[0]; struct argparse_option options[] = { OPT_HELP(), OPT_GROUP("Basic options"), OPT_BUFF('<', "input.prot", "Input amino acid sequence file (stdin)"), OPT_BUFF('>', "output.group", "Output group sequence file (stdout)"), OPT_END(), }; struct argparse argparse; char usage[500] = "\nExample: "; strcat(usage, programName); strcat(usage, " < input.prot > output.group\n"); strcat(usage, "Table:\n"); strcat(usage, "Prot\tGroup\n"); strcat(usage, "R\tP\n"); strcat(usage, "H\tP Amino acids with electric charged side chains: POSITIVE\n"); strcat(usage, "K\tP\n"); strcat(usage, "-\t-\n"); strcat(usage, "D\tN\n"); strcat(usage, "E\tN Amino acids with electric charged side chains: NEGATIVE\n"); strcat(usage, "-\t-\n"); strcat(usage, "S\tU\n"); strcat(usage, "T\tU\n"); strcat(usage, "N\tU Amino acids with electric UNCHARGED side chains\n"); strcat(usage, "Q\tU\n"); strcat(usage, "-\t-\n"); strcat(usage, "C\tS\n"); strcat(usage, "U\tS\n"); strcat(usage, "G\tS Special cases\n"); strcat(usage, "P\tS\n"); strcat(usage, "-\t-\n"); strcat(usage, "A\tH\n"); strcat(usage, "V\tH\n"); strcat(usage, "I\tH\n"); strcat(usage, "L\tH\n"); strcat(usage, "M\tH Amino acids with hydrophobic side chains\n"); strcat(usage, "F\tH\n"); strcat(usage, "Y\tH\n"); strcat(usage, "W\tH\n"); strcat(usage, "-\t-\n"); strcat(usage, "*\t* Others\n"); strcat(usage, "X\tX Unknown\n"); argparse_init(&argparse, options, NULL, programName, 0); argparse_describe(&argparse, "\nIt converts a amino acid sequence to a group sequence.", usage); argc = argparse_parse(&argparse, argc, argv); if(argc != 0) argparse_help_cb(&argparse, options); Buffer = CreateBuffer(BUF_SIZE); while((streamSize = fread(Buffer->buf, 1, Buffer->size, stdin))) { for(index = 0 ; index < streamSize ; ++index) { value = Buffer->buf[index]; switch(value) { case 'R': putchar('P'); break; case 'H': putchar('P'); break; case 'K': putchar('P'); break; case 'D': putchar('N'); break; case 'E': putchar('N'); break; case 'S': putchar('U'); break; case 'T': putchar('U'); break; case 'N': putchar('U'); break; case 'Q': putchar('U'); break; case 'C': putchar('S'); break; case 'U': putchar('S'); break; case 'G': putchar('S'); break; case 'P': putchar('S'); break; case 'A': putchar('H'); break; case 'V': putchar('H'); break; case 'I': putchar('H'); break; case 'L': putchar('H'); break; case 'M': putchar('H'); break; case 'F': putchar('H'); break; case 'Y': putchar('H'); break; case 'W': putchar('H'); break; case '*': putchar('*'); break; case 'X': putchar('X'); break; } } } RemoveBuffer(Buffer); return EXIT_SUCCESS; }
/* * This application discards the FASTQ reads with the minimum number of \"N\" symbols. * If present, it will erase the second header (after +). */ int main(int argc, char *argv[]) { Read *Read = CreateRead(65536+GUARD, 65535+GUARD); uint32_t sequenceSize = 0, N_counter = 0, globalIndex, index; uint64_t okReads = 0, totalReads = 0; int max_n_read = 0; char *programName = argv[0]; struct argparse_option options[] = { OPT_HELP(), OPT_GROUP("Basic options"), OPT_INTEGER('m', "max", &max_n_read, "The maximum of of \"N\" symbols in the read"), OPT_BUFF('<', "input.fastq", "Input FASTQ file format (stdin)"), OPT_BUFF('>', "output", "Output read information (stdout)"), OPT_END(), }; struct argparse argparse; char usage[250] = "\nExample: "; strcat(usage, programName); strcat(usage, " < input.fastq > output\n" "\nOutput example :\n" "<FASTQ non-filtered reads>\n" "Total reads : value\n" "Filtered reads : value\n"); argparse_init(&argparse, options, NULL, programName, 0); argparse_describe(&argparse, "\nIt discards the FASTQ reads with the minimum number of \"N\" symbols." "If present, it will erase the second header (after +).", usage); argc = argparse_parse(&argparse, argc, argv); if(argc != 0) argparse_help_cb(&argparse, options); if(max_n_read <= 0 || max_n_read > UINT_MAX) { fprintf(stderr, "\nERROR: The number of \"N\" symbols most be a positive unsigned int!\n"); argparse_help_cb(&argparse, options); exit(1); } // LOAD PARAMETERS while(GetRead(stdin, Read)) { sequenceSize = strlen((char *) Read->bases) - 1; N_counter = 0; for(globalIndex = 0 ; globalIndex < sequenceSize ; ++globalIndex) if(Read->bases[globalIndex] == 'N') ++N_counter; ++totalReads; // Evaluate to discard if(N_counter > max_n_read) continue; // Print read fprintf(stdout, "@"); for(index = 0 ; index < strlen((char *) Read->header1) ; ++index) fprintf(stdout, "%c", Read->header1[index]); for(index = 0 ; index < globalIndex ; ++index) fprintf(stdout, "%c", Read->bases[index]); fprintf(stdout, "\n+\n"); for(index = 0 ; index < globalIndex ; ++index) fprintf(stdout, "%c", Read->scores[index]); fprintf(stdout, "\n"); ++okReads; } fprintf(stderr, "Total reads : %"PRIu64"\n", totalReads); fprintf(stderr, "Filtered reads : %"PRIu64"\n", totalReads-okReads); FreeRead(Read); return EXIT_SUCCESS; }