From: Sarah Westcott Date: Tue, 1 May 2012 15:18:19 +0000 (-0400) Subject: Merge remote-tracking branch 'mothur/master' X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=f67ace597e7147f3ca35201e3623abe6440a9d24;hp=2b11c674bb4d57c4542ecb89989e1590dd9f07a7;p=mothur.git Merge remote-tracking branch 'mothur/master' --- diff --git a/cooccurrencecommand.cpp b/cooccurrencecommand.cpp index 8c763e2..75b87fa 100644 --- a/cooccurrencecommand.cpp +++ b/cooccurrencecommand.cpp @@ -494,6 +494,7 @@ int CooccurrenceCommand::getCooccurrence(vector& thisLookUp //swap_checkerboards takes the original matrix and swaps checkerboards else if(matrix == "sim9") { trial.swap_checkerboards (co_matrix, ncols, nrows); + nullmatrix = co_matrix; } else { m->mothurOut("[ERROR]: No null model selected!\n\n"); m->control_pressed = true; diff --git a/trialSwap2.cpp b/trialSwap2.cpp index a0c3210..2d25e83 100644 --- a/trialSwap2.cpp +++ b/trialSwap2.cpp @@ -195,20 +195,22 @@ int TrialSwap2::calc_combo (int nrows, int ncols, vector > &nullmatr int TrialSwap2::swap_checkerboards (vector > &co_matrix, int ncols, int nrows) { try { - //int ncols = co_matrix[0].size(); int nrows = co_matrix.size(); - int i, j, k, l; - i = m->getRandomIndex(nrows-1); - while((j = m->getRandomIndex(nrows-1) ) == i ) {;if (m->control_pressed) { return 0; }} - k = m->getRandomIndex(ncols-1); - while((l = m->getRandomIndex(ncols-1)) == k ) {;if (m->control_pressed) { return 0; }} - - if((co_matrix[i][k]*co_matrix[j][l]==1 && co_matrix[i][l]+co_matrix[j][k]==0)||(co_matrix[i][k]+co_matrix[j][l]==0 && co_matrix[i][l]*co_matrix[j][k]==1)) //checking for checkerboard value and swap - { - co_matrix[i][k]=1-co_matrix[i][k]; - co_matrix[i][l]=1-co_matrix[i][l]; - co_matrix[j][k]=1-co_matrix[j][k]; - co_matrix[j][l]=1-co_matrix[j][l]; - + //do 100 runs to make sure enough swaps are happening. This does NOT mean that there will be 1000 swaps, but that is the theoretical max. + for(int a=0;a<1000;a++){ + int i, j, k, l; + i = m->getRandomIndex(nrows-1); + while((j = m->getRandomIndex(nrows-1) ) == i ) {;if (m->control_pressed) { return 0; }} + k = m->getRandomIndex(ncols-1); + while((l = m->getRandomIndex(ncols-1)) == k ) {;if (m->control_pressed) { return 0; }} + + if((co_matrix[i][k]*co_matrix[j][l]==1 && co_matrix[i][l]+co_matrix[j][k]==0)||(co_matrix[i][k]+co_matrix[j][l]==0 && co_matrix[i][l]*co_matrix[j][k]==1)) //checking for checkerboard value and swap + { + co_matrix[i][k]=1-co_matrix[i][k]; + co_matrix[i][l]=1-co_matrix[i][l]; + co_matrix[j][k]=1-co_matrix[j][k]; + co_matrix[j][l]=1-co_matrix[j][l]; + + } } return 0;