]> git.donarmstrong.com Git - mothur.git/blobdiff - clusterfragmentscommand.cpp
modified reverse.seqs and qualscores.cpp
[mothur.git] / clusterfragmentscommand.cpp
index f345d3d05ad9a28f49b6dffc3a61721f99289020..a8277ffb029fdd6e5f3e110614836e37292ce9a3 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;
@@ -291,7 +290,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 +313,7 @@ bool ClusterFragmentsCommand::isFragment(string seq1, string seq2){
                        }
                        
                        if (numDiffs <= totalDiffs) { fragment = true; }
+                       
                }
                
                return fragment;