]> git.donarmstrong.com Git - mothur.git/blobdiff - chopseqscommand.cpp
working on pca
[mothur.git] / chopseqscommand.cpp
index fc2d9a7faf24c7cfa433482e6897ac7b224844a6..a09ff65856ae39c1e8fbb1a662ed8bacd8860694 100644 (file)
@@ -13,7 +13,7 @@
 //**********************************************************************************************************************
 vector<string> ChopSeqsCommand::getValidParameters(){  
        try {
-               string AlignArray[] =  {"fasta","numbases","countgaps","keep","outputdir","inputdir"};
+               string AlignArray[] =  {"fasta","short","numbases","countgaps","keep","outputdir","inputdir"};
                vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                return myArray;
        }
@@ -25,7 +25,7 @@ vector<string> ChopSeqsCommand::getValidParameters(){
 //**********************************************************************************************************************
 ChopSeqsCommand::ChopSeqsCommand(){    
        try {
-               //initialize outputTypes
+               abort = true; calledHelp = true; 
                vector<string> tempOutNames;
                outputTypes["fasta"] = tempOutNames;
                outputTypes["accnos"] = tempOutNames;
@@ -61,14 +61,14 @@ vector<string> ChopSeqsCommand::getRequiredFiles(){
 //**********************************************************************************************************************
 ChopSeqsCommand::ChopSeqsCommand(string option)  {
        try {
-               abort = false;
+               abort = false; calledHelp = false;   
                
                //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
-                       string Array[] =  {"fasta","numbases","countgaps","keep","outputdir","inputdir"};
+                       string Array[] =  {"fasta","numbases","countgaps","keep","short","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -113,7 +113,10 @@ ChopSeqsCommand::ChopSeqsCommand(string option)  {
                        convert(temp, numbases);   
                        
                        temp = validParameter.validFile(parameters, "countgaps", false);        if (temp == "not found") { temp = "f"; } 
-                       countGaps = m->isTrue(temp);   
+                       countGaps = m->isTrue(temp);  
+                       
+                       temp = validParameter.validFile(parameters, "short", false);    if (temp == "not found") { temp = "f"; } 
+                       Short = m->isTrue(temp);   
                
                        keep = validParameter.validFile(parameters, "keep", false);             if (keep == "not found") { keep = "front"; } 
                                
@@ -130,12 +133,14 @@ ChopSeqsCommand::ChopSeqsCommand(string option)  {
 
 void ChopSeqsCommand::help(){
        try {
-               m->mothurOut("The chop.seqs command reads a fasta file and outputs a .chop.fasta containing the trimmed sequences.\n");
+               m->mothurOut("The chop.seqs command reads a fasta file and outputs a .chop.fasta containing the trimmed sequences. Note: If a sequence is completely 'chopped', an accnos file will be created with the names of the sequences removed. \n");
                m->mothurOut("The chop.seqs command parameters are fasta, numbases, countgaps and keep. fasta and numbases are required required.\n");
                m->mothurOut("The chop.seqs command should be in the following format: chop.seqs(fasta=yourFasta, numbases=yourNum, keep=yourKeep).\n");
                m->mothurOut("The numbases parameter allows you to specify the number of bases you want to keep.\n");
                m->mothurOut("The keep parameter allows you to specify whether you want to keep the front or the back of your sequence, default=front.\n");
                m->mothurOut("The countgaps parameter allows you to specify whether you want to count gaps as bases, default=false.\n");
+               m->mothurOut("The short parameter allows you to specify you want to keep sequences that are too short to chop, default=false.\n");
+               m->mothurOut("For example, if you ran chop.seqs with numbases=200 and short=t, if a sequence had 100 bases mothur would keep the sequence rather than eliminate it.\n");
                m->mothurOut("Example chop.seqs(fasta=amazon.fasta, numbases=200, keep=front).\n");
                m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n");
        }
@@ -150,7 +155,7 @@ void ChopSeqsCommand::help(){
 int ChopSeqsCommand::execute(){
        try {
                
-               if (abort == true) { return 0; }
+               if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
                
                string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "chop.fasta";
                string outputFileNameAccnos = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "chop.accnos";
@@ -197,6 +202,21 @@ int ChopSeqsCommand::execute(){
                
                m->mothurOutEndLine();
                
+               //set fasta file as new current fastafile
+               string current = "";
+               itTypes = outputTypes.find("fasta");
+               if (itTypes != outputTypes.end()) {
+                       if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
+               }
+               
+               if (wroteAccnos) { //set accnos file as new current accnosfile
+                       itTypes = outputTypes.find("accnos");
+                       if (itTypes != outputTypes.end()) {
+                               if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setAccnosFile(current); }
+                       }
+               }
+               
+               
                return 0;               
        }
 
@@ -233,8 +253,9 @@ string ChopSeqsCommand::getChopped(Sequence seq) {
                                        if (stopSpot == 0) { temp = ""; }
                                        else {  temp = temp.substr(0, stopSpot);  }
                                                        
-                               }else { temp = ""; } //sequence too short
-                               
+                               }else { 
+                                       if (!Short) { temp = ""; } //sequence too short
+                               }
                        }else { //you are keeping the back
                                int tempLength = temp.length();
                                if (tempLength > numbases) { //you have enough bases to remove some
@@ -253,8 +274,9 @@ string ChopSeqsCommand::getChopped(Sequence seq) {
                                
                                        if (stopSpot == 0) { temp = ""; }
                                        else {  temp = temp.substr(stopSpot+1);  }
+                               }else { 
+                                       if (!Short) { temp = ""; } //sequence too short
                                }
-                               else {  temp = ""; } //sequence too short
                        }
 
                }else{
@@ -284,8 +306,9 @@ string ChopSeqsCommand::getChopped(Sequence seq) {
                                        if (stopSpot == 0) { temp = ""; }
                                        else {  temp = temp.substr(0, stopSpot);  }
                                                        
-                               }else { temp = ""; } //sequence too short
-                               
+                               }else { 
+                                       if (!Short) { temp = ""; } //sequence too short
+                               }                               
                        }else { //you are keeping the back
                                int tempLength = tempUnaligned.length();
                                if (tempLength > numbases) { //you have enough bases to remove some
@@ -308,8 +331,9 @@ string ChopSeqsCommand::getChopped(Sequence seq) {
                                
                                        if (stopSpot == 0) { temp = ""; }
                                        else {  temp = temp.substr(stopSpot+1);  }
+                               }else { 
+                                       if (!Short) { temp = ""; } //sequence too short
                                }
-                               else {  temp = ""; } //sequence too short
                        }
                }