Beispiel #1
0
int bammer_main(args *pars){
  gf=(getFasta *) allMethods[1];
  func = pars->callback;
  std::vector<char *> nams;

  //read bamfiles
  if(pars->inputfiles)
    nams = angsd::getFilenames(pars->inputfiles,pars->nInd);
  else
    nams.push_back(strdup(pars->inputfile));//if only one file just push bamfile
  
  bufReader *rd = initializeBufReaders2(nams);
 
  //read regions

  std::vector<char *> regionsRaw;
  if(pars->regionfile)
    regionsRaw = getRegions(pars->regionfile);
  else if(pars->region!=NULL){
    regionsRaw.push_back(strdup(pars->region));//if only one file just push bamfile
  }
  std::vector<regs> regions;
  for(size_t i=0;i<regionsRaw.size();i++){
    regs tmpRegs;
    if(parse_region(regionsRaw[i],*rd[0].hd,tmpRegs.refID,tmpRegs.start,tmpRegs.stop)<0||tmpRegs.stop<tmpRegs.start){
      fprintf(stderr,"[%s] problems with indexing: %s\n",__FUNCTION__,regionsRaw[i]);
      exit(0);
    }else
      regions.push_back(tmpRegs);
  }

  //printReg(stderr,regions)
  //each filereader contains a filename for a bam, if we try to read remote files, then we need to download the bai file, and update the filename
  if(regions.size()!=0)
    modNames(rd,nams.size());


  extern int maxThreads;

  if(pars->jobtype==2)
    uppile(pars->show,maxThreads,rd,pars->nLines,nams.size(),regions);
  else if(pars->jobtype==1)    	
    while(motherView(rd,nams.size(),regions));
  else{
    fprintf(stderr,"nothing to do? what should program do?\n");
  }

  //cleanup stuff
  for(int i=0;i<(int)nams.size();i++){
    free(nams[i]);
    dalloc_bufReader(rd[i]);

  }
  for(size_t i=0;i<regions.size();i++)
    free(regionsRaw[i]);
  delete [] rd;
  free(pars->inputfiles);free(pars->inputfile);free(pars->region);
  delete pars;
  return 0;
}
Beispiel #2
0
int
parse_data_record (int fd)
{
	struct data_record dr;
	int bytes;

	bytes = read (fd, &dr, sizeof(dr));
	if (bytes == 0)
		return 0;

	switch (dr.type) {
		case DATA_VERSION_TYPE:
			parse_advr (fd, dr.size);
			break;
		case APP_VERSION_TYPE:
			parse_avr (fd, dr.size);
			break;
		case REGION_TYPE:
			parse_region (fd, dr.size);
			break;
		default:
			fprintf (stderr, "Unknown data record type: '%c'\n", dr.type);
			valid = 0;
			return 0;
			break;
	}

	return 1;
}
//read program parameters
void setArgsBam(argStruct *arguments){
  remove_bads = angsd::getArg("-remove_bads",remove_bads,arguments);
  uniqueOnly = angsd::getArg("-uniqueOnly",uniqueOnly,arguments);
  only_proper_pairs =angsd::getArg("-only_proper_pairs",only_proper_pairs,arguments);
  minMapQ = angsd::getArg("-minMapQ",minMapQ,arguments);
  minQ = angsd::getArg("-minQ",minQ,arguments);
  trim = angsd::getArg("-trim",trim,arguments);
  adjustMapQ = angsd::getArg("-C",adjustMapQ,arguments);
  baq = angsd::getArg("-baq",baq,arguments);
  regfile =angsd::getArg("-r",regfile,arguments);
  regfiles = angsd::getArg("-rf",regfiles,arguments);
  checkBamHeaders = angsd::getArg("-checkBamHeaders",checkBamHeaders,arguments);
  arguments->show = angsd::getArg("-show",arguments->show,arguments);

  char *tmp = NULL;
  tmp = angsd::getArg("-ref",tmp,arguments);
  if(tmp==NULL && adjustMapQ!=0){
    fprintf(stderr,"Must also supply -ref for adjusting the mapping quality\n");
    exit(0);
  }
  if(tmp==NULL&&baq!=0){
    fprintf(stderr,"Must also supply -ref for adjusting base qualities (baq)\n");
    exit(0);
  }
  free(tmp);
  
  
  std::vector<char *> regionsRaw;
  if(regfiles)
    regionsRaw =  angsd::getFilenames(regfiles,0);
  
  if(regfile)
    regionsRaw.push_back(regfile);
   
  for(size_t i=0;i<regionsRaw.size();i++){
    regs tmpRegs;
    if(parse_region(regionsRaw[i],arguments->hd,tmpRegs.refID,tmpRegs.start,tmpRegs.stop,arguments->revMap)<0||tmpRegs.stop<tmpRegs.start){
      fprintf(stderr,"[%s] problems with indexing: %s\n",__FUNCTION__,regionsRaw[i]);
      exit(0);
    }else
      arguments->regions.push_back(tmpRegs);
  }



  printArg(arguments->argumentFile,arguments);
  free(regfile);
  free(regfiles);
}
Beispiel #4
0
void parse_world(FILE *fp, World *w)
{
    char tokenbuf[STRING_TOKEN_MAX_LENGTH];

    while (get_string_token(fp, tokenbuf) != Token_EOF) {
        if (strcmp(tokenbuf, "texture") == 0)
            parse_texture(fp, w);
        else if (strcmp(tokenbuf, "wall") == 0)
            parse_wall(fp, w);
        else if (strcmp(tokenbuf, "region") == 0)
            parse_region(fp, w);
        else if (strcmp(tokenbuf, "vertex") == 0)
            parse_vertex(fp, w);
        else
            parse_error("unknown structure type");
    }
}
Beispiel #5
0
//read program parameters
void setArgsBam(argStruct *arguments){
  int seed=0;
  remove_bads = angsd::getArg("-remove_bads",remove_bads,arguments);
  uniqueOnly = angsd::getArg("-uniqueOnly",uniqueOnly,arguments);
  only_proper_pairs =angsd::getArg("-only_proper_pairs",only_proper_pairs,arguments);
   fai_fname =angsd::getArg("-f",fai_fname,arguments);
  minMapQ = angsd::getArg("-minMapQ",minMapQ,arguments);
  cigstat = angsd::getArg("-cigstat",cigstat,arguments);
  minQ = angsd::getArg("-minQ",minQ,arguments);
  downSample = angsd::getArg("-downSample",downSample,arguments);
  seed = angsd::getArg("-seed",seed,arguments);
  trim = angsd::getArg("-trim",trim,arguments);
  trim5 = angsd::getArg("-trim5",trim5,arguments);
  trim3 = angsd::getArg("-trim3",trim3,arguments);
  arguments->ref=angsd::getArg("-ref",arguments->ref,arguments);
  arguments->anc=angsd::getArg("-anc",arguments->anc,arguments);
  rghash_name= angsd::getArg("+RG",rghash_name,arguments);
  if(rghash_name&&!angsd::fexists(rghash_name))
    rghash = add_read_group_single(rghash_name);
  if(rghash_name&&angsd::fexists(rghash_name))
    rghash = add_read_groups_file(rghash_name);
  if(rghash)
    fprintf(stderr,"\t-> [READGROUP info] Number of readgroups to include: %d\n",khash_str2int_size(rghash));
  adjustMapQ = angsd::getArg("-C",adjustMapQ,arguments);
  baq = angsd::getArg("-baq",baq,arguments);
  redo_baq = angsd::getArg("-redo-baq",redo_baq,arguments);
  if(baq){
    if(baq==1)
      baq=1; //wauv
    else if(baq==2)
      baq=3;
    else{
      fprintf(stderr,"\t-> only supported options for -baq is: 1 (normal baq) and 2 (extended baq (SAMtools default)). Value supplied:%d\n",baq);
      exit(0);//ly su
    }
    if(redo_baq==1)
      baq |=4;
  }
  //  fprintf(stderr,"baq:%d redobaq:%d\n",baq,redo_baq);exit(0);
  regfile =angsd::getArg("-r",regfile,arguments);
  regfiles = angsd::getArg("-rf",regfiles,arguments);
  MAX_SEQ_LEN = angsd::getArg("-setMinChunkSize",MAX_SEQ_LEN,arguments);
  checkBamHeaders = angsd::getArg("-checkBamHeaders",checkBamHeaders,arguments);
  doCheck = angsd::getArg("-doCheck",doCheck,arguments);
  MPLP_IGNORE_RG = angsd::getArg("--ignore-RG",MPLP_IGNORE_RG,arguments);
  arguments->nReads = angsd::getArg("-nReads",arguments->nReads,arguments);
  arguments->show = angsd::getArg("-show",arguments->show,arguments);
  if(regfile && regfiles)
    fprintf(stderr,"\t-> WARNING both -r and -rf has been set \n");

  if(seed)
    srand48(seed);
  char *tmp = NULL;
  tmp = angsd::getArg("-ref",tmp,arguments);
  if(tmp==NULL && adjustMapQ!=0){
    fprintf(stderr,"\t-> Must also supply -ref for adjusting the mapping quality\n");
    exit(0);
  }
  if(tmp==NULL&&baq!=0){
    fprintf(stderr,"\t-> Must also supply -ref for adjusting base qualities (baq)\n");
    exit(0);
  }
  free(tmp);
  
  
  std::vector<char *> regionsRaw;
  if(regfiles)
    regionsRaw =  angsd::getFilenames(regfiles,0);
  
  if(regfile)
    regionsRaw.push_back(strdup(regfile));
  //  fprintf(stderr,"\t-> RegionsRaw.size():%lu hd:%p\n",regionsRaw.size(),arguments->hd);
  for(size_t i=0;i<regionsRaw.size();i++){
    regs tmpRegs;
    if(parse_region(regionsRaw[i],arguments->hd,tmpRegs.refID,tmpRegs.start,tmpRegs.stop,arguments->revMap)<0||tmpRegs.stop<tmpRegs.start){
      fprintf(stderr,"[%s] Problems with indexing: %s\n",__FUNCTION__,regionsRaw[i]);
      exit(0);
    }else
      arguments->regions.push_back(tmpRegs);
    free(regionsRaw[i]);
  }



  printArg(arguments->argumentFile,arguments);

  if(regfile)
    free(regfile);
  if(regfiles)
    free(regfiles);

}
Beispiel #6
0
network parse_network_cfg(char *filename)
{
    list *sections = read_cfg(filename);
    node *n = sections->front;
    if(!n) error("Config file has no sections");
    network net = make_network(sections->size - 1);
    net.gpu_index = gpu_index;
    size_params params;

    section *s = (section *)n->val;
    list *options = s->options;
    if(!is_network(s)) error("First section must be [net] or [network]");
    parse_net_options(options, &net);

    params.h = net.h;
    params.w = net.w;
    params.c = net.c;
    params.inputs = net.inputs;
    params.batch = net.batch;
    params.time_steps = net.time_steps;
    params.net = net;

    size_t workspace_size = 0;
    n = n->next;
    int count = 0;
    free_section(s);
    fprintf(stderr, "layer     filters    size              input                output\n");
    while(n){
        params.index = count;
        fprintf(stderr, "%5d ", count);
        s = (section *)n->val;
        options = s->options;
        layer l = {0};
        LAYER_TYPE lt = string_to_layer_type(s->type);
        if(lt == CONVOLUTIONAL){
            l = parse_convolutional(options, params);
        }else if(lt == LOCAL){
            l = parse_local(options, params);
        }else if(lt == ACTIVE){
            l = parse_activation(options, params);
        }else if(lt == RNN){
            l = parse_rnn(options, params);
        }else if(lt == GRU){
            l = parse_gru(options, params);
        }else if(lt == CRNN){
            l = parse_crnn(options, params);
        }else if(lt == CONNECTED){
            l = parse_connected(options, params);
        }else if(lt == CROP){
            l = parse_crop(options, params);
        }else if(lt == COST){
            l = parse_cost(options, params);
        }else if(lt == REGION){
            l = parse_region(options, params);
        }else if(lt == DETECTION){
            l = parse_detection(options, params);
        }else if(lt == SOFTMAX){
            l = parse_softmax(options, params);
            net.hierarchy = l.softmax_tree;
        }else if(lt == NORMALIZATION){
            l = parse_normalization(options, params);
        }else if(lt == BATCHNORM){
            l = parse_batchnorm(options, params);
        }else if(lt == MAXPOOL){
            l = parse_maxpool(options, params);
        }else if(lt == REORG){
            l = parse_reorg(options, params);
        }else if(lt == AVGPOOL){
            l = parse_avgpool(options, params);
        }else if(lt == ROUTE){
            l = parse_route(options, params, net);
        }else if(lt == SHORTCUT){
            l = parse_shortcut(options, params, net);
        }else if(lt == DROPOUT){
            l = parse_dropout(options, params);
            l.output = net.layers[count-1].output;
            l.delta = net.layers[count-1].delta;
#ifdef GPU
            l.output_gpu = net.layers[count-1].output_gpu;
            l.delta_gpu = net.layers[count-1].delta_gpu;
#endif
        }else{
            fprintf(stderr, "Type not recognized: %s\n", s->type);
        }
        l.dontload = option_find_int_quiet(options, "dontload", 0);
        l.dontloadscales = option_find_int_quiet(options, "dontloadscales", 0);
        option_unused(options);
        net.layers[count] = l;
        if (l.workspace_size > workspace_size) workspace_size = l.workspace_size;
        free_section(s);
        n = n->next;
        ++count;
        if(n){
            params.h = l.out_h;
            params.w = l.out_w;
            params.c = l.out_c;
            params.inputs = l.outputs;
        }
    }   
    free_list(sections);
    net.outputs = get_network_output_size(net);
    net.output = get_network_output(net);
    if(workspace_size){
        //printf("%ld\n", workspace_size);
#ifdef GPU
        if(gpu_index >= 0){
            net.workspace = cuda_make_array(0, (workspace_size-1)/sizeof(float)+1);
        }else {
            net.workspace = calloc(1, workspace_size);
        }
#else
        net.workspace = calloc(1, workspace_size);
#endif
    }
    return net;
}
Beispiel #7
0
network *parse_network_cfg(char *filename)
{
    list *sections = read_cfg(filename);
    node *n = sections->front;
    if(!n) error("Config file has no sections");
    network *net = make_network(sections->size - 1);
    net->gpu_index = gpu_index;
    size_params params;

    section *s = (section *)n->val;
    list *options = s->options;
    if(!is_network(s)) error("First section must be [net] or [network]");
    parse_net_options(options, net);

    params.h = net->h;
    params.w = net->w;
    params.c = net->c;
    params.inputs = net->inputs;
    params.batch = net->batch;
    params.time_steps = net->time_steps;
    params.net = net;

    size_t workspace_size = 0;
    n = n->next;
    int count = 0;
    free_section(s);
    fprintf(stderr, "layer     filters    size              input                output\n");
    while(n){
        params.index = count;
        fprintf(stderr, "%5d ", count);
        s = (section *)n->val;
        options = s->options;
        layer l = {0};
        LAYER_TYPE lt = string_to_layer_type(s->type);
        if(lt == CONVOLUTIONAL){
            l = parse_convolutional(options, params);
        }else if(lt == DECONVOLUTIONAL){
            l = parse_deconvolutional(options, params);
        }else if(lt == LOCAL){
            l = parse_local(options, params);
        }else if(lt == ACTIVE){
            l = parse_activation(options, params);
        }else if(lt == LOGXENT){
            l = parse_logistic(options, params);
        }else if(lt == L2NORM){
            l = parse_l2norm(options, params);
        }else if(lt == RNN){
            l = parse_rnn(options, params);
        }else if(lt == GRU){
            l = parse_gru(options, params);
        }else if (lt == LSTM) {
            l = parse_lstm(options, params);
        }else if(lt == CRNN){
            l = parse_crnn(options, params);
        }else if(lt == CONNECTED){
            l = parse_connected(options, params);
        }else if(lt == CROP){
            l = parse_crop(options, params);
        }else if(lt == COST){
            l = parse_cost(options, params);
        }else if(lt == REGION){
            l = parse_region(options, params);
        }else if(lt == YOLO){
            l = parse_yolo(options, params);
        }else if(lt == ISEG){
            l = parse_iseg(options, params);
        }else if(lt == DETECTION){
            l = parse_detection(options, params);
        }else if(lt == SOFTMAX){
            l = parse_softmax(options, params);
            net->hierarchy = l.softmax_tree;
        }else if(lt == NORMALIZATION){
            l = parse_normalization(options, params);
        }else if(lt == BATCHNORM){
            l = parse_batchnorm(options, params);
        }else if(lt == MAXPOOL){
            l = parse_maxpool(options, params);
        }else if(lt == REORG){
            l = parse_reorg(options, params);
        }else if(lt == AVGPOOL){
            l = parse_avgpool(options, params);
        }else if(lt == ROUTE){
            l = parse_route(options, params, net);
        }else if(lt == UPSAMPLE){
            l = parse_upsample(options, params, net);
        }else if(lt == SHORTCUT){
            l = parse_shortcut(options, params, net);
        }else if(lt == DROPOUT){
            l = parse_dropout(options, params);
            l.output = net->layers[count-1].output;
            l.delta = net->layers[count-1].delta;
#ifdef GPU
            l.output_gpu = net->layers[count-1].output_gpu;
            l.delta_gpu = net->layers[count-1].delta_gpu;
#endif
        }else{
            fprintf(stderr, "Type not recognized: %s\n", s->type);
        }
        l.clip = net->clip;
        l.truth = option_find_int_quiet(options, "truth", 0);
        l.onlyforward = option_find_int_quiet(options, "onlyforward", 0);
        l.stopbackward = option_find_int_quiet(options, "stopbackward", 0);
        l.dontsave = option_find_int_quiet(options, "dontsave", 0);
        l.dontload = option_find_int_quiet(options, "dontload", 0);
        l.numload = option_find_int_quiet(options, "numload", 0);
        l.dontloadscales = option_find_int_quiet(options, "dontloadscales", 0);
        l.learning_rate_scale = option_find_float_quiet(options, "learning_rate", 1);
        l.smooth = option_find_float_quiet(options, "smooth", 0);
        option_unused(options);
        net->layers[count] = l;
        if (l.workspace_size > workspace_size) workspace_size = l.workspace_size;
        free_section(s);
        n = n->next;
        ++count;
        if(n){
            params.h = l.out_h;
            params.w = l.out_w;
            params.c = l.out_c;
            params.inputs = l.outputs;
        }
    }
    free_list(sections);
    layer out = get_network_output_layer(net);
    net->outputs = out.outputs;
    net->truths = out.outputs;
    if(net->layers[net->n-1].truths) net->truths = net->layers[net->n-1].truths;
    net->output = out.output;
    net->input = calloc(net->inputs*net->batch, sizeof(float));
    net->truth = calloc(net->truths*net->batch, sizeof(float));
#ifdef GPU
    net->output_gpu = out.output_gpu;
    net->input_gpu = cuda_make_array(net->input, net->inputs*net->batch);
    net->truth_gpu = cuda_make_array(net->truth, net->truths*net->batch);
#endif
    if(workspace_size){
        //printf("%ld\n", workspace_size);
#ifdef GPU
        if(gpu_index >= 0){
            net->workspace = cuda_make_array(0, (workspace_size-1)/sizeof(float)+1);
        }else {
            net->workspace = calloc(1, workspace_size);
        }
#else
        net->workspace = calloc(1, workspace_size);
#endif
    }
    return net;
}
Beispiel #8
0
int main( int argc, char* argv[] ) {
  char mafn[MAX_FN_LEN+1];
  char ma_in_fn[MAX_FN_LEN+1];
  char assign_id[MAX_ID_LEN+1];
  unsigned int any_arg;
  int id_assigned = 0; // Boolean, set to true if -I is given
  int cons_scheme;
  int out_ma   = 0;
  int in_ma    = 0;
  int no_dups  = 0; // allow duplicate ids by default - the user knows what he's doing
  int out_format = 1;
  int reg_start  = 90;
  int reg_end    = 109;
  int in_color   = 0;  // Output f6 format colored -> bad when you want to pipe it into a file
  MapAlignmentP maln;
  PWAlnFragP pwaln; 
  IDsListP rest_ids_list, // the IDs in the -i argument, if any, will go here
    used_ids_list;        // the IDs seen thusfar; just for this list,
                          // the segment character is tacked onto the end
  int ich, cons_scheme_def, ids_rest;
  double score_int, score_slo;
  extern char* optarg;
  cons_scheme_def = 1;
  ids_rest = 0; // Boolean set to no => no IDs restriction set (yet)
  /* Get input options */
  any_arg = 0;
  cons_scheme = cons_scheme_def;
  score_int = -1.0; // Set the score intercept to -1 => not specified (yet)
  score_slo = -1.0; // Set the score intercept to -1 => not specified (yet)
  while( (ich=getopt( argc, argv, "I:c:i:f:R:s:m:M:Cb:s:d" )) != -1 ) {
    switch(ich) {
    case 'h' :
      help();
      exit( 0 );
      any_arg = 1;
      break;
    case 'I' :
      strcpy( assign_id, optarg );
      id_assigned = 1;
      break;
    case 'c' :
      cons_scheme = atoi( optarg );
      any_arg = 1;
      break;
    case 'i' :
      rest_ids_list = parse_ids( optarg );
      ids_rest = 1;
      any_arg = 1;
      break;
    case 'f' :
      out_format = atoi( optarg );
      any_arg = 1;
      break;
    case 'R' :
      parse_region( optarg, &reg_start, &reg_end );
      any_arg = 1;
      break;
    case 's' :
      score_slo = atof( optarg );
      any_arg = 1;
      break;
    case 'b' :
      score_int = atof( optarg );
      any_arg = 1;
      break;
    case 'C' : 
      in_color = 1;
      break;
    case 'm' :
      strcpy( mafn, optarg );
      out_ma  = 1;
      any_arg = 1;
      break;
    case 'M' :
      strcpy( ma_in_fn, optarg );
      in_ma   = 1;
      any_arg = 1;
      break;
    case 'd' :
      no_dups = 1;
      used_ids_list = init_ids_list();
      any_arg = 1;
      break;
    default :
      help();
      any_arg = 1;
      exit( 0 );
    }
  }
  if ( !any_arg || 
       ( (score_slo == -1) && (score_int != -1) ) ||
       ( (score_slo != -1) && (score_int == -1) ) ) {
    help();
    exit( 0 );
  }

  /* Initialize maln, either from specified input file or 
     brand new */
  if ( in_ma ) {
    maln = read_ma( ma_in_fn );
  }

  else {
    help();
    exit( 0 );
  }

  /* Set the maln->cons_code to something reasonable */
  maln->cons_code = cons_scheme;

  /* Now input from all sources has been dealt with, we turn our 
     attention to output...*/
  sort_aln_frags( maln );

  /* If an ID to be assigned to the assembly was given, then assign it now */
  if ( id_assigned ) {
    strcpy( maln->ref->id, assign_id );
  }

  if ( (out_format == 6) ||
       (out_format == 61) ) {
    print_region( maln, reg_start, reg_end, out_format, in_color );
  }
  else {
    show_consensus( maln, out_format );
  }
  
  if (out_format == 7){
	  ace_output(maln);
  }

  /* Write MapAlignment output to a file */
  if ( out_ma ) {
    write_ma( mafn, maln );
  }

  exit( 0 );
}