]> git.donarmstrong.com Git - mothur.git/blobdiff - pintail.cpp
working on testing
[mothur.git] / pintail.cpp
index 84c3219822920e21bc20d89f2fdf6b4f58ead1f3..2362eb5ac80416f6aa86d8b7d011e275d7d3a88d 100644 (file)
@@ -92,7 +92,7 @@ int Pintail::doPrep() {
                m->mothurOut("Getting conservation... "); cout.flush();
                if (consfile == "") { 
                        m->mothurOut("Calculating probability of conservation for your template sequences.  This can take a while...  I will output the frequency of the highest base in each position to a .freq file so that you can input them using the conservation parameter next time you run this command.  Providing the .freq file will improve speed.    "); cout.flush();
-                       probabilityProfile = decalc->calcFreq(templateSeqs, outputDir + getSimpleName(templateFileName)); 
+                       probabilityProfile = decalc->calcFreq(templateSeqs, templateFileName); 
                        if (m->control_pressed) {  return 0;  }
                        m->mothurOut("Done."); m->mothurOutEndLine();
                }else                           {   probabilityProfile = readFreq();    m->mothurOut("Done.");            }
@@ -170,20 +170,20 @@ int Pintail::doPrep() {
                        string noOutliers, outliers;
                        
                        if ((!filter) && (seqMask == "")) {
-                               noOutliers = outputDir + getRootName(getSimpleName(templateFileName)) + "pintail.quan";
+                               noOutliers = templateFileName + "pintail.quan";
                        }else if ((!filter) && (seqMask != "")) { 
-                               noOutliers = outputDir + getRootName(getSimpleName(templateFileName)) + "pintail.masked.quan";
+                               noOutliers =templateFileName + "pintail.masked.quan";
                        }else if ((filter) && (seqMask != "")) { 
-                               noOutliers = outputDir + getRootName(getSimpleName(templateFileName)) + "pintail.filtered." + getSimpleName(getRootName(fastafile)) + "masked.quan";
+                               noOutliers = templateFileName + "pintail.filtered." + m->getSimpleName(m->getRootName(fastafile)) + "masked.quan";
                        }else if ((filter) && (seqMask == "")) { 
-                               noOutliers = outputDir + getRootName(getSimpleName(templateFileName)) + "pintail.filtered." + getSimpleName(getRootName(fastafile)) + "quan";
+                               noOutliers = templateFileName + "pintail.filtered." + m->getSimpleName(m->getRootName(fastafile)) + "quan";
                        }
 
                        decalc->removeObviousOutliers(quantilesMembers, templateSeqs.size());
                        
                        if (m->control_pressed) {  return 0;  }
                
-                       string outputString = "";
+                       string outputString = "#" + m->getVersion() + "\n";
                        
                        //adjust quantiles
                        for (int i = 0; i < quantilesMembers.size(); i++) {
@@ -196,20 +196,20 @@ int Pintail::doPrep() {
                                        }
                                }else{
                                        
-                                       sort(quantilesMembers[i].begin(), quantilesMembers[i].end(), compareQuanMembers);
+                                       sort(quantilesMembers[i].begin(), quantilesMembers[i].end());
                                        
                                        //save 10%
-                                       temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.10)].score);
+                                       temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.10)]);
                                        //save 25%
-                                       temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.25)].score);
+                                       temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.25)]);
                                        //save 50%
-                                       temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.5)].score);
+                                       temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.5)]);
                                        //save 75%
-                                       temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.75)].score);
+                                       temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.75)]);
                                        //save 95%
-                                       temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.95)].score);
+                                       temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.95)]);
                                        //save 99%
-                                       temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.99)].score);
+                                       temp.push_back(quantilesMembers[i][int(quantilesMembers[i].size() * 0.99)]);
                                        
                                }
                                
@@ -224,6 +224,9 @@ int Pintail::doPrep() {
                        
                        printQuanFile(noOutliers, outputString);
                        
+                       //free memory
+                       quantilesMembers.clear();
+                       
                        m->mothurOut("Done."); m->mothurOutEndLine();
                }
                
