]> git.donarmstrong.com Git - mothur.git/blobdiff - screenseqscommand.cpp
reworked the classifiers summary file added groupfile option to classify.seqs, added...
[mothur.git] / screenseqscommand.cpp
index 48bf17119c98d832b0176dcab78675a94ecf80e8..5b3d7d7604c4f0fe5460265fbd611e12dded4629 100644 (file)
@@ -12,7 +12,7 @@
 
 //***************************************************************************************************************
 
-ScreenSeqsCommand::ScreenSeqsCommand(string option){
+ScreenSeqsCommand::ScreenSeqsCommand(string option)  {
        try {
                abort = false;
                
@@ -76,7 +76,7 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option){
 
                        //check for required parameters
                        fastafile = validParameter.validFile(parameters, "fasta", true);
-                       if (fastafile == "not found") { mothurOut("fasta is a required parameter for the screen.seqs command."); mothurOutEndLine(); abort = true; }
+                       if (fastafile == "not found") { m->mothurOut("fasta is a required parameter for the screen.seqs command."); m->mothurOutEndLine(); abort = true; }
                        else if (fastafile == "not open") { abort = true; }     
        
                        groupfile = validParameter.validFile(parameters, "group", true);
@@ -121,7 +121,7 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option){
 
        }
        catch(exception& e) {
-               errorOut(e, "ScreenSeqsCommand", "ScreenSeqsCommand");
+               m->errorOut(e, "ScreenSeqsCommand", "ScreenSeqsCommand");
                exit(1);
        }
 }
@@ -129,25 +129,25 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option){
 
 void ScreenSeqsCommand::help(){
        try {
-               mothurOut("The screen.seqs command reads a fastafile and creates .....\n");
-               mothurOut("The screen.seqs command parameters are fasta, start, end, maxambig, maxhomop, minlength, maxlength, name, and group.\n");
-               mothurOut("The fasta parameter is required.\n");
-               mothurOut("The start parameter .... The default is -1.\n");
-               mothurOut("The end parameter .... The default is -1.\n");
-               mothurOut("The maxambig parameter .... The default is -1.\n");
-               mothurOut("The maxhomop parameter .... The default is -1.\n");
-               mothurOut("The minlength parameter .... The default is -1.\n");
-               mothurOut("The maxlength parameter .... The default is -1.\n");
-               mothurOut("The name parameter allows you to provide a namesfile, and the group parameter allows you to provide a groupfile.\n");
-               mothurOut("The screen.seqs command should be in the following format: \n");
-               mothurOut("screen.seqs(fasta=yourFastaFile, name=youNameFile, group=yourGroupFIle, start=yourStart, end=yourEnd, maxambig=yourMaxambig,  \n");
-               mothurOut("maxhomop=yourMaxhomop, minlength=youMinlength, maxlength=yourMaxlength)  \n");       
-               mothurOut("Example screen.seqs(fasta=abrecovery.fasta, name=abrecovery.names, group=abrecovery.groups, start=..., end=..., maxambig=..., maxhomop=..., minlength=..., maxlength=...).\n");
-               mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n");
+               m->mothurOut("The screen.seqs command reads a fastafile and creates .....\n");
+               m->mothurOut("The screen.seqs command parameters are fasta, start, end, maxambig, maxhomop, minlength, maxlength, name, and group.\n");
+               m->mothurOut("The fasta parameter is required.\n");
+               m->mothurOut("The start parameter .... The default is -1.\n");
+               m->mothurOut("The end parameter .... The default is -1.\n");
+               m->mothurOut("The maxambig parameter .... The default is -1.\n");
+               m->mothurOut("The maxhomop parameter .... The default is -1.\n");
+               m->mothurOut("The minlength parameter .... The default is -1.\n");
+               m->mothurOut("The maxlength parameter .... The default is -1.\n");
+               m->mothurOut("The name parameter allows you to provide a namesfile, and the group parameter allows you to provide a groupfile.\n");
+               m->mothurOut("The screen.seqs command should be in the following format: \n");
+               m->mothurOut("screen.seqs(fasta=yourFastaFile, name=youNameFile, group=yourGroupFIle, start=yourStart, end=yourEnd, maxambig=yourMaxambig,  \n");
+               m->mothurOut("maxhomop=yourMaxhomop, minlength=youMinlength, maxlength=yourMaxlength)  \n");    
+               m->mothurOut("Example screen.seqs(fasta=abrecovery.fasta, name=abrecovery.names, group=abrecovery.groups, start=..., end=..., maxambig=..., maxhomop=..., minlength=..., maxlength=...).\n");
+               m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n");
 
        }
        catch(exception& e) {
-               errorOut(e, "ScreenSeqsCommand", "help");
+               m->errorOut(e, "ScreenSeqsCommand", "help");
                exit(1);
        }
 }
@@ -175,6 +175,8 @@ int ScreenSeqsCommand::execute(){
                ofstream badSeqOut;             openOutputFile(badSeqFile, badSeqOut);          
                
                while(!inFASTA.eof()){
+                       if (m->control_pressed) { goodSeqOut.close(); badSeqOut.close(); inFASTA.close(); remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; }
+                       
                        Sequence currSeq(inFASTA);
                        if (currSeq.getName() != "") {
                                bool goodSeq = 1;               //      innocent until proven guilty
@@ -194,26 +196,46 @@ int ScreenSeqsCommand::execute(){
                                }
                        }
                        gobble(inFASTA);
-               }       
-               if(namefile != "" && groupfile != "")   {       screenNameGroupFile(badSeqNames);       }       // this screens both names and groups
-               else if(namefile != "")                                 {       screenNameGroupFile(badSeqNames);       }
-               else if(groupfile != "")                                {       screenGroupFile(badSeqNames);           }       // this screens just the groups
+               }
+                       
+               if(namefile != "" && groupfile != "")   {       
+                       screenNameGroupFile(badSeqNames);       
+                       if (m->control_pressed) { goodSeqOut.close(); badSeqOut.close(); inFASTA.close(); remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; }
+               }else if(namefile != "")        {       
+                       screenNameGroupFile(badSeqNames);
+                       if (m->control_pressed) { goodSeqOut.close(); badSeqOut.close(); inFASTA.close(); remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; }  
+               }else if(groupfile != "")                               {       screenGroupFile(badSeqNames);           }       // this screens just the group
+               
+               if (m->control_pressed) { goodSeqOut.close(); badSeqOut.close(); inFASTA.close(); remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; }
+
                if(alignreport != "")                                   {       screenAlignReport(badSeqNames);         }
                
                goodSeqOut.close();
                badSeqOut.close();
                inFASTA.close();
+               
+               
+               if (m->control_pressed) { remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; }
+
+               m->mothurOutEndLine();
+               m->mothurOut("Output File Names: "); m->mothurOutEndLine();
+               m->mothurOut(goodSeqFile); m->mothurOutEndLine();       
+               m->mothurOut(badSeqFile); m->mothurOutEndLine();        
+               for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
+               m->mothurOutEndLine();
+
+               
                return 0;
        }
        catch(exception& e) {
-               errorOut(e, "ScreenSeqsCommand", "execute");
+               m->errorOut(e, "ScreenSeqsCommand", "execute");
                exit(1);
        }
 }
 
 //***************************************************************************************************************
 
