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) {
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; }
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 hte user has not specified any groups then use them all
if (Groups.size() == 0) {
- Groups = groupMap->namesOfGroups; m->Groups = Groups;
+ Groups = groupMap->getNamesOfGroups(); m->setGroups(Groups);
}else { pickedGroups = true; }
//fill filehandles with neccessary ofstreams
//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());
+ m->mothurRemove((fileroot + Groups[i] + ".rabund"));
outputNames.push_back((fileroot + Groups[i] + ".rabund"));
outputTypes["rabund"].push_back((fileroot + Groups[i] + ".rabund"));
}
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 (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 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;
}
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->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;
}
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 (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; }
}
m->openOutputFile(outputMisMatchName, outMisMatch);
- map<string, string> listNames;
- map<string, string>::iterator itList;
+ set<string> listNames;
+ set<string>::iterator itList;
//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);
- while (names.find_first_of(',') != -1) {
- string name = names.substr(0,names.find_first_of(','));
- names = names.substr(names.find_first_of(',')+1, names.length());
+ vector<string> binNames;
+ m->splitAtComma(names, binNames);
+
+ for (int j = 0; j < binNames.size(); j++) {
+ string name = binNames[j];
string group = groupMap->getGroup(name);
if(group == "not found") { outMisMatch << name << endl; }
itList = listNames.find(name);
if (itList != listNames.end()) { m->mothurOut(name + " is in your list file more than once. Sequence names must be unique. please correct."); m->mothurOutEndLine(); }
- else { listNames[name] = name; }
+ else { listNames.insert(name); }
}
-
- //get last name
- string group = groupMap->getGroup(names);
- if(group == "not found") { outMisMatch << names << endl; }
-
- itList = listNames.find(names);
- if (itList != listNames.end()) { m->mothurOut(names + " is in your list file more than once. Sequence names must be unique. please correct."); m->mothurOutEndLine(); }
- else { listNames[names] = names; }
-
}
outMisMatch.close();
string names = SharedList->get(i);
- while (names.find_first_of(',') != -1) {
- string name = names.substr(0,names.find_first_of(','));
- names = names.substr(names.find_first_of(',')+1, names.length());
+ vector<string> binNames;
+ m->splitAtComma(names, binNames);
+
+ for (int j = 0; j < binNames.size(); j++) {
+
+ string name = binNames[j];
itList = namesInList.find(name);
if (itList != namesInList.end()) { m->mothurOut(name + " is in your list file more than once. Sequence names must be unique. please correct."); m->mothurOutEndLine(); }
namesInList[name] = name;
}
-
- itList = namesInList.find(names);
- if (itList != namesInList.end()) { m->mothurOut(names + " is in your list file more than once. Sequence names must be unique. please correct."); m->mothurOutEndLine(); }
-
- //get last name
- namesInList[names] = names;
}
//get names of sequences in groupfile
//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(){