From: westcott Date: Fri, 18 Feb 2011 15:14:03 +0000 (+0000) Subject: fixed unifrac bug with multiple processors if numComps was less than processors.... X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=e88ba6b7a994a8502030d38cc5cc542994694d4d fixed unifrac bug with multiple processors if numComps was less than processors. fixed bug with random number generator for sub.sample command. --- diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index 902e927..e479725 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -1625,7 +1625,7 @@ attributes = { ORGANIZATIONNAME = "Schloss Lab"; }; - buildConfigurationList = 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "Mothur" */; + buildConfigurationList = 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "mothur" */; compatibilityVersion = "Xcode 3.1"; developmentRegion = English; hasScannedForEncodings = 1; @@ -2048,7 +2048,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "Mothur" */ = { + 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "mothur" */ = { isa = XCConfigurationList; buildConfigurations = ( 1DEB928A08733DD80010E9CD /* Debug */, diff --git a/anosimcommand.cpp b/anosimcommand.cpp index 835b5a0..9f537b8 100644 --- a/anosimcommand.cpp +++ b/anosimcommand.cpp @@ -408,7 +408,7 @@ int AnosimCommand::execute(){ //print headers out << "label\tgroupsCompared\tRValue\tpValue" << endl; - m->mothurOut("label\tgroupsCompared\tRValue\tpValue"); m->mothurOutEndLine(); + m->mothurOut("\nlabel\tgroupsCompared\tRValue\tpValue"); m->mothurOutEndLine(); out.close(); } @@ -510,7 +510,7 @@ int AnosimCommand::execute(){ //print headers out << "groupsCompared\tRValue\tpValue" << endl; - m->mothurOut("groupsCompared\tRValue\tpValue"); m->mothurOutEndLine(); + m->mothurOut("\ngroupsCompared\tRValue\tpValue"); m->mothurOutEndLine(); out.close(); ReadPhylipVector readMatrix(phylipfile); diff --git a/getotuscommand.cpp b/getotuscommand.cpp index b075cb4..f10142b 100644 --- a/getotuscommand.cpp +++ b/getotuscommand.cpp @@ -186,7 +186,7 @@ int GetOtusCommand::execute(){ groupMap = new GroupMap(groupfile); groupMap->readMap(); - //get groups you want to remove + //get groups you want to get if (accnosfile != "") { readAccnos(); } //make sure groups are valid diff --git a/getsharedotucommand.cpp b/getsharedotucommand.cpp index 6ca4ee2..7746ef9 100644 --- a/getsharedotucommand.cpp +++ b/getsharedotucommand.cpp @@ -196,7 +196,7 @@ void GetSharedOTUCommand::help(){ m->mothurOut("The output parameter allows you to output the list of names without the group and bin number added. \n"); m->mothurOut("With this option you can use the names file as an input in get.seqs and remove.seqs commands. To do this enter output=accnos. \n"); m->mothurOut("The get.sharedseqs command outputs a .names file for each distance level containing a list of sequences in the OTUs shared by the groups specified.\n"); - m->mothurOut("The get.sharedseqs command should be in the following format: get.sabund(label=yourLabels, groups=yourGroups, fasta=yourFastafile, output=yourOutput).\n"); + m->mothurOut("The get.sharedseqs command should be in the following format: get.sharedseqs(label=yourLabels, groups=yourGroups, fasta=yourFastafile, output=yourOutput).\n"); m->mothurOut("Example get.sharedseqs(list=amazon.fn.list, label=unique-0.01, group=forest-pasture, fasta=amazon.fasta, output=accnos).\n"); m->mothurOut("The output to the screen is the distance and the number of otus at that distance for the groups you specified.\n"); m->mothurOut("The default value for label is all labels in your inputfile. The default for groups is all groups in your file.\n"); diff --git a/subsamplecommand.cpp b/subsamplecommand.cpp index 6b0e4f9..223c9f5 100644 --- a/subsamplecommand.cpp +++ b/subsamplecommand.cpp @@ -413,7 +413,7 @@ int SubSampleCommand::getSubSampleFasta() { bool done = false; int myrand; while (!done) { - myrand = (int)((float)(rand()) / (RAND_MAX / (thisSize-1) + 1)); + myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0)); if (subset.count(names[myrand]) == 0) { @@ -426,6 +426,7 @@ int SubSampleCommand::getSubSampleFasta() { } } }else { + //randomly select a subset of those names to include in the subsample for (int j = 0; j < size; j++) { @@ -435,7 +436,7 @@ int SubSampleCommand::getSubSampleFasta() { bool done = false; int myrand; while (!done) { - myrand = (int)((float)(rand()) / (RAND_MAX / (thisSize-1) + 1)); + myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0)); if (subset.count(names[myrand]) == 0) { @@ -762,7 +763,7 @@ int SubSampleCommand::processShared(vector& thislookup, ofs if (m->control_pressed) { delete order; return 0; } //get random number to sample from order between 0 and thisSize-1. - int myrand = (int)((float)(rand()) / (RAND_MAX / (thisSize-1) + 1)); + int myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0)); int bin = order->get(myrand); @@ -959,7 +960,7 @@ int SubSampleCommand::getSubSampleList() { bool done = false; int myrand; while (!done) { - myrand = (int)((float)(rand()) / (RAND_MAX / (names.size()-1) + 1)); + myrand = int((float)(names.size()) * (float)(rand()) / ((float)RAND_MAX+1.0)); if (subset.count(names[myrand]) == 0) { //you are not already added if (groupMap->getGroup(names[myrand]) == Groups[i]) { subset.insert(names[myrand]); break; } @@ -976,7 +977,7 @@ int SubSampleCommand::getSubSampleList() { bool done = false; int myrand; while (!done) { - myrand = (int)((float)(rand()) / (RAND_MAX / (names.size()-1) + 1)); + myrand = int((float)(names.size()) * (float)(rand()) / ((float)RAND_MAX+1.0)); if (subset.count(names[myrand]) == 0) { subset.insert(names[myrand]); break; } } @@ -1262,7 +1263,7 @@ int SubSampleCommand::processRabund(RAbundVector*& rabund, ofstream& out) { if (m->control_pressed) { delete order; return 0; } //get random number to sample from order between 0 and thisSize-1. - int myrand = (int)((float)(rand()) / (RAND_MAX / (thisSize-1) + 1)); + int myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0)); int bin = order->get(myrand); @@ -1422,7 +1423,7 @@ int SubSampleCommand::processSabund(SAbundVector*& sabund, ofstream& out) { if (m->control_pressed) { delete order; return 0; } //get random number to sample from order between 0 and thisSize-1. - int myrand = (int)((float)(rand()) / (RAND_MAX / (thisSize-1) + 1)); + int myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0)); int bin = order->get(myrand); diff --git a/unifracunweightedcommand.cpp b/unifracunweightedcommand.cpp index 634bf0c..566fd10 100644 --- a/unifracunweightedcommand.cpp +++ b/unifracunweightedcommand.cpp @@ -198,6 +198,8 @@ int UnifracUnweightedCommand::execute() { randomData.resize(numComp,0); //data[0] = unweightedscore //create new tree with same num nodes and leaves as users + if (numComp < processors) { processors = numComp; } + outSum << "Tree#" << '\t' << "Groups" << '\t' << "UWScore" <<'\t' << "UWSig" << endl; m->mothurOut("Tree#\tGroups\tUWScore\tUWSig"); m->mothurOutEndLine(); diff --git a/unifracweightedcommand.cpp b/unifracweightedcommand.cpp index 4c387da..1fa1a28 100644 --- a/unifracweightedcommand.cpp +++ b/unifracweightedcommand.cpp @@ -187,6 +187,8 @@ int UnifracWeightedCommand::execute() { //get weighted for users tree userData.resize(numComp,0); //data[0] = weightedscore AB, data[1] = weightedscore AC... randomData.resize(numComp,0); //data[0] = weightedscore AB, data[1] = weightedscore AC... + + if (numComp < processors) { processors = numComp; } //get weighted scores for users trees for (int i = 0; i < T.size(); i++) { diff --git a/unweighted.cpp b/unweighted.cpp index 24b41a1..ea66294 100644 --- a/unweighted.cpp +++ b/unweighted.cpp @@ -66,7 +66,6 @@ EstOutput Unweighted::getValues(Tree* t, int p, string o) { lines.push_back(linePair(startPos, numPairsPerProcessor)); } - data = createProcesses(t, namesOfGroupCombos); lines.clear(); } @@ -317,7 +316,7 @@ EstOutput Unweighted::getValues(Tree* t, string groupA, string groupB, int p, st } lines.push_back(linePair(startPos, numPairsPerProcessor)); } - + data = createProcesses(t, namesOfGroupCombos, true); lines.clear(); @@ -392,12 +391,13 @@ EstOutput Unweighted::createProcesses(Tree* t, vector< vector > namesOfG if (!in.eof()) { int num; in >> num; m->gobble(in); - + if (m->control_pressed) { break; } double w; for (int j = 0; j < num; j++) { in >> w; + results.push_back(w); } m->gobble(in);