-void ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
+int ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
 
        ifstream inputNames;
        openInputFile(namefile, inputNames);
@@ -224,10 +246,14 @@ void ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
        string goodNameFile = outputDir + getRootName(getSimpleName(namefile)) + "good" + getExtension(namefile);
        string badNameFile = outputDir + getRootName(getSimpleName(namefile)) + "bad" + getExtension(namefile);
        
+       outputNames.push_back(goodNameFile);  outputNames.push_back(badNameFile);
+       
        ofstream goodNameOut;   openOutputFile(goodNameFile, goodNameOut);
        ofstream badNameOut;    openOutputFile(badNameFile, badNameOut);                
        
        while(!inputNames.eof()){
+               if (m->control_pressed) { goodNameOut.close(); badNameOut.close(); inputNames.close(); remove(goodNameFile.c_str()); remove(badNameFile.c_str()); return 0; }
+
                inputNames >> seqName >> seqList;
                it = badSeqNames.find(seqName);
                
@@ -257,8 +283,8 @@ void ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
        //we were unable to remove some of the bad sequences
        if (badSeqNames.size() != 0) {
                for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) {  
-                       mothurOut("Your namefile does not include the sequence " + *it + " please correct."); 
-                       mothurOutEndLine();
+                       m->mothurOut("Your namefile does not include the sequence " + *it + " please correct."); 
+                       m->mothurOutEndLine();
                }
        }
 
@@ -270,10 +296,14 @@ void ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
                string goodGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "good" + getExtension(groupfile);
                string badGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "bad" + getExtension(groupfile);
                
+               outputNames.push_back(goodGroupFile);  outputNames.push_back(badGroupFile);
+               
                ofstream goodGroupOut;  openOutputFile(goodGroupFile, goodGroupOut);
                ofstream badGroupOut;   openOutputFile(badGroupFile, badGroupOut);              
                
                while(!inputGroups.eof()){
+                       if (m->control_pressed) { goodGroupOut.close(); badGroupOut.close(); inputGroups.close(); remove(goodNameFile.c_str()); remove(badNameFile.c_str()); remove(goodGroupFile.c_str()); remove(badGroupFile.c_str()); return 0; }
+
                        inputGroups >> seqName >> group;
 
                        it = badSeqGroups.find(seqName);
@@ -294,16 +324,19 @@ void ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
                //we were unable to remove some of the bad sequences
                if (badSeqGroups.size() != 0) {
                        for (it = badSeqGroups.begin(); it != badSeqGroups.end(); it++) {  
-                               mothurOut("Your namefile does not include the sequence " + *it + " please correct."); 
-                               mothurOutEndLine();
+                               m->mothurOut("Your namefile does not include the sequence " + *it + " please correct."); 
+                               m->mothurOutEndLine();
                        }
                }
        }
