X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=metastatscommand.cpp;h=7942bfcce548030951e3c5157438d13eb88c17d6;hb=1bf53bca7e26bf091588bc8ca6e68cbfae1df6fe;hp=4bb50ab107bb4fdde1d97b790cd15f3cb42d8599;hpb=ca9ac1d80c62f57270b0dcd49410ebe08a8aecd6;p=mothur.git diff --git a/metastatscommand.cpp b/metastatscommand.cpp index 4bb50ab..7942bfc 100644 --- a/metastatscommand.cpp +++ b/metastatscommand.cpp @@ -10,6 +10,7 @@ #include "metastatscommand.h" #include "metastats.h" #include "sharedutilities.h" +#include "mothurmetastats.h" //********************************************************************************************************************** vector MetaStatsCommand::setParameters(){ @@ -52,7 +53,7 @@ string MetaStatsCommand::getHelpString(){ helpString += "The metastats command should be in the following format: metastats(design=yourDesignFile).\n"; helpString += "Example metastats(design=temp.design, groups=A-B-C).\n"; helpString += "The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n"; - helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"; + helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n"; return helpString; } catch(exception& e) { @@ -83,6 +84,7 @@ MetaStatsCommand::MetaStatsCommand(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 { vector myArray = setParameters(); @@ -133,7 +135,7 @@ MetaStatsCommand::MetaStatsCommand(string option) { sharedfile = m->getSharedFile(); if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current sharedfile and the shared parameter is required."); m->mothurOutEndLine(); abort = true; } - } + }else { m->setSharedFile(sharedfile); } //check for required parameters designfile = validParameter.validFile(parameters, "design", true); @@ -143,7 +145,7 @@ MetaStatsCommand::MetaStatsCommand(string option) { designfile = m->getDesignFile(); if (designfile != "") { m->mothurOut("Using " + designfile + " as input file for the design parameter."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current designfile and the design parameter is required."); m->mothurOutEndLine(); abort = true; } - } + }else { m->setDesignFile(designfile); } //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ @@ -248,7 +250,7 @@ int MetaStatsCommand::execute(){ //as long as you are not at the end of the file or done wih the lines you want while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->Groups.clear(); delete input; delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->Groups.clear(); delete input; delete designMap; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ @@ -279,13 +281,13 @@ int MetaStatsCommand::execute(){ //prevent memory leak for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } - if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); delete input; delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); delete input; delete designMap; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } //get next line to process lookup = input->getSharedRAbundVectors(); } - if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); delete input; delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); delete input; delete designMap; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } //output error messages about any remaining user labels set::iterator it; @@ -317,7 +319,7 @@ int MetaStatsCommand::execute(){ delete input; delete designMap; - if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0;} + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0;} m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); @@ -395,13 +397,15 @@ int MetaStatsCommand::driver(int start, int num, vector& th //get filename string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + thisLookUp[0]->getLabel() + "." + setA + "-" + setB + ".metastats"; outputNames.push_back(outputFileName); outputTypes["metastats"].push_back(outputFileName); - int nameLength = outputFileName.length(); - char * output = new char[nameLength]; - strcpy(output, outputFileName.c_str()); + //int nameLength = outputFileName.length(); + //char * output = new char[nameLength]; + //strcpy(output, outputFileName.c_str()); //build matrix from shared rabunds - double** data; - data = new double*[thisLookUp[0]->getNumBins()]; + //double** data; + //data = new double*[thisLookUp[0]->getNumBins()]; + + vector< vector > data2; data2.resize(thisLookUp[0]->getNumBins()); vector subset; int setACount = 0; @@ -426,22 +430,29 @@ int MetaStatsCommand::driver(int start, int num, vector& th }else { //fill data for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) { - data[j] = new double[subset.size()]; + //data[j] = new double[subset.size()]; + data2[j].resize(subset.size(), 0.0); for (int i = 0; i < subset.size(); i++) { - data[j][i] = (subset[i]->getAbundance(j)); + //data[j][i] = (subset[i]->getAbundance(j)); + data2[j][i] = (subset[i]->getAbundance(j)); } } m->mothurOut("Comparing " + setA + " and " + setB + "..."); m->mothurOutEndLine(); - metastat_main(output, thisLookUp[0]->getNumBins(), subset.size(), threshold, iters, data, setACount); + //metastat_main(output, thisLookUp[0]->getNumBins(), subset.size(), threshold, iters, data, setACount); + + m->mothurOutEndLine(); + MothurMetastats mothurMeta(threshold, iters); + mothurMeta.runMetastats(outputFileName , data2, setACount); + m->mothurOutEndLine(); m->mothurOutEndLine(); } //free memory - delete output; - for(int i = 0; i < thisLookUp[0]->getNumBins(); i++) { delete[] data[i]; } - delete[] data; + //delete output; + //for(int i = 0; i < thisLookUp[0]->getNumBins(); i++) { delete[] data[i]; } + //delete[] data; } return 0;