//global variables for this unit string cVersion="v1.2"; int const maxtax=2000, maxgap=1000, maxfiles=15; int nfiles=0, outgroup=0;; string filenames[maxfiles], c_line; char cread[1024]; bool codegaps=true, allgaps=true; char gapchar='-', gapAbsent='A', gapPresent='C', gapUnknown='-', unknownChar1='?', unknownChar2='n', unknownChar3='N'; //-------------------------------------------------------------------- // MAIN PROGRAM CODE void makeNexus (void) { int nchar=0, ntax, lastntax=0, ngap, eh1, eh2, es1, es2; unsigned int maxname=0; int ctax, gapcount; int gaplist[maxgap+1][4], partitions[maxfiles][4]; bool readcont, skipseq[maxtax]; string filename1, filename2, temp, cread; string taxonlist[maxtax], datamatrix[maxtax], gapmatrix[maxtax], firstocc[maxgap+1]; string fdatamatrix[maxfiles][maxtax], fgapmatrix[maxfiles][maxtax]; string infvalgap; //holding arrays for results from reading multiple files int a_nchar[maxfiles], a_ngap[maxfiles]; //functions int findHardEnd(string seq, int pos, char gapchar); int findSoftEnd(string seq, int pos, char gapchar); bool evalinf (string cmatrix[maxtax], int ntax, int cpos); struct tm *ptr; // used to display time and date, see cpp reference; time_t lt; Form1->SaveDialog1->Execute(); filename2=Form1->SaveDialog1->FileName.c_str(); ofstream outfile(filename2.c_str()); for (int cfile=0;cfileMemo1->Lines->Strings[cfile].c_str(); ifstream infile(filename1.c_str()); if (!infile) { //file open error displaymsg ("file not found"); return; } ctax=0; //initialize datamatrix, gapmatrix with empty strings for (int i=0; i>cread; while (!infile.eof()) { //read until eof readcont=true; while (readcont) { // block for skipping initial lines preceeding first ">" if (cread.substr(0,1)==">") readcont= false; else infile>>cread; } if (cfile==0) { //only read taxon list first time cread.erase(0,1); taxonlist[ctax]=cread; while (taxonlist[ctax].size()>5) { //prune trailing xx, 5 = minimum taxon name size if (taxonlist[ctax][taxonlist[ctax].size()-1]=='x') taxonlist[ctax].erase(taxonlist[ctax].size()-1); else break; } } readcont=true; while (readcont) { //read all nucleotid lines infile>>cread; if (cread.substr(0,1)==">" || infile.eof()) { readcont=false; break; } else datamatrix[ctax]=datamatrix[ctax]+cread; //concatenate individual parts (lines) of fasta sequence } ctax++; } nchar=datamatrix[0].size(); // length of first sequence in current datamatrix ntax=ctax; infile.close(); //file reading done, continue with data processing if (cfile==0) { //find maximum length of taxon names maxname=0; for (int i=0; imaxname) maxname=taxonlist[i].size(); } if (cfile!=0 && ntax!=lastntax) { //taxa dimension error displaymsg ("ERROR: the number of taxa varies among datasets"); return; } lastntax=ntax; // remember number of taxa for next round //CODE GAPS if (codegaps) { ngap=0; for (int i=1; iRichEdit1->Lines->LoadFromFile(filename2.c_str()); //return; //ofstream finalfile(filename2.c_str()); int totchar=0; for (int i=0;i0) { outfile << "BEGIN PAUP;\n"; outfile << "\tSet INCREASE=AUTO;\n"; outfile << "\toutgroup "; for (int i=0;iRichEdit1->Lines->LoadFromFile(filename2.c_str()); } //------------------------------------------------------------------- int findHardEnd (string sec, int pos, char gapchar) { bool ingap=true; //check endpos int eh; while (ingap) { pos++; if(sec[pos]==gapchar || sec[pos]==unknownChar1 || sec[pos]==unknownChar2 || sec[pos]==unknownChar3) ingap = true; else ingap=false; } eh=pos-1; return eh; } //-------------------------------------------------------------------- int findSoftEnd (string sec, int pos, char gapchar) { bool ingap=true; //check endpos int es; while (ingap) { pos++; if(sec[pos]==gapchar) ingap = true; else ingap=false; } es=pos-1; return es; } //----------------------------------------------------------------------------- bool evalinf (string cmatrix[maxtax], int ntax, int cpos) { int numAbsent=0, numPresent=0; bool result; for (int i=0;i1 && numPresent>1) result=true; else result=false; return result; }