X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=readotucommand.cpp;h=30dc55343d46e0656c7123aba7afddea7f4b3a77;hb=b8f3e71c8a0310e25261464d27e6fcfe891483b0;hp=ba7eae42a668e7fa9bf3a9f8d33c4746b55ce810;hpb=753dc84cf289b1d5dc0ca5b0c043640927aa951a;p=mothur.git diff --git a/readotucommand.cpp b/readotucommand.cpp index ba7eae4..30dc553 100644 --- a/readotucommand.cpp +++ b/readotucommand.cpp @@ -10,7 +10,7 @@ #include "readotucommand.h" //********************************************************************************************************************** -ReadOtuCommand::ReadOtuCommand(string option){ +ReadOtuCommand::ReadOtuCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -21,21 +21,81 @@ ReadOtuCommand::ReadOtuCommand(string option){ else { //valid paramters for this command - string Array[] = {"list","order","shared", "line", "label","group","sabund", "rabund"}; + string Array[] = {"list","order","shared", "label","group","sabund", "rabund","groups","outputdir","inputdir"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); OptionParser parser(option); map parameters = parser.getParameters(); ValidParameters validParameter; + map::iterator it; //check to make sure all parameters are valid for command - for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - + globaldata->newRead(); + //if the user changes the input directory command factory will send this info to us in the output parameter + string inputDir = validParameter.validFile(parameters, "inputdir", false); + if (inputDir == "not found"){ inputDir = ""; } + else { + string path; + it = parameters.find("list"); + //user has given a template file + if(it != parameters.end()){ + path = 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; } + } + + it = parameters.find("order"); + //user has given a template file + if(it != parameters.end()){ + path = 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; } + } + + it = parameters.find("shared"); + //user has given a template file + if(it != parameters.end()){ + path = 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; } + } + + it = parameters.find("group"); + //user has given a template file + if(it != parameters.end()){ + path = 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; } + } + + it = parameters.find("sabund"); + //user has given a template file + if(it != parameters.end()){ + path = 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; } + } + + it = parameters.find("rabund"); + //user has given a template file + if(it != parameters.end()){ + path = 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; } + } + + } + + + //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"){ outputDir = ""; } + //check for required parameters listfile = validParameter.validFile(parameters, "list", true); if (listfile == "not open") { abort = true; } @@ -63,7 +123,18 @@ ReadOtuCommand::ReadOtuCommand(string option){ else { globaldata->setGroupFile(groupfile); groupMap = new GroupMap(groupfile); - groupMap->readMap(); + + int error = groupMap->readMap(); + if (error == 1) { abort = true; } + + globaldata->gGroupmap = groupMap; + } + + groups = validParameter.validFile(parameters, "groups", false); + if (groups == "not found") { groups = ""; } + else { + splitAtDash(groups, Groups); + globaldata->Groups = Groups; } //you are doing a list and group shared @@ -71,19 +142,11 @@ ReadOtuCommand::ReadOtuCommand(string option){ //you have not given a file if ((listfile == "") && (sharedfile == "") && (rabundfile == "") && (sabundfile == "")) { - cout << "You must enter either a listfile, rabundfile, sabundfile or a sharedfile with the read.otu command. " << endl; abort = true; + m->mothurOut("You must enter either a listfile, rabundfile, sabundfile or a sharedfile with the read.otu command. "); m->mothurOutEndLine(); abort = true; } //check for optional parameter and set defaults // ...at some point should added some additional type checking... - line = validParameter.validFile(parameters, "line", false); - if (line == "not found") { line = ""; } - else { - if(line != "all") { splitAtDash(line, lines); allLines = 0; } - else { allLines = 1; } - globaldata->lines = lines; - } - label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { @@ -93,31 +156,22 @@ ReadOtuCommand::ReadOtuCommand(string option){ } globaldata->allLines = allLines; - - //make sure user did not use both the line and label parameters - if ((line != "") && (label != "")) { cout << "You cannot use both the line and label parameters at the same time. " << endl; abort = true; } - + 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; - //read = new ReadOTUFile(filename); } - } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ReadOtuCommand class Function ReadOtuCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ReadOtuCommand class function ReadOtuCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "ReadOtuCommand", "ReadOtuCommand"); exit(1); } } @@ -125,76 +179,61 @@ ReadOtuCommand::ReadOtuCommand(string option){ void ReadOtuCommand::help(){ try { - cout << "The read.otu command must be run before you execute a collect.single, rarefaction.single, summary.single, " << "\n"; - cout << "collect.shared, rarefaction.shared or summary.shared command. Mothur will generate a .list, .rabund and .sabund upon completion of the cluster command " << "\n"; - cout << "or you may use your own. The read.otu command parameter options are list, rabund, sabund, shared, group, order, line and label." << "\n"; - cout << "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"; - cout << "For this use the read.otu command should be in the following format: read.otu(list=yourListFile, order=yourOrderFile, label=yourLabels)." << "\n"; - cout << "The list, rabund or sabund parameter is required, but you may only use one of them." << "\n"; - cout << "The line and label parameters are optional but you may not use both the line and label parameters at the same time." << "\n"; - cout << "The label and line parameters are used to read specific lines in your input." << "\n"; - cout << "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"; - cout << "In this case the read.otu command should be in the following format: read.otu(list=yourListFile, group=yourGroupFile, line=yourLines) or read.otu(shared=yourSharedFile). " << "\n"; - cout << "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"; - cout << "and separates it into groups. It outputs a .shared file containing the OTU information for each group. The read.otu command also outputs a .list file for each group. " << "\n"; - cout << "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile)." << "\n" << "\n"; + m->mothurOut("The read.otu command must be run before you execute a collect.single, rarefaction.single, summary.single, \n"); + m->mothurOut("collect.shared, rarefaction.shared or summary.shared command. Mothur will generate a .list, .rabund and .sabund upon completion of the cluster command \n"); + m->mothurOut("or you may use your own. The read.otu command parameter options are list, rabund, sabund, shared, group, order, label and groups.\n"); + m->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"); + m->mothurOut("For this use the read.otu command should be in the following format: read.otu(list=yourListFile, order=yourOrderFile, label=yourLabels).\n"); + m->mothurOut("The list, rabund or sabund parameter is required, but you may only use one of them.\n"); + m->mothurOut("The label parameter is used to read specific labels in your input.\n"); + m->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"); + m->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"); + m->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"); + m->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"); + m->mothurOut("You can use the groups parameter to choose only specific groups to be used in the .shared and .rabund files. \n"); + m->mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n"); } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ReadOtuCommand class Function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "ReadOtuCommand", "help"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the ReadOtuCommand class function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } //********************************************************************************************************************** - -ReadOtuCommand::~ReadOtuCommand(){ - if (abort == false) { //delete read; - } -} - +ReadOtuCommand::~ReadOtuCommand(){} //********************************************************************************************************************** int ReadOtuCommand::execute(){ try { if (abort == true) { return 0; } - - //read->read(&*globaldata); + if (globaldata->getFormat() == "shared") { - groupMap->readMap(); - - //if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; } - globaldata->gGroupmap = groupMap; - parselist = new ParseListCommand(); - parselist->execute(); - delete parselist; + shared = new SharedCommand(outputDir); + int okay = shared->execute(); + + //problem with shared + if (okay == 1) { + 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(); + } - shared = new SharedCommand(); - shared->execute(); delete shared; - - //change format to shared to speed up commands - globaldata->setFormat("sharedfile"); - globaldata->setListFile(""); - globaldata->setGroupFile(""); - globaldata->setSharedFile(getRootName(filename) + "shared"); } return 0; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ReadOtuCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ReadOtuCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "ReadOtuCommand", "execute"); exit(1); } }