try {
CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist);
CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pgroup);
- CommandParameter pordergroup("ordergroup", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pordergroup);
+ //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);
helpString += "The make.shared command parameters are list, group, ordergroup, groups and label. list and group are required unless a current file is available.\n";
helpString += "The groups parameter allows you to indicate which groups you want to include, group names should be separated by dashes. ex. groups=A-B-C. Default is all groups in your groupfile.\n";
helpString += "The label parameter allows you to indicate which labels you want to include, label names should be separated by dashes. Default is all labels in your list file.\n";
- helpString += "The ordergroup parameter allows you to indicate the order of the groups in the sharedfile, by default the groups are listed alphabetically.\n";
+ //helpString += "The ordergroup parameter allows you to indicate the order of the groups in the sharedfile, by default the groups are listed alphabetically.\n";
return helpString;
}
catch(exception& e) {
vector<string> tempOutNames;
outputTypes["rabund"] = tempOutNames;
outputTypes["shared"] = tempOutNames;
+ outputTypes["group"] = tempOutNames;
}
catch(exception& e) {
m->errorOut(e, "SharedCommand", "SharedCommand");
//allow user to run help
if(option == "help") { help(); abort = true; calledHelp = true; }
+ else if(option == "citation") { citation(); abort = true; calledHelp = true;}
else {
listfile = m->getListFile();
if (listfile != "") { m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); }
else { m->mothurOut("You have no current list file and the list parameter is required."); m->mothurOutEndLine(); abort = true; }
- }
+ }else { m->setListFile(listfile); }
ordergroupfile = validParameter.validFile(parameters, "ordergroup", true);
if (ordergroupfile == "not open") { abort = true; }
else if (ordergroupfile == "not found") { ordergroupfile = ""; }
groupfile = validParameter.validFile(parameters, "group", true);
- if (groupfile == "not open") { abort = true; }
+ if (groupfile == "not open") { groupfile = ""; abort = true; }
else if (groupfile == "not found") {
groupfile = m->getGroupFile();
if (groupfile != "") {
int error = groupMap->readMap();
if (error == 1) { abort = true; }
- m->namesOfGroups = groupMap->namesOfGroups;
+ vector<string> allGroups = groupMap->getNamesOfGroups();
+ m->setAllGroups(allGroups);
}
else { m->mothurOut("You have no current group file and the group parameter is required."); m->mothurOutEndLine(); abort = true; }
}else {
int error = groupMap->readMap();
if (error == 1) { abort = true; }
- m->namesOfGroups = groupMap->namesOfGroups;
+ vector<string> allGroups = groupMap->getNamesOfGroups();
+ m->setAllGroups(allGroups);
m->setGroupFile(groupfile);
}
if (groups == "not found") { groups = ""; }
else {
m->splitAtDash(groups, Groups);
- m->Groups = Groups;
+ m->setGroups(Groups);
}
//check for optional parameter and set defaults
if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
else { allLines = 1; }
}
-
- //getting output filename
- filename = listfile;
- if (outputDir == "") { outputDir += m->hasPath(filename); }
-
- filename = outputDir + m->getRootName(m->getSimpleName(filename));
- filename = filename + "shared";
- outputTypes["shared"].push_back(filename);
-
- m->openOutputFile(filename, out);
- pickedGroups = false;
-
- //if hte user has not specified any groups then use them all
- if (Groups.size() == 0) {
- Groups = groupMap->namesOfGroups; m->Groups = Groups;
- }
-
- //fill filehandles with neccessary ofstreams
- int i;
- ofstream* temp;
- for (i=0; i<Groups.size(); i++) {
- temp = new ofstream;
- filehandles[Groups[i]] = temp;
- }
-
- //set fileroot
- fileroot = outputDir + m->getRootName(m->getSimpleName(listfile));
-
- //clears file before we start to write to it below
- for (int i=0; i<Groups.size(); i++) {
- remove((fileroot + Groups[i] + ".rabund").c_str());
- outputNames.push_back((fileroot + Groups[i] + ".rabund"));
- outputTypes["rabund"].push_back((fileroot + Groups[i] + ".rabund"));
- }
-
}
}
if (abort == true) { if (calledHelp) { return 0; } return 2; }
+ //getting output filename
+ filename = listfile;
+
+ if (outputDir == "") { outputDir += m->hasPath(filename); }
+
+ filename = outputDir + m->getRootName(m->getSimpleName(filename));
+ filename = filename + "shared";
+ outputTypes["shared"].push_back(filename);
+
+ m->openOutputFile(filename, out);
+ pickedGroups = false;
+
+ //if hte user has not specified any groups then use them all
+ if (Groups.size() == 0) {
+ Groups = groupMap->getNamesOfGroups(); m->setGroups(Groups);
+ }else { pickedGroups = true; }
+
+ //fill filehandles with neccessary ofstreams
+ int i;
+ ofstream* temp;
+ for (i=0; i<Groups.size(); i++) {
+ temp = new ofstream;
+ filehandles[Groups[i]] = temp;
+ }
+
+ //set fileroot
+ fileroot = outputDir + m->getRootName(m->getSimpleName(listfile));
+
+ //clears file before we start to write to it below
+ for (int i=0; i<Groups.size(); i++) {
+ m->mothurRemove((fileroot + Groups[i] + ".rabund"));
+ outputNames.push_back((fileroot + Groups[i] + ".rabund"));
+ outputTypes["rabund"].push_back((fileroot + Groups[i] + ".rabund"));
+ }
+
//lookup.clear();
string errorOff = "no error";
//errorOff = "";
if (m->control_pressed) {
delete input; delete SharedList; delete groupMap;
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
- out.close(); remove(filename.c_str());
- for (int i=0; i<Groups.size(); i++) { remove((fileroot + Groups[i] + ".rabund").c_str()); }
+ out.close(); m->mothurRemove(filename);
+ for (int i=0; i<Groups.size(); i++) { m->mothurRemove((fileroot + Groups[i] + ".rabund")); }
return 0;
}
-
- if ((m->Groups.size() == 0) && (SharedList->getNumSeqs() != groupMap->getNumSeqs())) { //if the user has not specified any groups and their files don't match exit with error
+
+ //sanity check
+ int error = ListGroupSameSeqs();
+
+ if ((!pickedGroups) && (SharedList->getNumSeqs() != groupMap->getNumSeqs())) { //if the user has not specified any groups and their files don't match exit with error
m->mothurOut("Your group file contains " + toString(groupMap->getNumSeqs()) + " sequences and list file contains " + toString(SharedList->getNumSeqs()) + " sequences. Please correct."); m->mothurOutEndLine();
out.close();
- remove(filename.c_str()); //remove blank shared file you made
+ m->mothurRemove(filename); //remove blank shared file you made
createMisMatchFile();
return 0;
}
+ if (error == 1) { m->control_pressed = true; }
+
//if user has specified groups make new groupfile for them
- if (m->Groups.size() != 0) { //make new group file
+ if (pickedGroups) { //make new group file
string groups = "";
- if (m->Groups.size() < 4) {
- for (int i = 0; i < m->Groups.size(); i++) {
- groups += m->Groups[i] + ".";
+ if (m->getNumGroups() < 4) {
+ for (int i = 0; i < m->getNumGroups(); i++) {
+ groups += (m->getGroups())[i] + ".";
}
}else { groups = "merge"; }
string newGroupFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + groups + "groups";
+ outputTypes["group"].push_back(newGroupFile);
+ outputNames.push_back(newGroupFile);
ofstream outGroups;
m->openOutputFile(newGroupFile, outGroups);
string groupName;
for (int i = 0; i < names.size(); i++) {
groupName = groupMap->getGroup(names[i]);
- if (isValidGroup(groupName, m->Groups)) {
+ if (isValidGroup(groupName, m->getGroups())) {
outGroups << names[i] << '\t' << groupName << endl;
}
}
if (m->control_pressed) {
delete input; delete SharedList; delete groupMap;
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
- out.close(); remove(filename.c_str());
- for (int i=0; i<Groups.size(); i++) { remove((fileroot + Groups[i] + ".rabund").c_str()); }
+ out.close(); m->mothurRemove(filename);
+ for (int i=0; i<Groups.size(); i++) { m->mothurRemove((fileroot + Groups[i] + ".rabund")); }
return 0;
}
delete input; delete SharedList; delete groupMap;
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
- out.close(); remove(filename.c_str());
- for (int i=0; i<Groups.size(); i++) { remove((fileroot + Groups[i] + ".rabund").c_str()); }
+ out.close(); m->mothurRemove(filename);
+ for (int i=0; i<Groups.size(); i++) { m->mothurRemove((fileroot + Groups[i] + ".rabund")); }
return 0;
}
+ if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
printSharedData(lookup); //prints info to the .shared file
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
delete input; delete SharedList; delete groupMap;
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
- out.close(); remove(filename.c_str());
- for (int i=0; i<Groups.size(); i++) { remove((fileroot + Groups[i] + ".rabund").c_str()); }
+ out.close(); m->mothurRemove(filename);
+ for (int i=0; i<Groups.size(); i++) { m->mothurRemove((fileroot + Groups[i] + ".rabund")); }
return 0;
}
+ if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
printSharedData(lookup); //prints info to the .shared file
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
if (m->control_pressed) {
delete input; delete groupMap;
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
- out.close(); remove(filename.c_str());
- for (int i=0; i<Groups.size(); i++) { remove((fileroot + Groups[i] + ".rabund").c_str()); }
+ out.close(); m->mothurRemove(filename);
+ for (int i=0; i<Groups.size(); i++) { m->mothurRemove((fileroot + Groups[i] + ".rabund")); }
return 0;
}
+ if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
printSharedData(lookup); //prints info to the .shared file
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
delete SharedList;
delete input; delete groupMap;
if (m->control_pressed) {
- remove(filename.c_str());
- for (int i=0; i<Groups.size(); i++) { remove((fileroot + Groups[i] + ".rabund").c_str()); }
+ m->mothurRemove(filename);
+ for (int i=0; i<Groups.size(); i++) { m->mothurRemove((fileroot + Groups[i] + ".rabund")); }
return 0;
}
if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSharedFile(current); }
}
+ itTypes = outputTypes.find("group");
+ if (itTypes != outputTypes.end()) {
+ if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setGroupFile(current); }
+ }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
if (order.size() == 0) { //user has not specified an order so do aplabetically
sort(thislookup.begin(), thislookup.end(), compareSharedRabunds);
- m->Groups.clear();
+ m->clearGroups();
+ vector<string> Groups;
//initialize bin values
for (int i = 0; i < thislookup.size(); i++) {
out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t';
thislookup[i]->print(out);
- m->Groups.push_back(thislookup[i]->getGroup());
+ Groups.push_back(thislookup[i]->getGroup());
RAbundVector rav = thislookup[i]->getRAbundVector();
m->openOutputFileAppend(fileroot + thislookup[i]->getGroup() + ".rabund", *(filehandles[thislookup[i]->getGroup()]));
rav.print(*(filehandles[thislookup[i]->getGroup()]));
(*(filehandles[thislookup[i]->getGroup()])).close();
}
+ m->setGroups(Groups);
}else{
//create a map from groupName to each sharedrabund
map<string, SharedRAbundVector*> myMap;
myMap[thislookup[i]->getGroup()] = thislookup[i];
}
- m->Groups.clear();
+ m->clearGroups();
+ vector<string> Groups;
//loop through ordered list and print the rabund
for (int i = 0; i < order.size(); i++) {
out << (myIt->second)->getLabel() << '\t' << (myIt->second)->getGroup() << '\t';
(myIt->second)->print(out);
- m->Groups.push_back((myIt->second)->getGroup());
+ Groups.push_back((myIt->second)->getGroup());
RAbundVector rav = (myIt->second)->getRAbundVector();
m->openOutputFileAppend(fileroot + (myIt->second)->getGroup() + ".rabund", *(filehandles[(myIt->second)->getGroup()]));
m->mothurOut("Can't find shared info for " + order[i] + ", skipping."); m->mothurOutEndLine();
}
}
+
+ m->setGroups(Groups);
}
for (int j = 0; j < thislookup.size(); j++) {
newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup());
}
+ //if there is a bin label use it otherwise make one
}
//else{ cout << "bin # " << i << " is all zeros" << endl; }
}
//go through list and if group returns "not found" output it
for (int i = 0; i < SharedList->getNumBins(); i++) {
- if (m->control_pressed) { outMisMatch.close(); remove(outputMisMatchName.c_str()); return 0; }
+ if (m->control_pressed) { outMisMatch.close(); m->mothurRemove(outputMisMatchName); return 0; }
string names = SharedList->get(i);
//loop through names in seqNames and if they aren't in namesIn list output them
for (int i = 0; i < seqNames.size(); i++) {
- if (m->control_pressed) { outMisMatch.close(); remove(outputMisMatchName.c_str()); return 0; }
+ if (m->control_pressed) { outMisMatch.close(); m->mothurRemove(outputMisMatchName); return 0; }
itMatch = namesInList.find(seqNames[i]);
exit(1);
}
}
-
+//**********************************************************************************************************************
+int SharedCommand::ListGroupSameSeqs() {
+ try {
+
+ int error = 0;
+
+ vector<string> groupMapsSeqs = groupMap->getNamesSeqs();
+
+ set<string> groupNamesSeqs;
+ for(int i = 0; i < groupMapsSeqs.size(); i++) {
+ groupNamesSeqs.insert(groupMapsSeqs[i]);
+ }
+
+
+ //go through list and if group returns "not found" output it
+ for (int i = 0; i < SharedList->getNumBins(); i++) {
+ if (m->control_pressed) { return 0; }
+
+ string names = SharedList->get(i);
+
+ vector<string> listNames;
+ m->splitAtComma(names, listNames);
+
+ for (int j = 0; j < listNames.size(); j++) {
+ int num = groupNamesSeqs.count(listNames[j]);
+
+ if (num == 0) { error = 1; m->mothurOut("[ERROR]: " + listNames[j] + " is in your listfile and not in your groupfile. Please correct."); m->mothurOutEndLine(); }
+ else { groupNamesSeqs.erase(listNames[j]); }
+ }
+ }
+
+ for (set<string>::iterator itGroupSet = groupNamesSeqs.begin(); itGroupSet != groupNamesSeqs.end(); itGroupSet++) {
+ error = 1;
+ m->mothurOut("[ERROR]: " + (*itGroupSet) + " is in your groupfile and not your listfile. Please correct."); m->mothurOutEndLine();
+ }
+
+ return error;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SharedCommand", "ListGroupSameSeqs");
+ exit(1);
+ }
+}
//**********************************************************************************************************************
SharedCommand::~SharedCommand(){