X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=makebiomcommand.cpp;h=a1018833e6268b6d0fe04aa25d4598f37df9cb4d;hb=bcb6728939694811bf6a00ae6d568f783840edfd;hp=6385adef0fd1c36f73e509604f10b082a75e54a5;hpb=5c5c0428f6d548c28a8b903ac80efed4f92d59db;p=mothur.git diff --git a/makebiomcommand.cpp b/makebiomcommand.cpp index 6385ade..a101883 100644 --- a/makebiomcommand.cpp +++ b/makebiomcommand.cpp @@ -92,14 +92,14 @@ //********************************************************************************************************************** vector MakeBiomCommand::setParameters(){ try { - CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared); - CommandParameter pcontaxonomy("contaxonomy", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pcontaxonomy); - CommandParameter pmetadata("metadata", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pmetadata); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); - CommandParameter pmatrixtype("matrixtype", "Multiple", "sparse-dense", "sparse", "", "", "",false,false); parameters.push_back(pmatrixtype); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none","biom",false,true,true); parameters.push_back(pshared); + CommandParameter pcontaxonomy("contaxonomy", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pcontaxonomy); + CommandParameter pmetadata("metadata", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pmetadata); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); + CommandParameter pmatrixtype("matrixtype", "Multiple", "sparse-dense", "sparse", "", "", "","",false,false); parameters.push_back(pmatrixtype); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -133,24 +133,19 @@ string MakeBiomCommand::getHelpString(){ } } //********************************************************************************************************************** -string MakeBiomCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string MakeBiomCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //is this a type this command creates - it = outputTypes.find(type); - if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); } - else { - if (type == "biom") { outputFileName = "biom"; } - else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; } - } - return outputFileName; - } - catch(exception& e) { - m->errorOut(e, "MakeBiomCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "biom") { pattern = "[filename],[distance],biom"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "MakeBiomCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** @@ -388,8 +383,10 @@ int MakeBiomCommand::execute(){ //********************************************************************************************************************** int MakeBiomCommand::getBiom(vector& lookup){ try { - - string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + lookup[0]->getLabel() + "." + getOutputFileNameTag("biom"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); + variables["[distance]"] = lookup[0]->getLabel(); + string outputFileName = getOutputFileName("biom",variables); ofstream out; m->openOutputFile(outputFileName, out); outputNames.push_back(outputFileName); outputTypes["biom"].push_back(outputFileName); @@ -408,6 +405,7 @@ int MakeBiomCommand::getBiom(vector& lookup){ out << "{\n" + spaces + "\"id\":\"" + sharedfile + "-" + lookup[0]->getLabel() + "\",\n" + spaces + "\"format\": \"Biological Observation Matrix 0.9.1\",\n" + spaces + "\"format_url\": \"http://biom-format.org\",\n"; out << spaces + "\"type\": \"OTU table\",\n" + spaces + "\"generated_by\": \"" << mothurString << "\",\n" + spaces + "\"date\": \"" << dateString << "\",\n"; + int numBins = lookup[0]->getNumBins(); vector metadata = getMetaData(lookup); if (m->control_pressed) { out.close(); return 0; } @@ -423,11 +421,11 @@ int MakeBiomCommand::getBiom(vector& lookup){ out << spaces + "\"rows\":[\n"; string rowFront = spaces + spaces + "{\"id\":\""; string rowBack = "\", \"metadata\":"; - for (int i = 0; i < m->currentBinLabels.size()-1; i++) { + for (int i = 0; i < numBins-1; i++) { if (m->control_pressed) { out.close(); return 0; } out << rowFront << m->currentBinLabels[i] << rowBack << metadata[i] << "},\n"; } - out << rowFront << m->currentBinLabels[(m->currentBinLabels.size()-1)] << rowBack << metadata[(m->currentBinLabels.size()-1)] << "}\n" + spaces + "],\n"; + out << rowFront << m->currentBinLabels[(numBins-1)] << rowBack << metadata[(numBins-1)] << "}\n" + spaces + "],\n"; //get column info /*"columns": [ @@ -627,8 +625,8 @@ vector MakeBiomCommand::getMetaData(vector& lookup) //********************************************************************************************************************** int MakeBiomCommand::getSampleMetaData(vector& lookup){ try { - - if (metadatafile == "") { for (int i = 0; i < lookup.size(); i++) { sampleMetadata.push_back("null"); } } + sampleMetadata.clear(); + if (metadatafile == "") { for (int i = 0; i < lookup.size(); i++) { sampleMetadata.push_back("null"); } } else { ifstream in; m->openInputFile(metadatafile, in);