Esempio n. 1
0
int main(int argc, char **argv)
{
    if (argc != 3) {
        fprintf(stderr, "*** Invalid number of parameters\n");
        exit(1);
    }

    const char *const filename_sg1= argv[1];
    const char *const filename_ft= argv[2];

    struct sgraph1_reader_a r;

    if (0 > sgraph1_open_read_a(filename_sg1, &r, 2)) {
        exit(1);
    }

    if (0 > sgraph1_advise_a(&r, MADV_SEQUENTIAL)) {
        perror(filename_sg1);
        exit(1);
    }

    struct feature_a f;

    if (0 > feature_open_write_a(filename_ft, &f, r.h->n1
#if FEATURE_N2
                                 , r.h->n2
#endif
                                )) {
        exit(1);
    }

    if (0 > feature_advise_a(&f, MADV_SEQUENTIAL)) {
        perror(filename_ft);
        exit(1);
    }

    for (ua_ft u= 0;  u < r.h->n1;  ++u) {
        const ma_ft beg= read_ma(r.adj_to, u);
        const ma_ft end= u == r.h->n1 - 1 ? r.len_m : read_ma(r.adj_to, u + 1);
        assert(beg <= end);
        assert((ma_ft)(end - beg) < fa_max);
        writeonzero_fa(f.f1, u, end - beg);
    }

#if FEATURE_N2
    for (u_ft v= 0;  v < r.h->n2;  ++v) {
        const m_ft beg= read_m(r.adj_from, v);
        const m_ft end= v == r.h->n2 - 1 ? r.len_m : read_m(r.adj_from, v + 1);
        assert(end - beg < f_max);
        writeonzero_f(f.f2, v, end - beg);
    }
#endif

    if (0 > feature_close_write_a(&f)) {
        perror(filename_ft);
        if (0 > unlink(filename_ft)) {
            perror(filename_ft);
        }
        exit(1);
    }

    exit(0);
}
Esempio n. 2
0
int main(int argc, char **argv)
{
	if (argc != 3) {
		fprintf(stderr, "*** Expected 2 parameters\n");
		exit(1);
	}

	const char *const filename_sg1= argv[1];

	struct sgraph1_reader_a r;

	if (0 > sgraph1_open_read_a(filename_sg1, &r, 2)) {
		exit(1); 
	}

	if (0 > sgraph1_advise_a(&r, MADV_SEQUENTIAL)) {
		perror(filename_sg1); 
		exit(1);
	}

	uintmax_t t= 0;

	const ma_ft len_m= 2 * r.h->m - r.loops;
	assert(len_m == r.len_m); 
	const ua_ft n= (ua_ft)r.h->n1;
	r_to= r.to;

	for (ua_ft u= 0;  u < n;  ++u) {

		const ma_ft beg1_u= read_ma(r.adj_to, u);
		const ma_ft end1= (u + 1 == n ? len_m : read_ma(r.adj_to, u+1));

		for (ma_ft i= beg1_u;  i < end1;  ++i) {

			const va_ft v= read_va(r.to, i);

			if (v >= u)
				break;

			ma_ft beg1= beg1_u;
			ma_ft beg2= read_ma(r.adj_to, v);
			const ma_ft end2= (v + 1 == n) ? len_m : read_ma(r.adj_to, v+1);
			
			assert(beg1 <= end1);
			assert(beg2 <= end2); 
			assert(beg1 >= end2 || beg2 >= end1); 

#if VARIANT == 0
			while (beg1 < end1 && beg2 < end2) {

				/* This network is without multiple edges */ 
				assert(beg1 + 1 == end1 || read_u(r.to, beg1) < read_u(r.to, beg1 + 1));
				assert(beg2 + 1 == end2 || read_u(r.to, beg2) < read_u(r.to, beg2 + 1));
					    
				const ua_ft x1= read_u(r.to, beg1);
				const ua_ft x2= read_u(r.to, beg2);

				assert(SIZE_MAX - 1 >= t); 
				t += (x1 == x2);

				if (x1 <= x2)  ++beg1;
				if (x2 <= x1)  ++beg2; 
			}
#elif VARIANT == 1

			ma_ft t_uv= common_elements(beg1, end1, beg2, end2); 

			assert(SIZE_MAX - t_uv >= t); 
			t += t_uv;
#endif
		}
	}

	assert(t % 3 == 0); 
	t /= 3;

	if (0 > printf("%" PRIuMAX "\n", t)) {
		perror("printf");
		exit(1); 
	}

	exit(0);
}
Esempio n. 3
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 );
}