]> git.donarmstrong.com Git - mothur.git/blobdiff - indicatorcommand.cpp
Merge remote-tracking branch 'mothur/master'
[mothur.git] / indicatorcommand.cpp
index e8863f75fbdf330b338a28bc5a19aa9f45ce5dc2..01d8c2e8634d65c31f11515f89ecfa950b81a1ae 100644 (file)
@@ -38,10 +38,11 @@ vector<string> IndicatorCommand::setParameters(){
 string IndicatorCommand::getHelpString(){      
        try {
                string helpString = "";
-               helpString += "The indicator command reads a shared or relabund file and a tree or design file, and outputs a .indicator.tre and .indicator.summary file. \n";
+               helpString += "The indicator command can be run in 3 ways: with a shared or relabund file and a design file, or with a shared or relabund file and a tree file, or with a shared or relabund file, tree file and design file. \n";
+               helpString += "The indicator command outputs a .indicator.summary file and a .indicator.tre if a tree is given. \n";
                helpString += "The new tree contains labels at each internal node.  The label is the node number so you can relate the tree to the summary file.\n";
                helpString += "The summary file lists the indicator value for each OTU for each node.\n";
-               helpString += "The indicator command parameters are tree, groups, shared, relabund, design and label. The tree parameter is required as well as either shared or relabund.\n";
+               helpString += "The indicator command parameters are tree, groups, shared, relabund, design and label. \n";
                helpString += "The design parameter allows you to relate the tree to the shared or relabund file, if your tree contains the grouping names, or if no tree is provided to group your groups into groupings.\n";                  
                helpString += "The groups parameter allows you to specify which of the groups in your shared or relabund you would like analyzed, or if you provide a design file the groups in your design file.  The groups may be entered separated by dashes.\n";
                helpString += "The label parameter indicates at what distance your tree relates to the shared or relabund.\n";
@@ -95,8 +96,8 @@ IndicatorCommand::IndicatorCommand(string option)  {
                        }
                        
                        m->runParse = true;
-                       m->Groups.clear();
-                       m->namesOfGroups.clear();
+                       m->clearGroups();
+                       m->clearAllGroups();
                        m->Treenames.clear();
                        m->names.clear();
                        
@@ -168,17 +169,17 @@ IndicatorCommand::IndicatorCommand(string option)  {
                        groups = validParameter.validFile(parameters, "groups", false);                 
                        if (groups == "not found") { groups = "";  Groups.push_back("all"); }
                        else { m->splitAtDash(groups, Groups);  }                       
-                       m->Groups = Groups;
+                       m->setGroups(Groups);
                        
                        label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; m->mothurOut("You did not provide a label, I will use the first label in your inputfile."); m->mothurOutEndLine(); label=""; }  
                        
                        string temp = validParameter.validFile(parameters, "iters", false);             if (temp == "not found") { temp = "1000"; }
-                       convert(temp, iters); 
+                       m->mothurConvert(temp, iters); 
                        
                        temp = validParameter.validFile(parameters, "processors", false);       if (temp == "not found"){       temp = m->getProcessors();      }
                        m->setProcessors(temp);
-                       convert(temp, processors); 
+                       m->mothurConvert(temp, processors); 
                        
                        if ((relabundfile == "") && (sharedfile == "")) { 
                                //is there are current file available for either of these?
@@ -229,18 +230,21 @@ int IndicatorCommand::execute(){
                
                int start = time(NULL);
        
-               //read designfile if given and set up globaldatas groups for read of sharedfiles
+               //read designfile if given and set up groups for read of sharedfiles
                if (designfile != "") {
                        designMap = new GroupMap(designfile);
                        designMap->readDesignMap();
                        
                        //fill Groups - checks for "all" and for any typo groups
                        SharedUtil* util = new SharedUtil();
-                       util->setGroups(Groups, designMap->namesOfGroups);
+                       vector<string> nameGroups = designMap->getNamesOfGroups();
+                       util->setGroups(Groups, nameGroups);
+                       designMap->setNamesOfGroups(nameGroups);
                        delete util;
                        
                        //loop through the Groups and fill Globaldata's Groups with the design file info
-                       m->Groups = designMap->getNamesSeqs(Groups);
+                       vector<string> namesSeqs = designMap->getNamesSeqs(Groups);
+                       m->setGroups(namesSeqs);
                }
        
                /***************************************************/
@@ -256,8 +260,8 @@ int IndicatorCommand::execute(){
                        if (lookupFloat[0] == NULL) { m->mothurOut("[ERROR] reading relabund file."); m->mothurOutEndLine(); return 0; }
                }
                
-               //reset Globaldatas groups if needed
-               if (designfile != "") { m->Groups = Groups; }
+               //reset groups if needed
+               if (designfile != "") { m->setGroups(Groups); }
                        
                /***************************************************/
                //    reading tree info                                                    //
@@ -272,7 +276,7 @@ int IndicatorCommand::execute(){
                        for (int i = 0; i < m->Treenames.size(); i++) { 
                                //sanity check - is this a group that is not in the sharedfile?
                                if (designfile == "") {
-                                       if (!(m->inUsersGroups(m->Treenames[i], m->namesOfGroups))) {
+                                       if (!(m->inUsersGroups(m->Treenames[i], m->getAllGroups()))) {
                                                m->mothurOut("[ERROR]: " + m->Treenames[i] + " is not a group in your shared or relabund file."); m->mothurOutEndLine();
                                                mismatch = true;
                                        }
@@ -282,7 +286,7 @@ int IndicatorCommand::execute(){
                                        vector<string> myNames = designMap->getNamesSeqs(myGroups);
                                        
                                        for(int k = 0; k < myNames.size(); k++) {
-                                               if (!(m->inUsersGroups(myNames[k], m->namesOfGroups))) {
+                                               if (!(m->inUsersGroups(myNames[k], m->getAllGroups()))) {
                                                        m->mothurOut("[ERROR]: " + myNames[k] + " is not a group in your shared or relabund file."); m->mothurOutEndLine();
                                                        mismatch = true;
                                                }
@@ -322,9 +326,9 @@ int IndicatorCommand::execute(){
                        /***************************************************/
                        //    create ouptut tree - respecting pickedGroups //
                        /***************************************************/
-                       Tree* outputTree = new Tree(m->Groups.size(), treeMap); 
+                       Tree* outputTree = new Tree(m->getNumGroups(), treeMap); 
                        
-                       outputTree->getSubTree(T[0], m->Groups);
+                       outputTree->getSubTree(T[0], m->getGroups());
                        outputTree->assembleTree();
                                
                        //no longer need original tree, we have output tree to use and label
@@ -353,7 +357,7 @@ int IndicatorCommand::execute(){
                if (sharedfile != "") {  for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } }
                else { for (int i = 0; i < lookupFloat.size(); i++) {  delete lookupFloat[i];  } }
                
-               if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        remove(outputNames[i].c_str()); } return 0; }
+               if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        m->mothurRemove(outputNames[i]);        } return 0; }
                
                //set tree file as new current treefile
                if (treefile != "") {
@@ -412,11 +416,11 @@ int IndicatorCommand::GetIndicatorSpecies(){
                        vector<SharedRAbundVector*> subset;
                        
                        //for each grouping
-                       for (int i = 0; i < designMap->namesOfGroups.size(); i++) {
+                       for (int i = 0; i < (designMap->getNamesOfGroups()).size(); i++) {
                                
                                for (int k = 0; k < lookup.size(); k++) {
                                        //are you from this grouping?
-                                       if (designMap->getGroup(lookup[k]->getGroup()) == designMap->namesOfGroups[i]) {
+                                       if (designMap->getGroup(lookup[k]->getGroup()) == (designMap->getNamesOfGroups())[i]) {
                                                subset.push_back(lookup[k]);
                                                groupsAlreadyAdded.insert(lookup[k]->getGroup());
                                        }
@@ -436,10 +440,10 @@ int IndicatorCommand::GetIndicatorSpecies(){
                        vector<SharedRAbundFloatVector*> subset;
                        
                        //for each grouping
-                       for (int i = 0; i < designMap->namesOfGroups.size(); i++) {
+                       for (int i = 0; i < (designMap->getNamesOfGroups()).size(); i++) {
                                for (int k = 0; k < lookupFloat.size(); k++) {
                                        //are you from this grouping?
-                                       if (designMap->getGroup(lookupFloat[k]->getGroup()) == designMap->namesOfGroups[i]) {
+                                       if (designMap->getGroup(lookupFloat[k]->getGroup()) == (designMap->getNamesOfGroups())[i]) {
                                                subset.push_back(lookupFloat[k]);
                                                groupsAlreadyAdded.insert(lookupFloat[k]->getGroup());
                                        }
@@ -1116,7 +1120,7 @@ vector<float> IndicatorCommand::getPValues(vector< vector<SharedRAbundFloatVecto
        try {
                vector<float> pvalues;
                
-#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
                if(processors == 1){
                        pvalues = driver(groupings, groupingsMap, num, indicatorValues, iters);
                        for (int i = 0; i < pvalues.size(); i++) { pvalues[i] /= (double)iters; }
@@ -1183,7 +1187,7 @@ vector<float> IndicatorCommand::getPValues(vector< vector<SharedRAbundFloatVecto
                                        in >> numTemp; m->gobble(in);
                                        pvalues[j] += numTemp;
                                }
-                               in.close(); remove(tempFile.c_str());
+                               in.close(); m->mothurRemove(tempFile);
                        }
                        for (int i = 0; i < pvalues.size(); i++) { pvalues[i] /= (double)iters; } 
                }
@@ -1230,7 +1234,7 @@ vector<float> IndicatorCommand::getPValues(vector< vector<SharedRAbundVector*> >
        try {
                vector<float> pvalues;
                
-#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
                if(processors == 1){
                        pvalues = driver(groupings, groupingsMap, num, indicatorValues, iters);
                        for (int i = 0; i < pvalues.size(); i++) { pvalues[i] /= (double)iters; }
@@ -1296,7 +1300,7 @@ vector<float> IndicatorCommand::getPValues(vector< vector<SharedRAbundVector*> >
                                        in >> numTemp; m->gobble(in);
                                        pvalues[j] += numTemp;
                                }
-                               in.close(); remove(tempFile.c_str());
+                               in.close(); m->mothurRemove(tempFile);
                        }
                        for (int i = 0; i < pvalues.size(); i++) { pvalues[i] /= (double)iters; } 
                }