X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=unifracweightedcommand.cpp;h=b007db1f6eddc2d8e6119add616803b1d58526a2;hb=896a4f281982a3c2889f6ce6d73be997072aceae;hp=29cdf94091cebb65104e1b5691e5691e19a4e495;hpb=ca9ac1d80c62f57270b0dcd49410ebe08a8aecd6;p=mothur.git diff --git a/unifracweightedcommand.cpp b/unifracweightedcommand.cpp index 29cdf94..b007db1 100644 --- a/unifracweightedcommand.cpp +++ b/unifracweightedcommand.cpp @@ -48,7 +48,7 @@ string UnifracWeightedCommand::getHelpString(){ helpString += "Example unifrac.weighted(groups=A-B-C, iters=500).\n"; helpString += "The default value for groups is all the groups in your groupfile, and iters is 1000.\n"; helpString += "The unifrac.weighted command output two files: .weighted and .wsummary their descriptions are in the manual.\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) { @@ -80,6 +80,7 @@ UnifracWeightedCommand::UnifracWeightedCommand(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,6 +134,10 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { } m->runParse = true; + m->clearGroups(); + m->clearAllGroups(); + m->Treenames.clear(); + m->names.clear(); //check for required parameters treefile = validParameter.validFile(parameters, "tree", true); @@ -141,16 +146,18 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { treefile = m->getTreeFile(); if (treefile != "") { m->mothurOut("Using " + treefile + " as input file for the tree parameter."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current tree file and the tree parameter is required."); m->mothurOutEndLine(); abort = true; } - } + }else { m->setTreeFile(treefile); } //check for required parameters groupfile = validParameter.validFile(parameters, "group", true); if (groupfile == "not open") { abort = true; } else if (groupfile == "not found") { groupfile = ""; } + else { m->setGroupFile(groupfile); } namefile = validParameter.validFile(parameters, "name", true); if (namefile == "not open") { abort = true; } else if (namefile == "not found") { namefile = ""; } + else { m->setNameFile(namefile); } outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } @@ -161,11 +168,11 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { if (groups == "not found") { groups = ""; } else { m->splitAtDash(groups, Groups); - m->Groups = Groups; + m->setGroups(Groups); } itersString = validParameter.validFile(parameters, "iters", false); if (itersString == "not found") { itersString = "1000"; } - convert(itersString, iters); + m->mothurConvert(itersString, iters); string temp = validParameter.validFile(parameters, "distance", false); if (temp == "not found") { phylip = false; outputForm = ""; } @@ -182,7 +189,7 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } m->setProcessors(temp); - convert(temp, processors); + m->mothurConvert(temp, processors); if (!random) { iters = 0; } //turn off random calcs } @@ -200,6 +207,8 @@ int UnifracWeightedCommand::execute() { if (abort == true) { if (calledHelp) { return 0; } return 2; } + m->setTreeFile(treefile); + if (groupfile != "") { //read in group map info. tmap = new TreeMap(groupfile); @@ -243,8 +252,8 @@ int UnifracWeightedCommand::execute() { if (m->control_pressed) { delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; } - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); - m->Groups.clear(); + for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); + m->clearGroups(); return 0; } @@ -268,8 +277,11 @@ int UnifracWeightedCommand::execute() { util = new SharedUtil(); string s; //to make work with setgroups - util->setGroups(m->Groups, tmap->namesOfGroups, s, numGroups, "weighted"); //sets the groups the user wants to analyze - util->getCombos(groupComb, m->Groups, numComp); + Groups = m->getGroups(); + vector nameGroups = tmap->getNamesOfGroups(); + util->setGroups(Groups, nameGroups, s, numGroups, "weighted"); //sets the groups the user wants to analyze + util->getCombos(groupComb, Groups, numComp); + m->setGroups(Groups); delete util; weighted = new Weighted(tmap, includeRoot); @@ -286,7 +298,7 @@ int UnifracWeightedCommand::execute() { for (int i = 0; i < T.size(); i++) { if (m->control_pressed) { delete tmap; delete weighted; - for (int i = 0; i < T.size(); i++) { delete T[i]; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + for (int i = 0; i < T.size(); i++) { delete T[i]; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } counter = 0; rScores.resize(numComp); //data[0] = weightedscore AB, data[1] = weightedscore AC... @@ -301,7 +313,7 @@ int UnifracWeightedCommand::execute() { userData = weighted->getValues(T[i], processors, outputDir); //userData[0] = weightedscore if (m->control_pressed) { delete tmap; delete weighted; - for (int i = 0; i < T.size(); i++) { delete T[i]; } if (random) { delete output; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + for (int i = 0; i < T.size(); i++) { delete T[i]; } if (random) { delete output; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } //save users score for (int s=0; s > namesOfGroupCombos; for (int a=0; a groups; groups.push_back(m->Groups[a]); groups.push_back(m->Groups[l]); + vector groups; groups.push_back((m->getGroups())[a]); groups.push_back((m->getGroups())[l]); namesOfGroupCombos.push_back(groups); } } @@ -355,7 +367,7 @@ int UnifracWeightedCommand::execute() { #endif if (m->control_pressed) { delete tmap; delete weighted; - for (int i = 0; i < T.size(); i++) { delete T[i]; } delete output; outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + for (int i = 0; i < T.size(); i++) { delete T[i]; } delete output; outSum.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } //report progress // m->mothurOut("Iter: " + toString(j+1)); m->mothurOutEndLine(); @@ -393,20 +405,20 @@ int UnifracWeightedCommand::execute() { if (m->control_pressed) { delete tmap; delete weighted; - for (int i = 0; i < T.size(); i++) { delete T[i]; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + for (int i = 0; i < T.size(); i++) { delete T[i]; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } printWSummaryFile(); if (phylip) { createPhylipFile(); } //clear out users groups - m->Groups.clear(); + m->clearGroups(); delete tmap; delete weighted; for (int i = 0; i < T.size(); i++) { delete T[i]; } if (m->control_pressed) { - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } @@ -491,7 +503,7 @@ int UnifracWeightedCommand::createProcesses(Tree* t, vector< vector > na double tempScore; for (int j = lines[(i+1)].start; j < (lines[(i+1)].start + lines[(i+1)].num); j++) { in >> tempScore; scores[j].push_back(tempScore); } in.close(); - remove(s.c_str()); + m->mothurRemove(s); } return 0; @@ -572,8 +584,10 @@ void UnifracWeightedCommand::printWeightedFile() { void UnifracWeightedCommand::printWSummaryFile() { try { //column headers - outSum << "Tree#" << '\t' << "Groups" << '\t' << "WScore" << '\t' << "WSig" << endl; - m->mothurOut("Tree#\tGroups\tWScore\tWSig"); m->mothurOutEndLine(); + outSum << "Tree#" << '\t' << "Groups" << '\t' << "WScore" << '\t'; + m->mothurOut("Tree#\tGroups\tWScore\t"); + if (random) { outSum << "WSig"; m->mothurOut("WSig"); } + outSum << endl; m->mothurOutEndLine(); //format output outSum.setf(ios::fixed, ios::floatfield); outSum.setf(ios::showpoint); @@ -593,9 +607,9 @@ void UnifracWeightedCommand::printWSummaryFile() { m->mothurOutJustToLog(toString(i+1) +"\t" + groupComb[j] +"\t" + toString(utreeScores[count]) +"\t<" + toString((1/float(iters))) + "\n"); } }else{ - outSum << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << "0.00" << endl; - cout << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << "0.00" << endl; - m->mothurOutJustToLog(toString(i+1) +"\t" + groupComb[j] +"\t" + toString(utreeScores[count]) +"\t0.00\n"); + outSum << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << endl; + cout << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << endl; + m->mothurOutJustToLog(toString(i+1) +"\t" + groupComb[j] +"\t" + toString(utreeScores[count]) +"\n"); } count++; } @@ -628,17 +642,17 @@ void UnifracWeightedCommand::createPhylipFile() { if ((outputForm == "lt") || (outputForm == "square")) { //output numSeqs - out << m->Groups.size() << endl; + out << m->getNumGroups() << endl; } //make matrix with scores in it - vector< vector > dists; dists.resize(m->Groups.size()); - for (int i = 0; i < m->Groups.size(); i++) { - dists[i].resize(m->Groups.size(), 0.0); + vector< vector > dists; dists.resize(m->getNumGroups()); + for (int i = 0; i < m->getNumGroups(); i++) { + dists[i].resize(m->getNumGroups(), 0.0); } //flip it so you can print it - for (int r=0; rGroups.size(); r++) { + for (int r=0; rgetNumGroups(); r++) { for (int l = 0; l < r; l++) { dists[r][l] = utreeScores[count]; dists[l][r] = utreeScores[count]; @@ -647,9 +661,9 @@ void UnifracWeightedCommand::createPhylipFile() { } //output to file - for (int r=0; rGroups.size(); r++) { + for (int r=0; rgetNumGroups(); r++) { //output name - string name = m->Groups[r]; + string name = (m->getGroups())[r]; if (name.length() < 10) { //pad with spaces to make compatible while (name.length() < 10) { name += " "; } } @@ -664,12 +678,12 @@ void UnifracWeightedCommand::createPhylipFile() { out << name << '\t'; //output distances - for (int l = 0; l < m->Groups.size(); l++) { out << dists[r][l] << '\t'; } + for (int l = 0; l < m->getNumGroups(); l++) { out << dists[r][l] << '\t'; } out << endl; }else{ //output distances for (int l = 0; l < r; l++) { - string otherName = m->Groups[l]; + string otherName = (m->getGroups())[l]; if (otherName.length() < 10) { //pad with spaces to make compatible while (otherName.length() < 10) { otherName += " "; } }