#include #define boolean int //{ This program inputs a T4klist in the file //T4klist.Thetaktree. //This list of trees should have data in the form //a b c d aabb abab abba //where (a b) (c d) is assumed to be correct. Ties will be ignored, //as will the values of aabb etc. //It analyzes the list for consistency, assuming that there are relatively //few errors in the list. //It outputs a new list //T4klist.ErrorCorrect //with some "corrections" for the sake of consistency. The error rectification //is done in a number of "passes", which may be specified by the user. //A file //ErrorCorrectT4k.comments //tells information //about the process. //Values of inconsistency are not reliable since aabb etc are ignored //in the error correction process. //Values of b therefore may differ slightly from those //obtained when ties are allowed in the lists. //Ties are not allowed in the list under this error correction process //and also because the tree building method does not allow //stars in the tree. //} const int maxleaves = 30; // {maximum number of species allowed} const int maxreps = 100; // {maximum number of error correcting runs plus 1} const int labellength = 50; // {length of the labels for species} const int maxstringlength = 1000; //{maximal length of an identifying string} int t4first[maxleaves-3][maxleaves-3][ maxleaves-3][ maxleaves-3]; int t4second[maxleaves-3][maxleaves-3][ maxleaves-3][ maxleaves-3]; int t4third[maxleaves-3][maxleaves-3][ maxleaves-3][ maxleaves-3]; int t4fourth[maxleaves-3][maxleaves-3][ maxleaves-3][ maxleaves-3]; float t4aabb[maxleaves-3][maxleaves-3][ maxleaves-3][ maxleaves-3]; float t4abab[maxleaves-3][maxleaves-3][ maxleaves-3][ maxleaves-3]; float t4abba[maxleaves-3][maxleaves-3][ maxleaves-3][ maxleaves-3]; char t4code[maxleaves-3][maxleaves-3][ maxleaves-3][ maxleaves-3][3]; int actualleaves; // {The actual number of leaves or strings. // It should be less than maxleaves.} ofstream outcomment; //{the output file, containing a description of the output tree} ifstream int4list; // {the file containing the trees of the list of t4} ofstream outt4list; // {the file containing the modified trees} char identification[maxstringlength]; // {identifying string for the source of data} int stringlength; // {actual length of the identification string} int testflag; //{flag for the kind of criterion used} boolean writemonitor, writeperm; float aabb, abab, abba, oldaabb, oldabab, oldabba; int numberreversed; float totaldemerits; int actualrepcount; boolean immediate; boolean same; int nonstdtype; char ch; int flag; // {= 0 if - counts as a separate symbol, = 1 if - is to be ignored} char labels[maxleaves+1][labellength]; // {******* utility variables} int temp, i, j, k, l, i1, j1; int demerit2, demerit3, demerit4; // {demerit2 counts the number of demerits for (ij)(kl); // demerit3 counts the number of demerits for (ik)(jl); // demerit4 counts the number of demerits for (il)(jk).} int jtrue,ktrue,ltrue; // {jtrue = j+1, ktrue = k+2, etc. offset j,k,l} int rep; int repcount; //{the number of error rectifying runs} int newone; int limit; boolean done; int oldcode; void finishup(void); void finishup(void) { char ch; outcomment.close(); int4list.close(); outt4list.close(); cout<<"Quit the application now.\n"; cin.get(ch); } boolean check (int, int, int, int); boolean check(int a, int b, int c,int d) //{This function returns true if (ab)(cd) is selected by the t4code[1]. //It returns false if any two are equal. //Note that a,b,c, d are the true labels for the taxa.} { int temp; int first, second, third, fourth; if (a == b) return false; else if (a == c) return false; else if (a == d) return false; else if (b == c) return false; else if (b == d) return false; else if (c == d) return false; else { first = a; second = b; third = c; fourth = d; if (second < first) { temp = first; first = second; second = temp; } if (third < first) { temp = first; first = third; third = temp; } if (fourth < first) { temp = first; first = fourth; fourth = temp; } if (third < second) { temp = second; second = third; third = temp; } if (fourth < second) { temp = second; second = fourth; fourth = temp; } if (fourth < third) { temp = third; third = fourth; fourth = temp; } // {now in order first < second < third < fourth} temp = t4code[first-1][second-2][third-3][ fourth-4][1]; if (temp == 2) { //{first matches second; but first = order1 in the original list} if ((first == a) && (second == b)) return true; else if ((first == b) && (second == a)) return true; else if ((first == c) && (second == d)) return true; else if ((first == d) && (second == c)) return true; else return false; } else if (temp == 3) { if ((first == a) && (third == b)) return true; else if ((first == b) && (third == a)) return true; else if ((first == c) && (third == d)) return true; else if ((first == d) && (third == c)) return true; else return false; } else { if ((first == a) && (fourth == b)) return true; else if ((first == b) && (fourth == a)) return true; else if ((first == c) && (fourth == d)) return true; else if ((first == d) && (fourth == c)) return true; else return false; } } } // {check} void readln(void); void readln(void) { boolean done; char ch; done = false; while (! done) { { int4list.get(ch); if ((ch == '\n')||(ch == '\r')) done = true; } } } // readln int main() { writeperm = true; writemonitor = true; numberreversed = 0; outcomment.open("ErrorRectifyT4k.output"); outt4list.open("T4klist.ErrorRectify"); // {read in the t4list} int4list.open("T4klist.Thetaktree"); int4list>>actualleaves >>flag; outt4list << actualleaves << ' ' << flag << '\n'; if ((actualleaves > maxleaves) || (actualleaves < 0)) { outcomment<< "Wrong number of leaves\n"; finishup(); } readln(); // {read in the identifying data for the source of strings} stringlength = 0; done = false; while (! done) { int4list.get(ch); if ((ch == '\n') || (ch == '\r')) { done = true; } else if (stringlength >= maxstringlength) done = true; else { identification[stringlength]= ch; stringlength = stringlength + 1; } } for (i1 = 0; i1< stringlength; i1++) { outcomment <> i; done = false; j1 = 1; while (! done) { int4list.get(ch); if (ch == '\n' ) done = true; else if (j1 >= labellength) { done = true; readln(); } else { labels[i1][j1]=ch; j1++;} } if (i != i1) { outcomment<<"****** Mismatch of species in file \n" ; outcomment<<" Species should be in numerical order.\n"; finishup(); } } for (i1 = 1; i1<= actualleaves; i1++) { outt4list <> i >> j >> k >> l >> aabb >>abab >> abba; readln(); if (i == 0) { done = true; } else { oldcode = 2; // {sort into order ij) outcomment<<"Error in reordering of taxa " <