int main(int argc, char *argv[]) {
    
    // First: Sort out the command line.
    struct arg_file *files_to_verify = arg_filen(NULL, NULL, "<table file>", 0, 100000, "GRT parts to verify.");
    struct arg_dbl *percent = arg_dbl0(NULL, "percent", "[0-100]", "Percent of chains to randomly verify.");
    struct arg_int *sequential = arg_int0(NULL, "sequential", "<n>", "Check every nth chain");
    /*
    void *argtable[] = {table_files, output_directory, bits, move_source, end};

    // Get arguments, collect data, check for basic errors.
    if (arg_nullcheck(argtable) != 0) {
      printf("error: insufficient memory\n");
    }
    // Look for errors
    int nerrors = arg_parse(argc,argv,argtable);
    if (nerrors > 0) {
      // Print errors, exit.
      arg_print_errors(stdout,end,argv[0]);
      // Print help.
      printf("\n\nOptions: \n");
      arg_print_glossary(stdout,argtable,"  %-20s %s\n");
      exit(1);
    }
    */
}
Example #2
0
int main(int argc, char **argv)
    {
    struct arg_dbl *a    = arg_dbl1(NULL,NULL,"a","a is <double>");
    struct arg_dbl *b    = arg_dbl0(NULL,NULL,"b","b is <double>");
    struct arg_dbl *c    = arg_dbl0(NULL,NULL,"c","c is <double>");
    struct arg_dbl *d    = arg_dbln("dD","delta","<double>",0,3,"d can occur 0..3 times");
    struct arg_dbl *e    = arg_dbl0(NULL,"eps,eqn","<double>","eps is optional");
    struct arg_lit *help = arg_lit0(NULL,"help","print this help and exit");
    struct arg_end *end  = arg_end(20);
    void* argtable[] = {a,b,c,d,e,help,end};
    int nerrors;
    int exitcode=0;
    int i;
    double sum=0;
    
    /*
    printf("a=%p\n",a);
    printf("b=%p\n",b);
    printf("c=%p\n",c);
    printf("d=%p\n",d);
    printf("e=%p\n",e);
    printf("help=%p\n",help);
    printf("end=%p\n",end);
    printf("argtable=%p\n",argtable);
    */
    
    /* print the command line */
    for (i=0; i<argc; i++)
        printf("%s ",argv[i]);
    printf("\n");
    
    /* verify the argtable[] entries were allocated sucessfully */
    if (arg_nullcheck(argtable) != 0)
        {
        /* NULL entries were detected, some allocations must have failed */
        printf("%s: insufficient memory\n",argv[0]);
        exitcode=1;
        goto exit;
        }
    
    /* Parse the command line as defined by argtable[] */
    nerrors = arg_parse(argc,argv,argtable);

    /* special case: '--help' takes precedence over error reporting */
    if (help->count > 0)
        {
        printf("Usage: %s ", argv[0]);
        arg_print_syntax(stdout,argtable,"\n");
        arg_print_glossary(stdout,argtable,"  %-25s %s\n");
        exitcode=0;
        goto exit;
        }

    /* If the parser returned any errors then display them and exit */
    if (nerrors > 0)
        {
        /* Display the error details contained in the arg_end struct.*/
        arg_print_errors(stdout,end,argv[0]);
        exitcode=1;
        goto exit;
        }

    /* parsing complete, verify all args sum to zero */
    for (i=0; i<a->count; i++)
        {
        printf("a[%d]=%f\n",i,a->dval[i]);
        sum += a->dval[i];
        }
    for (i=0; i<b->count; i++)
        {
        printf("b[%d]=%f\n",i,b->dval[i]);
        sum += b->dval[i];
        }
    for (i=0; i<c->count; i++)
        {
        printf("c[%d]=%f\n",i,c->dval[i]);
        sum += c->dval[i];
        }
    for (i=0; i<d->count; i++)
        {
        printf("d[%d]=%f\n",i,d->dval[i]);
        sum += d->dval[i];
        }
    for (i=0; i<e->count; i++)
        {
        printf("e[%d]=%f\n",i,e->dval[i]);
        sum += e->dval[i];
        }
    printf("sum=%f\n",sum);
    if (sum<-1.0e-6 || sum>1.0e-6)
        {
        printf("%s: error - sum=%f is non-zero\n",argv[0],sum);
        exitcode=1;
        goto exit;
        }
        
    exit:
    /* deallocate each non-null entry in argtable[] */
    arg_freetable(argtable,sizeof(argtable)/sizeof(argtable[0]));
    
    printf("%s: exitcode=%d\n\n",argv[0],exitcode);

    /* close stdin and stdout to stop memcheck whining about their memory not being freed */
    fclose(stdin);
    fclose(stdout);
   
    return exitcode;
    }
Example #3
0
int main(int argc, char *argv[]) {

  struct arg_dbl *_dt = arg_dbl0("t",
			       "time-step",
			       NULL,
			       "time step for time history integration");

  struct arg_dbl *_d = arg_dbl0("d",
			       "duration",
			       NULL,
			       "the duration of the analysis");

  struct arg_dbl *_a = arg_dbl0("a",
			       "alpha",
			       NULL,
			       "Reynolds damping alpha");

  struct arg_dbl *_b = arg_dbl0("b",
			       "beta",
			       NULL,
			       "Reynolds damping beta");

  struct arg_dbl *_E = arg_dbl0("E",
			       "youngs-modulus",
			       NULL,
			       "the material stiffness");

  struct arg_dbl *_A = arg_dbl0("A",
			       "area",
			       NULL,
			       "the member's cross-sectional stiffness");

  struct arg_dbl *_I = arg_dbl0("I",
			       "moment-of-interia",
			       NULL,
			       "the member's moment of interia");

  struct arg_dbl *_m = arg_dbl0("m",
			       "mass",
			       NULL,
			       "the mass at the top of the member");

  struct arg_dbl *_F = arg_dbl0("F",
			       "force",
			       NULL,
			       "the force applied at the top of the member");

  struct arg_dbl *_h = arg_dbl0("h",
			       "height",
			       NULL,
			       "the height of the member");

  _dt->dval[0] = 0.1;
  _d->dval[0] = 10;
  _a->dval[0] = 0.0115;
  _b->dval[0] = 0.0115;
  _A->dval[0] = 0.0002;
  _E->dval[0] = 200000000;
  _I->dval[0] = 0.0000000133333;
  _m->dval[0] = 10;
  _F->dval[0] = 40;
  _h->dval[0] = 2;


  struct arg_end *end = arg_end(10);
  void* argtable[] = {_dt,_d,_a,_b,_A,_E,_I,_m,_F,_h,end};

  const char* progname = "sdof-step";
  int exitcode = 0, returnvalue = 0;
  int nerrors = arg_nullcheck(argtable);


  if(nerrors != 0) {
    cerr << "Not enough memory to proceed" << endl;
    arg_print_errors(stderr,end,progname);
    arg_freetable(argtable,sizeof(argtable)/sizeof(argtable[0]));
    return nerrors;
  }

  nerrors = arg_parse(argc, argv, argtable);

  if(nerrors != 0) {
    arg_print_errors(stderr,end,progname);
    cerr << "Usage: " << endl;
    arg_print_syntaxv(stderr,argtable,"\n");
    return(nerrors);
  }

  FILE* param = fopen("parameters.txt","w");
  fprintf(param,"Input Parameters:\n");
  fprintf(param,"Time step: %lf\n",_dt->dval[0]);
  fprintf(param,"Duration:  %lf\n",_d->dval[0]);
  fprintf(param,"alpha:     %lf\n",_a->dval[0]);
  fprintf(param,"beta:      %lf\n",_b->dval[0]);
  fprintf(param,"area:      %lf\n",_A->dval[0]);
  fprintf(param,"I:         %lf\n",_I->dval[0]);
  fprintf(param,"E:         %lf\n",_E->dval[0]);
  fprintf(param,"mass:      %lf\n",_m->dval[0]);
  fprintf(param,"h:         %lf\n",_h->dval[0]);
  fprintf(param,"F:         %lf\n",_F->dval[0]);
  fclose(param);

  double* x = new double[3];
  double* v = new double[3];
  double* a = new double[3];
  bool* constrainType = new bool[3];
  double* constrainValue = new double[3];
  double* mass = new double[3];

  Node** nodes = new Node*[2];
  
  x[0] = x[1] = x[2] = 0.0;
  v[0] = v[1] = v[2] = a[0] = a[1] = a[2] = 0.0;

  constrainType[0] = Node::DISP;
  constrainType[1] = Node::DISP;
  constrainType[2] = Node::DISP;

  constrainValue[0] = 0.0;
  constrainValue[1] = 0.0;
  constrainValue[2] = 0.0;

  mass[0] = _m->dval[0];
  mass[1] = _m->dval[0];
  mass[2] = _m->dval[0]/4;

  nodes[0] = new Node(x, v, a, 3, constrainType, constrainValue,
		      mass, 0);

  // set y coord of second node
  x[1] = _h->dval[0];

  constrainType[0] = Node::FORCE;
  constrainType[1] = Node::FORCE;
  constrainType[2] = Node::FORCE;

  cerr << "about to make the second node" << endl;

  nodes[1] = new Node(x, v, a, 3, constrainType, constrainValue,
		      mass, 1);

  cerr << "made 2nd node" << endl;

  Element** elements = new Element*[1];
  
  elements[0] = new LinearBeam(nodes, 
			       2,
			       _A->dval[0],
			       _E->dval[0],
			       _I->dval[0]);

  cerr << "generated elements" << endl;

  double dt = _dt->dval[0];

  double time = _d->dval[0];
  int nSteps = (int) (time / dt);
  cerr << "Number of Time Steps: " << nSteps << endl;
  double wf = 2;
  cerr << "bo" << endl;
  double **loads;
  cerr << "bi" << endl;
  loads = new double*[6];
  for(int i = 0; i < 6; i++) {
    loads[i] = new double[nSteps];
  }
  cerr << "ba" << endl;

  double E = _E->dval[0];
  double I = _I->dval[0];
  double L = _h->dval[0];

  double k = 3*E*I/(L*L*L);

  double w = sqrt(k/_m->dval[0]);
  double T = 2*M_PI/w;

  cerr << "Period is " << T << endl;

  for(int i = 0; i < nSteps; i++) {
    for(int j = 0; j < 6; j++)
      loads[j][i] = 0.0;
  }

  loads[3][2] = _F->dval[0];
  
  
  FILE* load = fopen("load.csv", "w");
  for(int i = 0; i < nSteps; i++) {
    for(int j = 0; j < 6; j++)
      fprintf(load,"%lf,",loads[j][i]);
    fprintf(load,"\n");;
  }

  Enoch* enoch = new Enoch(nodes,elements,loads,2,1,nSteps, dt,
			   _a->dval[0], _b->dval[0], 0.5, 0.25);

  enoch->run();
}
Example #4
0
int main(int argc, char *argv[]) {
    int retcode = 1;
    int nerrors = 0;
    streamer_t streamer;
    memset(&streamer, 0, sizeof(streamer_t));

    // Signal handlers
    signal(SIGINT, sig_fn);
    signal(SIGTERM, sig_fn);

    // Initialize SDL2
    if (SDL_Init(SDL_INIT_AUDIO) != 0) {
        fprintf(stderr, "%s\n", SDL_GetError());
        return 1;
    }

    // Defaults
    streamer.freq = 44100;
    streamer.n_channels = 2;
    streamer.bits = 16;
    streamer.volume = 1.0f;
    streamer.quality = DUMB_RQ_CUBIC;

    // commandline argument parser options
    struct arg_lit *arg_help =
        arg_lit0("h", "help", "print this help and exits");
    struct arg_dbl *arg_volume =
        arg_dbl0("v", "volume", "<volume",
                 "sets the output volume (-8.0 to +8.0, default 1.0)");
    struct arg_int *arg_samplerate = arg_int0(
        "s", "samplerate", "<freq>", "sets the sampling rate (default 44100)");
    struct arg_int *arg_quality = arg_int0(
        "r", "quality", "<quality>", "specify the resampling quality to use");
    struct arg_lit *arg_mono =
        arg_lit0("m", "mono", "generate mono output instead of stereo");
    struct arg_lit *arg_eight =
        arg_lit0("8", "eight", "generate 8-bit instead of 16-bit");
    struct arg_lit *arg_noprogress =
        arg_lit0("n", "noprogress", "hide progress bar");
    struct arg_file *arg_output =
        arg_file0("o", "output", "<file>", "output file");
    struct arg_file *arg_input =
        arg_file1(NULL, NULL, "<file>", "input module file");
    struct arg_end *arg_fend = arg_end(20);
    void *argtable[] = {arg_help,       arg_input,      arg_volume,
                        arg_samplerate, arg_quality,    arg_mono,
                        arg_eight,      arg_noprogress, arg_fend};
    const char *progname = "dumbplay";

    // Make sure everything got allocated
    if (arg_nullcheck(argtable) != 0) {
        fprintf(stderr, "%s: insufficient memory\n", progname);
        goto exit_0;
    }

    // Parse inputs
    nerrors = arg_parse(argc, argv, argtable);

    // Handle help
    if (arg_help->count > 0) {
        fprintf(stderr, "Usage: %s", progname);
        arg_print_syntax(stderr, argtable, "\n");
        fprintf(stderr, "\nArguments:\n");
        arg_print_glossary(stderr, argtable, "%-25s %s\n");
        goto exit_0;
    }

    // Handle libargtable errors
    if (nerrors > 0) {
        arg_print_errors(stderr, arg_fend, progname);
        fprintf(stderr, "Try '%s --help' for more information.\n", progname);
        goto exit_0;
    }

    // Handle the switch options
    streamer.input = arg_input->filename[0];
    if (arg_eight->count > 0) {
        streamer.bits = 8;
    }
    if (arg_mono->count > 0) {
        streamer.n_channels = 1;
    }
    if (arg_noprogress->count > 0) {
        streamer.no_progress = true;
    }

    if (arg_volume->count > 0) {
        streamer.volume = arg_volume->dval[0];
        if (streamer.volume < -8.0f || streamer.volume > 8.0f) {
            fprintf(stderr, "Volume must be between -8.0f and 8.0f.\n");
            goto exit_0;
        }
    }

    if (arg_samplerate->count > 0) {
        streamer.freq = arg_samplerate->ival[0];
        if (streamer.freq < 1 || streamer.freq > 96000) {
            fprintf(stderr, "Sampling rate must be between 1 and 96000.\n");
            goto exit_0;
        }
    }

    if (arg_quality->count > 0) {
        streamer.quality = arg_quality->ival[0];
        if (streamer.quality < 0 || streamer.quality >= DUMB_RQ_N_LEVELS) {
            fprintf(stderr, "Quality must be between %d and %d.\n", 0,
                    DUMB_RQ_N_LEVELS - 1);
            goto exit_0;
        }
    }

    // Load source file.
    dumb_register_stdfiles();
    streamer.src = dumb_load_any(streamer.input, 0, 0);
    if (!streamer.src) {
        fprintf(stderr, "Unable to load file %s for playback!\n",
                streamer.input);
        goto exit_0;
    }

    // Set up playback
    streamer.renderer =
        duh_start_sigrenderer(streamer.src, 0, streamer.n_channels, 0);
    streamer.delta = 65536.0f / streamer.freq;
    streamer.sbytes = (streamer.bits / 8) * streamer.n_channels;
    streamer.ssize = duh_get_length(streamer.src);

    // Stop producing samples on module end
    DUMB_IT_SIGRENDERER *itsr = duh_get_it_sigrenderer(streamer.renderer);
    dumb_it_set_loop_callback(itsr, &dumb_it_callback_terminate, NULL);
    dumb_it_set_xm_speed_zero_callback(itsr, &dumb_it_callback_terminate, NULL);
    dumb_it_set_resampling_quality(itsr, streamer.quality);

    // Set up the SDL2 format we want for playback.
    SDL_AudioSpec want;
    SDL_zero(want);
    want.freq = streamer.freq;
    want.format = (streamer.bits == 16) ? AUDIO_S16 : AUDIO_S8;
    want.channels = streamer.n_channels;
    want.samples = SAMPLES;
    want.callback = stream_audio;
    want.userdata = &streamer;

    // Find SDL2 audio device, and request the format we just set up.
    // SDL2 will tell us what we got in the "have" struct.
    SDL_AudioSpec have;
    streamer.dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0);
    if (streamer.dev == 0) {
        fprintf(stderr, "%s\n", SDL_GetError());
        goto exit_1;
    }

    // Make sure we got the format we wanted. If not, stop here.
    if (have.format != want.format) {
        fprintf(stderr, "Could not get correct playback format.\n");
        goto exit_2;
    }

    // Play file
    SDL_PauseAudioDevice(streamer.dev, 0);

    // Show initial state of the progress bar (if it is enabled)
    int time_start = SDL_GetTicks();
    float seek = 0.0f;
    int ms_played = 0;
    if (!streamer.no_progress) {
        show_progress(PROGRESSBAR_LENGTH, seek, ms_played);
    }

    // Loop while dumb is still giving data. Update progressbar if enabled.
    while (!stop_signal && !streamer.ended) {
        if (!streamer.no_progress) {
            seek = ((float)streamer.spos) / ((float)streamer.ssize);
            ms_played = SDL_GetTicks() - time_start;
            show_progress(PROGRESSBAR_LENGTH, seek, ms_played);
        }
        SDL_Delay(100);
    }

    // We made it this far without crashing, so let's just exit with no error :)
    retcode = 0;

    // Free up resources and exit.
    if (streamer.sig_samples) {
        destroy_sample_buffer(streamer.sig_samples);
    }

