]> git.donarmstrong.com Git - mothur.git/blobdiff - clusterfragmentscommand.cpp
fixed clearcut version bug, added group count output to get.groups and remove.groups
[mothur.git] / clusterfragmentscommand.cpp
index f345d3d05ad9a28f49b6dffc3a61721f99289020..be78e76d75e15ace53867afb13bece32969c76ad 100644 (file)
@@ -40,8 +40,7 @@ vector<string> ClusterFragmentsCommand::getValidParameters(){
 //**********************************************************************************************************************
 ClusterFragmentsCommand::ClusterFragmentsCommand(){    
        try {
-               abort = true;
-               //initialize outputTypes
+               abort = true; calledHelp = true; 
                vector<string> tempOutNames;
                outputTypes["fasta"] = tempOutNames;
                outputTypes["name"] = tempOutNames;
@@ -77,10 +76,10 @@ vector<string> ClusterFragmentsCommand::getRequiredFiles(){
 //**********************************************************************************************************************
 ClusterFragmentsCommand::ClusterFragmentsCommand(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
@@ -166,7 +165,7 @@ void ClusterFragmentsCommand::help(){
                m->mothurOut("The cluster.fragments command parameters are fasta, name, diffs and percent. The fasta parameter is required. \n");
                m->mothurOut("The names parameter allows you to give a list of seqs that are identical. This file is 2 columns, first column is name or representative sequence, second column is a list of its identical sequences separated by commas.\n");
                m->mothurOut("The diffs parameter allows you to set the number of differences allowed, default=0. \n");
-               m->mothurOut("The percent parameter allows you to set percentage of differences allowed, default=0. percent=2 means if the number of difference is less than two percent of the length of the fragment, then cluster.\n");
+               m->mothurOut("The percent parameter allows you to set percentage of differences allowed, default=0. percent=2 means if the number of difference is less than or equal to two percent of the length of the fragment, then cluster.\n");
                m->mothurOut("You may use diffs and percent at the same time to say something like: If the number or differences is greater than 1 or more than 2% of the fragment length, don't merge. \n");
                m->mothurOut("The cluster.fragments command should be in the following format: \n");
                m->mothurOut("cluster.fragments(fasta=yourFastaFile, names=yourNamesFile) \n");
@@ -182,7 +181,7 @@ void ClusterFragmentsCommand::help(){
 int ClusterFragmentsCommand::execute(){
        try {
                
-               if (abort == true) { return 0; }
+               if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
                
                int start = time(NULL);
                
@@ -213,7 +212,7 @@ int ClusterFragmentsCommand::execute(){
                                        if (alignSeqs[j].active) {  //this sequence has not been merged yet
                                                
                                                string jBases = alignSeqs[j].seq.getUnaligned();
-                                                                                               
+                                                                                                       
                                                if (isFragment(iBases, jBases)) {
                                                        //merge
                                                        alignSeqs[i].names += ',' + alignSeqs[j].names;
@@ -259,6 +258,18 @@ int ClusterFragmentsCommand::execute(){
                m->mothurOut(newNamesFile); m->mothurOutEndLine();      
                outputNames.push_back(newFastaFile);  outputNames.push_back(newNamesFile); outputTypes["fasta"].push_back(newFastaFile); outputTypes["name"].push_back(newNamesFile);
                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); }
+               }
+               
+               itTypes = outputTypes.find("name");
+               if (itTypes != outputTypes.end()) {
+                       if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setNameFile(current); }
+               }
 
                return 0;
                
@@ -291,7 +302,7 @@ bool ClusterFragmentsCommand::isFragment(string seq1, string seq2){
                                int percentDiff = floor((seq2.length() * (percent / 100.0)));
                                if (percentDiff < totalDiffs) { totalDiffs = percentDiff; }
                        }
-                               
+                       
                        Alignment* alignment = new NeedlemanOverlap(-1.0, 1.0, -1.0, (seq1.length()+totalDiffs+1));
                                                        
                        //use needleman to align 
@@ -314,6 +325,7 @@ bool ClusterFragmentsCommand::isFragment(string seq1, string seq2){
                        }
                        
                        if (numDiffs <= totalDiffs) { fragment = true; }
+                       
                }
                
                return fragment;