]> git.donarmstrong.com Git - mothur.git/commitdiff
fixing out labels to match those in shared file. If shared file does not have column...
authorSarah Westcott <mothur.westcott@gmail.com>
Fri, 13 Apr 2012 18:44:22 +0000 (14:44 -0400)
committerSarah Westcott <mothur.westcott@gmail.com>
Fri, 13 Apr 2012 18:44:22 +0000 (14:44 -0400)
indicatorcommand.cpp
metastatscommand.cpp
otuassociationcommand.cpp
sharedrabundfloatvector.cpp
sharedrabundvector.cpp

index 94d5c84344f86eb4676f0e71111e898c5c28596d..97f480e749b7042a07a39d0f48890ff137d49dd0 100644 (file)
@@ -468,17 +468,17 @@ int IndicatorCommand::GetIndicatorSpecies(){
                                
                        if (m->control_pressed) { out.close(); return 0; }
                        
-                       out << (j+1) << '\t' << indicatorValues[j] << '\t'; 
+                       out << m->currentBinLabels[j] << '\t' << indicatorValues[j] << '\t'; 
                        
                        if (pValues[j] > (1/(float)iters)) { out << pValues[j] << endl; } 
                        else { out << "<" << (1/(float)iters) << endl; }
                        
                        if (pValues[j] <= 0.05) {
-                               cout << "OTU" << j+1 << '\t' << indicatorValues[j]  << '\t';
+                               cout << m->currentBinLabels[j] << '\t' << indicatorValues[j]  << '\t';
                                string pValueString = "<" + toString((1/(float)iters)); 
                                if (pValues[j] > (1/(float)iters)) { pValueString = toString(pValues[j]); cout << pValues[j];} 
                                else { cout << "<" << (1/(float)iters); }
-                               m->mothurOutJustToLog("OTU" + toString(j+1) + "\t" + toString(indicatorValues[j]) + "\t" + pValueString); 
+                               m->mothurOutJustToLog(m->currentBinLabels[j] + "\t" + toString(indicatorValues[j]) + "\t" + pValueString); 
                                m->mothurOutEndLine(); 
                        }
                }
@@ -514,7 +514,7 @@ int IndicatorCommand::GetIndicatorSpecies(Tree*& T){
                
                //print headings
                out << "TreeNode\t";
-               for (int i = 0; i < numBins; i++) { out << "OTU" << (i+1) << "_IndValue" << '\t' << "pValue" << '\t'; }
+               for (int i = 0; i < numBins; i++) { out << m->currentBinLabels[i] << "_IndValue" << '\t' << "pValue" << '\t'; }
                out << endl;
                
                m->mothurOutEndLine(); m->mothurOut("Node\tSpecies\tIndicatorValue\tpValue\n");
@@ -671,11 +671,11 @@ int IndicatorCommand::GetIndicatorSpecies(Tree*& T){
                                }
                                
                                if (pValues[j] <= 0.05) {
-                                       cout << i+1 << "\tOTU" << j+1 << '\t' << indicatorValues[j]  << '\t';
+                                       cout << i+1 << '\t' << m->currentBinLabels[j] << '\t' << indicatorValues[j]  << '\t';
                                        string pValueString = "<" + toString((1/(float)iters)); 
                                        if (pValues[j] > (1/(float)iters)) { pValueString = toString(pValues[j]); cout << pValues[j];} 
                                        else { cout << "<" << (1/(float)iters); }
-                                       m->mothurOutJustToLog(toString(i) + "\tOTU" + toString(j+1) + "\t" + toString(indicatorValues[j]) + "\t" + pValueString); 
+                                       m->mothurOutJustToLog(toString(i) + "\t" + m->currentBinLabels[j] + "\t" + toString(indicatorValues[j]) + "\t" + pValueString); 
                                        m->mothurOutEndLine(); 
                                }
                        }
index 4744424d426d61243894d4779fa60dcd20781be3..c5d349bc77b685b67a1e3251fa70f15602bb215d 100644 (file)
@@ -483,25 +483,16 @@ int MetaStatsCommand::driver(int start, int num, vector<SharedRAbundVector*>& th
                                outputNames.pop_back();
                        }else {
                 
-                ofstream outTemp;
-                string tempOut = outputDir + "data." + setA + "-" + setB + ".matrix";
-                m->openOutputFile(tempOut, outTemp);
-                for (int i = 0; i < subset.size(); i++) { outTemp << '\t' << subset[i]->getGroup(); }
-                outTemp << endl;
-                
-                
                                //fill data
                                for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
                                        //data[j] = new double[subset.size()];
                                        data2[j].resize(subset.size(), 0.0);
-                    outTemp << "OTU" << (j+1);
+                   
                                        for (int i = 0; i < subset.size(); i++) {
                                                data2[j][i] = (subset[i]->getAbundance(j));
-                        outTemp << '\t' << subset[i]->getAbundance(j);
                                        }
-                    outTemp << endl;
                                }
-                               outTemp.close();
+                               
                                m->mothurOut("Comparing " + setA + " and " + setB + "..."); m->mothurOutEndLine(); 
                                //metastat_main(output, thisLookUp[0]->getNumBins(), subset.size(), threshold, iters, data, setACount);
                                
