types.insert("tree");
types.insert("flow");
types.insert("biom");
+ types.insert("count");
types.insert("processors");
return types;
if (treefile != "") { mothurOut("tree=" + treefile); mothurOutEndLine(); }
if (flowfile != "") { mothurOut("flow=" + flowfile); mothurOutEndLine(); }
if (biomfile != "") { mothurOut("biom=" + biomfile); mothurOutEndLine(); }
+ if (counttablefile != "") { mothurOut("count=" + counttablefile); mothurOutEndLine(); }
if (processors != "1") { mothurOut("processors=" + processors); mothurOutEndLine(); }
}
if (treefile != "") { return true; }
if (flowfile != "") { return true; }
if (biomfile != "") { return true; }
+ if (counttablefile != "") { return true; }
if (processors != "1") { return true; }
return hasCurrent;
taxonomyfile = "";
flowfile = "";
biomfile = "";
+ counttablefile = "";
processors = "1";
}
catch(exception& e) {
}
for (int i = index; i >= 0; i--) {
- newFileName = dirs[i] + "\\" + newFileName;
+ newFileName = dirs[i] + "\\\\" + newFileName;
}
return newFileName;
int MothurOut::renameFile(string oldName, string newName){
try {
+
+ if (oldName == newName) { return 0; }
+
ifstream inTest;
int exist = openInputFile(newName, inTest, "");
inTest.close();
string firstName, secondName;
float dist;
- while (input) {
+ while (!input.eof()) {
input >> firstName >> secondName >> dist;
output << dist << '\t' << firstName << '\t' << secondName << endl;
gobble(input);
//read in sorted file and put distance at end again
ifstream input2;
+ ofstream output2;
openInputFile(tempOutfile, input2);
- openOutputFile(outfile, output);
+ openOutputFile(outfile, output2);
- while (input2) {
+ while (!input2.eof()) {
input2 >> dist >> firstName >> secondName;
- output << firstName << '\t' << secondName << '\t' << dist << endl;
+ output2 << firstName << '\t' << secondName << '\t' << dist << endl;
gobble(input2);
}
input2.close();
- output.close();
+ output2.close();
//remove temp files
mothurRemove(tempDistFile);
positions.push_back(0);
while(!in.eof()){
- //unsigned long long lastpos = in.tellg();
- //input = getline(in);
- //if (input.length() != 0) {
- //unsigned long long pos = in.tellg();
- //if (pos != -1) { positions.push_back(pos - input.length() - 1); }
- //else { positions.push_back(lastpos); }
- //}
- //gobble(in); //has to be here since windows line endings are 2 characters and mess up the positions
-
-
//getline counting reads
char d = in.get(); count++;
while ((d != '\n') && (d != '\r') && (d != '\f') && (d != in.eof())) {
for (int i = 0; i < size; i++) {
if (!isspace(buffer[i])) { rest += buffer[i]; }
else {
- pieces.push_back(rest); rest = "";
+ if (rest != "") { pieces.push_back(rest); rest = ""; }
while (i < size) { //gobble white space
if (isspace(buffer[i])) { i++; }
else { rest = buffer[i]; break; } //cout << "next piece buffer = " << nextPiece << endl;
for (int i = 0; i < input.length(); i++) {
if (!isspace(input[i])) { rest += input[i]; }
else {
- pieces.push_back(rest); rest = "";
+ if (rest != "") { pieces.push_back(rest); rest = ""; }
while (i < input.length()) { //gobble white space
if (isspace(input[i])) { i++; }
else { rest = input[i]; break; } //cout << "next piece buffer = " << nextPiece << endl;
exit(1);
}
}
+/***********************************************************************/
+vector<string> MothurOut::splitWhiteSpaceWithQuotes(string input){
+ try {
+ vector<string> pieces;
+ string rest = "";
+
+ int pos = input.find('\'');
+ int pos2 = input.find('\"');
+
+ if ((pos == string::npos) && (pos2 == string::npos)) { return splitWhiteSpace(input); } //no quotes to worry about
+ else {
+ for (int i = 0; i < input.length(); i++) {
+ if ((input[i] == '\'') || (input[i] == '\"') || (rest == "\'") || (rest == "\"")) { //grab everything til end or next ' or "
+ rest += input[i];
+ for (int j = i+1; j < input.length(); j++) {
+ if ((input[j] == '\'') || (input[j] == '\"')) { //then quit
+ rest += input[j];
+ i = j+1;
+ j+=input.length();
+ }else { rest += input[j]; }
+ }
+ }else if (!isspace(input[i])) { rest += input[i]; }
+ else {
+ if (rest != "") { pieces.push_back(rest); rest = ""; }
+ while (i < input.length()) { //gobble white space
+ if (isspace(input[i])) { i++; }
+ else { rest = input[i]; break; } //cout << "next piece buffer = " << nextPiece << endl;
+ }
+ }
+ }
+
+ if (rest != "") { pieces.push_back(rest); }
+ }
+ return pieces;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "splitWhiteSpace");
+ exit(1);
+ }
+}
//**********************************************************************************************************************
int MothurOut::readTax(string namefile, map<string, string>& taxMap) {
try {
-
//open input file
ifstream in;
openInputFile(namefile, in);
if (pairDone) {
//are there confidence scores, if so remove them
if (secondCol.find_first_of('(') != -1) { removeConfidences(secondCol); }
- taxMap[firstCol] = secondCol;
- if (debug) { mothurOut("[DEBUG]: name = '" + firstCol + "' tax = '" + secondCol + "'\n"); }
+ map<string, string>::iterator itTax = taxMap.find(firstCol);
+
+ if(itTax == taxMap.end()) {
+ bool ignore = false;
+ if (secondCol != "") { if (secondCol[secondCol.length()-1] != ';') { mothurOut("[ERROR]: " + firstCol + " is missing the final ';', ignoring.\n"); ignore=true; }
+ }
+ 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;
+ }
pairDone = false;
}
}
}
in.close();
+
+ if (rest != "") {
+ vector<string> pieces = splitWhiteSpace(rest);
+
+ for (int i = 0; i < pieces.size(); i++) {
+ if (columnOne) { firstCol = pieces[i]; columnOne=false; }
+ else { secondCol = pieces[i]; pairDone = true; columnOne=true; }
+
+ if (pairDone) {
+ //are there confidence scores, if so remove them
+ if (secondCol.find_first_of('(') != -1) { removeConfidences(secondCol); }
+ map<string, string>::iterator itTax = taxMap.find(firstCol);
+
+ if(itTax == taxMap.end()) {
+ bool ignore = false;
+ if (secondCol != "") { if (secondCol[secondCol.length()-1] != ';') { mothurOut("[ERROR]: " + firstCol + " is missing the final ';', ignoring.\n"); ignore=true; }
+ }
+ 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;
+ }
+
+ pairDone = false;
+ }
+ }
+ }
return taxMap.size();
/**********************************************************************************************************************/
int MothurOut::readNames(string namefile, map<string, string>& nameMap, bool redund) {
try {
-
//open input file
ifstream in;
openInputFile(namefile, in);
}
}
in.close();
+
+ if (rest != "") {
+ vector<string> pieces = splitWhiteSpace(rest);
+
+ for (int i = 0; i < pieces.size(); i++) {
+ if (columnOne) { firstCol = pieces[i]; columnOne=false; }
+ else { secondCol = pieces[i]; pairDone = true; columnOne=true; }
+
+ if (pairDone) {
+ //parse names into vector
+ vector<string> theseNames;
+ splitAtComma(secondCol, theseNames);
+ for (int i = 0; i < theseNames.size(); i++) { nameMap[theseNames[i]] = firstCol; }
+ pairDone = false;
+ }
+ }
+ }
return nameMap.size();
/**********************************************************************************************************************/
int MothurOut::readNames(string namefile, map<string, string>& nameMap, int flip) {
try {
-
//open input file
ifstream in;
openInputFile(namefile, in);
}
}
in.close();
+
+ if (rest != "") {
+ vector<string> pieces = splitWhiteSpace(rest);
+
+ for (int i = 0; i < pieces.size(); i++) {
+ if (columnOne) { firstCol = pieces[i]; columnOne=false; }
+ else { secondCol = pieces[i]; pairDone = true; columnOne=true; }
+
+ if (pairDone) {
+ nameMap[secondCol] = firstCol;
+ pairDone = false;
+ }
+ }
+ }
return nameMap.size();
/**********************************************************************************************************************/
int MothurOut::readNames(string namefile, map<string, string>& nameMap, map<string, int>& nameCount) {
try {
- nameMap.clear(); nameCount.clear();
+ nameMap.clear(); nameCount.clear();
//open input file
ifstream in;
openInputFile(namefile, in);
}
in.close();
+ if (rest != "") {
+ vector<string> pieces = splitWhiteSpace(rest);
+
+ for (int i = 0; i < pieces.size(); i++) {
+ if (columnOne) { firstCol = pieces[i]; columnOne=false; }
+ else { secondCol = pieces[i]; pairDone = true; columnOne=true; }
+
+ if (pairDone) {
+ //parse names into vector
+ vector<string> theseNames;
+ splitAtComma(secondCol, theseNames);
+ for (int i = 0; i < theseNames.size(); i++) { nameMap[theseNames[i]] = firstCol; }
+ nameCount[firstCol] = theseNames.size();
+ pairDone = false;
+ }
+ }
+
+ }
return nameMap.size();
}
/**********************************************************************************************************************/
int MothurOut::readNames(string namefile, map<string, string>& nameMap) {
try {
-
//open input file
ifstream in;
openInputFile(namefile, in);
}
}
in.close();
+
+ if (rest != "") {
+ vector<string> pieces = splitWhiteSpace(rest);
+
+ for (int i = 0; i < pieces.size(); i++) {
+ if (columnOne) { firstCol = pieces[i]; columnOne=false; }
+ else { secondCol = pieces[i]; pairDone = true; columnOne=true; }
+
+ if (pairDone) { nameMap[firstCol] = secondCol; pairDone = false; }
+ }
+ }
return nameMap.size();
}
/**********************************************************************************************************************/
int MothurOut::readNames(string namefile, map<string, vector<string> >& nameMap) {
- try {
-
+ try {
//open input file
ifstream in;
openInputFile(namefile, in);
}
in.close();
+ if (rest != "") {
+ vector<string> pieces = splitWhiteSpace(rest);
+
+ for (int i = 0; i < pieces.size(); i++) {
+ if (columnOne) { firstCol = pieces[i]; columnOne=false; }
+ else { secondCol = pieces[i]; pairDone = true; columnOne=true; }
+
+ if (pairDone) {
+ vector<string> temp;
+ splitAtComma(secondCol, temp);
+ nameMap[firstCol] = temp;
+ pairDone = false;
+ }
+ }
+ }
+
return nameMap.size();
}
catch(exception& e) {
/**********************************************************************************************************************/
map<string, int> MothurOut::readNames(string namefile) {
try {
-
map<string, int> nameMap;
//open input file
}
}
in.close();
+
+ if (rest != "") {
+ vector<string> pieces = splitWhiteSpace(rest);
+ for (int i = 0; i < pieces.size(); i++) {
+ if (columnOne) { firstCol = pieces[i]; columnOne=false; }
+ else { secondCol = pieces[i]; pairDone = true; columnOne=true; }
+
+ if (pairDone) {
+ int num = getNumNames(secondCol);
+ nameMap[firstCol] = num;
+ pairDone = false;
+ }
+ }
+ }
return nameMap;
}
in.close();
+ if (rest != "") {
+ vector<string> pieces = splitWhiteSpace(rest);
+
+ for (int i = 0; i < pieces.size(); i++) {
+ if (columnOne) { firstCol = pieces[i]; columnOne=false; }
+ else { secondCol = pieces[i]; pairDone = true; columnOne=true; }
+
+ if (pairDone) {
+ int num = getNumNames(secondCol);
+
+ map<string, string>::iterator it = fastamap.find(firstCol);
+ if (it == fastamap.end()) {
+ error = 1;
+ mothurOut("[ERROR]: " + firstCol + " is not in your fastafile, but is in your namesfile, please correct."); mothurOutEndLine();
+ }else {
+ seqPriorityNode temp(num, it->second, firstCol);
+ nameVector.push_back(temp);
+ }
+
+ pairDone = false;
+ }
+ }
+ }
return error;
}
catch(exception& e) {
//**********************************************************************************************************************
set<string> MothurOut::readAccnos(string accnosfile){
try {
- set<string> names;
+ set<string> names;
ifstream in;
openInputFile(accnosfile, in);
string name;
}
in.close();
+ if (rest != "") {
+ vector<string> pieces = splitWhiteSpace(rest);
+ for (int i = 0; i < pieces.size(); i++) { names.insert(pieces[i]); }
+ }
return names;
}
catch(exception& e) {
for (int i = 0; i < pieces.size(); i++) { names.push_back(pieces[i]); }
}
in.close();
+
+ if (rest != "") {
+ vector<string> pieces = splitWhiteSpace(rest);
+ for (int i = 0; i < pieces.size(); i++) { names.push_back(pieces[i]); }
+ }
return 0;
}
exit(1);
}
}
+//**********************************************************************************************************************
+bool MothurOut::isSubset(vector<string> bigset, vector<string> subset) {
+ try {
+
+
+ if (subset.size() > bigset.size()) { return false; }
+
+ //check if each guy in suset is also in bigset
+ for (int i = 0; i < subset.size(); i++) {
+ bool match = false;
+ for (int j = 0; j < bigset.size(); j++) {
+ if (subset[i] == bigset[j]) { match = true; break; }
+ }
+
+ //you have a guy in subset that had no match in bigset
+ if (match == false) { return false; }
+ }
+
+ return true;
+
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "isSubset");
+ exit(1);
+ }
+}
/***********************************************************************/
int MothurOut::mothurRemove(string filename){
try {
exit(1);
}
}
+/***********************************************************************/
+bool MothurOut::mothurConvert(string item, intDist& num){
+ try {
+ bool error = false;
+
+ if (isNumeric1(item)) {
+ convert(item, num);
+ }else {
+ num = 0;
+ error = true;
+ mothurOut("[ERROR]: cannot convert " + item + " to an integer."); mothurOutEndLine();
+ commandInputsConvertError = true;
+ }
+
+ return error;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "mothurConvert");
+ exit(1);
+ }
+}
+
/***********************************************************************/
bool MothurOut::isNumeric1(string stringToCheck){
try {
//This function parses the estimator options and puts them in a vector
void MothurOut::splitAtChar(string& estim, vector<string>& container, char symbol) {
try {
+
+ if (symbol == '-') { splitAtDash(estim, container); return; }
+
string individual = "";
int estimLength = estim.size();
for(int i=0;i<estimLength;i++){
try {
string individual = "";
int estimLength = estim.size();
+ bool prevEscape = false;
for(int i=0;i<estimLength;i++){
- if(estim[i] == '-'){
- container.push_back(individual);
- individual = "";
+ if(prevEscape){
+ individual += estim[i];
+ prevEscape = false;
}
else{
- individual += estim[i];
+ if(estim[i] == '\\'){
+ prevEscape = true;
+ }
+ else if(estim[i] == '-'){
+ container.push_back(individual);
+ individual = "";
+ prevEscape = false;
+ }
+ else{
+ individual += estim[i];
+ prevEscape = false;
+ }
}
}
container.push_back(individual);
-
-
- /* string individual;
-
- while (estim.find_first_of('-') != -1) {
- individual = estim.substr(0,estim.find_first_of('-'));
- if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
- estim = estim.substr(estim.find_first_of('-')+1, estim.length());
- container.push_back(individual);
- }
- }
- //get last one
- container.push_back(estim); */
- }
+ }
catch(exception& e) {
errorOut(e, "MothurOut", "splitAtDash");
exit(1);
try {
string individual = "";
int estimLength = estim.size();
+ bool prevEscape = false;
for(int i=0;i<estimLength;i++){
- if(estim[i] == '-'){
- container.insert(individual);
- individual = "";
+ if(prevEscape){
+ individual += estim[i];
+ prevEscape = false;
}
else{
- individual += estim[i];
+ if(estim[i] == '\\'){
+ prevEscape = true;
+ }
+ else if(estim[i] == '-'){
+ container.insert(individual);
+ individual = "";
+ prevEscape = false;
+ }
+ else{
+ individual += estim[i];
+ prevEscape = false;
+ }
}
}
container.insert(individual);
-
- // string individual;
-
- // while (estim.find_first_of('-') != -1) {
- // individual = estim.substr(0,estim.find_first_of('-'));
- // if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
- // estim = estim.substr(estim.find_first_of('-')+1, estim.length());
- // container.insert(individual);
- // }
- // }
- //get last one
- // container.insert(estim);
-
+
}
catch(exception& e) {
errorOut(e, "MothurOut", "splitAtDash");
//This function parses the line options and puts them in a set
void MothurOut::splitAtDash(string& estim, set<int>& container) {
try {
- string individual;
+ string individual = "";
int lineNum;
-
- while (estim.find_first_of('-') != -1) {
- individual = estim.substr(0,estim.find_first_of('-'));
- if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
- estim = estim.substr(estim.find_first_of('-')+1, estim.length());
- convert(individual, lineNum); //convert the string to int
- container.insert(lineNum);
+ int estimLength = estim.size();
+ bool prevEscape = false;
+ for(int i=0;i<estimLength;i++){
+ if(prevEscape){
+ individual += estim[i];
+ prevEscape = false;
+ }
+ else{
+ if(estim[i] == '\\'){
+ prevEscape = true;
+ }
+ else if(estim[i] == '-'){
+ convert(individual, lineNum); //convert the string to int
+ container.insert(lineNum);
+ individual = "";
+ prevEscape = false;
+ }
+ else{
+ individual += estim[i];
+ prevEscape = false;
+ }
}
}
- //get last one
- convert(estim, lineNum); //convert the string to int
+ convert(individual, lineNum); //convert the string to int
container.insert(lineNum);
}
catch(exception& e) {
exit(1);
}
}
+/**************************************************************************************************/
+
+bool MothurOut::inUsersGroups(vector<int> set, vector< vector<int> > sets) {
+ try {
+ for (int i = 0; i < sets.size(); i++) {
+ if (set == sets[i]) { return true; }
+ }
+ return false;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "inUsersGroups");
+ exit(1);
+ }
+}
+/**************************************************************************************************/
+
+bool MothurOut::inUsersGroups(int groupname, vector<int> Groups) {
+ try {
+ for (int i = 0; i < Groups.size(); i++) {
+ if (groupname == Groups[i]) { return true; }
+ }
+ return false;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "inUsersGroups");
+ exit(1);
+ }
+}
+
/**************************************************************************************************/
//returns true if any of the strings in first vector are in second vector
bool MothurOut::inUsersGroups(vector<string> groupnames, vector<string> Groups) {
}
}
/**************************************************************************************************/
-
-
+string MothurOut::removeQuotes(string tax) {
+ try {
+
+ string taxon;
+ string newTax = "";
+
+ for (int i = 0; i < tax.length(); i++) {
+
+ if (control_pressed) { return newTax; }
+
+ if ((tax[i] != '\'') && (tax[i] != '\"')) { newTax += tax[i]; }
+
+ }
+
+ return newTax;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "removeQuotes");
+ exit(1);
+ }
+}
+/**************************************************************************************************/
+// function for calculating standard deviation
+double MothurOut::getStandardDeviation(vector<int>& featureVector){
+ try {
+ //finds sum
+ double average = 0;
+ for (int i = 0; i < featureVector.size(); i++) { average += featureVector[i]; }
+ average /= (double) featureVector.size();
+
+ //find standard deviation
+ double stdDev = 0;
+ for (int i = 0; i < featureVector.size(); i++) { //compute the difference of each dist from the mean, and square the result of each
+ stdDev += ((featureVector[i] - average) * (featureVector[i] - average));
+ }
+
+ stdDev /= (double) featureVector.size();
+ stdDev = sqrt(stdDev);
+
+ return stdDev;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "getStandardDeviation");
+ exit(1);
+ }
+}
+/**************************************************************************************************/