]> git.donarmstrong.com Git - mothur.git/blobdiff - binsequencecommand.cpp
fixed clearcut version bug, added group count output to get.groups and remove.groups
[mothur.git] / binsequencecommand.cpp
index a761d5a6eed759f3fd4f93d0d3500c20a4e87676..8b137c8935e099f6e806f60746244c0d244b9687 100644 (file)
@@ -9,16 +9,64 @@
 
 #include "binsequencecommand.h"
 
+//**********************************************************************************************************************
+vector<string> BinSeqCommand::getValidParameters(){    
+       try {
+               string AlignArray[] =  {"fasta","label","name", "group","outputdir","inputdir"};
+               vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "BinSeqCommand", "getValidParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> BinSeqCommand::getRequiredParameters(){ 
+       try {
+               string AlignArray[] =  {"fasta"};
+               vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "BinSeqCommand", "getRequiredParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> BinSeqCommand::getRequiredFiles(){      
+       try {
+               string AlignArray[] =  {"list"};
+               vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "BinSeqCommand", "getRequiredFiles");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+BinSeqCommand::BinSeqCommand(){        
+       try {
+               abort = true; calledHelp = true; 
+               vector<string> tempOutNames;
+               outputTypes["fasta"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "BinSeqCommand", "BinSeqCommand");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
 BinSeqCommand::BinSeqCommand(string option) {
        try {
                globaldata = GlobalData::getInstance();
-               abort = false;
+               abort = false; calledHelp = false;   
                allLines = 1;
                labels.clear();
                
                //allow user to run help
-               if(option == "help") { help(); abort = true; }
+               if(option == "help") { help(); abort = true; calledHelp = true; }
                
                else {
                        //valid paramters for this command
@@ -36,6 +84,10 @@ BinSeqCommand::BinSeqCommand(string option) {
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //initialize outputTypes
+                       vector<string> tempOutNames;
+                       outputTypes["fasta"] = tempOutNames;
+                       
                        //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 = ""; 
@@ -165,7 +217,7 @@ BinSeqCommand::~BinSeqCommand(){
 
 int BinSeqCommand::execute(){
        try {
-               if (abort == true) {    return 0;       }
+               if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
        
                int error = 0;
                
@@ -316,7 +368,7 @@ int BinSeqCommand::process(ListVector* list) {
                                m->openOutputFile(outputFileName, out);
                                
                                //save to output list of output file names
-                               outputNames.push_back(outputFileName);
+                               outputNames.push_back(outputFileName);  outputTypes["fasta"].push_back(outputFileName);
 
                                m->mothurOut(list->getLabel()); m->mothurOutEndLine();
                                
@@ -335,7 +387,7 @@ int BinSeqCommand::process(ListVector* list) {
                                                if (sequence != "not found") {
                                                        //if you don't have groups
                                                        if (groupfile == "") {
-                                                               name = name + "|" + toString(i+1);
+                                                               name = name + "\t" + toString(i+1);
                                                                out << ">" << name << endl;
                                                                out << sequence << endl;
                                                        }else {//if you do have groups
@@ -344,7 +396,7 @@ int BinSeqCommand::process(ListVector* list) {
                                                                        m->mothurOut(name + " is missing from your group file. Please correct. ");  m->mothurOutEndLine();
                                                                        return 1;
                                                                }else{
-                                                                       name = name + "|" + group + "|" + toString(i+1);
+                                                                       name = name + "\t" + group + "\t" + toString(i+1);
                                                                        out << ">" << name << endl;
                                                                        out << sequence << endl;
                                                                }
@@ -361,7 +413,7 @@ int BinSeqCommand::process(ListVector* list) {
                                        if (sequence != "not found") {
                                                //if you don't have groups
                                                if (groupfile == "") {
-                                                       binnames = binnames + "|" + toString(i+1);
+                                                       binnames = binnames + "\t" + toString(i+1);
                                                        out << ">" << binnames << endl;
                                                        out << sequence << endl;
                                                }else {//if you do have groups
@@ -370,7 +422,7 @@ int BinSeqCommand::process(ListVector* list) {
                                                                m->mothurOut(binnames + " is missing from your group file. Please correct. "); m->mothurOutEndLine();
                                                                return 1;
                                                        }else{
-                                                               binnames = binnames + "|" + group + "|" + toString(i+1);
+                                                               binnames = binnames + "\t" + group + "\t" + toString(i+1);
                                                                out << ">" << binnames << endl;
                                                                out << sequence << endl;
                                                        }