/* @author: joao lopes @workplace: Reading University @date: 6th May 2009 */ #include "interface.h" /* It creates an ABC .len file given an IM input file. @arg length format filename @arg output filename */ int createFreqTab2(char *input,char *output){ int cloc, cpop, cdna, cindiv, csite, i, j, cmark, //iterators nmark, //nr. of total markers used nloc, //number of loci equalDna, //auxiliar to build the .len file outsize, //size of output file name *ldna, //number of different dna data by loci *lmark, //nr of markers per loci *nsamp, //total number of samples per loci **lsamp, //size of sample per pop per loci ***freq; //freq of dna data by no_pop by no. of diff dna data char type, //type of analysis choosen c1, //gets the value of a char temporarly aux[MAXCHAR], //auxiliar pop1[MAXCHAR], //name of population 1 pop2[MAXCHAR], //name of population 2 DNAtype[MAXCHAR], //current locus mutation model used in IM *ltype, //DNA type per loci *outname, //name of the output file **locname; //name of the loci FILE *inp, //pntr to the input file *outp; //pntr to the output file time_t startClock; //time when the program starts const struct tm *startTime; //struct time when the program starts // only used in microssatelite dna analysis int **valM, //list of all the diff microsatellite sizes **IDsort, //list of the order of the diff microsatellite sizes ***genotM2, //list of all the individual's haplotype per pop per loci ****genotM; //list of all the individual's haplotype per pop per loci // only used in sequence dna analysis char **mainseq, //main sequence of a loci ***valS, //list of all the diff dna sequencies ****genotS2, //list of all the individual's haplotype per pop per loci ****genotS; //list of all the individual's haplotype per pop per loci int *lsites; //number of bases per loci inp = fopen(input,"r"); if(inp == NULL) return 1; //cannot open sample file outsize = strlen(output) + 5; outname = (char *)malloc(outsize*sizeof(char)); strcpy(outname,output); outp = fopen(strcat(outname,".len"),"w"); if(outp == NULL) return 2; //cannot create output file time( &startClock ); // Get time in seconds startTime = localtime( &startClock ); // Convert time to struct tm form //print first line to output file fprintf(outp,"# IMa file converted to .len file with im2table1.0\n"); fprintf(outp,"# input file: %s\n",input); fprintf(outp,"# output file: %s.len\n",output); fprintf(outp,"# date: %s#\n#",asctime(startTime)); while(!isendline(c1=getc(inp))){ fprintf(outp,"%c",c1); } fprintf(outp,"\n"); //if # (commentary) run to end of line c1 = getc(inp); while(c1 == '#'){ while(!isendline(c1 = getc(inp))); while(isspace(c1=getc(inp))||isendline(c1)||c1=='\t'); } ungetc(c1,inp); fscanf(inp,"%s",&pop1); fscanf(inp,"%s",&pop2); fscanf(inp,"%d",&nloc); //allocate memory to DNAtype, lsamp, locname, genotM or genotS and lsites ltype = (char *)malloc(nloc*sizeof(char)); lmark = (int *)malloc(nloc*sizeof(int)); lsamp = (int **)malloc(nloc*sizeof(int*)); nsamp = (int *)malloc(nloc*sizeof(int)); locname = (char **)malloc(nloc*sizeof(char*)); lsites = (int *)malloc(nloc*sizeof(int)); genotM = (int****)malloc(nloc*sizeof(int***)); genotS = (char****)malloc(nloc*sizeof(char***)); for(cloc=0;cloc=ldna[i]){ for(j=0;j=ldna[i]){ for(j=0;j1) fprintf(outp,"#Locus %d - %s_%d\n",i+1,locname[cloc],cmark+1); else fprintf(outp,"#Locus %d - %s\n",i+1,locname[cloc]); i++; } } fprintf(outp,"\n2\n"); //outp: npop fprintf(outp,"%d\n",nmark); //outp: nloc for(cloc=0 ; cloc