]> git.donarmstrong.com Git - mothur.git/blobdiff - listvector.cpp
changed random forest output filename
[mothur.git] / listvector.cpp
index e123298930f706f9bf19d267e0ee17a5ddb41243..2758c94264a1ba527e8d7c3970e0bac53254579b 100644 (file)
 #include "ordervector.hpp"
 #include "listvector.hpp"
 
+//sorts highest to lowest
+/***********************************************************************/
+inline bool abundNamesSort(string left, string right){
+    
+    int countLeft = 0;
+    if(left != ""){
+        countLeft = 1;
+        for(int i=0;i<left.size();i++){  if(left[i] == ','){  countLeft++;  }  }
+    }
+    
+    int countRight = 0;
+    if(right != ""){
+        countRight = 1;
+        for(int i=0;i<right.size();i++){  if(right[i] == ','){  countRight++;  }  }
+    }
+    
+       if (countLeft > countRight) {
+        return true;
+    }
+    return false;      
+} 
 
 /***********************************************************************/
 
@@ -28,7 +49,7 @@ ListVector::ListVector(string id, vector<string> lv) : DataVector(id), data(lv){
        try {
                for(int i=0;i<data.size();i++){
                        if(data[i] != ""){
-                               int binSize = getNumNames(data[i]);
+                               int binSize = m->getNumNames(data[i]);
                                numBins = i+1;
                                if(binSize > maxRank)   {       maxRank = binSize;      }
                                numSeqs += binSize;
@@ -36,7 +57,7 @@ ListVector::ListVector(string id, vector<string> lv) : DataVector(id), data(lv){
                }
        }
        catch(exception& e) {
-               errorOut(e, "ListVector", "ListVector");
+               m->errorOut(e, "ListVector", "ListVector");
                exit(1);
        }
 }
@@ -55,11 +76,10 @@ ListVector::ListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numS
                        f >> inputData;
                        set(i, inputData);
                }
-               
-               gobble(f);
+               m->gobble(f);
        }
        catch(exception& e) {
-               errorOut(e, "ListVector", "ListVector");
+               m->errorOut(e, "ListVector", "ListVector");
                exit(1);
        }
 }
@@ -68,9 +88,9 @@ ListVector::ListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numS
 
 void ListVector::set(int binNumber, string seqNames){
        try {
-               int nNames_old = getNumNames(data[binNumber]);
+               int nNames_old = m->getNumNames(data[binNumber]);
                data[binNumber] = seqNames;
-               int nNames_new = getNumNames(seqNames);
+               int nNames_new = m->getNumNames(seqNames);
        
                if(nNames_old == 0)                     {       numBins++;                              }
                if(nNames_new == 0)                     {       numBins--;                              }
@@ -79,7 +99,7 @@ void ListVector::set(int binNumber, string seqNames){
                numSeqs += (nNames_new - nNames_old);
        }
        catch(exception& e) {
-               errorOut(e, "ListVector", "set");
+               m->errorOut(e, "ListVector", "set");
                exit(1);
        }
 }
@@ -95,7 +115,7 @@ string ListVector::get(int index){
 void ListVector::push_back(string seqNames){
        try {
                data.push_back(seqNames);
-               int nNames = getNumNames(seqNames);
+               int nNames = m->getNumNames(seqNames);
        
                numBins++;
        
@@ -104,7 +124,7 @@ void ListVector::push_back(string seqNames){
                numSeqs += nNames;
        }
        catch(exception& e) {
-               errorOut(e, "ListVector", "push_back");
+               m->errorOut(e, "ListVector", "push_back");
                exit(1);
        }
 }
@@ -136,15 +156,18 @@ void ListVector::print(ostream& output){
        try {
                output << label << '\t' << numBins << '\t';
        
-               for(int i=0;i<data.size();i++){
-                       if(data[i] != ""){
-                               output << data[i] << '\t';
+        vector<string> hold = data;
+        sort(hold.begin(), hold.end(), abundNamesSort);
+        
+               for(int i=0;i<hold.size();i++){
+                       if(hold[i] != ""){
+                               output << hold[i] << '\t';
                        }
                }
                output << endl;
        }
        catch(exception& e) {
-               errorOut(e, "ListVector", "print");
+               m->errorOut(e, "ListVector", "print");
                exit(1);
        }
 }
@@ -157,7 +180,7 @@ RAbundVector ListVector::getRAbundVector(){
                RAbundVector rav;
        
                for(int i=0;i<data.size();i++){
-                       int binSize = getNumNames(data[i]);
+                       int binSize = m->getNumNames(data[i]);
                        rav.push_back(binSize);
                }
        
@@ -175,7 +198,7 @@ RAbundVector ListVector::getRAbundVector(){
                return rav;
        }
        catch(exception& e) {
-               errorOut(e, "ListVector", "getRAbundVector");
+               m->errorOut(e, "ListVector", "getRAbundVector");
                exit(1);
        }
 }
@@ -187,7 +210,7 @@ SAbundVector ListVector::getSAbundVector(){
                SAbundVector sav(maxRank+1);
        
                for(int i=0;i<data.size();i++){
-                       int binSize = getNumNames(data[i]);     
+                       int binSize = m->getNumNames(data[i]);  
                        sav.set(binSize, sav.get(binSize) + 1); 
                }
                sav.set(0, 0);
@@ -196,7 +219,7 @@ SAbundVector ListVector::getSAbundVector(){
                return sav;
        }
        catch(exception& e) {
-               errorOut(e, "ListVector", "getSAbundVector");
+               m->errorOut(e, "ListVector", "getSAbundVector");
                exit(1);
        }
 }
@@ -210,7 +233,7 @@ OrderVector ListVector::getOrderVector(map<string,int>* orderMap = NULL){
                        OrderVector ov;
                
                        for(int i=0;i<data.size();i++){
-                               int binSize = getNumNames(data[i]);             
+                               int binSize = m->getNumNames(data[i]);          
                                for(int j=0;j<binSize;j++){
                                        ov.push_back(i);
                                }
@@ -238,7 +261,7 @@ OrderVector ListVector::getOrderVector(map<string,int>* orderMap = NULL){
                                        }
                                        else{
                                                if(orderMap->count(seqName) == 0){
-                                                       mothurOut(seqName + " not found, check *.names file\n");
+                                                       m->mothurOut(seqName + " not found, check *.names file\n");
                                                        exit(1);
                                                }
                                        
@@ -248,7 +271,7 @@ OrderVector ListVector::getOrderVector(map<string,int>* orderMap = NULL){
                                }
                        
                                if(orderMap->count(seqName) == 0){
-                                       mothurOut(seqName + " not found, check *.names file\n");
+                                       m->mothurOut(seqName + " not found, check *.names file\n");
                                        exit(1);
                                }
                                ov.set((*orderMap)[seqName], i);        
@@ -261,7 +284,7 @@ OrderVector ListVector::getOrderVector(map<string,int>* orderMap = NULL){
                }
        }
        catch(exception& e) {
-               errorOut(e, "ListVector", "getOrderVector");
+               m->errorOut(e, "ListVector", "getOrderVector");
                exit(1);
        }
 }