X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=slayer.cpp;h=a244ea42634fc9b31218aceaafd3d76f249d92e8;hb=1cf188b912d6da8f2cd03dd71cecef664a699c1a;hp=20ab0ceae564b631e29776afe967c7536ee7f87e;hpb=a535607ef9867014c3ca73df2407c70a79bd4fa2;p=mothur.git diff --git a/slayer.cpp b/slayer.cpp index 20ab0ce..a244ea4 100644 --- a/slayer.cpp +++ b/slayer.cpp @@ -28,74 +28,56 @@ 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); - //cout << divs.size() << endl; - if (m->control_pressed) { - delete q; - delete leftParent; - delete rightParent; - return "no"; - } + + if (m->control_pressed) { delete q; delete leftParent; delete rightParent; return "no"; } -// cout << divs.size() << endl; 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)) { + //require at least 4 SNPs on each side of the break if ((numSNPSLeft >= 4) && (numSNPSRight >= 4)) { - - //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 ) { - - 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"; - } + 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]; + } - selectedDivs.push_back(divs[k]); - //} + //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]); } } @@ -113,53 +95,10 @@ string Slayer::getResults(Sequence* query, vector refSeqs) { //sort them sort(all.begin(), all.end(), compareDataStruct); reverse(all.begin(), all.end()); - /*vector newAll; - - for (int i = 0; i < all.size(); i++) { - - //are we within 10 points of the bootstrap cutoff? - if (all[i].bsMax >= (minBS-10)) { - - vector snpsLeft = getSNPS(all[i].parentA.getAligned(), all[i].querySeq.getAligned(), all[i].parentB.getAligned(), all[i].winLStart, all[i].winLEnd); - vector snpsRight = getSNPS(all[i].parentA.getAligned(), all[i].querySeq.getAligned(), all[i].parentB.getAligned(), all[i].winRStart, all[i].winREnd); - - if (m->control_pressed) { return "no"; } - - int numSNPSLeft = snpsLeft.size(); - int numSNPSRight = snpsRight.size(); - - //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, 1000); - if (m->control_pressed) { return "no"; } - cout << i << '\t' << BS_A << '\t' << BS_B << endl; - all[i].bsa = BS_A; - all[i].bsb = BS_B; - all[i].bsMax = max(BS_A, BS_B); - all[i].chimeraMax = max(all[i].qla_qrb, all[i].qlb_qra); - - newAll.push_back(all[i]); - } - } - } - - if (newAll.size() != 0) { - sort(newAll.begin(), newAll.end(), compareDataStruct); - reverse(newAll.begin(), newAll.end()); - - outputResults = newAll; - return "yes"; - }else { - outputResults = newAll; - return "no"; - }*/ - outputResults = all; - return "yes"; - } - else { + return "yes"; + }else { outputResults = all; return "no"; } @@ -187,13 +126,10 @@ vector 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->getUnaligned() << endl << endl; +//cout << pB->getName() << endl << pB->getUnaligned() << endl << endl; +//cout << " length = " << length << endl; //check window size if (length < (2*windowSize+windowStep)) { @@ -230,6 +166,11 @@ cout << pB->getName() << endl;*/ 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; @@ -342,7 +283,7 @@ int Slayer::bootstrapSNPS(vector left, vector right, float& BSA, flo 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. @@ -411,15 +352,6 @@ int Slayer::bootstrapSNPS(vector left, vector right, float& BSA, flo BSA = (float) count_A / (float) numIters * 100; BSB = (float) count_B / (float) numIters * 100; //cout << "bsa = " << BSA << " bsb = " << BSB << endl; - - //run borderline bootstrap values longer - //if (numIters < 1000) { - //are you within 10 points of min bootstrap value cutoff - // if (((abs((double)(BSA - minBS))) <= 5) || ((abs((double)(BSB - minBS))) <= 5)) { - // m->mothurOut("extending bootstrap for " + myQuery.getName()); m->mothurOutEndLine(); - // bootstrapSNPS(left, right, BSA, BSB, 1000); - // } - //} return 0; @@ -494,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");