]> git.donarmstrong.com Git - mothur.git/blobdiff - ccode.cpp
modified mpi code to save ram by writing out every 10 seqs.
[mothur.git] / ccode.cpp
index 326af7cec61a88eb6ab859f203098c0ded3a9cfb..3aad3f6b48780505cb5f88c733b28027e28968b1 100644 (file)
--- a/ccode.cpp
+++ b/ccode.cpp
@@ -35,11 +35,9 @@ void Ccode::printHeader(ostream& out) {
        out << "For full window mapping info refer to " << mapInfo << endl << endl;
 }
 //***************************************************************************************************************
-void Ccode::print(ostream& out) {
+int Ccode::print(ostream& out, ostream& outAcc) {
        try {
                
-               mothurOutEndLine();
-               
                ofstream out2;
                openOutputFileAppend(mapInfo, out2);
                
@@ -111,16 +109,17 @@ void Ccode::print(ostream& out) {
                out << endl;    
                        
                if (results) {
-                       mothurOut(querySeq->getName() + " was found have at least one chimeric window."); mothurOutEndLine();
+                       m->mothurOut(querySeq->getName() + " was found have at least one chimeric window."); m->mothurOutEndLine();
+                       outAcc << querySeq->getName() << endl;
                }
 
                //free memory
                for (int i = 0; i < closest.size(); i++) {  delete closest[i].seq;  }
 
-               
+               return 0;
        }
        catch(exception& e) {
-               errorOut(e, "Ccode", "print");
+               m->errorOut(e, "Ccode", "print");
                exit(1);
        }
 }
@@ -155,6 +154,8 @@ int Ccode::getChimeras(Sequence* query) {
                //find closest matches to query
                closest = findClosest(query, numWanted);
                
+               if (m->control_pressed) {  return 0;  }
+               
                //initialize spotMap
                for (int i = 0; i < query->getAligned().length(); i++) {        spotMap[i] = i;         }
        
@@ -177,7 +178,10 @@ int Ccode::getChimeras(Sequence* query) {
                        
                        createFilter(temp, 0.5);
                
-                       for (int i = 0; i < temp.size(); i++) { runFilter(temp[i]);  }
+                       for (int i = 0; i < temp.size(); i++) { 
+                               if (m->control_pressed) {  return 0;  }
+                               runFilter(temp[i]);  
+                       }
                        
                        //update spotMap
                        map<int, int> newMap;
@@ -195,35 +199,37 @@ int Ccode::getChimeras(Sequence* query) {
 
                //trim sequences - this follows ccodes remove_extra_gaps 
                trimSequences(query);
-               
+               if (m->control_pressed) {  return 0;  }
                
                //windows are equivalent to words - ccode paper recommends windows are between 5% and 20% on alignment length().  
                //Our default will be 10% and we will warn if user tries to use a window above or below these recommendations
                windows = findWindows();  
-               
+               if (m->control_pressed) {  return 0;  }
 
                //remove sequences that are more than 20% different and less than 0.5% different - may want to allow user to specify this later 
                removeBadReferenceSeqs(closest);
-               
+               if (m->control_pressed) {  return 0;  }
                
                //find the averages for each querys references
                getAverageRef(closest);  //fills sumRef, averageRef, sumSquaredRef and refCombo.
                getAverageQuery(closest, query);  //fills sumQuery, averageQuery, sumSquaredQuery.
-                                       
+               if (m->control_pressed) {  return 0;  }                 
                
                //find the averages for each querys references 
                findVarianceRef();  //fills varRef and sdRef also sets minimum error rate to 0.001 to avoid divide by 0.
-                       
+               if (m->control_pressed) {  return 0;  } 
                        
                //find the averages for the query 
                findVarianceQuery();  //fills varQuery and sdQuery also sets minimum error rate to 0.001 to avoid divide by 0.
+               if (m->control_pressed) {  return 0;  }
                                        
                determineChimeras();  //fills anova, isChimericConfidence, isChimericTStudent and isChimericANOVA. 
+               if (m->control_pressed) {  return 0;  }
                
                return 0;
        }
        catch(exception& e) {
-               errorOut(e, "Ccode", "getChimeras");
+               m->errorOut(e, "Ccode", "getChimeras");
                exit(1);
        }
 }
@@ -305,7 +311,7 @@ void Ccode::trimSequences(Sequence* query) {
 
                
                //check to make sure that is not whole seq
-               if ((rearPos - frontPos - 1) <= 0) {  mothurOut("Error, when I trim your sequences, the entire sequence is trimmed."); mothurOutEndLine(); exit(1);  }
+               if ((rearPos - frontPos - 1) <= 0) {  m->mothurOut("Error, when I trim your sequences, the entire sequence is trimmed."); m->mothurOutEndLine(); exit(1);  }
                
                map<int, int> tempTrim;
                tempTrim[frontPos] = rearPos;
@@ -325,7 +331,7 @@ void Ccode::trimSequences(Sequence* query) {
                spotMap = newMap;
        }
        catch(exception& e) {
-               errorOut(e, "Ccode", "trimSequences");
+               m->errorOut(e, "Ccode", "trimSequences");
                exit(1);
        }
 }
@@ -340,13 +346,13 @@ vector<int> Ccode::findWindows() {
        
                //default is wanted = 10% of total length
                if (windowSizes > length) { 
-                       mothurOut("You have slected a window larger than your sequence length after all filters, masks and trims have been done. I will use the default 10% of sequence length.");
+                       m->mothurOut("You have slected a window larger than your sequence length after all filters, masks and trims have been done. I will use the default 10% of sequence length.");
                        windowSizes = length / 10;
                }else if (windowSizes == 0) { windowSizes = length / 10;  }
                else if (windowSizes > (length * 0.20)) {
-                       mothurOut("You have selected a window that is larger than 20% of your sequence length.  This is not recommended, but I will continue anyway."); mothurOutEndLine();
+                       m->mothurOut("You have selected a window that is larger than 20% of your sequence length.  This is not recommended, but I will continue anyway."); m->mothurOutEndLine();
                }else if (windowSizes < (length * 0.05)) {
-                       mothurOut("You have selected a window that is smaller than 5% of your sequence length.  This is not recommended, but I will continue anyway."); mothurOutEndLine();
+                       m->mothurOut("You have selected a window that is smaller than 5% of your sequence length.  This is not recommended, but I will continue anyway."); m->mothurOutEndLine();
                }
                
                //save starting points of each window
@@ -360,7 +366,7 @@ vector<int> Ccode::findWindows() {
                return win;
        }
        catch(exception& e) {
-               errorOut(e, "Ccode", "findWindows");
+               m->errorOut(e, "Ccode", "findWindows");
                exit(1);
        }
 }
@@ -415,7 +421,7 @@ int Ccode::getDiff(string seqA, string seqB) {
        
        }
        catch(exception& e) {
-               errorOut(e, "Ccode", "getDiff");
+               m->errorOut(e, "Ccode", "getDiff");
                exit(1);
        }
 }
@@ -485,12 +491,12 @@ void Ccode::removeBadReferenceSeqs(vector<SeqDist>& seqs) {
                        seqs = goodSeqs;
                        
                }else { //warn, but dont remove any
-                       mothurOut(querySeq->getName() + " does not have an adaquate number of reference sequences that are within 20% and 0.5% similarity.  I will continue, but please check."); mothurOutEndLine();  
+                       m->mothurOut(querySeq->getName() + " does not have an adaquate number of reference sequences that are within 20% and 0.5% similarity.  I will continue, but please check."); m->mothurOutEndLine();  
                }
 
        }
        catch(exception& e) {
-               errorOut(e, "Ccode", "removeBadReferenceSeqs");
+               m->errorOut(e, "Ccode", "removeBadReferenceSeqs");
                exit(1);
        }
 }