index eeefb41ffa9781aacad02a594cd4d61859631cb0..0d41e63f3526bc9af4e3933d5f3337d62ebd0f2a 100644 (file)
@@ -308,8 +308,7 @@ int OTUAssociationCommand::process(vector<SharedRAbundVector*>& lookup){
                                else if (method == "kendall")   {       coef = linear.calcKendall(xy[i], xy[k], sig);   }                   
                                else { m->mothurOut("[ERROR]: invalid method, choices are spearman, pearson or kendall."); m->mothurOutEndLine(); m->control_pressed = true; }
                        
-                               if (m->binLabelsInFile.size() != 0) { out << m->binLabelsInFile[i] << '\t' << m->binLabelsInFile[k] << '\t' << coef << '\t' << sig << endl; }
-                else { out << i+1 << '\t' << k+1 << '\t' << coef << '\t' << sig << endl; }
+                out << m->binLabelsInFile[i] << '\t' << m->binLabelsInFile[k] << '\t' << coef << '\t' << sig << endl;
                        }
                }
                
@@ -437,8 +436,7 @@ int OTUAssociationCommand::process(vector<SharedRAbundFloatVector*>& lookup){
                                else if (method == "kendall")   {       coef = linear.calcKendall(xy[i], xy[k], sig);   }                   
                                else { m->mothurOut("[ERROR]: invalid method, choices are spearman, pearson or kendall."); m->mothurOutEndLine(); m->control_pressed = true; }
                                
-                if (m->binLabelsInFile.size() != 0) { out << m->binLabelsInFile[i] << '\t' << m->binLabelsInFile[k] << '\t' << coef << '\t' << sig << endl; }
-                else { out << i+1 << '\t' << k+1 << '\t' << coef << '\t' << sig << endl; }
+                out << m->binLabelsInFile[i] << '\t' << m->binLabelsInFile[k] << '\t' << coef << '\t' << sig << endl; 
                        }
                }
                
index 9f6c15687edc77d0fbd77df7de286cbe98b6339e..b6d916a1900edc643291df4432728d3619a711a6 100644 (file)
@@ -48,7 +48,7 @@ SharedRAbundFloatVector::SharedRAbundFloatVector(ifstream& f) : DataVector(), ma
                //are we at the beginning of the file??
                if (m->saveNextLabel == "") {  
                        f >> label; 
-                       
+            
                        //is this a shared file that has headers
                        if (label == "label") { 
                                //gets "group"
@@ -67,20 +67,40 @@ SharedRAbundFloatVector::SharedRAbundFloatVector(ifstream& f) : DataVector(), ma
                                        if (m->control_pressed) { break; }
                                        string temp;
                                        iStringStream >> temp;  m->gobble(iStringStream);
-                                       
+                    
                                        m->binLabelsInFile.push_back(temp);
                                }
                                
-                               f >> label;
-                       }
-               }else { label = m->saveNextLabel; }
+                               f >> label >> groupN >> num;
+                       }else {
+                //read in first row since you know there is at least 1 group.
+                f >> groupN >> num;
+                
+                //make binlabels because we don't have any
+                string snumBins = toString(num);
+                m->binLabelsInFile.clear();
+                for (int i = 0; i < num; i++) {  
+                    //if there is a bin label use it otherwise make one
+                    string binLabel = "Otu";
+                    string sbinNumber = toString(i+1);
+                    if (sbinNumber.length() < snumBins.length()) { 
+                        int diff = snumBins.length() - sbinNumber.length();
+                        for (int h = 0; h < diff; h++) { binLabel += "0"; }
+                    }
+                    binLabel += sbinNumber;
+                    m->binLabelsInFile.push_back(binLabel);
+                }
+            }
+               }else { 
+            label = m->saveNextLabel; 
+            
+            //read in first row since you know there is at least 1 group.
+            f >> groupN >> num;
+        }
                
                //reset labels, currentLabels may have gotten changed as otus were eliminated because of group choices or sampling
                m->currentBinLabels = m->binLabelsInFile;
                
-               //read in first row since you know there is at least 1 group.
-               f >> groupN >> num;
-
                holdLabel = label;
                
                //add new vector to lookup
index 70b09603be0f4cd85081f9f1b530c5ec0b61040e..3901650cef965dc7a3c0126ecb54a8fb425e434d 100644 (file)
@@ -95,16 +95,36 @@ SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0),
                                        m->binLabelsInFile.push_back(temp);
                                }
                                
-                               f >> label;
-                       }
-               }else { label = m->saveNextLabel; }
+                               f >> label >> groupN >> num;
+                       }else {
+                //read in first row since you know there is at least 1 group.
+                f >> groupN >> num;
+                
+                //make binlabels because we don't have any
+                string snumBins = toString(num);
+                m->binLabelsInFile.clear();
+                for (int i = 0; i < num; i++) {  
+                    //if there is a bin label use it otherwise make one
+                    string binLabel = "Otu";
+                    string sbinNumber = toString(i+1);
+                    if (sbinNumber.length() < snumBins.length()) { 
+                        int diff = snumBins.length() - sbinNumber.length();
+                        for (int h = 0; h < diff; h++) { binLabel += "0"; }
+                    }
+                    binLabel += sbinNumber;
+                    m->binLabelsInFile.push_back(binLabel);
+                }
+            }
+               }else { 
+            label = m->saveNextLabel; 
+            
+            //read in first row since you know there is at least 1 group.
+            f >> groupN >> num;
+        }
                
                //reset labels, currentLabels may have gotten changed as otus were eliminated because of group choices or sampling
                m->currentBinLabels = m->binLabelsInFile;
                
-               //read in first row since you know there is at least 1 group.
-               f >> groupN >> num;
-               
                holdLabel = label;
                
                //add new vector to lookup