//**********************************************************************************************************************
vector<string> SharedCommand::setParameters(){
try {
- CommandParameter pbiom("biom", "InputTypes", "", "", "BiomListGroup", "BiomListGroup", "none",false,false); parameters.push_back(pbiom);
- CommandParameter plist("list", "InputTypes", "", "", "BiomListGroup", "BiomListGroup", "ListGroup",false,false); parameters.push_back(plist);
- CommandParameter pcount("count", "InputTypes", "", "", "", "GroupCount", "",false,false); parameters.push_back(pcount);
- CommandParameter pgroup("group", "InputTypes", "", "", "none", "GroupCount", "ListGroup",false,false); parameters.push_back(pgroup);
+ CommandParameter pbiom("biom", "InputTypes", "", "", "BiomListGroup", "BiomListGroup", "none","shared",false,false); parameters.push_back(pbiom);
+ CommandParameter plist("list", "InputTypes", "", "", "BiomListGroup", "BiomListGroup", "ListGroup","shared",false,false,true); parameters.push_back(plist);
+ CommandParameter pcount("count", "InputTypes", "", "", "none", "GroupCount", "none","",false,false); parameters.push_back(pcount);
+ CommandParameter pgroup("group", "InputTypes", "", "", "none", "GroupCount", "ListGroup","",false,false,true); parameters.push_back(pgroup);
//CommandParameter pordergroup("ordergroup", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pordergroup);
- CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel);
- CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
- CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
- CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
+ CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel);
+ CommandParameter pgroups("groups", "String", "", "", "", "", "","group",false,false); parameters.push_back(pgroups);
+ CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
+ CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
vector<string> myArray;
for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
}
}
//**********************************************************************************************************************
-string SharedCommand::getOutputFileNameTag(string type, string inputName=""){
- try {
- string outputFileName = "";
- map<string, vector<string> >::iterator it;
+string SharedCommand::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 == "shared") { outputFileName = "shared"; }
- else if (type == "rabund") { outputFileName = "rabund"; }
- else if (type == "group") { outputFileName = "groups"; }
- 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, "SharedCommand", "getOutputFileNameTag");
- exit(1);
- }
+ if (type == "shared") { pattern = "[filename],shared-[filename],[distance],shared"; }
+ else if (type == "rabund") { pattern = "[filename],[group],rabund"; }
+ else if (type == "group") { pattern = "[filename],[group],groups"; }
+ else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; }
+
+ return pattern;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SharedCommand", "getOutputPattern");
+ exit(1);
+ }
}
-
//**********************************************************************************************************************
SharedCommand::SharedCommand(){
try {
try {
if (abort == true) { if (calledHelp) { return 0; } return 2; }
-
- //getting output filename
- string filename = "";
- if (listfile != "") { filename = listfile; }
- else { filename = biomfile; }
-
- if (outputDir == "") { outputDir += m->hasPath(filename); }
-
- filename = outputDir + m->getRootName(m->getSimpleName(filename));
- filename = filename + getOutputFileNameTag("shared");
- outputNames.push_back(filename); outputTypes["shared"].push_back(filename);
-
- if (listfile != "") { createSharedFromListGroup(filename); }
- else { createSharedFromBiom(filename); }
+
+ if (listfile != "") { createSharedFromListGroup(); }
+ else { createSharedFromBiom(); }
if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } }
}
}
//**********************************************************************************************************************
-int SharedCommand::createSharedFromBiom(string filename) {
+int SharedCommand::createSharedFromBiom() {
try {
+ //getting output filename
+ string filename = biomfile;
+ if (outputDir == "") { outputDir += m->hasPath(filename); }
+
+ map<string, string> variables;
+ variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename));
+ filename = getOutputFileName("shared",variables);
+ outputNames.push_back(filename); outputTypes["shared"].push_back(filename);
+
ofstream out;
m->openOutputFile(filename, out);
if (it == fileLines.end()) { m->mothurOut("[ERROR]: you file does not have a data provided.\n"); }
else {
string thisLine = it->second;
- m->currentBinLabels = otuNames;
+ m->currentSharedBinLabels = otuNames;
//read data
vector<SharedRAbundVector*> lookup = readData(matrixFormat, thisLine, matrixElementType, groupNames, otuNames.size());
for (int h = 0; h < diff; h++) { binLabel += "0"; }
}
binLabel += sbinNumber;
- if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+ if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; }
newBinLabels.push_back(binLabel);
}
for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; }
thislookup = newLookup;
- m->currentBinLabels = newBinLabels;
+ m->currentSharedBinLabels = newBinLabels;
return 0;
}
}
//**********************************************************************************************************************
-int SharedCommand::createSharedFromListGroup(string filename) {
+int SharedCommand::createSharedFromListGroup() {
try {
- ofstream out;
- m->openOutputFile(filename, out);
GroupMap* groupMap = NULL;
CountTable* countTable = NULL;
m->setAllGroups(allGroups);
}else{
countTable = new CountTable();
- countTable->readTable(countfile);
+ countTable->readTable(countfile, true, false);
}
if (m->control_pressed) { return 0; }
m->setGroups(Groups);
}else { pickedGroups = true; }
+
+ ofstream out;
+ string filename = "";
+ if (!pickedGroups) {
+ string filename = listfile;
+ if (outputDir == "") { outputDir += m->hasPath(filename); }
+
+ map<string, string> variables;
+ variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename));
+ filename = getOutputFileName("shared",variables);
+ outputNames.push_back(filename); outputTypes["shared"].push_back(filename);
+ m->openOutputFile(filename, out);
+ }
+
//fill filehandles with neccessary ofstreams
int i;
ofstream* temp;
//set fileroot
fileroot = outputDir + m->getRootName(m->getSimpleName(listfile));
-
+ map<string, string> variables;
+ variables["[filename]"] = fileroot;
//clears file before we start to write to it below
for (int i=0; i<Groups.size(); i++) {
- m->mothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund")));
- outputNames.push_back((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund")));
- outputTypes["rabund"].push_back((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund")));
+ variables["[group]"] = Groups[i];
+ string rabundFIleName = getOutputFileName("rabund",variables);
+ m->mothurRemove(rabundFIleName);
+ outputNames.push_back(rabundFIleName);
+ outputTypes["rabund"].push_back(rabundFIleName);
}
string errorOff = "no error";
if (m->control_pressed) {
delete SharedList; if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; }
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
- out.close(); m->mothurRemove(filename);
- for (int i=0; i<Groups.size(); i++) { m->mothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); }
+ out.close(); if (!pickedGroups) { m->mothurRemove(filename); }
+ for (int i=0; i<Groups.size(); i++) { variables["[group]"] = Groups[i];
+ string rabundFIleName = getOutputFileName("rabund",variables);
+ m->mothurRemove(rabundFIleName); }
return 0;
}
if ((!pickedGroups) && (SharedList->getNumSeqs() != numGroupNames)) { //if the user has not specified any groups and their files don't match exit with error
m->mothurOut("Your group file contains " + toString(numGroupNames) + " sequences and list file contains " + toString(SharedList->getNumSeqs()) + " sequences. Please correct."); m->mothurOutEndLine(); m->control_pressed = true;
- out.close(); m->mothurRemove(filename); //remove blank shared file you made
+ out.close(); if (!pickedGroups) { m->mothurRemove(filename); } //remove blank shared file you made
//delete memory
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
if ((pickedGroups) && (m->groupMode == "group")) { //make new group file
string groups = "";
if (m->getNumGroups() < 4) {
- for (int i = 0; i < m->getNumGroups(); i++) {
+ for (int i = 0; i < m->getNumGroups()-1; i++) {
groups += (m->getGroups())[i] + ".";
}
+ groups+=(m->getGroups())[m->getNumGroups()-1];
}else { groups = "merge"; }
-
- string newGroupFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + groups + getOutputFileNameTag("group");
+ map<string, string> variables;
+ variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile));
+ variables["[group]"] = groups;
+ string newGroupFile = getOutputFileName("group",variables);
outputTypes["group"].push_back(newGroupFile);
outputNames.push_back(newGroupFile);
ofstream outGroups;
if (m->control_pressed) {
delete SharedList; if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; }
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
- out.close(); m->mothurRemove(filename);
- for (int i=0; i<Groups.size(); i++) { m->mothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); }
+ if (!pickedGroups) { out.close(); m->mothurRemove(filename); }
+ for (int i=0; i<Groups.size(); i++) { variables["[group]"] = Groups[i];
+ string rabundFIleName = getOutputFileName("rabund",variables);
+ m->mothurRemove(rabundFIleName); }
return 0;
}
lookup = SharedList->getSharedRAbundVector();
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
- if (pickedGroups) { //check for otus with no seqs in them
- eliminateZeroOTUS(lookup);
- }
if (m->control_pressed) {
delete SharedList; if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; }
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
- out.close(); m->mothurRemove(filename);
- for (int i=0; i<Groups.size(); i++) { m->mothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); }
+ if (!pickedGroups) { out.close(); m->mothurRemove(filename); }
+ for (int i=0; i<Groups.size(); i++) { variables["[group]"] = Groups[i];
+ string rabundFIleName = getOutputFileName("rabund",variables);
+ m->mothurRemove(rabundFIleName); }
return 0;
}
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
- printSharedData(lookup, out); //prints info to the .shared file
+ //if picked groups must split the shared file by label
+ if (pickedGroups) {
+ string filename = listfile;
+ if (outputDir == "") { outputDir += m->hasPath(filename); }
+
+ map<string, string> variables;
+ variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename));
+ variables["[distance]"] = lookup[0]->getLabel();
+ filename = getOutputFileName("shared",variables);
+ outputNames.push_back(filename); outputTypes["shared"].push_back(filename);
+ ofstream out2;
+ m->openOutputFile(filename, out2);
+
+ vector<string> savedLabels = m->currentSharedBinLabels;
+ eliminateZeroOTUS(lookup);
+ lookup[0]->printHeaders(out2);
+ printSharedData(lookup, out2);
+ out2.close();
+ m->currentSharedBinLabels = savedLabels; //restore old labels
+
+ }else {
+ if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); }
+ printSharedData(lookup, out); //prints info to the .shared file
+ }
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
processedLabels.insert(SharedList->getLabel());
lookup = SharedList->getSharedRAbundVector();
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
- if (pickedGroups) { //check for otus with no seqs in them
- eliminateZeroOTUS(lookup);
- }
-
if (m->control_pressed) {
delete SharedList; if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; }
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
- out.close(); m->mothurRemove(filename);
- for (int i=0; i<Groups.size(); i++) { m->mothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); }
+ if (!pickedGroups) { out.close(); m->mothurRemove(filename); }
+ for (int i=0; i<Groups.size(); i++) { variables["[group]"] = Groups[i];
+ string rabundFIleName = getOutputFileName("rabund",variables);
+ m->mothurRemove(rabundFIleName); }
return 0;
}
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
- printSharedData(lookup, out); //prints info to the .shared file
+ //if picked groups must split the shared file by label
+ if (pickedGroups) {
+ string filename = listfile;
+ if (outputDir == "") { outputDir += m->hasPath(filename); }
+
+ map<string, string> variables;
+ variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename));
+ variables["[distance]"] = lookup[0]->getLabel();
+ filename = getOutputFileName("shared",variables);
+ outputNames.push_back(filename); outputTypes["shared"].push_back(filename);
+ ofstream out2;
+ m->openOutputFile(filename, out2);
+
+ vector<string> savedLabels = m->currentSharedBinLabels;
+ eliminateZeroOTUS(lookup);
+ lookup[0]->printHeaders(out2);
+ printSharedData(lookup, out2);
+ out2.close();
+ m->currentSharedBinLabels = savedLabels; //restore old labels
+
+ }else {
+ if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); }
+ printSharedData(lookup, out); //prints info to the .shared file
+ }
+
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
processedLabels.insert(SharedList->getLabel());
lookup = SharedList->getSharedRAbundVector();
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
- if (pickedGroups) { //check for otus with no seqs in them
- eliminateZeroOTUS(lookup);
- }
if (m->control_pressed) {
if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; }
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
- out.close(); m->mothurRemove(filename);
- for (int i=0; i<Groups.size(); i++) { m->mothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); }
+ if (!pickedGroups) { out.close(); m->mothurRemove(filename); }
+ for (int i=0; i<Groups.size(); i++) { variables["[group]"] = Groups[i];
+ string rabundFIleName = getOutputFileName("rabund",variables);
+ m->mothurRemove(rabundFIleName); }
return 0;
}
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
- printSharedData(lookup, out); //prints info to the .shared file
+ //if picked groups must split the shared file by label
+ if (pickedGroups) {
+ string filename = listfile;
+ if (outputDir == "") { outputDir += m->hasPath(filename); }
+
+ map<string, string> variables;
+ variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename));
+ variables["[distance]"] = lookup[0]->getLabel();
+ filename = getOutputFileName("shared",variables);
+ outputNames.push_back(filename); outputTypes["shared"].push_back(filename);
+ ofstream out2;
+ m->openOutputFile(filename, out2);
+
+ vector<string> savedLabels = m->currentSharedBinLabels;
+ eliminateZeroOTUS(lookup);
+ lookup[0]->printHeaders(out2);
+ printSharedData(lookup, out2);
+ out2.close();
+ m->currentSharedBinLabels = savedLabels; //restore old labels
+
+ }else {
+ if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); }
+ printSharedData(lookup, out); //prints info to the .shared file
+ }
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
delete SharedList;
}
- out.close();
+ if (!pickedGroups) { out.close(); }
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
delete it3->second;
if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; }
if (m->control_pressed) {
- m->mothurRemove(filename);
- for (int i=0; i<Groups.size(); i++) { m->mothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); }
+ if (!pickedGroups) { m->mothurRemove(filename); }
+ for (int i=0; i<Groups.size(); i++) { variables["[group]"] = Groups[i];
+ string rabundFIleName = getOutputFileName("rabund",variables);
+ m->mothurRemove(rabundFIleName); }
return 0;
}
Groups.push_back(thislookup[i]->getGroup());
RAbundVector rav = thislookup[i]->getRAbundVector();
- m->openOutputFileAppend(fileroot + thislookup[i]->getGroup() + "." + getOutputFileNameTag("rabund"), *(filehandles[thislookup[i]->getGroup()]));
+ map<string, string> variables;
+ variables["[filename]"] = fileroot;
+ variables["[group]"] = thislookup[i]->getGroup();
+ m->openOutputFileAppend(getOutputFileName("rabund",variables), *(filehandles[thislookup[i]->getGroup()]));
rav.print(*(filehandles[thislookup[i]->getGroup()]));
(*(filehandles[thislookup[i]->getGroup()])).close();
}
Groups.push_back((myIt->second)->getGroup());
RAbundVector rav = (myIt->second)->getRAbundVector();
- m->openOutputFileAppend(fileroot + (myIt->second)->getGroup() + "." + getOutputFileNameTag("rabund"), *(filehandles[(myIt->second)->getGroup()]));
+ map<string, string> variables;
+ variables["[filename]"] = fileroot;
+ variables["[group]"] = (myIt->second)->getGroup();
+ m->openOutputFileAppend(getOutputFileName("rabund",variables), *(filehandles[(myIt->second)->getGroup()]));
rav.print(*(filehandles[(myIt->second)->getGroup()]));
(*(filehandles[(myIt->second)->getGroup()])).close();
}else{