]> git.donarmstrong.com Git - mothur.git/blobdiff - slayer.cpp
added getCommandInfoCommand for gui
[mothur.git] / slayer.cpp
index 2d079cd6ac10ae5ed4aeea0454ff3f0e984561e8..1c9039087419572d1cd7fca638ab68e752894c67 100644 (file)
@@ -20,21 +20,37 @@ string Slayer::getResults(Sequence* query, vector<Sequence*> refSeqs) {
                for (int i = 0; i < refSeqs.size(); i++) {
                
                        for (int j = i+1; j < refSeqs.size(); j++) {
+                       
+                               if (m->control_pressed) { return "no";  }
        
                                //make copies of query and each parent because runBellerophon removes gaps and messes them up
                                Sequence* q = new Sequence(query->getName(), query->getAligned());
                                Sequence* leftParent = new Sequence(refSeqs[i]->getName(), refSeqs[i]->getAligned());
                                Sequence* rightParent = new Sequence(refSeqs[j]->getName(), refSeqs[j]->getAligned());
-                               
+
                                map<int, int> spots;  //map from spot in original sequence to spot in filtered sequence for query and both parents
                                vector<data_struct> divs = runBellerophon(q, leftParent, rightParent, spots);
                                
+                               if (m->control_pressed) { 
+                                       delete q;
+                                       delete leftParent;
+                                       delete rightParent;
+                                       return "no"; 
+                               }
+                                       
                                vector<data_struct> selectedDivs;
                                for (int k = 0; k < divs.size(); k++) {
-                               
+                                       
                                        vector<snps> snpsLeft = getSNPS(divs[k].parentA.getAligned(), divs[k].querySeq.getAligned(), divs[k].parentB.getAligned(), divs[k].winLStart, divs[k].winLEnd);
                                        vector<snps> snpsRight = getSNPS(divs[k].parentA.getAligned(), divs[k].querySeq.getAligned(), divs[k].parentB.getAligned(), divs[k].winRStart, divs[k].winREnd);
                                        
+                                       if (m->control_pressed) { 
+                                               delete q;
+                                               delete leftParent;
+                                               delete rightParent;
+                                               return "no"; 
+                                       }
+                                       
                                        int numSNPSLeft = snpsLeft.size();
                                        int numSNPSRight = snpsRight.size();
                                        
@@ -54,6 +70,13 @@ string Slayer::getResults(Sequence* query, vector<Sequence*> refSeqs) {
                                                        
                                                        float BS_A, BS_B;
                                                        bootstrapSNPS(snpsLeft, snpsRight, BS_A, BS_B);
+                                                       
+                                                       if (m->control_pressed) { 
+                                                               delete q;
+                                                               delete leftParent;
+                                                               delete rightParent;
+                                                               return "no"; 
+                                                       }
 
                                                        divs[k].bsa = BS_A;
                                                        divs[k].bsb = BS_B;
@@ -82,7 +105,6 @@ string Slayer::getResults(Sequence* query, vector<Sequence*> refSeqs) {
                        }
                }
                
-
                // compute bootstrap support
                if (all.size() > 0) {
                        //sort them
@@ -120,22 +142,24 @@ vector<data_struct> Slayer::runBellerophon(Sequence* q, Sequence* pA, Sequence*
                string parentA = pA->getAligned();
                string parentB = pB->getAligned();
                int length = query.length();
-//cout << q->getName() << endl << q->getAligned() << endl << endl;     
-//cout << pA->getName() << endl << pA->getAligned() << endl << endl;           
-//cout << pB->getName() << endl << pB->getAligned() << endl << endl;   
-//cout << " length = " << length << endl;
-//cout << q->getName() << endl;
-//cout << pA->getName() << '\t';
-//cout << pB->getName() << endl;
+/*cout << q->getName() << endl << q->getAligned() << endl << endl;     
+cout << pA->getName() << endl << pA->getAligned() << endl << endl;             
+cout << pB->getName() << endl << pB->getAligned() << endl << endl;     
+cout << " length = " << length << endl;
+cout << q->getName() << endl;
+cout << pA->getName() << '\t';
+cout << pB->getName() << endl;*/
        
                //check window size
                if (length < (2*windowSize+windowStep)) { 
-                       m->mothurOut("Your window size is too large for " + q->getName() + ". I will make the window size " + toString(length/4) + " which is 1/4 the filtered length."); m->mothurOutEndLine();        
+//                     m->mothurOut("Your window size is too large for " + q->getName() + ". I will make the window size " + toString(length/4) + " which is 1/4 the filtered length."); m->mothurOutEndLine();        
                        windowSize = length / 4;
                }
                
                for (int i = windowSize-1; i <= (length - windowSize); i += windowStep) {
                
+                       if (m->control_pressed) { return data; }
+               
                        int breakpoint = i;
                        int leftLength = breakpoint + 1;
                        int rightLength = length - leftLength;
@@ -262,7 +286,7 @@ vector<snps> Slayer::getSNPS(string parentA, string query, string parentB, int l
        }
 }
 /***********************************************************************/
-void Slayer::bootstrapSNPS(vector<snps> left, vector<snps> right, float& BSA, float& BSB) {
+int Slayer::bootstrapSNPS(vector<snps> left, vector<snps> right, float& BSA, float& BSB) {
        try {
 
                srand((unsigned)time( NULL ));
@@ -276,6 +300,8 @@ void Slayer::bootstrapSNPS(vector<snps> left, vector<snps> right, float& BSA, fl
                for (int i = 0; i < iters; i++) {
                        //random sampling with replacement.
                
+                       if (m->control_pressed) { return 0;  }
+                       
                        vector<snps> selectedLeft;
 
                        for (int j = 0; j < numLeft; j++) {
@@ -339,6 +365,8 @@ void Slayer::bootstrapSNPS(vector<snps> left, vector<snps> right, float& BSA, fl
                BSA = ((float) count_A / (float) iters) * 100;
                BSB = ((float) count_B / (float) iters) * 100;
 //cout << "bsa = " << BSA << " bsb = " << BSB << endl;
+
+               return 0;
        
        }
        catch(exception& e) {