]> git.donarmstrong.com Git - mothur.git/blobdiff - screenseqscommand.cpp
version working on mac with .tellg changed to unget for windows
[mothur.git] / screenseqscommand.cpp
index bc375dee4e36de59fa2e8ae66d3516aa41c9339b..70094f2f3afe77711dcb4fe7b46d70f3d35f4835 100644 (file)
@@ -21,7 +21,8 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string AlignArray[] =  {"fasta", "start", "end", "maxambig", "maxhomop", "minlength", "maxlength", "name", "group"};
+                       string AlignArray[] =  {"fasta", "start", "end", "maxambig", "maxhomop", "minlength", "maxlength",
+                                                                       "name", "group", "alignreport"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -38,7 +39,7 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option){
                        fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not found") { cout << "fasta is a required parameter for the screen.seqs command." << endl; abort = true; }
                        else if (fastafile == "not open") { abort = true; }     
-               
+       
                        groupfile = validParameter.validFile(parameters, "group", true);
                        if (groupfile == "not open") { abort = true; }  
                        else if (groupfile == "not found") { groupfile = ""; }
@@ -47,7 +48,10 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option){
                        if (namefile == "not open") { abort = true; }
                        else if (namefile == "not found") { namefile = ""; }    
 
-               
+                       alignreport = validParameter.validFile(parameters, "alignreport", true);
+                       if (alignreport == "not open") { abort = true; }
+                       else if (alignreport == "not found") { alignreport = ""; }      
+                       
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
                        string temp;
@@ -152,13 +156,13 @@ int ScreenSeqsCommand::execute(){
                        }
                        gobble(inFASTA);
                }       
-               if(namefile != ""){
-                       screenNameGroupFile(badSeqNames);
-               }
-               else if(groupfile != ""){
-                       screenGroupFile(badSeqNames);
-               }
+               if(namefile != "")              {       screenNameGroupFile(badSeqNames);       }
+               if(groupfile != "")             {       screenGroupFile(badSeqNames);           }
+               if(alignreport != "")   {       screenAlignReport(badSeqNames);         }
                
+               goodSeqOut.close();
+               badSeqOut.close();
+               inFASTA.close();
                return 0;
        }
        catch(exception& e) {
@@ -282,4 +286,51 @@ void ScreenSeqsCommand::screenGroupFile(set<string> badSeqNames){
 
 //***************************************************************************************************************
 
+void ScreenSeqsCommand::screenAlignReport(set<string> badSeqNames){
+       
+       ifstream inputAlignReport;
+       openInputFile(alignreport, inputAlignReport);
+       string seqName, group;
+       set<string>::iterator it;
+       
+       string goodAlignReportFile = getRootName(alignreport) + "good" + getExtension(alignreport);
+       string badAlignReportFile = getRootName(alignreport) + "bad" + getExtension(alignreport);
+       
+       ofstream goodAlignReportOut;    openOutputFile(goodAlignReportFile, goodAlignReportOut);
+       ofstream badAlignReportOut;             openOutputFile(badAlignReportFile, badAlignReportOut);          
+
+       while (!inputAlignReport.eof()) {               //      need to copy header
+               char c = inputAlignReport.get();
+               goodAlignReportOut << c;
+               badAlignReportOut << c;
+               if (c == 10 || c == 13){        break;  }       
+       }
+
+       while(!inputAlignReport.eof()){
+               inputAlignReport >> seqName;
+               it = badSeqNames.find(seqName);
+               string line;            
+               while (!inputAlignReport.eof()) {               //      need to copy header
+                       char c = inputAlignReport.get();
+                       line += c;
+                       if (c == 10 || c == 13){        break;  }       
+               }
+               
+               if(it != badSeqNames.end()){
+                       badSeqNames.erase(it);
+                       badAlignReportOut << seqName << '\t' << line;;
+               }
+               else{
+                       goodAlignReportOut << seqName << '\t' << line;
+               }
+               gobble(inputAlignReport);
+       }
+       inputAlignReport.close();
+       goodAlignReportOut.close();
+       badAlignReportOut.close();
+       
+}
+
+//***************************************************************************************************************
+