X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=makelefsecommand.cpp;h=c859bfbc230201e4be1ef73ab19ed56f28b3412d;hp=8f2857e5e302b0587555a03e6a705082c47f9d45;hb=cf9987b67aa49777a4c91c2d21f96e58bf17aa82;hpb=ad4f75fd7c938090d3b1ce4cfefcc21edf1869eb diff --git a/makelefsecommand.cpp b/makelefsecommand.cpp index 8f2857e..c859bfb 100644 --- a/makelefsecommand.cpp +++ b/makelefsecommand.cpp @@ -7,6 +7,7 @@ // #include "makelefsecommand.h" +#include "designmap.h" //********************************************************************************************************************** vector MakeLefseCommand::setParameters(){ @@ -42,8 +43,8 @@ string MakeLefseCommand::getHelpString(){ helpString += "The constaxonomy parameter is used to input your taxonomy file. http://www.wiki.mothur.org/wiki/Constaxonomy_file. The contaxonomy file is the taxonomy file outputted by classify.otu(list=yourListfile, taxonomy=yourTaxonomyFile). Be SURE that the you are the constaxonomy file distance matches the shared file distance. ie, for *.0.03.cons.taxonomy set label=0.03. Mothur is smart enough to handle shared files that have been subsampled. \n"; helpString += "The scale parameter allows you to select what scale you would like to use to convert your shared file abundances to relative abundances. Choices are totalgroup, totalotu, averagegroup, averageotu, default is totalgroup.\n"; helpString += "The label parameter allows you to select what distance level you would like used, if none is given the first distance is used.\n"; - helpString += "The make.lefse command should be in the following format: make.lefse(list=yourListFile, taxonomy=outputFromClassify.seqsCommand, name=yourNameFile)\n"; - helpString += "make.lefse(shared=final.an.list, taxonomy=final.an.taxonomy, name=final.names)\n"; + helpString += "The make.lefse command should be in the following format: make.lefse(shared=yourSharedFile)\n"; + helpString += "make.lefse(shared=final.an.shared)\n"; return helpString; } catch(exception& e) { @@ -258,28 +259,37 @@ int MakeLefseCommand::runRelabund(map& consTax, vectoropenOutputFile(outputFile, out); - GroupMap* designMap = NULL; + DesignMap* designMap = NULL; if (designfile != "") { - designMap = new GroupMap(designfile); - designMap->readDesignMap(); + designMap = new DesignMap(designfile); + vector categories = designMap->getNamesOfCategories(); - out << "treatment\t"; - for (int i = 0; i < lookup.size(); i++) { - string treatment = designMap->getGroup(lookup[i]->getGroup()); - if (treatment == "not found") { - m->mothurOut("[ERROR]: " + lookup[i]->getGroup() + " is not in your design file, please correct.\n"); - }else { out << treatment << '\t'; } + if (categories.size() > 3) { m->mothurOut("\n[NOTE]: LEfSe input files allow for a class, subclass and subject. More than 3 categories can cause formatting errors.\n\n"); } + + for (int j = 0; j < categories.size(); j++) { + out << categories[j] << "\t"; + for (int i = 0; i < lookup.size()-1; i++) { + if (m->control_pressed) { out.close(); delete designMap; return 0; } + string value = designMap->get(lookup[i]->getGroup(), categories[j]); + if (value == "not found") { + m->mothurOut("[ERROR]: " + lookup[i]->getGroup() + " is not in your design file, please correct.\n"); m->control_pressed = true; + }else { out << value << '\t'; } + } + string value = designMap->get(lookup[lookup.size()-1]->getGroup(), categories[j]); + if (value == "not found") { + m->mothurOut("[ERROR]: " + lookup[lookup.size()-1]->getGroup() + " is not in your design file, please correct.\n"); m->control_pressed = true; + }else { out << value; } + out << endl; } - out << endl; } out << "group\t"; - for (int i = 0; i < lookup.size(); i++) { out << lookup[i]->getGroup() << '\t'; } - out << endl; + for (int i = 0; i < lookup.size()-1; i++) { out << lookup[i]->getGroup() << '\t'; } + out << lookup[lookup.size()-1]->getGroup() << endl; for (int i = 0; i < lookup[0]->getNumBins(); i++) { //process each otu if (m->control_pressed) { break; } - string nameOfOtu = m->currentBinLabels[i]; + string nameOfOtu = m->currentSharedBinLabels[i]; if (constaxonomyfile != "") { //try to find the otuName in consTax to replace with consensus taxonomy map::iterator it = consTax.find(nameOfOtu); if (it != consTax.end()) { @@ -289,7 +299,7 @@ int MakeLefseCommand::runRelabund(map& consTax, vectorremoveConfidences(nameOfOtu); for (int j = 0; j < nameOfOtu.length()-1; j++) { - if (nameOfOtu[j] == ';') { fixedName += "_" + m->currentBinLabels[i] + '|'; } + if (nameOfOtu[j] == ';') { fixedName += "_" + m->currentSharedBinLabels[i] + '|'; } else { fixedName += nameOfOtu[j]; } } nameOfOtu = fixedName; @@ -302,8 +312,9 @@ int MakeLefseCommand::runRelabund(map& consTax, vectorgetAbundance(i) << '\t'; } - out << endl; + for (int j = 0; j < lookup.size()-1; j++) { out << lookup[j]->getAbundance(i) << '\t'; } + + out << lookup[lookup.size()-1]->getAbundance(i)<< endl; } out.close();