else if (type == "name") { pattern = "[filename],subsample,[extension]"; }
else if (type == "group") { pattern = "[filename],subsample,[extension]"; }
else if (type == "count") { pattern = "[filename],subsample,[extension]"; }
- else if (type == "list") { pattern = "[filename],subsample,[extension]"; }
+ else if (type == "list") { pattern = "[filename],[distance],subsample,[extension]"; }
else if (type == "taxonomy") { pattern = "[filename],subsample,[extension]"; }
else if (type == "shared") { pattern = "[filename],[distance],subsample,[extension]"; }
else if (type == "rabund") { pattern = "[filename],subsample,[extension]"; }
else if (countfile == "not found") { countfile = ""; }
else {
m->setCountTableFile(countfile);
- ct.readTable(countfile);
+ ct.readTable(countfile, true, false);
}
if ((namefile != "") && (countfile != "")) {
else{
itGroupCounts = groupCounts.find(group);
if (itGroupCounts != groupCounts.end()) {
- if (groupCounts[group] < size) { subset.insert(names[j]); groupCounts[group]++; }
+ if (itGroupCounts->second < size) { subset.insert(names[j]); (itGroupCounts->second)++; }
}
}
}
try {
//save mothurOut's binLabels to restore for next label
- vector<string> saveBinLabels = m->currentBinLabels;
+ vector<string> saveBinLabels = m->currentSharedBinLabels;
string thisOutputDir = outputDir;
if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); }
m->openOutputFile(outputFileName, out);
outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName);
- m->currentBinLabels = subsampledLabels;
+ m->currentSharedBinLabels = subsampledLabels;
thislookup[0]->printHeaders(out);
//save mothurOut's binLabels to restore for next label
- m->currentBinLabels = saveBinLabels;
+ m->currentSharedBinLabels = saveBinLabels;
return 0;
if (namefile != "") { m->readNames(namefile, nameMap); }
- string thisOutputDir = outputDir;
- if (outputDir == "") { thisOutputDir += m->hasPath(listfile); }
- map<string, string> variables;
- variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile));
- variables["[extension]"] = m->getExtension(listfile);
- string outputFileName = getOutputFileName("list", variables);
- ofstream out;
- m->openOutputFile(outputFileName, out);
- outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
-
InputData* input = new InputData(listfile, "list");
ListVector* list = input->getListVector();
string lastLabel = list->getLabel();
- //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
set<string> processedLabels;
set<string> userLabels = labels;
//file mismatch quit
if (list->getNumSeqs() != groupMap.getNumSeqs()) {
m->mothurOut("[ERROR]: your list file contains " + toString(list->getNumSeqs()) + " sequences, and your groupfile contains " + toString(groupMap.getNumSeqs()) + ", please correct.");
- m->mothurOutEndLine(); delete list; delete input; out.close(); outGroup.close(); return 0;
+ m->mothurOutEndLine(); delete list; delete input; outGroup.close(); return 0;
}
}else if (countfile != "") {
if (ct.hasGroupInfo()) {
//as long as you are not at the end of the file or done wih the lines you want
while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
- if (m->control_pressed) { delete list; delete input; out.close(); return 0; }
+ if (m->control_pressed) { delete list; delete input; return 0; }
if(allLines == 1 || labels.count(list->getLabel()) == 1){
m->mothurOut(list->getLabel()); m->mothurOutEndLine();
- processList(list, out, subset);
+ processList(list, subset);
processedLabels.insert(list->getLabel());
userLabels.erase(list->getLabel());
list = input->getListVector(lastLabel);
m->mothurOut(list->getLabel()); m->mothurOutEndLine();
- processList(list, out, subset);
+ processList(list, subset);
processedLabels.insert(list->getLabel());
userLabels.erase(list->getLabel());
}
- if (m->control_pressed) { if (list != NULL) { delete list; } delete input; out.close(); return 0; }
+ if (m->control_pressed) { if (list != NULL) { delete list; } delete input; return 0; }
//output error messages about any remaining user labels
set<string>::iterator it;
m->mothurOut(list->getLabel()); m->mothurOutEndLine();
- processList(list, out, subset);
+ processList(list, subset);
delete list; list = NULL;
}
- out.close();
if (list != NULL) { delete list; }
delete input;
if (taxonomyfile != "") {
if (namefile == "") {
- //fake nameMap
- for (set<string>::iterator it = subset.begin(); it != subset.end(); it++) {
- vector<string> temp; temp.push_back(*it);
- nameMap[*it] = temp;
+ InputData input(listfile, "list");
+ ListVector* list = input.getListVector();
+ string lastLabel = list->getLabel();
+
+ for (int i = 0; i < list->getNumBins(); i++) {
+ vector<string> temp;
+ string bin = list->get(i);
+ m->splitAtComma(bin, temp);
+ for (int j = 0; j < temp.size(); j++) { vector<string> tempFakeOut; tempFakeOut.push_back(temp[j]); nameMap[temp[j]] = tempFakeOut; }
}
+ delete list;
+
int tcount = getTax(subset);
if (tcount != subset.size()) { m->mothurOut("[ERROR]: subsampled list file contains " + toString(subset.size()) + " sequences, but I only found " + toString(tcount) + " in your taxonomy file, did you forget a name file? Please correct."); m->mothurOutEndLine(); }
}else {
}
}
//**********************************************************************************************************************
-int SubSampleCommand::processList(ListVector*& list, ofstream& out, set<string>& subset) {
+int SubSampleCommand::processList(ListVector*& list, set<string>& subset) {
try {
-
+ string thisOutputDir = outputDir;
+ if (outputDir == "") { thisOutputDir += m->hasPath(listfile); }
+ map<string, string> variables;
+ variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile));
+ variables["[extension]"] = m->getExtension(listfile);
+ variables["[distance]"] = list->getLabel();
+ string outputFileName = getOutputFileName("list", variables);
+ ofstream out;
+ m->openOutputFile(outputFileName, out);
+ outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
+
int numBins = list->getNumBins();
ListVector* temp = new ListVector();
temp->setLabel(list->getLabel());
+ vector<string> binLabels = list->getLabels();
+ vector<string> newLabels;
for (int i = 0; i < numBins; i++) {
if (m->control_pressed) { break; }
if (newNames != "") {
newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
temp->push_back(newNames);
+ newLabels.push_back(binLabels[i]);
}
}
+ temp->setLabels(newLabels);
delete list;
list = temp;
- if (m->control_pressed) { return 0; }
+ if (m->control_pressed) { out.close(); return 0; }
+ list->printHeaders(out);
list->print(out);
+ out.close();
return 0;