]> git.donarmstrong.com Git - mothur.git/blobdiff - getrelabundcommand.cpp
added mothur executable to cvs
[mothur.git] / getrelabundcommand.cpp
index 8293c9b31485bad93f1bb8875f2e53fc28a1d746..4c79b21ab53e903fec94fa17296a7da30a9569bf 100644 (file)
@@ -39,7 +39,7 @@ GetRelAbundCommand::GetRelAbundCommand(string option) {
                        //if the user changes the output directory command factory will send this info to us in the output parameter 
                        outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
                                outputDir = ""; 
-                               outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it  
+                               outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it       
                        }
                        
                        //make sure the user has already run the read.otu command
@@ -52,7 +52,7 @@ GetRelAbundCommand::GetRelAbundCommand(string option) {
                        label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
-                               if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
+                               if(label != "all") {  m->splitAtDash(label, labels);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
@@ -66,7 +66,7 @@ GetRelAbundCommand::GetRelAbundCommand(string option) {
                        if (groups == "not found") { groups = ""; pickedGroups = false; }
                        else { 
                                pickedGroups = true;
-                               splitAtDash(groups, Groups);
+                               m->splitAtDash(groups, Groups);
                                globaldata->Groups = Groups;
                        }
                        
@@ -94,7 +94,7 @@ void GetRelAbundCommand::help(){
                m->mothurOut("The label parameter allows you to select what distance levels you would like, and are also separated by dashes.\n");
                m->mothurOut("The scale parameter allows you to select what scale you would like to use. Choices are totalgroup, totalotu, averagegroup, averageotu, default is totalgroup.\n");
                m->mothurOut("The get.relabund command should be in the following format: get.relabund(groups=yourGroups, label=yourLabels).\n");
-               m->mothurOut("Example get.relabund(groups=A-B-C, scale=log10).\n");
+               m->mothurOut("Example get.relabund(groups=A-B-C, scale=averagegroup).\n");
                m->mothurOut("The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n");
                m->mothurOut("The get.relabund command outputs a .relabund file.\n");
                m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n");
@@ -118,9 +118,9 @@ int GetRelAbundCommand::execute(){
        
                if (abort == true) { return 0; }
                
-               string outputFileName = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "relabund";
+               string outputFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "relabund";
                ofstream out;
-               openOutputFile(outputFileName, out);
+               m->openOutputFile(outputFileName, out);
                out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint);
                
                read = new ReadOTUFile(globaldata->inputFileName);      
@@ -147,7 +147,7 @@ int GetRelAbundCommand::execute(){
                                userLabels.erase(lookup[0]->getLabel());
                        }
                        
-                       if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
+                       if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
                                string saveLabel = lookup[0]->getLabel();
                        
                                for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }  
@@ -226,14 +226,6 @@ int GetRelAbundCommand::getRelAbundance(vector<SharedRAbundVector*>& thisLookUp,
        try {
                if (pickedGroups) { eliminateZeroOTUS(thisLookUp); }
 
-               int totalNumSeqs = 0;
-               if ((scale == "totalgroup") || (scale == "averagegroup")) {
-                       for (int i = 0; i < thisLookUp.size(); i++) {
-                               //find total number of sequences in all samples
-                               totalNumSeqs += thisLookUp[i]->getNumSeqs();
-                       }
-               }
-               float averageNumSeqs = totalNumSeqs / (float) thisLookUp.size();
                
                 for (int i = 0; i < thisLookUp.size(); i++) {
                        out << thisLookUp[i]->getLabel() << '\t' << thisLookUp[i]->getGroup() << '\t' << thisLookUp[i]->getNumBins() << '\t';
@@ -246,16 +238,15 @@ int GetRelAbundCommand::getRelAbundance(vector<SharedRAbundVector*>& thisLookUp,
                                
                                float relabund = 0.0;
                                
-                               if (scale == "totalgroup") {  //abund of this otu compared to total number of sequence in my group
-                                       relabund = abund / (float) totalNumSeqs;
+                               if (scale == "totalgroup") { 
+                                       relabund = abund / (float) thisLookUp[i]->getNumSeqs();
                                }else if (scale == "totalotu") {
                                        //calc the total in this otu
                                        int totalOtu = 0;
                                        for (int l = 0; l < thisLookUp.size(); l++) {  totalOtu += thisLookUp[l]->getAbundance(j); }
-                                       
                                        relabund = abund / (float) totalOtu;
                                }else if (scale == "averagegroup") {
-                                       relabund = abund / (float) averageNumSeqs;
+                                       relabund = abund / (float) (thisLookUp[i]->getNumSeqs() / (float) thisLookUp[i]->getNumBins());
                                }else if (scale == "averageotu") {
                                        //calc the total in this otu
                                        int totalOtu = 0;