int main(int argc, char **argv) { if(argc < 2) exit_main(); if(!strcmp(argv[1], "generate"))generate<3>(argc, argv); else if(!strcmp(argv[1], "convert")) convert<3>(argc, argv); else if(!strcmp(argv[1], "train")) train<3>(argc, argv); //else if(!strcmp(argv[1], "predict")) predict<3>(argc, argv); //else if (!strcmp(argv[1], "view")) view(argc, argv); //else printf("Invalid command: %s\n", argv[1]); return 0; }
GuiApp::~GuiApp() { //! close simulation exit_main(0); libManager->releaseLibrary("cfg_manager"); libManager->releaseLibrary("lib_manager_gui"); libManager->releaseLibrary("main_gui"); libManager->clearLibraries(); delete libManager; #ifdef WIN32 // end scheduler of 1ms timeEndPeriod(1); #endif //WIN32 }
extern int main( int argc, char *argv[]) #endif { boolean closein = false; short ifile, format, err = 0, seqtype = kDNA, nlines=0, seqout = 0, phylvers = 2; long atseq, nseq, i, skiplines, seqlen, seqlen0=0; /* changed atseq and nseq from short to long - James J (UQ) */ unsigned long checksum= 0, checkall= 0; char *seq=NULL, *cp=NULL, *firstseq = NULL, *seqlist=NULL, *progname; /*char tempname[] = "readseqXXXXXX";*/ char *tempname = NULL; char seqid[MAXLINE], *seqidptr = seqid; char stempstore[256], *stemp = stempstore; FILE *ftmp=NULL, *fin=NULL, *fout=NULL; long outindexmax= 0, noutindex= 0, *outindex = NULL; #define exit_main(err) { \ if (closeout) fclose(fout); \ if (closein) fclose(fin); \ if (tempname != NULL) remove(tempname); \ Exit(err); } #define indexout() if (interleaved) {\ if (noutindex>=outindexmax) {\ outindexmax= noutindex + 20;\ outindex= (long*) realloc(outindex, sizeof(long)*outindexmax);\ if (outindex==NULL) { err= eMemFull; erralert(err); exit_main(err); }\ }\ outindex[noutindex++]= ftell(fout);\ } resetGlobals(); foo = stdout; progname = argv[0]; *oname = 0; /* initialize gPretty ?? -- done in header */ for (i=1; i < argc; i++) { err= readopt( argv[i]); if (err <= 0) exit_main(err); } /* pipe input from stdin !? */ if (dopipe && !gotinputfile) { int c; int fd; /* tmpnam(tempname); inputfile = tempname; ftmp = fopen( inputfile, "w"); */ tempname = strdup("readseqXXXXXX"); fd = mkstemp(tempname); if (fd == -1) { erralert(eFileCreate); exit_main(eFileCreate); } strcpy(inputfile, tempname); while ((c = getc(stdin)) != EOF) write(fd, &c, 1); close(fd); gotinputfile= true; } quietly = (dopipe || (gotinputfile && (listonly || whichSeq != 0))); if (verbose || (!quietly && !gotinputfile)) fprintf( stderr, "%s", title); ifile = 1; /* UI: Choose output */ if (askout && !closeout && !quietly) { askout = false; fprintf(stderr,"\nName of output file (?=help, defaults to display): \n"); fgets(oname= onamestore, 128, stdin); skipwhitespace(oname); if (*oname == '?') { usage(); exit_main(0); } else if (*oname != 0) { closeout = true; foo = fopen( oname, "w"); if (!foo) { erralert(eFileCreate); exit_main(eFileCreate); } } } fout = foo; if (outform == kNoformat) outform = chooseFormat(quietly); /* set up formats ... */ switch ((int) outform) { case kPhylip2: interleaved= false; phylvers = 2; outform = kPhylip; break; case kPhylip4: interleaved= true; phylvers = 4; outform = kPhylip; break; case kMSF: case kPAUP: interleaved= true; break; case kPretty: gPretty.isactive= true; interleaved= true; break; } if (gPretty.isactive && gPretty.noleaves) interleaved= false; if (interleaved) { fout = ftmp = tmpfile(); outindexmax= 30; noutindex= 0; outindex = (long*) malloc(outindexmax*sizeof(long)); if (outindex==NULL) { err= eMemFull; erralert(err); exit_main(err); } } /* big loop over all input files */ do { /* select next input file */ /*gotinputfile = (*tempname != 0);*/ gotinputfile = (tempname != NULL); while ((ifile < argc) && (!gotinputfile)) { if (*argv[ifile] != '-') { strcpy( inputfile, argv[ifile]); gotinputfile = (*inputfile != 0); --nfile; } ifile++; } while (!gotinputfile) { fprintf(stderr,"\nName an input sequence or -option: \n"); inputfile= inputfilestore; fgets(stemp= stempstore, 256, stdin); if (*stemp==0) goto fini; /* !! need this to finish work during interactive use */ stemp= strtok(stempstore, " \n\r\t"); while (stemp) { err= readopt( stemp); /* will read inputfile if it exists */ if (err<0) exit_main(err); stemp= strtok( NULL, " \n\r\t"); } } /* thanks to [email protected] for this PHYLIP3 fix: */ /* head for end (interleave if needed) */ if (*inputfile == 0) break; format = seqFileFormat( inputfile, &skiplines, &err); if (err == 0) { #ifdef NCBI if (format == kASNseqentry || format == kASNseqset) seqlist = listASNSeqs( inputfile, skiplines, format, &nseq, &err); else #endif seqlist = listSeqs( inputfile, skiplines, format, &nseq, &err); } if (err != 0) erralert(err); else if (listonly) { dumpSeqList(seqlist,format); free( seqlist); } else { /* choose whichSeq if needed */ if (nseq == 1 || chooseall || (quietly && whichSeq == 0)) { chooseall= true; whichSeq = 1; quietly = true; /* no loop */ } else if (whichSeq > nseq && quietly) { erralert(eItemNotFound); err= eItemNotFound; } else if (whichSeq > nseq || !quietly) { dumpSeqList(seqlist, format); fprintf(stderr,"\nChoose a sequence (# or All): \n"); fgets(stemp= stempstore, 256, stdin); skipwhitespace(stemp); if (to_lower(*stemp) == 'a') { chooseall= true; whichSeq = 1; quietly = true; /* !? this means we don't ask for another file as well as no more whichSeqs... */ } else if (isdigit((int) *stemp)) whichSeq= atol(stemp); else whichSeq= 1; /* default */ } free( seqlist); if (false /*chooseall*/) { /* this isn't debugged yet...*/ fin = fopen(inputfile, "r"); closein= true; } while (whichSeq > 0 && whichSeq <= nseq) { /* need to open multiple output files ? */ manyout = ((chooseall || nwhichlist>1) && nseq > 1 && (outform == kPlain || outform == kGCG)); if (manyout) { if ( whichSeq == 1 ) erralert(eOneFormat); else if (closeout) { sprintf( stemp,"%s_%ld", oname, whichSeq); freopen( stemp, "w", fout); fprintf( stderr,"Writing sequence %ld to file %s\n", whichSeq, stemp); } } if (closein) { /* !! this fails... skips most seqs... */ /* !! in sequential read, must count seqs already read from whichSeq ... */ /* need major revision of ureadseq before we can do this */ atseq= whichSeq-1; seqidptr= seqid; seq = readSeqFp( whichSeq, fin, skiplines, format, &seqlen, &atseq, &err, seqidptr); skiplines= 0; } else { atseq= 0; seqidptr= seqid; #ifdef NCBI if (format == kASNseqentry || format == kASNseqset) { seqidptr= NULL; seq = readASNSeq( whichSeq, inputfile, skiplines, format, &seqlen, &atseq, &err, &seqidptr); } else #endif seq = readSeq( whichSeq, inputfile, skiplines, format, &seqlen, &atseq, &err, seqidptr); } if (gPretty.degap) { char *newseq; long newlen; newseq= compressSeq( gPretty.gapchar, seq, seqlen, &newlen); if (newseq) { free(seq); seq= newseq; seqlen= newlen; } } if (outform == kMSF) checksum= GCGchecksum(seq, seqlen, &checkall); else if (verbose) checksum= seqchecksum(seq, seqlen, &checkall); if (verbose) fprintf( stderr, "Sequence %ld, length= %ld, checksum= %X, format= %s, id= %s\n", whichSeq, seqlen, (int)checksum, formatstr(format), seqidptr); if (err != 0) erralert(err); else { /* format fixes that writeseq doesn't do */ switch ((int) outform) { case kPIR: if (seqout == 0) fprintf( foo,"\\\\\\\n"); break; case kASN1: if (seqout == 0) fprintf( foo, "%s", kASN1headline); break; case kPhylip: if (seqout == 0) { if (!interleaved) { /* bug, nseq is for 1st infile only */ if (chooseall) i= nseq; else i=1; if (phylvers >= 4) fprintf(foo," %ld %ld\n", i, seqlen); else fprintf(foo," %ld %ld YF\n", i, seqlen); } seqlen0 = seqlen; } else if (seqlen != seqlen0) { erralert(eUnequalSize); if (seqlen < seqlen0) seq = (char *)realloc(seq, seqlen0); for (i=seqlen; i<seqlen0; i++) seq[i]= gPretty.gapchar; seqlen = seqlen0; seq[seqlen] = 0; } break; case kPAUP: if (seqout == 0) { seqtype= getseqtype(seq, seqlen); seqlen0 = seqlen; } else if (seqlen != seqlen0) { erralert(eUnequalSize); if (seqlen < seqlen0) seq = (char *)realloc(seq, seqlen0); for (i=seqlen; i<seqlen0; i++) seq[i]= gPretty.gapchar; seqlen = seqlen0; seq[seqlen] = 0; } break; } if (doupper) for (i = 0; i<seqlen; i++) seq[i] = to_upper(seq[i]); else if (dolower) for (i = 0; i<seqlen; i++) seq[i] = to_lower(seq[i]); if (doreverse) { long j, k; char ctemp; for (j=0, k=seqlen-1; j <= k; j++, k--) { ctemp = compl[seq[j] - ' ']; seq[j] = compl[seq[k] - ' ']; seq[k] = ctemp; } } if ((gPretty.isactive || outform==kPAUP) && gPretty.domatch && firstseq != NULL) { for (i=0; i<seqlen; i++) if (seq[i]==firstseq[i]) seq[i]= gPretty.matchchar; } if (gPretty.isactive && gPretty.numtop && seqout == 0) { gPretty.numline = 1; indexout(); (void) writeSeq( fout, seq, seqlen, outform, seqidptr); gPretty.numline = 2; indexout(); (void) writeSeq( fout, seq, seqlen, outform, seqidptr); gPretty.numline = 0; } indexout(); nlines = writeSeq( fout, seq, seqlen, outform, seqidptr); seqout++; } if ((gPretty.isactive || outform==kPAUP) && gPretty.domatch && firstseq == NULL) { firstseq= seq; seq = NULL; } else if (seq!=NULL) { free(seq); seq = NULL; } #ifdef NCBI if ( (format == kASNseqentry || format == kASNseqset) && seqidptr && seqidptr!= seqid) free(seqidptr); #endif if (chooseall) whichSeq++; else if (iwhichlist<nwhichlist) whichSeq= whichlist[iwhichlist++]; else whichSeq= 0; } if (closein) { fclose(fin); closein= false; } } whichSeq = 0; } while (nfile > 0 || !quietly); fini: if (firstseq) { free(firstseq); firstseq= NULL; } if (err || listonly) exit_main(err); if (gPretty.isactive && gPretty.numbot) { gPretty.numline = 2; indexout(); (void) writeSeq( fout, seq, seqlen, outform, seqidptr); gPretty.numline = 1; indexout(); (void) writeSeq( fout, seq, seqlen, outform, seqidptr); gPretty.numline = 0; } if (outform == kMSF) { if (*oname) cp= oname; else cp= inputfile; fprintf(foo, "\n %s MSF: %ld Type: N January 01, 1776 12:00 Check: %ld ..\n\n", cp, seqlen, checkall); } if (outform == kPAUP) { fprintf(foo,"#NEXUS\n"); if (*oname) cp= oname; else cp= inputfile; fprintf(foo,"[%s -- data title]\n\n", cp); /* ! now have header lines for each sequence... put them before "begin data;... */ } if (outform==kPhylip && interleaved) { if (phylvers >= 4) fprintf(foo," %d %ld\n", seqout, seqlen); else fprintf(foo," %d %ld YF\n", seqout, seqlen); } if (interleaved) { /* interleave species lines in true output */ /* nlines is # lines / sequence */ short iline, j, leaf, iseq; char *s = stempstore; indexout(); noutindex--; /* mark eof */ for (leaf=0; leaf<nlines; leaf++) { if (outform == kMSF && leaf == 1) { fputs("//\n\n", foo); } if (outform == kPAUP && leaf==1) { switch (seqtype) { case kDNA : cp= "dna"; break; case kRNA : cp= "rna"; break; case kNucleic : cp= "dna"; break; case kAmino : cp= "protein"; break; case kOtherSeq: cp= "dna"; break; } fprintf(foo,"\nbegin data;\n"); fprintf(foo," dimensions ntax=%d nchar=%ld;\n", seqout, seqlen); fprintf(foo," format datatype=%s interleave missing=%c", cp, gPretty.gapchar); if (gPretty.domatch) fprintf(foo," matchchar=%c", gPretty.matchchar); fprintf(foo,";\n matrix\n"); } for (iseq=0; iseq<noutindex; iseq++) { fseek(ftmp, outindex[iseq], 0); for (iline=0; iline<=leaf; iline++) if (!fgets(s, 256, ftmp)) *s= 0; if (ftell(ftmp) <= outindex[iseq+1]) fputs( s, foo); } for (j=0; j<gPretty.interline; j++) fputs( "\n", foo); /* some want spacer line */ } fclose(ftmp); /* tmp disappears */ fout= foo; } if (outform == kASN1) fprintf( foo, "} }\n"); if (outform == kPAUP) fprintf( foo,";\n end;\n"); if (outindex != NULL) free(outindex); exit_main(0); }
int main(int argc, char **argv) { char *input_file = NULL; input_file = (char*)malloc(sizeof(char)*1024); int machines = 1; double epsilon = 0.001; if(argc != 6) exit_main(); for(int i=1;i<argc-1;i++) { if(argv[i][0]!='-') { exit_main(); } i++; switch(argv[i-1][1]) { case 'p': machines = atoi(argv[i]); break; case 'e': epsilon = atof(argv[i]); break; default: fprintf(stderr,"unknow options:-%s\n",argv[i-1]); exit_main(); break; } } strcpy(input_file, argv[argc-1]); FILE *fp = fopen(input_file,"r"); printf("Split the data......\n"); int *query = NULL; int k = 0; int nr_query = 1; int l = 0; struct Query_Info *q_info = NULL; int *nr_in_machine = NULL; struct Query_Machine *query_machine = NULL; nr_in_machine = (int*)malloc(sizeof(int)*machines); for(int i=0;i<machines;i++) nr_in_machine[i] = 0; if(fp==NULL) { fprintf(stderr, "can't open input file %s\n",input_file); exit(1); } max_line_len = 1024; line = Malloc(char,max_line_len); while(readline(fp)!=NULL) { l++; } rewind(fp); fclose(fp); //printf("l=%d\n",l); //exit(1); query = (int*)malloc(sizeof(int)*l); statistic_queries(input_file, query, l); qsort(query, l, sizeof(int), compare_query);// in decending order //for(int i=0;i<l;i++) //printf("query:%d\n",query[i]); //exit(1); for(int j=1;j<l;j++) { if(query[j] != query[j-1]) nr_query++; } //printf("nr_query=%d",nr_query); //exit(1); // q_info = (struct Query_Info *)malloc(sizeof(Query_Info)*nr_query); q_info[0].query = query[0]; for(int j=0;j<nr_query;j++) { q_info[j].num = 0; q_info[j].selected = false; q_info[j].machine_id = INF; } // calculate the number of instances for each query. for(int j=0;j<l;j++) { if(query[j]==q_info[k].query) { q_info[k].num++; } else { k++; q_info[k].query = query[j]; q_info[k].num++; } } //address the imbalance issue. i.e., different computing nodes will get almost //the same number of instances. //solve_imbalance_issue(q_info, nr_query, machines, l, epsilon, nr_in_machine); printf("Slove the imbalance issue.\n"); query_machine = (Query_Machine*)malloc(sizeof(Query_Machine)*nr_query); address_imbalance_doublelist(q_info, nr_query, machines, l, epsilon, nr_in_machine, query_machine); //for(int i=0;i<machines;i++) //printf("nr_in_machine[%d]=%d\n",i,nr_in_machine[i]); //exit(1); //for(int i=0;i<nr_query;i++) //printf("query:%d->machined_id:%d\n",q_info[i].query,q_info[i].machine_id); //exit(1); double average = (double) l/machines; for(int i=0;i<machines;i++) { printf("Instance Count: %d in Machine %d* ",nr_in_machine[i], i); printf("Difference:%d* ", nr_in_machine[i]-(int)average); printf("Difference Rate:%f%\n",((double)nr_in_machine[i]-average)/average*100); } //split the input file split(input_file, l, machines, nr_query, query_machine, query); printf("The splited data have been completed!!\n"); //free the assigned memory //system("cd temp_dir/"); //system("ls"); //system("cd .."); //system("rm -r temp_dir"); free(q_info); free(nr_in_machine); free(query_machine); free(query); free(line); free(input_file); return 0; }