@@ -310,11 +313,12 @@ int Pintail::print(MPI_File& out, MPI_File& outAcc) {
                        
                        MPI_Status statusAcc;
                        int 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;
+
                        results = true;
                }
                outputString += "Observed\t";
@@ -329,10 +333,11 @@ int Pintail::print(MPI_File& out, MPI_File& outAcc) {
                
                MPI_Status status;
                int length = outputString.length();
-               char buf2[length];
-               strcpy(buf2, outputString.c_str()); 
+               char* buf2 = new char[length];
+               memcpy(buf2, outputString.c_str(), length);
                                
                MPI_File_write_shared(out, buf2, length, MPI_CHAR, &status);
+               delete buf2;
                
                return results;
        }
@@ -424,21 +429,29 @@ vector<float> Pintail::readFreq() {
                MPI_File inMPI;
                MPI_Offset size;
                MPI_Status status;
+
+               //char* inFileName = new char[consfile.length()];
+               //memcpy(inFileName, consfile.c_str(), consfile.length());
                
-               char inFileName[consfile.length()];
+               char inFileName[1024];
                strcpy(inFileName, consfile.c_str());
 
                MPI_File_open(MPI_COMM_WORLD, inFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI);  
                MPI_File_get_size(inMPI, &size);
+               //delete inFileName;
 
-               char buffer[size];
+               char* buffer = new char[size];
                MPI_File_read(inMPI, buffer, size, MPI_CHAR, &status);
 
                string tempBuf = buffer;
+               delete buffer;
 
                if (tempBuf.length() > size) { tempBuf = tempBuf.substr(0, size);  }
                istringstream iss (tempBuf,istringstream::in);
                
+               //read version
+               string line = m->getline(iss); m->gobble(iss);
+               
                while(!iss.eof()) {
                        iss >> pos >> num;
        
@@ -453,7 +466,7 @@ vector<float> Pintail::readFreq() {
                                prob.push_back(Pi);  
                        }
                        
-                       gobble(iss);
+                       m->gobble(iss);
                }
        
                MPI_File_close(&inMPI);
@@ -461,7 +474,10 @@ vector<float> Pintail::readFreq() {
        #else   
 
                ifstream in;
-               openInputFile(consfile, in);
+               m->openInputFile(consfile, in);
+               
+               //read version
+               string line = m->getline(in); m->gobble(in);
                                
                while(!in.eof()){
                        
@@ -478,7 +494,7 @@ vector<float> Pintail::readFreq() {
                                prob.push_back(Pi);  
                        }
                        
-                       gobble(in);
+                       m->gobble(in);
                }
                in.close();
                
@@ -530,14 +546,14 @@ void Pintail::createProcessesQuan() {
                                //write out data to file so parent can read it
                                ofstream out;
                                string s = toString(getpid()) + ".temp";
-                               openOutputFile(s, out);
+                               m->openOutputFile(s, out);
                                
                                                                
                                //output observed distances
                                for (int i = 0; i < quantilesMembers.size(); i++) {
                                        out << quantilesMembers[i].size() << '\t';
                                        for (int j = 0; j < quantilesMembers[i].size(); j++) {
-                                               out << quantilesMembers[i][j].score << '\t' << quantilesMembers[i][j].member1 << '\t' << quantilesMembers[i][j].member2 << '\t';
+                                               out << quantilesMembers[i][j] << '\t';
                                        }
                                        out << endl;
                                }
@@ -558,28 +574,26 @@ void Pintail::createProcessesQuan() {
                for (int i=0;i<processors;i++) { 
                        ifstream in;
                        string s = toString(processIDS[i]) + ".temp";
-                       openInputFile(s, in);
+                       m->openInputFile(s, in);
                        
-                       vector< vector<quanMember> > quan; 
+                       vector< vector<float> > quan; 
                        quan.resize(100);
                        
                        //get quantiles
-                       for (int m = 0; m < quan.size(); m++) {
+                       for (int h = 0; h < quan.size(); h++) {
                                int num;
                                in >> num; 
                                
-                               gobble(in);
+                               m->gobble(in);
 
-                               vector<quanMember> q;  float w; int b, n;
+                               vector<float> q;  float w; 
                                for (int j = 0; j < num; j++) {
-                                       in >> w >> b >> n;
-       
-                                       quanMember newMember(w, b, n);
-                                       q.push_back(newMember);
+                                       in >> w;
+                                       q.push_back(w);
                                }
 
-                               quan[m] = q;
-                               gobble(in);
+                               quan[h] = q;
+                               m->gobble(in);
                        }
                        
        
@@ -621,18 +635,27 @@ vector< vector<float> > Pintail::readQuantiles() {
                MPI_Offset size;
                MPI_Status status;
                
-               char inFileName[quanfile.length()];
+               //char* inFileName = new char[quanfile.length()];
+               //memcpy(inFileName, quanfile.c_str(), quanfile.length());
+               
+               char inFileName[1024];
                strcpy(inFileName, quanfile.c_str());
 
                MPI_File_open(MPI_COMM_WORLD, inFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI);  
                MPI_File_get_size(inMPI, &size);
+               //delete inFileName;
 
-               char buffer[size];
+
+               char* buffer = new char[size];
                MPI_File_read(inMPI, buffer, size, MPI_CHAR, &status);
 
                string tempBuf = buffer;
                if (tempBuf.length() > size) { tempBuf = tempBuf.substr(0, size);  }
                istringstream iss (tempBuf,istringstream::in);
+               delete buffer;
+               
+               //read version
+               string line = m->getline(iss); m->gobble(iss);
                
                while(!iss.eof()) {
                        iss >> num >> ten >> twentyfive >> fifty >> seventyfive >> ninetyfive >> ninetynine; 
@@ -648,7 +671,7 @@ vector< vector<float> > Pintail::readQuantiles() {
                        
                        quan.push_back(temp);  
                        
-                       gobble(iss);
+                       m->gobble(iss);
                }
        
                MPI_File_close(&inMPI);
@@ -656,7 +679,10 @@ vector< vector<float> > Pintail::readQuantiles() {
        #else   
 
                ifstream in;
-               openInputFile(quanfile, in);
+               m->openInputFile(quanfile, in);
+               
+               //read version
+               string line = m->getline(in); m->gobble(in);
                        
                while(!in.eof()){
                        
@@ -673,7 +699,7 @@ vector< vector<float> > Pintail::readQuantiles() {
                        
                        quan.push_back(temp);  
        
-                       gobble(in);
+                       m->gobble(in);
                }
                in.close();
        #endif
@@ -700,24 +726,30 @@ void Pintail::printQuanFile(string file, string outputString) {
                        MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
 
                        int outMode=MPI_MODE_CREATE|MPI_MODE_WRONLY;
+
+                       //char* FileName = new char[file.length()];
+                       //memcpy(FileName, file.c_str(), file.length());
                        
-                       char FileName[file.length()];
+                       char FileName[1024];
                        strcpy(FileName, file.c_str());
                        
                        if (pid == 0) {
                                MPI_File_open(MPI_COMM_SELF, FileName, outMode, MPI_INFO_NULL, &outQuan);  //comm, filename, mode, info, filepointer
                                
                                int length = outputString.length();
-                               char buf[length];
-                               strcpy(buf, outputString.c_str()); 
+                               char* buf = new char[length];
+                               memcpy(buf, outputString.c_str(), length);
                                        
                                MPI_File_write(outQuan, buf, length, MPI_CHAR, &status);
-                       
+                               delete buf;
+
                                MPI_File_close(&outQuan);
                        }
+
+                       //delete FileName;
                #else
                        ofstream outQuan;
-                       openOutputFile(file, outQuan);
+                       m->openOutputFile(file, outQuan);
                        
                        outQuan << outputString;