X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=mothurout.cpp;h=1f1c96b6f203e4f1fa8b1dca2e018c735caa6b9f;hp=fc16d204b142e5a6f55783f56bc52aafb8e6a4d1;hb=b25ede2ad307ae76f8a610443e0ec3ec69621ce7;hpb=c48d91112209b841444923670dca5454da0e2a4d diff --git a/mothurout.cpp b/mothurout.cpp index fc16d20..1f1c96b 100644 --- a/mothurout.cpp +++ b/mothurout.cpp @@ -796,6 +796,39 @@ bool MothurOut::dirCheck(string& dirName){ } } +//********************************************************************************************************************** + +map > MothurOut::parseClasses(string classes){ + try { + map > parts; + + //treatment-age + vector pieces; splitAtDash(classes, pieces); // -> treatment, age + + 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 values; splitAtChar(value, values, '|'); + parts[category] = values; + } + + return parts; + } + catch(exception& e) { + errorOut(e, "MothurOut", "parseClasses"); + exit(1); + } +} /***********************************************************************/ string MothurOut::hasPath(string longName){ @@ -1360,6 +1393,67 @@ vector MothurOut::setFilePosFasta(string filename, int& num) exit(1); } } +//********************************************************************************************************************** +vector MothurOut::readConsTax(string inputfile){ + try { + + vector 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& 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 MothurOut::setFilePosEachLine(string filename, int& num) { try { @@ -2242,9 +2336,11 @@ map MothurOut::readNames(string namefile, unsigned long int& numSeq /************************************************************/ int MothurOut::checkName(string& name) { try { - for (int i = 0; i < name.length(); i++) { - if (name[i] == ':') { name[i] = '_'; changedSeqNames = true; } - } + if (modifyNames) { + for (int i = 0; i < name.length(); i++) { + if (name[i] == ':') { name[i] = '_'; changedSeqNames = true; } + } + } return 0; } catch(exception& e) { @@ -2346,7 +2442,9 @@ set MothurOut::readAccnos(string accnosfile){ in.read(buffer, 4096); vector 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(); @@ -3270,6 +3368,26 @@ vector MothurOut::getAverages(vector< vector >& dists) { exit(1); } } +/**************************************************************************************************/ +double MothurOut::getAverage(vector dists) { + try{ + double average = 0; + + for (int i = 0; i < dists.size(); i++) { + average += dists[i]; + } + + //finds average. + average /= (double) dists.size(); + + return average; + } + catch(exception& e) { + errorOut(e, "MothurOut", "getAverage"); + exit(1); + } +} + /**************************************************************************************************/ vector MothurOut::getStandardDeviation(vector< vector >& dists) { try{