exit(1);
}
}
+/***********************************************************************/
+int MothurOut::openOutputFileBinaryAppend(string fileName, ofstream& fileHandle){
+ try {
+ fileName = getFullPathName(fileName);
+
+ fileHandle.open(fileName.c_str(), ios::app | ios::binary);
+ if(!fileHandle) {
+ mothurOut("[ERROR]: Could not open " + fileName); mothurOutEndLine();
+ return 1;
+ }
+ else {
+ return 0;
+ }
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "openOutputFileAppend");
+ exit(1);
+ }
+}
+
/***********************************************************************/
void MothurOut::gobble(istream& f){
try {
}
}
+//**********************************************************************************************************************
+
+map<string, vector<string> > MothurOut::parseClasses(string classes){
+ try {
+ map<string, vector<string> > parts;
+
+ //treatment<Early|Late>-age<young|old>
+ vector<string> pieces; splitAtDash(classes, pieces); // -> treatment<Early|Late>, age<young|old>
+
+ for (int i = 0; i < pieces.size(); i++) {
+ string category = ""; string value = "";
+ bool foundOpen = false;
+ for (int j = 0; j < pieces[i].length(); j++) {
+ if (control_pressed) { return parts; }
+
+ if (pieces[i][j] == '<') { foundOpen = true; }
+ else if (pieces[i][j] == '>') { j += pieces[i].length(); }
+ else {
+ if (!foundOpen) { category += pieces[i][j]; }
+ else { value += pieces[i][j]; }
+ }
+ }
+ vector<string> values; splitAtChar(value, values, '|');
+ parts[category] = values;
+ }
+
+ return parts;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "parseClasses");
+ exit(1);
+ }
+}
/***********************************************************************/
string MothurOut::hasPath(string longName){
}
}
+/***********************************************************************/
+int MothurOut::openOutputFileBinary(string fileName, ofstream& fileHandle){
+ try {
+
+ string completeFileName = getFullPathName(fileName);
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+#ifdef USE_COMPRESSION
+ // check for gzipped file
+ if (endsWith(completeFileName, ".gz") || endsWith(completeFileName, ".bz2")) {
+ string tempName = string(tmpnam(0));
+ mkfifo(tempName.c_str(), 0666);
+ cerr << "Compressing " << completeFileName << " via temporary named pipe " << tempName << "\n";
+ int fork_result = fork();
+ if (fork_result < 0) {
+ cerr << "Error forking.\n";
+ exit(1);
+ } else if (fork_result == 0) {
+ string command = string(endsWith(completeFileName, ".gz") ? "gzip" : "bzip2") + " -v > " + completeFileName + string(" < ") + tempName;
+ system(command.c_str());
+ exit(0);
+ } else {
+ completeFileName = tempName;
+ }
+ }
+#endif
+#endif
+ fileHandle.open(completeFileName.c_str(), ios::trunc | ios::binary);
+ if(!fileHandle) {
+ mothurOut("[ERROR]: Could not open " + completeFileName); mothurOutEndLine();
+ return 1;
+ }
+ else {
+ return 0;
+ }
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "openOutputFileBinary");
+ exit(1);
+ }
+
+}
/**************************************************************************************************/
int MothurOut::appendFiles(string temp, string filename) {
try{
exit(1);
}
}
+//**********************************************************************************************************************
+vector<consTax> MothurOut::readConsTax(string inputfile){
+ try {
+
+ vector<consTax> taxes;
+
+ ifstream in;
+ openInputFile(inputfile, in);
+
+ //read headers
+ getline(in);
+
+ while (!in.eof()) {
+
+ if (control_pressed) { break; }
+
+ string otu = ""; string tax = "unknown";
+ int size = 0;
+
+ in >> otu >> size >> tax; gobble(in);
+ consTax temp(otu, tax, size);
+ taxes.push_back(temp);
+ }
+ in.close();
+
+ return taxes;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "readConsTax");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+int MothurOut::readConsTax(string inputfile, map<string, consTax2>& taxes){
+ try {
+ ifstream in;
+ openInputFile(inputfile, in);
+
+ //read headers
+ getline(in);
+
+ while (!in.eof()) {
+
+ if (control_pressed) { break; }
+
+ string otu = ""; string tax = "unknown";
+ int size = 0;
+
+ in >> otu >> size >> tax; gobble(in);
+ consTax2 temp(tax, size);
+ taxes[otu] = temp;
+ }
+ in.close();
+
+ return 0;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "readConsTax");
+ exit(1);
+ }
+}
/**************************************************************************************************/
vector<unsigned long long> MothurOut::setFilePosEachLine(string filename, int& num) {
try {
bool pairDone = false;
bool columnOne = true;
string firstCol, secondCol;
+ bool error = false;
while (!in.eof()) {
if (control_pressed) { break; }
if (!ignore) { taxMap[firstCol] = secondCol; }
if (debug) { mothurOut("[DEBUG]: name = '" + firstCol + "' tax = '" + secondCol + "'\n"); }
}else {
- mothurOut("[ERROR]: " + firstCol + " is already in your taxonomy file, names must be unique./n"); control_pressed = true;
+ mothurOut("[ERROR]: " + firstCol + " is already in your taxonomy file, names must be unique.\n"); error = true;
}
pairDone = false;
}
if (!ignore) { taxMap[firstCol] = secondCol; }
if (debug) { mothurOut("[DEBUG]: name = '" + firstCol + "' tax = '" + secondCol + "'\n"); }
}else {
- mothurOut("[ERROR]: " + firstCol + " is already in your taxonomy file, names must be unique./n"); control_pressed = true;
+ mothurOut("[ERROR]: " + firstCol + " is already in your taxonomy file, names must be unique./n"); error = true;
}
pairDone = false;
}
}
+ if (error) { control_pressed = true; }
+ if (debug) { mothurOut("[DEBUG]: numSeqs saved = '" + toString(taxMap.size()) + "'\n"); }
return taxMap.size();
}
in.read(buffer, 4096);
vector<string> pieces = splitWhiteSpace(rest, buffer, in.gcount());
- for (int i = 0; i < pieces.size(); i++) { checkName(pieces[i]); names.insert(pieces[i]); }
+ for (int i = 0; i < pieces.size(); i++) { checkName(pieces[i]);
+ names.insert(pieces[i]);
+ }
}
in.close();