]> git.donarmstrong.com Git - mothur.git/commitdiff
fixed bug in corr.axes so that it now uses the shared files bin numbers. finished...
authorSarah Westcott <mothur.westcott@gmail.com>
Tue, 3 Apr 2012 17:36:38 +0000 (13:36 -0400)
committerSarah Westcott <mothur.westcott@gmail.com>
Tue, 3 Apr 2012 17:36:38 +0000 (13:36 -0400)
Mothur.xcodeproj/project.pbxproj
corraxescommand.cpp
matrixoutputcommand.cpp
matrixoutputcommand.h
mothur.h
sequenceparser.cpp
subsample.cpp
subsample.h

index 2088e3791a7a7602e0a8015c06606afad8dc5d52..b181f5b68fee47805e3691c67d4ba5fd8af82f3e 100644 (file)
@@ -3,7 +3,7 @@
        archiveVersion = 1;
        classes = {
        };
-       objectVersion = 45;
+       objectVersion = 46;
        objects = {
 
 /* Begin PBXBuildFile section */
                08FB7793FE84155DC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        attributes = {
+                               LastUpgradeCheck = 0420;
                                ORGANIZATIONNAME = "Schloss Lab";
                        };
                        buildConfigurationList = 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "Mothur" */;
-                       compatibilityVersion = "Xcode 3.1";
+                       compatibilityVersion = "Xcode 3.2";
                        developmentRegion = English;
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                ALWAYS_SEARCH_USER_PATHS = NO;
                                COPY_PHASE_STRIP = NO;
                                GCC_DYNAMIC_NO_PIC = NO;
-                               GCC_ENABLE_FIX_AND_CONTINUE = YES;
                                GCC_MODEL_TUNING = G5;
                                GCC_OPTIMIZATION_LEVEL = 0;
                                INSTALL_PATH = /usr/local/bin;
                                        "-lncurses",
                                        "-lreadline",
                                );
-                               PREBINDING = NO;
                                SDKROOT = macosx10.6;
                                USER_HEADER_SEARCH_PATHS = "";
                        };
                                        "-lncurses",
                                        "-lreadline",
                                );
-                               PREBINDING = NO;
                                SDKROOT = macosx10.6;
                        };
                        name = Release;