@@ -530,7 +536,7 @@ vector<SeqDist>  Ccode::findClosest(Sequence* q, int numWanted) {
 
        }
        catch(exception& e) {
-               errorOut(e, "Ccode", "findClosestSides");
+               m->errorOut(e, "Ccode", "findClosestSides");
                exit(1);
        }
 }
@@ -617,7 +623,7 @@ void Ccode::getAverageRef(vector<SeqDist> ref) {
                
        }
        catch(exception& e) {
-               errorOut(e, "Ccode", "getAverageRef");
+               m->errorOut(e, "Ccode", "getAverageRef");
                exit(1);
        }
 }
@@ -686,7 +692,7 @@ void Ccode::getAverageQuery (vector<SeqDist> ref, Sequence* query) {
                }
        }
        catch(exception& e) {
-               errorOut(e, "Ccode", "getAverageQuery");
+               m->errorOut(e, "Ccode", "getAverageQuery");
                exit(1);
        }
 }
@@ -712,7 +718,7 @@ void Ccode::findVarianceRef() {
                }
        }
        catch(exception& e) {
-               errorOut(e, "Ccode", "findVarianceRef");
+               m->errorOut(e, "Ccode", "findVarianceRef");
                exit(1);
        }
 }
@@ -737,7 +743,7 @@ void Ccode::findVarianceQuery() {
 
        }
        catch(exception& e) {
-               errorOut(e, "Ccode", "findVarianceQuery");
+               m->errorOut(e, "Ccode", "findVarianceQuery");
                exit(1);
        }
 }
@@ -799,7 +805,7 @@ void Ccode::determineChimeras() {
                
        }
        catch(exception& e) {
-               errorOut(e, "Ccode", "determineChimeras");
+               m->errorOut(e, "Ccode", "determineChimeras");
                exit(1);
        }
 }
@@ -844,13 +850,13 @@ float Ccode::getT(int numseq) {
         else if (numseq > 2) tvalue = 2.353;
         else if (numseq > 1) tvalue = 2.920;
                else if (numseq <= 1) {
-                       mothurOut("Two or more reference sequences are required, your data will be flawed.\n"); mothurOutEndLine();
+                       m->mothurOut("Two or more reference sequences are required, your data will be flawed.\n"); m->mothurOutEndLine();
                }
                
                return tvalue;
        }
        catch(exception& e) {
-               errorOut(e, "Ccode", "getT");
+               m->errorOut(e, "Ccode", "getT");
                exit(1);
        }
 }
@@ -896,13 +902,13 @@ float Ccode::getF(int numseq) {
         else if (numseq > 1) fvalue = 18.5;
         else if (numseq > 0) fvalue = 161;
                else if (numseq <= 0) {
-                       mothurOut("Two or more reference sequences are required, your data will be flawed.\n"); mothurOutEndLine();
+                       m->mothurOut("Two or more reference sequences are required, your data will be flawed.\n"); m->mothurOutEndLine();
         }
                
                return fvalue;
        }
        catch(exception& e) {
-               errorOut(e, "Ccode", "getF");
+               m->errorOut(e, "Ccode", "getF");
                exit(1);
        }
 }