/* @author: joao lopes @workplace: Reading University @date: 8th May 2009 */ #include "interface.h" /* It creates an ABC .len file given a Nexus file (.nex) @arg length format filename @arg output filename */ int createFreqTab4(char *input,char *output){ int cloc, cpop, cdna, csamp, csite, i, j, //iterators nr1, //retrieve info from input file nr2, //retrieve info from input file reachEOF, //check if EOF has been reached endSets, //check if end of Sets has been reached endPop, //check if end of pop has been reached firstInd, //check if using '-' to define populations equalDna, //auxiliar to build the .len file outsize, //size of output file name npop, //number of populations nsites, //number of bases ndna, //number of different dna data nsamp, //total number of samples *lsamp, //size of sample per pop *id, //identify the belonging population of each used individual **freq; //freq of dna data by no_pop by no. of diff dna data char c1, //gets the value of a char temporarly info1[MAXCHAR], //retrieve info from the input file info2[MAXCHAR], //retrieve info from the input file aux[MAXCHAR], //auxiliar *outname, //name of the output file *mainseq, //main sequence of a loci **lpop=NULL, //list of the populations names **indiv, //list of samples **valS, //list of all the diff dna sequencies ***genotS; //list of all the individual's haplotype per pop per 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 inp = fopen(input,"r"); if(inp == NULL) return 1; //cannot open .nex 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 fgets(aux,MAXCHAR,inp); //#NEXUS reachEOF=0; while(!reachEOF){ //reads input file while(isspace(c1=getc(inp))||isendline(c1)||c1=='\t'); if(c1 == '[') while((c1 = getc(inp))!=']'); else if(c1==EOF) reachEOF=1; else ungetc(c1,inp); if(!reachEOF){ while(isspace(c1=getc(inp))||isendline(c1)||c1=='\t'); ungetc(c1,inp); fscanf(inp,"%s",aux); if(strcmp(aux,"begin")==0||strcmp(aux,"BEGIN")==0||strcmp(aux,"Begin")==0){ fscanf(inp,"%s",aux); if(strcmp(aux,"data;")==0||strcmp(aux,"DATA;")==0||strcmp(aux,"Data;")==0){ fscanf(inp,"%s",aux); //DIMENSIONS fscanf(inp,"%s",aux); i=0; j=0; while(!isdigit(aux[i])) i++; while(isdigit(aux[i+j])){ info1[j]=aux[i+j]; j++; } nsamp=atoi(info1); fscanf(inp,"%s",aux); i=0; j=0; while(!isdigit(aux[i])) i++; while(isdigit(aux[i+j])){ info1[j]=aux[i+j]; j++; } nsites=atoi(info1); fscanf(inp,"%s",aux); //FORMAT fscanf(inp,"%s",aux); i=0; j=0; while(aux[i]!='=') i++; while(isalpha(aux[1+i+j])){ info1[j]=aux[1+i+j]; j++; } info1[j]='\0'; if(!(strcmp(info1,"DNA")==0||strcmp(info1,"dna")==0||strcmp(info1,"Dna")==0)) return 3; //program can't deal with specified data //MATRIX: go through all the individuals fscanf(inp,"%s",aux); //MATRIX indiv=(char**)malloc(nsamp*sizeof(char*)); for(csamp=0; csamp=nr2) return 6; //problem defining TAXSET: n1>=n2 for(i=nr1;i<=nr2;i++) id[i-1]=cpop; } } cpop++; } else return 7; //unrecognized specifier after BEGIN SETS (use TAXSET) } npop=cpop; } else return 8; //unrecognized specifier after BEGIN (use DATA or SETS) } else if(aux[0]=='['){ for(i=strlen(aux)-1; i>=0; i--) ungetc(aux[i],inp); } else return 9; //unrecognized command (only BEGIN accepted) } } //fill lsamp and genotS genotS = (char***)malloc(npop*sizeof(char**)); lsamp = (int *)malloc(npop*sizeof(int)); for(cpop=0; cpop=ndna){ for(j=0;j