index a1c3a3d6cd9e6849fb5f86be42a1d46bcd9bc138..c27eb4b9ac335112f19244c708cee9bb8630feda 100644 (file)
@@ -321,7 +321,7 @@ int CorrAxesCommand::calcPearson(map<string, vector<float> >& axes, ofstream& ou
           //for each otu
           for (int i = 0; i < lookupFloat[0]->getNumBins(); i++) {
                   
-                  if (metadatafile == "") {  out << i+1;       }
+                  if (metadatafile == "") {  out << m->currentBinLabels[i];    }
                   else {  out << metadataLabels[i];            }
                                   
                   //find the averages this otu - Y
@@ -456,7 +456,7 @@ int CorrAxesCommand::calcSpearman(map<string, vector<float> >& axes, ofstream& o
                //for each otu
                for (int i = 0; i < lookupFloat[0]->getNumBins(); i++) {
                        
-                       if (metadatafile == "") {  out << i+1;  }
+                       if (metadatafile == "") {  out << m->currentBinLabels[i];       }
                        else {  out << metadataLabels[i];               }
                        
                        //find the ranks of this otu - Y
@@ -609,7 +609,7 @@ int CorrAxesCommand::calcKendall(map<string, vector<float> >& axes, ofstream& ou
                //for each otu
                for (int i = 0; i < lookupFloat[0]->getNumBins(); i++) {
                
-                       if (metadatafile == "") {  out << i+1;  }
+                       if (metadatafile == "") {  out << m->currentBinLabels[i];       }
                        else {  out << metadataLabels[i];               }
                        
                        //find the ranks of this otu - Y
index cada2f16035f6bfea109aa4112908b9bb8c128f3..73c38f7ca3b06cd5b38b45b070beb2c8fd2f0a8b 100644 (file)
@@ -425,7 +425,7 @@ int MatrixOutputCommand::execute(){
        }
 }
 /***********************************************************/
-void MatrixOutputCommand::printSims(ostream& out, vector< vector<float> >& simMatrix) {
+void MatrixOutputCommand::printSims(ostream& out, vector< vector<double> >& simMatrix) {
        try {
                
                out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint);
@@ -464,7 +464,7 @@ int MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
                vector< vector< vector<seqDist> > > calcDistsTotals;  //each iter, one for each calc, then each groupCombos dists. this will be used to make .dist files
 
         vector< vector<seqDist>  > calcDists; calcDists.resize(matrixCalculators.size());              
-       
+
         for (int thisIter = 0; thisIter < iters; thisIter++) {
             
             vector<SharedRAbundVector*> thisItersLookup = thisLookup;
@@ -472,9 +472,26 @@ int MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
             if (subsample) {
                 SubSample sample;
                 vector<string> tempLabels; //dont need since we arent printing the sampled sharedRabunds
-                thisItersLookup = sample.getSamplePreserve(thisLookup, tempLabels, subsampleSize);
+                
+                //make copy of lookup so we don't get access violations
+                vector<SharedRAbundVector*> newLookup;
+                for (int k = 0; k < thisItersLookup.size(); k++) {
+                    SharedRAbundVector* temp = new SharedRAbundVector();
+                    temp->setLabel(thisItersLookup[k]->getLabel());
+                    temp->setGroup(thisItersLookup[k]->getGroup());
+                    newLookup.push_back(temp);
+                }
+                
+                //for each bin
+                for (int k = 0; k < thisItersLookup[0]->getNumBins(); k++) {
+                    if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) {  delete newLookup[j];  } return 0; }
+                    for (int j = 0; j < thisItersLookup.size(); j++) { newLookup[j]->push_back(thisItersLookup[j]->getAbundance(k), thisItersLookup[j]->getGroup()); }
+                }
+                
+                tempLabels = sample.getSample(newLookup, subsampleSize);
+                thisItersLookup = newLookup;
             }
-            cout << thisIter << endl;
+        
             if(processors == 1){
                 driver(thisItersLookup, 0, numGroups, calcDists);
             }else{
@@ -608,9 +625,11 @@ int MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
             calcDistsTotals.push_back(calcDists);
             
             if (subsample) {  
+                
                 //clean up memory
-               // for (int i = 0; i < thisItersLookup.size(); i++) { delete thisItersLookup[i]; }
-               // thisItersLookup.clear();
+                for (int i = 0; i < thisItersLookup.size(); i++) { delete thisItersLookup[i]; }
+                thisItersLookup.clear();
+                for (int i = 0; i < calcDists.size(); i++) {  calcDists[i].clear(); }
             }
                }
                
@@ -619,7 +638,7 @@ int MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
             
             vector< vector<seqDist>  > calcAverages; calcAverages.resize(matrixCalculators.size()); 
             for (int i = 0; i < calcAverages.size(); i++) {  //initialize sums to zero.
-                calcAverages[i].resize(calcDists[i].size());
+                calcAverages[i].resize(calcDistsTotals[0][i].size());
                 
                 for (int j = 0; j < calcAverages[i].size(); j++) {
                     calcAverages[i][j].seq1 = calcDists[i][j].seq1;
@@ -645,7 +664,7 @@ int MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
             //find standard deviation
             vector< vector<seqDist>  > stdDev; stdDev.resize(matrixCalculators.size());
             for (int i = 0; i < stdDev.size(); i++) {  //initialize sums to zero.
-                stdDev[i].resize(calcDists[i].size());
+                stdDev[i].resize(calcDistsTotals[0][i].size());
                 
                 for (int j = 0; j < stdDev[i].size(); j++) {
                     stdDev[i][j].seq1 = calcDists[i][j].seq1;
@@ -671,11 +690,11 @@ int MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
             
             //print results
             for (int i = 0; i < calcDists.size(); i++) {
-                vector< vector<float> > matrix; //square matrix to represent the distance
+                vector< vector<double> > matrix; //square matrix to represent the distance
                 matrix.resize(thisLookup.size());
                 for (int k = 0; k < thisLookup.size(); k++) {  matrix[k].resize(thisLookup.size(), 0.0); }
                 
-                vector< vector<float> > stdmatrix; //square matrix to represent the stdDev
+                vector< vector<double> > stdmatrix; //square matrix to represent the stdDev
                 stdmatrix.resize(thisLookup.size());
                 for (int k = 0; k < thisLookup.size(); k++) {  stdmatrix[k].resize(thisLookup.size(), 0.0); }
 
@@ -692,54 +711,57 @@ int MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
                     stdmatrix[column][row] = stdDist;
                 }
             
-                string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel()  + ".results";
-                outputNames.push_back(distFileName); outputTypes["subsample"].push_back(distFileName);
+                string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel()  + "." + output + ".ave.dist";
+                outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName);
+                ofstream outAve;
+                m->openOutputFile(distFileName, outAve);
+                outAve.setf(ios::fixed, ios::floatfield); outAve.setf(ios::showpoint);
+                
+                printSims(outAve, matrix);
+                
+                outAve.close();
+                
+                distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel()  + "." + output + ".std.dist";
+                outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName);
+                ofstream outSTD;
+                m->openOutputFile(distFileName, outSTD);
+                outSTD.setf(ios::fixed, ios::floatfield); outSTD.setf(ios::showpoint);
+                
+                printSims(outSTD, stdmatrix);
+                
+                outSTD.close();
+
+            }
+        }else {
+        
+            for (int i = 0; i < calcDists.size(); i++) {
+                if (m->control_pressed) { break; }
+                
+                //initialize matrix
+                vector< vector<double> > matrix; //square matrix to represent the distance
+                matrix.resize(thisLookup.size());
+                for (int k = 0; k < thisLookup.size(); k++) {  matrix[k].resize(thisLookup.size(), 0.0); }
+                
+                for (int j = 0; j < calcDists[i].size(); j++) {
+                    int row = calcDists[i][j].seq1;
+                    int column = calcDists[i][j].seq2;
+                    double dist = calcDists[i][j].dist;
+                    
+                    matrix[row][column] = dist;
+                    matrix[column][row] = dist;
+                }
+                
+                string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel()  + "." + output + ".dist";
+                outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName);
                 ofstream outDist;
                 m->openOutputFile(distFileName, outDist);
                 outDist.setf(ios::fixed, ios::floatfield); outDist.setf(ios::showpoint);
                 
-                outDist << "Group1\tGroup2\tAverageDist\tStdDev\n";
-                for (int m = 0; m < matrix.size(); m++)        {
-                    for (int n = 0; n < m; n++)        {
-                        outDist << lookup[m]->getGroup() << '\t' <<  lookup[n]->getGroup() << '\t';
-                        outDist << matrix[m][n] << '\t' << stdmatrix[m][n] << endl; 
-                    }
-                }
-                outDist.close();
-            }
-            
-            //output averages as distance matrix
-            calcDists = calcAverages;
-        }
-        
-        for (int i = 0; i < calcDists.size(); i++) {
-            if (m->control_pressed) { break; }
-            
-            //initialize matrix
-            vector< vector<float> > matrix; //square matrix to represent the distance
-            matrix.resize(thisLookup.size());
-            for (int k = 0; k < thisLookup.size(); k++) {  matrix[k].resize(thisLookup.size(), 0.0); }
-            
-            for (int j = 0; j < calcDists[i].size(); j++) {
-                int row = calcDists[i][j].seq1;
-                int column = calcDists[i][j].seq2;
-                float dist = calcDists[i][j].dist;
+                printSims(outDist, matrix);
                 
-                matrix[row][column] = dist;
-                matrix[column][row] = dist;
+                outDist.close();
             }
-            
-            string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel()  + "." + output + ".dist";
-            outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName);
-            ofstream outDist;
-            m->openOutputFile(distFileName, outDist);
-            outDist.setf(ios::fixed, ios::floatfield); outDist.setf(ios::showpoint);
-            
-            printSims(outDist, matrix);
-            
-            outDist.close();
         }
-
                
                return 0;
        }
@@ -751,7 +773,6 @@ int MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
 /**************************************************************************************************/
 int MatrixOutputCommand::driver(vector<SharedRAbundVector*> thisLookup, int start, int end, vector< vector<seqDist> >& calcDists) { 
        try {
-               
                vector<SharedRAbundVector*> subset;
                for (int k = start; k < end; k++) { // pass cdd each set of groups to compare
                        
index f915dfcda8d7ab88040fcb1e8e2f4bbabf833590..8af539ba01ae59ed07027d63f2bd9d1859b4c217 100644 (file)
@@ -88,7 +88,7 @@ private:
        };
        vector<linePair> lines;
        
-       void printSims(ostream&, vector< vector<float> >&);
+       void printSims(ostream&, vector< vector<double> >&);
        int process(vector<SharedRAbundVector*>);
        
        vector<Calculator*> matrixCalculators;
index 1a07b6f930ec77b58a888cac1e715e2a292ea42f..2c143e8667786c5740f0aa6324ea4062eab66b76 100644 (file)
--- a/mothur.h
+++ b/mothur.h
@@ -131,9 +131,9 @@ struct clusterNode {
 struct seqDist {
        int seq1;
        int seq2;
-       float dist;
+       double dist;
        seqDist() {}
-       seqDist(int s1, int s2, float d) : seq1(s1), seq2(s2), dist(d) {}
+       seqDist(int s1, int s2, double d) : seq1(s1), seq2(s2), dist(d) {}
        ~seqDist() {}
 };
 /************************************************************/
index 6c98c047af76d2a3c29ee599b1141c336240390b..fd94b246a43217cc9cbfa131bfe4cd672955e001 100644 (file)
@@ -316,6 +316,7 @@ int SequenceParser::getSeqs(string g, string filename, bool uchimeFormat=false){
                                }
                                
                        }else { 
+                //m->mothurOut("Group " + g +  " contains " + toString(seqForThisGroup.size()) + " unique seqs.\n");
                                for (int i = 0; i < seqForThisGroup.size(); i++) {
                                        
                                        if(m->control_pressed) { out.close(); m->mothurRemove(filename); return 1; }
index d5b4e3ecf19f2114855426350e1ecfbe57780736..e6dd845adf9b64bec6c932f4cf72de6d8b9fe909 100644 (file)
@@ -8,66 +8,6 @@
 
 #include "subsample.h"
 
-//**********************************************************************************************************************
-vector<SharedRAbundVector*> SubSample::getSamplePreserve(vector<SharedRAbundVector*>& thislookup, vector<string>& newLabels, int size) {
-       try {
-               
-        vector<SharedRAbundVector*> newlookup; newlookup.resize(thislookup.size(), NULL); 
-        
-               //save mothurOut's binLabels to restore for next label
-               vector<string> saveBinLabels = m->currentBinLabels;
-               
-               int numBins = thislookup[0]->getNumBins();
-               for (int i = 0; i < thislookup.size(); i++) {           
-                       int thisSize = thislookup[i]->getNumSeqs();
-                       
-                       if (thisSize != size) {
-                               
-                               string thisgroup = thislookup[i]->getGroup();
-                               
-                               OrderVector order;
-                               for(int p=0;p<numBins;p++){
-                                       for(int j=0;j<thislookup[i]->getAbundance(p);j++){
-                                               order.push_back(p);
-                                       }
-                               }
-                               random_shuffle(order.begin(), order.end());
-                               
-                               SharedRAbundVector* temp = new SharedRAbundVector(numBins);
-                               temp->setLabel(thislookup[i]->getLabel());
-                               temp->setGroup(thislookup[i]->getGroup());
-                               
-                               newlookup[i] = temp;
-                               
-                               for (int j = 0; j < size; j++) {
-                                       
-                                       if (m->control_pressed) {  return newlookup; }
-                                       
-                                       int bin = order.get(j);
-                                       
-                                       int abund = newlookup[i]->getAbundance(bin);
-                                       newlookup[i]->set(bin, (abund+1), thisgroup);
-                               }       
-                       }
-               }
-               
-               //subsampling may have created some otus with no sequences in them
-               eliminateZeroOTUS(newlookup);
-               
-               if (m->control_pressed) { return newlookup; }
-               
-               //save mothurOut's binLabels to restore for next label
-        newLabels = m->currentBinLabels;
-               m->currentBinLabels = saveBinLabels;
-               
-               return newlookup;
-               
-       }
-       catch(exception& e) {
-               m->errorOut(e, "SubSample", "getSamplePreserve");
-               exit(1);
-       }
-}      
 //**********************************************************************************************************************
 vector<string> SubSample::getSample(vector<SharedRAbundVector*>& thislookup, int size) {
        try {
index 9156e094f9706426fa50d3d9b7e664494e839485..09c7dcdf0901f8a229ee3c89633ca1186d03a7ef 100644 (file)
@@ -21,9 +21,8 @@ class SubSample {
         SubSample() { m = MothurOut::getInstance(); }
         ~SubSample() {}
     
-        vector<string> getSample(vector<SharedRAbundVector*>&, int); //returns the bin labels for the subsample, mothurOuts binlabels are preserved so you can run this multiple times.
+        vector<string> getSample(vector<SharedRAbundVector*>&, int); //returns the bin labels for the subsample, mothurOuts binlabels are preserved so you can run this multiple times. Overwrites original vector passed in, if you need to preserve it deep copy first.
     
-        vector<SharedRAbundVector*> getSamplePreserve(vector<SharedRAbundVector*>&, vector<string>&, int);
     
     private: