X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=slayer.cpp;h=a244ea42634fc9b31218aceaafd3d76f249d92e8;hb=1cf188b912d6da8f2cd03dd71cecef664a699c1a;hp=5d5a48b864695ce2ed92357006b834efa24195bb;hpb=aa9238c0a9e6e7aa0ed8b8b606b08ad4fd7dcfe3;p=mothur.git diff --git a/slayer.cpp b/slayer.cpp index 5d5a48b..a244ea4 100644 --- a/slayer.cpp +++ b/slayer.cpp @@ -10,12 +10,13 @@ #include "slayer.h" /***********************************************************************/ -Slayer::Slayer(int win, int increment, int parentThreshold, float div, int i, int snp) : - windowSize(win), windowStep(increment), parentFragmentThreshold(parentThreshold), divRThreshold(div), iters(i), percentSNPSample(snp){ m = MothurOut::getInstance(); } +Slayer::Slayer(int win, int increment, int parentThreshold, float div, int i, int snp, int mi) : + minBS(mi), windowSize(win), windowStep(increment), parentFragmentThreshold(parentThreshold), divRThreshold(div), iters(i), percentSNPSample(snp){ m = MothurOut::getInstance(); } /***********************************************************************/ string Slayer::getResults(Sequence* query, vector refSeqs) { try { vector all; all.clear(); + myQuery = *query; for (int i = 0; i < refSeqs.size(); i++) { @@ -27,77 +28,61 @@ string Slayer::getResults(Sequence* query, vector refSeqs) { 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 spots; //map from spot in original sequence to spot in filtered sequence for query and both parents vector divs = runBellerophon(q, leftParent, rightParent, spots); - - if (m->control_pressed) { - delete q; - delete leftParent; - delete rightParent; - return "no"; - } - + + if (m->control_pressed) { delete q; delete leftParent; delete rightParent; return "no"; } + vector selectedDivs; for (int k = 0; k < divs.size(); k++) { - + vector snpsLeft = getSNPS(divs[k].parentA.getAligned(), divs[k].querySeq.getAligned(), divs[k].parentB.getAligned(), divs[k].winLStart, divs[k].winLEnd); vector 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"; - } + + if (m->control_pressed) { delete q; delete leftParent; delete rightParent; return "no"; } int numSNPSLeft = snpsLeft.size(); int numSNPSRight = snpsRight.size(); - //require at least 3 SNPs on each side of the break - if ((numSNPSLeft >= 3) && (numSNPSRight >= 3)) { - - //removed in 12/09 version of chimeraSlayer - //int winSizeLeft = divs[k].winLEnd - divs[k].winLStart + 1; - //int winSizeRight = divs[k].winREnd - divs[k].winRStart + 1; - - //float snpRateLeft = numSNPSLeft / (float) winSizeLeft; - //float snpRateRight = numSNPSRight / (float) winSizeRight; - //float logR = log(snpRateLeft / snpRateRight) / log(2.0); - - // do not accept excess snp ratio on either side of the break - //if (abs(logR) < 1 ) { + //require at least 4 SNPs on each side of the break + if ((numSNPSLeft >= 4) && (numSNPSRight >= 4)) { - float BS_A, BS_B; - bootstrapSNPS(snpsLeft, snpsRight, BS_A, BS_B); - - if (m->control_pressed) { - delete q; - delete leftParent; - delete rightParent; - return "no"; - } + float BS_A, BS_B; + bootstrapSNPS(snpsLeft, snpsRight, BS_A, BS_B, iters); + + if (m->control_pressed) { delete q; delete leftParent; delete rightParent; return "no"; } + divs[k].bsa = BS_A; + divs[k].bsb = BS_B; + divs[k].bsMax = max(BS_A, BS_B); + divs[k].chimeraMax = max(divs[k].qla_qrb, divs[k].qlb_qra); + + + //are we within 10 points of the bootstrap cutoff? + if ((divs[k].bsMax >= (minBS-10)) && (iters < 1000)) { + bootstrapSNPS(snpsLeft, snpsRight, BS_A, BS_B, 1000); + + if (m->control_pressed) { delete q; delete leftParent; delete rightParent; return "no"; } + divs[k].bsa = BS_A; divs[k].bsb = BS_B; - divs[k].bsMax = max(BS_A, BS_B); - divs[k].chimeraMax = max(divs[k].qla_qrb, divs[k].qlb_qra); - - //so results reflect orignal alignment - divs[k].winLStart = spots[divs[k].winLStart]; - divs[k].winLEnd = spots[divs[k].winLEnd]; - divs[k].winRStart = spots[divs[k].winRStart]; - divs[k].winREnd = spots[divs[k].winREnd]; + } + + //so results reflect orignal alignment + divs[k].winLStart = spots[divs[k].winLStart]; + divs[k].winLEnd = spots[divs[k].winLEnd]; + divs[k].winRStart = spots[divs[k].winRStart]; + divs[k].winREnd = spots[divs[k].winREnd]; - selectedDivs.push_back(divs[k]); - //} + selectedDivs.push_back(divs[k]); } } //save selected - for (int m = 0; m < selectedDivs.size(); m++) { all.push_back(selectedDivs[m]); } + for (int mi = 0; mi < selectedDivs.size(); mi++) { all.push_back(selectedDivs[mi]); } delete q; delete leftParent; @@ -105,17 +90,15 @@ string Slayer::getResults(Sequence* query, vector refSeqs) { } } - // compute bootstrap support if (all.size() > 0) { //sort them sort(all.begin(), all.end(), compareDataStruct); reverse(all.begin(), all.end()); - + outputResults = all; return "yes"; - } - else { + }else { outputResults = all; return "no"; } @@ -144,16 +127,13 @@ vector Slayer::runBellerophon(Sequence* q, Sequence* pA, Sequence* 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 << pA->getName() << endl << pA->getUnaligned() << endl << endl; +//cout << pB->getName() << endl << pB->getUnaligned() << 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; } @@ -186,6 +166,11 @@ vector Slayer::runBellerophon(Sequence* q, Sequence* pA, Sequence* float divR_QLA_QRB = min((QLA_QRB/QA), (QLA_QRB/QB)); float divR_QLB_QRA = min((QLB_QRA/QA), (QLB_QRA/QB)); + //cout << q->getName() << '\t'; + //cout << pA->getName() << '\t'; + //cout << pB->getName() << '\t'; + // cout << "bp: " << breakpoint << " CHIM_TYPE_A\t" << divR_QLA_QRB << "\tQLA: " << QLA << "\tQRB: " << QRB << "\tQLA_QRB: " << QLA_QRB; + //cout << "\tCHIM_TYPE_B\t" << divR_QLB_QRA << "\tQLB: " << QLB << "\tQRA: " << QRA << "\tQLB_QRA: " << QLB_QRA << endl; //cout << leftLength << '\t' << rightLength << '\t' << QLA << '\t' << QRB << '\t' << QLB << '\t' << QRA << '\t' << LAB << '\t' << RAB << '\t' << AB << '\t' << QA << '\t' << QB << '\t' << QLA_QRB << '\t' << QLB_QRA << endl; //cout << divRThreshold << endl; @@ -276,6 +261,7 @@ vector Slayer::getSNPS(string parentA, string query, string parentB, int l data.push_back(member); } } +// cout << i << '\t' << data.size() << endl; } return data; @@ -287,7 +273,7 @@ vector Slayer::getSNPS(string parentA, string query, string parentB, int l } } /***********************************************************************/ -int Slayer::bootstrapSNPS(vector left, vector right, float& BSA, float& BSB) { +int Slayer::bootstrapSNPS(vector left, vector right, float& BSA, float& BSB, int numIters) { try { srand((unsigned)time( NULL )); @@ -295,10 +281,10 @@ int Slayer::bootstrapSNPS(vector left, vector right, float& BSA, flo int count_A = 0; // sceneario QLA,QRB supported int count_B = 0; // sceneario QLB,QRA supported - int numLeft = max(1, int(left.size() * (percentSNPSample/(float)100) + 0.5)); - int numRight = max(1, int(right.size() * (percentSNPSample/(float)100) + 0.5)); - - for (int i = 0; i < iters; i++) { + int numLeft = max(1, int(left.size() * percentSNPSample/(float)100 + 0.5)); + int numRight = max(1, int(right.size() * percentSNPSample/(float)100 + 0.5)); + //cout << numLeft << '\t' << numRight << endl; + for (int i = 0; i < numIters; i++) { //random sampling with replacement. if (m->control_pressed) { return 0; } @@ -361,10 +347,10 @@ int Slayer::bootstrapSNPS(vector left, vector right, float& BSA, flo } + //cout << count_A << '\t' << count_B << endl; - - BSA = ((float) count_A / (float) iters) * 100; - BSB = ((float) count_B / (float) iters) * 100; + BSA = (float) count_A / (float) numIters * 100; + BSB = (float) count_B / (float) numIters * 100; //cout << "bsa = " << BSA << " bsb = " << BSB << endl; return 0; @@ -440,21 +426,41 @@ float Slayer::snpAB(vector data) { } } /***********************************************************************/ -float Slayer::computePercentID(string queryFrag, string parent, int left, int right) { +float Slayer::computePercentID(string queryAlign, string chimera, int left, int right) { try { - int total = 0; - int matches = 0; - + + int numIdentical = 0; + int countA = 0; + int countB = 0; for (int i = left; i <= right; i++) { - total++; - if (queryFrag[i] == parent[i]) { - matches++; + if (((queryAlign[i] != 'G') && (queryAlign[i] != 'T') && (queryAlign[i] != 'A') && (queryAlign[i] != 'C')&& (queryAlign[i] != '.') && (queryAlign[i] != '-')) || + ((chimera[i] != 'G') && (chimera[i] != 'T') && (chimera[i] != 'A') && (chimera[i] != 'C')&& (chimera[i] != '.') && (chimera[i] != '-'))) {} + else { + + bool charA = false; bool charB = false; + if ((queryAlign[i] == 'G') || (queryAlign[i] == 'T') || (queryAlign[i] == 'A') || (queryAlign[i] == 'C')) { charA = true; } + if ((chimera[i] == 'G') || (chimera[i] == 'T') || (chimera[i] == 'A') || (chimera[i] == 'C')) { charB = true; } + + if (charA || charB) { + + if (charA) { countA++; } + if (charB) { countB++; } + + if (queryAlign[i] == chimera[i]) { + numIdentical++; + } + } } } - - float percentID =( matches/(float)total) * 100; - return percentID; + float numBases = (countA + countB) /(float) 2; + + if (numBases == 0) { return 0; } + + float percentIdentical = (numIdentical/(float)numBases) * 100; + + return percentIdentical; + } catch(exception& e) { m->errorOut(e, "Slayer", "computePercentID");