exit_2:
    SDL_CloseAudioDevice(streamer.dev);

exit_1:
    if (streamer.renderer) {
        duh_end_sigrenderer(streamer.renderer);
    }
    if (streamer.src) {
        unload_duh(streamer.src);
    }

exit_0:
    arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
    SDL_Quit();
    return retcode;
}
Example #5
0
int main(int argc, char *argv[]) {
    
#ifndef _OPENMP
    fprintf(stderr, "\nERROR: Program built with compiler lacking OpenMP support.\n");
    fprintf(stderr, "See SEAStAR README file for information about suitable compilers.\n");
    exit(EXIT_FAILURE);
#endif
    
    ///////////////////////////
    // Variable declarations
    ///////////////////////////
    
    // Input filenames
    UT_string *in_read1_fq_fn, *in_read2_fq_fn, *in_single1_fq_fn, *in_single2_fq_fn;
    utstring_new(in_read1_fq_fn);
    utstring_new(in_read2_fq_fn);
    utstring_new(in_single1_fq_fn);
    utstring_new(in_single2_fq_fn);
    
    // Output filenames
    UT_string *out_read1_fn, *out_read2_fn, *out_single1_fn, *out_single2_fn, *out_mates_fn, *out_filetype;
    utstring_new(out_filetype);
    utstring_new(out_read1_fn);
    utstring_new(out_read2_fn);
    utstring_new(out_single1_fn);
    utstring_new(out_single2_fn);
    utstring_new(out_mates_fn);
    
    // Read name prefix
    UT_string *out_read_prefix;
    utstring_new(out_read_prefix);
    
    // Flags
    int singles_flag = 0;   // 1 when two output singles files being written
    int num_input_singles_files = 0;
    
    // Read counters
    unsigned long int mp_org = 0, R1_org = 0, R2_org = 0, singlet1_org = 0, singlet2_org = 0;
    unsigned long int mp_cnt = 0, R1_cnt = 0, R2_cnt = 0, singlet1_cnt = 0, singlet2_cnt = 0, s1_cnt = 0, s2_cnt = 0;
    unsigned long int comp_r1 = 0, comp_r2 = 0, comp_s1 = 0, comp_s2 = 0;
    unsigned long int read1_singlet_cnt = 0, read2_singlet_cnt = 0;

    ////////////////////////////////////////////////////////////////////////
    // All done with variable declarations!!
    
    ///////////////////////////////////
    // Command line argtable settings
    ///////////////////////////////////
    
    struct arg_lit *gzip = arg_lit0("z", "gzip", "Output converted files in gzip compressed format. [NULL]");
    struct arg_lit *inv_singles = arg_lit0("v", "invert_singles", "Causes singles output to be the inverse of the input. 2->1 or 1->2 [NULL]");
    struct arg_lit *num_singles = arg_lit0("s", "singles", "Write two singlet files, one for each mate-paired input file. [NULL]");
    struct arg_rem *sing_rem = arg_rem(NULL, "Note! -v is only valid when there are input singlet reads. -s is only valid when there are NO input singlet reads.");    
    struct arg_str *pre_read_id = arg_str0(NULL, "prefix", "<string>", "Prefix to add to read identifiers. [out_prefix]");
    struct arg_lit *no_pre = arg_lit0(NULL, "no_prefix", "Do not change the read names in any way. [NULL]");
    struct arg_lit *pre_read_len = arg_lit0(NULL, "add_len", "Add the final trimmed length value to the read id prefix. [length not added]");
    struct arg_dbl *prob = arg_dbl0("p","correct_prob","<d>","Probability that output reads are correct. 0.0 disables quality trimming. [0.5]");
    struct arg_int *fixed_len = arg_int0("f","fixed_len","<u>","Trim all reads to a fixed length, still filtering on quality [no fixed length]");
    struct arg_int *len = arg_int0("l","min_read_len","<u>","Minimum length of a singlet or longest-mate in nucleotides [24]");
    struct arg_int *mate_len = arg_int0("m","min_mate_len","<u>","Minimum length of the shortest mate in nucleotides [min_read_len]");
    struct arg_dbl *entropy = arg_dbl0("e","entropy_filter","<d>","Remove reads with per position information below given value (in bits per dinucleotide) [No filter]");
    struct arg_lit *entropy_strict = arg_lit0(NULL, "entropy_strict", "Reject reads for low entropy overall, not just the retained part after trimming [NULL]");
    struct arg_lit *mates = arg_lit0(NULL, "mates_file", "Produce a Velvet compatible interleaved paired read output file (e.g. <out_prefix>_mates.fastq). [NULL]");
    struct arg_lit *no_rev = arg_lit0(NULL, "no_rev", "By default, the second read in each pair is reversed for colorspace --mate-file output. --no_rev disables reversing. [rev]");
    struct arg_lit *only_mates = arg_lit0(NULL, "only_mates", "Supress writing .read1 and .read2 outputs. Requires --mates_file. [NULL]");
    struct arg_lit *fasta = arg_lit0(NULL, "fasta", "Write FASTA format files instead of FASTQ for all outputs (e.g. <out_prefix>.<read_type>.fasta). [FASTQ]");
    struct arg_file *input = arg_file1(NULL, NULL, "<in_prefix>", "Input file prefix: (e.g. <in_prefix>_single.fastq [<in_prefix>_read1.fastq <in_prefix>_read2.fastq]) ");
    struct arg_file *output = arg_file1(NULL, NULL, "<out_prefix>", "Output file prefix: (e.g. <out_prefix>_single.fastq [<out_prefix>_read1.fastq <out_prefix>_read2.fastq]) ");
    struct arg_lit *version = arg_lit0(NULL,"version","Print the build version and exit."); 
    struct arg_lit *h = arg_lit0("h", "help", "Request help.");
    struct arg_end *end = arg_end(20);
    
    void *argtable[] = {h,version,gzip,inv_singles,num_singles,sing_rem,prob,len,mate_len,fixed_len,pre_read_id,pre_read_len,no_pre,entropy,entropy_strict,mates,no_rev,only_mates,fasta,input,output,end};
    int arg_errors = 0;
        
    ////////////////////////////////////////////////////////////////////////
    // Handle command line processing (via argtable2 library) 
    ////////////////////////////////////////////////////////////////////////
    
    arg_errors = arg_parse(argc, argv, argtable);

	if (version->count) {
		fprintf(stderr, "%s version: %s\n", argv[0], SS_BUILD_VERSION);
		exit(EXIT_SUCCESS);
    }    
	
    if (h->count) {
        fprintf(stderr,"\ntrim_fastq is a utility for performing quality and information-based\n");
        fprintf(stderr,"trimming on paired or unpaired, nucleotide or SOLiD colorspace reads. \n\n");
        arg_print_syntaxv(stderr, argtable, "\n\n");
        arg_print_glossary(stderr, argtable, "%-25s %s\n");
        fprintf(stderr, "\nInput and output \"prefixes\" are the part of the filename before:\n");
        fprintf(stderr, "_single.fastq [_read1.fastq _read2.fastq]  A singlets (single) file\n");
        fprintf(stderr, "is required.  Mate-paired read files are automatically used if present.\n");
        fprintf(stderr, "Multiple output files only produced for mate-paired inputs.\n");
        fprintf(stderr, "\nNote! Input and output files may be gzipped, and outputs can be written\n");
        fprintf(stderr, "as either FASTQ or FASTA format files.\n");
        
        exit(EXIT_FAILURE);
    }    
    
    if (arg_errors) { 
        arg_print_errors(stderr, end, "trimfastq");
        arg_print_syntaxv(stderr, argtable, "\n");
        exit(EXIT_FAILURE);
    }
    
    // Validate entropy
    if (entropy->count) {
        entropy_cutoff = entropy->dval[0];
        if ((entropy_cutoff < 0.0) || (entropy_cutoff > 4.0)) {
            fprintf(stderr, "entropy_filter must be [0.0 - 4.0] \n");
            exit(EXIT_FAILURE);
        }
        strict_ent = entropy_strict->count;
    } else {
        if (entropy_strict->count) {
            fprintf(stderr, "Error: --entropy_strict requires --entropy_filter.\n");
            exit(EXIT_FAILURE);
        } 
        entropy_cutoff = -1.0;
    }    
    
    // Validate error_prob
    if (prob->count) {
        err_prob = prob->dval[0];
        if ((err_prob < 0.0) || (err_prob > 1.0)) {
            fprintf(stderr, "--correct_prob (-p) must be 0.0 - 1.0 inclusive\n");
            exit(EXIT_FAILURE);
        }
    } else {
        err_prob = 0.5;
    }    

    // Validate min read len
    if (len->count) {
        min_len = len->ival[0];
        if (min_len <= 0) {
            fprintf(stderr, "min_read_len must be > 0\n");
            exit(EXIT_FAILURE);
        }        
    } else {
        min_len = 24;
    }

    // Validate min mate len
    if (mate_len->count) {
        min_mate_len = mate_len->ival[0];
        if (min_mate_len <= 0) {
            fprintf(stderr, "min_mate_len must be > 0\n");
            exit(EXIT_FAILURE);
        }        
        if (min_mate_len > min_len) {
            fprintf(stderr, "min_mate_len must be <= min_len\n");
            exit(EXIT_FAILURE);
        }        
    } else {
        min_mate_len = min_len;
    }
    
    if (fixed_len->count) {
        fix_len = min_mate_len = min_len = fixed_len->ival[0];
        if ((mate_len->count) || (len->count)) {
            fprintf(stderr, "fixed_len cannot be used with min_read_len or min_mate_len\n");
            exit(EXIT_FAILURE);
        }
        if (fix_len <= 0) {
            fprintf(stderr, "fixed_len must be > 0\n");
            exit(EXIT_FAILURE);
        }
    } else {
        fix_len = 0;
    }
    
    if (pre_read_id->count) {
        
        if (no_pre->count) {
            fprintf(stderr, "Error: Both --prefix and --no_prefix were specified.\n");
            exit(EXIT_FAILURE);
        }
        
        if (! strlen(pre_read_id->sval[0])) {
            fprintf(stderr, "Read ID prefix may not be zero length.\n");
            exit(EXIT_FAILURE);
        } 
        
        if (strchr(pre_read_id->sval[0], ':') || strchr(pre_read_id->sval[0], '|') || strchr(pre_read_id->sval[0], '+') || strchr(pre_read_id->sval[0], '/')) {
            fprintf(stderr, "Read ID prefix '%s' may not contain the characters ':', '|', '+' or '/'.\n", pre_read_id->sval[0]);
            exit(EXIT_FAILURE);
        }
        
        // Build default read ID prefix
        ss_strcat_utstring(out_read_prefix, pre_read_id->sval[0]);
        
    } else {

        if (!no_pre->count) {
            
            if (strchr(output->filename[0], ':') || strchr(output->filename[0], '|') || strchr(output->filename[0], '+') || strchr(output->filename[0], '/')) {
                fprintf(stderr, "Read ID prefix '%s' (from output prefix) may not contain the characters ':', '|', '+' or '/'.\n", output->filename[0]);
                fprintf(stderr, "Hint: Use the --prefix parameter if the output file prefix contains path information.\n");
                exit(EXIT_FAILURE);
            }  
            
            // Build default read ID prefix
            ss_strcat_utstring(out_read_prefix, output->filename[0]);
        }
    }
    
    if ((only_mates->count) && (!mates->count)) {
        fprintf(stderr, "--only_mates requires --mates.\n");
        exit(EXIT_FAILURE);
    }

    if ((no_rev->count) && (!mates->count)) {
        fprintf(stderr, "--no_rev requires --mates.\n");
        exit(EXIT_FAILURE);
    }
    
    // Check for null string prefixes
    if (!(strlen(input->filename[0]) && strlen(output->filename[0]))) {
        fprintf(stderr, "Error: NULL prefix strings are not permitted.\n");
        exit(EXIT_FAILURE);
    }
    
    // Construct input filenames
    utstring_printf(in_read1_fq_fn, "%s.read1.fastq", input->filename[0]);
    utstring_printf(in_read2_fq_fn, "%s.read2.fastq", input->filename[0]);
    
    utstring_printf(in_single1_fq_fn, "%s.single.fastq", input->filename[0]);
    
    FILE *in_read_file = NULL;
    
    num_input_singles_files = 1;
    
    // Try to open a singlet fastq file
    // Check singlet output options -s and -v
    // Set input singlet names to
    //   - *.single.fastq or
    //   - *.single1.fastq and *.single2.fastq
    if (!(in_read_file = ss_get_gzFile(utstring_body(in_single1_fq_fn), "r"))) {
        utstring_clear(in_single1_fq_fn);
        utstring_printf(in_single1_fq_fn, "%s.single1.fastq", input->filename[0]);
        utstring_printf(in_single2_fq_fn, "%s.single2.fastq", input->filename[0]);
        num_input_singles_files = 2;
        
        if ((in_read_file = ss_get_gzFile(utstring_body(in_single1_fq_fn), "r")) || (in_read_file = ss_get_gzFile(utstring_body(in_single2_fq_fn), "r"))) {
            singles_flag = 1;   // Two singlet outputs
        } else {
            singles_flag = num_singles->count;  // Number of singlet outputs set by -s parm
            if (inv_singles->count) {
                fprintf(stderr, "Error: Invalid option -v, No input singlet file(s) found. Use -s to select multiple output singlet files.\n");
                exit(EXIT_FAILURE);
            }
        }
    }
    
    if (in_read_file) {
        gzclose(in_read_file);
        if (num_singles->count) {
            fprintf(stderr, "Error: Invalid option -s, Input singlet file(s) found, use -v to change the number of output singlet files.\n");
            exit(EXIT_FAILURE);
        }
    }

    // singles->count inverts the current singles file input scheme
    singles_flag = (singles_flag ^ inv_singles->count);
    
    // Check if input fastq is colorspace
    // If some files are colorspace and some are basespace, throw an error
    int fcount = 0;
    int cscount = 0;
    fcount += ss_is_fastq(utstring_body(in_read1_fq_fn));
    fcount += ss_is_fastq(utstring_body(in_read2_fq_fn));
    fcount += ss_is_fastq(utstring_body(in_single1_fq_fn));
    fcount += ss_is_fastq(utstring_body(in_single2_fq_fn));
    cscount += (ss_is_fastq(utstring_body(in_read1_fq_fn)) && ss_is_colorspace_fastq(utstring_body(in_read1_fq_fn)));
    cscount += (ss_is_fastq(utstring_body(in_read2_fq_fn)) && ss_is_colorspace_fastq(utstring_body(in_read2_fq_fn)));
    cscount += (ss_is_fastq(utstring_body(in_single1_fq_fn)) && ss_is_colorspace_fastq(utstring_body(in_single1_fq_fn)));
    cscount += (ss_is_fastq(utstring_body(in_single2_fq_fn)) && ss_is_colorspace_fastq(utstring_body(in_single2_fq_fn)));
    
    if (cscount && (cscount != fcount)) {        
        printf("Error: Mixed colorspace and basespace FASTQ files detected\n");
        exit(EXIT_FAILURE);
    }
    colorspace_flag = cscount ? 1 : 0;
    
    // Output filenames
    
    if (fasta->count) {
        ss_strcat_utstring(out_filetype, "fasta");
        read_count_divisor = 2;
    } else {
        ss_strcat_utstring(out_filetype, "fastq");
        read_count_divisor = 4;
    }
    
    if (!only_mates->count) {
        utstring_printf(out_read1_fn, "%s.read1.%s", output->filename[0], utstring_body(out_filetype));
        utstring_printf(out_read2_fn, "%s.read2.%s", output->filename[0], utstring_body(out_filetype));
    }
    
    if (singles_flag == 1) {
        utstring_printf(out_single1_fn, "%s.single1.%s", output->filename[0], utstring_body(out_filetype));
        utstring_printf(out_single2_fn, "%s.single2.%s", output->filename[0], utstring_body(out_filetype));
    } else {
        utstring_printf(out_single1_fn, "%s.single.%s", output->filename[0], utstring_body(out_filetype));
    }

    if (mates->count) {
        utstring_printf(out_mates_fn, "%s.mates.%s", output->filename[0], utstring_body(out_filetype));
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////
    // Begin processing!
    
#ifdef _OPENMP    
    omp_set_num_threads(10);
#endif    
    
    // This is the value of a non-valid pipe descriptor    
#define NO_PIPE 0
    
    int r1_pipe[2];
    int r2_pipe[2];
    int s1_pipe[2];
    int s2_pipe[2];
    pipe(r1_pipe);
    pipe(r2_pipe);
    pipe(s1_pipe);
    pipe(s2_pipe);
    
    int r1_out_pipe[2];
    int r2_out_pipe[2];
    int mates_out_pipe[2];
    int s1_out_pipe[2];
    int s2_out_pipe[2];
    pipe(r1_out_pipe);
    pipe(r2_out_pipe);
    pipe(mates_out_pipe);
    pipe(s1_out_pipe);
    pipe(s2_out_pipe);
    
    
#pragma omp parallel sections default(shared)       
    {
        
#pragma omp section 
        {   // Read1 reader
            fq_stream_trimmer(in_read1_fq_fn, r1_pipe[1], out_read_prefix, no_pre->count, pre_read_len->count, &comp_r1, &R1_org, '\0', fasta->count);
        }
        
#pragma omp section 
        {   // Read1 writer
            R1_cnt = ss_stream_writer(out_read1_fn, r1_out_pipe[0], gzip->count) / read_count_divisor;
        }
        
#pragma omp section 
        {   // Read2 reader
            fq_stream_trimmer(in_read2_fq_fn, r2_pipe[1], out_read_prefix, no_pre->count, pre_read_len->count, &comp_r2, &R2_org, '\0', fasta->count);
        }
        
#pragma omp section 
        {   // Read2 writer
            R2_cnt = ss_stream_writer(out_read2_fn, r2_out_pipe[0], gzip->count) / read_count_divisor;
        }
        
#pragma omp section 
        {   // Single1 reader
            
            // When there is only one input singles file, but two output singles files, then supply which mate to use for this stream in the split parameter
            if ((singles_flag) && (num_input_singles_files == 1)) {
                singlet1_cnt = fq_stream_trimmer(in_single1_fq_fn, s1_pipe[1], out_read_prefix, no_pre->count, pre_read_len->count, &comp_s1, &singlet1_org, '1', fasta->count);
            } else {
                singlet1_cnt = fq_stream_trimmer(in_single1_fq_fn, s1_pipe[1], out_read_prefix, no_pre->count, pre_read_len->count, &comp_s1, &singlet1_org, '\0', fasta->count);
            }
        }
        
#pragma omp section 
        {   // Single1 writer
            s1_cnt = ss_stream_writer(out_single1_fn, s1_out_pipe[0], gzip->count) / read_count_divisor;
        }
        
#pragma omp section 
        {   // Single2 reader
            
            // When there is only one input singles file, but two output singles files, then supply which mate to use for this stream in the split parameter
            if ((singles_flag) && (num_input_singles_files == 1)) {
                singlet2_cnt = fq_stream_trimmer(in_single1_fq_fn, s2_pipe[1], out_read_prefix, no_pre->count, pre_read_len->count, &comp_s2, &singlet2_org, '2', fasta->count);
            } else {
                singlet2_cnt = fq_stream_trimmer(in_single2_fq_fn, s2_pipe[1], out_read_prefix, no_pre->count, pre_read_len->count, &comp_s2, &singlet2_org, '\0', fasta->count);
            }
        }
        
#pragma omp section 
        {   // Single2 writer
            s2_cnt = ss_stream_writer(out_single2_fn, s2_out_pipe[0], gzip->count) / read_count_divisor;
        }

#pragma omp section 
        {   // Velvet mates writer
            // Divide count by 2 because both R1 and R2 reads go through this writer
            mp_cnt = ss_stream_writer(out_mates_fn, mates_out_pipe[0], gzip->count)  / 2 / read_count_divisor;
        }
        
#pragma omp section 
        {   // Dispatcher

            
            // Allocate data buffer strings
            
            UT_string *r1_data;
            utstring_new(r1_data);
            UT_string *r2_data;
            utstring_new(r2_data);
            UT_string *s1_data;
            utstring_new(s1_data);
            UT_string *s2_data;
            utstring_new(s2_data);
            
            UT_string *rev_tmp;
            utstring_new(rev_tmp);
            
            UT_string *rev_data;
            utstring_new(rev_data);
            
            // Pipes
            FILE *r1_in = fdopen(r1_pipe[0],"r"); 
            FILE *r2_in = fdopen(r2_pipe[0],"r");                 
            
            FILE *s1_in = fdopen(s1_pipe[0],"r");
            FILE *s2_in = fdopen(s2_pipe[0],"r");             

            FILE *mates_out = fdopen(mates_out_pipe[1],"w"); 
            
            FILE *r1_out = fdopen(r1_out_pipe[1],"w"); 
            FILE *r2_out = fdopen(r2_out_pipe[1],"w");                 
            
            FILE *s1_out = fdopen(s1_out_pipe[1],"w");
            FILE *s2_out = fdopen(s2_out_pipe[1],"w");             
            
            if (!singles_flag) {
                fclose(s2_out);
                s2_out = s1_out;
            }
            
            // Flags for data left in single files
            int single1_hungry = 1;
            int single2_hungry = 1;
            
            // Handle read1 and read2 files
            while (ss_get_utstring(r1_in, r1_data)) {
                if (!ss_get_utstring(r2_in, r2_data)) {
                    fprintf(stderr, "Error: Input read1 and read2 files are not synced\n");
                    exit(EXIT_FAILURE);
                }
                if (keep_read(r1_data)) {
                    if (keep_read(r2_data)) {
                        // Output both read1 and read2
                        if (mates->count) {
                            if (only_mates->count) {
                                // Interleaved velvet output only
                                output_read(r1_data, NULL, NULL, r1_in, NULL, mates_out, fasta->count);
                                if (no_rev->count || !colorspace_flag) {
                                    output_read(r2_data, NULL, NULL, r2_in, NULL, mates_out, fasta->count);
                                } else {
                                    output_read(r2_data, rev_data, rev_tmp, r2_in, NULL, mates_out, fasta->count);
                                }
                            } else {
                                // Interleaved velvet output and normal read file output
                                output_read(r1_data, NULL, NULL, r1_in, r1_out, mates_out, fasta->count);
                                if (no_rev->count || !colorspace_flag) {
                                    output_read(r2_data, NULL, NULL, r2_in, r2_out, mates_out, fasta->count);
                                } else {
                                    output_read(r2_data, rev_data, rev_tmp, r2_in, r2_out, mates_out, fasta->count);
                                }
                            }
                        } else {
                            // No interleaved velvet output
                            output_read(r1_data, NULL, NULL, r1_in, r1_out, NULL, fasta->count);
                            output_read(r2_data, NULL, NULL, r2_in, r2_out, NULL, fasta->count);
                        }
                    } else {
                        // Discard read2, output read1 as singlet
                        output_read(r1_data, NULL, NULL, r1_in, s1_out, NULL, fasta->count);
                        read1_singlet_cnt++;
                    }
                } else {
                    if (keep_read(r2_data)) {
                        // Discard read1, output read2 as singlet
                        output_read(r2_data, NULL, NULL, r2_in, s2_out, NULL, fasta->count);
                        read2_singlet_cnt++;
                    }
                }
                
                // Process reads from singles here to take advantage of
                // parallelism
                if (single1_hungry || single2_hungry) {
                    if (single1_hungry) {
                        if (ss_get_utstring(s1_in, s1_data)) {
                            if (keep_read(s1_data)) {
                                output_read(s1_data, NULL, NULL, s1_in, s1_out, NULL, fasta->count);
                            }
                        } else {
                            single1_hungry = 0;
                        }
                    }
                    if (single2_hungry) {
                        if (ss_get_utstring(s2_in, s2_data)) {
                            if (keep_read(s2_data)) {
                                output_read(s2_data, NULL, NULL, s2_in, s2_out, NULL, fasta->count);
                            }
                        } else {
                            single2_hungry = 0;
                        }
                    }
                }
            }
            
            while (single1_hungry || single2_hungry) {
                if (single1_hungry) {
                    if (ss_get_utstring(s1_in, s1_data)) {
                        if (keep_read(s1_data)) {
                            output_read(s1_data, NULL, NULL, s1_in, s1_out, NULL, fasta->count);
                        }
                    } else {
                        single1_hungry = 0;
                    }
                }
                if (single2_hungry) {
                    if (ss_get_utstring(s2_in, s2_data)) {
                        if (keep_read(s2_data)) {
                            output_read(s2_data, NULL, NULL, s2_in, s2_out, NULL, fasta->count);
                        }
                    } else {
                        single2_hungry = 0;
                    }
                }
            }
            
            fclose(r1_in);
            fclose(r2_in);
            
            fclose(s1_in);
            fclose(s2_in);
            
            fclose(mates_out);
            
            fclose(r1_out);
            fclose(r2_out);
            
            fclose(s1_out);
            
            if (singles_flag) {
                fclose(s2_out);
            }
            
            // Free buffers
            utstring_free(r1_data);
            utstring_free(r2_data);
            utstring_free(s1_data);
            utstring_free(s2_data);
            utstring_free(rev_tmp);
            utstring_free(rev_data);
        }
    }

    if (!(R1_org+singlet1_org+singlet2_org)) {
    
        fprintf(stderr, "ERROR! No reads found in input files, or input(s) not found.\n");
        exit(EXIT_FAILURE);
    
    }
    
    if (R1_org != R2_org) {
        fprintf(stderr, "\nWarning! read1 and read2 fastq files did not contain an equal number of reads. %lu %lu\n", R1_org, R2_org);
    }
    
    if ((R1_org + R2_org) && !(singlet1_cnt + singlet2_cnt)) {
        fprintf(stderr, "\nWarning! read1/read2 files were processed, but no corresponding input singlets were found.\n");
    } 
    
    if (entropy->count) {
        printf("\nLow complexity reads discarded: Read1: %lu, Read2: %lu, Singlets: %lu %lu\n", comp_r1, comp_r2, comp_s1, comp_s2);
    }

    mp_org = R1_org;
    if (!only_mates->count) {
        mp_cnt = R1_cnt;
    }
    
    printf("\nMatepairs: Before: %lu, After: %lu\n", mp_org, mp_cnt);
    printf("Singlets: Before: %lu %lu After: %lu %lu\n", singlet1_org, singlet2_org, s1_cnt, s2_cnt);
    printf("Read1 singlets: %lu, Read2 singlets: %lu, Original singlets: %lu %lu\n", read1_singlet_cnt, read2_singlet_cnt, singlet1_cnt, singlet2_cnt);
    printf("Total Reads Processed: %lu, Reads retained: %lu\n", 2*mp_org+singlet1_org+singlet2_org, 2*mp_cnt+s1_cnt+s2_cnt);
    
    utstring_free(in_read1_fq_fn);
    utstring_free(in_read2_fq_fn);
    utstring_free(in_single1_fq_fn);
    utstring_free(in_single2_fq_fn);
    utstring_free(out_read1_fn);
    utstring_free(out_read2_fn);
    utstring_free(out_single1_fn);
    utstring_free(out_single2_fn);
    utstring_free(out_mates_fn);
    utstring_free(out_filetype);
    
    utstring_free(out_read_prefix);
    
    exit(EXIT_SUCCESS);
}
Example #6
0
int main(int argc, char* argv[])
{
    struct arg_lit *help, *strip;
    struct arg_file *input, *output;
    struct arg_str *translation, *rotation;
    struct arg_dbl *scale;
    struct arg_end *end;

    /* command line parsing through argtable package */
    void* argtable[] = {
        help        = arg_lit0("h", "help", "display this help and exit"),
        input       = arg_file0("i", "input", "input", "name of the input file (default stdin"),
        output      = arg_file0("o", "output", "file", "name of the output file (default stdout)"),
        strip       = arg_lit0(NULL, "strip", "remove numbers from the atom labels"),
        scale       = arg_dbl0(NULL, "scale", "scalar", "scale with a factor s"),
        translate   = arg_str0(NULL, "translate", "\"x y z\"", "translate along vector x y z"),
        rotate      = arg_str0(NULL, "rotate", "\"x y z w\"", "rotate w degrees around axis x y z"),
        end         = arg_end(20) };
    const char* progname = "xyztk-rotate";
    int rc = 0;
    int nerrors;

    /* verify the argtable[] entries were allocated sucessfully */
    if (arg_nullcheck(argtable) != 0)
        {
        /* NULL entries were detected, some allocations must have failed */
        printf("%s: insufficient memory\n", progname);
        rc=1;
        goto exit;
        }

    /* set default values */
    scale->dval[0] = 1.0;

    /* parse the command line flags, overriding default values */
    nerrors = arg_parse(argc,argv,argtable);

    /* special case: '--help' takes precedence over error reporting */
    if (help->count > 0)
        {
        printf("Usage: %s", progname);
        arg_print_syntax(stdout,argtable,"\n");
        printf("\n");
        arg_print_glossary(stdout,argtable,"  %-40s %s\n");
        printf("\n");
        rc=0;
        goto exit;
        }

    /* special case: no command line options induces brief help */
    if (argc==1) {
        printf("Try '%s --help' for more information.\n",progname);
        rc=0;
        goto exit;
    }

    /* If the parser returned any errors then display them and exit */
    if (nerrors > 0)
        {
        /* Display the error details contained in the arg_end struct.*/
        arg_print_errors(stdout,end,progname);
        printf("Try '%s --help' for more information.\n",progname);
        rc=1;
        goto exit;
        }

    /* set global structures */

    /* initialize I/O pointers */
    FILE* in;
    if (input->count) {
      in = fopen(input->filename[0], "r");
    } else {
      in = stdin;
    }

    FILE* out;
    if (output->count) {
      out = fopen(output->filename[0], "w");
    } else {
      out = stdout;
    }

    /* initialize molecule structure */
    xyztk_molecule_t molecule;
    xyztk_molecule_load (&molecule, in);


    /* read rotation from string */
    xyztk_quat_t r;
    sscanf (rotation->sval[0], "%lf%lf%lf%lf", &r.x, &r.y, &r.z, &r.w);
    xyztk_molecule_rotate (&molecule, &r);

    /* print output */
    int i;
    fprintf(out, "%d\n", molecule.n_atoms);
    fprintf(out, "%s", molecule.name);
    for (i = 0; i < molecule.n_atoms; ++i)
      {
      fprintf(out, "%-8s %20.14lf %20.14lf %20.14lf \n",
	      molecule.label[i].s, molecule.coord[i].x, molecule.coord[i].y, molecule.coord[i].z);
      }

exit:
    /* deallocate each non-null entry in argtable[] */
    arg_freetable(argtable,sizeof(argtable)/sizeof(argtable[0]));

    return rc;
}
Example #7
0
int main(int argc, char** argv)
{
    // force routine can appear at most once --> arg_str0
    struct arg_str* arg_force_routine
        = arg_str0("f", "force", "<string>",
                   "Specify the force subroutine.\n"
                   "                             - N2         N2 refrence\n"
                   "                             - cell_ref   Cell-list refrence\n"
                   "                             - cell_v1    Cell-list improvement 1\n"
                   "                             - cell_v2    Cell-list improvement 2\n"
                   "                             - knuth      Cell-list (Knuth)\n"
                   "                             - q          Quadrant\n"
                   "                             - q_g        Quadrant (ghost)\n"
                   "                             - q_g_u      Quadrant (ghost unrolled)\n"
                   "                             - q_g_avx    Quadrant (ghost-avx)\n"
                   "                             - q_g_fma    Quadrant (ghost-fma)");

    // integrator routine can appear at most once --> arg_str0
    struct arg_str* arg_integrator_routine
        = arg_str0("i", "integrator", "<string>",
                   "Specify the integrator subroutine.\n"
                   "                             - lf         Leap-frog (refrence)\n"
                   "                             - lf2        Leap-frog (unroll x2)\n"
                   "                             - lf4        Leap-frog (unroll x4)\n"
                   "                             - lf8        Leap-frog (unroll x8)\n"
                   "                             - lf_avx     Leap-frog (avx)");
    // periodic routine
    struct arg_str* arg_periodic_routine
        = arg_str0("p", "periodic", "<string>",
                   "Specify the periodic subroutine.\n"
                   "                             - ref        Refrence implementation\n"
                   "                             - c          With assumption\n"
                   "                             - c4         With assumption (unroll x4)");
    // parameter can appear at most once --> arg_file0
    struct arg_file* arg_parameters
        = arg_file0("c", "config", "<file>", "Path to to the configuration file.");

    // contains the number of desired particles
    struct arg_int* arg_desired_particles
        = arg_int0("n", "N", "<int>", "Set the number of particles.");

    // contains the number of desired timesteps
    struct arg_int* arg_desired_steps
        = arg_int0("s", "step", "<int>", "Set the number of timesteps.");

    // contains the number of desired timesteps
    struct arg_dbl* arg_desired_density
        = arg_dbl0("r", "rho", "<flaot>", "Set the particle density.");

    // help
    struct arg_lit* arg_help = arg_lit0("h", "help", "Print this help statement and exit.");
    // verbosity
    struct arg_int* arg_verb
        = arg_int0("v", "verbose", "<int>",
                   "Set verbosity level.\n"
                   "                             - 0:  Only print timers in the end\n"
                   "                             - 1:  Print settings (default)\n"
                   "                             - 2:  Full output (print energies every step)");

    // maximal number of errors = 20
    struct arg_end* end_struct = arg_end(20);

    void* argtable[] = {arg_force_routine,
                        arg_integrator_routine,
                        arg_periodic_routine,
                        arg_parameters,
                        arg_desired_particles,
                        arg_desired_steps,
                        arg_desired_density,
                        arg_help,
                        arg_verb,
                        end_struct};

    char* progname = "molec";
    // verify the argtable[] entries were allocated sucessfully
    if(arg_nullcheck(argtable) != 0)
    {
        // NULL entries were detected, some allocations must have failed
        printf("%s: insufficient memory\n", progname);
        exit(1);
    }

    // set any command line default values prior to parsing
    arg_force_routine->sval[0] = "cell_ref";
    arg_integrator_routine->sval[0] = "lf";
    arg_periodic_routine->sval[0] = "ref";
    arg_parameters->filename[0] = "";
    arg_desired_particles->ival[0] = 1000;
    arg_desired_steps->ival[0] = 100;
    arg_desired_density->dval[0] = 1.25f;
    arg_verb->ival[0] = 1;

    // parse argtable
    int nerrors = arg_parse(argc, argv, argtable);
    // special case: '--help | -h' takes precedence over error reporting
    if(arg_help->count > 0)
    {
        printf("Usage: %s", progname);
        arg_print_syntax(stdout, argtable, "\n");
        arg_print_glossary(stdout, argtable, "  %-25s %s\n");
        exit(0);
    }
    if(nerrors > 0)
    {
        // Display the error details contained in the arg_end struct
        arg_print_errors(stdout, end_struct, progname);
        printf("Try '%s --help' for more information.\n", progname);
        exit(1);
    }

    // normal case: take the command line options at face value
    molec_force_calculation force_calculation = arg_get_force_routine(arg_force_routine->sval[0]);
    molec_force_integration force_integration
        = arg_get_integration_routine(arg_integrator_routine->sval[0]);
    molec_periodic periodic = arg_get_periodic_routine(arg_periodic_routine->sval[0]);
    const char* config_file_name = arg_parameters->filename[0];
    const int desired_N = arg_desired_particles->ival[0];
    const float desired_rho = arg_desired_density->dval[0];
    molec_verbose = arg_verb->ival[0];

    srand(42);
    molec_load_parameters(config_file_name, 1, desired_N, desired_rho);

    // set the number of steps
    molec_parameter->Nstep = arg_desired_steps->ival[0];

    // print the used routines passed as argument
    if(molec_verbose)
    {
        printf("\n      ================ MOLEC - Settings ================\n\n");
        printf("      %-20s %10s\n", "Force routine:", arg_force_routine->sval[0]);
        printf("      %-20s %10s\n", "Integrator routine:", arg_integrator_routine->sval[0]);
        printf("      %-20s %10s\n", "Periodic routine:", arg_periodic_routine->sval[0]);
    }

    MOLEC_MEASUREMENT_INIT;

    MOLEC_MEASUREMENT_SIMULATION_START();
    molec_run_simulation(force_calculation, force_integration, periodic);
    MOLEC_MEASUREMENT_SIMULATION_STOP();

    printf("\n");
    MOLEC_MEASUREMENT_PRINT;

    // free memory 
    MOLEC_FREE(molec_parameter);
    MOLEC_MEASUREMENT_FINISH;
    arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
}
Example #8
0
int main(int argc, char * argv[])
{
    struct arg_file * train_file = arg_file1("f", "features", "<filename>", "Training dataset");
    struct arg_file * index_file = arg_file0("x", "index", "<filename>", "Training dataset index");
    struct arg_file * output_index = arg_file0(NULL, "output-index", "<filename>", "Save used index to file");
    struct arg_file * input  = arg_file0("i", "input", "<filename>", "Input dataset in libsvm format");
    struct arg_file * output = arg_file0("o", "output", "<filename>", "");
    struct arg_lit * hist = arg_lit0(NULL, "hist", "");
    struct arg_lit * help   = arg_lit0("h", "help", "Print this help and exit");
    struct arg_int * verbosity = arg_int0 ("v", "verbosity", "{0..4}", "Log verbosity"
            "\nIndex parameters :");
    struct arg_int  * distance = arg_int0("d", "distance", "{1..9}", "Distance metric"
            "\n\t1=L2 (default), 2=L1, 3=MINKOWSKI,\n\t4=MAX, 5=HIST_INTERSECT, 6=HELLLINGER,"
            "\n\t7=CS, 8=KULLBACK_LEIBLER, 9=HAMMING");
    struct arg_int  * index_type = arg_int0("t", "index-type", "{0..5}", "Constructed index type"
            "\n t=0 - linear brute force search"
            "\n t=1 - kd-tree :");
    struct arg_int * kd_tree_count = arg_int0(NULL, "kd-tree-count", "{1..16+}", "Number of parallel trees (default 4)"
            "\n t=2 - k-means :");
    struct arg_int * km_branching  = arg_int0(NULL, "km-branching", "n", "Branching factor (default 32)");
    struct arg_int * km_iterations = arg_int0(NULL, "km-iterations", "n", "Maximum iterations (default 11)");
    struct arg_int * km_centers    = arg_int0(NULL, "km-centers", "{0..2}", "Initial cluster centers"
            "\n\t0=CENTERS_RANDOM (default)\n\t1=CENTERS_GONZALES\n\t2=CENTERS_KMEANSPP");
    struct arg_dbl * km_index      = arg_dbl0(NULL, "km-index", "", "Cluster boundary index (default 0.2)"
            "\n t=3 (default) - kd-tree + k-means"
            "\n t=4 - LSH :");
    struct arg_int * lsh_table_count = arg_int0(NULL, "lsh-table-count", "{0..}", "Number of hash tables");
    struct arg_int * lsh_key_size    = arg_int0(NULL, "lsh-key-size", "{0..}", "Hash key bits");
    struct arg_int * lsh_probe_level = arg_int0(NULL, "lsh-probe-level", "{0..}", "Bit shift for neighboring bucket check"
            "\n t=5 - automatically tuned index :");
    struct arg_dbl * auto_precision       = arg_dbl0(NULL, "auto-precision", "[0,1]", "Expected percentage of exact hits");
    struct arg_dbl * auto_build_weight    = arg_dbl0(NULL, "auto-build-weight", "", "");
    struct arg_dbl * auto_memory_weight   = arg_dbl0(NULL, "auto-memory-weight", "", "");
    struct arg_dbl * auto_sample_fraction = arg_dbl0(NULL, "auto-sample-fraction", "[0,1]", ""
            "\nSearch parameters :");
    struct arg_int * neighbors = arg_int0("n", "neighbors", "n", "Neighbor count (default 1)");
    struct arg_dbl * radius    = arg_dbl0("r", "radius", "r", "Search radius, requests radius search");
    struct arg_int * checks    = arg_int0("c", "checks", "...", "Search checks (default 32)");
    struct arg_end * end = arg_end(20);
    void * argtable[] = {
       train_file, index_file, output_index, input, output, hist, help, verbosity,
       distance, index_type, kd_tree_count,
       km_branching, km_iterations, km_centers, km_index,
       lsh_table_count, lsh_key_size, lsh_probe_level,
       auto_precision, auto_build_weight, auto_memory_weight, auto_sample_fraction,
       neighbors, radius, checks, end };
    if(arg_nullcheck(argtable) != 0)
    {
        fprintf(stderr, "%s: insufficient memory\n", argv[0]);
        return EXIT_FAILURE;
    }
    // -- Defaults --
    verbosity->ival[0] = 0;
    distance->ival[0] = 1;//L2
    index_type->ival[0] = 3;//kd + km
    // kd-tree
    kd_tree_count->ival[0] = 4;
    // k-means
    km_branching ->ival[0] = 32;
    km_iterations->ival[0] = 11;
    km_centers   ->ival[0] = 0;//CENTERS_RANDOM
    km_index     ->dval[0] = 0.2;
    // auto
    auto_precision      ->dval[0] = 0.9;
    auto_build_weight   ->dval[0] = 0.01;
    auto_memory_weight  ->dval[0] = 0;
    auto_sample_fraction->dval[0] = 0.1;
    // search
    neighbors->ival[0] = 1;
    checks->ival[0] = 32;
    // -- Parse --
    int arg_errors = arg_parse(argc, argv, argtable);
    if(help->count > 0)
    {
        printf("Usage: %s", argv[0]);
        arg_print_syntax(stdout, argtable, "\n");
        arg_print_glossary(stdout, argtable,"  %-25s %s\n");
        return EXIT_SUCCESS;
    }
    if(arg_errors > 0)
    {
        arg_print_errors(stderr, end, argv[0]);
        fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
        return EXIT_FAILURE;
    }

    cvflann::log_verbosity(verbosity->ival[0]);

    std::cout << "Loading features '" << train_file->filename[0] << "' ..." << std::flush;

    auto train = load(train_file->filename[0]);

    cv::Mat_<float> mat = cv::Mat_<float>::zeros(train.data.size(), train.dim);

    boost::dynamic_bitset<> train_class_set;
    std::vector<size_t> train_class_hist;
    for(size_t i = 0; i < train.data.size(); ++i)
    {
        size_t const c = train.data[i].first;
        if(c >= train_class_set.size())
        {
            train_class_set.resize(c+1);
            train_class_hist.resize(c+1, 0);
        }
        train_class_set.set(c);
        train_class_hist[c] += 1;

        for(auto p : train.data[i].second)
            mat(i, p.first-1) = p.second;
    }

    std::cout << " OK\n"
        "\tdata : " << train.data.size() << 'x' << train.dim << ", " << train_class_set.count() << " classes\n";
    if(hist->count > 0)
    {
        std::cout << "\thistogram :\n";
        for(size_t i = 0; i < train_class_set.size(); ++i)
            std::cout << '\t' << i << " : " << train_class_hist[i] << " (" << (100.*train_class_hist[i]/train.data.size()) << "%)\n";
    }

    // -- Index --

    cv::flann::Index index;
    if(index_file->count > 0)
    {
        std::cout << "Loading index '" << index_file->filename[0] << "' ..." << std::flush;
        if(!index.load(mat, index_file->filename[0]))
        {
            fprintf(stderr, "Can't load index '%s'.\n", index_file->filename[0]);
            return EXIT_SUCCESS;
        }
    }
    else
    {
        std::cout << "Building index ..." << std::flush;
        // Parameters
        std::unique_ptr<cv::flann::IndexParams> params;
        switch(index_type->ival[0])
        {
            case 0 : // linear brute force search
                params = std::make_unique<cv::flann::LinearIndexParams>();
                break;
            case 1 : // k-d tree
                params = std::make_unique<cv::flann::KDTreeIndexParams>(
                    kd_tree_count->ival[0]);
                break;
            case 2 : // k-means 
                params = std::make_unique<cv::flann::KMeansIndexParams>(
                    km_branching ->ival[0],
                    km_iterations->ival[0],
                    static_cast<cvflann::flann_centers_init_t>(km_centers->ival[0]),
                    km_index->dval[0]);
                break;
            case 3 : // k-d tree + k-means
                params = std::make_unique<cv::flann::CompositeIndexParams>(
                    kd_tree_count->ival[0],
                    km_branching ->ival[0],
                    km_iterations->ival[0],
                    static_cast<cvflann::flann_centers_init_t>(km_centers->ival[0]),
                    km_index->dval[0]);
                break;
            case 4 : // lsh
                if((lsh_table_count->count == 0) || (lsh_key_size == 0) || (lsh_probe_level == 0))
                {
                    std::cerr << "For t=4, lsh-table-count, lsh-key-size and lsh-probe-level must be set.\n";
                    return EXIT_FAILURE;
                }
                params = std::make_unique<cv::flann::LshIndexParams>(
                    lsh_table_count->ival[0],
                    lsh_key_size   ->ival[0],
                    lsh_probe_level->ival[0]);
                break;
            case 5 : // autotuned index
                params = std::make_unique<cv::flann::AutotunedIndexParams>(
                    auto_precision      ->dval[0],
                    auto_build_weight   ->dval[0],
                    auto_memory_weight  ->dval[0],
                    auto_sample_fraction->dval[0]);
                break;
            default :
                std::cerr << "Unknown index type " << index_type->ival[0] << std::endl;
                return EXIT_FAILURE;
        }
        index.build(mat, *params, static_cast<cvflann::flann_distance_t>(distance->ival[0]));
    }
    std::cout << " OK\n";

    if(output_index->count > 0)
    {
        std::cout << "Saving index '" << output_index->filename[0] << "' ..." << std::flush;
        index.save(output_index->filename[0]);
        std::cout << " OK\n";
    }

    // -- Query --

    if(input->count > 0)
    {
        std::cout << "Loading query '" << input->filename[0] << "' ..." << std::flush;

        auto test = load(input->filename[0]);

        boost::dynamic_bitset<> test_class_set(train_class_set.size());
        std::vector<size_t> test_class_hist(train_class_set.size());
        for(size_t i = 0; i < test.data.size(); ++i)
        {
            size_t const c = test.data[i].first;
            if(c >= test_class_set.size())
            {
                test_class_set.resize(c+1);
                test_class_hist.resize(c+1, 0);
            }
            test_class_set.set(c);
            test_class_hist[c] += 1;
        }

        std::cout << " OK\n"
            "\tdata : " << test.data.size() << 'x' << test.dim << ", " << test_class_set.count() << " classes\n";
        if(!test_class_set.is_subset_of(train_class_set))
            std::cout << "\t!!! " << (test_class_set-train_class_set).count() << " test classes not in training data\n";
        //std::cout << "\thistogram :\n";
        //for(size_t i = 0; i < test_class_set.size(); ++i)
        //    std::cout << '\t' << i << " : " << test_class_hist[i] << " (" << (100.*test_class_hist[i]/test.data.size()) << "%)\n";

        std::cout << "Searching ..." << std::flush;

        cv::flann::SearchParams const params{checks->ival[0]};

        std::ofstream file;
        if(output->count > 0)
        {
            file.open(output->filename[0]);
            if(!file)
            {
                fprintf(stderr, "Can't open output file '%s'\n", output->filename[0]);
                return EXIT_FAILURE;
            }
        }

        auto const n = neighbors->ival[0];
        std::vector<size_t> match_counts(n, 0);
        std::vector<size_t> cumulative_match_counts(n, 0);
        std::vector<size_t> match_hist(n+1, 0);

        namespace acc = boost::accumulators;
        
        std::vector<acc::accumulator_set<double, acc::stats<
            acc::tag::mean, acc::tag::min, acc::tag::max>>> class_matches(test_class_set.size());

        for(size_t i = 0; i < test.data.size(); ++i)
        {
            std::vector<float> query(test.dim, 0);
            std::vector<int  > indices(n);
            std::vector<float> dists(n);

            for(auto p : test.data[i].second)
                query[p.first-1] = p.second;

            if(radius->count > 0)
                index.radiusSearch(query, indices, dists, radius->dval[0], n, params);
            else
                index.knnSearch(query, indices, dists, n, params);

            unsigned matching_neighbors = 0;
            bool found = false;
            file << test.data[i].first;
            for(int j = 0; j < n; ++j)
            {
                file << ' ' << indices[j] << ':' << train.data[indices[j]].first;
                bool ok = abs(test.data[i].first - train.data[indices[j]].first) < 0.1;
                if(ok)
                {
                    ++matching_neighbors;
                    ++match_counts[j];
                }
                found = found || ok;
                if(found)
                    ++cumulative_match_counts[j];
            }
            file << ' ' << matching_neighbors << std::endl;

            ++match_hist[matching_neighbors];

            class_matches[test.data[i].first](matching_neighbors);
        }
        std::cout << " OK\n";

        auto const count = test.data.size();

        for(int i = 0; i < n; ++i)
        {
            std::cout << i << " : " << match_counts[i] << ", total " << cumulative_match_counts[i]
                << " (" << (100.*match_counts[i]/count) << "%, " << (100.*cumulative_match_counts[i]/count) << "%)\n";
        }
        for(int i = 0; i < (n+1); ++i)
        {
            std::cout << i << " : " << match_hist[i] << " (" << (100.*match_hist[i]/count) << "%)\n";
        }

        std::cout << "Class matches :\n";
        for(size_t i = 0; i < class_matches.size(); ++i)
        {
            auto const cnt = acc::count(class_matches[i]);
            if(cnt > 0)
            {
                auto const mean = acc::mean(class_matches[i]);
                std::cout << i << " : " << cnt << " (" << (100.*cnt/count) << "%) - "
                    << mean << " (" << (100.*mean/n)
                    << "%) in [" << acc::min(class_matches[i]) << ',' << acc::max(class_matches[i]) << "]\n";
            }
        }
    }
    return EXIT_SUCCESS;
}
Example #9
0
int _tmain(int argc, char* argv[])
{
// determine my process name
_splitpath(argv[0],NULL,NULL,gszProcName,NULL);
#else
int
main(int argc, const char** argv)
{
// determine my process name
CUtility::splitpath((char *)argv[0],NULL,gszProcName);
#endif

int iFileLogLevel;			// level of file diagnostics
int iScreenLogLevel;		// level of file diagnostics
char szLogFile[_MAX_PATH];	// write diagnostics to this file

int Rslt = 0;   			// function result code >= 0 represents success, < 0 on failure
int Idx;

etPMode PMode;				// processing mode

int MinCovBases;				// accept SNPs with at least this number covering bases
double MaxPValue;				// accept SNPs with at most this P-value
int MinSpeciesTotCntThres;		// individual species must have at least this number of total bases at SNP loci to count as SNP - 0 if no threshold
int AltSpeciesMaxCnt;			// only report markers if no other species has more than this number of counts at the putative SNP loci
int MinSpeciesWithCnts;			// only report markers where at least this number of species has SNP at the SNP loci


char szRefGenome[cMaxLenName+1];	// reference genome against which other relative genomes were aligned

int NumRelGenomes;			// number of relative genome names
char *pszRelGenomes[cRRMaxInFileSpecs];  // names of relative genome names

int NumSNPFiles;			// number of input SNP files
char *pszSNPFiles[cRRMaxInFileSpecs];  // input SNP files

int NumAlignFiles;			// number of input alignment files
char *pszAlignFiles[cRRMaxInFileSpecs];  // input alignment files

char szMarkerFile[_MAX_PATH];		// write markers to this file

int NumberOfProcessors;		// number of installed CPUs
int NumThreads;				// number of threads (0 defaults to number of CPUs)

// command line args
struct arg_lit  *help    = arg_lit0("hH","help",                "print this help and exit");
struct arg_lit  *version = arg_lit0("v","version,ver",			"print version information and exit");
struct arg_int *FileLogLevel=arg_int0("f", "FileLogLevel",		"<int>","Level of diagnostics written to logfile 0=fatal,1=errors,2=info,3=diagnostics,4=debug");
struct arg_file *LogFile = arg_file0("F","log","<file>",		"diagnostics log file");

struct arg_int *pmode = arg_int0("m","mode","<int>",		    "Marker processing mode: 0 - default");
struct arg_int *mincovbases=arg_int0("b", "MinCovBases","<int>","Filter out SNPs with less than this number of covering bases (default 5)");
struct arg_dbl *maxpvalue=arg_dbl0("p", "MaxPValue","<dbl>",	"Filter out SNPs with P-Value higher (default 0.05)");

struct arg_int *mintotcntthres = arg_int0("z","mintotcntthres","<int>",	"Species must have at least this number of total bases covering marker loci");
struct arg_int *mincovspecies=arg_int0("Z", "mincovspecies","<int>","Do not report markers unless this minimum number of species have SNP at same loci");
struct arg_int *altspeciesmaxcnt = arg_int0("a","altspeciesmaxcnt","<int>",	"Only report markers if no other species has more than this number of counts at the putative SNP loci (defaults to 1)");

struct arg_str *refgenome=arg_str1("r", "refgenome","<str>",	 "alignments and SNPs of relative genomes were against this genome assembly (default 'RefGenome')");
struct arg_str *relgenomes = arg_strn("R","relgenomes","<relgenomes>",1,cRRMaxInFileSpecs,"alignments and SNPs from these genomes");
struct arg_file *snpfiles = arg_filen("i","insnps","<file>",1,cRRMaxInFileSpecs,"Load SNPs from file(s)");
struct arg_file *alignfiles = arg_filen("I","inaligns","<file>",1,cRRMaxInFileSpecs,"Load alignments from file(s)");

struct arg_file *markerfile = arg_file1("o","out","<file>",		"Output markers to this file");

struct arg_int *threads = arg_int0("T","threads","<int>",		"number of processing threads 0..128 (defaults to 0 which sets threads to number of CPU cores)");
struct arg_end *end = arg_end(100);

void *argtable[] = {help,version,FileLogLevel,LogFile,
	pmode,mincovbases,maxpvalue,mintotcntthres,altspeciesmaxcnt,mincovspecies,refgenome,relgenomes,snpfiles,alignfiles,markerfile,threads,
	end};
char **pAllArgs;
int argerrors;
argerrors = CUtility::arg_parsefromfile(argc,(char **)argv,&pAllArgs);
if(argerrors >= 0)
	argerrors = arg_parse(argerrors,pAllArgs,argtable);

/* special case: '--help' takes precedence over error reporting */
if (help->count > 0)
        {
		printf("\n%s Generate Markers, Version %s\nOptions ---\n", gszProcName,cpszProgVer);
        arg_print_syntax(stdout,argtable,"\n");
        arg_print_glossary(stdout,argtable,"  %-25s %s\n");
		printf("\nNote: Parameters can be entered into a parameter file, one parameter per line.");
		printf("\n      To invoke this parameter file then precede its name with '@'");
		printf("\n      e.g. %s @myparams.txt\n",gszProcName);
		printf("\nPlease report any issues regarding usage of %s at https://github.com/csiro-crop-informatics/biokanga/issues\n\n",gszProcName);
		exit(1);
        }

    /* special case: '--version' takes precedence error reporting */
if (version->count > 0)
        {
		printf("\n%s Version %s\n",gszProcName,cpszProgVer);
		exit(1);
        }

if (!argerrors)
	{
	if(FileLogLevel->count && !LogFile->count)
		{
		printf("\nError: FileLogLevel '-f%d' specified but no logfile '-F<logfile>\n'",FileLogLevel->ival[0]);
		exit(1);
		}

	iScreenLogLevel = iFileLogLevel = FileLogLevel->count ? FileLogLevel->ival[0] : eDLInfo;
	if(iFileLogLevel < eDLNone || iFileLogLevel > eDLDebug)
		{
		printf("\nError: FileLogLevel '-l%d' specified outside of range %d..%d\n",iFileLogLevel,eDLNone,eDLDebug);
		exit(1);
		}

	if(LogFile->count)
		{
		strncpy(szLogFile,LogFile->filename[0],_MAX_PATH);
		szLogFile[_MAX_PATH-1] = '\0';
		}
	else
		{
		iFileLogLevel = eDLNone;
		szLogFile[0] = '\0';
		}

	// now that log parameters have been parsed then initialise diagnostics log system
	if(!gDiagnostics.Open(szLogFile,(etDiagLevel)iScreenLogLevel,(etDiagLevel)iFileLogLevel,true))
		{
		printf("\nError: Unable to start diagnostics subsystem\n");
		if(szLogFile[0] != '\0')
			printf(" Most likely cause is that logfile '%s' can't be opened/created\n",szLogFile);
		exit(1);
		}

	gDiagnostics.DiagOut(eDLInfo,gszProcName,"Version: %s",cpszProgVer);

	PMode = (etPMode)(pmode->count ? pmode->ival[0] : ePMdefault);
	if(PMode < ePMdefault || PMode >= ePMplaceholder)
		{
		gDiagnostics.DiagOut(eDLFatal,gszProcName,"Error: Processing mode '-m%d' specified outside of range %d..%d\n",PMode,ePMdefault,(int)ePMplaceholder-1);
		exit(1);
		}

#ifdef _WIN32
	SYSTEM_INFO SystemInfo;
	GetSystemInfo(&SystemInfo);
	NumberOfProcessors = SystemInfo.dwNumberOfProcessors;
#else
	NumberOfProcessors = sysconf(_SC_NPROCESSORS_CONF);
#endif
	int MaxAllowedThreads = min(cMaxWorkerThreads,NumberOfProcessors);	// limit to be at most cMaxWorkerThreads
	if((NumThreads = threads->count ? threads->ival[0] : MaxAllowedThreads)==0)
		NumThreads = MaxAllowedThreads;
	if(NumThreads < 0 || NumThreads > MaxAllowedThreads)
		{
		gDiagnostics.DiagOut(eDLWarn,gszProcName,"Warning: Number of threads '-T%d' specified was outside of range %d..%d",NumThreads,1,MaxAllowedThreads);
		gDiagnostics.DiagOut(eDLWarn,gszProcName,"Warning: Defaulting number of threads to %d",MaxAllowedThreads);
		NumThreads = MaxAllowedThreads;
		}

	MinCovBases = mincovbases->count ? mincovbases->ival[0] : 5;
	if(MinCovBases < 1 || MinCovBases > 10000)
		{
		gDiagnostics.DiagOut(eDLFatal,gszProcName,"Error: Minimum covering bases '-b%d' must be in range 1..1000",MinCovBases);
		exit(1);
		}

	AltSpeciesMaxCnt = altspeciesmaxcnt->count ? altspeciesmaxcnt->ival[0] : 1;
	if(AltSpeciesMaxCnt < 1 || AltSpeciesMaxCnt > 10000)
		{
		gDiagnostics.DiagOut(eDLFatal,gszProcName,"Error: Max alternative species coverage '-a%d' at putative marker loci must be in range 1..1000",AltSpeciesMaxCnt);
		exit(1);
		}


	MaxPValue = maxpvalue->count ? maxpvalue->dval[0] : 0.05;
	if(MaxPValue < 0.0 || MaxPValue > 0.25)
		{
		gDiagnostics.DiagOut(eDLFatal,gszProcName,"Error: Maximum P-Value '-p%1.4f' must be in range 0.0..0.25",MaxPValue);
		exit(1);
		}

	if(refgenome->count)
		{
		strncpy(szRefGenome,refgenome->sval[0],cMaxLenName);
		szRefGenome[cMaxLenName-1]= '\0';
		}
	else
		strcpy(szRefGenome,"RefGenome");

	if(!relgenomes->count)
		{
		gDiagnostics.DiagOut(eDLFatal,gszProcName,"Error: No alignment from genome name(s) specified with with '-R<relgenomes>' option)");
		exit(1);
		}
	for(NumRelGenomes=Idx=0;NumRelGenomes < cRRMaxInFileSpecs && Idx < relgenomes->count; Idx++)
		{
		pszRelGenomes[Idx] = NULL;
		if(pszRelGenomes[NumRelGenomes] == NULL)
			pszRelGenomes[NumRelGenomes] = new char [_MAX_PATH];
		strncpy(pszRelGenomes[NumRelGenomes],relgenomes->sval[Idx],_MAX_PATH);
		pszRelGenomes[NumRelGenomes][_MAX_PATH-1] = '\0';
		CUtility::TrimQuotedWhitespcExtd(pszRelGenomes[NumRelGenomes]);
		if(pszRelGenomes[NumRelGenomes][0] != '\0')
			NumRelGenomes++;
		}


	strncpy(szMarkerFile,markerfile->filename[0],_MAX_PATH);
	szMarkerFile[_MAX_PATH-1] = '\0';

	if(!snpfiles->count)
		{
		gDiagnostics.DiagOut(eDLFatal,gszProcName,"Error: No input SNP file(s) specified with with '-i<filespec>' option)");
		exit(1);
		}

	for(NumSNPFiles=Idx=0;NumSNPFiles < cRRMaxInFileSpecs && Idx < snpfiles->count; Idx++)
		{
		pszSNPFiles[Idx] = NULL;
		if(pszSNPFiles[NumSNPFiles] == NULL)
			pszSNPFiles[NumSNPFiles] = new char [_MAX_PATH];
		strncpy(pszSNPFiles[NumSNPFiles],snpfiles->filename[Idx],_MAX_PATH);
		pszSNPFiles[NumSNPFiles][_MAX_PATH-1] = '\0';
		CUtility::TrimQuotedWhitespcExtd(pszSNPFiles[NumSNPFiles]);
		if(pszSNPFiles[NumSNPFiles][0] != '\0')
			NumSNPFiles++;
		}

	if(!NumSNPFiles)
		{
		gDiagnostics.DiagOut(eDLFatal,gszProcName,"Error: After removal of whitespace, no input SNP file(s) specified with '-i<filespec>' option");
		exit(1);
		}

	if(!alignfiles->count)
		{
		gDiagnostics.DiagOut(eDLFatal,gszProcName,"Error: No input alignment file(s) specified with with '-I<filespec>' option)");
		exit(1);
		}

	for(NumAlignFiles=Idx=0;NumAlignFiles < cRRMaxInFileSpecs && Idx < alignfiles->count; Idx++)
		{
		pszAlignFiles[Idx] = NULL;
		if(pszAlignFiles[NumAlignFiles] == NULL)
			pszAlignFiles[NumAlignFiles] = new char [_MAX_PATH];
		strncpy(pszAlignFiles[NumAlignFiles],alignfiles->filename[Idx],_MAX_PATH);
		pszAlignFiles[NumAlignFiles][_MAX_PATH-1] = '\0';
		CUtility::TrimQuotedWhitespcExtd(pszAlignFiles[NumAlignFiles]);
		if(pszAlignFiles[NumAlignFiles][0] != '\0')
			NumAlignFiles++;
		}

	if(!NumAlignFiles)
		{
		gDiagnostics.DiagOut(eDLFatal,gszProcName,"Error: After removal of whitespace, no input alignment file(s) specified with '-I<filespec>' option");
		exit(1);
		}

	// number of alignment files must be same as the number of SNP files and genome names!
	if(NumAlignFiles != NumSNPFiles && NumAlignFiles != NumRelGenomes)
		{
		gDiagnostics.DiagOut(eDLFatal,gszProcName,"Error: Expected same number of genome names, alignment files and SNP files, %d genome names, %d alignment files, %d SNP files",NumRelGenomes,NumAlignFiles,NumSNPFiles);
		exit(1);
		}
	
	MinSpeciesTotCntThres = mincovspecies->count ? mincovspecies->ival[0] : 1;
	if(MinSpeciesTotCntThres < 1 || MinSpeciesTotCntThres > 10000)
		{
		gDiagnostics.DiagOut(eDLFatal,gszProcName,"Error: Minimum species total bases '-z%d' must be in range 1..10000",MinSpeciesTotCntThres);
		exit(1);
		}

	MinSpeciesWithCnts = mincovspecies->count ? mincovspecies->ival[0] : 1;
	if(MinSpeciesWithCnts < 1 || MinSpeciesWithCnts > NumAlignFiles)
		{
		gDiagnostics.DiagOut(eDLFatal,gszProcName,"Error: Minimum species to call marker '-Z%d' must be in range 1..%d",NumAlignFiles);
		exit(1);
		}

// show user current resource limits
#ifndef _WIN32
	gDiagnostics.DiagOut(eDLInfo, gszProcName, "Resources: %s",CUtility::ReportResourceLimits());
#endif

	gDiagnostics.DiagOut(eDLInfo,gszProcName,"Processing parameters:");
	const char *pszDescr;

	switch(PMode) {
		case ePMdefault:
			pszDescr = "Default marker processing";
			break;
		}

	gDiagnostics.DiagOutMsgOnly(eDLInfo,"Processing mode is : '%s'",pszDescr);

	gDiagnostics.DiagOutMsgOnly(eDLInfo,"Minimum coverage : %d",MinCovBases);
	gDiagnostics.DiagOutMsgOnly(eDLInfo,"Maximum P-Value : %1.4f'",MaxPValue);
	gDiagnostics.DiagOutMsgOnly(eDLInfo,"Reference genome assembly name : '%s'",szRefGenome);

	gDiagnostics.DiagOutMsgOnly(eDLInfo,"Minimum total bases for species at SNP call loci : %d",MinSpeciesTotCntThres);
	gDiagnostics.DiagOutMsgOnly(eDLInfo,"Maximum alternative species coverage at SNP call loci : %d",AltSpeciesMaxCnt);
	gDiagnostics.DiagOutMsgOnly(eDLInfo,"Minimum number of species with SNP call at same loci : %d",MinSpeciesWithCnts);

	for(Idx=0; Idx < NumRelGenomes; Idx++)
		gDiagnostics.DiagOutMsgOnly(eDLInfo,"Alignments and SNPs from this genome (%d) : '%s'",Idx+1,pszRelGenomes[Idx]);

	for(Idx=0; Idx < NumSNPFiles; Idx++)
		gDiagnostics.DiagOutMsgOnly(eDLInfo,"Input SNP file (%d) : '%s'",Idx+1,pszSNPFiles[Idx]);

	for(Idx=0; Idx < NumAlignFiles; Idx++)
		gDiagnostics.DiagOutMsgOnly(eDLInfo,"Input alignment file (%d) : '%s'",Idx+1,pszAlignFiles[Idx]);

	gDiagnostics.DiagOutMsgOnly(eDLInfo,"Output markers to file : '%s'",szMarkerFile);

	gDiagnostics.DiagOutMsgOnly(eDLInfo,"number of threads : %d",NumThreads);

	#ifdef _WIN32
	SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
#endif
	gStopWatch.Start();
	Rslt = Process(PMode,MinCovBases,MaxPValue,MinSpeciesTotCntThres,MinSpeciesWithCnts,AltSpeciesMaxCnt,szRefGenome,NumRelGenomes,pszRelGenomes,NumThreads,NumSNPFiles,pszSNPFiles,NumAlignFiles,pszAlignFiles,szMarkerFile);
	gStopWatch.Stop();
	Rslt = Rslt >=0 ? 0 : 1;
	gDiagnostics.DiagOut(eDLInfo,gszProcName,"Exit code: %d Total processing time: %s",Rslt,gStopWatch.Read());
	exit(Rslt);
	}
else
	{
	printf("\n%s Generate Markers, Version %s\n",gszProcName,cpszProgVer);
	arg_print_errors(stdout,end,gszProcName);
	arg_print_syntax(stdout,argtable,"\nUse '-h' to view option and parameter usage\n");
	exit(1);
	}
return 0;
}
Example #10
0
int _tmain(int argc, char* argv[])
{
// determine my process name
_splitpath(argv[0],NULL,NULL,gszProcName,NULL);
#else
int 
main(int argc, const char** argv)
{
// determine my process name
CUtility::splitpath((char *)argv[0],NULL,gszProcName);
#endif
int iScreenLogLevel;		// level of screen diagnostics
int iFileLogLevel;			// level of file diagnostics
char szLogFile[_MAX_PATH];	// write diagnostics to this file
int Rslt = 0;   			// function result code >= 0 represents success, < 0 on failure

etPMode PMode;				// processing mode
etFMode FMode;				// format output mode

int TruncLength;			// truncate regions to be no longer than this length
int OfsLoci;				// offset region loci by this many bases
int DeltaLen;				// change region lengths by this many bases

int MovAvgFilter;			// apply this moving average window size filter
int BaselineFilter;			// use this window size when normalising for baseline
char szTrackTitle[cMaxDatasetSpeciesChrom];			// title to identify predicted nucleosome track
double Dyadratio;
double Dyad2ratio;
double Dyad3ratio;
char szRsltsFile[_MAX_PATH];
char szInConfFile[_MAX_PATH];
char szInGenomeFile[_MAX_PATH];

char szInclRegionFile[_MAX_PATH]; //  only report predicted nucleosomes if intersecting with regions in this file


// command line args
struct arg_lit  *help    = arg_lit0("hH","help",                "print this help and exit");
struct arg_lit  *version = arg_lit0("v","version,ver",			"print version information and exit");
struct arg_int *FileLogLevel=arg_int0("f", "FileLogLevel",		"<int>","Level of diagnostics written to logfile 0=fatal,1=errors,2=info,3=diagnostics,4=debug");
struct arg_file *LogFile = arg_file0("F","log","<file>",		"diagnostics log file");

struct arg_int *pmode = arg_int0("m","mode","<int>",		    "processing mode: 0 - predict from minor groove (default = 0)");
struct arg_file *inGenomefile = arg_file1("i","in","<file>",	"input from this bioseq genome file");
struct arg_file *inConfFile = arg_file1("I","conf","<file>",	"input conformation characteristics from this file");

struct arg_file *inclRegionFile = arg_file0("r","inclregions","<file>",	"only report predicted nucleosomes if intersecting with regions in this file");
struct arg_int  *trunclength = arg_int0("T","trunclength","<int>","truncate regions to be no longer than this length (default 147)");
struct arg_int  *ofsloci   = arg_int0("u","offset","<int>",	    "offset region loci by this many bases, -2048 to +2048 (default 0)");
struct arg_int  *deltalen  = arg_int0("U","deltalen","<int>",	"delta region lengths by this many bases, -2048 to +2048 (default 0)");

struct arg_dbl *dyadratio=arg_dbl0("d", "dyadratio",	"<double>","dyad minor grooves must be at least this ratio to background (default 1.020");
struct arg_dbl *dyad2ratio=arg_dbl0("D", "dyad2ratio",	"<double>","immediately flanking minor grooves must be at least this ratio to background (default 1.015");
struct arg_dbl *dyad3ratio=arg_dbl0("e", "dyad3ratio",	"<double>","remainder flanking minor grooves must be at least this ratio to background (default 1.010");

struct arg_int *movavgfilter = arg_int0("a","avgwindow","<int>","apply lowpass filter as a moving average window of this size, 0 if none else 5..100 (default: 10)");
struct arg_int *baselinefilter = arg_int0("A","basewindow","<int>","baseline normalisation window size, 0 if none else 25..5000 (default: 250)");

struct arg_file *outfile = arg_file1("o","out","<file>",		"output nucleosome predictions to this file");
struct arg_int *format = arg_int0("M","format","<int>",		    "output format: 0 - UCSC bedGraph dyads, 1 - UCSC BED dyads, 2 - CSV dyads,  3 - UCSC bedGraph nucleosomes, 4 - UCSC BED nucleosomes, 5 - CSV nucleosomes, 6 - CSV scores (default: 0)");
struct arg_str  *title = arg_str0("t","title","<string>",       "track title");

struct arg_end *end = arg_end(20);

void *argtable[] = {help,version,FileLogLevel,LogFile,
					pmode,format,movavgfilter,baselinefilter,title,dyadratio,dyad2ratio,dyad3ratio,inGenomefile,inConfFile,outfile,
					inclRegionFile,trunclength,ofsloci,deltalen,
					end};

char **pAllArgs;
int argerrors;
argerrors = CUtility::arg_parsefromfile(argc,(char **)argv,&pAllArgs);
if(argerrors >= 0)
	argerrors = arg_parse(argerrors,pAllArgs,argtable);

/* special case: '--help' takes precedence over error reporting */
if (help->count > 0)
        {
		printf("\n%s ", gszProcName);
        arg_print_syntax(stdout,argtable,"\n");
        arg_print_glossary(stdout,argtable,"  %-25s %s\n");
		printf("\nNote: Parameters can be entered into a parameter file, one parameter per line.");
		printf("\n      To invoke this parameter file then precede its name with '@'");
		printf("\n      e.g. %s @myparams.txt\n\n",gszProcName);
		exit(1);
        }

    /* special case: '--version' takes precedence error reporting */ 
if (version->count > 0)
        {
		printf("\n%s Version %d.%2.2d",gszProcName,cProgVer/100,cProgVer%100);
		exit(1);
        }

if (!argerrors)
	{
	if(FileLogLevel->count && !LogFile->count)
		{
		printf("\nError: FileLogLevel '-f%d' specified but no logfile '-F<logfile>'",FileLogLevel->ival[0]);
		exit(1);
		}

	iScreenLogLevel = iFileLogLevel = FileLogLevel->count ? FileLogLevel->ival[0] : eDLInfo;
	if(iFileLogLevel < eDLNone || iFileLogLevel > eDLDebug)
		{
		printf("\nError: FileLogLevel '-l%d' specified outside of range %d..%d",iFileLogLevel,eDLNone,eDLDebug);
		exit(1);
		}
	
	if(LogFile->count)
		{
		strncpy(szLogFile,LogFile->filename[0],_MAX_PATH);
		szLogFile[_MAX_PATH-1] = '\0';
		}
	else
		{
		iFileLogLevel = eDLNone;
		szLogFile[0] = '\0';
		}

	PMode = (etPMode)(pmode->count ? pmode->ival[0] : 0);
	if(PMode < 0 || PMode >= ePMplaceholder)
		{
		printf("\nError: Processing mode '-m%d' specified outside of range %d..%d",PMode,0,(int)ePMplaceholder-1);
		exit(1);
		}

	FMode = (etFMode)(format->count ? format->ival[0] : eFMbedGraphDyads);
	if(FMode < eFMbedGraphDyads || FMode >= eFMplaceholder)
		{
		printf("\nError: Output format mode '-m%d' specified outside of range %d..%d",FMode,eFMbedGraphDyads,(int)eFMplaceholder-1);
		exit(1);
		}

		MovAvgFilter = movavgfilter->count ? movavgfilter->ival[0] : 10;
	if(MovAvgFilter != 0 && (MovAvgFilter < 5 || MovAvgFilter > 100))
		{
		printf("\nError: Moving average filter width '-a%d' specified outside of range 0 or 5..100",MovAvgFilter);
		exit(1);
		}


	BaselineFilter = baselinefilter->count ? baselinefilter->ival[0] : 250;
	if(BaselineFilter != 0 && (BaselineFilter < 25 || MovAvgFilter > 5000))
		{
		printf("\nError: Baseline normalisation window width '-A%d' specified outside of range 0 or 25..5000",BaselineFilter);
		exit(1);
		}

	Dyadratio = dyadratio->count ? dyadratio->dval[0] : cDfltDyadratio;
	Dyad2ratio = dyad2ratio->count ? dyad2ratio->dval[0] : cDfltDyad2ratio;
	Dyad3ratio = dyad3ratio->count ? dyad3ratio->dval[0] : cDfltDyad3ratio;
	if(Dyadratio < 1.0f || Dyad2ratio < 1.0f || Dyad3ratio < 1.0f)
		{
		printf("\nError: All dyad and flanking threshold ratios must be at least 1.0");
		exit(1);
		}


	if(!title->count)
		{
		printf("\nError: no track title has been specified with '-t<title>' option");
		exit(1);
		}
	if(strlen(title->sval[0]) >= cMaxDatasetSpeciesChrom)
		{
		printf("\nError: track title '%s' is too long, must be shorter than %d chars",title->sval[0],cMaxDatasetSpeciesChrom-1);
		exit(1);
		}
	strncpy(szTrackTitle,title->sval[0],sizeof(szTrackTitle));
	szTrackTitle[sizeof(szTrackTitle)-1] = '\0';
	CUtility::TrimQuotedWhitespcExtd(szTrackTitle);
	CUtility::ReduceWhitespace(szTrackTitle);
	if(szTrackTitle[0] == '\0')
		{
		printf("\nError: specified track title is empty or whitespace only");
		exit(1);
		}

	strcpy(szInGenomeFile,inGenomefile->filename[0]);
	strcpy(szInConfFile,inConfFile->filename[0]);
	strcpy(szRsltsFile,outfile->filename[0]);

	if(inclRegionFile->count)
		{
		strncpy(szInclRegionFile,inclRegionFile->filename[0],_MAX_PATH);
		szInclRegionFile[_MAX_PATH-1] = '\0';

		OfsLoci = ofsloci->count ? ofsloci->ival[0] : 0;
		if(abs(OfsLoci) > 1024)
			{
			printf("Error: loci offset '-u%d' must be in the range -2048 to +2048",OfsLoci);
			exit(1);
			}

		DeltaLen = deltalen->count ? deltalen->ival[0] : 0;
		if(abs(DeltaLen) > 1024)
			{
			printf("Error: delta length '-U%d' must be in the range -2048 to +2048",DeltaLen);
			exit(1);
			}

		TruncLength = trunclength->count ? trunclength->ival[0] : 147;
		if(TruncLength < 147)
			{
			printf("Error: regions truncation length '-T%d' must be at least 147",TruncLength);
			exit(1);
			}
		}
	else
		{
		szInclRegionFile[0] = '\0';
		OfsLoci = 0;
		DeltaLen = 0;
		TruncLength = 0;
		}
	


		// now that command parameters have been parsed then initialise diagnostics log system
	if(!gDiagnostics.Open(szLogFile,(etDiagLevel)iScreenLogLevel,(etDiagLevel)iFileLogLevel,true))
		{
		printf("\nError: Unable to start diagnostics subsystem.");
		if(szLogFile[0] != '\0')
			printf(" Most likely cause is that logfile '%s' can't be opened/created",szLogFile);
		exit(1);
		}

// show user current resource limits
#ifndef _WIN32
	gDiagnostics.DiagOut(eDLInfo, gszProcName, "Resources: %s",CUtility::ReportResourceLimits());
#endif

	gDiagnostics.DiagOut(eDLInfo,gszProcName,"Version: %d.%2.2d Processing parameters:",cProgVer/100,cProgVer%100);
	const char *pszDescr;
	switch(PMode) {
		case ePMdefault:				
			pszDescr = "Default - predict from minor groove";
			break;
		}

	gDiagnostics.DiagOutMsgOnly(eDLInfo,"processing mode is : '%s'",pszDescr);

	switch(FMode) {
		case eFMbedGraphDyads:				
			pszDescr = "UCSC bedGraph dyads";
			break;
		case eFMbedDyads:					
			pszDescr = "UCSC BED dyads";
			break;
		case eFMcsvDyads:					
			pszDescr = "CSV dyads";
			break;
		case eFMbedGraphNucs:					
			pszDescr = "UCSC bedGraph nucleosomes";
			break;
		case eFMbedNucs:					
			pszDescr = "UCSC BED nucleosomes";
			break;
		case eFMcsvNucs:					
			pszDescr = "CSV nucleosomes";
			break;
		case eFMMcsvScores:					
			pszDescr = "CSV dyad scores along genome";
			break;

		}
	gDiagnostics.DiagOutMsgOnly(eDLInfo,"output format is : '%s'",pszDescr);

	gDiagnostics.DiagOutMsgOnly(eDLInfo,"moving average filter width : %d",MovAvgFilter);
	gDiagnostics.DiagOutMsgOnly(eDLInfo,"baseline noramlisation width : %d",BaselineFilter);

	gDiagnostics.DiagOutMsgOnly(eDLInfo,"dyad name: '%s'",szTrackTitle);

	gDiagnostics.DiagOutMsgOnly(eDLInfo,"dyad minor groove threshold: %1.4f",Dyadratio);
	gDiagnostics.DiagOutMsgOnly(eDLInfo,"dyad immediately flanking minor groove threshold: %1.4f",Dyad2ratio);
	gDiagnostics.DiagOutMsgOnly(eDLInfo,"dyad remainder flanking minor groove threshold: %1.4f",Dyad3ratio);

	gDiagnostics.DiagOutMsgOnly(eDLInfo,"input genome file: '%s'",szInGenomeFile);
	gDiagnostics.DiagOutMsgOnly(eDLInfo,"input conformation file: '%s'",szInConfFile);

	gDiagnostics.DiagOutMsgOnly(eDLInfo,"output predicted nucleosomes file: '%s'",szRsltsFile);
	
	if(szInclRegionFile[0] != '0')
		{
		gDiagnostics.DiagOutMsgOnly(eDLInfo,"Offset region start loci by : %d",OfsLoci);
		gDiagnostics.DiagOutMsgOnly(eDLInfo,"Delta region length by : %d",DeltaLen);
		gDiagnostics.DiagOutMsgOnly(eDLInfo,"Truncate region length: %d",TruncLength);
		gDiagnostics.DiagOutMsgOnly(eDLInfo,"include regions file: '%s'",szInclRegionFile);
		}
#ifdef _WIN32
	SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
#endif
	gStopWatch.Start();
	Rslt = Process(PMode,FMode,MovAvgFilter,BaselineFilter,szTrackTitle,Dyadratio,Dyad2ratio,Dyad3ratio,szInGenomeFile,szInConfFile,szRsltsFile,
									szInclRegionFile,OfsLoci,DeltaLen,TruncLength);
	gStopWatch.Stop();
	Rslt = Rslt >=0 ? 0 : 1;
	gDiagnostics.DiagOut(eDLInfo,gszProcName,"Exit code: %d Total processing time: %s",Rslt,gStopWatch.Read());
	exit(Rslt);
	}
else
	{
	arg_print_errors(stdout,end,gszProcName);
	arg_print_syntax(stdout,argtable,"\nend of help\n");
	exit(1);
	}
return 0;
}