]> git.donarmstrong.com Git - mothur.git/blobdiff - getsharedotucommand.cpp
added sequence name to error string in fastq.info. Changed np_shannon to npshannon.
[mothur.git] / getsharedotucommand.cpp
index f627aedef1223caf64b4eca8a37f06217315c2b6..2312649d1cff739956638ba2ad8788949669f1d5 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include "getsharedotucommand.h"
+#include "sharedutilities.h"
 
 //**********************************************************************************************************************
 vector<string> GetSharedOTUCommand::setParameters(){   
@@ -82,6 +83,7 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option)  {
                
                //allow user to run help
                if(option == "help") { help(); abort = true; calledHelp = true; }
+               else if(option == "citation") { citation(); abort = true; calledHelp = true;}
                
                else {
                        vector<string> myArray = setParameters();
@@ -147,7 +149,7 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option)  {
                                        m->mothurOut("No valid current list file. You must provide a list file."); m->mothurOutEndLine(); 
                                        abort = true;
                                }
-                       }else {  format = "list";       }
+                       }else {  format = "list";       m->setListFile(listfile); }
                        
                        groupfile = validParameter.validFile(parameters, "group", true);
                        if (groupfile == "not open") { abort = true; }  
@@ -158,7 +160,7 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option)  {
                                        m->mothurOut("No valid current group file. You must provide a group file."); m->mothurOutEndLine(); 
                                        abort = true;
                                }
-                       }
+                       }else { m->setGroupFile(groupfile); }
                                                
                        if ((listfile == "") || (groupfile == "")) { m->mothurOut("The list and group parameters are required."); m->mothurOutEndLine(); abort = true; }
                        
@@ -180,7 +182,7 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option)  {
                        else { 
                                userGroups = "unique." + groups;
                                m->splitAtDash(groups, Groups);
-                               m->Groups = Groups;
+                               m->setGroups(Groups);
                                
                        }
                        
@@ -189,14 +191,14 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option)  {
                        else { 
                                userGroups = groups;
                                m->splitAtDash(groups, Groups);
-                               m->Groups = Groups;
+                               m->setGroups(Groups);
                                unique = false;
                        }
                        
                        fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not open") { abort = true; }
                        else if (fastafile == "not found") {  fastafile = "";  }        
-                               
+                       else { m->setFastaFile(fastafile); }
                }
 
        }
@@ -219,12 +221,18 @@ int GetSharedOTUCommand::execute(){
                if (m->control_pressed) { delete groupMap; return 0; }
                
                if (Groups.size() == 0) {
-                       Groups = groupMap->namesOfGroups;
+                       Groups = groupMap->getNamesOfGroups();
                        
                        //make string for outputfile name
                        userGroups = "unique.";
                        for(int i = 0; i < Groups.size(); i++) {  userGroups += Groups[i] + "-";  }
                        userGroups = userGroups.substr(0, userGroups.length()-1);
+               }else{
+                       //sanity check for group names
+                       SharedUtil util;
+                       vector<string> namesOfGroups = groupMap->getNamesOfGroups(); 
+                       util.setGroups(Groups, namesOfGroups);
+                       groupMap->setNamesOfGroups(namesOfGroups);
                }
        
                //put groups in map to find easier
@@ -260,7 +268,7 @@ int GetSharedOTUCommand::execute(){
                        
                        if (m->control_pressed) { 
                                if (lastlist != NULL) {         delete lastlist;        }
-                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); }  outputTypes.clear();
+                               for (int i = 0; i < outputNames.size(); i++) {  m->mothurRemove(outputNames[i]); }  outputTypes.clear();
                                delete groupMap; return 0;
                        }
                        
@@ -319,11 +327,11 @@ int GetSharedOTUCommand::execute(){
                
 
                //reset groups parameter
-               m->Groups.clear();  
+               m->clearGroups();  
                
                if (lastlist != NULL) {         delete lastlist;        }
                
-               if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) {   remove(outputNames[i].c_str()); }  delete groupMap; return 0; } 
+               if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) {   m->mothurRemove(outputNames[i]); }  delete groupMap; return 0; } 
                
                //set fasta file as new current fastafile
                string current = "";
@@ -375,7 +383,7 @@ int GetSharedOTUCommand::process(ListVector* shared) {
                                
                //go through each bin, find out if shared
                for (int i = 0; i < shared->getNumBins(); i++) {
-                       if (m->control_pressed) { outNames.close(); remove(outputFileNames.c_str()); return 0; }
+                       if (m->control_pressed) { outNames.close(); m->mothurRemove(outputFileNames); return 0; }
                        
                        bool uniqueOTU = true;
                        
@@ -453,7 +461,7 @@ int GetSharedOTUCommand::process(ListVector* shared) {
                outNames.close();
                
                if (!wroteSomething) {
-                       remove(outputFileNames.c_str());
+                       m->mothurRemove(outputFileNames);
                        string outputString = "\t" + toString(num) + " - No otus shared by groups";
                        
                        string groupString = "";