+               
+       return 0;
+
 }
 
 //***************************************************************************************************************
 
-void ScreenSeqsCommand::screenGroupFile(set<string> badSeqNames){
+int ScreenSeqsCommand::screenGroupFile(set<string> badSeqNames){
 
        ifstream inputGroups;
        openInputFile(groupfile, inputGroups);
@@ -313,10 +346,14 @@ void ScreenSeqsCommand::screenGroupFile(set<string> badSeqNames){
        string goodGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "good" + getExtension(groupfile);
        string badGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "bad" + getExtension(groupfile);
        
+       outputNames.push_back(goodGroupFile);  outputNames.push_back(badGroupFile);
+       
        ofstream goodGroupOut;  openOutputFile(goodGroupFile, goodGroupOut);
        ofstream badGroupOut;   openOutputFile(badGroupFile, badGroupOut);              
        
        while(!inputGroups.eof()){
+               if (m->control_pressed) { goodGroupOut.close(); badGroupOut.close(); inputGroups.close(); remove(goodGroupFile.c_str()); remove(badGroupFile.c_str()); return 0; }
+
                inputGroups >> seqName >> group;
                it = badSeqNames.find(seqName);
                
@@ -330,11 +367,13 @@ void ScreenSeqsCommand::screenGroupFile(set<string> badSeqNames){
                gobble(inputGroups);
        }
        
+       if (m->control_pressed) { goodGroupOut.close(); badGroupOut.close(); inputGroups.close(); remove(goodGroupFile.c_str()); remove(badGroupFile.c_str()); return 0; }
+
        //we were unable to remove some of the bad sequences
        if (badSeqNames.size() != 0) {
                for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) {  
-                       mothurOut("Your groupfile does not include the sequence " + *it + " please correct."); 
-                       mothurOutEndLine();
+                       m->mothurOut("Your groupfile does not include the sequence " + *it + " please correct."); 
+                       m->mothurOutEndLine();
                }
        }
        
@@ -342,11 +381,16 @@ void ScreenSeqsCommand::screenGroupFile(set<string> badSeqNames){
        goodGroupOut.close();
        badGroupOut.close();
        
+       if (m->control_pressed) { remove(goodGroupFile.c_str()); remove(badGroupFile.c_str());  }
+
+       
+       return 0;
+       
 }
 
 //***************************************************************************************************************
 
-void ScreenSeqsCommand::screenAlignReport(set<string> badSeqNames){
+int ScreenSeqsCommand::screenAlignReport(set<string> badSeqNames){
        
        ifstream inputAlignReport;
        openInputFile(alignreport, inputAlignReport);
@@ -356,6 +400,8 @@ void ScreenSeqsCommand::screenAlignReport(set<string> badSeqNames){
        string goodAlignReportFile = outputDir + getRootName(getSimpleName(alignreport)) + "good" + getExtension(alignreport);
        string badAlignReportFile = outputDir + getRootName(getSimpleName(alignreport)) + "bad" + getExtension(alignreport);
        
+       outputNames.push_back(goodAlignReportFile);  outputNames.push_back(badAlignReportFile);
+       
        ofstream goodAlignReportOut;    openOutputFile(goodAlignReportFile, goodAlignReportOut);
        ofstream badAlignReportOut;             openOutputFile(badAlignReportFile, badAlignReportOut);          
 
@@ -367,6 +413,8 @@ void ScreenSeqsCommand::screenAlignReport(set<string> badSeqNames){
        }
 
        while(!inputAlignReport.eof()){
+               if (m->control_pressed) { goodAlignReportOut.close(); badAlignReportOut.close(); inputAlignReport.close(); remove(goodAlignReportFile.c_str()); remove(badAlignReportFile.c_str()); return 0; }
+
                inputAlignReport >> seqName;
                it = badSeqNames.find(seqName);
                string line;            
@@ -386,17 +434,24 @@ void ScreenSeqsCommand::screenAlignReport(set<string> badSeqNames){
                gobble(inputAlignReport);
        }
        
+       if (m->control_pressed) { goodAlignReportOut.close(); badAlignReportOut.close(); inputAlignReport.close(); remove(goodAlignReportFile.c_str()); remove(badAlignReportFile.c_str()); return 0; }
+
        //we were unable to remove some of the bad sequences
        if (badSeqNames.size() != 0) {
                for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) {  
-                       mothurOut("Your file does not include the sequence " + *it + " please correct."); 
-                       mothurOutEndLine();
+                       m->mothurOut("Your file does not include the sequence " + *it + " please correct."); 
+                       m->mothurOutEndLine();
                }
        }
 
        inputAlignReport.close();
        goodAlignReportOut.close();
        badAlignReportOut.close();
+                       
+       if (m->control_pressed) {  remove(goodAlignReportFile.c_str()); remove(badAlignReportFile.c_str()); return 0; }
+       
+       return 0;
+
        
 }