#include "getsharedotucommand.h"
-//**********************************************************************************************************************
+//**********************************************************************************************************************
+vector<string> GetSharedOTUCommand::getValidParameters(){
+ try {
+ string Array[] = {"label","unique","shared","fasta","list","group","output","outputdir","inputdir"};
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetSharedOTUCommand", "getValidParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+GetSharedOTUCommand::GetSharedOTUCommand(){
+ try {
+ abort = true; calledHelp = true;
+ vector<string> tempOutNames;
+ outputTypes["fasta"] = tempOutNames;
+ outputTypes["accnos"] = tempOutNames;
+ outputTypes["sharedseqs"] = tempOutNames;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetSharedOTUCommand", "GetSharedOTUCommand");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> GetSharedOTUCommand::getRequiredParameters(){
+ try {
+ string Array[] = {"list","group"};
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetSharedOTUCommand", "getRequiredParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> GetSharedOTUCommand::getRequiredFiles(){
+ try {
+ vector<string> myArray;
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetSharedOTUCommand", "getRequiredFiles");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
GetSharedOTUCommand::GetSharedOTUCommand(string option) {
try {
globaldata = GlobalData::getInstance();
- abort = false;
+ abort = false; calledHelp = false;
unique = true;
allLines = 1;
labels.clear();
//allow user to run help
- if(option == "help") { help(); abort = true; }
+ if(option == "help") { help(); abort = true; calledHelp = true; }
else {
//valid paramters for this command
if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
+ //initialize outputTypes
+ vector<string> tempOutNames;
+ outputTypes["fasta"] = tempOutNames;
+ outputTypes["accnos"] = tempOutNames;
+ outputTypes["sharedseqs"] = tempOutNames;
+
//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 = ""; }
m->mothurOut("The output parameter allows you to output the list of names without the group and bin number added. \n");
m->mothurOut("With this option you can use the names file as an input in get.seqs and remove.seqs commands. To do this enter output=accnos. \n");
m->mothurOut("The get.sharedseqs command outputs a .names file for each distance level containing a list of sequences in the OTUs shared by the groups specified.\n");
- m->mothurOut("The get.sharedseqs command should be in the following format: get.sabund(label=yourLabels, groups=yourGroups, fasta=yourFastafile, output=yourOutput).\n");
+ m->mothurOut("The get.sharedseqs command should be in the following format: get.sharedseqs(label=yourLabels, groups=yourGroups, fasta=yourFastafile, output=yourOutput).\n");
m->mothurOut("Example get.sharedseqs(list=amazon.fn.list, label=unique-0.01, group=forest-pasture, fasta=amazon.fasta, output=accnos).\n");
m->mothurOut("The output to the screen is the distance and the number of otus at that distance for the groups you specified.\n");
m->mothurOut("The default value for label is all labels in your inputfile. The default for groups is all groups in your file.\n");
int GetSharedOTUCommand::execute(){
try {
- if (abort == true) { return 0; }
+ if (abort == true) { if (calledHelp) { return 0; } return 2; }
groupMap = new GroupMap(groupfile);
int error = groupMap->readMap();
m->openInputFile(fastafile, inFasta);
while(!inFasta.eof()) {
- if (m->control_pressed) { inFasta.close(); delete groupMap; return 0; }
+ if (m->control_pressed) { outputTypes.clear(); inFasta.close(); delete groupMap; return 0; }
Sequence seq(inFasta); m->gobble(inFasta);
if (seq.getName() != "") { seqs.push_back(seq); }
if (m->control_pressed) {
if (lastlist != NULL) { delete lastlist; }
- for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear();
delete groupMap; return 0;
}
if (lastlist != NULL) { delete lastlist; }
- if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete groupMap; return 0; }
+ if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete groupMap; return 0; }
+
+ //set fasta file as new current fastafile
+ string current = "";
+ itTypes = outputTypes.find("fasta");
+ if (itTypes != outputTypes.end()) {
+ if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
+ }
+
+ if (output == "accnos") {
+ itTypes = outputTypes.find("accnos");
+ if (itTypes != outputTypes.end()) {
+ if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setAccnosFile(current); }
+ }
+ }
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
}else {
m->mothurOut("\t" + toString(num)); m->mothurOutEndLine();
outputNames.push_back(outputFileNames);
+ if (output != "accnos") { outputTypes["sharedseqs"].push_back(outputFileNames); }
+ else { outputTypes["accnos"].push_back(outputFileNames); }
}
//if fasta file provided output new fasta file
string outputFileFasta = outputDir + m->getRootName(m->getSimpleName(fastafile)) + shared->getLabel() + userGroups + ".shared.fasta";
ofstream outFasta;
m->openOutputFile(outputFileFasta, outFasta);
- outputNames.push_back(outputFileFasta);
+ outputNames.push_back(outputFileFasta); outputTypes["fasta"].push_back(outputFileFasta);
for (int k = 0; k < seqs.size(); k++) {
if (m->control_pressed) { outFasta.close(); return 0; }