X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=readotucommand.cpp;h=f39e8df2c382f02451848ca41ec6edb23e07aa49;hb=ee8403d4eb5760187d62b42a9cf4272de8fc0ec4;hp=89013e68bfd0235678ac6664838e3259596956f3;hpb=6777912b79eb6d011163da47f3ada09d1a9293c1;p=mothur.git diff --git a/readotucommand.cpp b/readotucommand.cpp index 89013e6..f39e8df 100644 --- a/readotucommand.cpp +++ b/readotucommand.cpp @@ -9,19 +9,35 @@ #include "readotucommand.h" + //********************************************************************************************************************** -ReadOtuCommand::ReadOtuCommand(string option){ +ReadOtuCommand::ReadOtuCommand(){ try { - globaldata = GlobalData::getInstance(); - abort = false; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["shared"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ReadOtuCommand", "ReadOtuCommand"); + exit(1); + } +} +//********************************************************************************************************************** +ReadOtuCommand::ReadOtuCommand(string option) { + try { + abort = false; calledHelp = false; allLines = 1; //allow user to run help - if(option == "help") { help(); abort = true; } + if(option == "help") { help(); abort = true; calledHelp = true; } + else if(option == "citation") { citation(); abort = true; calledHelp = true;} else { + /* //valid paramters for this command - string Array[] = {"list","order","shared", "label","group","sabund", "rabund","groups","outputdir","inputdir"}; + string Array[] = {"list","order","shared","relabund","label","group","sabund", "rabund","groups","ordergroup","outputdir","inputdir"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); OptionParser parser(option); @@ -35,6 +51,11 @@ ReadOtuCommand::ReadOtuCommand(string option){ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["shared"] = tempOutNames; + globaldata->newRead(); //if the user changes the input directory command factory will send this info to us in the output parameter @@ -45,7 +66,7 @@ ReadOtuCommand::ReadOtuCommand(string option){ it = parameters.find("list"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["list"] = inputDir + it->second; } } @@ -53,7 +74,7 @@ ReadOtuCommand::ReadOtuCommand(string option){ it = parameters.find("order"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["order"] = inputDir + it->second; } } @@ -61,7 +82,7 @@ ReadOtuCommand::ReadOtuCommand(string option){ it = parameters.find("shared"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["shared"] = inputDir + it->second; } } @@ -69,7 +90,7 @@ ReadOtuCommand::ReadOtuCommand(string option){ it = parameters.find("group"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["group"] = inputDir + it->second; } } @@ -77,7 +98,7 @@ ReadOtuCommand::ReadOtuCommand(string option){ it = parameters.find("sabund"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["sabund"] = inputDir + it->second; } } @@ -85,11 +106,26 @@ ReadOtuCommand::ReadOtuCommand(string option){ it = parameters.find("rabund"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["rabund"] = inputDir + it->second; } } - + + it = parameters.find("ordergroup"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["ordergroup"] = inputDir + it->second; } + } + + it = parameters.find("relabund"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["relabund"] = inputDir + it->second; } + } } @@ -112,11 +148,22 @@ ReadOtuCommand::ReadOtuCommand(string option){ else if (rabundfile == "not found") { rabundfile = ""; } else { globaldata->setRabundFile(rabundfile); globaldata->setFormat("rabund");} + ordergroupfile = validParameter.validFile(parameters, "ordergroup", true); + if (ordergroupfile == "not open") { abort = true; } + else if (ordergroupfile == "not found") { ordergroupfile = ""; } + else { globaldata->setOrderGroupFile(ordergroupfile); } + sharedfile = validParameter.validFile(parameters, "shared", true); if (sharedfile == "not open") { abort = true; } else if (sharedfile == "not found") { sharedfile = ""; } else { globaldata->setSharedFile(sharedfile); globaldata->setFormat("sharedfile"); } + relAbundfile = validParameter.validFile(parameters, "relabund", true); + if (relAbundfile == "not open") { abort = true; } + else if (relAbundfile == "not found") { relAbundfile = ""; } + else { globaldata->setRelAbundFile(relAbundfile); globaldata->setFormat("relabund"); } + + groupfile = validParameter.validFile(parameters, "group", true); if (groupfile == "not open") { abort = true; } else if (groupfile == "not found") { groupfile = ""; } @@ -133,7 +180,7 @@ ReadOtuCommand::ReadOtuCommand(string option){ groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); globaldata->Groups = Groups; } @@ -141,8 +188,8 @@ ReadOtuCommand::ReadOtuCommand(string option){ if ((listfile != "") && (groupfile != "")) { globaldata->setFormat("shared"); } //you have not given a file - if ((listfile == "") && (sharedfile == "") && (rabundfile == "") && (sabundfile == "")) { - mothurOut("You must enter either a listfile, rabundfile, sabundfile or a sharedfile with the read.otu command. "); mothurOutEndLine(); abort = true; + if ((listfile == "") && (sharedfile == "") && (rabundfile == "") && (sabundfile == "") && (relAbundfile == "")) { + m->mothurOut("You must enter either a listfile, rabundfile, sabundfile, relabund or a sharedfile with the read.otu command. "); m->mothurOutEndLine(); abort = true; } //check for optional parameter and set defaults @@ -150,71 +197,41 @@ ReadOtuCommand::ReadOtuCommand(string option){ label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } globaldata->labels = labels; } globaldata->allLines = allLines; - + orderfile = validParameter.validFile(parameters, "order", true); if (orderfile == "not open") { abort = true; } else if (orderfile == "not found") { orderfile = ""; } else { globaldata->setOrderFile(orderfile); } - + if (abort == false) { //gets whichever one of the above is set filename = globaldata->inputFileName; } - + */ } } catch(exception& e) { - errorOut(e, "ReadOtuCommand", "ReadOtuCommand"); + m->errorOut(e, "ReadOtuCommand", "ReadOtuCommand"); exit(1); } } -//********************************************************************************************************************** - -void ReadOtuCommand::help(){ - try { - mothurOut("The read.otu command must be run before you execute a collect.single, rarefaction.single, summary.single, \n"); - mothurOut("collect.shared, rarefaction.shared or summary.shared command. Mothur will generate a .list, .rabund and .sabund upon completion of the cluster command \n"); - mothurOut("or you may use your own. The read.otu command parameter options are list, rabund, sabund, shared, group, order, label and groups.\n"); - mothurOut("The read.otu command can be used in two ways. The first is to read a list, rabund or sabund and run the collect.single, rarefaction.single or summary.single.\n"); - mothurOut("For this use the read.otu command should be in the following format: read.otu(list=yourListFile, order=yourOrderFile, label=yourLabels).\n"); - mothurOut("The list, rabund or sabund parameter is required, but you may only use one of them.\n"); - mothurOut("The label parameter is used to read specific labels in your input.\n"); - mothurOut("The second way to use the read.otu command is to read a list and a group, or a shared so you can use the collect.shared, rarefaction.shared or summary.shared commands.\n"); - mothurOut("In this case the read.otu command should be in the following format: read.otu(list=yourListFile, group=yourGroupFile) or read.otu(shared=yourSharedFile). \n"); - mothurOut("The list parameter and group paramaters or the shared paremeter is required. When using the command the second way with a list and group file read.otu command parses the .list file\n"); - mothurOut("and separates it into groups. It outputs a .shared file containing the OTU information for each group. The read.otu command also outputs a .rabund file for each group. \n"); - mothurOut("You can use the groups parameter to choose only specific groups to be used in the .shared and .rabund files. \n"); - mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n"); - - } - catch(exception& e) { - errorOut(e, "ReadOtuCommand", "help"); - exit(1); - } -} - - - -//********************************************************************************************************************** - -ReadOtuCommand::~ReadOtuCommand(){ - } - -//********************************************************************************************************************** +///********************************************************************************************************************** int ReadOtuCommand::execute(){ try { - if (abort == true) { return 0; } - + if (abort == true) { if (calledHelp) { return 0; } return 2; } + m->mothurOut(getHelpString()); m->mothurOutEndLine(); + + /* if (globaldata->getFormat() == "shared") { shared = new SharedCommand(outputDir); @@ -225,14 +242,35 @@ int ReadOtuCommand::execute(){ globaldata->setListFile(""); globaldata->setGroupFile(""); globaldata->setSharedFile(""); + }else { //shared command outputs the filenames + //m->mothurOutEndLine(); + //m->mothurOut("Output File Name: "); m->mothurOutEndLine(); + //m->mothurOut(globaldata->getSharedFile()); m->mothurOutEndLine(); + //m->mothurOutEndLine(); + } + + outputTypes = shared->getOutputFiles(); + + //set rabund file as new current rabundfile + string current = ""; + itTypes = outputTypes.find("rabund"); + if (itTypes != outputTypes.end()) { + if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setRabundFile(current); } } + itTypes = outputTypes.find("shared"); + if (itTypes != outputTypes.end()) { + if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSharedFile(current); } + } + delete shared; } + */ + return 0; } catch(exception& e) { - errorOut(e, "ReadOtuCommand", "execute"); + m->errorOut(e, "ReadOtuCommand", "execute"); exit(1); } }