#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<Sequence*> refSeqs) {
try {
vector<data_struct> all; all.clear();
+ myQuery = *query;
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();
- //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);
+ 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]);
}
}
//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;
}
}
-
// 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";
}
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;
}
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;
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;
data.push_back(member);
}
}
+// cout << i << '\t' << data.size() << endl;
}
return data;
}
}
/***********************************************************************/
-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, int numIters) {
try {
srand((unsigned)time( NULL ));
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; }
+
vector<snps> selectedLeft;
for (int j = 0; j < numLeft; j++) {
}
+ //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;
}
catch(exception& e) {