//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;
set<string> userLabels = labels;
if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); delete input; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0;}
-
- numGroups = lookup.size();
- lines.resize(processors);
- for (int i = 0; i < processors; i++) {
- lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups);
- lines[i].end = int (sqrt(float(i+1)/float(processors)) * numGroups);
- }
if (subsample) {
if (subsampleSize == -1) { //user has not set size, set size = smallest samples size
lookup = temp;
m->setGroups(Groups);
}
+
+ if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; delete input; return 0; }
}
-
+
+ numGroups = lookup.size();
+ lines.resize(processors);
+ for (int i = 0; i < processors; i++) {
+ lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups);
+ lines[i].end = int (sqrt(float(i+1)/float(processors)) * numGroups);
+ }
+
if (m->control_pressed) { delete input; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->clearGroups(); return 0; }
//as long as you are not at the end of the file or done wih the lines you want
int TreeGroupCommand::makeSimsShared() {
try {
- numGroups = lookup.size();
- lines.resize(processors);
- for (int i = 0; i < processors; i++) {
- lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups);
- lines[i].end = int (sqrt(float(i+1)/float(processors)) * numGroups);
- }
-
if (subsample) {
if (subsampleSize == -1) { //user has not set size, set size = smallest samples size
subsampleSize = lookup[0]->getNumSeqs();
lookup = temp;
m->setGroups(Groups);
}
+
+ if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; return 0; }
}
+ numGroups = lookup.size();
+ lines.resize(processors);
+ for (int i = 0; i < processors; i++) {
+ lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups);
+ lines[i].end = int (sqrt(float(i+1)/float(processors)) * numGroups);
+ }
+
set<string> processedLabels;
set<string> userLabels = labels;
int TrialSwap2::swap_checkerboards (vector<vector<int> > &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;