}
}
//**********************************************************************************************************************
+string ClassifyOtuCommand::getOutputFileNameTag(string type, string inputName=""){
+ try {
+ string outputFileName = "";
+ map<string, vector<string> >::iterator it;
+
+ //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 == "constaxonomy") { outputFileName = "cons.taxonomy"; }
+ else if (type == "taxsummary") { outputFileName = "cons.tax.summary"; }
+ 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, "ClassifyOtuCommand", "getOutputFileNameTag");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
ClassifyOtuCommand::ClassifyOtuCommand(){
try {
abort = true; calledHelp = true;
else if (refTaxonomy == "not open") { abort = true; }
namefile = validParameter.validFile(parameters, "name", true);
- if (namefile == "not open") { abort = true; }
+ if (namefile == "not open") { namefile = ""; abort = true; }
else if (namefile == "not found") { namefile = ""; }
else { m->setNameFile(namefile); }
if ((cutoff < 51) || (cutoff > 100)) { m->mothurOut("cutoff must be above 50, and no greater than 100."); m->mothurOutEndLine(); abort = true; }
+ if (namefile == ""){
+ vector<string> files; files.push_back(taxfile);
+ parser.getNameFile(files);
+ }
+
}
}
catch(exception& e) {
if (abort == true) { if (calledHelp) { return 0; } return 2; }
//if user gave a namesfile then use it
- if (namefile != "") { readNamesFile(); }
+ if (namefile != "") { m->readNames(namefile, nameMap, true); }
//read taxonomy file and save in map for easy access in building bin trees
- readTaxonomyFile();
+ m->readTax(taxfile, taxMap);
if (m->control_pressed) { return 0; }
exit(1);
}
}
-
-//**********************************************************************************************************************
-int ClassifyOtuCommand::readNamesFile() {
- try {
-
- ifstream inNames;
- m->openInputFile(namefile, inNames);
-
- string name, names;
-
- while(!inNames.eof()){
- inNames >> name; //read from first column A
- inNames >> names; //read from second column A,B,C,D
- m->gobble(inNames);
-
- //parse names into vector
- vector<string> theseNames;
- m->splitAtComma(names, theseNames);
-
- for (int i = 0; i < theseNames.size(); i++) { nameMap[theseNames[i]] = name; }
-
- if (m->control_pressed) { inNames.close(); nameMap.clear(); return 0; }
- }
- inNames.close();
-
- return 0;
- }
- catch(exception& e) {
- m->errorOut(e, "ClassifyOtuCommand", "readNamesFile");
- exit(1);
- }
-}
-//**********************************************************************************************************************
-int ClassifyOtuCommand::readTaxonomyFile() {
- try {
-
- ifstream in;
- m->openInputFile(taxfile, in);
-
- string name, tax;
-
- while(!in.eof()){
- in >> name >> tax;
- m->gobble(in);
-
- //are there confidence scores, if so remove them
- if (tax.find_first_of('(') != -1) { m->removeConfidences(tax); }
-
- taxMap[name] = tax;
-
- if (m->control_pressed) { in.close(); taxMap.clear(); return 0; }
- }
- in.close();
-
- return 0;
- }
- catch(exception& e) {
- m->errorOut(e, "ClassifyOtuCommand", "readTaxonomyFile");
- exit(1);
- }
-}
//**********************************************************************************************************************
vector<string> ClassifyOtuCommand::findConsensusTaxonomy(int bin, ListVector* thisList, int& size, string& conTax) {
try{
}
}
+
+ //phylotree adds an extra unknown so we want to remove that
+ if (bestChild.name == "unknown") { bestChildSize--; }
//is this taxonomy above cutoff
int consensusConfidence = ceil((bestChildSize / (float) size) * 100);
if (outputDir == "") { outputDir += m->hasPath(listfile); }
ofstream out;
- string outputFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + ".cons.taxonomy";
+ string outputFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + getOutputFileNameTag("constaxonomy");
m->openOutputFile(outputFile, out);
outputNames.push_back(outputFile); outputTypes["constaxonomy"].push_back(outputFile);
ofstream outSum;
- string outputSumFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + ".cons.tax.summary";
+ string outputSumFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + getOutputFileNameTag("taxsummary");
m->openOutputFile(outputSumFile, outSum);
outputNames.push_back(outputSumFile); outputTypes["taxsummary"].push_back(outputSumFile);
taxaSum = new PhyloSummary(groupfile);
}
+
//for each bin in the list vector
+ string snumBins = toString(processList->getNumBins());
for (int i = 0; i < processList->getNumBins(); i++) {
if (m->control_pressed) { break; }
if (m->control_pressed) { out.close(); return 0; }
//output to new names file
- out << (i+1) << '\t' << size << '\t' << conTax << endl;
+ string binLabel = "Otu";
+ string sbinNumber = toString(i+1);
+ if (sbinNumber.length() < snumBins.length()) {
+ int diff = snumBins.length() - sbinNumber.length();
+ for (int h = 0; h < diff; h++) { binLabel += "0"; }
+ }
+ binLabel += sbinNumber;
+
+ out << binLabel << '\t' << size << '\t' << conTax << endl;
string noConfidenceConTax = conTax;
m->removeConfidences(noConfidenceConTax);