]> git.donarmstrong.com Git - mothur.git/blobdiff - bellerophon.cpp
moved utilities out of mothur.h and into mothurOut class.
[mothur.git] / bellerophon.cpp
index 25c5de757f9de3061eb39326f4a0f5412f711327..4f48d9ce03b64ec2a5c1f52d4d3ef2feaab9d8a5 100644 (file)
@@ -132,7 +132,7 @@ int Bellerophon::print(ostream& out, ostream& outAcc) {
 //***************************************************************************************************************
 int Bellerophon::print(MPI_File& out, MPI_File& outAcc) {
        try {
-               
+       
                int pid;
                MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
                
@@ -148,35 +148,47 @@ int Bellerophon::print(MPI_File& out, MPI_File& outAcc) {
 
                        if (m->control_pressed) { return numSeqs; }
                        
-                       outString += "Name\tScore\tLeft\tRight\n";
+                       outString = "Name\tScore\tLeft\tRight\n";
+                       MPI_Status status;
+                       int olength = outString.length();
+                       char* buf5 = new char[olength];
+                       memcpy(buf5, outString.c_str(), olength);
+                                       
+                       MPI_File_write_shared(out, buf5, olength, MPI_CHAR, &status);
+                       
+                       delete buf5;
+
                        //output prefenence structure to .chimeras file
                        for (int i = 0; i < best.size(); i++) {
                                
                                if (m->control_pressed) {  return numSeqs; }
                                
-                               outString += best[i].name + "\t" +  toString(best[i].score) + "\t" + best[i].leftParent + "\t" + best[i].rightParent + "\n";
-                               
+                               outString = best[i].name + "\t" +  toString(best[i].score) + "\t" + best[i].leftParent + "\t" + best[i].rightParent + "\n";
+                       
                                MPI_Status status;
                                int length = outString.length();
-                               char buf2[length];
-                               strcpy(buf2, outString.c_str()); 
+                               char* buf2 = new char[length];
+                               memcpy(buf2, outString.c_str(), length);
                                        
                                MPI_File_write_shared(out, buf2, length, MPI_CHAR, &status);
-
+                               
+                               delete buf2;
                                
                                //calc # of seqs with preference above 95%tile
                                if (best[i].score >= cutoffScore) { 
                                        above1++; 
-                                       string outAccString;
+                                       string outAccString = "";
                                         outAccString += best[i].name + "\n";
                                        
                                        MPI_Status statusAcc;
                                        length = outAccString.length();
-                                       char buf[length];
-                                       strcpy(buf, outAccString.c_str()); 
+                                       char* buf = new char[length];
+                                       memcpy(buf, outAccString.c_str(), length);
                                        
                                        MPI_File_write_shared(outAcc, buf, length, MPI_CHAR, &statusAcc);
                                        
+                                       delete buf;
+
                                        cout << best[i].name << " is a suspected chimera at breakpoint " << toString(best[i].midpoint) << endl;
                                        cout << "It's score is " << toString(best[i].score) << " with suspected left parent " << best[i].leftParent << " and right parent " << best[i].rightParent << endl;
                                }
@@ -234,7 +246,7 @@ int Bellerophon::getChimeras() {
                numSeqsPerProcessor = iters / processors;
                
                //each process hits this only once
-               int startPos = pid * numSeqsPerProcessor;
+               unsigned long int startPos = pid * numSeqsPerProcessor;
                if(pid == processors - 1){
                                numSeqsPerProcessor = iters - pid * numSeqsPerProcessor;
                }
@@ -261,12 +273,13 @@ int Bellerophon::getChimeras() {
                                        int length;
                                        MPI_Recv(&length, 1, MPI_INT, j, 2001, MPI_COMM_WORLD, &status);
                                        
-                                       char buf[length];
+                                       char* buf = new char[length];
                                        MPI_Recv(&buf, length, MPI_CHAR, j, 2001, MPI_COMM_WORLD, &status);
                                        
                                        string temp = buf;
                                        if (temp.length() > length) { temp = temp.substr(0, length); }
-                                       
+                                       delete buf;
+
                                        MPIBestSend.push_back(temp);
                                }
                                
@@ -287,16 +300,17 @@ int Bellerophon::getChimeras() {
                                if (m->control_pressed) { return 0; }
                                
                                int bestLength = MPIBestSend[i].length();
-                               char buf[bestLength];
-                               strcpy(buf, MPIBestSend[i].c_str()); 
+                               char* buf = new char[bestLength];
+                               memcpy(buf, MPIBestSend[i].c_str(), bestLength);
                                
                                MPI_Send(&bestLength, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD);
                                MPI_Send(buf, bestLength, MPI_CHAR, 0, 2001, MPI_COMM_WORLD);
+                               delete buf;
                        }
                        
                        MPIBestSend.clear();
                }
-               
+               MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case
        #else
        
                //divide breakpoints between processors
@@ -312,7 +326,7 @@ int Bellerophon::getChimeras() {
                                int numSeqsPerProcessor = iters / processors;
                                
                                for (int i = 0; i < processors; i++) {
-                                       int startPos = i * numSeqsPerProcessor;
+                                       unsigned long int startPos = i * numSeqsPerProcessor;
                                        if(i == processors - 1){
                                                numSeqsPerProcessor = iters - i * numSeqsPerProcessor;
                                        }
@@ -651,7 +665,7 @@ int Bellerophon::writePrefs(string file, linePair tempLine) {
        try {
        
                ofstream outTemp;
-               openOutputFile(file, outTemp);
+               m->openOutputFile(file, outTemp);
                
                //lets you know what part of the pref matrix you are writing
                outTemp << tempLine.start << '\t' << tempLine.num << endl;
@@ -681,12 +695,12 @@ int Bellerophon::readPrefs(string file) {
        try {
        
                ifstream inTemp;
-               openInputFile(file, inTemp);
+               m->openInputFile(file, inTemp);
                
                int start, num;
                
                //lets you know what part of the pref matrix you are writing
-               inTemp >> start >> num;  gobble(inTemp);
+               inTemp >> start >> num;  m->gobble(inTemp);
                
                for (int i = start; i < num; i++) {
                        
@@ -696,7 +710,7 @@ int Bellerophon::readPrefs(string file) {
                        
                                inTemp >> pref[i][j].name >> pref[i][j].leftParent >> pref[i][j].rightParent;
                                inTemp >> pref[i][j].score >> pref[i][j].closestLeft >> pref[i][j].closestRight >> pref[i][j].midpoint;
-                               gobble(inTemp);
+                               m->gobble(inTemp);
                        }
                }