X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=homovacommand.cpp;h=a8d2786f085ef584ba5f18069dfea2c5a51da572;hb=e150b0b0664caec517485ee6d69dcdade6dcae77;hp=52456b4ddedcd7b1db62a4fa8d03c5082eedf932;hpb=7b287636ea67fb2254b119c21b4057a177d3ce19;p=mothur.git diff --git a/homovacommand.cpp b/homovacommand.cpp index 52456b4..a8d2786 100644 --- a/homovacommand.cpp +++ b/homovacommand.cpp @@ -12,61 +12,58 @@ #include "readphylipvector.h" //********************************************************************************************************************** - -vector HomovaCommand::getValidParameters(){ +vector HomovaCommand::setParameters(){ try { - string Array[] = {"outputdir","iters","phylip","design","alpha", "inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pdesign); + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip); + CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); + CommandParameter palpha("alpha", "Number", "", "0.05", "", "", "",false,false); parameters.push_back(palpha); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "HomovaCommand", "getValidParameters"); + m->errorOut(e, "HomovaCommand", "setParameters"); exit(1); } } - //********************************************************************************************************************** - -HomovaCommand::HomovaCommand(){ +string HomovaCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["homova"] = tempOutNames; + string helpString = ""; + helpString += "Referenced: Stewart CN, Excoffier L (1996). Assessing population genetic structure and variability with RAPD data: Application to Vaccinium macrocarpon (American Cranberry). J Evol Biol 9: 153-71.\n"; + helpString += "The homova command outputs a .homova file. \n"; + helpString += "The homova command parameters are phylip, iters, and alpha. The phylip and design parameters are required, unless valid current files exist.\n"; + helpString += "The design parameter allows you to assign your samples to groups when you are running homova. It is required. \n"; + helpString += "The design file looks like the group file. It is a 2 column tab delimited file, where the first column is the sample name and the second column is the group the sample belongs to.\n"; + helpString += "The iters parameter allows you to set number of randomization for the P value. The default is 1000. \n"; + helpString += "The homova command should be in the following format: homova(phylip=file.dist, design=file.design).\n"; + helpString += "Note: No spaces between parameter labels (i.e. iters), '=' and parameters (i.e. 1000).\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "HomovaCommand", "HomovaCommand"); + m->errorOut(e, "HomovaCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector HomovaCommand::getRequiredParameters(){ - try { - string Array[] = {"design"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "HomovaCommand", "getRequiredParameters"); - exit(1); - } -} - -//********************************************************************************************************************** - -vector HomovaCommand::getRequiredFiles(){ +HomovaCommand::HomovaCommand(){ try { - string Array[] = {}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["homova"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "HomovaCommand", "getRequiredFiles"); + m->errorOut(e, "HomovaCommand", "HomovaCommand"); exit(1); } } - //********************************************************************************************************************** HomovaCommand::HomovaCommand(string option) { @@ -75,11 +72,10 @@ HomovaCommand::HomovaCommand(string option) { //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } + else if(option == "citation") { citation(); abort = true; calledHelp = true;} else { - //valid paramters for this command - string AlignArray[] = {"design","outputdir","iters","phylip","alpha", "inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -123,22 +119,22 @@ HomovaCommand::HomovaCommand(string option) { phylipFileName = validParameter.validFile(parameters, "phylip", true); if (phylipFileName == "not open") { phylipFileName = ""; abort = true; } - else if (phylipFileName == "not found") { phylipFileName = ""; } - else if (designFileName == "not found") { - designFileName = ""; - m->mothurOut("You must provide an phylip file."); - m->mothurOutEndLine(); - abort = true; + else if (phylipFileName == "not found") { + //if there is a current phylip file, use it + phylipFileName = m->getPhylipFile(); + if (phylipFileName != "") { m->mothurOut("Using " + phylipFileName + " as input file for the phylip parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current phylip file and the phylip parameter is required."); m->mothurOutEndLine(); abort = true; } + } //check for required parameters designFileName = validParameter.validFile(parameters, "design", true); if (designFileName == "not open") { abort = true; } else if (designFileName == "not found") { - designFileName = ""; - m->mothurOut("You must provide an design file."); - m->mothurOutEndLine(); - abort = true; + //if there is a current design file, use it + designFileName = m->getDesignFile(); + if (designFileName != "") { m->mothurOut("Using " + designFileName + " as input file for the design parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current design file and the design parameter is required."); m->mothurOutEndLine(); abort = true; } } string temp = validParameter.validFile(parameters, "iters", false); @@ -156,30 +152,6 @@ HomovaCommand::HomovaCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void HomovaCommand::help(){ - try { - m->mothurOut("Referenced: Stewart CN, Excoffier L (1996). Assessing population genetic structure and variability with RAPD data: Application to Vaccinium macrocarpon (American Cranberry). J Evol Biol 9: 153-71.\n"); - m->mothurOut("The homova command outputs a .homova file. \n"); - m->mothurOut("The homova command parameters are phylip, iters, and alpha. The phylip and design parameters are required.\n"); - m->mothurOut("The design parameter allows you to assign your samples to groups when you are running homova. It is required. \n"); - m->mothurOut("The design file looks like the group file. It is a 2 column tab delimited file, where the first column is the sample name and the second column is the group the sample belongs to.\n"); - m->mothurOut("The iters parameter allows you to set number of randomization for the P value. The default is 1000. \n"); - m->mothurOut("The homova command should be in the following format: homova(phylip=file.dist, design=file.design).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. iters), '=' and parameters (i.e. 1000).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "HomovaCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -HomovaCommand::~HomovaCommand(){} - //********************************************************************************************************************** int HomovaCommand::execute(){ @@ -216,8 +188,8 @@ int HomovaCommand::execute(){ m->openOutputFile(HOMOVAFileName, HOMOVAFile); outputNames.push_back(HOMOVAFileName); outputTypes["homova"].push_back(HOMOVAFileName); - HOMOVAFile << "HOMOVA\tBValue\tP-value\tSSwithin_values" << endl; - m->mothurOut("HOMOVA\tBValue\tP-value\tSSwithin_values\n"); + HOMOVAFile << "HOMOVA\tBValue\tP-value\tSSwithin/(Ni-1)_values" << endl; + m->mothurOut("HOMOVA\tBValue\tP-value\tSSwithin/(Ni-1)_values\n"); double fullHOMOVAPValue = runHOMOVA(HOMOVAFile, origGroupSampleMap, experimentwiseAlpha); @@ -231,8 +203,7 @@ int HomovaCommand::execute(){ for(itA=origGroupSampleMap.begin();itA!=origGroupSampleMap.end();itA++){ itB = itA;itB++; - for(itB;itB!=origGroupSampleMap.end();itB++){ - + for(;itB!=origGroupSampleMap.end();itB++){ map > pairwiseGroupSampleMap; pairwiseGroupSampleMap[itA->first] = itA->second; pairwiseGroupSampleMap[itB->first] = itB->second; @@ -296,7 +267,7 @@ double HomovaCommand::runHOMOVA(ofstream& HOMOVAFile, map > HOMOVAFile << it->first; m->mothurOut(it->first); it++; - for(it;it!=groupSampleMap.end();it++){ + for(;it!=groupSampleMap.end();it++){ HOMOVAFile << '-' << it->first; m->mothurOut('-' + it->first); } @@ -379,6 +350,8 @@ double HomovaCommand::calcBValue(map > groupSampleMap, vecto secondTermSum += (numSamplesInGroup - 1) * log(ssWithinVector[index] / (double)(numSamplesInGroup - 1)); inverseOneMinusSum += 1.0 / (double)(numSamplesInGroup - 1); + + ssWithinVector[index] /= (double)(numSamplesInGroup - 1); //this line is only for output purposes to scale SSw by the number of samples in the group index++; }