示例#1
0
文件: rna.c 项目: cjpatton/misc
void print_pairs (const rna_t *mol, int i, int j)
/* Recover the the optimal secondary structure from the computed OPT matrix. 
 * Print the base pairs of the molecule. */
{
  int a = mol->opt[i][j].a,
      b = mol->opt[i][j].b; 

  if (a >= 0 && j >= 0) 
  {
    printf("(%d, %d)\n", a,b);
    print_pairs (mol, i, a-1); 
    print_pairs (mol, a+1, b-1);
  }
}
示例#2
0
int main(int argc, char **argv)
{
    // Setting default parameters
    int n_hist = 4;
    int n_ori = 8;
    int n_bins = 36;
    int meth_flag = 1;
    float thresh = 0.6;
    int verb_flag = 0;
    char label[256];
    strcpy(label, "extra");

    // Parsing command line
    int res = parse_options(argc, argv, &n_bins, &n_hist, &n_ori,
                            &meth_flag, &thresh, &verb_flag, label);
    if (res == EXIT_FAILURE)
        return EXIT_FAILURE;

    // Memory allocation
    struct sift_keypoints* k1 = sift_malloc_keypoints();
    struct sift_keypoints* k2 = sift_malloc_keypoints();
    struct sift_keypoints* out_k1 = sift_malloc_keypoints();
    struct sift_keypoints* out_k2A = sift_malloc_keypoints();
    struct sift_keypoints* out_k2B = sift_malloc_keypoints();

    // Read input keypoint ASCII files
    int readflag = verb_flag + 1;
    sift_read_keypoints(k1, argv[1], n_hist, n_ori, n_bins, readflag);
    sift_read_keypoints(k2, argv[2], n_hist, n_ori, n_bins, readflag);


    debug("size read keys / k1 %i / k2 %i /", k1->size, k2->size);

    // Matching
    matching(k1, k2, out_k1, out_k2A, out_k2B, thresh, meth_flag);

    // Print
    print_pairs(out_k1, out_k2A);
    char name[FILENAME_MAX];
    if(verb_flag == 1){
        save_pairs_extra("OUTmatches.txt", out_k1, out_k2A, out_k2B);
        sprintf(name, "%s_im0.txt", label);
        sift_save_keypoints(out_k1, name, 1);
        sprintf(name, "%s_im1.txt", label);
        sift_save_keypoints(out_k2A, name, 1);
    }

    // Free memory
    sift_free_keypoints(k1);
    sift_free_keypoints(k2);
    sift_free_keypoints(out_k1);
    sift_free_keypoints(out_k2A);
    sift_free_keypoints(out_k2B);

    return EXIT_SUCCESS;
}
int main(int argc, char * argv[]){

  pair_t ** pairs = new_pairs(); //create a new pair array

  add_pair(pairs, 2, 10); //assign a new pair
  add_pair(pairs, 0, 3); //assign a new pair
  add_pair(pairs, 13, 7);

  print_pairs(pairs); //print pairs

  rm_pair(pairs, 1); //remove pair at index 1

  printf("------------\n");
  print_pairs(pairs); //print pairs (again)

  delete_pairs(pairs); //delete all pairs, no memleaks!

  return 0;
}
示例#4
0
// PURPOSE: print all the unmatched patinets in the database (s-receivers, s-donors, pairs)
// NOTE: patients who were added to a balanced system are removed from patient lists
void Database::print_patients()
{
	cout << "\n==== PRINTING ALL PATIENTS IN DB ====\n\n";
	cout << "\n- Single Reciver -\n";
	print_s_receivers();
	cout << "\n- Single Donor -\n";
	print_s_donors();
	cout << "\n- D_R_Pairs -\n";
	print_pairs();
	return;
}
示例#5
0
int main(int argc, char ** argv)
{
    if (argc != 2)
    {
        explain_usage();
    }
    else
    {
        size_t point_count = strtoul(argv[1], 0, 0);

        if (point_count == 0u)
            return handle_invalid_point_count();

        print_pairs(point_count);
    }

    return 0;
}
示例#6
0
文件: rna.c 项目: cjpatton/misc
int main(int argc, const char **argv)
{
  
  char c, rna [MAX]; 
  int i, j=0, score;
  rna_t *molecule = (rna_t *)malloc(sizeof(rna_t)); 

  /* Get RNA strand from stdin. Finish input on EOF */ 
  for (i = 0; (c=getchar()) != EOF && i < MAX; i++) 
  {
    switch (c) 
    {
      case ' ': 
      case '\t':
      case '\n': break;
      case 'A':
      case 'G':
      case 'C':
      case 'U':
      default: rna[j++] = c; 
    }
  }
  rna[j] = '\0';

  printf("%s\n", rna); 

  /* Compute OPT */ 
  score = predict( rna, molecule ); 
 
  //printf("score: %d\n   ", score); 
  //print_opt (molecule);
  print_structure (molecule); 
  printf("  score: %d\n", score); 
  print_pairs (molecule, 0, strlen(rna)-1); 

  free (molecule); 
  return 0;
}
int main(int argc, char *argv[])
{
	int i = 1, remaining = argc - 1;
	if (remaining > 0 && strcmp(argv[i], "-t") == 0) {
		technical = 1;
		remaining--;
		i++;
	}
	if (remaining > 0 && strcmp(argv[i], "-q") == 0) {
		quiet = 1;
		remaining--;
		i++;
	}
	if (remaining > 0 && strcmp(argv[i], "-t") == 0) {
		technical = 1;
		remaining--;
		i++;
	}

	if (remaining != 2) {
		usage("wrong number of arguments");
	} else {
		FILE *data_input = fopen(argv[i], "r");
		assert(data_input);
		FILE *output = fopen(argv[i + 1], "w");
		assert(output);

		read_data(data_input);
		compare_pairs();
		print_counters();
		init_scores_and_sort();
		print_pairs();
		mark_for_output();
		recalc_relevant_for_output(output);

		return 0;
	}
}
示例#8
0
main (int argc, char *argv[]) {

	int i, j, **seqs, **nall, ord=1, ns, **pij, lkf=0, npt=0, pnew=0, anc=0;
	int tcat=1, rcat=0, verb=1, miss=0, *flocs;

	int sw_flag=0, moment_flag=0, rmin_flag=0, sim_flag=0, test_flag=0;
	char fname[MAXNAME+1], **seqnames;
	long seed=-setseed();
	extern int sizeofpset;
	double *locs;

	double **lkmat, *lkres;
	FILE *ifp=NULL, *ifp2=NULL, *ifp3=NULL, *tfp;
	struct site_type **pset;
	struct data_sum *data;
	int ask_questions = 1;
	char *in_str;

	print_help(argc, argv);
	idum = &seed;
	data = malloc((size_t) sizeof(struct data_sum));
	data->exact = 0;
	strcpy(data->prefix, "");

	for(i = 0; i < argc; i++)
	{
		if(*argv[i] == '-')
		{ 
			in_str = argv[i];
			ask_questions = 0;
			if(strcmp(in_str, "-seq") == 0) ifp = fopen(argv[i+1], "r");		
			if(strcmp(in_str, "-loc") == 0) ifp2 = fopen(argv[i+1], "r");
			if(strcmp(in_str, "-lk") == 0) 
			{
				lkf = 1;
				ifp3 = fopen(argv[i+1], "r");
			}
			if(strcmp(in_str, "-exact") == 0) data->exact = 1;
			if(strcmp(in_str, "-concise") == 0) verb=0;
			if(strcmp(in_str, "-window") == 0) sw_flag=1;
			if(strcmp(in_str, "-moment") == 0) moment_flag=1;
			if(strcmp(in_str, "-simulate") == 0) sim_flag=1;
			if(strcmp(in_str, "-rmin_flag") == 0) rmin_flag=2;
			if(strcmp(in_str, "-test") == 0) test_flag=1;
			if(strcmp(in_str, "-prefix") == 0) strcpy(data->prefix, argv[i+1]);
		}
	}
	if (ifp == NULL) 
	{
		printf("\nCould not find seqs file in command line.\n");
		printf("\nInput filename for seqs:\n");
		scanf("%s", &fname);
		ifp = fopen(fname, "r");
	}
	if (ifp == NULL) nrerror("Error in opening sequence file");

	
	fscanf(ifp,"%i%i%i", &data->nseq, &data->lseq, &data->hd);
	if ((data->nseq < 2) || (data->lseq < 2)) {printf("\n\nInsufficient data for analysis (n > 1, L > 1) \n\n"); exit(1);}
	if (data->nseq > SEQ_MAX) {printf("\n\nMore than max no. sequences: Using first %i for analysis\n\n", SEQ_MAX); data->nseq=SEQ_MAX;}
	printf("\nAnalysing %i (n=%i) sequences of length %i seg sites\n", data->nseq, data->hd, data->lseq);
	seqs = imatrix(1, data->nseq, 1, data->lseq);
    seqnames = cmatrix(1, data->nseq+11, 1, MAXNAME+11);
	if (read_fasta(seqs, ifp, data->nseq, data->lseq, seqnames)) printf("\nSequences read succesfully\n");
    fclose(ifp);

	nall = imatrix(1, data->lseq, 1, 6);
	allele_count(seqs, data->nseq, data->lseq, nall,1, data->hd, data->prefix);

	/*Store lnfac values in array for speed of computation*/

	lnfac_array = (double *) malloc((size_t) ((int) (data->nseq+2)*(data->hd))*sizeof(double));

	lnfac_array[0]=lnfac_array[1]=0;

	for (j=2;j<=((int) data->nseq*(data->hd));j++) lnfac_array[j]=(double) lnfac_array[j-1]+log(j);


	/*Open file with location of seg sites and read in data*/	
	if (ifp2 == NULL) 
	{
		printf("\nCould not find locs file in command line.\n");
		printf("\nInput name of file containing location of seg sites\n\n");
		scanf("%s", &fname);
		ifp2 = fopen(fname, "r");
	}

	if (ifp2 == NULL) nrerror("Cannot open loc file");
	fscanf(ifp2, "%i %lf %c", &ns, &data->tlseq, &data->lc);
	if (ns != data->lseq) nrerror("Lseq and Locs disagree");
	if ((data->lc != 'C')&&(data->lc != 'L')) nrerror("Must input linear(L)/conversion(C)");
	if (data->lc == 'C') {
	  data->avc=0;
	  while (data->avc <= 0) {
	    printf("\n\nInput average tract length for conversion model: ");scanf("%lf", &(data->avc));
	  }
	}

	locs = dvector(1, data->lseq);
	flocs = ivector(1, data->lseq); /*Array to use when simulating data*/


	for (i=1; i<=data->lseq; i++) {
		fscanf(ifp2, "%lf", &locs[i]); 
		if ((locs[i]==0)||(locs[i]>data->tlseq)) {printf("\n\nError in Loc file\n\n%lf\n", data->tlseq); exit(1);}
		if (i>1 && locs[i]<=locs[i-1]) nrerror("Error in locs file: SNPs must be montonically increasing");
	}
	printf("\nLocation of seg sites\n\n");
	for (i=1; i<=data->lseq; i++) printf("%3i   %4.2lf\n", i, locs[i]);
	fclose(ifp2);

	/*Read in likelihood file where needed*/
    if (ask_questions) 
	{
			printf("\n\nUse existing likelihood file? (yes=1, no=0):");
			scanf("%i", &lkf);  /*lkf is a flag: 1 means use existing likelihood file as starting point*/
			if (lkf) 
			{
				printf("\n\nInput name of likelihood file: ");
				scanf("%s", &fname);
				ifp3 = fopen(fname, "r");
			}
			else 
				data->exact=0;

			if (lkf == 1)
			{
				printf("\n\nIs likelihood file an exact match to data?(no=0/yes=1): ");
				scanf("%i", &data->exact);
			}
	}

	if (lkf && !ifp3) nrerror("Cannot open likelihood file");
	if (!lkf && data->hd==2) nrerror("For diploid data need complete lookup table for sequences");

	/*Store pair-types in pij matrix - classify in pair_spectrum routine*/

	data->w	= data->lseq;  /*Note for this program use all data - pair_int restricts to a smaller window*/
	pij = imatrix((int) 1,(int) data->lseq,(int) 1,(int) data->w);

	for (i=1;i<=data->lseq;i++) for (j=1;j<=data->w;j++) pij[i][j]=0;

	pset = init_pset(pset, lkf, ifp3, &npt, data);  /*Reads in type configurations from likelihood file*/

	printf("\n\n*** Calculating distribution of pair types ***\n\n");
	pset = pair_spectrum(seqs, data, nall, pset, &npt, &pnew, &miss, anc, pij);
	printf("\n\n *** Completed classification of pair types ***\n\n");

	if (data->exact && (pnew || miss)) nrerror("Lookup table is not exact for sequences\n(possibly generated by interval)");
	printf("\n\nOld = %i: New = %i: Missing = %i\n\n", npt,pnew,miss);
	data->ptt = (int) npt+pnew+miss;  /*npt is number from likelihood file, pnew is number new with no missing data, miss is # new with missing data*/
	if (verb) {
		strcpy(fname, data->prefix);
		tfp = fopen(strcat(fname, "type_table.txt"), "w");
		if (!tfp) nrerror("Cannot open type file");
		type_print(pij, data->lseq, data->w,tfp);
		fclose(tfp);
	}
	if (verb) print_pairs(stdout, pset, npt+pnew, data->hd, data->nseq);

	/*Need a complete set for missing data or diploid data - check this*/
	if (!data->exact && (data->hd ==2 || miss)) {
		printf("\n\nMissing data or diploid: checking that likelihood table is exhaustive\n\n");
		check_exhaustive(pset,npt,(data->nseq)*((int) data->hd));
	}
	/*Read parameters and likelihoods from likelihood file - where appropriate*/
	if (lkf) {
		read_pars(ifp3, &tcat, &data->th, &data->rcat, &data->rmax);
		lkmat = dmatrix(1,npt+pnew+miss,1,data->rcat);
		if (lkf) read_lk(ifp3, lkmat, npt, tcat, data->rcat);
	}

	/*If haploid, but novel types, need to calculate new likelihoods and input parameter values*/
	if (data->hd ==1 && pnew) { /*Note can have pnew for diploid data, but this has been checked for already*/
		if (!lkf) {
			data->th=data->rmax=-1.0; data->rcat=0;
			printf("\n\nInput theta per site (suggest Watterson estimate of %.5lf):",(double) data->lseq/(watterson(data->nseq*data->hd)*data->tlseq));
			while (data->th<0.0) scanf("%lf", &data->th);
			printf("\n\nMax 4Ner for grid (suggest 100):");
			while(data->rmax<0.0) scanf("%lf", &data->rmax);
			printf("\n\nNumber of points on grid (suggest 101, min=2):");
			while(data->rcat<2) scanf("%i", &data->rcat);
			lkmat = dmatrix(1,npt+pnew+miss,1,data->rcat);
		}
		lk_est(pset,npt,pnew,lkmat,data->th,data->rcat,data->rmax);
		data->exact=1;
	}

	/*Sum over missing data or resolve genotypes and sum over missing data+configurations*/
	else if (miss && data->hd==1) {  
		printf("\n\n*** Calculating likelihoods for missing data ***\n\n");
		for (i=1;i<=miss;i++) {
			lk_miss(pset[npt+i],lkmat[npt+i],lkmat,data);
			printf("\rType %i", i);
		}

		printf("  ...Done!\n\n");
	}


	/*Sum over resolutions for diploid data*/
	else if (data->hd==2 && !data->exact) {
	  printf("\n\n*** Resolving diploid data: %i ***\n\n",pnew+miss);
	  lkres = dvector(1,data->rcat);
	  for (i=1;i<=pnew+miss;i++) {
	    lk_resolve(lkres,pset[npt+i],lkmat[npt+i],lkmat,data);
	    printf("\rType %i", i); 
	  }
	  free_dvector(lkres,1,data->rcat); 

	  printf("  ...Done!\n\n");
	}

	/*If new likelihood generated can output likelihood file for future analyses*/
	if (verb) print_lks(pset, data, npt+pnew+miss, lkmat);


	/*Basic analysis - estimation of 4Ner asuming constant rate*/

	data->rme=data->rmax; data->rce=data->rcat;
	if (1) {
		printf("\n\nDo you wish to change grid over which to estimate likelihoods for (default = %i points, 4Ner 0 - %.1lf) (1/0) :",data->rcat,data->rmax);
		scanf("%i", &lkf);
		if (lkf) {
			data->rme=-10; data->rce=0;
			printf("\n\nMax 4Ner for estimation           : ");
			while (data->rme < 0.0) scanf("%lf", &data->rme);  
       		printf("\n\nNumber of classes to estimate for: ");
       		while (data->rce < 1) scanf("%i", &data->rce);
		}
	}
	data->lksurf = dmatrix(1,data->rce,1,2);
	lk_surf(pset, pij, data, lkmat, data->th, locs, 1);


	/*Print marginal likelihood ratio test statistics for each pair of sites*/
	printf("\n\nCalculating fits\n\n");
	fit_pwlk(data,pij,locs,lkmat,verb);

	/*Sliding windows version*/
	if (1) {
		printf("\n\nDo you wish to carry out a sliding windows analysis? (yes=1/no=0):");
		scanf("%i", &sw_flag);
	}
	if (sw_flag) lk_win(pset,pij,data,lkmat,locs,nall);

	/*Nonparametric estimation of recombination rate*/
	if (1) {
		printf("\n\nPrint out table of Rmin values?\n(0=No, 1=Total only, 2=Full table):");
		scanf("%i", &rmin_flag);
	}

	if (rmin_flag) {
		rmin(data, pset, pij, locs, lkf-1);
		printf("\n\nLower bound on Rmin = %i\n\n",data->rmin);
	}

	/*Estimate 4Ner by Wakeley 1997 method*/
	if (1) {
		printf("\n\nEstimate 4Ner by moment method? (yes=1, no=0)");
		scanf("%i", &moment_flag);
	}

	if (moment_flag) wakeley_est(data, seqs, locs);

	/*Recombination tests - only available for haploid data!*/
	if (data->hd==1) {
		if (1) {
			printf("\n\nDo you wish to test for recombination? (yes=1, no=0): ");
			scanf("%i", &test_flag);
		}
		if (test_flag) {
			rec_test(data, pij, locs, lkmat, pset, npt+pnew+miss);
		}
	}

	/*Conditional simulation - only available for haploid data with a complete lk file*/
	if (data->hd==1 && !(data->exact)) {

		if (1) {
	  printf("\n\nDo you wish to test constant-rate model and estimate sampling distribution by simulation? (yes=1/no=0): ");
	  scanf("%i", &test_flag);
		}
	  if (test_flag) {
	    freq_min(locs, flocs, nall, data);
	    printf("\n\nHow many simulations? ");
	    scanf("%i", &lkf);
	    snp_sim(locs, flocs, pset, lkmat, lkf, data);
	  }
	}

	free_imatrix(pij,1,data->lseq,1,data->w);
	free_imatrix(seqs,1,data->nseq,1,data->lseq);
	free_imatrix(nall,1,data->lseq,1,5);
	for (i=1;i<sizeofpset;i++) free(pset[i]);
	free(pset);
	free(data);
	free_dvector(locs, 1, data->lseq);
	free_ivector(flocs, 1, data->lseq);

	/* system("PAUSE"); */
}