From: westcott Date: Tue, 24 Aug 2010 11:51:33 +0000 (+0000) Subject: moved utilities out of mothur.h and into mothurOut class. X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=260ae19c36cb11a53ddc5a75b5e507f8dd8b31d6 moved utilities out of mothur.h and into mothurOut class. --- diff --git a/aligncommand.cpp b/aligncommand.cpp index 613f9b7..0f4c89a 100644 --- a/aligncommand.cpp +++ b/aligncommand.cpp @@ -68,7 +68,7 @@ AlignCommand::AlignCommand(string option) { //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["template"] = inputDir + it->second; } } @@ -86,12 +86,12 @@ AlignCommand::AlignCommand(string option) { candidateFileName = validParameter.validFile(parameters, "candidate", false); if (candidateFileName == "not found") { m->mothurOut("candidate is a required parameter for the align.seqs command."); m->mothurOutEndLine(); abort = true; } else { - splitAtDash(candidateFileName, candidateFileNames); + m->splitAtDash(candidateFileName, candidateFileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < candidateFileNames.size(); i++) { if (inputDir != "") { - string path = hasPath(candidateFileNames[i]); + string path = m->hasPath(candidateFileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { candidateFileNames[i] = inputDir + candidateFileNames[i]; } } @@ -99,14 +99,14 @@ AlignCommand::AlignCommand(string option) { int ableToOpen; ifstream in; - ableToOpen = openInputFile(candidateFileNames[i], in, "noerror"); + ableToOpen = m->openInputFile(candidateFileNames[i], in, "noerror"); //if you can't open it, try default location if (ableToOpen == 1) { if (m->getDefaultPath() != "") { //default path is set - string tryPath = m->getDefaultPath() + getSimpleName(candidateFileNames[i]); + string tryPath = m->getDefaultPath() + m->getSimpleName(candidateFileNames[i]); m->mothurOut("Unable to open " + candidateFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = openInputFile(tryPath, in, "noerror"); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); candidateFileNames[i] = tryPath; } } @@ -147,7 +147,7 @@ AlignCommand::AlignCommand(string option) { convert(temp, processors); temp = validParameter.validFile(parameters, "flip", false); if (temp == "not found"){ temp = "f"; } - flip = isTrue(temp); + flip = m->isTrue(temp); temp = validParameter.validFile(parameters, "threshold", false); if (temp == "not found"){ temp = "0.50"; } convert(temp, threshold); @@ -230,10 +230,10 @@ int AlignCommand::execute(){ m->mothurOut("Aligning sequences from " + candidateFileNames[s] + " ..." ); m->mothurOutEndLine(); - if (outputDir == "") { outputDir += hasPath(candidateFileNames[s]); } - string alignFileName = outputDir + getRootName(getSimpleName(candidateFileNames[s])) + "align"; - string reportFileName = outputDir + getRootName(getSimpleName(candidateFileNames[s])) + "align.report"; - string accnosFileName = outputDir + getRootName(getSimpleName(candidateFileNames[s])) + "flip.accnos"; + if (outputDir == "") { outputDir += m->hasPath(candidateFileNames[s]); } + string alignFileName = outputDir + m->getRootName(m->getSimpleName(candidateFileNames[s])) + "align"; + string reportFileName = outputDir + m->getRootName(m->getSimpleName(candidateFileNames[s])) + "align.report"; + string accnosFileName = outputDir + m->getRootName(m->getSimpleName(candidateFileNames[s])) + "flip.accnos"; bool hasAccnos = true; int numFastaSeqs = 0; @@ -279,7 +279,7 @@ int AlignCommand::execute(){ if (pid == 0) { //you are the root process - MPIPos = setFilePosFasta(candidateFileNames[s], numFastaSeqs); //fills MPIPos, returns numSeqs + MPIPos = m->setFilePosFasta(candidateFileNames[s], numFastaSeqs); //fills MPIPos, returns numSeqs //send file positions to all processes for(int i = 1; i < processors; i++) { @@ -346,8 +346,9 @@ int AlignCommand::execute(){ } #else - vector positions = divideFile(candidateFileNames[s], processors); - + + vector positions = m->divideFile(candidateFileNames[s], processors); + for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(new linePair(positions[i], positions[(i+1)])); } @@ -358,7 +359,7 @@ int AlignCommand::execute(){ if (m->control_pressed) { remove(accnosFileName.c_str()); remove(alignFileName.c_str()); remove(reportFileName.c_str()); return 0; } //delete accnos file if its blank else report to user - if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; } + if (m->isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; } else { m->mothurOut("Some of you sequences generated alignments that eliminated too many bases, a list is provided in " + accnosFileName + "."); if (!flip) { @@ -386,7 +387,7 @@ int AlignCommand::execute(){ vector nonBlankAccnosFiles; //delete blank accnos files generated with multiple processes for(int i=0;iisBlank(accnosFileName + toString(processIDS[i]) + ".temp"))) { nonBlankAccnosFiles.push_back(accnosFileName + toString(processIDS[i]) + ".temp"); }else { remove((accnosFileName + toString(processIDS[i]) + ".temp").c_str()); } } @@ -414,7 +415,7 @@ int AlignCommand::execute(){ if (m->control_pressed) { remove(accnosFileName.c_str()); remove(alignFileName.c_str()); remove(reportFileName.c_str()); return 0; } //delete accnos file if its blank else report to user - if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; } + if (m->isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; } else { m->mothurOut("Some of you sequences generated alignments that eliminated too many bases, a list is provided in " + accnosFileName + "."); if (!flip) { @@ -466,15 +467,15 @@ int AlignCommand::execute(){ int AlignCommand::driver(linePair* filePos, string alignFName, string reportFName, string accnosFName, string filename){ try { ofstream alignmentFile; - openOutputFile(alignFName, alignmentFile); + m->openOutputFile(alignFName, alignmentFile); ofstream accnosFile; - openOutputFile(accnosFName, accnosFile); + m->openOutputFile(accnosFName, accnosFile); NastReport report(reportFName); ifstream inFASTA; - openInputFile(filename, inFASTA); + m->openInputFile(filename, inFASTA); inFASTA.seekg(filePos->start); @@ -485,7 +486,7 @@ int AlignCommand::driver(linePair* filePos, string alignFName, string reportFNam if (m->control_pressed) { return 0; } - Sequence* candidateSeq = new Sequence(inFASTA); gobble(inFASTA); + Sequence* candidateSeq = new Sequence(inFASTA); m->gobble(inFASTA); int origNumBases = candidateSeq->getNumBases(); string originalUnaligned = candidateSeq->getUnaligned(); @@ -769,7 +770,7 @@ int AlignCommand::createProcesses(string alignFileName, string reportFileName, s //pass numSeqs to parent ofstream out; string tempFile = alignFileName + toString(getpid()) + ".num.temp"; - openOutputFile(tempFile, out); + m->openOutputFile(tempFile, out); out << num << endl; out.close(); @@ -786,7 +787,7 @@ int AlignCommand::createProcesses(string alignFileName, string reportFileName, s for (int i = 0; i < processIDS.size(); i++) { ifstream in; string tempFile = alignFileName + toString(processIDS[i]) + ".num.temp"; - openInputFile(tempFile, in); + m->openInputFile(tempFile, in); if (!in.eof()) { int tempNum = 0; in >> tempNum; num += tempNum; } in.close(); remove(tempFile.c_str()); } @@ -806,8 +807,8 @@ void AlignCommand::appendAlignFiles(string temp, string filename) { ofstream output; ifstream input; - openOutputFileAppend(filename, output); - openInputFile(temp, input); + m->openOutputFileAppend(filename, output); + m->openInputFile(temp, input); while(char c = input.get()){ if(input.eof()) { break; } @@ -829,8 +830,8 @@ void AlignCommand::appendReportFiles(string temp, string filename) { ofstream output; ifstream input; - openOutputFileAppend(filename, output); - openInputFile(temp, input); + m->openOutputFileAppend(filename, output); + m->openInputFile(temp, input); while (!input.eof()) { char c = input.get(); if (c == 10 || c == 13){ break; } } // get header line diff --git a/alignmentdb.cpp b/alignmentdb.cpp index bdd3e03..e2b1dc1 100644 --- a/alignmentdb.cpp +++ b/alignmentdb.cpp @@ -40,7 +40,7 @@ AlignmentDB::AlignmentDB(string fastaFileName, string s, int kmerSize, float gap MPI_File_open(MPI_COMM_WORLD, inFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI); //comm, filename, mode, info, filepointer if (pid == 0) { - positions = setFilePosFasta(fastaFileName, numSeqs); //fills MPIPos, returns numSeqs + positions = m->setFilePosFasta(fastaFileName, numSeqs); //fills MPIPos, returns numSeqs //send file positions to all processes for(int i = 1; i < processors; i++) { @@ -84,10 +84,10 @@ AlignmentDB::AlignmentDB(string fastaFileName, string s, int kmerSize, float gap #else ifstream fastaFile; - openInputFile(fastaFileName, fastaFile); + m->openInputFile(fastaFileName, fastaFile); while (!fastaFile.eof()) { - Sequence temp(fastaFile); gobble(fastaFile); + Sequence temp(fastaFile); m->gobble(fastaFile); if (m->control_pressed) { templateSequences.clear(); break; } @@ -124,7 +124,7 @@ AlignmentDB::AlignmentDB(string fastaFileName, string s, int kmerSize, float gap ifstream kmerFileTest(kmerDBName.c_str()); if(kmerFileTest){ - bool GoodFile = checkReleaseVersion(kmerFileTest, m->getVersion()); + bool GoodFile = m->checkReleaseVersion(kmerFileTest, m->getVersion()); if (GoodFile) { needToGenerate = false; } } #endif diff --git a/bayesian.cpp b/bayesian.cpp index e596f67..531abc5 100644 --- a/bayesian.cpp +++ b/bayesian.cpp @@ -18,7 +18,7 @@ Classify(), kmerSize(ksize), confidenceThreshold(cutoff), iters(i) { /************calculate the probablity that each word will be in a specific taxonomy*************/ string tfileroot = tfile.substr(0,tfile.find_last_of(".")+1); - string tempfileroot = getRootName(getSimpleName(tempFile)); + string tempfileroot = m->getRootName(m->getSimpleName(tempFile)); string phyloTreeName = tfileroot + "tree.train"; string phyloTreeSumName = tfileroot + "tree.sum"; string probFileName = tfileroot + tempfileroot + char('0'+ kmerSize) + "mer.prob"; @@ -90,14 +90,14 @@ Classify(), kmerSize(ksize), confidenceThreshold(cutoff), iters(i) { #endif - openOutputFile(probFileName, out); + m->openOutputFile(probFileName, out); //output mothur version out << "#" << m->getVersion() << endl; out << numKmers << endl; - openOutputFile(probFileName2, out2); + m->openOutputFile(probFileName2, out2); //output mothur version out2 << "#" << m->getVersion() << endl; @@ -408,8 +408,8 @@ void Bayesian::readProbFile(ifstream& in, ifstream& inNum, string inName, string MPI_File_open(MPI_COMM_WORLD, inFileName2, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI2); //comm, filename, mode, info, filepointer if (pid == 0) { - positions = setFilePosEachLine(inNumName, num); - positions2 = setFilePosEachLine(inName, num2); + positions = m->setFilePosEachLine(inNumName, num); + positions2 = m->setFilePosEachLine(inName, num2); for(int i = 1; i < processors; i++) { MPI_Send(&num, 1, MPI_INT, i, tag, MPI_COMM_WORLD); @@ -515,9 +515,9 @@ void Bayesian::readProbFile(ifstream& in, ifstream& inNum, string inName, string MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case #else //read version - string line = getline(in); gobble(in); + string line = m->getline(in); m->gobble(in); - in >> numKmers; gobble(in); + in >> numKmers; m->gobble(in); //initialze probabilities wordGenusProb.resize(numKmers); @@ -530,12 +530,12 @@ void Bayesian::readProbFile(ifstream& in, ifstream& inNum, string inName, string vector zeroCountProb; zeroCountProb.resize(numKmers); //read version - string line2 = getline(inNum); gobble(inNum); + string line2 = m->getline(inNum); m->gobble(inNum); while (inNum) { inNum >> zeroCountProb[count] >> num[count]; count++; - gobble(inNum); + m->gobble(inNum); } inNum.close(); @@ -553,7 +553,7 @@ void Bayesian::readProbFile(ifstream& in, ifstream& inNum, string inName, string wordGenusProb[kmer][name] = prob; } - gobble(in); + m->gobble(in); } in.close(); @@ -571,10 +571,10 @@ bool Bayesian::checkReleaseDate(ifstream& file1, ifstream& file2, ifstream& file bool good = true; vector lines; - lines.push_back(getline(file1)); - lines.push_back(getline(file2)); - lines.push_back(getline(file3)); - lines.push_back(getline(file4)); + lines.push_back(m->getline(file1)); + lines.push_back(m->getline(file2)); + lines.push_back(m->getline(file3)); + lines.push_back(m->getline(file4)); //before we added this check if ((lines[0][0] != '#') || (lines[1][0] != '#') || (lines[2][0] != '#') || (lines[3][0] != '#')) { good = false; } @@ -586,12 +586,12 @@ bool Bayesian::checkReleaseDate(ifstream& file1, ifstream& file2, ifstream& file string version = m->getVersion(); vector versionVector; - splitAtChar(version, versionVector, '.'); + m->splitAtChar(version, versionVector, '.'); //check each files version for (int i = 0; i < lines.size(); i++) { vector linesVector; - splitAtChar(lines[i], linesVector, '.'); + m->splitAtChar(lines[i], linesVector, '.'); if (versionVector.size() != linesVector.size()) { good = false; break; } else { diff --git a/bellerophon.cpp b/bellerophon.cpp index 743c6d7..4f48d9c 100644 --- a/bellerophon.cpp +++ b/bellerophon.cpp @@ -665,7 +665,7 @@ int Bellerophon::writePrefs(string file, linePair tempLine) { try { ofstream outTemp; - openOutputFile(file, outTemp); + m->openOutputFile(file, outTemp); //lets you know what part of the pref matrix you are writing outTemp << tempLine.start << '\t' << tempLine.num << endl; @@ -695,12 +695,12 @@ int Bellerophon::readPrefs(string file) { try { ifstream inTemp; - openInputFile(file, inTemp); + m->openInputFile(file, inTemp); int start, num; //lets you know what part of the pref matrix you are writing - inTemp >> start >> num; gobble(inTemp); + inTemp >> start >> num; m->gobble(inTemp); for (int i = start; i < num; i++) { @@ -710,7 +710,7 @@ int Bellerophon::readPrefs(string file) { inTemp >> pref[i][j].name >> pref[i][j].leftParent >> pref[i][j].rightParent; inTemp >> pref[i][j].score >> pref[i][j].closestLeft >> pref[i][j].closestRight >> pref[i][j].midpoint; - gobble(inTemp); + m->gobble(inTemp); } } diff --git a/binsequencecommand.cpp b/binsequencecommand.cpp index 1d4f8c6..a761d5a 100644 --- a/binsequencecommand.cpp +++ b/binsequencecommand.cpp @@ -39,7 +39,7 @@ BinSeqCommand::BinSeqCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(globaldata->getListFile()); //if user entered a file with a path then preserve it + outputDir += m->hasPath(globaldata->getListFile()); //if user entered a file with a path then preserve it } @@ -58,7 +58,7 @@ BinSeqCommand::BinSeqCommand(string option) { it = parameters.find("fasta"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } @@ -66,7 +66,7 @@ BinSeqCommand::BinSeqCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -74,7 +74,7 @@ BinSeqCommand::BinSeqCommand(string option) { it = parameters.find("group"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["group"] = inputDir + it->second; } } @@ -92,7 +92,7 @@ BinSeqCommand::BinSeqCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -111,7 +111,7 @@ BinSeqCommand::BinSeqCommand(string option) { else if (groupfile == "not found") { groupfile = ""; } if (abort == false) { -// openInputFile(fastafile, in); +// m->openInputFile(fastafile, in); fasta = new FastaMap(); if (groupfile != "") { groupMap = new GroupMap(groupfile); @@ -209,7 +209,7 @@ int BinSeqCommand::execute(){ userLabels.erase(list->getLabel()); } - if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = list->getLabel(); delete list; @@ -277,7 +277,7 @@ int BinSeqCommand::execute(){ void BinSeqCommand::readNamesFile() { try { vector dupNames; - openInputFile(namesfile, inNames); + m->openInputFile(namesfile, inNames); string name, names, sequence; @@ -288,7 +288,7 @@ void BinSeqCommand::readNamesFile() { dupNames.clear(); //parse names into vector - splitAtComma(names, dupNames); + m->splitAtComma(names, dupNames); //store names in fasta map sequence = fasta->getSequence(name); @@ -296,7 +296,7 @@ void BinSeqCommand::readNamesFile() { fasta->push_back(dupNames[i], sequence); } - gobble(inNames); + m->gobble(inNames); } inNames.close(); @@ -312,8 +312,8 @@ int BinSeqCommand::process(ListVector* list) { try { string binnames, name, sequence; - string outputFileName = outputDir + getRootName(getSimpleName(globaldata->getListFile())) + list->getLabel() + ".fasta"; - openOutputFile(outputFileName, out); + string outputFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->getListFile())) + list->getLabel() + ".fasta"; + m->openOutputFile(outputFileName, out); //save to output list of output file names outputNames.push_back(outputFileName); diff --git a/blastalign.cpp b/blastalign.cpp index 04c7716..5e7fb61 100644 --- a/blastalign.cpp +++ b/blastalign.cpp @@ -72,7 +72,7 @@ void BlastAlignment::setPairwiseSeqs(){ // This method call assigns the blast ge // to the pairwise entry in the Sequence class for the // candidate and template Sequence objects ifstream blastFile; - openInputFile(blastFileName, blastFile); + m->openInputFile(blastFileName, blastFile); seqAaln = ""; seqBaln = ""; diff --git a/blastdb.cpp b/blastdb.cpp index d8a04da..979d507 100644 --- a/blastdb.cpp +++ b/blastdb.cpp @@ -69,7 +69,7 @@ vector BlastDB::findClosestSequences(Sequence* seq, int n) { vector topMatches; ofstream queryFile; - openOutputFile((queryFileName+seq->getName()), queryFile); + m->openOutputFile((queryFileName+seq->getName()), queryFile); queryFile << '>' << seq->getName() << endl; queryFile << seq->getUnaligned() << endl; queryFile.close(); @@ -84,11 +84,11 @@ vector BlastDB::findClosestSequences(Sequence* seq, int n) { system(blastCommand.c_str()); ifstream m8FileHandle; - openInputFile(blastFileName+seq->getName(), m8FileHandle, "no error"); + m->openInputFile(blastFileName+seq->getName(), m8FileHandle, "no error"); string dummy; int templateAccession; - gobble(m8FileHandle); + m->gobble(m8FileHandle); while(!m8FileHandle.eof()){ m8FileHandle >> dummy >> templateAccession >> searchScore; @@ -96,7 +96,7 @@ vector BlastDB::findClosestSequences(Sequence* seq, int n) { //get rest of junk in line while (!m8FileHandle.eof()) { char c = m8FileHandle.get(); if (c == 10 || c == 13){ break; } } - gobble(m8FileHandle); + m->gobble(m8FileHandle); topMatches.push_back(templateAccession); } m8FileHandle.close(); @@ -118,7 +118,7 @@ vector BlastDB::findClosestMegaBlast(Sequence* seq, int n) { vector topMatches; ofstream queryFile; - openOutputFile((queryFileName+seq->getName()), queryFile); + m->openOutputFile((queryFileName+seq->getName()), queryFile); queryFile << '>' << seq->getName() << endl; queryFile << seq->getUnaligned() << endl; queryFile.close(); @@ -132,11 +132,11 @@ vector BlastDB::findClosestMegaBlast(Sequence* seq, int n) { system(blastCommand.c_str()); ifstream m8FileHandle; - openInputFile(blastFileName+seq->getName(), m8FileHandle, "no error"); + m->openInputFile(blastFileName+seq->getName(), m8FileHandle, "no error"); string dummy; int templateAccession; - gobble(m8FileHandle); + m->gobble(m8FileHandle); while(!m8FileHandle.eof()){ m8FileHandle >> dummy >> templateAccession >> searchScore; @@ -144,7 +144,7 @@ vector BlastDB::findClosestMegaBlast(Sequence* seq, int n) { //get rest of junk in line while (!m8FileHandle.eof()) { char c = m8FileHandle.get(); if (c == 10 || c == 13){ break; } } - gobble(m8FileHandle); + m->gobble(m8FileHandle); topMatches.push_back(templateAccession); //cout << templateAccession << endl; } @@ -164,7 +164,7 @@ void BlastDB::addSequence(Sequence seq) { try { ofstream unalignedFastaFile; - openOutputFileAppend(dbFileName, unalignedFastaFile); + m->openOutputFileAppend(dbFileName, unalignedFastaFile); // generating a fasta file with unaligned template unalignedFastaFile << '>' << count << endl; // sequences, which will be input to formatdb diff --git a/bootstrapsharedcommand.cpp b/bootstrapsharedcommand.cpp index d174cdd..9424347 100644 --- a/bootstrapsharedcommand.cpp +++ b/bootstrapsharedcommand.cpp @@ -52,7 +52,7 @@ BootSharedCommand::BootSharedCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it } @@ -67,7 +67,7 @@ BootSharedCommand::BootSharedCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -80,7 +80,7 @@ BootSharedCommand::BootSharedCommand(string option) { groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); globaldata->Groups = Groups; } @@ -89,7 +89,7 @@ BootSharedCommand::BootSharedCommand(string option) { else { if (calc == "default") { calc = "jclass-thetayc"; } } - splitAtDash(calc, Estimators); + m->splitAtDash(calc, Estimators); string temp; temp = validParameter.validFile(parameters, "iters", false); if (temp == "not found") { temp = "1000"; } @@ -232,7 +232,7 @@ int BootSharedCommand::execute(){ } //you have a label the user want that is smaller than this label and the last label has not already been processed - if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = order->getLabel(); delete order; @@ -408,8 +408,8 @@ int BootSharedCommand::process(SharedOrderVector* order) { //open an ostream for each calc to print to for (int z = 0; z < treeCalculators.size(); z++) { //create a new filename - outputFile = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + treeCalculators[z]->getName() + ".boot" + order->getLabel() + ".tre"; - openOutputFile(outputFile, *(out[z])); + outputFile = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + treeCalculators[z]->getName() + ".boot" + order->getLabel() + ".tre"; + m->openOutputFile(outputFile, *(out[z])); outputNames.push_back(outputFile); } @@ -487,7 +487,7 @@ int BootSharedCommand::process(SharedOrderVector* order) { //set global data to calc trees globaldata->gTree = trees[k]; - string filename = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + treeCalculators[k]->getName() + ".boot" + order->getLabel(); + string filename = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + treeCalculators[k]->getName() + ".boot" + order->getLabel(); consensus = new ConcensusCommand(filename); consensus->execute(); delete consensus; diff --git a/catchallcommand.cpp b/catchallcommand.cpp index 434c273..b185b9f 100644 --- a/catchallcommand.cpp +++ b/catchallcommand.cpp @@ -44,7 +44,7 @@ CatchAllCommand::CatchAllCommand(string option) { it = parameters.find("sabund"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["sabund"] = inputDir + it->second; } } @@ -59,7 +59,7 @@ CatchAllCommand::CatchAllCommand(string option) { string label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -102,13 +102,13 @@ int CatchAllCommand::execute() { vector outputNames; //prepare full output directory - outputDir = getFullPathName(outputDir); + outputDir = m->getFullPathName(outputDir); //get location of catchall GlobalData* globaldata = GlobalData::getInstance(); string path = globaldata->argv; path = path.substr(0, (path.find_last_of('m'))); - path = getFullPathName(path); + path = m->getFullPathName(path); string catchAllCommandExe = ""; #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) @@ -159,7 +159,7 @@ cout << catchAllCommand << endl; userLabels.erase(sabund->getLabel()); } - if ((anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = sabund->getLabel(); delete sabund; @@ -264,11 +264,11 @@ cout << catchAllCommand << endl; //********************************************************************************************************************** string CatchAllCommand::process(SAbundVector* sabund) { try { - string filename = outputDir + getRootName(getSimpleName(sabundfile)) + sabund->getLabel() + ".catchall"; - filename = getFullPathName(filename); + string filename = outputDir + m->getRootName(m->getSimpleName(sabundfile)) + sabund->getLabel() + ".catchall"; + filename = m->getFullPathName(filename); ofstream out; - openOutputFile(filename, out); + m->openOutputFile(filename, out); for (int i = 1; i <= sabund->getMaxRank(); i++) { int temp = sabund->get(i); diff --git a/ccode.cpp b/ccode.cpp index c276448..15e482a 100644 --- a/ccode.cpp +++ b/ccode.cpp @@ -25,7 +25,7 @@ Ccode::Ccode(string filename, string temp, bool f, string mask, int win, int num distCalc = new eachGapDist(); decalc = new DeCalculator(); - mapInfo = outputDir + getRootName(getSimpleName(fastafile)) + "mapinfo"; + mapInfo = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "mapinfo"; #ifdef USE_MPI @@ -58,7 +58,7 @@ Ccode::Ccode(string filename, string temp, bool f, string mask, int win, int num #else ofstream out2; - openOutputFile(mapInfo, out2); + m->openOutputFile(mapInfo, out2); out2 << "Place in masked, filtered and trimmed sequence\tPlace in original alignment" << endl; out2.close(); @@ -78,7 +78,7 @@ int Ccode::print(ostream& out, ostream& outAcc) { try { ofstream out2; - openOutputFileAppend(mapInfo, out2); + m->openOutputFileAppend(mapInfo, out2); out2 << querySeq->getName() << endl; for (it = spotMap.begin(); it!= spotMap.end(); it++) { diff --git a/chimera.cpp b/chimera.cpp index 685d6db..ae9ad9a 100644 --- a/chimera.cpp +++ b/chimera.cpp @@ -123,7 +123,7 @@ vector Chimera::readSeqs(string file) { //delete inFileName; if (pid == 0) { - positions = setFilePosFasta(file, numSeqs); //fills MPIPos, returns numSeqs + positions = m->setFilePosFasta(file, numSeqs); //fills MPIPos, returns numSeqs //send file positions to all processes for(int i = 1; i < processors; i++) { @@ -167,14 +167,14 @@ vector Chimera::readSeqs(string file) { #else ifstream in; - openInputFile(file, in); + m->openInputFile(file, in); //read in seqs and store in vector while(!in.eof()){ if (m->control_pressed) { return container; } - Sequence* current = new Sequence(in); gobble(in); + Sequence* current = new Sequence(in); m->gobble(in); if (count == 0) { length = current->getAligned().length(); count++; } //gets first seqs length else if (length != current->getAligned().length()) { unaligned = true; } @@ -241,7 +241,7 @@ void Chimera::setMask(string filename) { #else ifstream infile; - openInputFile(filename, infile); + m->openInputFile(filename, infile); if (!infile.eof()) { Sequence temp(infile); diff --git a/chimerabellerophoncommand.cpp b/chimerabellerophoncommand.cpp index 6d09616..a504d0b 100644 --- a/chimerabellerophoncommand.cpp +++ b/chimerabellerophoncommand.cpp @@ -42,12 +42,12 @@ ChimeraBellerophonCommand::ChimeraBellerophonCommand(string option) { fastafile = validParameter.validFile(parameters, "fasta", false); if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the chimera.bellerophon command."); m->mothurOutEndLine(); abort = true; } else { - splitAtDash(fastafile, fastaFileNames); + m->splitAtDash(fastafile, fastaFileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < fastaFileNames.size(); i++) { if (inputDir != "") { - string path = hasPath(fastaFileNames[i]); + string path = m->hasPath(fastaFileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { fastaFileNames[i] = inputDir + fastaFileNames[i]; } } @@ -55,14 +55,14 @@ ChimeraBellerophonCommand::ChimeraBellerophonCommand(string option) { int ableToOpen; ifstream in; - ableToOpen = openInputFile(fastaFileNames[i], in, "noerror"); + ableToOpen = m->openInputFile(fastaFileNames[i], in, "noerror"); //if you can't open it, try default location if (ableToOpen == 1) { if (m->getDefaultPath() != "") { //default path is set - string tryPath = m->getDefaultPath() + getSimpleName(fastaFileNames[i]); + string tryPath = m->getDefaultPath() + m->getSimpleName(fastaFileNames[i]); m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = openInputFile(tryPath, in, "noerror"); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); fastaFileNames[i] = tryPath; } } @@ -84,15 +84,15 @@ ChimeraBellerophonCommand::ChimeraBellerophonCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(fastafile); //if user entered a file with a path then preserve it + outputDir += m->hasPath(fastafile); //if user entered a file with a path then preserve it } string temp; temp = validParameter.validFile(parameters, "filter", false); if (temp == "not found") { temp = "F"; } - filter = isTrue(temp); + filter = m->isTrue(temp); temp = validParameter.validFile(parameters, "correction", false); if (temp == "not found") { temp = "T"; } - correction = isTrue(temp); + correction = m->isTrue(temp); temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found") { temp = "1"; } convert(temp, processors); @@ -153,8 +153,8 @@ int ChimeraBellerophonCommand::execute(){ chimera = new Bellerophon(fastaFileNames[i], filter, correction, window, increment, processors, outputDir); - string outputFileName = outputDir + getRootName(getSimpleName(fastaFileNames[i])) + "bellerophon.chimeras"; - string accnosFileName = outputDir + getRootName(getSimpleName(fastaFileNames[i])) + "bellerophon.accnos"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[i])) + "bellerophon.chimeras"; + string accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[i])) + "bellerophon.accnos"; chimera->getChimeras(); @@ -183,10 +183,10 @@ int ChimeraBellerophonCommand::execute(){ #else ofstream out; - openOutputFile(outputFileName, out); + m->openOutputFile(outputFileName, out); ofstream out2; - openOutputFile(accnosFileName, out2); + m->openOutputFile(accnosFileName, out2); numSeqs = chimera->print(out, out2); out.close(); diff --git a/chimeraccodecommand.cpp b/chimeraccodecommand.cpp index 7a9431e..6a1904f 100644 --- a/chimeraccodecommand.cpp +++ b/chimeraccodecommand.cpp @@ -43,7 +43,7 @@ ChimeraCcodeCommand::ChimeraCcodeCommand(string option) { it = parameters.find("template"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["template"] = inputDir + it->second; } } @@ -53,12 +53,12 @@ ChimeraCcodeCommand::ChimeraCcodeCommand(string option) { fastafile = validParameter.validFile(parameters, "fasta", false); if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the chimera.ccode command."); m->mothurOutEndLine(); abort = true; } else { - splitAtDash(fastafile, fastaFileNames); + m->splitAtDash(fastafile, fastaFileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < fastaFileNames.size(); i++) { if (inputDir != "") { - string path = hasPath(fastaFileNames[i]); + string path = m->hasPath(fastaFileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { fastaFileNames[i] = inputDir + fastaFileNames[i]; } } @@ -66,14 +66,14 @@ ChimeraCcodeCommand::ChimeraCcodeCommand(string option) { int ableToOpen; ifstream in; - ableToOpen = openInputFile(fastaFileNames[i], in, "noerror"); + ableToOpen = m->openInputFile(fastaFileNames[i], in, "noerror"); //if you can't open it, try default location if (ableToOpen == 1) { if (m->getDefaultPath() != "") { //default path is set - string tryPath = m->getDefaultPath() + getSimpleName(fastaFileNames[i]); + string tryPath = m->getDefaultPath() + m->getSimpleName(fastaFileNames[i]); m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = openInputFile(tryPath, in, "noerror"); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); fastaFileNames[i] = tryPath; } } @@ -94,7 +94,7 @@ ChimeraCcodeCommand::ChimeraCcodeCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(fastafile); //if user entered a file with a path then preserve it + outputDir += m->hasPath(fastafile); //if user entered a file with a path then preserve it } templatefile = validParameter.validFile(parameters, "template", true); @@ -105,20 +105,20 @@ ChimeraCcodeCommand::ChimeraCcodeCommand(string option) { if (maskfile == "not found") { maskfile = ""; } else if (maskfile != "default") { if (inputDir != "") { - string path = hasPath(maskfile); + string path = m->hasPath(maskfile); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { maskfile = inputDir + maskfile; } } ifstream in; - int ableToOpen = openInputFile(maskfile, in); + int ableToOpen = m->openInputFile(maskfile, in); if (ableToOpen == 1) { abort = true; } in.close(); } string temp; temp = validParameter.validFile(parameters, "filter", false); if (temp == "not found") { temp = "F"; } - filter = isTrue(temp); + filter = m->isTrue(temp); temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found") { temp = "1"; } convert(temp, processors); @@ -194,14 +194,14 @@ int ChimeraCcodeCommand::execute(){ string outputFileName, accnosFileName; if (maskfile != "") { - outputFileName = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + maskfile + ".ccode.chimeras"; - accnosFileName = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + maskfile + ".ccode.accnos"; + outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + maskfile + ".ccode.chimeras"; + accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + maskfile + ".ccode.accnos"; }else { - outputFileName = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "ccode.chimeras"; - accnosFileName = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "ccode.accnos"; + outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "ccode.chimeras"; + accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "ccode.accnos"; } - string mapInfo = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "mapinfo"; + string mapInfo = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "mapinfo"; if (m->control_pressed) { delete chimera; for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; } @@ -248,7 +248,7 @@ int ChimeraCcodeCommand::execute(){ MPI_File_write_shared(outMPI, buf2, length, MPI_CHAR, &status); delete buf2; - MPIPos = setFilePosFasta(fastaFileNames[s], numSeqs); //fills MPIPos, returns numSeqs + MPIPos = m->setFilePosFasta(fastaFileNames[s], numSeqs); //fills MPIPos, returns numSeqs //send file positions to all processes for(int i = 1; i < processors; i++) { @@ -293,14 +293,14 @@ int ChimeraCcodeCommand::execute(){ #else ofstream outHeader; - string tempHeader = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + maskfile + "ccode.chimeras.tempHeader"; - openOutputFile(tempHeader, outHeader); + string tempHeader = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + maskfile + "ccode.chimeras.tempHeader"; + m->openOutputFile(tempHeader, outHeader); outHeader << "For full window mapping info refer to " << mapInfo << endl << endl; outHeader.close(); - vector positions = divideFile(fastaFileNames[s], processors); + vector positions = m->divideFile(fastaFileNames[s], processors); for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(new linePair(positions[i], positions[(i+1)])); @@ -324,13 +324,13 @@ int ChimeraCcodeCommand::execute(){ //append output files for(int i=1;iappendFiles((outputFileName + toString(processIDS[i]) + ".temp"), outputFileName); remove((outputFileName + toString(processIDS[i]) + ".temp").c_str()); } //append output files for(int i=1;iappendFiles((accnosFileName + toString(processIDS[i]) + ".temp"), accnosFileName); remove((accnosFileName + toString(processIDS[i]) + ".temp").c_str()); } @@ -352,7 +352,7 @@ int ChimeraCcodeCommand::execute(){ #endif - appendFiles(outputFileName, tempHeader); + m->appendFiles(outputFileName, tempHeader); remove(outputFileName.c_str()); rename(tempHeader.c_str(), outputFileName.c_str()); @@ -387,13 +387,13 @@ int ChimeraCcodeCommand::execute(){ int ChimeraCcodeCommand::driver(linePair* filePos, string outputFName, string filename, string accnos){ try { ofstream out; - openOutputFile(outputFName, out); + m->openOutputFile(outputFName, out); ofstream out2; - openOutputFile(accnos, out2); + m->openOutputFile(accnos, out2); ifstream inFASTA; - openInputFile(filename, inFASTA); + m->openInputFile(filename, inFASTA); inFASTA.seekg(filePos->start); @@ -404,7 +404,7 @@ int ChimeraCcodeCommand::driver(linePair* filePos, string outputFName, string fi if (m->control_pressed) { return 1; } - Sequence* candidateSeq = new Sequence(inFASTA); gobble(inFASTA); + Sequence* candidateSeq = new Sequence(inFASTA); m->gobble(inFASTA); if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file @@ -468,7 +468,7 @@ int ChimeraCcodeCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File istringstream iss (tempBuf,istringstream::in); delete buf4; - Sequence* candidateSeq = new Sequence(iss); gobble(iss); + Sequence* candidateSeq = new Sequence(iss); m->gobble(iss); if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file @@ -523,7 +523,7 @@ int ChimeraCcodeCommand::createProcesses(string outputFileName, string filename, //pass numSeqs to parent ofstream out; string tempFile = outputFileName + toString(getpid()) + ".num.temp"; - openOutputFile(tempFile, out); + m->openOutputFile(tempFile, out); out << num << endl; out.close(); @@ -540,7 +540,7 @@ int ChimeraCcodeCommand::createProcesses(string outputFileName, string filename, for (int i = 0; i < processIDS.size(); i++) { ifstream in; string tempFile = outputFileName + toString(processIDS[i]) + ".num.temp"; - openInputFile(tempFile, in); + m->openInputFile(tempFile, in); if (!in.eof()) { int tempNum = 0; in >> tempNum; num += tempNum; } in.close(); remove(tempFile.c_str()); } diff --git a/chimeracheckcommand.cpp b/chimeracheckcommand.cpp index de6f438..4d99aa4 100644 --- a/chimeracheckcommand.cpp +++ b/chimeracheckcommand.cpp @@ -41,7 +41,7 @@ ChimeraCheckCommand::ChimeraCheckCommand(string option) { it = parameters.find("template"); //user has given a template file if(it != parameters.end()){ - string path = hasPath(it->second); + string path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["template"] = inputDir + it->second; } } @@ -51,12 +51,12 @@ ChimeraCheckCommand::ChimeraCheckCommand(string option) { fastafile = validParameter.validFile(parameters, "fasta", false); if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the chimera.check command."); m->mothurOutEndLine(); abort = true; } else { - splitAtDash(fastafile, fastaFileNames); + m->splitAtDash(fastafile, fastaFileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < fastaFileNames.size(); i++) { if (inputDir != "") { - string path = hasPath(fastaFileNames[i]); + string path = m->hasPath(fastaFileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { fastaFileNames[i] = inputDir + fastaFileNames[i]; } } @@ -64,14 +64,14 @@ ChimeraCheckCommand::ChimeraCheckCommand(string option) { int ableToOpen; ifstream in; - ableToOpen = openInputFile(fastaFileNames[i], in, "noerror"); + ableToOpen = m->openInputFile(fastaFileNames[i], in, "noerror"); //if you can't open it, try default location if (ableToOpen == 1) { if (m->getDefaultPath() != "") { //default path is set - string tryPath = m->getDefaultPath() + getSimpleName(fastaFileNames[i]); + string tryPath = m->getDefaultPath() + m->getSimpleName(fastaFileNames[i]); m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = openInputFile(tryPath, in, "noerror"); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); fastaFileNames[i] = tryPath; } } @@ -99,12 +99,12 @@ ChimeraCheckCommand::ChimeraCheckCommand(string option) { namefile = validParameter.validFile(parameters, "name", false); if (namefile == "not found") { namefile = ""; } else { - splitAtDash(namefile, nameFileNames); + m->splitAtDash(namefile, nameFileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < nameFileNames.size(); i++) { if (inputDir != "") { - string path = hasPath(nameFileNames[i]); + string path = m->hasPath(nameFileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { nameFileNames[i] = inputDir + nameFileNames[i]; } } @@ -112,14 +112,14 @@ ChimeraCheckCommand::ChimeraCheckCommand(string option) { int ableToOpen; ifstream in; - ableToOpen = openInputFile(nameFileNames[i], in, "noerror"); + ableToOpen = m->openInputFile(nameFileNames[i], in, "noerror"); //if you can't open it, try default location if (ableToOpen == 1) { if (m->getDefaultPath() != "") { //default path is set - string tryPath = m->getDefaultPath() + getSimpleName(nameFileNames[i]); + string tryPath = m->getDefaultPath() + m->getSimpleName(nameFileNames[i]); m->mothurOut("Unable to open " + nameFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = openInputFile(tryPath, in, "noerror"); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); nameFileNames[i] = tryPath; } } @@ -150,7 +150,7 @@ ChimeraCheckCommand::ChimeraCheckCommand(string option) { convert(temp, ksize); temp = validParameter.validFile(parameters, "svg", false); if (temp == "not found") { temp = "F"; } - svg = isTrue(temp); + svg = m->isTrue(temp); if (nameFileNames.size() != 0) { svg = true; } temp = validParameter.validFile(parameters, "increment", false); if (temp == "not found") { temp = "10"; } @@ -217,7 +217,7 @@ int ChimeraCheckCommand::execute(){ if (m->control_pressed) { delete chimera; return 0; } - string outputFileName = outputDir + getRootName(getSimpleName(fastaFileNames[i])) + "chimeracheck.chimeras"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[i])) + "chimeracheck.chimeras"; outputNames.push_back(outputFileName); #ifdef USE_MPI @@ -248,7 +248,7 @@ int ChimeraCheckCommand::execute(){ if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } if (pid == 0) { //you are the root process - MPIPos = setFilePosFasta(fastaFileNames[i], numSeqs); //fills MPIPos, returns numSeqs + MPIPos = m->setFilePosFasta(fastaFileNames[i], numSeqs); //fills MPIPos, returns numSeqs //send file positions to all processes for(int j = 1; j < processors; j++) { @@ -299,7 +299,7 @@ int ChimeraCheckCommand::execute(){ MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case #else - vector positions = divideFile(fastaFileNames[i], processors); + vector positions = m->divideFile(fastaFileNames[i], processors); for (int s = 0; s < (positions.size()-1); s++) { lines.push_back(new linePair(positions[s], positions[(s+1)])); @@ -321,7 +321,7 @@ int ChimeraCheckCommand::execute(){ //append output files for(int j=1;jappendFiles((outputFileName + toString(processIDS[j]) + ".temp"), outputFileName); remove((outputFileName + toString(processIDS[j]) + ".temp").c_str()); } @@ -365,12 +365,12 @@ int ChimeraCheckCommand::execute(){ int ChimeraCheckCommand::driver(linePair* filePos, string outputFName, string filename){ try { ofstream out; - openOutputFile(outputFName, out); + m->openOutputFile(outputFName, out); ofstream out2; ifstream inFASTA; - openInputFile(filename, inFASTA); + m->openInputFile(filename, inFASTA); inFASTA.seekg(filePos->start); @@ -381,7 +381,7 @@ int ChimeraCheckCommand::driver(linePair* filePos, string outputFName, string fi if (m->control_pressed) { return 1; } - Sequence* candidateSeq = new Sequence(inFASTA); gobble(inFASTA); + Sequence* candidateSeq = new Sequence(inFASTA); m->gobble(inFASTA); if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file //find chimeras @@ -437,7 +437,7 @@ int ChimeraCheckCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File istringstream iss (tempBuf,istringstream::in); delete buf4; - Sequence* candidateSeq = new Sequence(iss); gobble(iss); + Sequence* candidateSeq = new Sequence(iss); m->gobble(iss); if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file //find chimeras @@ -484,7 +484,7 @@ int ChimeraCheckCommand::createProcesses(string outputFileName, string filename) //pass numSeqs to parent ofstream out; string tempFile = outputFileName + toString(getpid()) + ".num.temp"; - openOutputFile(tempFile, out); + m->openOutputFile(tempFile, out); out << num << endl; out.close(); @@ -501,7 +501,7 @@ int ChimeraCheckCommand::createProcesses(string outputFileName, string filename) for (int i = 0; i < processIDS.size(); i++) { ifstream in; string tempFile = outputFileName + toString(processIDS[i]) + ".num.temp"; - openInputFile(tempFile, in); + m->openInputFile(tempFile, in); if (!in.eof()) { int tempNum = 0; in >> tempNum; num += tempNum; } in.close(); remove(tempFile.c_str()); } diff --git a/chimeracheckrdp.cpp b/chimeracheckrdp.cpp index e89277b..1840c38 100644 --- a/chimeracheckrdp.cpp +++ b/chimeracheckrdp.cpp @@ -283,7 +283,7 @@ void ChimeraCheckRDP::readName(string namefile) { delete buffer; while(!iss.eof()) { - iss >> name; gobble(iss); + iss >> name; m->gobble(iss); names[name] = name; } @@ -292,10 +292,10 @@ void ChimeraCheckRDP::readName(string namefile) { #else ifstream in; - openInputFile(namefile, in); + m->openInputFile(namefile, in); while (!in.eof()) { - in >> name; gobble(in); + in >> name; m->gobble(in); names[name] = name; } in.close(); @@ -432,7 +432,7 @@ void ChimeraCheckRDP::makeSVGpic(vector info) { string file = outputDir + querySeq->getName() + ".chimeracheck.svg"; ofstream outsvg; - openOutputFile(file, outsvg); + m->openOutputFile(file, outsvg); int width = (info.size()*5) + 150; diff --git a/chimerapintailcommand.cpp b/chimerapintailcommand.cpp index 9e1bfe1..a8a85eb 100644 --- a/chimerapintailcommand.cpp +++ b/chimerapintailcommand.cpp @@ -43,7 +43,7 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { it = parameters.find("template"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["template"] = inputDir + it->second; } } @@ -51,7 +51,7 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { it = parameters.find("conservation"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["conservation"] = inputDir + it->second; } } @@ -59,7 +59,7 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { it = parameters.find("quantile"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["quantile"] = inputDir + it->second; } } @@ -70,12 +70,12 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { fastafile = validParameter.validFile(parameters, "fasta", false); if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the chimera.pintail command."); m->mothurOutEndLine(); abort = true; } else { - splitAtDash(fastafile, fastaFileNames); + m->splitAtDash(fastafile, fastaFileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < fastaFileNames.size(); i++) { if (inputDir != "") { - string path = hasPath(fastaFileNames[i]); + string path = m->hasPath(fastaFileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { fastaFileNames[i] = inputDir + fastaFileNames[i]; } } @@ -83,14 +83,14 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { int ableToOpen; ifstream in; - ableToOpen = openInputFile(fastaFileNames[i], in, "noerror"); + ableToOpen = m->openInputFile(fastaFileNames[i], in, "noerror"); //if you can't open it, try default location if (ableToOpen == 1) { if (m->getDefaultPath() != "") { //default path is set - string tryPath = m->getDefaultPath() + getSimpleName(fastaFileNames[i]); + string tryPath = m->getDefaultPath() + m->getSimpleName(fastaFileNames[i]); m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = openInputFile(tryPath, in, "noerror"); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); fastaFileNames[i] = tryPath; } } @@ -110,7 +110,7 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { string temp; temp = validParameter.validFile(parameters, "filter", false); if (temp == "not found") { temp = "F"; } - filter = isTrue(temp); + filter = m->isTrue(temp); temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found") { temp = "1"; } convert(temp, processors); @@ -125,13 +125,13 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { if (maskfile == "not found") { maskfile = ""; } else if (maskfile != "default") { if (inputDir != "") { - string path = hasPath(maskfile); + string path = m->hasPath(maskfile); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { maskfile = inputDir + maskfile; } } ifstream in; - int ableToOpen = openInputFile(maskfile, in); + int ableToOpen = m->openInputFile(maskfile, in); if (ableToOpen == 1) { abort = true; } in.close(); } @@ -140,7 +140,7 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(fastafile); //if user entered a file with a path then preserve it + outputDir += m->hasPath(fastafile); //if user entered a file with a path then preserve it } templatefile = validParameter.validFile(parameters, "template", true); @@ -152,10 +152,10 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { else if (consfile == "not found") { consfile = ""; //check for consfile - string tempConsFile = getRootName(inputDir + getSimpleName(templatefile)) + "freq"; + string tempConsFile = m->getRootName(inputDir + m->getSimpleName(templatefile)) + "freq"; ifstream FileTest(tempConsFile.c_str()); if(FileTest){ - bool GoodFile = checkReleaseVersion(FileTest, m->getVersion()); + bool GoodFile = m->checkReleaseVersion(FileTest, m->getVersion()); if (GoodFile) { m->mothurOut("I found " + tempConsFile + " in your input file directory. I will use it to save time."); m->mothurOutEndLine(); consfile = tempConsFile; FileTest.close(); } @@ -227,18 +227,18 @@ int ChimeraPintailCommand::execute(){ //check for quantile to save the time string tempQuan = ""; if ((!filter) && (maskfile == "")) { - tempQuan = inputDir + getRootName(getSimpleName(templatefile)) + "pintail.quan"; + tempQuan = inputDir + m->getRootName(m->getSimpleName(templatefile)) + "pintail.quan"; }else if ((!filter) && (maskfile != "")) { - tempQuan = inputDir + getRootName(getSimpleName(templatefile)) + "pintail.masked.quan"; + tempQuan = inputDir + m->getRootName(m->getSimpleName(templatefile)) + "pintail.masked.quan"; }else if ((filter) && (maskfile != "")) { - tempQuan = inputDir + getRootName(getSimpleName(templatefile)) + "pintail.filtered." + getSimpleName(getRootName(fastaFileNames[s])) + "masked.quan"; + tempQuan = inputDir + m->getRootName(m->getSimpleName(templatefile)) + "pintail.filtered." + m->getSimpleName(m->getRootName(fastaFileNames[s])) + "masked.quan"; }else if ((filter) && (maskfile == "")) { - tempQuan = inputDir + getRootName(getSimpleName(templatefile)) + "pintail.filtered." + getSimpleName(getRootName(fastaFileNames[s])) + "quan"; + tempQuan = inputDir + m->getRootName(m->getSimpleName(templatefile)) + "pintail.filtered." + m->getSimpleName(m->getRootName(fastaFileNames[s])) + "quan"; } ifstream FileTest(tempQuan.c_str()); if(FileTest){ - bool GoodFile = checkReleaseVersion(FileTest, m->getVersion()); + bool GoodFile = m->checkReleaseVersion(FileTest, m->getVersion()); if (GoodFile) { m->mothurOut("I found " + tempQuan + " in your input file directory. I will use it to save time."); m->mothurOutEndLine(); quanfile = tempQuan; FileTest.close(); } @@ -248,11 +248,11 @@ int ChimeraPintailCommand::execute(){ string outputFileName, accnosFileName; if (maskfile != "") { - outputFileName = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + maskfile + ".pintail.chimeras"; - accnosFileName = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + maskfile + ".pintail.accnos"; + outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + maskfile + ".pintail.chimeras"; + accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + maskfile + ".pintail.accnos"; }else { - outputFileName = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "pintail.chimeras"; - accnosFileName = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "pintail.accnos"; + outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "pintail.chimeras"; + accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "pintail.accnos"; } if (m->control_pressed) { delete chimera; for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; } @@ -297,7 +297,7 @@ int ChimeraPintailCommand::execute(){ if (pid == 0) { //you are the root process - MPIPos = setFilePosFasta(fastaFileNames[s], numSeqs); //fills MPIPos, returns numSeqs + MPIPos = m->setFilePosFasta(fastaFileNames[s], numSeqs); //fills MPIPos, returns numSeqs //send file positions to all processes for(int i = 1; i < processors; i++) { @@ -337,7 +337,7 @@ int ChimeraPintailCommand::execute(){ MPI_File_close(&outMPIAccnos); MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case #else - vector positions = divideFile(fastaFileNames[s], processors); + vector positions = m->divideFile(fastaFileNames[s], processors); for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(new linePair(positions[i], positions[(i+1)])); @@ -361,13 +361,13 @@ int ChimeraPintailCommand::execute(){ //append output files for(int i=1;iappendFiles((outputFileName + toString(processIDS[i]) + ".temp"), outputFileName); remove((outputFileName + toString(processIDS[i]) + ".temp").c_str()); } //append output files for(int i=1;iappendFiles((accnosFileName + toString(processIDS[i]) + ".temp"), accnosFileName); remove((accnosFileName + toString(processIDS[i]) + ".temp").c_str()); } @@ -417,13 +417,13 @@ int ChimeraPintailCommand::execute(){ int ChimeraPintailCommand::driver(linePair* filePos, string outputFName, string filename, string accnos){ try { ofstream out; - openOutputFile(outputFName, out); + m->openOutputFile(outputFName, out); ofstream out2; - openOutputFile(accnos, out2); + m->openOutputFile(accnos, out2); ifstream inFASTA; - openInputFile(filename, inFASTA); + m->openInputFile(filename, inFASTA); inFASTA.seekg(filePos->start); @@ -434,7 +434,7 @@ int ChimeraPintailCommand::driver(linePair* filePos, string outputFName, string if (m->control_pressed) { return 1; } - Sequence* candidateSeq = new Sequence(inFASTA); gobble(inFASTA); + Sequence* candidateSeq = new Sequence(inFASTA); m->gobble(inFASTA); if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file @@ -497,7 +497,7 @@ int ChimeraPintailCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_Fi istringstream iss (tempBuf,istringstream::in); delete buf4; - Sequence* candidateSeq = new Sequence(iss); gobble(iss); + Sequence* candidateSeq = new Sequence(iss); m->gobble(iss); if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file @@ -552,7 +552,7 @@ int ChimeraPintailCommand::createProcesses(string outputFileName, string filenam //pass numSeqs to parent ofstream out; string tempFile = outputFileName + toString(getpid()) + ".num.temp"; - openOutputFile(tempFile, out); + m->openOutputFile(tempFile, out); out << num << endl; out.close(); @@ -569,7 +569,7 @@ int ChimeraPintailCommand::createProcesses(string outputFileName, string filenam for (int i = 0; i < processIDS.size(); i++) { ifstream in; string tempFile = outputFileName + toString(processIDS[i]) + ".num.temp"; - openInputFile(tempFile, in); + m->openInputFile(tempFile, in); if (!in.eof()) { int tempNum = 0; in >> tempNum; num += tempNum; } in.close(); remove(tempFile.c_str()); } diff --git a/chimeraslayer.cpp b/chimeraslayer.cpp index ff13590..1bfdafe 100644 --- a/chimeraslayer.cpp +++ b/chimeraslayer.cpp @@ -105,7 +105,7 @@ int ChimeraSlayer::doPrep() { bool needToGenerateLeft = true; if(kmerFileTestLeft){ - bool GoodFile = checkReleaseVersion(kmerFileTestLeft, m->getVersion()); + bool GoodFile = m->checkReleaseVersion(kmerFileTestLeft, m->getVersion()); if (GoodFile) { needToGenerateLeft = false; } } @@ -136,7 +136,7 @@ int ChimeraSlayer::doPrep() { bool needToGenerateRight = true; if(kmerFileTestRight){ - bool GoodFile = checkReleaseVersion(kmerFileTestRight, m->getVersion()); + bool GoodFile = m->checkReleaseVersion(kmerFileTestRight, m->getVersion()); if (GoodFile) { needToGenerateRight = false; } } diff --git a/chimeraslayercommand.cpp b/chimeraslayercommand.cpp index 35f3b98..8a80d4d 100644 --- a/chimeraslayercommand.cpp +++ b/chimeraslayercommand.cpp @@ -45,7 +45,7 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option) { it = parameters.find("template"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["template"] = inputDir + it->second; } } @@ -56,12 +56,12 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option) { fastafile = validParameter.validFile(parameters, "fasta", false); if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the chimera.slayer command."); m->mothurOutEndLine(); abort = true; } else { - splitAtDash(fastafile, fastaFileNames); + m->splitAtDash(fastafile, fastaFileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < fastaFileNames.size(); i++) { if (inputDir != "") { - string path = hasPath(fastaFileNames[i]); + string path = m->hasPath(fastaFileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { fastaFileNames[i] = inputDir + fastaFileNames[i]; } } @@ -69,14 +69,14 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option) { int ableToOpen; ifstream in; - ableToOpen = openInputFile(fastaFileNames[i], in, "noerror"); + ableToOpen = m->openInputFile(fastaFileNames[i], in, "noerror"); //if you can't open it, try default location if (ableToOpen == 1) { if (m->getDefaultPath() != "") { //default path is set - string tryPath = m->getDefaultPath() + getSimpleName(fastaFileNames[i]); + string tryPath = m->getDefaultPath() + m->getSimpleName(fastaFileNames[i]); m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = openInputFile(tryPath, in, "noerror"); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); fastaFileNames[i] = tryPath; } } @@ -97,7 +97,7 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(fastafile); //if user entered a file with a path then preserve it + outputDir += m->hasPath(fastafile); //if user entered a file with a path then preserve it } templatefile = validParameter.validFile(parameters, "template", true); @@ -138,7 +138,7 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option) { convert(temp, parents); temp = validParameter.validFile(parameters, "realign", false); if (temp == "not found") { temp = "f"; } - realign = isTrue(temp); + realign = m->isTrue(temp); search = validParameter.validFile(parameters, "search", false); if (search == "not found") { search = "distance"; } @@ -219,8 +219,8 @@ int ChimeraSlayerCommand::execute(){ chimera = new ChimeraSlayer(fastaFileNames[s], templatefile, search, ksize, match, mismatch, window, divR, minSimilarity, minCoverage, minBS, minSNP, parents, iters, increment, numwanted, realign); - string outputFileName = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "slayer.chimeras"; - string accnosFileName = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "slayer.accnos"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "slayer.chimeras"; + string accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "slayer.accnos"; if (m->control_pressed) { delete chimera; for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; } @@ -277,7 +277,7 @@ int ChimeraSlayerCommand::execute(){ MPI_File_write_shared(outMPI, buf2, length, MPI_CHAR, &status); delete buf2; - MPIPos = setFilePosFasta(fastaFileNames[s], numSeqs); //fills MPIPos, returns numSeqs + MPIPos = m->setFilePosFasta(fastaFileNames[s], numSeqs); //fills MPIPos, returns numSeqs //send file positions to all processes for(int i = 1; i < processors; i++) { @@ -319,13 +319,13 @@ int ChimeraSlayerCommand::execute(){ #else ofstream outHeader; - string tempHeader = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "slayer.chimeras.tempHeader"; - openOutputFile(tempHeader, outHeader); + string tempHeader = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "slayer.chimeras.tempHeader"; + m->openOutputFile(tempHeader, outHeader); chimera->printHeader(outHeader); outHeader.close(); - vector positions = divideFile(fastaFileNames[s], processors); + vector positions = m->divideFile(fastaFileNames[s], processors); for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(new linePair(positions[i], positions[(i+1)])); @@ -348,13 +348,13 @@ int ChimeraSlayerCommand::execute(){ //append output files for(int i=1;iappendFiles((outputFileName + toString(processIDS[i]) + ".temp"), outputFileName); remove((outputFileName + toString(processIDS[i]) + ".temp").c_str()); } //append output files for(int i=1;iappendFiles((accnosFileName + toString(processIDS[i]) + ".temp"), accnosFileName); remove((accnosFileName + toString(processIDS[i]) + ".temp").c_str()); } @@ -368,7 +368,7 @@ int ChimeraSlayerCommand::execute(){ #endif - appendFiles(outputFileName, tempHeader); + m->appendFiles(outputFileName, tempHeader); remove(outputFileName.c_str()); rename(tempHeader.c_str(), outputFileName.c_str()); @@ -403,13 +403,13 @@ int ChimeraSlayerCommand::execute(){ int ChimeraSlayerCommand::driver(linePair* filePos, string outputFName, string filename, string accnos){ try { ofstream out; - openOutputFile(outputFName, out); + m->openOutputFile(outputFName, out); ofstream out2; - openOutputFile(accnos, out2); + m->openOutputFile(accnos, out2); ifstream inFASTA; - openInputFile(filename, inFASTA); + m->openInputFile(filename, inFASTA); inFASTA.seekg(filePos->start); @@ -420,7 +420,7 @@ int ChimeraSlayerCommand::driver(linePair* filePos, string outputFName, string f if (m->control_pressed) { return 1; } - Sequence* candidateSeq = new Sequence(inFASTA); gobble(inFASTA); + Sequence* candidateSeq = new Sequence(inFASTA); m->gobble(inFASTA); if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file @@ -483,7 +483,7 @@ int ChimeraSlayerCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_Fil delete buf4; - Sequence* candidateSeq = new Sequence(iss); gobble(iss); + Sequence* candidateSeq = new Sequence(iss); m->gobble(iss); if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file @@ -539,7 +539,7 @@ int ChimeraSlayerCommand::createProcesses(string outputFileName, string filename //pass numSeqs to parent ofstream out; string tempFile = outputFileName + toString(getpid()) + ".num.temp"; - openOutputFile(tempFile, out); + m->openOutputFile(tempFile, out); out << num << endl; out.close(); @@ -556,7 +556,7 @@ int ChimeraSlayerCommand::createProcesses(string outputFileName, string filename for (int i = 0; i < processIDS.size(); i++) { ifstream in; string tempFile = outputFileName + toString(processIDS[i]) + ".num.temp"; - openInputFile(tempFile, in); + m->openInputFile(tempFile, in); if (!in.eof()) { int tempNum = 0; in >> tempNum; num += tempNum; } in.close(); remove(tempFile.c_str()); } diff --git a/chopseqscommand.cpp b/chopseqscommand.cpp index 2eabbc1..12e48f4 100644 --- a/chopseqscommand.cpp +++ b/chopseqscommand.cpp @@ -46,7 +46,7 @@ ChopSeqsCommand::ChopSeqsCommand(string option) { it = parameters.find("fasta"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } @@ -61,7 +61,7 @@ ChopSeqsCommand::ChopSeqsCommand(string option) { convert(temp, numbases); temp = validParameter.validFile(parameters, "countgaps", false); if (temp == "not found") { temp = "f"; } - countGaps = isTrue(temp); + countGaps = m->isTrue(temp); keep = validParameter.validFile(parameters, "keep", false); if (keep == "not found") { keep = "front"; } @@ -100,17 +100,17 @@ int ChopSeqsCommand::execute(){ if (abort == true) { return 0; } - string outputFileName = outputDir + getRootName(getSimpleName(fastafile)) + "chop.fasta"; - string outputFileNameAccnos = outputDir + getRootName(getSimpleName(fastafile)) + "chop.accnos"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "chop.fasta"; + string outputFileNameAccnos = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "chop.accnos"; ofstream out; - openOutputFile(outputFileName, out); + m->openOutputFile(outputFileName, out); ofstream outAcc; - openOutputFile(outputFileNameAccnos, outAcc); + m->openOutputFile(outputFileNameAccnos, outAcc); ifstream in; - openInputFile(fastafile, in); + m->openInputFile(fastafile, in); bool wroteAccnos = false; diff --git a/classify.cpp b/classify.cpp index 59a6158..875628d 100644 --- a/classify.cpp +++ b/classify.cpp @@ -46,7 +46,7 @@ void Classify::generateDatabaseAndNames(string tfile, string tempFile, string me //delete inFileName; if (pid == 0) { //only one process needs to scan file - positions = setFilePosFasta(tempFile, numSeqs); //fills MPIPos, returns numSeqs + positions = m->setFilePosFasta(tempFile, numSeqs); //fills MPIPos, returns numSeqs //send file positions to all processes for(int i = 1; i < processors; i++) { @@ -96,8 +96,8 @@ void Classify::generateDatabaseAndNames(string tfile, string tempFile, string me //need to know number of template seqs for suffixdb if (method == "suffix") { ifstream inFASTA; - openInputFile(tempFile, inFASTA); - getNumSeqs(inFASTA, numSeqs); + m->openInputFile(tempFile, inFASTA); + m->getNumSeqs(inFASTA, numSeqs); inFASTA.close(); } @@ -109,7 +109,7 @@ void Classify::generateDatabaseAndNames(string tfile, string tempFile, string me kmerDBName = tempFile.substr(0,tempFile.find_last_of(".")+1) + char('0'+ kmerSize) + "mer"; ifstream kmerFileTest(kmerDBName.c_str()); if(kmerFileTest){ - bool GoodFile = checkReleaseVersion(kmerFileTest, m->getVersion()); + bool GoodFile = m->checkReleaseVersion(kmerFileTest, m->getVersion()); if (GoodFile) { needToGenerate = false; } } } @@ -124,11 +124,11 @@ void Classify::generateDatabaseAndNames(string tfile, string tempFile, string me if (needToGenerate) { ifstream fastaFile; - openInputFile(tempFile, fastaFile); + m->openInputFile(tempFile, fastaFile); while (!fastaFile.eof()) { Sequence temp(fastaFile); - gobble(fastaFile); + m->gobble(fastaFile); names.push_back(temp.getName()); @@ -143,11 +143,11 @@ void Classify::generateDatabaseAndNames(string tfile, string tempFile, string me database->readKmerDB(kmerFileTest); ifstream fastaFile; - openInputFile(tempFile, fastaFile); + m->openInputFile(tempFile, fastaFile); while (!fastaFile.eof()) { Sequence temp(fastaFile); - gobble(fastaFile); + m->gobble(fastaFile); names.push_back(temp.getName()); } @@ -204,7 +204,7 @@ int Classify::readTaxonomy(string file) { //delete inFileName; if (pid == 0) { - positions = setFilePosEachLine(file, num); + positions = m->setFilePosEachLine(file, num); //send file positions to all processes for(int i = 1; i < processors; i++) { @@ -239,7 +239,7 @@ int Classify::readTaxonomy(string file) { MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case #else ifstream inTax; - openInputFile(file, inTax); + m->openInputFile(file, inTax); //read template seqs and save while (!inTax.eof()) { @@ -249,7 +249,7 @@ int Classify::readTaxonomy(string file) { phyloTree->addSeqToTree(name, taxInfo); - gobble(inTax); + m->gobble(inTax); } inTax.close(); #endif diff --git a/classifyotucommand.cpp b/classifyotucommand.cpp index 00f04b0..0e23461 100644 --- a/classifyotucommand.cpp +++ b/classifyotucommand.cpp @@ -45,7 +45,7 @@ ClassifyOtuCommand::ClassifyOtuCommand(string option) { it = parameters.find("list"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["list"] = inputDir + it->second; } } @@ -53,7 +53,7 @@ ClassifyOtuCommand::ClassifyOtuCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -61,7 +61,7 @@ ClassifyOtuCommand::ClassifyOtuCommand(string option) { it = parameters.find("taxonomy"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["taxonomy"] = inputDir + it->second; } } @@ -89,7 +89,7 @@ ClassifyOtuCommand::ClassifyOtuCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; allLines = 1; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -97,7 +97,7 @@ ClassifyOtuCommand::ClassifyOtuCommand(string option) { convert(temp, cutoff); temp = validParameter.validFile(parameters, "probs", false); if (temp == "not found"){ temp = "true"; } - probs = isTrue(temp); + probs = m->isTrue(temp); if ((cutoff < 51) || (cutoff > 100)) { m->mothurOut("cutoff must be above 50, and no greater than 100."); m->mothurOutEndLine(); abort = true; } @@ -171,7 +171,7 @@ int ClassifyOtuCommand::execute(){ userLabels.erase(list->getLabel()); } - if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = list->getLabel(); delete list; @@ -241,18 +241,18 @@ int ClassifyOtuCommand::readNamesFile() { try { ifstream inNames; - openInputFile(namefile, inNames); + m->openInputFile(namefile, inNames); string name, names; while(inNames){ inNames >> name; //read from first column A inNames >> names; //read from second column A,B,C,D - gobble(inNames); + m->gobble(inNames); //parse names into vector vector theseNames; - splitAtComma(names, theseNames); + m->splitAtComma(names, theseNames); for (int i = 0; i < theseNames.size(); i++) { nameMap[theseNames[i]] = name; } @@ -272,13 +272,13 @@ int ClassifyOtuCommand::readTaxonomyFile() { try { ifstream in; - openInputFile(taxfile, in); + m->openInputFile(taxfile, in); string name, tax; while(!in.eof()){ in >> name >> tax; - gobble(in); + m->gobble(in); //are there confidence scores, if so remove them if (tax.find_first_of('(') != -1) { removeConfidences(tax); } @@ -306,7 +306,7 @@ string ClassifyOtuCommand::findConsensusTaxonomy(int bin, ListVector* thisList, //parse names into vector string binnames = thisList->get(bin); - splitAtComma(binnames, names); + m->splitAtComma(binnames, names); //create a tree containing sequences from this bin PhyloTree* phylo = new PhyloTree(); @@ -417,11 +417,11 @@ int ClassifyOtuCommand::process(ListVector* processList) { int size; //create output file - if (outputDir == "") { outputDir += hasPath(listfile); } + if (outputDir == "") { outputDir += m->hasPath(listfile); } ofstream out; - string outputFile = outputDir + getRootName(getSimpleName(listfile)) + processList->getLabel() + ".cons.taxonomy"; - openOutputFile(outputFile, out); + string outputFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + ".cons.taxonomy"; + m->openOutputFile(outputFile, out); outputNames.push_back(outputFile); //for each bin in the list vector diff --git a/classifyseqscommand.cpp b/classifyseqscommand.cpp index c8c0d72..e934d9d 100644 --- a/classifyseqscommand.cpp +++ b/classifyseqscommand.cpp @@ -51,7 +51,7 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { it = parameters.find("template"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["template"] = inputDir + it->second; } } @@ -59,7 +59,7 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { it = parameters.find("taxonomy"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["taxonomy"] = inputDir + it->second; } } @@ -67,7 +67,7 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { it = parameters.find("group"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["group"] = inputDir + it->second; } } @@ -86,12 +86,12 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { fastaFileName = validParameter.validFile(parameters, "fasta", false); if (fastaFileName == "not found") { m->mothurOut("fasta is a required parameter for the classify.seqs command."); m->mothurOutEndLine(); abort = true; } else { - splitAtDash(fastaFileName, fastaFileNames); + m->splitAtDash(fastaFileName, fastaFileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < fastaFileNames.size(); i++) { if (inputDir != "") { - string path = hasPath(fastaFileNames[i]); + string path = m->hasPath(fastaFileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { fastaFileNames[i] = inputDir + fastaFileNames[i]; } } @@ -99,14 +99,14 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { int ableToOpen; ifstream in; - ableToOpen = openInputFile(fastaFileNames[i], in, "noerror"); + ableToOpen = m->openInputFile(fastaFileNames[i], in, "noerror"); //if you can't open it, try default location if (ableToOpen == 1) { if (m->getDefaultPath() != "") { //default path is set - string tryPath = m->getDefaultPath() + getSimpleName(fastaFileNames[i]); + string tryPath = m->getDefaultPath() + m->getSimpleName(fastaFileNames[i]); m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = openInputFile(tryPath, in, "noerror"); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); fastaFileNames[i] = tryPath; } } @@ -139,26 +139,26 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { if (namefile == "not found") { namefile = ""; } else { - splitAtDash(namefile, namefileNames); + m->splitAtDash(namefile, namefileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < namefileNames.size(); i++) { if (inputDir != "") { - string path = hasPath(namefileNames[i]); + string path = m->hasPath(namefileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { namefileNames[i] = inputDir + namefileNames[i]; } } int ableToOpen; ifstream in; - ableToOpen = openInputFile(namefileNames[i], in, "noerror"); + ableToOpen = m->openInputFile(namefileNames[i], in, "noerror"); //if you can't open it, try default location if (ableToOpen == 1) { if (m->getDefaultPath() != "") { //default path is set - string tryPath = m->getDefaultPath() + getSimpleName(namefileNames[i]); + string tryPath = m->getDefaultPath() + m->getSimpleName(namefileNames[i]); m->mothurOut("Unable to open " + namefileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = openInputFile(tryPath, in, "noerror"); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); namefileNames[i] = tryPath; } } @@ -181,26 +181,26 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { groupfile = validParameter.validFile(parameters, "group", false); if (groupfile == "not found") { groupfile = ""; } else { - splitAtDash(groupfile, groupfileNames); + m->splitAtDash(groupfile, groupfileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < groupfileNames.size(); i++) { if (inputDir != "") { - string path = hasPath(groupfileNames[i]); + string path = m->hasPath(groupfileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { groupfileNames[i] = inputDir + groupfileNames[i]; } } int ableToOpen; ifstream in; - ableToOpen = openInputFile(groupfileNames[i], in, "noerror"); + ableToOpen = m->openInputFile(groupfileNames[i], in, "noerror"); //if you can't open it, try default location if (ableToOpen == 1) { if (m->getDefaultPath() != "") { //default path is set - string tryPath = m->getDefaultPath() + getSimpleName(groupfileNames[i]); + string tryPath = m->getDefaultPath() + m->getSimpleName(groupfileNames[i]); m->mothurOut("Unable to open " + groupfileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = openInputFile(tryPath, in, "noerror"); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); groupfileNames[i] = tryPath; } } @@ -253,7 +253,7 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { convert(temp, cutoff); temp = validParameter.validFile(parameters, "probs", false); if (temp == "not found"){ temp = "true"; } - probs = isTrue(temp); + probs = m->isTrue(temp); temp = validParameter.validFile(parameters, "iters", false); if (temp == "not found") { temp = "100"; } convert(temp, iters); @@ -342,18 +342,18 @@ int ClassifySeqsCommand::execute(){ m->mothurOut("Classifying sequences from " + fastaFileNames[s] + " ..." ); m->mothurOutEndLine(); - string RippedTaxName = getRootName(getSimpleName(taxonomyFileName)); - RippedTaxName = getExtension(RippedTaxName.substr(0, RippedTaxName.length()-1)); + string RippedTaxName = m->getRootName(m->getSimpleName(taxonomyFileName)); + RippedTaxName = m->getExtension(RippedTaxName.substr(0, RippedTaxName.length()-1)); if (RippedTaxName[0] == '.') { RippedTaxName = RippedTaxName.substr(1, RippedTaxName.length()); } RippedTaxName += "."; - if (outputDir == "") { outputDir += hasPath(fastaFileNames[s]); } - string newTaxonomyFile = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + RippedTaxName + "taxonomy"; - string tempTaxonomyFile = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "taxonomy.temp"; - string taxSummary = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + RippedTaxName + "tax.summary"; + if (outputDir == "") { outputDir += m->hasPath(fastaFileNames[s]); } + string newTaxonomyFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + RippedTaxName + "taxonomy"; + string tempTaxonomyFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "taxonomy.temp"; + string taxSummary = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + RippedTaxName + "tax.summary"; if ((method == "knn") && (search == "distance")) { - string DistName = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "match.dist"; + string DistName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "match.dist"; classify->setDistName(DistName); outputNames.push_back(DistName); } @@ -410,7 +410,7 @@ int ClassifySeqsCommand::execute(){ if (pid == 0) { //you are the root process - MPIPos = setFilePosFasta(fastaFileNames[s], numFastaSeqs); //fills MPIPos, returns numSeqs + MPIPos = m->setFilePosFasta(fastaFileNames[s], numFastaSeqs); //fills MPIPos, returns numSeqs //send file positions to all processes for(int i = 1; i < processors; i++) { @@ -461,7 +461,7 @@ int ClassifySeqsCommand::execute(){ #else - vector positions = divideFile(fastaFileNames[s], processors); + vector positions = m->divideFile(fastaFileNames[s], processors); for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(new linePair(positions[i], positions[(i+1)])); @@ -510,14 +510,14 @@ int ClassifySeqsCommand::execute(){ nameMap.clear(); //remove old names ifstream inNames; - openInputFile(namefileNames[s], inNames); + m->openInputFile(namefileNames[s], inNames); string firstCol, secondCol; while(!inNames.eof()) { - inNames >> firstCol >> secondCol; gobble(inNames); + inNames >> firstCol >> secondCol; m->gobble(inNames); vector temp; - splitAtComma(secondCol, temp); + m->splitAtComma(secondCol, temp); nameMap[firstCol] = temp; } @@ -537,13 +537,13 @@ int ClassifySeqsCommand::execute(){ if (namefile == "") { taxaSum.summarize(tempTaxonomyFile); } else { ifstream in; - openInputFile(tempTaxonomyFile, in); + m->openInputFile(tempTaxonomyFile, in); //read in users taxonomy file and add sequences to tree string name, taxon; while(!in.eof()){ - in >> name >> taxon; gobble(in); + in >> name >> taxon; m->gobble(in); itNames = nameMap.find(name); @@ -565,17 +565,17 @@ int ClassifySeqsCommand::execute(){ //print summary file ofstream outTaxTree; - openOutputFile(taxSummary, outTaxTree); + m->openOutputFile(taxSummary, outTaxTree); taxaSum.print(outTaxTree); outTaxTree.close(); //output taxonomy with the unclassified bins added ifstream inTax; - openInputFile(newTaxonomyFile, inTax); + m->openInputFile(newTaxonomyFile, inTax); ofstream outTax; string unclass = newTaxonomyFile + ".unclass.temp"; - openOutputFile(unclass, outTax); + m->openOutputFile(unclass, outTax); //get maxLevel from phylotree so you know how many 'unclassified's to add int maxLevel = taxaSum.getMaxLevel(); @@ -585,7 +585,7 @@ int ClassifySeqsCommand::execute(){ while (!inTax.eof()) { if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } remove(unclass.c_str()); delete classify; return 0; } - inTax >> name >> taxon; gobble(inTax); + inTax >> name >> taxon; m->gobble(inTax); string newTax = addUnclassifieds(taxon, maxLevel); @@ -669,7 +669,7 @@ int ClassifySeqsCommand::createProcesses(string taxFileName, string tempTaxFile, //pass numSeqs to parent ofstream out; string tempFile = filename + toString(getpid()) + ".num.temp"; - openOutputFile(tempFile, out); + m->openOutputFile(tempFile, out); out << num << endl; out.close(); @@ -686,7 +686,7 @@ int ClassifySeqsCommand::createProcesses(string taxFileName, string tempTaxFile, for (int i = 0; i < processIDS.size(); i++) { ifstream in; string tempFile = filename + toString(processIDS[i]) + ".num.temp"; - openInputFile(tempFile, in); + m->openInputFile(tempFile, in); if (!in.eof()) { int tempNum = 0; in >> tempNum; num += tempNum; } in.close(); remove(tempFile.c_str()); } @@ -706,8 +706,8 @@ void ClassifySeqsCommand::appendTaxFiles(string temp, string filename) { ofstream output; ifstream input; - openOutputFileAppend(filename, output); - openInputFile(temp, input); + m->openOutputFileAppend(filename, output); + m->openInputFile(temp, input); while(char c = input.get()){ if(input.eof()) { break; } @@ -728,13 +728,13 @@ void ClassifySeqsCommand::appendTaxFiles(string temp, string filename) { int ClassifySeqsCommand::driver(linePair* filePos, string taxFName, string tempTFName, string filename){ try { ofstream outTax; - openOutputFile(taxFName, outTax); + m->openOutputFile(taxFName, outTax); ofstream outTaxSimple; - openOutputFile(tempTFName, outTaxSimple); + m->openOutputFile(tempTFName, outTaxSimple); ifstream inFASTA; - openInputFile(filename, inFASTA); + m->openInputFile(filename, inFASTA); string taxonomy; @@ -746,7 +746,7 @@ int ClassifySeqsCommand::driver(linePair* filePos, string taxFName, string tempT while (!done) { if (m->control_pressed) { return 0; } - Sequence* candidateSeq = new Sequence(inFASTA); gobble(inFASTA); + Sequence* candidateSeq = new Sequence(inFASTA); m->gobble(inFASTA); if (candidateSeq->getName() != "") { taxonomy = classify->getTaxonomy(candidateSeq); @@ -890,10 +890,10 @@ int ClassifySeqsCommand::MPIReadNamesFile(string nameFilename){ string firstCol, secondCol; while(!iss.eof()) { - iss >> firstCol >> secondCol; gobble(iss); + iss >> firstCol >> secondCol; m->gobble(iss); vector temp; - splitAtComma(secondCol, temp); + m->splitAtComma(secondCol, temp); nameMap[firstCol] = temp; } diff --git a/clearcutcommand.cpp b/clearcutcommand.cpp index b1f40e0..d6c284d 100644 --- a/clearcutcommand.cpp +++ b/clearcutcommand.cpp @@ -42,7 +42,7 @@ ClearcutCommand::ClearcutCommand(string option) { it = parameters.find("fasta"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } @@ -50,7 +50,7 @@ ClearcutCommand::ClearcutCommand(string option) { it = parameters.find("phylip"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["phylip"] = inputDir + it->second; } } @@ -72,53 +72,53 @@ ClearcutCommand::ClearcutCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter - outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = hasPath(inputFile); } + outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(inputFile); } string temp; temp = validParameter.validFile(parameters, "version", false); if (temp == "not found"){ temp = "F"; } - version = isTrue(temp); + version = m->isTrue(temp); temp = validParameter.validFile(parameters, "verbose", false); if (temp == "not found"){ temp = "F"; } - verbose = isTrue(temp); + verbose = m->isTrue(temp); temp = validParameter.validFile(parameters, "quiet", false); if (temp == "not found"){ temp = "F"; } - quiet = isTrue(temp); + quiet = m->isTrue(temp); seed = validParameter.validFile(parameters, "seed", false); if (seed == "not found"){ seed = "*"; } temp = validParameter.validFile(parameters, "norandom", false); if (temp == "not found"){ temp = "F"; } - norandom = isTrue(temp); + norandom = m->isTrue(temp); temp = validParameter.validFile(parameters, "shuffle", false); if (temp == "not found"){ temp = "F"; } - shuffle = isTrue(temp); + shuffle = m->isTrue(temp); temp = validParameter.validFile(parameters, "neighbor", false); if (temp == "not found"){ temp = "T"; } - neighbor = isTrue(temp); + neighbor = m->isTrue(temp); temp = validParameter.validFile(parameters, "DNA", false); if (temp == "not found"){ temp = "F"; } - DNA = isTrue(temp); + DNA = m->isTrue(temp); temp = validParameter.validFile(parameters, "protein", false); if (temp == "not found"){ temp = "F"; } - protein = isTrue(temp); + protein = m->isTrue(temp); temp = validParameter.validFile(parameters, "jukes", false); if (temp == "not found"){ temp = "F"; } - jukes = isTrue(temp); + jukes = m->isTrue(temp); temp = validParameter.validFile(parameters, "kimura", false); if (temp == "not found"){ temp = "F"; } - kimura = isTrue(temp); + kimura = m->isTrue(temp); temp = validParameter.validFile(parameters, "stdout", false); if (temp == "not found"){ temp = "F"; } - stdoutWanted = isTrue(temp); + stdoutWanted = m->isTrue(temp); matrixout = validParameter.validFile(parameters, "matrixout", false); if (matrixout == "not found"){ matrixout = ""; } ntrees = validParameter.validFile(parameters, "ntrees", false); if (ntrees == "not found"){ ntrees = "1"; } temp = validParameter.validFile(parameters, "expblen", false); if (temp == "not found"){ temp = "F"; } - expblen = isTrue(temp); + expblen = m->isTrue(temp); temp = validParameter.validFile(parameters, "expdist", false); if (temp == "not found"){ temp = "F"; } - expdist = isTrue(temp); + expdist = m->isTrue(temp); if ((fastafile != "") && ((!DNA) && (!protein))) { m->mothurOut("You must specify the type of sequences you are using: DNA or protein"); m->mothurOutEndLine(); abort=true; } } @@ -175,7 +175,7 @@ int ClearcutCommand::execute() { if (abort == true) { return 0; } //prepare filename - string outputName = outputDir + getRootName(getSimpleName(inputFile)) + "tre"; + string outputName = outputDir + m->getRootName(m->getSimpleName(inputFile)) + "tre"; //get location of clearcut GlobalData* globaldata = GlobalData::getInstance(); diff --git a/cluster.cpp b/cluster.cpp index a766e08..440562c 100644 --- a/cluster.cpp +++ b/cluster.cpp @@ -53,7 +53,7 @@ rabund(rav), list(lv), dMatrix(dm), method(f) // sequence in the distance matrix. //ofstream outtemp; //string temp = "temp"; -//openOutputFile(temp, outtemp); +//m->openOutputFile(temp, outtemp); //cout << lv->size() << endl; seqVec = vector(lv->size()); for (MatData currentCell = dMatrix->begin(); currentCell != dMatrix->end(); currentCell++) { diff --git a/clustercommand.cpp b/clustercommand.cpp index 3f27560..6df5faa 100644 --- a/clustercommand.cpp +++ b/clustercommand.cpp @@ -57,7 +57,7 @@ ClusterCommand::ClusterCommand(string option) { convert(temp, precision); temp = validParameter.validFile(parameters, "hard", false); if (temp == "not found") { temp = "F"; } - hard = isTrue(temp); + hard = m->isTrue(temp); temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found") { temp = "10"; } @@ -94,12 +94,12 @@ ClusterCommand::ClusterCommand(string option) { else if(method == "weighted"){ cluster = new WeightedLinkage(rabund, list, matrix, cutoff, method); } tag = cluster->getTag(); - if (outputDir == "") { outputDir += hasPath(globaldata->inputFileName); } - fileroot = outputDir + getRootName(getSimpleName(globaldata->inputFileName)); + if (outputDir == "") { outputDir += m->hasPath(globaldata->inputFileName); } + fileroot = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)); - openOutputFile(fileroot+ tag + ".sabund", sabundFile); - openOutputFile(fileroot+ tag + ".rabund", rabundFile); - openOutputFile(fileroot+ tag + ".list", listFile); + m->openOutputFile(fileroot+ tag + ".sabund", sabundFile); + m->openOutputFile(fileroot+ tag + ".rabund", rabundFile); + m->openOutputFile(fileroot+ tag + ".list", listFile); outputNames.push_back(fileroot+ tag + ".sabund"); outputNames.push_back(fileroot+ tag + ".rabund"); @@ -169,9 +169,9 @@ int ClusterCommand::execute(){ return 0; } - if (print_start && isTrue(timing)) { + if (print_start && m->isTrue(timing)) { m->mothurOut("Clustering (" + tag + ") dist " + toString(matrix->getSmallDist()) + "/" - + toString(roundDist(matrix->getSmallDist(), precision)) + + toString(m->roundDist(matrix->getSmallDist(), precision)) + "\t(precision: " + toString(precision) + ", Nodes: " + toString(matrix->getNNodes()) + ")"); cout.flush(); print_start = false; @@ -184,9 +184,9 @@ int ClusterCommand::execute(){ float dist = matrix->getSmallDist(); float rndDist; if (hard) { - rndDist = ceilDist(dist, precision); + rndDist = m->ceilDist(dist, precision); }else{ - rndDist = roundDist(dist, precision); + rndDist = m->roundDist(dist, precision); } if(previousDist <= 0.0000 && dist != previousDist){ @@ -202,7 +202,7 @@ int ClusterCommand::execute(){ oldList = *list; } - if (print_start && isTrue(timing)) { + if (print_start && m->isTrue(timing)) { m->mothurOut("Clustering (" + tag + ") for distance " + toString(previousDist) + "/" + toString(rndPreviousDist) + "\t(precision: " + toString(precision) + ", Nodes: " + toString(matrix->getNNodes()) + ")"); cout.flush(); @@ -233,8 +233,8 @@ int ClusterCommand::execute(){ listFile.close(); if (saveCutoff != cutoff) { - if (hard) { saveCutoff = ceilDist(saveCutoff, precision); } - else { saveCutoff = roundDist(saveCutoff, precision); } + if (hard) { saveCutoff = m->ceilDist(saveCutoff, precision); } + else { saveCutoff = m->roundDist(saveCutoff, precision); } m->mothurOut("changed cutoff to " + toString(cutoff)); m->mothurOutEndLine(); } @@ -245,7 +245,7 @@ int ClusterCommand::execute(){ m->mothurOutEndLine(); - //if (isTrue(timing)) { + //if (m->isTrue(timing)) { m->mothurOut("It took " + toString(time(NULL) - estart) + " seconds to cluster"); m->mothurOutEndLine(); //} @@ -262,7 +262,7 @@ int ClusterCommand::execute(){ void ClusterCommand::printData(string label){ try { - if (isTrue(timing)) { + if (m->isTrue(timing)) { m->mothurOut("\tTime: " + toString(time(NULL) - start) + "\tsecs for " + toString(oldRAbund.getNumBins()) + "\tclusters. Updates: " + toString(loops)); m->mothurOutEndLine(); } @@ -271,7 +271,7 @@ void ClusterCommand::printData(string label){ start = time(NULL); oldRAbund.setLabel(label); - if (isTrue(showabund)) { + if (m->isTrue(showabund)) { oldRAbund.getSAbundVector().print(cout); } oldRAbund.print(rabundFile); diff --git a/clustersplitcommand.cpp b/clustersplitcommand.cpp index ced5a63..fb1a702 100644 --- a/clustersplitcommand.cpp +++ b/clustersplitcommand.cpp @@ -57,7 +57,7 @@ ClusterSplitCommand::ClusterSplitCommand(string option) { it = parameters.find("phylip"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["phylip"] = inputDir + it->second; } } @@ -65,7 +65,7 @@ ClusterSplitCommand::ClusterSplitCommand(string option) { it = parameters.find("column"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["column"] = inputDir + it->second; } } @@ -73,7 +73,7 @@ ClusterSplitCommand::ClusterSplitCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -81,7 +81,7 @@ ClusterSplitCommand::ClusterSplitCommand(string option) { it = parameters.find("taxonomy"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["taxonomy"] = inputDir + it->second; } } @@ -89,7 +89,7 @@ ClusterSplitCommand::ClusterSplitCommand(string option) { it = parameters.find("fasta"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } @@ -142,10 +142,10 @@ ClusterSplitCommand::ClusterSplitCommand(string option) { convert(temp, precision); temp = validParameter.validFile(parameters, "hard", false); if (temp == "not found") { temp = "F"; } - hard = isTrue(temp); + hard = m->isTrue(temp); temp = validParameter.validFile(parameters, "large", false); if (temp == "not found") { temp = "F"; } - large = isTrue(temp); + large = m->isTrue(temp); temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; } convert(temp, processors); @@ -271,7 +271,7 @@ int ClusterSplitCommand::execute(){ if (namefile == "") { //you need to make a namefile for split matrix ofstream out; namefile = phylipfile + ".names"; - openOutputFile(namefile, out); + m->openOutputFile(namefile, out); for (int i = 0; i < listToMakeNameFile->getNumBins(); i++) { string bin = listToMakeNameFile->get(i); out << bin << '\t' << bin << endl; @@ -497,13 +497,13 @@ int ClusterSplitCommand::execute(){ for(int i=0;iopenInputFile(filename, in); - in >> tag; gobble(in); + in >> tag; m->gobble(in); while(!in.eof()) { string tempName; - in >> tempName; gobble(in); + in >> tempName; m->gobble(in); listFileNames.push_back(tempName); } in.close(); @@ -512,15 +512,15 @@ int ClusterSplitCommand::execute(){ //get labels filename = toString(processIDS[i]) + ".temp.labels"; ifstream in2; - openInputFile(filename, in2); + m->openInputFile(filename, in2); float tempCutoff; - in2 >> tempCutoff; gobble(in2); + in2 >> tempCutoff; m->gobble(in2); if (tempCutoff < cutoff) { cutoff = tempCutoff; } while(!in2.eof()) { string tempName; - in2 >> tempName; gobble(in2); + in2 >> tempName; m->gobble(in2); if (labels.count(tempName) == 0) { labels.insert(tempName); } } in2.close(); @@ -586,12 +586,12 @@ map ClusterSplitCommand::completeListFile(vector listNames, //read in singletons if (singleton != "none") { ifstream in; - openInputFile(singleton, in); + m->openInputFile(singleton, in); string firstCol, secondCol; listSingle = new ListVector(); while (!in.eof()) { - in >> firstCol >> secondCol; gobble(in); + in >> firstCol >> secondCol; m->gobble(in); listSingle->push_back(secondCol); } in.close(); @@ -632,7 +632,7 @@ map ClusterSplitCommand::completeListFile(vector listNames, string filledInList = listNames[k] + "filledInTemp"; ofstream outFilled; - openOutputFile(filledInList, outFilled); + m->openOutputFile(filledInList, outFilled); //for each label needed for(int l = 0; l < orderFloat.size(); l++){ @@ -689,12 +689,12 @@ map ClusterSplitCommand::completeListFile(vector listNames, //********************************************************************************************************************** int ClusterSplitCommand::mergeLists(vector listNames, map userLabels, ListVector* listSingle){ try { - if (outputDir == "") { outputDir += hasPath(distfile); } - fileroot = outputDir + getRootName(getSimpleName(distfile)); + if (outputDir == "") { outputDir += m->hasPath(distfile); } + fileroot = outputDir + m->getRootName(m->getSimpleName(distfile)); - openOutputFile(fileroot+ tag + ".sabund", outSabund); - openOutputFile(fileroot+ tag + ".rabund", outRabund); - openOutputFile(fileroot+ tag + ".list", outList); + m->openOutputFile(fileroot+ tag + ".sabund", outSabund); + m->openOutputFile(fileroot+ tag + ".rabund", outRabund); + m->openOutputFile(fileroot+ tag + ".list", outList); outputNames.push_back(fileroot+ tag + ".sabund"); outputNames.push_back(fileroot+ tag + ".rabund"); @@ -718,7 +718,7 @@ int ClusterSplitCommand::mergeLists(vector listNames, map us if (listSingle != NULL) { for (int j = 0; j < listSingle->getNumBins(); j++) { outList << listSingle->get(j) << '\t'; - rabund->push_back(getNumNames(listSingle->get(j))); + rabund->push_back(m->getNumNames(listSingle->get(j))); } } @@ -735,7 +735,7 @@ int ClusterSplitCommand::mergeLists(vector listNames, map us else { for (int j = 0; j < list->getNumBins(); j++) { outList << list->get(j) << '\t'; - rabund->push_back(getNumNames(list->get(j))); + rabund->push_back(m->getNumNames(list->get(j))); } delete list; } @@ -775,7 +775,7 @@ void ClusterSplitCommand::printData(ListVector* oldList){ RAbundVector oldRAbund = oldList->getRAbundVector(); oldRAbund.setLabel(label); - if (isTrue(showabund)) { + if (m->isTrue(showabund)) { oldRAbund.getSAbundVector().print(cout); } oldRAbund.print(outRabund); @@ -811,7 +811,7 @@ int ClusterSplitCommand::createProcesses(vector < vector < map > //write out names to file string filename = toString(getpid()) + ".temp"; ofstream out; - openOutputFile(filename, out); + m->openOutputFile(filename, out); out << tag << endl; for (int j = 0; j < listFileNames.size(); j++) { out << listFileNames[j] << endl; } out.close(); @@ -819,7 +819,7 @@ int ClusterSplitCommand::createProcesses(vector < vector < map > //print out labels ofstream outLabels; filename = toString(getpid()) + ".temp.labels"; - openOutputFile(filename, outLabels); + m->openOutputFile(filename, outLabels); outLabels << cutoff << endl; for (set::iterator it = labels.begin(); it != labels.end(); it++) { @@ -917,11 +917,11 @@ vector ClusterSplitCommand::cluster(vector< map > distNa else if(method == "average"){ cluster = new AverageLinkage(rabund, list, matrix, cutoff, method); } tag = cluster->getTag(); - if (outputDir == "") { outputDir += hasPath(thisDistFile); } - fileroot = outputDir + getRootName(getSimpleName(thisDistFile)); + if (outputDir == "") { outputDir += m->hasPath(thisDistFile); } + fileroot = outputDir + m->getRootName(m->getSimpleName(thisDistFile)); ofstream listFile; - openOutputFile(fileroot+ tag + ".list", listFile); + m->openOutputFile(fileroot+ tag + ".list", listFile); listFileNames.push_back(fileroot+ tag + ".list"); @@ -950,9 +950,9 @@ vector ClusterSplitCommand::cluster(vector< map > distNa float dist = matrix->getSmallDist(); float rndDist; if (hard) { - rndDist = ceilDist(dist, precision); + rndDist = m->ceilDist(dist, precision); }else{ - rndDist = roundDist(dist, precision); + rndDist = m->roundDist(dist, precision); } if(previousDist <= 0.0000 && dist != previousDist){ @@ -995,8 +995,8 @@ vector ClusterSplitCommand::cluster(vector< map > distNa remove(thisNamefile.c_str()); if (saveCutoff != cutoff) { - if (hard) { saveCutoff = ceilDist(saveCutoff, precision); } - else { saveCutoff = roundDist(saveCutoff, precision); } + if (hard) { saveCutoff = m->ceilDist(saveCutoff, precision); } + else { saveCutoff = m->roundDist(saveCutoff, precision); } m->mothurOut("Cutoff was " + toString(cutoff) + " changed cutoff to " + toString(saveCutoff)); m->mothurOutEndLine(); } diff --git a/collectcommand.cpp b/collectcommand.cpp index ca48d75..2d952fa 100644 --- a/collectcommand.cpp +++ b/collectcommand.cpp @@ -73,7 +73,7 @@ CollectCommand::CollectCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -88,7 +88,7 @@ CollectCommand::CollectCommand(string option) { else { if (calc == "default") { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson"; } } - splitAtDash(calc, Estimators); + m->splitAtDash(calc, Estimators); string temp; temp = validParameter.validFile(parameters, "freq", false); if (temp == "not found") { temp = "100"; } @@ -150,8 +150,8 @@ int CollectCommand::execute(){ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } return 0; } - if (outputDir == "") { outputDir += hasPath(inputFileNames[p]); } - string fileNameRoot = outputDir + getRootName(getSimpleName(inputFileNames[p])); + if (outputDir == "") { outputDir += m->hasPath(inputFileNames[p]); } + string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])); globaldata->inputFileName = inputFileNames[p]; if (inputFileNames.size() > 1) { @@ -296,7 +296,7 @@ int CollectCommand::execute(){ } //you have a label the user want that is smaller than this label and the last label has not already been processed - if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = order->getLabel(); delete order; @@ -414,7 +414,7 @@ vector CollectCommand::parseSharedFile(string filename) { input = globaldata->ginput; vector lookup = input->getSharedRAbundVectors(); - string sharedFileRoot = getRootName(filename); + string sharedFileRoot = m->getRootName(filename); //clears file before we start to write to it below for (int i=0; i CollectCommand::parseSharedFile(string filename) { for (int i = 0; i < lookup.size(); i++) { RAbundVector rav = lookup[i]->getRAbundVector(); - openOutputFileAppend(sharedFileRoot + lookup[i]->getGroup() + ".rabund", *(filehandles[lookup[i]->getGroup()])); + m->openOutputFileAppend(sharedFileRoot + lookup[i]->getGroup() + ".rabund", *(filehandles[lookup[i]->getGroup()])); rav.print(*(filehandles[lookup[i]->getGroup()])); (*(filehandles[lookup[i]->getGroup()])).close(); } diff --git a/collectsharedcommand.cpp b/collectsharedcommand.cpp index 40b911b..c0b8248 100644 --- a/collectsharedcommand.cpp +++ b/collectsharedcommand.cpp @@ -79,7 +79,7 @@ CollectSharedCommand::CollectSharedCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -94,12 +94,12 @@ CollectSharedCommand::CollectSharedCommand(string option) { else { if (calc == "default") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; } } - splitAtDash(calc, Estimators); + m->splitAtDash(calc, Estimators); groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); } globaldata->Groups = Groups; @@ -108,12 +108,12 @@ CollectSharedCommand::CollectSharedCommand(string option) { convert(temp, freq); temp = validParameter.validFile(parameters, "all", false); if (temp == "not found") { temp = "false"; } - all = isTrue(temp); + all = m->isTrue(temp); if (abort == false) { - if (outputDir == "") { outputDir += hasPath(globaldata->inputFileName); } - string fileNameRoot = outputDir + getRootName(getSimpleName(globaldata->inputFileName)); + if (outputDir == "") { outputDir += m->hasPath(globaldata->inputFileName); } + string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)); format = globaldata->getFormat(); int i; @@ -283,7 +283,7 @@ int CollectSharedCommand::execute(){ } //you have a label the user want that is smaller than this label and the last label has not already been processed - if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = order->getLabel(); delete order; diff --git a/consensuscommand.cpp b/consensuscommand.cpp index 2fef5b1..a65d56f 100644 --- a/consensuscommand.cpp +++ b/consensuscommand.cpp @@ -68,7 +68,7 @@ int ConcensusCommand::execute(){ //open file for pairing not included in the tree notIncluded = filename + ".cons.pairs"; - openOutputFile(notIncluded, out2); + m->openOutputFile(notIncluded, out2); consensusTree = new Tree(); @@ -151,7 +151,7 @@ int ConcensusCommand::execute(){ } outputFile = filename + ".cons.tre"; - openOutputFile(outputFile, out); + m->openOutputFile(outputFile, out); consensusTree->printForBoot(out); diff --git a/decalc.cpp b/decalc.cpp index 94b6c93..a5a0ec0 100644 --- a/decalc.cpp +++ b/decalc.cpp @@ -290,10 +290,10 @@ vector DeCalculator::calcFreq(vector seqs, string filename) { try { vector prob; - string freqfile = getRootName(filename) + "freq"; + string freqfile = m->getRootName(filename) + "freq"; ofstream outFreq; - openOutputFile(freqfile, outFreq); + m->openOutputFile(freqfile, outFreq); outFreq << "#" << m->getVersion() << endl; diff --git a/deconvolutecommand.cpp b/deconvolutecommand.cpp index 663a6bf..b3fa7dd 100644 --- a/deconvolutecommand.cpp +++ b/deconvolutecommand.cpp @@ -41,7 +41,7 @@ DeconvoluteCommand::DeconvoluteCommand(string option) { it = parameters.find("fasta"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } @@ -49,7 +49,7 @@ DeconvoluteCommand::DeconvoluteCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -64,7 +64,7 @@ DeconvoluteCommand::DeconvoluteCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(inFastaName); //if user entered a file with a path then preserve it + outputDir += m->hasPath(inFastaName); //if user entered a file with a path then preserve it } oldNameMapFName = validParameter.validFile(parameters, "name", true); @@ -102,8 +102,8 @@ int DeconvoluteCommand::execute() { if (abort == true) { return 0; } //prepare filenames and open files - string outNameFile = outputDir + getRootName(getSimpleName(inFastaName)) + "names"; - string outFastaFile = outputDir + getRootName(getSimpleName(inFastaName)) + "unique" + getExtension(inFastaName); + string outNameFile = outputDir + m->getRootName(m->getSimpleName(inFastaName)) + "names"; + string outFastaFile = outputDir + m->getRootName(m->getSimpleName(inFastaName)) + "unique" + m->getExtension(inFastaName); FastaMap fastamap; diff --git a/degapseqscommand.cpp b/degapseqscommand.cpp index 8f8a5c3..6a9c25e 100644 --- a/degapseqscommand.cpp +++ b/degapseqscommand.cpp @@ -43,25 +43,25 @@ DegapSeqsCommand::DegapSeqsCommand(string option) { fastafile = validParameter.validFile(parameters, "fasta", false); if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the degap.seqs command."); m->mothurOutEndLine(); abort = true; } else { - splitAtDash(fastafile, fastaFileNames); + m->splitAtDash(fastafile, fastaFileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < fastaFileNames.size(); i++) { if (inputDir != "") { - string path = hasPath(fastaFileNames[i]); + string path = m->hasPath(fastaFileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { fastaFileNames[i] = inputDir + fastaFileNames[i]; } } ifstream in; - int ableToOpen = openInputFile(fastaFileNames[i], in, "noerror"); + int ableToOpen = m->openInputFile(fastaFileNames[i], in, "noerror"); //if you can't open it, try default location if (ableToOpen == 1) { if (m->getDefaultPath() != "") { //default path is set - string tryPath = m->getDefaultPath() + getSimpleName(fastaFileNames[i]); + string tryPath = m->getDefaultPath() + m->getSimpleName(fastaFileNames[i]); m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = openInputFile(tryPath, in, "noerror"); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); fastaFileNames[i] = tryPath; } } @@ -83,7 +83,7 @@ DegapSeqsCommand::DegapSeqsCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(fastafile); //if user entered a file with a path then preserve it + outputDir += m->hasPath(fastafile); //if user entered a file with a path then preserve it } } @@ -128,16 +128,16 @@ int DegapSeqsCommand::execute(){ m->mothurOut("Degapping sequences from " + fastaFileNames[s] + " ..." ); m->mothurOutEndLine(); ifstream inFASTA; - openInputFile(fastaFileNames[s], inFASTA); + m->openInputFile(fastaFileNames[s], inFASTA); ofstream outFASTA; - string degapFile = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "ng.fasta"; - openOutputFile(degapFile, outFASTA); + string degapFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "ng.fasta"; + m->openOutputFile(degapFile, outFASTA); while(!inFASTA.eof()){ if (m->control_pressed) { inFASTA.close(); outFASTA.close(); remove(degapFile.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; } - Sequence currSeq(inFASTA); gobble(inFASTA); + Sequence currSeq(inFASTA); m->gobble(inFASTA); if (currSeq.getName() != "") { outFASTA << ">" << currSeq.getName() << endl; outFASTA << currSeq.getUnaligned() << endl; diff --git a/distancecommand.cpp b/distancecommand.cpp index 36bae2e..351a3f4 100644 --- a/distancecommand.cpp +++ b/distancecommand.cpp @@ -48,7 +48,7 @@ DistanceCommand::DistanceCommand(string option) { it2 = parameters.find("fasta"); //user has given a template file if(it2 != parameters.end()){ - path = hasPath(it2->second); + path = m->hasPath(it2->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it2->second; } } @@ -56,7 +56,7 @@ DistanceCommand::DistanceCommand(string option) { it2 = parameters.find("oldfasta"); //user has given a template file if(it2 != parameters.end()){ - path = hasPath(it2->second); + path = m->hasPath(it2->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["oldfasta"] = inputDir + it2->second; } } @@ -64,7 +64,7 @@ DistanceCommand::DistanceCommand(string option) { it2 = parameters.find("column"); //user has given a template file if(it2 != parameters.end()){ - path = hasPath(it2->second); + path = m->hasPath(it2->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["column"] = inputDir + it2->second; } } @@ -76,7 +76,7 @@ DistanceCommand::DistanceCommand(string option) { else if (fastafile == "not open") { abort = true; } else{ ifstream inFASTA; - openInputFile(fastafile, inFASTA); + m->openInputFile(fastafile, inFASTA); alignDB = SequenceDB(inFASTA); inFASTA.close(); } @@ -92,7 +92,7 @@ DistanceCommand::DistanceCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(fastafile); //if user entered a file with a path then preserve it + outputDir += m->hasPath(fastafile); //if user entered a file with a path then preserve it } //check for optional parameter and set defaults @@ -102,7 +102,7 @@ DistanceCommand::DistanceCommand(string option) { else { if (calc == "default") { calc = "onegap"; } } - splitAtDash(calc, Estimators); + m->splitAtDash(calc, Estimators); string temp; temp = validParameter.validFile(parameters, "countends", false); if(temp == "not found"){ temp = "T"; } @@ -124,7 +124,7 @@ DistanceCommand::DistanceCommand(string option) { ValidCalculators validCalculator; - if (isTrue(countends) == true) { + if (m->isTrue(countends) == true) { for (int i=0; igetRootName(m->getSimpleName(fastafile)) + "phylip.dist"; remove(outputFile.c_str()); //output numSeqs to phylip formatted dist file }else if (output == "column") { //user wants column format - outputFile = outputDir + getRootName(getSimpleName(fastafile)) + "dist"; + outputFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "dist"; //so we don't accidentally overwrite if (outputFile == column) { @@ -222,7 +222,7 @@ int DistanceCommand::execute(){ remove(outputFile.c_str()); }else { //assume square - outputFile = outputDir + getRootName(getSimpleName(fastafile)) + "square.dist"; + outputFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "square.dist"; remove(outputFile.c_str()); } @@ -367,7 +367,7 @@ int DistanceCommand::execute(){ //append and remove temp files for (; it != processIDS.end(); it++) { - appendFiles((outputFile + toString(it->second) + ".temp"), outputFile); + m->appendFiles((outputFile + toString(it->second) + ".temp"), outputFile); remove((outputFile + toString(it->second) + ".temp").c_str()); } } @@ -390,7 +390,7 @@ int DistanceCommand::execute(){ ifstream fileHandle; fileHandle.open(outputFile.c_str()); if(fileHandle) { - gobble(fileHandle); + m->gobble(fileHandle); if (fileHandle.eof()) { m->mothurOut(outputFile + " is blank. This can result if there are no distances below your cutoff."); m->mothurOutEndLine(); } } @@ -399,10 +399,10 @@ int DistanceCommand::execute(){ //we had to rename the column file so we didnt overwrite above, but we want to keep old name if (outputFile == column) { string tempcolumn = column + ".old"; - appendFiles(tempcolumn, outputFile); + m->appendFiles(tempcolumn, outputFile); remove(tempcolumn.c_str()); }else{ - appendFiles(outputFile, column); + m->appendFiles(outputFile, column); remove(outputFile.c_str()); outputFile = column; } @@ -666,7 +666,7 @@ int DistanceCommand::convertMatrix(string outputFile) { try{ //sort file by first column so the distances for each row are together - string outfile = getRootName(outputFile) + "sorted.dist.temp"; + string outfile = m->getRootName(outputFile) + "sorted.dist.temp"; //use the unix sort #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) @@ -680,10 +680,10 @@ int DistanceCommand::convertMatrix(string outputFile) { //output to new file distance for each row and save positions in file where new row begins ifstream in; - openInputFile(outfile, in); + m->openInputFile(outfile, in); ofstream out; - openOutputFile(outputFile, out); + m->openOutputFile(outputFile, out); out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint); @@ -701,12 +701,12 @@ int DistanceCommand::convertMatrix(string outputFile) { rowDists[first] = 0.00; //distance to yourself is 0.0 in.seekg(0); - //openInputFile(outfile, in); + //m->openInputFile(outfile, in); while(!in.eof()) { if (m->control_pressed) { in.close(); remove(outfile.c_str()); out.close(); return 0; } - in >> first >> second >> dist; gobble(in); + in >> first >> second >> dist; m->gobble(in); if (first != currentRow) { //print out last row @@ -754,7 +754,7 @@ int DistanceCommand::convertToLowerTriangle(string outputFile) { try{ //sort file by first column so the distances for each row are together - string outfile = getRootName(outputFile) + "sorted.dist.temp"; + string outfile = m->getRootName(outputFile) + "sorted.dist.temp"; //use the unix sort #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) @@ -768,10 +768,10 @@ int DistanceCommand::convertToLowerTriangle(string outputFile) { //output to new file distance for each row and save positions in file where new row begins ifstream in; - openInputFile(outfile, in); + m->openInputFile(outfile, in); ofstream out; - openOutputFile(outputFile, out); + m->openOutputFile(outputFile, out); out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint); @@ -791,12 +791,12 @@ int DistanceCommand::convertToLowerTriangle(string outputFile) { rowDists[first] = 0.00; //distance to yourself is 0.0 in.seekg(0); - //openInputFile(outfile, in); + //m->openInputFile(outfile, in); while(!in.eof()) { if (m->control_pressed) { in.close(); remove(outfile.c_str()); out.close(); return 0; } - in >> first >> second >> dist; gobble(in); + in >> first >> second >> dist; m->gobble(in); if (first != currentRow) { //print out last row @@ -853,7 +853,7 @@ bool DistanceCommand::sanityCheck() { //make sure the 2 fasta files have the same alignment length ifstream in; - openInputFile(fastafile, in); + m->openInputFile(fastafile, in); int fastaAlignLength = 0; if (in) { Sequence tempIn(in); @@ -862,7 +862,7 @@ bool DistanceCommand::sanityCheck() { in.close(); ifstream in2; - openInputFile(oldfastafile, in2); + m->openInputFile(oldfastafile, in2); int oldfastaAlignLength = 0; if (in2) { Sequence tempIn2(in2); @@ -876,7 +876,7 @@ bool DistanceCommand::sanityCheck() { set namesOldFasta; ifstream inFasta; - openInputFile(oldfastafile, inFasta); + m->openInputFile(oldfastafile, inFasta); while (!inFasta.eof()) { if (m->control_pressed) { inFasta.close(); return good; } @@ -888,25 +888,25 @@ bool DistanceCommand::sanityCheck() { alignDB.push_back(temp); //add to DB } - gobble(inFasta); + m->gobble(inFasta); } inFasta.close(); //read through the column file checking names and removing distances above the cutoff ifstream inDist; - openInputFile(column, inDist); + m->openInputFile(column, inDist); ofstream outDist; string outputFile = column + ".temp"; - openOutputFile(outputFile, outDist); + m->openOutputFile(outputFile, outDist); string name1, name2; float dist; while (!inDist.eof()) { if (m->control_pressed) { inDist.close(); outDist.close(); remove(outputFile.c_str()); return good; } - inDist >> name1 >> name2 >> dist; gobble(inDist); + inDist >> name1 >> name2 >> dist; m->gobble(inDist); //both names are in fasta file and distance is below cutoff if ((namesOldFasta.count(name1) == 0) || (namesOldFasta.count(name2) == 0)) { good = false; break; } @@ -929,20 +929,20 @@ bool DistanceCommand::sanityCheck() { } catch(exception& e) { - m->errorOut(e, "DistanceCommand", "appendFiles"); + m->errorOut(e, "DistanceCommand", "m->appendFiles"); exit(1); } } /************************************************************************************************** -void DistanceCommand::appendFiles(string temp, string filename) { +void DistanceCommand::m->appendFiles(string temp, string filename) { try{ ofstream output; ifstream input; //open output file in append mode - openOutputFileAppend(filename, output); - openInputFile(temp, input); + m->openOutputFileAppend(filename, output); + m->openInputFile(temp, input); while(char c = input.get()){ if(input.eof()) { break; } @@ -953,7 +953,7 @@ void DistanceCommand::appendFiles(string temp, string filename) { output.close(); } catch(exception& e) { - m->errorOut(e, "DistanceCommand", "appendFiles"); + m->errorOut(e, "DistanceCommand", "m->appendFiles"); exit(1); } } diff --git a/distancecommand.h b/distancecommand.h index 36a1e24..4a25761 100644 --- a/distancecommand.h +++ b/distancecommand.h @@ -43,7 +43,7 @@ private: bool abort; vector Estimators; //holds estimators to be used - //void appendFiles(string, string); + //void m->appendFiles(string, string); void createProcesses(string); int driver(/*Dist*, SequenceDB, */int, int, string, float); diff --git a/engine.cpp b/engine.cpp index fbf986d..5e82d13 100644 --- a/engine.cpp +++ b/engine.cpp @@ -49,7 +49,7 @@ InteractEngine::InteractEngine(string path){ //break apart path variable by ':' vector dirs; - splitAtChar(envPath, dirs, delim); + mout->splitAtChar(envPath, dirs, delim); //get path related to mothur string mothurPath = ""; @@ -199,7 +199,7 @@ string Engine::getCommand() { string nextCommand = ""; mout->mothurOut("mothur > "); - getline(cin, nextCommand); + m->getline(cin, nextCommand); mout->mothurOutJustToLog(toString(nextCommand)); return nextCommand; @@ -218,7 +218,7 @@ BatchEngine::BatchEngine(string path, string batchFileName){ try { globaldata = GlobalData::getInstance(); - openedBatch = openInputFile(batchFileName, inputBatchFile); + openedBatch = mout->openInputFile(batchFileName, inputBatchFile); string temppath = path.substr(0, (path.find_last_of('m'))); @@ -237,7 +237,7 @@ BatchEngine::BatchEngine(string path, string batchFileName){ //break apart path variable by ':' vector dirs; - splitAtChar(envPath, dirs, delim); + mout->splitAtChar(envPath, dirs, delim); //get path related to mothur string mothurPath = ""; @@ -370,7 +370,7 @@ bool BatchEngine::getInput(){ } } - gobble(inputBatchFile); + mout->gobble(inputBatchFile); } inputBatchFile.close(); @@ -388,7 +388,7 @@ string BatchEngine::getNextCommand(ifstream& inputBatchFile) { string nextcommand = ""; if (inputBatchFile.eof()) { nextcommand = "quit()"; } - else { nextcommand = getline(inputBatchFile); } + else { nextcommand = mout->getline(inputBatchFile); } return nextcommand; } @@ -425,7 +425,7 @@ ScriptEngine::ScriptEngine(string path, string commandString){ //break apart path variable by ':' vector dirs; - splitAtChar(envPath, dirs, delim); + mout->splitAtChar(envPath, dirs, delim); //get path related to mothur string mothurPath = ""; diff --git a/fastamap.cpp b/fastamap.cpp index 36b0721..95d3f3c 100644 --- a/fastamap.cpp +++ b/fastamap.cpp @@ -15,7 +15,7 @@ void FastaMap::readFastaFile(string inFileName) { try { ifstream in; - openInputFile(inFileName, in); + m->openInputFile(inFileName, in); string name, sequence, line; sequence = ""; string temp; @@ -41,7 +41,7 @@ void FastaMap::readFastaFile(string inFileName) { // data[sequence].groupnumber++; } } - gobble(in); + m->gobble(in); } in.close(); } @@ -56,7 +56,7 @@ void FastaMap::readFastaFile(string inFileName) { void FastaMap::readFastaFile(string inFastaFile, string oldNameFileName){ //prints data ifstream oldNameFile; - openInputFile(oldNameFileName, oldNameFile); + m->openInputFile(oldNameFileName, oldNameFile); map oldNameMap; string name, list; @@ -65,12 +65,12 @@ void FastaMap::readFastaFile(string inFastaFile, string oldNameFileName){ //prin oldNameFile >> name >> list; oldNameMap[name] = list; - gobble(oldNameFile); + m->gobble(oldNameFile); } oldNameFile.close(); ifstream inFASTA; - openInputFile(inFastaFile, inFASTA); + m->openInputFile(inFastaFile, inFASTA); string sequence; while(!inFASTA.eof()){ if (m->control_pressed) { break; } @@ -93,7 +93,7 @@ void FastaMap::readFastaFile(string inFastaFile, string oldNameFileName){ //prin // data[sequence].groupnumber++; } } - gobble(inFASTA); + m->gobble(inFASTA); } @@ -147,7 +147,7 @@ int FastaMap::sizeUnique(){ //returns datas size which is the number of unique s void FastaMap::printNamesFile(string outFileName){ //prints data try { ofstream outFile; - openOutputFile(outFileName, outFile); + m->openOutputFile(outFileName, outFile); // two column file created with groupname and them list of identical sequence names for (map::iterator it = data.begin(); it != data.end(); it++) { @@ -167,7 +167,7 @@ void FastaMap::printNamesFile(string outFileName){ //prints data void FastaMap::printCondensedFasta(string outFileName){ //prints data try { ofstream out; - openOutputFile(outFileName, out); + m->openOutputFile(outFileName, out); //creates a fasta file for (map::iterator it = data.begin(); it != data.end(); it++) { if (m->control_pressed) { break; } diff --git a/fileoutput.cpp b/fileoutput.cpp index 117f8ab..c2432ac 100644 --- a/fileoutput.cpp +++ b/fileoutput.cpp @@ -23,16 +23,16 @@ ThreeColumnFile::~ThreeColumnFile(){ void ThreeColumnFile::initFile(string label){ try { if(counter != 0){ - openOutputFile(outName, outFile); - openInputFile(inName, inFile); + m->openOutputFile(outName, outFile); + m->openInputFile(inName, inFile); string inputBuffer; - inputBuffer = getline(inFile); + inputBuffer = m->getline(inFile); outFile << inputBuffer << '\t' << label << "\tlci\thci" << endl; } else{ - openOutputFile(outName, outFile); + m->openOutputFile(outName, outFile); outFile << "numsampled\t" << label << "\tlci\thci" << endl; } @@ -51,7 +51,7 @@ void ThreeColumnFile::output(int nSeqs, vector data){ try { if(counter != 0){ string inputBuffer; - inputBuffer = getline(inFile); + inputBuffer = m->getline(inFile); outFile << inputBuffer << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl; } @@ -110,11 +110,11 @@ ColumnFile::~ColumnFile(){ void ColumnFile::initFile(string label, vector tags){ try { if(counter != 0){ - openOutputFile(outName, outFile); - openInputFile(inName, inFile); + m->openOutputFile(outName, outFile); + m->openInputFile(inName, inFile); string inputBuffer; - inputBuffer = getline(inFile); + inputBuffer = m->getline(inFile); outFile << inputBuffer << '\t'; for(int i = 0; i < tags.size(); i++) { @@ -123,7 +123,7 @@ void ColumnFile::initFile(string label, vector tags){ outFile << endl; } else{ - openOutputFile(outName, outFile); + m->openOutputFile(outName, outFile); for(int i = 0; i < tags.size(); i++) { outFile << label + tags[i] << '\t'; } @@ -146,7 +146,7 @@ void ColumnFile::output(vector data){ if(counter != 0){ string inputBuffer; - inputBuffer = getline(inFile); + inputBuffer = m->getline(inFile); outFile << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(iters.length()); for (int i = 1; i< data.size(); i++) { @@ -214,16 +214,16 @@ SharedThreeColumnFile::~SharedThreeColumnFile(){ void SharedThreeColumnFile::initFile(string label){ try { if(counter != 0){ - openOutputFile(outName, outFile); - openInputFile(inName, inFile); + m->openOutputFile(outName, outFile); + m->openInputFile(inName, inFile); string inputBuffer; - inputBuffer = getline(inFile); + inputBuffer = m->getline(inFile); outFile << inputBuffer << '\t' << label << "\tlci\thci" << endl; } else{ - openOutputFile(outName, outFile); + m->openOutputFile(outName, outFile); outFile << "numsampled\t" << groupLabel << '\t' << label << "\tlci\thci" << endl; } @@ -242,7 +242,7 @@ void SharedThreeColumnFile::output(int nSeqs, vector data){ try { if(counter != 0){ string inputBuffer; - inputBuffer = getline(inFile); + inputBuffer = m->getline(inFile); outFile << inputBuffer << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl; } @@ -303,16 +303,16 @@ OneColumnFile::~OneColumnFile(){ void OneColumnFile::initFile(string label){ try { if(counter != 0){ - openOutputFile(outName, outFile); - openInputFile(inName, inFile); + m->openOutputFile(outName, outFile); + m->openInputFile(inName, inFile); string inputBuffer; - inputBuffer = getline(inFile); + inputBuffer = m->getline(inFile); outFile << inputBuffer << '\t' << label << endl; } else{ - openOutputFile(outName, outFile); + m->openOutputFile(outName, outFile); outFile << "numsampled\t" << label << endl; } @@ -331,7 +331,7 @@ void OneColumnFile::output(int nSeqs, vector data){ try { if(counter != 0){ string inputBuffer; - inputBuffer = getline(inFile); + inputBuffer = m->getline(inFile); outFile << inputBuffer << setprecision(4) << '\t' << data[0] << endl; } @@ -390,17 +390,17 @@ SharedOneColumnFile::~SharedOneColumnFile(){ void SharedOneColumnFile::initFile(string label){ try { if(counter != 0){ - openOutputFile(outName, outFile); - openInputFile(inName, inFile); + m->openOutputFile(outName, outFile); + m->openInputFile(inName, inFile); string inputBuffer; - inputBuffer = getline(inFile); + inputBuffer = m->getline(inFile); outFile << inputBuffer << '\t' << label << endl; } else{ - openOutputFile(outName, outFile); + m->openOutputFile(outName, outFile); outFile << "sampled\t" << label << endl; } @@ -427,7 +427,7 @@ void SharedOneColumnFile::output(int nSeqs, vector data){ } if(counter != 0){ string inputBuffer; - inputBuffer = getline(inFile); + inputBuffer = m->getline(inFile); outFile << inputBuffer << setprecision(2) << '\t' << dataOutput << endl; } diff --git a/filters.h b/filters.h index 13607e7..21bc8bb 100644 --- a/filters.h +++ b/filters.h @@ -19,7 +19,7 @@ class Filters { public: - Filters() {}; + Filters() { m = MothurOut::getInstance(); }; ~Filters(){}; string getFilter() { return filter; } @@ -77,7 +77,7 @@ public: void doHard(string hard) { ifstream fileHandle; - openInputFile(hard, fileHandle); + m->openInputFile(hard, fileHandle); fileHandle >> filter; @@ -102,6 +102,7 @@ protected: int alignmentLength, numSeqs; float soft; char trump; + MothurOut* m; }; diff --git a/filterseqscommand.cpp b/filterseqscommand.cpp index 2c61465..4ee6748 100644 --- a/filterseqscommand.cpp +++ b/filterseqscommand.cpp @@ -44,7 +44,7 @@ FilterSeqsCommand::FilterSeqsCommand(string option) { it = parameters.find("fasta"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } @@ -52,7 +52,7 @@ FilterSeqsCommand::FilterSeqsCommand(string option) { it = parameters.find("hard"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["hard"] = inputDir + it->second; } } @@ -62,25 +62,25 @@ FilterSeqsCommand::FilterSeqsCommand(string option) { fasta = validParameter.validFile(parameters, "fasta", false); if (fasta == "not found") { m->mothurOut("fasta is a required parameter for the filter.seqs command."); m->mothurOutEndLine(); abort = true; } else { - splitAtDash(fasta, fastafileNames); + m->splitAtDash(fasta, fastafileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < fastafileNames.size(); i++) { if (inputDir != "") { - string path = hasPath(fastafileNames[i]); + string path = m->hasPath(fastafileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { fastafileNames[i] = inputDir + fastafileNames[i]; } } ifstream in; - int ableToOpen = openInputFile(fastafileNames[i], in, "noerror"); + int ableToOpen = m->openInputFile(fastafileNames[i], in, "noerror"); //if you can't open it, try default location if (ableToOpen == 1) { if (m->getDefaultPath() != "") { //default path is set - string tryPath = m->getDefaultPath() + getSimpleName(fastafileNames[i]); + string tryPath = m->getDefaultPath() + m->getSimpleName(fastafileNames[i]); m->mothurOut("Unable to open " + fastafileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = openInputFile(tryPath, in, "noerror"); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); fastafileNames[i] = tryPath; } } @@ -92,7 +92,7 @@ FilterSeqsCommand::FilterSeqsCommand(string option) { fastafileNames.erase(fastafileNames.begin()+i); i--; }else{ - string simpleName = getSimpleName(fastafileNames[i]); + string simpleName = m->getSimpleName(fastafileNames[i]); filterFileName += simpleName.substr(0, simpleName.find_first_of('.')); } in.close(); @@ -106,7 +106,7 @@ FilterSeqsCommand::FilterSeqsCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(fastafileNames[0]); //if user entered a file with a path then preserve it + outputDir += m->hasPath(fastafileNames[0]); //if user entered a file with a path then preserve it } } //check for optional parameter and set defaults @@ -174,7 +174,7 @@ int FilterSeqsCommand::execute() { if (abort == true) { return 0; } ifstream inFASTA; - openInputFile(fastafileNames[0], inFASTA); + m->openInputFile(fastafileNames[0], inFASTA); Sequence testSeq(inFASTA); alignmentLength = testSeq.getAlignLength(); @@ -199,7 +199,7 @@ int FilterSeqsCommand::execute() { ofstream outFilter; string filterFile = outputDir + filterFileName + ".filter"; - openOutputFile(filterFile, outFilter); + m->openOutputFile(filterFile, outFilter); outFilter << filter << endl; outFilter.close(); outputNames.push_back(filterFile); @@ -254,7 +254,7 @@ int FilterSeqsCommand::filterSequences() { for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); - string filteredFasta = outputDir + getRootName(getSimpleName(fastafileNames[s])) + "filter.fasta"; + string filteredFasta = outputDir + m->getRootName(m->getSimpleName(fastafileNames[s])) + "filter.fasta"; #ifdef USE_MPI int pid, start, end, numSeqsPerProcessor, num; int tag = 2001; @@ -283,7 +283,7 @@ int FilterSeqsCommand::filterSequences() { if (pid == 0) { //you are the root process - MPIPos = setFilePosFasta(fastafileNames[s], num); //fills MPIPos, returns numSeqs + MPIPos = m->setFilePosFasta(fastafileNames[s], num); //fills MPIPos, returns numSeqs numSeqs += num; //send file positions to all processes @@ -338,7 +338,7 @@ int FilterSeqsCommand::filterSequences() { MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case #else - vector positions = divideFile(fastafileNames[s], processors); + vector positions = m->divideFile(fastafileNames[s], processors); for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(new linePair(positions[i], positions[(i+1)])); @@ -355,7 +355,7 @@ int FilterSeqsCommand::filterSequences() { //append fasta files for(int i=1;iappendFiles((fastafileNames[s] + toString(processIDS[i]) + ".temp"), filteredFasta); remove((fastafileNames[s] + toString(processIDS[i]) + ".temp").c_str()); } } @@ -400,7 +400,7 @@ int FilterSeqsCommand::driverMPIRun(int start, int num, MPI_File& inMPI, MPI_Fil istringstream iss (tempBuf,istringstream::in); delete buf4; - Sequence seq(iss); gobble(iss); + Sequence seq(iss); m->gobble(iss); if (seq.getName() != "") { string align = seq.getAligned(); @@ -456,10 +456,10 @@ int FilterSeqsCommand::driverMPIRun(int start, int num, MPI_File& inMPI, MPI_Fil int FilterSeqsCommand::driverRunFilter(string F, string outputFilename, string inputFilename, linePair* filePos) { try { ofstream out; - openOutputFile(outputFilename, out); + m->openOutputFile(outputFilename, out); ifstream in; - openInputFile(inputFilename, in); + m->openInputFile(inputFilename, in); in.seekg(filePos->start); @@ -470,7 +470,7 @@ int FilterSeqsCommand::driverRunFilter(string F, string outputFilename, string i if (m->control_pressed) { in.close(); out.close(); return 0; } - Sequence seq(in); gobble(in); + Sequence seq(in); m->gobble(in); if (seq.getName() != "") { string align = seq.getAligned(); string filterSeq = ""; @@ -528,7 +528,7 @@ int FilterSeqsCommand::createProcessesRunFilter(string F, string filename) { //pass numSeqs to parent ofstream out; string tempFile = filename + toString(getpid()) + ".num.temp"; - openOutputFile(tempFile, out); + m->openOutputFile(tempFile, out); out << num << endl; out.close(); @@ -545,7 +545,7 @@ int FilterSeqsCommand::createProcessesRunFilter(string F, string filename) { for (int i = 0; i < processIDS.size(); i++) { ifstream in; string tempFile = filename + toString(processIDS[i]) + ".num.temp"; - openInputFile(tempFile, in); + m->openInputFile(tempFile, in); if (!in.eof()) { int tempNum = 0; in >> tempNum; num += tempNum; } in.close(); remove(tempFile.c_str()); } @@ -570,7 +570,7 @@ string FilterSeqsCommand::createFilter() { F.setLength(alignmentLength); - if(trump != '*' || isTrue(vertical) || soft != 0){ + if(trump != '*' || m->isTrue(vertical) || soft != 0){ F.initialize(); } @@ -578,7 +578,7 @@ string FilterSeqsCommand::createFilter() { else { F.setFilter(string(alignmentLength, '1')); } numSeqs = 0; - if(trump != '*' || isTrue(vertical) || soft != 0){ + if(trump != '*' || m->isTrue(vertical) || soft != 0){ for (int s = 0; s < fastafileNames.size(); s++) { for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); @@ -604,7 +604,7 @@ string FilterSeqsCommand::createFilter() { if (m->control_pressed) { MPI_File_close(&inMPI); return 0; } if (pid == 0) { //you are the root process - MPIPos = setFilePosFasta(fastafileNames[s], num); //fills MPIPos, returns numSeqs + MPIPos = m->setFilePosFasta(fastafileNames[s], num); //fills MPIPos, returns numSeqs numSeqs += num; //send file positions to all processes @@ -646,7 +646,7 @@ string FilterSeqsCommand::createFilter() { MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case #else - vector positions = divideFile(fastafileNames[s], processors); + vector positions = m->divideFile(fastafileNames[s], processors); for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(new linePair(positions[i], positions[(i+1)])); @@ -679,7 +679,7 @@ string FilterSeqsCommand::createFilter() { MPI_Comm_rank(MPI_COMM_WORLD, &pid); - if(trump != '*' || isTrue(vertical) || soft != 0){ + if(trump != '*' || m->isTrue(vertical) || soft != 0){ if (pid == 0) { //only one process should output the filter @@ -727,8 +727,9 @@ string FilterSeqsCommand::createFilter() { if (pid == 0) { //only one process should output the filter #endif + F.setNumSeqs(numSeqs); - if(isTrue(vertical) == 1) { F.doVertical(); } + if(m->isTrue(vertical) == 1) { F.doVertical(); } if(soft != 0) { F.doSoft(); } filterString = F.getFilter(); @@ -764,7 +765,7 @@ int FilterSeqsCommand::driverCreateFilter(Filters& F, string filename, linePair* try { ifstream in; - openInputFile(filename, in); + m->openInputFile(filename, in); in.seekg(filePos->start); @@ -775,12 +776,12 @@ int FilterSeqsCommand::driverCreateFilter(Filters& F, string filename, linePair* if (m->control_pressed) { in.close(); return 1; } - Sequence seq(in); gobble(in); + Sequence seq(in); m->gobble(in); if (seq.getName() != "") { if (seq.getAligned().length() != alignmentLength) { m->mothurOut("Sequences are not all the same length, please correct."); m->mothurOutEndLine(); m->control_pressed = true; } if(trump != '*') { F.doTrump(seq); } - if(isTrue(vertical) || soft != 0) { F.getFreqs(seq); } + if(m->isTrue(vertical) || soft != 0) { F.getFreqs(seq); } cout.flush(); count++; } @@ -831,7 +832,7 @@ int FilterSeqsCommand::MPICreateFilter(int start, int num, Filters& F, MPI_File& if (seq.getAligned().length() != alignmentLength) { cout << "Alignment length is " << alignmentLength << " and sequence " << seq.getName() << " has length " << seq.getAligned().length() << ", please correct." << endl; exit(1); } if(trump != '*'){ F.doTrump(seq); } - if(isTrue(vertical) || soft != 0){ F.getFreqs(seq); } + if(m->isTrue(vertical) || soft != 0){ F.getFreqs(seq); } cout.flush(); //report progress @@ -878,7 +879,7 @@ int FilterSeqsCommand::createProcessesCreateFilter(Filters& F, string filename) //write out filter counts to file filename += toString(getpid()) + "filterValues.temp"; ofstream out; - openOutputFile(filename, out); + m->openOutputFile(filename, out); out << num << endl; out << F.getFilter() << endl; @@ -905,21 +906,21 @@ int FilterSeqsCommand::createProcessesCreateFilter(Filters& F, string filename) for (int i = 0; i < processIDS.size(); i++) { string tempFilename = filename + toString(processIDS[i]) + "filterValues.temp"; ifstream in; - openInputFile(tempFilename, in); + m->openInputFile(tempFilename, in); int temp, tempNum; string tempFilterString; - in >> tempNum; gobble(in); num += tempNum; + in >> tempNum; m->gobble(in); num += tempNum; in >> tempFilterString; F.mergeFilter(tempFilterString); - for (int k = 0; k < alignmentLength; k++) { in >> temp; F.a[k] += temp; } gobble(in); - for (int k = 0; k < alignmentLength; k++) { in >> temp; F.t[k] += temp; } gobble(in); - for (int k = 0; k < alignmentLength; k++) { in >> temp; F.g[k] += temp; } gobble(in); - for (int k = 0; k < alignmentLength; k++) { in >> temp; F.c[k] += temp; } gobble(in); - for (int k = 0; k < alignmentLength; k++) { in >> temp; F.gap[k] += temp; } gobble(in); + for (int k = 0; k < alignmentLength; k++) { in >> temp; F.a[k] += temp; } m->gobble(in); + for (int k = 0; k < alignmentLength; k++) { in >> temp; F.t[k] += temp; } m->gobble(in); + for (int k = 0; k < alignmentLength; k++) { in >> temp; F.g[k] += temp; } m->gobble(in); + for (int k = 0; k < alignmentLength; k++) { in >> temp; F.c[k] += temp; } m->gobble(in); + for (int k = 0; k < alignmentLength; k++) { in >> temp; F.gap[k] += temp; } m->gobble(in); in.close(); remove(tempFilename.c_str()); diff --git a/formatcolumn.cpp b/formatcolumn.cpp index 64b8531..2bbcf51 100644 --- a/formatcolumn.cpp +++ b/formatcolumn.cpp @@ -12,7 +12,7 @@ /***********************************************************************/ FormatColumnMatrix::FormatColumnMatrix(string df) : filename(df){ - openInputFile(filename, fileHandle); + m->openInputFile(filename, fileHandle); } /***********************************************************************/ @@ -35,7 +35,7 @@ int FormatColumnMatrix::read(NameAssignment* nameMap){ ofstream out; string tempOutFile = filename + ".temp"; - openOutputFile(tempOutFile, out); + m->openOutputFile(tempOutFile, out); while(fileHandle && lt == 1){ //let's assume it's a triangular matrix... @@ -68,7 +68,7 @@ int FormatColumnMatrix::read(NameAssignment* nameMap){ reading->update(itA->second * nseqs / 2); } - gobble(fileHandle); + m->gobble(fileHandle); } out.close(); fileHandle.close(); @@ -79,7 +79,7 @@ int FormatColumnMatrix::read(NameAssignment* nameMap){ }else{ squareFile = tempOutFile; } //sort file by first column so the distances for each row are together - string outfile = getRootName(squareFile) + "sorted.dist.temp"; + string outfile = m->getRootName(squareFile) + "sorted.dist.temp"; //use the unix sort #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) @@ -94,10 +94,10 @@ int FormatColumnMatrix::read(NameAssignment* nameMap){ //output to new file distance for each row and save positions in file where new row begins ifstream in; - openInputFile(outfile, in); + m->openInputFile(outfile, in); distFile = outfile + ".rowFormatted"; - openOutputFile(distFile, out); + m->openOutputFile(distFile, out); rowPos.resize(nseqs, -1); int currentRow; @@ -117,7 +117,7 @@ int FormatColumnMatrix::read(NameAssignment* nameMap){ if (m->control_pressed) { in.close(); out.close(); remove(distFile.c_str()); remove(tempOutFile.c_str()); remove(outfile.c_str()); delete reading; return 0; } - in >> first >> second >> dist; gobble(in); + in >> first >> second >> dist; m->gobble(in); if (first != currentRow) { //save position in file of each new row diff --git a/formatphylip.cpp b/formatphylip.cpp index 206df7e..60a3b41 100644 --- a/formatphylip.cpp +++ b/formatphylip.cpp @@ -12,7 +12,7 @@ /***********************************************************************/ FormatPhylipMatrix::FormatPhylipMatrix(string df) : filename(df) { - openInputFile(filename, fileHandle); + m->openInputFile(filename, fileHandle); } /***********************************************************************/ //not using nameMap @@ -37,11 +37,11 @@ int FormatPhylipMatrix::read(NameAssignment* nameMap){ fileHandle.close(); //reset file //open and get through numSeqs, code below formats rest of file - openInputFile(filename, fileHandle); - fileHandle >> nseqs; gobble(fileHandle); + m->openInputFile(filename, fileHandle); + fileHandle >> nseqs; m->gobble(fileHandle); distFile = filename + ".rowFormatted"; - openOutputFile(distFile, out); + m->openOutputFile(distFile, out); break; } if(d == '\n'){ @@ -59,7 +59,7 @@ int FormatPhylipMatrix::read(NameAssignment* nameMap){ ofstream outTemp; string tempFile = filename + ".temp"; - openOutputFile(tempFile, outTemp); + m->openOutputFile(tempFile, outTemp); //convert to square column matrix for(int i=1;igetRootName(tempFile) + "sorted.dist.temp"; //use the unix sort #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) @@ -103,10 +103,10 @@ int FormatPhylipMatrix::read(NameAssignment* nameMap){ //output to new file distance for each row and save positions in file where new row begins ifstream in; - openInputFile(outfile, in); + m->openInputFile(outfile, in); distFile = outfile + ".rowFormatted"; - openOutputFile(distFile, out); + m->openOutputFile(distFile, out); rowPos.resize(nseqs, -1); int currentRow; @@ -125,7 +125,7 @@ int FormatPhylipMatrix::read(NameAssignment* nameMap){ while(!in.eof()) { if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); remove(distFile.c_str()); remove(outfile.c_str()); delete reading; return 0; } - in >> first >> second >> dist; gobble(in); + in >> first >> second >> dist; m->gobble(in); if (first != currentRow) { //save position in file of each new row @@ -196,7 +196,7 @@ int FormatPhylipMatrix::read(NameAssignment* nameMap){ reading->update(index); } - gobble(fileHandle); + m->gobble(fileHandle); //save position in file of each new row rowPos[i] = out.tellp(); diff --git a/getgroupcommand.cpp b/getgroupcommand.cpp index 817331f..cf47661 100644 --- a/getgroupcommand.cpp +++ b/getgroupcommand.cpp @@ -40,12 +40,12 @@ GetgroupCommand::GetgroupCommand(string option) { if (abort == false) { //open shared file sharedfile = globaldata->getSharedFile(); - openInputFile(sharedfile, in); + m->openInputFile(sharedfile, in); //open output file - if (outputDir == "") { outputDir += hasPath(sharedfile); } - outputFile = outputDir + getRootName(getSimpleName(sharedfile)) + "bootGroups"; - openOutputFile(outputFile, out); + if (outputDir == "") { outputDir += m->hasPath(sharedfile); } + outputFile = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "bootGroups"; + m->openOutputFile(outputFile, out); } } diff --git a/getlabelcommand.cpp b/getlabelcommand.cpp index 1c08eb1..971feb4 100644 --- a/getlabelcommand.cpp +++ b/getlabelcommand.cpp @@ -59,7 +59,7 @@ int GetlabelCommand::execute(){ filename = globaldata->inputFileName; ifstream in; - openInputFile(filename, in); + m->openInputFile(filename, in); string label; int numBins = 0; int count = -1; diff --git a/getlistcountcommand.cpp b/getlistcountcommand.cpp index 43280ed..23c0eaf 100644 --- a/getlistcountcommand.cpp +++ b/getlistcountcommand.cpp @@ -46,7 +46,7 @@ GetListCountCommand::GetListCountCommand(string option) { it = parameters.find("list"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["list"] = inputDir + it->second; } } @@ -70,7 +70,7 @@ GetListCountCommand::GetListCountCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -160,7 +160,7 @@ int GetListCountCommand::execute(){ userLabels.erase(list->getLabel()); } - if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = list->getLabel(); delete list; @@ -245,9 +245,9 @@ int GetListCountCommand::execute(){ void GetListCountCommand::process(ListVector* list) { try { string binnames; - if (outputDir == "") { outputDir += hasPath(listfile); } - string outputFileName = outputDir + getRootName(getSimpleName(listfile)) + list->getLabel() + ".otu"; - openOutputFile(outputFileName, out); + if (outputDir == "") { outputDir += m->hasPath(listfile); } + string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + list->getLabel() + ".otu"; + m->openOutputFile(outputFileName, out); outputNames.push_back(outputFileName); m->mothurOut(list->getLabel()); m->mothurOutEndLine(); @@ -262,7 +262,7 @@ void GetListCountCommand::process(ListVector* list) { out << i+1 << '\t' << binnames << endl; }else{ //sort = name vector names; - splitAtComma(binnames, names); + m->splitAtComma(binnames, names); for (int j = 0; j < names.size(); j++) { out << names[j] << '\t' << i+1 << endl; diff --git a/getoturepcommand.cpp b/getoturepcommand.cpp index de7d761..6b2570c 100644 --- a/getoturepcommand.cpp +++ b/getoturepcommand.cpp @@ -70,7 +70,7 @@ GetOTURepCommand::GetOTURepCommand(string option) { it = parameters.find("list"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["list"] = inputDir + it->second; } } @@ -78,7 +78,7 @@ GetOTURepCommand::GetOTURepCommand(string option) { it = parameters.find("fasta"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } @@ -86,7 +86,7 @@ GetOTURepCommand::GetOTURepCommand(string option) { it = parameters.find("phylip"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["phylip"] = inputDir + it->second; } } @@ -94,7 +94,7 @@ GetOTURepCommand::GetOTURepCommand(string option) { it = parameters.find("column"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["column"] = inputDir + it->second; } } @@ -102,7 +102,7 @@ GetOTURepCommand::GetOTURepCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -110,7 +110,7 @@ GetOTURepCommand::GetOTURepCommand(string option) { it = parameters.find("group"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["group"] = inputDir + it->second; } } @@ -153,7 +153,7 @@ GetOTURepCommand::GetOTURepCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; allLines = 1; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -179,13 +179,13 @@ GetOTURepCommand::GetOTURepCommand(string option) { m->mothurOut("You must provide a groupfile to use groups."); m->mothurOutEndLine(); abort = true; }else { - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); } } globaldata->Groups = Groups; string temp = validParameter.validFile(parameters, "large", false); if (temp == "not found") { temp = "F"; } - large = isTrue(temp); + large = m->isTrue(temp); temp = validParameter.validFile(parameters, "precision", false); if (temp == "not found") { temp = "100"; } convert(temp, precision); @@ -307,7 +307,7 @@ int GetOTURepCommand::execute(){ delete nameMap; //openfile for getMap to use - openInputFile(distFile, inRow); + m->openInputFile(distFile, inRow); if (m->control_pressed) { inRow.close(); remove(distFile.c_str()); return 0; } } @@ -322,7 +322,7 @@ int GetOTURepCommand::execute(){ names.clear(); binnames = globaldata->gListVector->get(i); - splitAtComma(binnames, names); + m->splitAtComma(binnames, names); for (int j = 0; j < names.size(); j++) { nameToIndex[names[j]] = i; @@ -386,7 +386,7 @@ int GetOTURepCommand::execute(){ userLabels.erase(list->getLabel()); } - if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = list->getLabel(); delete list; @@ -489,7 +489,7 @@ int GetOTURepCommand::execute(){ void GetOTURepCommand::readNamesFile() { try { vector dupNames; - openInputFile(namefile, inNames); + m->openInputFile(namefile, inNames); string name, names, sequence; @@ -500,7 +500,7 @@ void GetOTURepCommand::readNamesFile() { dupNames.clear(); //parse names into vector - splitAtComma(names, dupNames); + m->splitAtComma(names, dupNames); //store names in fasta map sequence = fasta->getSequence(name); @@ -508,7 +508,7 @@ void GetOTURepCommand::readNamesFile() { fasta->push_back(dupNames[i], sequence); } - gobble(inNames); + m->gobble(inNames); } inNames.close(); @@ -598,15 +598,15 @@ int GetOTURepCommand::process(ListVector* processList) { string nameRep; //create output file - if (outputDir == "") { outputDir += hasPath(listfile); } + if (outputDir == "") { outputDir += m->hasPath(listfile); } ofstream newNamesOutput; string outputNamesFile; map filehandles; if (Groups.size() == 0) { //you don't want to use groups - outputNamesFile = outputDir + getRootName(getSimpleName(listfile)) + processList->getLabel() + ".rep.names"; - openOutputFile(outputNamesFile, newNamesOutput); + outputNamesFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + ".rep.names"; + m->openOutputFile(outputNamesFile, newNamesOutput); outputNames.push_back(outputNamesFile); outputNameFiles[outputNamesFile] = processList->getLabel(); }else{ //you want to use groups @@ -614,9 +614,9 @@ int GetOTURepCommand::process(ListVector* processList) { for (int i=0; igetLabel() + "." + Groups[i] + ".rep.names"; + outputNamesFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + "." + Groups[i] + ".rep.names"; - openOutputFile(outputNamesFile, *(temp)); + m->openOutputFile(outputNamesFile, *(temp)); outputNames.push_back(outputNamesFile); outputNameFiles[outputNamesFile] = processList->getLabel() + "." + Groups[i]; } @@ -639,7 +639,7 @@ int GetOTURepCommand::process(ListVector* processList) { string temp = processList->get(i); vector namesInBin; - splitAtComma(temp, namesInBin); + m->splitAtComma(temp, namesInBin); if (Groups.size() == 0) { nameRep = findRep(namesInBin); @@ -655,7 +655,7 @@ int GetOTURepCommand::process(ListVector* processList) { if (thisgroup == "not found") { m->mothurOut(namesInBin[j] + " is not in your groupfile, please correct."); m->mothurOutEndLine(); m->control_pressed = true; } - if (inUsersGroups(thisgroup, Groups)) { //add this name to correct group + if (m->inUsersGroups(thisgroup, Groups)) { //add this name to correct group NamesInGroup[thisgroup].push_back(namesInBin[j]); } } @@ -701,27 +701,27 @@ int GetOTURepCommand::processNames(string filename, string label) { try{ //create output file - if (outputDir == "") { outputDir += hasPath(listfile); } - string outputFileName = outputDir + getRootName(getSimpleName(listfile)) + label + ".rep.fasta"; - openOutputFile(outputFileName, out); + if (outputDir == "") { outputDir += m->hasPath(listfile); } + string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + label + ".rep.fasta"; + m->openOutputFile(outputFileName, out); vector reps; outputNames.push_back(outputFileName); ofstream out2; string tempNameFile = filename + ".temp"; - openOutputFile(tempNameFile, out2); + m->openOutputFile(tempNameFile, out2); ifstream in; - openInputFile(filename, in); + m->openInputFile(filename, in); int i = 0; while (!in.eof()) { string rep, binnames; - in >> i >> rep >> binnames; gobble(in); + in >> i >> rep >> binnames; m->gobble(in); out2 << rep << '\t' << binnames << endl; vector names; - splitAtComma(binnames, names); + m->splitAtComma(binnames, names); int binsize = names.size(); //if you have a groupfile diff --git a/getrabundcommand.cpp b/getrabundcommand.cpp index b665c88..b7dd715 100644 --- a/getrabundcommand.cpp +++ b/getrabundcommand.cpp @@ -39,7 +39,7 @@ GetRAbundCommand::GetRAbundCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter string outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it } //make sure the user has already run the read.otu command @@ -50,12 +50,12 @@ GetRAbundCommand::GetRAbundCommand(string option) { string temp; temp = validParameter.validFile(parameters, "sorted", false); if (temp == "not found") { temp = "T"; } - sorted = isTrue(temp); + sorted = m->isTrue(temp); label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -66,8 +66,8 @@ GetRAbundCommand::GetRAbundCommand(string option) { } if (abort == false) { - filename = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "rabund"; - openOutputFile(filename, out); + filename = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "rabund"; + m->openOutputFile(filename, out); } } @@ -141,7 +141,7 @@ int GetRAbundCommand::execute(){ userLabels.erase(list->getLabel()); } - if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = list->getLabel(); delete list; diff --git a/getrelabundcommand.cpp b/getrelabundcommand.cpp index 037cd3e..4c79b21 100644 --- a/getrelabundcommand.cpp +++ b/getrelabundcommand.cpp @@ -39,7 +39,7 @@ GetRelAbundCommand::GetRelAbundCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it } //make sure the user has already run the read.otu command @@ -52,7 +52,7 @@ GetRelAbundCommand::GetRelAbundCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -66,7 +66,7 @@ GetRelAbundCommand::GetRelAbundCommand(string option) { if (groups == "not found") { groups = ""; pickedGroups = false; } else { pickedGroups = true; - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); globaldata->Groups = Groups; } @@ -118,9 +118,9 @@ int GetRelAbundCommand::execute(){ if (abort == true) { return 0; } - string outputFileName = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "relabund"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "relabund"; ofstream out; - openOutputFile(outputFileName, out); + m->openOutputFile(outputFileName, out); out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint); read = new ReadOTUFile(globaldata->inputFileName); @@ -147,7 +147,7 @@ int GetRelAbundCommand::execute(){ userLabels.erase(lookup[0]->getLabel()); } - if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = lookup[0]->getLabel(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } diff --git a/getsabundcommand.cpp b/getsabundcommand.cpp index ca8c8a6..ba05ea1 100644 --- a/getsabundcommand.cpp +++ b/getsabundcommand.cpp @@ -39,7 +39,7 @@ GetSAbundCommand::GetSAbundCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter string outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it } //make sure the user has already run the read.otu command @@ -50,7 +50,7 @@ GetSAbundCommand::GetSAbundCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -61,8 +61,8 @@ GetSAbundCommand::GetSAbundCommand(string option) { } if (abort == false) { - filename = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "sabund"; - openOutputFile(filename, out); + filename = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "sabund"; + m->openOutputFile(filename, out); } } @@ -133,7 +133,7 @@ int GetSAbundCommand::execute(){ userLabels.erase(order->getLabel()); } - if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = order->getLabel(); delete order; diff --git a/getseqscommand.cpp b/getseqscommand.cpp index ef0a1ac..e7226ce 100644 --- a/getseqscommand.cpp +++ b/getseqscommand.cpp @@ -47,7 +47,7 @@ GetSeqsCommand::GetSeqsCommand(string option) { it = parameters.find("alignreport"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["alignreport"] = inputDir + it->second; } } @@ -55,7 +55,7 @@ GetSeqsCommand::GetSeqsCommand(string option) { it = parameters.find("fasta"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } @@ -63,7 +63,7 @@ GetSeqsCommand::GetSeqsCommand(string option) { it = parameters.find("accnos"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["accnos"] = inputDir + it->second; } } @@ -71,7 +71,7 @@ GetSeqsCommand::GetSeqsCommand(string option) { it = parameters.find("list"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["list"] = inputDir + it->second; } } @@ -79,7 +79,7 @@ GetSeqsCommand::GetSeqsCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -87,7 +87,7 @@ GetSeqsCommand::GetSeqsCommand(string option) { it = parameters.find("group"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["group"] = inputDir + it->second; } } @@ -95,7 +95,7 @@ GetSeqsCommand::GetSeqsCommand(string option) { it = parameters.find("taxonomy"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["taxonomy"] = inputDir + it->second; } } @@ -133,7 +133,7 @@ GetSeqsCommand::GetSeqsCommand(string option) { string usedDups = "true"; string temp = validParameter.validFile(parameters, "dups", false); if (temp == "not found") { temp = "false"; usedDups = ""; } - dups = isTrue(temp); + dups = m->isTrue(temp); if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "") && (taxfile == "")) { m->mothurOut("You must provide one of the following: fasta, name, group, alignreport, taxonomy or listfile."); m->mothurOutEndLine(); abort = true; } @@ -206,14 +206,14 @@ int GetSeqsCommand::execute(){ //********************************************************************************************************************** int GetSeqsCommand::readFasta(){ try { - if (outputDir == "") { outputDir += hasPath(fastafile); } - string outputFileName = outputDir + getRootName(getSimpleName(fastafile)) + "pick" + getExtension(fastafile); + if (outputDir == "") { outputDir += m->hasPath(fastafile); } + string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "pick" + m->getExtension(fastafile); ofstream out; - openOutputFile(outputFileName, out); + m->openOutputFile(outputFileName, out); ifstream in; - openInputFile(fastafile, in); + m->openInputFile(fastafile, in); string name; bool wroteSomething = false; @@ -233,7 +233,7 @@ int GetSeqsCommand::readFasta(){ currSeq.printSequence(out); } } - gobble(in); + m->gobble(in); } in.close(); out.close(); @@ -252,13 +252,13 @@ int GetSeqsCommand::readFasta(){ //********************************************************************************************************************** int GetSeqsCommand::readList(){ try { - if (outputDir == "") { outputDir += hasPath(listfile); } - string outputFileName = outputDir + getRootName(getSimpleName(listfile)) + "pick" + getExtension(listfile); + if (outputDir == "") { outputDir += m->hasPath(listfile); } + string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" + m->getExtension(listfile); ofstream out; - openOutputFile(outputFileName, out); + m->openOutputFile(outputFileName, out); ifstream in; - openInputFile(listfile, in); + m->openInputFile(listfile, in); bool wroteSomething = false; @@ -304,7 +304,7 @@ int GetSeqsCommand::readList(){ newList.print(out); } - gobble(in); + m->gobble(in); } in.close(); out.close(); @@ -323,14 +323,14 @@ int GetSeqsCommand::readList(){ //********************************************************************************************************************** int GetSeqsCommand::readName(){ try { - if (outputDir == "") { outputDir += hasPath(namefile); } - string outputFileName = outputDir + getRootName(getSimpleName(namefile)) + "pick" + getExtension(namefile); + if (outputDir == "") { outputDir += m->hasPath(namefile); } + string outputFileName = outputDir + m->getRootName(m->getSimpleName(namefile)) + "pick" + m->getExtension(namefile); ofstream out; - openOutputFile(outputFileName, out); + m->openOutputFile(outputFileName, out); ifstream in; - openInputFile(namefile, in); + m->openInputFile(namefile, in); string name, firstCol, secondCol; bool wroteSomething = false; @@ -396,7 +396,7 @@ int GetSeqsCommand::readName(){ } } } - gobble(in); + m->gobble(in); } in.close(); out.close(); @@ -416,14 +416,14 @@ int GetSeqsCommand::readName(){ //********************************************************************************************************************** int GetSeqsCommand::readGroup(){ try { - if (outputDir == "") { outputDir += hasPath(groupfile); } - string outputFileName = outputDir + getRootName(getSimpleName(groupfile)) + "pick" + getExtension(groupfile); + if (outputDir == "") { outputDir += m->hasPath(groupfile); } + string outputFileName = outputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile); ofstream out; - openOutputFile(outputFileName, out); + m->openOutputFile(outputFileName, out); ifstream in; - openInputFile(groupfile, in); + m->openInputFile(groupfile, in); string name, group; bool wroteSomething = false; @@ -443,7 +443,7 @@ int GetSeqsCommand::readGroup(){ out << name << '\t' << group << endl; } - gobble(in); + m->gobble(in); } in.close(); out.close(); @@ -462,13 +462,13 @@ int GetSeqsCommand::readGroup(){ //********************************************************************************************************************** int GetSeqsCommand::readTax(){ try { - if (outputDir == "") { outputDir += hasPath(taxfile); } - string outputFileName = outputDir + getRootName(getSimpleName(taxfile)) + "pick" + getExtension(taxfile); + if (outputDir == "") { outputDir += m->hasPath(taxfile); } + string outputFileName = outputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile); ofstream out; - openOutputFile(outputFileName, out); + m->openOutputFile(outputFileName, out); ifstream in; - openInputFile(taxfile, in); + m->openInputFile(taxfile, in); string name, tax; bool wroteSomething = false; @@ -487,7 +487,7 @@ int GetSeqsCommand::readTax(){ out << name << '\t' << tax << endl; } - gobble(in); + m->gobble(in); } in.close(); out.close(); @@ -507,14 +507,14 @@ int GetSeqsCommand::readTax(){ //alignreport file has a column header line then all other lines contain 16 columns. we just want the first column since that contains the name int GetSeqsCommand::readAlign(){ try { - if (outputDir == "") { outputDir += hasPath(alignfile); } - string outputFileName = outputDir + getRootName(getSimpleName(alignfile)) + "pick.align.report"; + if (outputDir == "") { outputDir += m->hasPath(alignfile); } + string outputFileName = outputDir + m->getRootName(m->getSimpleName(alignfile)) + "pick.align.report"; ofstream out; - openOutputFile(outputFileName, out); + m->openOutputFile(outputFileName, out); ifstream in; - openInputFile(alignfile, in); + m->openInputFile(alignfile, in); string name, junk; bool wroteSomething = false; @@ -554,7 +554,7 @@ int GetSeqsCommand::readAlign(){ } } - gobble(in); + m->gobble(in); } in.close(); out.close(); @@ -576,7 +576,7 @@ int GetSeqsCommand::readAccnos(){ try { ifstream in; - openInputFile(accnosfile, in); + m->openInputFile(accnosfile, in); string name; while(!in.eof()){ @@ -584,7 +584,7 @@ int GetSeqsCommand::readAccnos(){ names.insert(name); - gobble(in); + m->gobble(in); } in.close(); diff --git a/getsharedotucommand.cpp b/getsharedotucommand.cpp index d2e4088..492195d 100644 --- a/getsharedotucommand.cpp +++ b/getsharedotucommand.cpp @@ -50,7 +50,7 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option) { it = parameters.find("fasta"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } @@ -58,7 +58,7 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option) { it = parameters.find("list"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["list"] = inputDir + it->second; } } @@ -66,7 +66,7 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option) { it = parameters.find("group"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["group"] = inputDir + it->second; } } @@ -90,7 +90,7 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -101,7 +101,7 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option) { if (groups == "not found") { groups = ""; } else { userGroups = "unique." + groups; - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); globaldata->Groups = Groups; } @@ -110,7 +110,7 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option) { if (groups == "not found") { groups = ""; } else { userGroups = groups; - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); globaldata->Groups = Groups; unique = false; } @@ -188,12 +188,12 @@ int GetSharedOTUCommand::execute(){ if (fastafile != "") { ifstream inFasta; - openInputFile(fastafile, inFasta); + m->openInputFile(fastafile, inFasta); while(!inFasta.eof()) { if (m->control_pressed) { inFasta.close(); delete groupMap; return 0; } - Sequence seq(inFasta); gobble(inFasta); + Sequence seq(inFasta); m->gobble(inFasta); if (seq.getName() != "") { seqs.push_back(seq); } } inFasta.close(); @@ -207,7 +207,7 @@ int GetSharedOTUCommand::execute(){ set userLabels = labels; ifstream in; - openInputFile(listfile, in); + m->openInputFile(listfile, in); //as long as you are not at the end of the file or done wih the lines you want while((!in.eof()) && ((allLines == 1) || (userLabels.size() != 0))) { @@ -228,7 +228,7 @@ int GetSharedOTUCommand::execute(){ userLabels.erase(list->getLabel()); } - if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = list->getLabel(); m->mothurOut(lastlist->getLabel()); @@ -302,13 +302,13 @@ int GetSharedOTUCommand::process(ListVector* shared) { ofstream outNames; string outputFileNames; - if (outputDir == "") { outputDir += hasPath(listfile); } + if (outputDir == "") { outputDir += m->hasPath(listfile); } if (output != "accnos") { - outputFileNames = outputDir + getRootName(getSimpleName(listfile)) + shared->getLabel() + userGroups + ".shared.seqs"; + outputFileNames = outputDir + m->getRootName(m->getSimpleName(listfile)) + shared->getLabel() + userGroups + ".shared.seqs"; }else { - outputFileNames = outputDir + getRootName(getSimpleName(listfile)) + shared->getLabel() + userGroups + ".accnos"; + outputFileNames = outputDir + m->getRootName(m->getSimpleName(listfile)) + shared->getLabel() + userGroups + ".accnos"; } - openOutputFile(outputFileNames, outNames); + m->openOutputFile(outputFileNames, outNames); bool wroteSomething = false; int num = 0; @@ -410,10 +410,10 @@ int GetSharedOTUCommand::process(ListVector* shared) { //if fasta file provided output new fasta file if ((fastafile != "") && wroteSomething) { - if (outputDir == "") { outputDir += hasPath(fastafile); } - string outputFileFasta = outputDir + getRootName(getSimpleName(fastafile)) + shared->getLabel() + userGroups + ".shared.fasta"; + if (outputDir == "") { outputDir += m->hasPath(fastafile); } + string outputFileFasta = outputDir + m->getRootName(m->getSimpleName(fastafile)) + shared->getLabel() + userGroups + ".shared.fasta"; ofstream outFasta; - openOutputFile(outputFileFasta, outFasta); + m->openOutputFile(outputFileFasta, outFasta); outputNames.push_back(outputFileFasta); for (int k = 0; k < seqs.size(); k++) { diff --git a/groupmap.cpp b/groupmap.cpp index d57646e..47fbc36 100644 --- a/groupmap.cpp +++ b/groupmap.cpp @@ -14,7 +14,7 @@ GroupMap::GroupMap(string filename) { m = MothurOut::getInstance(); groupFileName = filename; - openInputFile(filename, fileHandle); + m->openInputFile(filename, fileHandle); index = 0; } @@ -27,7 +27,7 @@ int GroupMap::readMap() { int error = 0; while(fileHandle){ - fileHandle >> seqName; gobble(fileHandle); //read from first column + fileHandle >> seqName; m->gobble(fileHandle); //read from first column fileHandle >> seqGroup; //read from second column if (m->control_pressed) { fileHandle.close(); return 1; } @@ -41,7 +41,7 @@ int GroupMap::readMap() { groupmap[seqName] = seqGroup; //store data in map seqsPerGroup[seqGroup]++; //increment number of seqs in that group } - gobble(fileHandle); + m->gobble(fileHandle); } fileHandle.close(); return error; diff --git a/hcluster.cpp b/hcluster.cpp index 9466483..e1830cd 100644 --- a/hcluster.cpp +++ b/hcluster.cpp @@ -27,7 +27,7 @@ HCluster::HCluster(RAbundVector* rav, ListVector* lv, string ms, string d, NameA } if (method != "average") { - openInputFile(distfile, filehandle); + m->openInputFile(distfile, filehandle); }else{ processFile(); } @@ -389,7 +389,7 @@ vector HCluster::getSeqsFNNN(){ //get entry while (!filehandle.eof()) { - filehandle >> firstName >> secondName >> distance; gobble(filehandle); + filehandle >> firstName >> secondName >> distance; m->gobble(filehandle); //save first one if (prevDistance == -1) { prevDistance = distance; } @@ -438,7 +438,7 @@ vector HCluster::getSeqsAN(){ vector sameSeqs; prevDistance = -1; - openInputFile(distfile, filehandle, "no error"); + m->openInputFile(distfile, filehandle, "no error"); //is the smallest value in mergedMin or the distfile? float mergedMinDist = 10000; @@ -446,7 +446,7 @@ vector HCluster::getSeqsAN(){ if (mergedMin.size() > 0) { mergedMinDist = mergedMin[0].dist; } if (!filehandle.eof()) { - filehandle >> firstName >> secondName >> distance; gobble(filehandle); + filehandle >> firstName >> secondName >> distance; m->gobble(filehandle); //save first one if (prevDistance == -1) { prevDistance = distance; } if (distance != -1) { //-1 means skip me @@ -469,7 +469,7 @@ vector HCluster::getSeqsAN(){ //get entry while (!filehandle.eof()) { - filehandle >> firstName >> secondName >> distance; gobble(filehandle); + filehandle >> firstName >> secondName >> distance; m->gobble(filehandle); if (prevDistance == -1) { prevDistance = distance; } @@ -511,13 +511,13 @@ int HCluster::combineFile() { string tempDistFile = distfile + ".temp"; ofstream out; - openOutputFile(tempDistFile, out); + m->openOutputFile(tempDistFile, out); //FILE* in; //in = fopen(distfile.c_str(), "rb"); ifstream in; - openInputFile(distfile, in); + m->openInputFile(distfile, in); int first, second; float dist; @@ -550,7 +550,7 @@ int HCluster::combineFile() { //since file is sorted and mergedMin is sorted //you can put the smallest distance from each through the code below and keep the file sorted - in >> first >> second >> dist; gobble(in); + in >> first >> second >> dist; m->gobble(in); if (m->control_pressed) { in.close(); out.close(); remove(tempDistFile.c_str()); return 0; } @@ -688,7 +688,7 @@ seqDist HCluster::getNextDist(char* buffer, int& index, int size){ if ((buffer[index] == 10) || (buffer[index] == 13)) { //newline in unix or windows gotDist = true; - //gobble space + //m->gobble space while (index < size) { if (isspace(buffer[index])) { index++; } else { break; } @@ -741,17 +741,17 @@ int HCluster::processFile() { float distance; ifstream in; - openInputFile(distfile, in); + m->openInputFile(distfile, in); ofstream out; string outTemp = distfile + ".temp"; - openOutputFile(outTemp, out); + m->openOutputFile(outTemp, out); //get entry while (!in.eof()) { if (m->control_pressed) { in.close(); out.close(); remove(outTemp.c_str()); return 0; } - in >> firstName >> secondName >> distance; gobble(in); + in >> firstName >> secondName >> distance; m->gobble(in); map::iterator itA = nameMap->find(firstName); map::iterator itB = nameMap->find(secondName); diff --git a/hclustercommand.cpp b/hclustercommand.cpp index b4d6017..fd95323 100644 --- a/hclustercommand.cpp +++ b/hclustercommand.cpp @@ -47,7 +47,7 @@ HClusterCommand::HClusterCommand(string option) { it = parameters.find("phylip"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["phylip"] = inputDir + it->second; } } @@ -55,7 +55,7 @@ HClusterCommand::HClusterCommand(string option) { it = parameters.find("column"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["column"] = inputDir + it->second; } } @@ -63,7 +63,7 @@ HClusterCommand::HClusterCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -105,7 +105,7 @@ HClusterCommand::HClusterCommand(string option) { convert(temp, precision); temp = validParameter.validFile(parameters, "hard", false); if (temp == "not found") { temp = "F"; } - hard = isTrue(temp); + hard = m->isTrue(temp); temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found") { temp = "10"; } @@ -123,7 +123,7 @@ HClusterCommand::HClusterCommand(string option) { sort = validParameter.validFile(parameters, "sorted", false); if (sort == "not found") { sort = "F"; } - sorted = isTrue(sort); + sorted = m->isTrue(sort); timing = validParameter.validFile(parameters, "timing", false); if (timing == "not found") { timing = "F"; } @@ -131,16 +131,16 @@ HClusterCommand::HClusterCommand(string option) { if (abort == false) { - if (outputDir == "") { outputDir += hasPath(distfile); } - fileroot = outputDir + getRootName(getSimpleName(distfile)); + if (outputDir == "") { outputDir += m->hasPath(distfile); } + fileroot = outputDir + m->getRootName(m->getSimpleName(distfile)); if (method == "furthest") { tag = "fn"; } else if (method == "nearest") { tag = "nn"; } else { tag = "an"; } - openOutputFile(fileroot+ tag + ".sabund", sabundFile); - openOutputFile(fileroot+ tag + ".rabund", rabundFile); - openOutputFile(fileroot+ tag + ".list", listFile); + m->openOutputFile(fileroot+ tag + ".sabund", sabundFile); + m->openOutputFile(fileroot+ tag + ".rabund", rabundFile); + m->openOutputFile(fileroot+ tag + ".list", listFile); outputNames.push_back(fileroot+ tag + ".sabund"); outputNames.push_back(fileroot+ tag + ".rabund"); @@ -282,9 +282,9 @@ int HClusterCommand::execute(){ float rndDist; if (hard) { - rndDist = ceilDist(seqs[i].dist, precision); + rndDist = m->ceilDist(seqs[i].dist, precision); }else{ - rndDist = roundDist(seqs[i].dist, precision); + rndDist = m->roundDist(seqs[i].dist, precision); } @@ -360,7 +360,7 @@ int HClusterCommand::execute(){ void HClusterCommand::printData(string label){ try { - if (isTrue(timing)) { + if (m->isTrue(timing)) { m->mothurOut("\tTime: " + toString(time(NULL) - start) + "\tsecs for " + toString(oldRAbund.getNumBins()) + "\tclusters. Updates: " + toString(loops)); m->mothurOutEndLine(); } @@ -369,7 +369,7 @@ void HClusterCommand::printData(string label){ start = time(NULL); oldRAbund.setLabel(label); - if (isTrue(showabund)) { + if (m->isTrue(showabund)) { oldRAbund.getSAbundVector().print(cout); } oldRAbund.print(rabundFile); diff --git a/heatmap.cpp b/heatmap.cpp index aef9f37..2aabfd7 100644 --- a/heatmap.cpp +++ b/heatmap.cpp @@ -63,8 +63,8 @@ string HeatMap::getPic(RAbundVector* rabund) { } - string filenamesvg = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + rabund->getLabel() + ".heatmap.bin.svg"; - openOutputFile(filenamesvg, outsvg); + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + rabund->getLabel() + ".heatmap.bin.svg"; + m->openOutputFile(filenamesvg, outsvg); //svg image outsvg << "getNumBins()*5 + 120)) + "\">\n"; @@ -148,8 +148,8 @@ string HeatMap::getPic(vector lookup) { } } - string filenamesvg = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + ".heatmap.bin.svg"; - openOutputFile(filenamesvg, outsvg); + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + ".heatmap.bin.svg"; + m->openOutputFile(filenamesvg, outsvg); //svg image outsvg << "getNumBins()*5 + 120)) + "\">\n"; diff --git a/heatmapcommand.cpp b/heatmapcommand.cpp index b57f3a0..1ca894f 100644 --- a/heatmapcommand.cpp +++ b/heatmapcommand.cpp @@ -40,7 +40,7 @@ HeatMapCommand::HeatMapCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it } //make sure the user has already run the read.otu command @@ -53,7 +53,7 @@ HeatMapCommand::HeatMapCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -66,7 +66,7 @@ HeatMapCommand::HeatMapCommand(string option) { groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); globaldata->Groups = Groups; } @@ -178,7 +178,7 @@ int HeatMapCommand::execute(){ userLabels.erase(lookup[0]->getLabel()); } - if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = lookup[0]->getLabel(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } @@ -252,7 +252,7 @@ int HeatMapCommand::execute(){ userLabels.erase(rabund->getLabel()); } - if ((anyLabelsToProcess(rabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(rabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = rabund->getLabel(); delete rabund; diff --git a/heatmapsim.cpp b/heatmapsim.cpp index 4fb3e37..efe4140 100644 --- a/heatmapsim.cpp +++ b/heatmapsim.cpp @@ -36,8 +36,8 @@ vector HeatMapSim::getPic(vector lookup, vectorcontrol_pressed) { return outputNames; } - string filenamesvg = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + calcs[k]->getName() + ".heatmap.sim.svg"; - openOutputFile(filenamesvg, outsvg); + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + calcs[k]->getName() + ".heatmap.sim.svg"; + m->openOutputFile(filenamesvg, outsvg); outputNames.push_back(filenamesvg); //svg image @@ -114,8 +114,8 @@ string HeatMapSim::getPic(vector< vector > dists, vector groups) vector sims; - string filenamesvg = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "heatmap.sim.svg"; - openOutputFile(filenamesvg, outsvg); + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "heatmap.sim.svg"; + m->openOutputFile(filenamesvg, outsvg); //svg image outsvg << "\n"; diff --git a/heatmapsimcommand.cpp b/heatmapsimcommand.cpp index dc67a8d..61e2939 100644 --- a/heatmapsimcommand.cpp +++ b/heatmapsimcommand.cpp @@ -62,7 +62,7 @@ HeatMapSimCommand::HeatMapSimCommand(string option) { it = parameters.find("phylip"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["phylip"] = inputDir + it->second; } } @@ -70,7 +70,7 @@ HeatMapSimCommand::HeatMapSimCommand(string option) { it = parameters.find("column"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["column"] = inputDir + it->second; } } @@ -78,7 +78,7 @@ HeatMapSimCommand::HeatMapSimCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -88,12 +88,12 @@ HeatMapSimCommand::HeatMapSimCommand(string option) { phylipfile = validParameter.validFile(parameters, "phylip", true); if (phylipfile == "not open") { abort = true; } else if (phylipfile == "not found") { phylipfile = ""; } - else { format = "phylip"; if (outputDir == "") { outputDir += hasPath(phylipfile); } } + else { format = "phylip"; if (outputDir == "") { outputDir += m->hasPath(phylipfile); } } columnfile = validParameter.validFile(parameters, "column", true); if (columnfile == "not open") { abort = true; } else if (columnfile == "not found") { columnfile = ""; } - else { format = "column"; if (outputDir == "") { outputDir += hasPath(columnfile); } } + else { format = "column"; if (outputDir == "") { outputDir += m->hasPath(columnfile); } } namefile = validParameter.validFile(parameters, "name", true); if (namefile == "not open") { abort = true; } @@ -113,12 +113,12 @@ HeatMapSimCommand::HeatMapSimCommand(string option) { //check for optional parameter and set defaults // ...at some point should added some additional type checking... if (format == "shared") { - if (outputDir == "") { outputDir += hasPath(globaldata->getSharedFile()); } + if (outputDir == "") { outputDir += m->hasPath(globaldata->getSharedFile()); } label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -133,12 +133,12 @@ HeatMapSimCommand::HeatMapSimCommand(string option) { else { if (calc == "default") { calc = "jest-thetayc"; } } - splitAtDash(calc, Estimators); + m->splitAtDash(calc, Estimators); groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); globaldata->Groups = Groups; } } @@ -292,7 +292,7 @@ int HeatMapSimCommand::runCommandShared() { userLabels.erase(lookup[0]->getLabel()); } - if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = lookup[0]->getLabel(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } @@ -374,7 +374,7 @@ int HeatMapSimCommand::runCommandDist() { //read distance file and create distance vector and names vector if (format == "phylip") { //read phylip file - openInputFile(phylipfile, in); + m->openInputFile(phylipfile, in); string name; int numSeqs; @@ -422,7 +422,7 @@ int HeatMapSimCommand::runCommandDist() { if (m->control_pressed) { return 0; } for(int j=0;j> matrix[i][j]; } - gobble(in); + m->gobble(in); } }else { double dist; @@ -436,7 +436,7 @@ int HeatMapSimCommand::runCommandDist() { in >> dist; matrix[i][j] = dist; matrix[j][i] = dist; } - gobble(in); + m->gobble(in); } } in.close(); @@ -459,10 +459,10 @@ int HeatMapSimCommand::runCommandDist() { //read column file string first, second; double dist; - openInputFile(columnfile, in); + m->openInputFile(columnfile, in); while (!in.eof()) { - in >> first >> second >> dist; gobble(in); + in >> first >> second >> dist; m->gobble(in); if (m->control_pressed) { return 0; } diff --git a/inputdata.cpp b/inputdata.cpp index 65685d6..7c9fbe9 100644 --- a/inputdata.cpp +++ b/inputdata.cpp @@ -16,7 +16,7 @@ InputData::InputData(string fName, string f) : format(f){ m = MothurOut::getInstance(); - openInputFile(fName, fileHandle); + m->openInputFile(fName, fileHandle); filename = fName; } @@ -36,7 +36,7 @@ InputData::InputData(string fName, string orderFileName, string f) : format(f){ try { m = MothurOut::getInstance(); ifstream ofHandle; - openInputFile(orderFileName, ofHandle); + m->openInputFile(orderFileName, ofHandle); string name; int count = 0; @@ -45,11 +45,11 @@ InputData::InputData(string fName, string orderFileName, string f) : format(f){ ofHandle >> name; orderMap[name] = count; count++; - gobble(ofHandle); + m->gobble(ofHandle); } ofHandle.close(); - openInputFile(fName, fileHandle); + m->openInputFile(fName, fileHandle); } catch(exception& e) { m->errorOut(e, "InputData", "InputData"); @@ -65,7 +65,7 @@ ListVector* InputData::getListVector(){ list = new ListVector(fileHandle); }else{ list = NULL; } - gobble(fileHandle); + m->gobble(fileHandle); return list; } else{ @@ -83,7 +83,7 @@ ListVector* InputData::getListVector(string label){ try { ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ @@ -98,7 +98,7 @@ ListVector* InputData::getListVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete list; } - gobble(in); + m->gobble(in); } }else{ list = NULL; } @@ -127,7 +127,7 @@ ListVector* InputData::getListVector(string label, bool resetFP){ while (fileHandle.eof() != true) { - list = new ListVector(fileHandle); gobble(fileHandle); + list = new ListVector(fileHandle); m->gobble(fileHandle); thisLabel = list->getLabel(); //if you are at the last label @@ -158,7 +158,7 @@ SharedListVector* InputData::getSharedListVector(){ SharedList = new SharedListVector(fileHandle); }else{ SharedList = NULL; } - gobble(fileHandle); + m->gobble(fileHandle); return SharedList; } else{ @@ -176,7 +176,7 @@ SharedListVector* InputData::getSharedListVector(string label){ try { ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ @@ -191,7 +191,7 @@ SharedListVector* InputData::getSharedListVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete SharedList; } - gobble(in); + m->gobble(in); } }else{ SharedList = NULL; } @@ -220,7 +220,7 @@ SharedOrderVector* InputData::getSharedOrderVector(){ SharedOrder = new SharedOrderVector(fileHandle); }else{ SharedOrder = NULL; } - gobble(fileHandle); + m->gobble(fileHandle); return SharedOrder; }else{ @@ -239,7 +239,7 @@ SharedOrderVector* InputData::getSharedOrderVector(string label){ try { ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ @@ -254,7 +254,7 @@ SharedOrderVector* InputData::getSharedOrderVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete SharedOrder; } - gobble(in); + m->gobble(in); } }else{ SharedOrder = NULL; } @@ -295,7 +295,7 @@ OrderVector* InputData::getOrderVector(){ input = new SAbundVector(fileHandle); } - gobble(fileHandle); + m->gobble(fileHandle); output = new OrderVector(); *output = (input->getOrderVector()); @@ -318,7 +318,7 @@ OrderVector* InputData::getOrderVector(string label){ ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ if((format == "list") || (format == "listorder")) { @@ -332,7 +332,7 @@ OrderVector* InputData::getOrderVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } else if (format == "shared") { @@ -346,7 +346,7 @@ OrderVector* InputData::getOrderVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } @@ -361,7 +361,7 @@ OrderVector* InputData::getOrderVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } @@ -376,7 +376,7 @@ OrderVector* InputData::getOrderVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } @@ -391,7 +391,7 @@ OrderVector* InputData::getOrderVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } @@ -431,7 +431,7 @@ vector InputData::getSharedRAbundVectors(){ return SharedList->getSharedRAbundVector(); } } - gobble(fileHandle); + m->gobble(fileHandle); } //this is created to signal to calling function that the input file is at eof @@ -450,7 +450,7 @@ vector InputData::getSharedRAbundVectors(string label){ ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ if (format == "sharedfile") { @@ -468,7 +468,7 @@ vector InputData::getSharedRAbundVectors(string label){ delete SharedRAbund; } }else{ break; } - gobble(in); + m->gobble(in); } }else if (format == "shared") { @@ -484,7 +484,7 @@ vector InputData::getSharedRAbundVectors(string label){ delete SharedList; } }else{ break; } - gobble(in); + m->gobble(in); } @@ -525,7 +525,7 @@ SAbundVector* InputData::getSAbundVector(){ input = new SAbundVector(fileHandle); } - gobble(fileHandle); + m->gobble(fileHandle); sabund = new SAbundVector(); *sabund = (input->getSAbundVector()); @@ -547,7 +547,7 @@ SAbundVector* InputData::getSAbundVector(string label){ ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ if (format == "list") { @@ -561,7 +561,7 @@ SAbundVector* InputData::getSAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } else if (format == "shared") { @@ -575,7 +575,7 @@ SAbundVector* InputData::getSAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } @@ -590,7 +590,7 @@ SAbundVector* InputData::getSAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } @@ -605,7 +605,7 @@ SAbundVector* InputData::getSAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } @@ -620,7 +620,7 @@ SAbundVector* InputData::getSAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } @@ -664,7 +664,7 @@ RAbundVector* InputData::getRAbundVector(){ input = new SAbundVector(fileHandle); } - gobble(fileHandle); + m->gobble(fileHandle); rabund = new RAbundVector(); *rabund = (input->getRAbundVector()); @@ -686,7 +686,7 @@ RAbundVector* InputData::getRAbundVector(string label){ ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ if (format == "list") { @@ -700,7 +700,7 @@ RAbundVector* InputData::getRAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } else if (format == "shared") { @@ -714,7 +714,7 @@ RAbundVector* InputData::getRAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } @@ -729,7 +729,7 @@ RAbundVector* InputData::getRAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } @@ -744,7 +744,7 @@ RAbundVector* InputData::getRAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } @@ -759,7 +759,7 @@ RAbundVector* InputData::getRAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } diff --git a/jackknife.cpp b/jackknife.cpp index 150b7cd..8f06298 100644 --- a/jackknife.cpp +++ b/jackknife.cpp @@ -12,7 +12,7 @@ /***********************************************************************/ void Jackknife::getAMatrix(void){ try { - vector > B = binomial(maxOrder); + vector > B = m->binomial(maxOrder); aMat.resize(maxOrder+1); diff --git a/kmerdb.cpp b/kmerdb.cpp index bd5b976..2926593 100644 --- a/kmerdb.cpp +++ b/kmerdb.cpp @@ -107,7 +107,7 @@ void KmerDB::generateDB(){ try { ofstream kmerFile; // once we have the kmerLocations folder print it out - openOutputFile(kmerDBName, kmerFile); // to a file + m->openOutputFile(kmerDBName, kmerFile); // to a file //output version kmerFile << m->getVersion() << endl; @@ -160,7 +160,7 @@ void KmerDB::readKmerDB(ifstream& kmerDBFile){ kmerDBFile.seekg(0); // start at the beginning of the file //read version - string line = getline(kmerDBFile); gobble(kmerDBFile); + string line = m->getline(kmerDBFile); m->gobble(kmerDBFile); string seqName; int seqNumber; diff --git a/knn.cpp b/knn.cpp index a843072..1835c48 100644 --- a/knn.cpp +++ b/knn.cpp @@ -26,7 +26,7 @@ void Knn::setDistName(string s) { try { outDistName = s; ofstream outDistance; - openOutputFile(outDistName, outDistance); + m->openOutputFile(outDistName, outDistance); outDistance << "Name\tBestMatch\tDistance" << endl; outDistance.close(); } @@ -54,7 +54,7 @@ string Knn::getTaxonomy(Sequence* seq) { //use database to find closest seq vector closest = database->findClosestSequences(seq, num); - if (search == "distance") { ofstream outDistance; openOutputFileAppend(outDistName, outDistance); outDistance << seq->getName() << '\t' << database->getName(closest[0]) << '\t' << database->getSearchScore() << endl; outDistance.close(); } + if (search == "distance") { ofstream outDistance; m->openOutputFileAppend(outDistName, outDistance); outDistance << seq->getName() << '\t' << database->getName(closest[0]) << '\t' << database->getSearchScore() << endl; outDistance.close(); } if (m->control_pressed) { return tax; } diff --git a/libshuffcommand.cpp b/libshuffcommand.cpp index 219b0bf..773d8d3 100644 --- a/libshuffcommand.cpp +++ b/libshuffcommand.cpp @@ -47,7 +47,7 @@ LibShuffCommand::LibShuffCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(globaldata->getPhylipFile()); //if user entered a file with a path then preserve it + outputDir += m->hasPath(globaldata->getPhylipFile()); //if user entered a file with a path then preserve it } //make sure the user has already run the read.dist command @@ -61,7 +61,7 @@ LibShuffCommand::LibShuffCommand(string option) { if (groups == "not found") { groups = ""; savegroups = groups; } else { savegroups = groups; - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); globaldata->Groups = Groups; } @@ -215,8 +215,8 @@ int LibShuffCommand::printCoverageFile() { try { ofstream outCov; - summaryFile = outputDir + getRootName(getSimpleName(globaldata->getPhylipFile())) + "libshuff.coverage"; - openOutputFile(summaryFile, outCov); + summaryFile = outputDir + m->getRootName(m->getSimpleName(globaldata->getPhylipFile())) + "libshuff.coverage"; + m->openOutputFile(summaryFile, outCov); outputNames.push_back(summaryFile); outCov.setf(ios::fixed, ios::floatfield); outCov.setf(ios::showpoint); //cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint); @@ -311,8 +311,8 @@ int LibShuffCommand::printSummaryFile() { try { ofstream outSum; - summaryFile = outputDir + getRootName(getSimpleName(globaldata->getPhylipFile())) + "libshuff.summary"; - openOutputFile(summaryFile, outSum); + summaryFile = outputDir + m->getRootName(m->getSimpleName(globaldata->getPhylipFile())) + "libshuff.summary"; + m->openOutputFile(summaryFile, outSum); outputNames.push_back(summaryFile); outSum.setf(ios::fixed, ios::floatfield); outSum.setf(ios::showpoint); diff --git a/listseqscommand.cpp b/listseqscommand.cpp index 3200137..a3f88cf 100644 --- a/listseqscommand.cpp +++ b/listseqscommand.cpp @@ -47,7 +47,7 @@ ListSeqsCommand::ListSeqsCommand(string option) { it = parameters.find("alignreport"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["alignreport"] = inputDir + it->second; } } @@ -55,7 +55,7 @@ ListSeqsCommand::ListSeqsCommand(string option) { it = parameters.find("fasta"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } @@ -63,7 +63,7 @@ ListSeqsCommand::ListSeqsCommand(string option) { it = parameters.find("list"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["list"] = inputDir + it->second; } } @@ -71,7 +71,7 @@ ListSeqsCommand::ListSeqsCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -79,7 +79,7 @@ ListSeqsCommand::ListSeqsCommand(string option) { it = parameters.find("group"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["group"] = inputDir + it->second; } } @@ -87,7 +87,7 @@ ListSeqsCommand::ListSeqsCommand(string option) { it = parameters.find("taxonomy"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["taxonomy"] = inputDir + it->second; } } @@ -169,12 +169,12 @@ int ListSeqsCommand::execute(){ //sort in alphabetical order sort(names.begin(), names.end()); - if (outputDir == "") { outputDir += hasPath(inputFileName); } + if (outputDir == "") { outputDir += m->hasPath(inputFileName); } - string outputFileName = outputDir + getRootName(getSimpleName(inputFileName)) + "accnos"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + "accnos"; ofstream out; - openOutputFile(outputFileName, out); + m->openOutputFile(outputFileName, out); //output to .accnos file for (int i = 0; i < names.size(); i++) { @@ -206,7 +206,7 @@ int ListSeqsCommand::readFasta(){ try { ifstream in; - openInputFile(fastafile, in); + m->openInputFile(fastafile, in); string name; while(!in.eof()){ @@ -218,7 +218,7 @@ int ListSeqsCommand::readFasta(){ if (name != "") { names.push_back(name); } - gobble(in); + m->gobble(in); } in.close(); @@ -234,7 +234,7 @@ int ListSeqsCommand::readFasta(){ int ListSeqsCommand::readList(){ try { ifstream in; - openInputFile(listfile, in); + m->openInputFile(listfile, in); if(!in.eof()){ //read in list vector @@ -271,7 +271,7 @@ int ListSeqsCommand::readName(){ try { ifstream in; - openInputFile(namefile, in); + m->openInputFile(namefile, in); string name, firstCol, secondCol; while(!in.eof()){ @@ -291,7 +291,7 @@ int ListSeqsCommand::readName(){ //get name after last , names.push_back(secondCol); - gobble(in); + m->gobble(in); } in.close(); return 0; @@ -308,7 +308,7 @@ int ListSeqsCommand::readGroup(){ try { ifstream in; - openInputFile(groupfile, in); + m->openInputFile(groupfile, in); string name, group; while(!in.eof()){ @@ -320,7 +320,7 @@ int ListSeqsCommand::readGroup(){ names.push_back(name); - gobble(in); + m->gobble(in); } in.close(); return 0; @@ -338,7 +338,7 @@ int ListSeqsCommand::readAlign(){ try { ifstream in; - openInputFile(alignfile, in); + m->openInputFile(alignfile, in); string name, junk; //read column headers @@ -362,7 +362,7 @@ int ListSeqsCommand::readAlign(){ names.push_back(name); - gobble(in); + m->gobble(in); } in.close(); @@ -380,7 +380,7 @@ int ListSeqsCommand::readTax(){ try { ifstream in; - openInputFile(taxfile, in); + m->openInputFile(taxfile, in); string name, firstCol, secondCol; while(!in.eof()){ @@ -392,7 +392,7 @@ int ListSeqsCommand::readTax(){ names.push_back(firstCol); - gobble(in); + m->gobble(in); } in.close(); diff --git a/listvector.cpp b/listvector.cpp index 94ca026..4bb45b7 100644 --- a/listvector.cpp +++ b/listvector.cpp @@ -28,7 +28,7 @@ ListVector::ListVector(string id, vector lv) : DataVector(id), data(lv){ try { for(int i=0;igetNumNames(data[i]); numBins = i+1; if(binSize > maxRank) { maxRank = binSize; } numSeqs += binSize; @@ -56,7 +56,7 @@ ListVector::ListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numS set(i, inputData); } - gobble(f); + m->gobble(f); } catch(exception& e) { m->errorOut(e, "ListVector", "ListVector"); @@ -68,9 +68,9 @@ ListVector::ListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numS void ListVector::set(int binNumber, string seqNames){ try { - int nNames_old = getNumNames(data[binNumber]); + int nNames_old = m->getNumNames(data[binNumber]); data[binNumber] = seqNames; - int nNames_new = getNumNames(seqNames); + int nNames_new = m->getNumNames(seqNames); if(nNames_old == 0) { numBins++; } if(nNames_new == 0) { numBins--; } @@ -95,7 +95,7 @@ string ListVector::get(int index){ void ListVector::push_back(string seqNames){ try { data.push_back(seqNames); - int nNames = getNumNames(seqNames); + int nNames = m->getNumNames(seqNames); numBins++; @@ -157,7 +157,7 @@ RAbundVector ListVector::getRAbundVector(){ RAbundVector rav; for(int i=0;igetNumNames(data[i]); rav.push_back(binSize); } @@ -187,7 +187,7 @@ SAbundVector ListVector::getSAbundVector(){ SAbundVector sav(maxRank+1); for(int i=0;igetNumNames(data[i]); sav.set(binSize, sav.get(binSize) + 1); } sav.set(0, 0); @@ -210,7 +210,7 @@ OrderVector ListVector::getOrderVector(map* orderMap = NULL){ OrderVector ov; for(int i=0;igetNumNames(data[i]); for(int j=0;jmothurOut("fasta is a required parameter for the make.group command."); m->mothurOutEndLine(); abort = true; } else { - splitAtDash(fastaFileName, fastaFileNames); + m->splitAtDash(fastaFileName, fastaFileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < fastaFileNames.size(); i++) { if (inputDir != "") { - string path = hasPath(fastaFileNames[i]); + string path = m->hasPath(fastaFileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { fastaFileNames[i] = inputDir + fastaFileNames[i]; } } ifstream in; - int ableToOpen = openInputFile(fastaFileNames[i], in, "noerror"); + int ableToOpen = m->openInputFile(fastaFileNames[i], in, "noerror"); //if you can't open it, try default location if (ableToOpen == 1) { if (m->getDefaultPath() != "") { //default path is set - string tryPath = m->getDefaultPath() + getSimpleName(fastaFileNames[i]); + string tryPath = m->getDefaultPath() + m->getSimpleName(fastaFileNames[i]); m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = openInputFile(tryPath, in, "noerror"); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); fastaFileNames[i] = tryPath; } } @@ -79,7 +79,7 @@ MakeGroupCommand::MakeGroupCommand(string option) { //erase from file list fastaFileNames.erase(fastaFileNames.begin()+i); i--; - }else{ filename += getRootName(getSimpleName(fastaFileNames[i])); } + }else{ filename += m->getRootName(m->getSimpleName(fastaFileNames[i])); } } filename += "groups"; @@ -90,7 +90,7 @@ MakeGroupCommand::MakeGroupCommand(string option) { groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { m->mothurOut("groups is a required parameter for the make.group command."); m->mothurOutEndLine(); abort = true; } - else { splitAtDash(groups, groupsNames); } + else { m->splitAtDash(groups, groupsNames); } if (groupsNames.size() != fastaFileNames.size()) { m->mothurOut("You do not have the same number of valid fastfile files as groups. This could be because we could not open a fastafile."); m->mothurOutEndLine(); abort = true; } } @@ -131,18 +131,18 @@ int MakeGroupCommand::execute(){ if (abort == true) { return 0; } ofstream out; - openOutputFile(filename, out); + m->openOutputFile(filename, out); for (int i = 0; i < fastaFileNames.size(); i++) { if (m->control_pressed) { out.close(); remove(filename.c_str()); return 0; } ifstream in; - openInputFile(fastaFileNames[i], in); + m->openInputFile(fastaFileNames[i], in); while (!in.eof()) { - Sequence seq(in, "no align"); gobble(in); + Sequence seq(in, "no align"); m->gobble(in); if (m->control_pressed) { in.close(); out.close(); remove(filename.c_str()); return 0; } diff --git a/matrixoutputcommand.cpp b/matrixoutputcommand.cpp index 390f47f..a55edd0 100644 --- a/matrixoutputcommand.cpp +++ b/matrixoutputcommand.cpp @@ -52,7 +52,7 @@ MatrixOutputCommand::MatrixOutputCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it } //make sure the user has already run the read.otu command @@ -66,7 +66,7 @@ MatrixOutputCommand::MatrixOutputCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -82,7 +82,7 @@ MatrixOutputCommand::MatrixOutputCommand(string option) { groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); globaldata->Groups = Groups; } @@ -91,7 +91,7 @@ MatrixOutputCommand::MatrixOutputCommand(string option) { else { if (calc == "default") { calc = "jclass-thetayc"; } } - splitAtDash(calc, Estimators); + m->splitAtDash(calc, Estimators); if (abort == false) { @@ -209,7 +209,7 @@ int MatrixOutputCommand::execute(){ userLabels.erase(lookup[0]->getLabel()); } - if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = lookup[0]->getLabel(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } @@ -347,8 +347,8 @@ int MatrixOutputCommand::process(vector thisLookup){ } } - exportFileName = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".dist"; - openOutputFile(exportFileName, out); + exportFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".dist"; + m->openOutputFile(exportFileName, out); outputNames.push_back(exportFileName); printSims(out); diff --git a/mergefilecommand.cpp b/mergefilecommand.cpp index a076281..098da00 100644 --- a/mergefilecommand.cpp +++ b/mergefilecommand.cpp @@ -40,7 +40,7 @@ MergeFileCommand::MergeFileCommand(string option) { string fileList = validParameter.validFile(parameters, "input", false); if(fileList == "not found") { m->mothurOut("you must enter two or more file names"); m->mothurOutEndLine(); abort=true; } - else{ splitAtDash(fileList, fileNames); } + else{ m->splitAtDash(fileList, fileNames); } //if the user changes the output directory command factory will send this info to us in the output parameter string outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found") { outputDir = ""; } @@ -55,19 +55,19 @@ MergeFileCommand::MergeFileCommand(string option) { else{ for(int i=0;ihasPath(fileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { fileNames[i] = inputDir + fileNames[i]; } } - if(openInputFile(fileNames[i], testFile)){ abort = true; } + if(m->openInputFile(fileNames[i], testFile)){ abort = true; } testFile.close(); } } outputFileName = validParameter.validFile(parameters, "output", false); if (outputFileName == "not found") { m->mothurOut("you must enter an output file name"); m->mothurOutEndLine(); abort=true; } - else if (outputDir != "") { outputFileName = outputDir + getSimpleName(outputFileName); } + else if (outputDir != "") { outputFileName = outputDir + m->getSimpleName(outputFileName); } } } @@ -88,13 +88,13 @@ int MergeFileCommand::execute(){ if (abort == true) { return 0; } ofstream outputFile; - openOutputFile(outputFileName, outputFile); + m->openOutputFile(outputFileName, outputFile); char c; for(int i=0;iopenInputFile(fileNames[i], inputFile); while(!inputFile.eof()){ if (m->control_pressed) { inputFile.close(); outputFile.close(); remove(outputFileName.c_str()); return 0; } diff --git a/mgclustercommand.cpp b/mgclustercommand.cpp index 9a1ac21..eef54ef 100644 --- a/mgclustercommand.cpp +++ b/mgclustercommand.cpp @@ -42,7 +42,7 @@ MGClusterCommand::MGClusterCommand(string option) { it = parameters.find("blast"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["blast"] = inputDir + it->second; } } @@ -50,7 +50,7 @@ MGClusterCommand::MGClusterCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -65,7 +65,7 @@ MGClusterCommand::MGClusterCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(blastfile); //if user entered a file with a path then preserve it + outputDir += m->hasPath(blastfile); //if user entered a file with a path then preserve it } namefile = validParameter.validFile(parameters, "name", true); @@ -97,16 +97,16 @@ MGClusterCommand::MGClusterCommand(string option) { convert(temp, penalty); temp = validParameter.validFile(parameters, "min", false); if (temp == "not found") { temp = "true"; } - minWanted = isTrue(temp); + minWanted = m->isTrue(temp); temp = validParameter.validFile(parameters, "merge", false); if (temp == "not found") { temp = "true"; } - merge = isTrue(temp); + merge = m->isTrue(temp); temp = validParameter.validFile(parameters, "hcluster", false); if (temp == "not found") { temp = "false"; } - hclusterWanted = isTrue(temp); + hclusterWanted = m->isTrue(temp); temp = validParameter.validFile(parameters, "hard", false); if (temp == "not found") { temp = "F"; } - hard = isTrue(temp); + hard = m->isTrue(temp); } } @@ -153,7 +153,7 @@ int MGClusterCommand::execute(){ nameMap->readMap(); }else{ nameMap= new NameAssignment(); } - string fileroot = outputDir + getRootName(getSimpleName(blastfile)); + string fileroot = outputDir + m->getRootName(m->getSimpleName(blastfile)); string tag = ""; time_t start; float previousDist = 0.00000; @@ -179,9 +179,9 @@ int MGClusterCommand::execute(){ else { tag = "an"; } //open output files - openOutputFile(fileroot+ tag + ".list", listFile); - openOutputFile(fileroot+ tag + ".rabund", rabundFile); - openOutputFile(fileroot+ tag + ".sabund", sabundFile); + m->openOutputFile(fileroot+ tag + ".list", listFile); + m->openOutputFile(fileroot+ tag + ".rabund", rabundFile); + m->openOutputFile(fileroot+ tag + ".sabund", sabundFile); if (m->control_pressed) { delete nameMap; delete read; delete list; delete rabund; @@ -223,9 +223,9 @@ int MGClusterCommand::execute(){ float dist = distMatrix->getSmallDist(); float rndDist; if (hard) { - rndDist = ceilDist(dist, precision); + rndDist = m->ceilDist(dist, precision); }else{ - rndDist = roundDist(dist, precision); + rndDist = m->roundDist(dist, precision); } if(previousDist <= 0.0000 && dist != previousDist){ @@ -309,7 +309,7 @@ int MGClusterCommand::execute(){ vector seqs; seqs.resize(1); // to start loop //ifstream inHcluster; - //openInputFile(distFile, inHcluster); + //m->openInputFile(distFile, inHcluster); if (m->control_pressed) { delete nameMap; delete list; delete rabund; delete hcluster; @@ -345,9 +345,9 @@ int MGClusterCommand::execute(){ float rndDist; if (hard) { - rndDist = ceilDist(seqs[i].dist, precision); + rndDist = m->ceilDist(seqs[i].dist, precision); }else{ - rndDist = roundDist(seqs[i].dist, precision); + rndDist = m->roundDist(seqs[i].dist, precision); } if((previousDist <= 0.0000) && (seqs[i].dist != previousDist)){ @@ -477,7 +477,7 @@ ListVector* MGClusterCommand::mergeOPFs(map binInfo, float dist){ int count = 0; if (hclusterWanted) { - openInputFile(overlapFile, inOverlap); + m->openInputFile(overlapFile, inOverlap); if (inOverlap.eof()) { done = true; } }else { if (overlapMatrix.size() == 0) { done = true; } } @@ -498,7 +498,7 @@ ListVector* MGClusterCommand::mergeOPFs(map binInfo, float dist){ if (!inOverlap.eof()) { string firstName, secondName; float overlapDistance; - inOverlap >> firstName >> secondName >> overlapDistance; gobble(inOverlap); + inOverlap >> firstName >> secondName >> overlapDistance; m->gobble(inOverlap); //commented out because we check this in readblast already //map::iterator itA = nameMap->find(firstName); @@ -571,12 +571,12 @@ ListVector* MGClusterCommand::mergeOPFs(map binInfo, float dist){ void MGClusterCommand::sortHclusterFiles(string unsortedDist, string unsortedOverlap) { try { //sort distFile - string sortedDistFile = sortFile(unsortedDist, outputDir); + string sortedDistFile = m->sortFile(unsortedDist, outputDir); remove(unsortedDist.c_str()); //delete unsorted file distFile = sortedDistFile; //sort overlap file - string sortedOverlapFile = sortFile(unsortedOverlap, outputDir); + string sortedOverlapFile = m->sortFile(unsortedOverlap, outputDir); remove(unsortedOverlap.c_str()); //delete unsorted file overlapFile = sortedOverlapFile; } diff --git a/mothur.cpp b/mothur.cpp index eb5e8f9..18d8d43 100644 --- a/mothur.cpp +++ b/mothur.cpp @@ -82,7 +82,7 @@ int main(int argc, char *argv[]){ if (lastChar != "\\") { temp += "\\"; } #endif - temp = getFullPathName(temp); + temp = m->getFullPathName(temp); m->setDefaultPath(temp); m->mothurOutJustToLog("Using default file location " + temp); @@ -192,11 +192,11 @@ int main(int argc, char *argv[]){ }else { ofstream outNewLog; - openOutputFileAppend(newlogFileName, outNewLog); + m->openOutputFileAppend(newlogFileName, outNewLog); outNewLog << endl << endl << "*********************************************************************************" << endl << endl; outNewLog.close(); - appendFiles(logFileName, newlogFileName); + m->appendFiles(logFileName, newlogFileName); remove(logFileName.c_str()); } }else{ diff --git a/mothur.h b/mothur.h index d5086b3..bfe0692 100644 --- a/mothur.h +++ b/mothur.h @@ -132,1119 +132,81 @@ public: }; //********************************************************************************************************************** - template -inline void convert(const string& s, T& x, bool failIfLeftoverChars = true){ - istringstream i(s); - char c; - if (!(i >> x) || (failIfLeftoverChars && i.get(c))) - throw BadConversion(s); +void convert(const string& s, T& x, bool failIfLeftoverChars = true){ + + istringstream i(s); + char c; + if (!(i >> x) || (failIfLeftoverChars && i.get(c))) + throw BadConversion(s); + } //********************************************************************************************************************** template -inline bool convertTestFloat(const string& s, T& x, bool failIfLeftoverChars = true){ - istringstream i(s); - char c; - if (!(i >> x) || (failIfLeftoverChars && i.get(c))) - { - return false; - } - return true; +bool convertTestFloat(const string& s, T& x, bool failIfLeftoverChars = true){ + + istringstream i(s); + char c; + if (!(i >> x) || (failIfLeftoverChars && i.get(c))) + { + return false; + } + return true; + } //********************************************************************************************************************** template -inline bool convertTest(const string& s, T& x, bool failIfLeftoverChars = true){ - istringstream i(s); - char c; - if (!(i >> x) || (failIfLeftoverChars && i.get(c))) - { - cout << "unable to be converted into an integer.\n" << endl; - return false; - } - return true; +bool convertTest(const string& s, T& x, bool failIfLeftoverChars = true){ + + istringstream i(s); + char c; + if (!(i >> x) || (failIfLeftoverChars && i.get(c))) + { + return false; + } + return true; + } - //********************************************************************************************************************** - template string toString(const T&x){ - stringstream output; - output << x; - return output.str(); + + stringstream output; + output << x; + return output.str(); + } //********************************************************************************************************************** template string toHex(const T&x){ - stringstream output; - output << hex << x; + stringstream output; + + output << hex << x; - return output.str(); + return output.str(); + } //********************************************************************************************************************** template string toString(const T&x, int i){ - stringstream output; - - output.precision(i); - output << fixed << x; - - return output.str(); -} -/***********************************************************************/ -inline int openOutputFileAppend(string fileName, ofstream& fileHandle){ - - fileHandle.open(fileName.c_str(), ios::app); - if(!fileHandle) { - cout << "Error: Could not open " << fileName << endl; - return 1; - } - else { - return 0; - } - -} -/***********************************************************************/ - -inline void gobble(istream& f){ - - char d; - while(isspace(d=f.get())) {;} - f.putback(d); - -} -/***********************************************************************/ - -inline void gobble(istringstream& f){ - - char d; - while(isspace(d=f.get())) {;} - f.putback(d); - -} - -/***********************************************************************/ - -inline string getline(istringstream& fileHandle) { - try { - - string line = ""; - - while (!fileHandle.eof()) { - //get next character - char c = fileHandle.get(); - - //are you at the end of the line - if ((c == '\n') || (c == '\r') || (c == '\f')){ break; } - else { line += c; } - } - - return line; - - } - catch(exception& e) { - cout << "Error in mothur function getline" << endl; - exit(1); - } -} -/***********************************************************************/ - -inline string getline(ifstream& fileHandle) { - try { - string line = ""; + stringstream output; - while (!fileHandle.eof()) { - //get next character - char c = fileHandle.get(); - - //are you at the end of the line - if ((c == '\n') || (c == '\r') || (c == '\f')){ break; } - else { line += c; } - } + output.precision(i); + output << fixed << x; - return line; - - } - catch(exception& e) { - cout << "Error in mothur function getline" << endl; - exit(1); - } -} -/***********************************************************************/ - -inline bool isTrue(string f){ - - if ((f == "TRUE") || (f == "T") || (f == "true") || (f == "t")) { return true; } - else { return false; } -} - -/***********************************************************************/ - -inline float roundDist(float dist, int precision){ - - return int(dist * precision + 0.5)/float(precision); - -} -/***********************************************************************/ - -inline float ceilDist(float dist, int precision){ - - return int(ceil(dist * precision))/float(precision); - -} - -/***********************************************************************/ - -inline int getNumNames(string names){ - - int count = 0; - - if(names != ""){ - count = 1; - for(int i=0;i > binomial(int maxOrder){ - - vector > binomial(maxOrder+1); - - for(int i=0;i<=maxOrder;i++){ - binomial[i].resize(maxOrder+1); - binomial[i][0]=1; - binomial[0][i]=0; - } - binomial[0][0]=1; - - binomial[1][0]=1; - binomial[1][1]=1; - - for(int i=2;i<=maxOrder;i++){ - binomial[1][i]=0; - } - - for(int i=2;i<=maxOrder;i++){ - for(int j=1;j<=maxOrder;j++){ - if(i==j){ binomial[i][j]=1; } - if(j>i) { binomial[i][j]=0; } - else { binomial[i][j]=binomial[i-1][j-1]+binomial[i-1][j]; } - } - } - - return binomial; -} - -/***********************************************************************/ - -inline string getRootName(string longName){ - - string rootName = longName; - - if(longName.find_last_of(".") != longName.npos){ - int pos = longName.find_last_of('.')+1; - rootName = longName.substr(0, pos); - } - - return rootName; -} -/***********************************************************************/ - -inline string getSimpleName(string longName){ - - string simpleName = longName; - - size_t found; - found=longName.find_last_of("/\\"); - - if(found != longName.npos){ - simpleName = longName.substr(found+1); - } - - //if(longName.find_last_of("/") != longName.npos){ - // int pos = longName.find_last_of('/')+1; - // simpleName = longName.substr(pos, longName.length()); - //} - - return simpleName; -} - -/***********************************************************************/ - -inline int factorial(int num){ - int total = 1; - - for (int i = 1; i <= num; i++) { - total *= i; - } - - return total; -} -/************************************************************************************************** - -double min(double x, double y) -{ - if(x 0) { simpleCWD = cwd.substr(1); } - - //break apart the current working directory - vector dirs; - while (simpleCWD.find_first_of('/') != -1) { - string dir = simpleCWD.substr(0,simpleCWD.find_first_of('/')); - simpleCWD = simpleCWD.substr(simpleCWD.find_first_of('/')+1, simpleCWD.length()); - dirs.push_back(dir); - } - //get last one // ex. ../../../filename = /user/work/desktop/filename - dirs.push_back(simpleCWD); //ex. dirs[0] = user, dirs[1] = work, dirs[2] = desktop - - - int index = dirs.size()-1; - - while((pos = path.rfind("./")) != -1) { //while you don't have a complete path - if (pos == 0) { break; //you are at the end - }else if (path[(pos-1)] == '.') { //you want your parent directory ../ - path = path.substr(0, pos-1); - index--; - if (index == 0) { break; } - }else if (path[(pos-1)] == '/') { //you want the current working dir ./ - path = path.substr(0, pos); - }else if (pos == 1) { break; //you are at the end - }else { cout << "cannot resolve path for " << fileName << endl; return fileName; } - } - - for (int i = index; i >= 0; i--) { - newFileName = dirs[i] + "/" + newFileName; - } - - newFileName = "/" + newFileName; - return newFileName; - } - #else - if (path.find("~") != -1) { //go to home directory - string homeDir = getenv ("HOMEPATH"); - newFileName = homeDir + fileName.substr(fileName.find("~")+1); - return newFileName; - }else { //find path - if (path.rfind(".\\") == -1) { return fileName; } //already complete name - else { newFileName = fileName.substr(fileName.rfind(".\\")+2); } //save the complete part of the name - - char *cwdpath = NULL; - cwdpath = getcwd(NULL, 0); // or _getcwd - if ( cwdpath != NULL) { cwd = cwdpath; } - else { cwd = ""; } - - //break apart the current working directory - vector dirs; - while (cwd.find_first_of('\\') != -1) { - string dir = cwd.substr(0,cwd.find_first_of('\\')); - cwd = cwd.substr(cwd.find_first_of('\\')+1, cwd.length()); - dirs.push_back(dir); - - } - //get last one - dirs.push_back(cwd); //ex. dirs[0] = user, dirs[1] = work, dirs[2] = desktop - - int index = dirs.size()-1; - - while((pos = path.rfind(".\\")) != -1) { //while you don't have a complete path - if (pos == 0) { break; //you are at the end - }else if (path[(pos-1)] == '.') { //you want your parent directory ../ - path = path.substr(0, pos-1); - index--; - if (index == 0) { break; } - }else if (path[(pos-1)] == '\\') { //you want the current working dir ./ - path = path.substr(0, pos); - }else if (pos == 1) { break; //you are at the end - }else { cout << "cannot resolve path for " << fileName << endl; return fileName; } - } - - for (int i = index; i >= 0; i--) { - newFileName = dirs[i] + "\\" + newFileName; - } - - return newFileName; - } - - #endif - } - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function getFullPathName. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; - exit(1); - } } -/***********************************************************************/ - -inline int openInputFile(string fileName, ifstream& fileHandle, string m){ - - //get full path name - string completeFileName = getFullPathName(fileName); - - fileHandle.open(completeFileName.c_str()); - if(!fileHandle) { - return 1; - }else { - //check for blank file - gobble(fileHandle); - return 0; - } -} -/***********************************************************************/ - -inline int openInputFile(string fileName, ifstream& fileHandle){ - - //get full path name - string completeFileName = getFullPathName(fileName); - - fileHandle.open(completeFileName.c_str()); - if(!fileHandle) { - cout << "Error: Could not open " << completeFileName << endl; - return 1; - } - else { - //check for blank file - gobble(fileHandle); - if (fileHandle.eof()) { cout << completeFileName << " is blank. Please correct." << endl; } - - return 0; - } - -} -/***********************************************************************/ - -inline int renameFile(string oldName, string newName){ - - ifstream inTest; - int exist = openInputFile(newName, inTest, ""); - -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) - if (exist == 0) { //you could open it so you want to delete it - inTest.close(); - string command = "rm " + newName; - system(command.c_str()); - } - - string command = "mv " + oldName + " " + newName; - system(command.c_str()); -#else - remove(newName.c_str()); - int renameOk = rename(oldName.c_str(), newName.c_str()); -#endif - return 0; -} - -/***********************************************************************/ - -inline int openOutputFile(string fileName, ofstream& fileHandle){ - - string completeFileName = getFullPathName(fileName); - - fileHandle.open(completeFileName.c_str(), ios::trunc); - if(!fileHandle) { - cout << "Error: Could not open " << completeFileName << endl; - return 1; - } - else { - return 0; - } - -} - -/***********************************************************************/ - -inline int getNumSeqs(ifstream& file){ - - int numSeqs = count(istreambuf_iterator(file),istreambuf_iterator(), '>'); - file.seekg(0); - return numSeqs; - -} -/***********************************************************************/ -inline void getNumSeqs(ifstream& file, int& numSeqs){ - - string input; - numSeqs = 0; - while(!file.eof()){ - input = getline(file); - if (input.length() != 0) { - if(input[0] == '>'){ numSeqs++; } - } - } -} - -/***********************************************************************/ - -inline bool inVector(string member, vector group){ - - for (int i = 0; i < group.size(); i++) { - if (group[i] == member) { return true; } - } - - return false; -} -/***********************************************************************/ - -//This function parses the estimator options and puts them in a vector -inline void splitAtChar(string& estim, vector& container, char symbol) { - try { - string individual; - - while (estim.find_first_of(symbol) != -1) { - individual = estim.substr(0,estim.find_first_of(symbol)); - if ((estim.find_first_of(symbol)+1) <= estim.length()) { //checks to make sure you don't have dash at end of string - estim = estim.substr(estim.find_first_of(symbol)+1, estim.length()); - container.push_back(individual); - } - } - //get last one - container.push_back(estim); - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function splitAtDash. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; - exit(1); - } -} - -/***********************************************************************/ - -//This function parses the estimator options and puts them in a vector -inline void splitAtDash(string& estim, vector& container) { - try { - 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) { - cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function splitAtDash. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; - exit(1); - } -} - -/***********************************************************************/ -//This function parses the label options and puts them in a set -inline void splitAtDash(string& estim, set& container) { - try { - 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) { - cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function splitAtDash. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; - exit(1); - } -} -/***********************************************************************/ -//This function parses the line options and puts them in a set -inline void splitAtDash(string& estim, set& container) { - try { - 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); - } - } - //get last one - convert(estim, lineNum); //convert the string to int - container.insert(lineNum); - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function splitAtDash. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; - exit(1); - } -} -/***********************************************************************/ -//This function parses the a string and puts peices in a vector -inline void splitAtComma(string& estim, vector& container) { - try { - 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 comma 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) { - cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function splitAtComma. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; - exit(1); - } -} -/***********************************************************************/ - -//This function splits up the various option parameters -inline void splitAtComma(string& prefix, string& suffix){ - try { - prefix = suffix.substr(0,suffix.find_first_of(',')); - if ((suffix.find_first_of(',')+2) <= suffix.length()) { //checks to make sure you don't have comma at end of string - suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length()); - string space = " "; - while(suffix.at(0) == ' ') - suffix = suffix.substr(1, suffix.length()); - } - - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function splitAtComma. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; - exit(1); - } -} -/***********************************************************************/ - -//This function separates the key value from the option value i.e. dist=96_... -inline void splitAtEquals(string& key, string& value){ - try { - if(value.find_first_of('=') != -1){ - key = value.substr(0,value.find_first_of('=')); - if ((value.find_first_of('=')+1) <= value.length()) { - value = value.substr(value.find_first_of('=')+1, value.length()); - } - }else{ - key = value; - value = 1; - } - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function splitAtEquals. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; - exit(1); - } -} - -/**************************************************************************************************/ - -inline bool inUsersGroups(string groupname, vector Groups) { - try { - for (int i = 0; i < Groups.size(); i++) { - if (groupname == Groups[i]) { return true; } - } - return false; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function inUsersGroups. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; - exit(1); - } -} -/**************************************************************************************************/ -//returns true if any of the strings in first vector are in second vector -inline bool inUsersGroups(vector groupnames, vector Groups) { - try { - - for (int i = 0; i < groupnames.size(); i++) { - if (inUsersGroups(groupnames[i], Groups)) { return true; } - } - return false; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function inUsersGroups. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; - exit(1); - } -} -/***********************************************************************/ -//this function determines if the user has given us labels that are smaller than the given label. -//if so then it returns true so that the calling function can run the previous valid distance. -//it's a "smart" distance function. It also checks for invalid labels. -inline bool anyLabelsToProcess(string label, set& userLabels, string errorOff) { - try { - - set::iterator it; - vector orderFloat; - map userMap; //the conversion process removes trailing 0's which we need to put back - map::iterator it2; - float labelFloat; - bool smaller = false; - - //unique is the smallest line - if (label == "unique") { return false; } - else { - if (convertTestFloat(label, labelFloat)) { - convert(label, labelFloat); - }else { //cant convert - return false; - } - } - - //go through users set and make them floats - for(it = userLabels.begin(); it != userLabels.end(); ++it) { - - float temp; - if ((*it != "unique") && (convertTestFloat(*it, temp) == true)){ - convert(*it, temp); - orderFloat.push_back(temp); - userMap[*it] = temp; - }else if (*it == "unique") { - orderFloat.push_back(-1.0); - userMap["unique"] = -1.0; - }else { - if (errorOff == "") { cout << *it << " is not a valid label." << endl; } - userLabels.erase(*it); - it--; - } - } - - //sort order - sort(orderFloat.begin(), orderFloat.end()); - - /*************************************************/ - //is this label bigger than any of the users labels - /*************************************************/ - - //loop through order until you find a label greater than label - for (int i = 0; i < orderFloat.size(); i++) { - if (orderFloat[i] < labelFloat) { - smaller = true; - if (orderFloat[i] == -1) { - if (errorOff == "") { cout << "Your file does not include the label unique." << endl; } - userLabels.erase("unique"); - } - else { - if (errorOff == "") { cout << "Your file does not include the label " << endl; } - string s = ""; - for (it2 = userMap.begin(); it2!= userMap.end(); it2++) { - if (it2->second == orderFloat[i]) { - s = it2->first; - //remove small labels - userLabels.erase(s); - break; - } - } - if (errorOff == "") {cout << s << ". I will use the next smallest distance. " << endl; } - } - //since they are sorted once you find a bigger one stop looking - }else { break; } - } - - return smaller; - - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function anyLabelsToProcess. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; - exit(1); - } -} - -/**************************************************************************************************/ -inline void appendFiles(string temp, string filename) { - try{ - ofstream output; - ifstream input; - - //open output file in append mode - openOutputFileAppend(filename, output); - int ableToOpen = openInputFile(temp, input, "no error"); - - if (ableToOpen == 0) { //you opened it - while(char c = input.get()){ - if(input.eof()) { break; } - else { output << c; } - } - input.close(); - } - - output.close(); - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function appendFiles. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; - exit(1); - } -} - -/**************************************************************************************************/ -inline string sortFile(string distFile, string outputDir){ - try { - - //if (outputDir == "") { outputDir += hasPath(distFile); } - string outfile = getRootName(distFile) + "sorted.dist"; - - - //if you can, use the unix sort since its been optimized for years - #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) - string command = "sort -n -k +3 " + distFile + " -o " + outfile; - system(command.c_str()); - #else //you are stuck with my best attempt... - //windows sort does not have a way to specify a column, only a character in the line - //since we cannot assume that the distance will always be at the the same character location on each line - //due to variable sequence name lengths, I chose to force the distance into first position, then sort and then put it back. - - //read in file line by file and put distance first - string tempDistFile = distFile + ".temp"; - ifstream input; - ofstream output; - openInputFile(distFile, input); - openOutputFile(tempDistFile, output); - - string firstName, secondName; - float dist; - while (input) { - input >> firstName >> secondName >> dist; - output << dist << '\t' << firstName << '\t' << secondName << endl; - gobble(input); - } - input.close(); - output.close(); - - - //sort using windows sort - string tempOutfile = outfile + ".temp"; - string command = "sort " + tempDistFile + " /O " + tempOutfile; - system(command.c_str()); - - //read in sorted file and put distance at end again - ifstream input2; - openInputFile(tempOutfile, input2); - openOutputFile(outfile, output); - - while (input2) { - input2 >> dist >> firstName >> secondName; - output << firstName << '\t' << secondName << '\t' << dist << endl; - gobble(input2); - } - input2.close(); - output.close(); - - //remove temp files - remove(tempDistFile.c_str()); - remove(tempOutfile.c_str()); - #endif - - return outfile; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function sortfile. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; - exit(1); - } -} -/**************************************************************************************************/ -inline vector setFilePosFasta(string filename, int& num) { - - vector positions; - ifstream inFASTA; - openInputFile(filename, inFASTA); - - string input; - while(!inFASTA.eof()){ - input = getline(inFASTA); - if (input.length() != 0) { - if(input[0] == '>'){ unsigned long int pos = inFASTA.tellg(); positions.push_back(pos - input.length() - 1); } - } - gobble(inFASTA); //has to be here since windows line endings are 2 characters and mess up the positions - } - inFASTA.close(); - - num = positions.size(); - - /*FILE * pFile; - long size; - - //get num bytes in file - pFile = fopen (filename.c_str(),"rb"); - if (pFile==NULL) perror ("Error opening file"); - else{ - fseek (pFile, 0, SEEK_END); - size=ftell (pFile); - fclose (pFile); - }*/ - - unsigned long int size = positions[(positions.size()-1)]; - ifstream in; - openInputFile(filename, in); - - in.seekg(size); - - while(char c = in.get()){ - if(in.eof()) { break; } - else { size++; } - } - in.close(); - - positions.push_back(size); - - return positions; -} -/**************************************************************************************************/ -inline vector setFilePosEachLine(string filename, int& num) { - - vector positions; - ifstream in; - openInputFile(filename, in); - - string input; - while(!in.eof()){ - unsigned long int lastpos = in.tellg(); - input = getline(in); - if (input.length() != 0) { - unsigned long int 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 - } - in.close(); - - num = positions.size(); - - FILE * pFile; - unsigned long int size; - - //get num bytes in file - pFile = fopen (filename.c_str(),"rb"); - if (pFile==NULL) perror ("Error opening file"); - else{ - fseek (pFile, 0, SEEK_END); - size=ftell (pFile); - fclose (pFile); - } - - positions.push_back(size); - - return positions; -} -/**************************************************************************************************/ - -inline vector divideFile(string filename, int& proc) { - try{ - - vector filePos; - filePos.push_back(0); - - FILE * pFile; - unsigned long int size; - - //get num bytes in file - pFile = fopen (filename.c_str(),"rb"); - if (pFile==NULL) perror ("Error opening file"); - else{ - fseek (pFile, 0, SEEK_END); - size=ftell (pFile); - fclose (pFile); - } - - //estimate file breaks - unsigned long int chunkSize = 0; - chunkSize = size / proc; - - //file to small to divide by processors - if (chunkSize == 0) { proc = 1; filePos.push_back(size); return filePos; } - - //for each process seekg to closest file break and search for next '>' char. make that the filebreak - for (int i = 0; i < proc; i++) { - unsigned long int spot = (i+1) * chunkSize; - - ifstream in; - openInputFile(filename, in); - in.seekg(spot); - - //look for next '>' - unsigned long int newSpot = spot; - while (!in.eof()) { - char c = in.get(); - if (c == '>') { in.putback(c); newSpot = in.tellg(); break; } - } - - //there was not another sequence before the end of the file - unsigned long int sanityPos = in.tellg(); - if (sanityPos == -1) { break; } - else { filePos.push_back(newSpot); } - - in.close(); - } - - //save end pos - filePos.push_back(size); - - //sanity check filePos - for (int i = 0; i < (filePos.size()-1); i++) { - if (filePos[(i+1)] <= filePos[i]) { filePos.erase(filePos.begin()+(i+1)); i--; } - } - - proc = (filePos.size() - 1); - - return filePos; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function divideFile. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; - exit(1); - } -} -/**************************************************************************************************/ -inline bool checkReleaseVersion(ifstream& file, string version) { - try { - - bool good = true; - - string line = getline(file); +//********************************************************************************************************************** - //before we added this check - if (line[0] != '#') { good = false; } - else { - //rip off # - line = line.substr(1); - - vector versionVector; - splitAtChar(version, versionVector, '.'); - - //check file version - vector linesVector; - splitAtChar(line, linesVector, '.'); - - if (versionVector.size() != linesVector.size()) { good = false; } - else { - for (int j = 0; j < versionVector.size(); j++) { - int num1, num2; - convert(versionVector[j], num1); - convert(linesVector[j], num2); - - //if mothurs version is newer than this files version, then we want to remake it - if (num1 > num2) { good = false; break; } - } - } - - } - - if (!good) { file.close(); } - else { file.seekg(0); } - - return good; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function checkReleaseVersion. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; - exit(1); - } -} -/**************************************************************************************************/ #endif diff --git a/mothurout.cpp b/mothurout.cpp index d3f8e7a..5c5fd37 100644 --- a/mothurout.cpp +++ b/mothurout.cpp @@ -1,261 +1,1401 @@ -/* - * m->mothurOut.cpp - * Mothur - * - * Created by westcott on 2/25/10. - * Copyright 2010 Schloss Lab. All rights reserved. - * - */ - -#include "mothurout.h" - -/******************************************************/ -MothurOut* MothurOut::getInstance() { - if( _uniqueInstance == 0) { - _uniqueInstance = new MothurOut(); - } - return _uniqueInstance; -} -/*********************************************************************************************/ -void MothurOut::setFileName(string filename) { - try { - logFileName = filename; - - #ifdef USE_MPI - int pid; - MPI_Comm_rank(MPI_COMM_WORLD, &pid); - - if (pid == 0) { //only one process should output to screen - #endif - - openOutputFile(filename, out); - - #ifdef USE_MPI - } - #endif - } - catch(exception& e) { - errorOut(e, "MothurOut", "setFileName"); - exit(1); - } -} -/*********************************************************************************************/ -void MothurOut::setDefaultPath(string pathname) { - try { - - //add / to name if needed - string lastChar = pathname.substr(pathname.length()-1); - #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) - if (lastChar != "/") { pathname += "/"; } - #else - if (lastChar != "\\") { pathname += "\\"; } - #endif - - defaultPath = pathname; - - } - catch(exception& e) { - errorOut(e, "MothurOut", "setDefaultPath"); - exit(1); - } -} -/*********************************************************************************************/ -void MothurOut::closeLog() { - try { - - #ifdef USE_MPI - int pid; - MPI_Comm_rank(MPI_COMM_WORLD, &pid); - - if (pid == 0) { //only one process should output to screen - #endif - - out.close(); - - #ifdef USE_MPI - } - #endif - } - catch(exception& e) { - errorOut(e, "MothurOut", "closeLog"); - exit(1); - } -} - -/*********************************************************************************************/ -MothurOut::~MothurOut() { - try { - _uniqueInstance = 0; - - } - catch(exception& e) { - errorOut(e, "MothurOut", "MothurOut"); - exit(1); - } -} -/*********************************************************************************************/ -void MothurOut::mothurOut(string output) { - try { - - #ifdef USE_MPI - int pid; - MPI_Comm_rank(MPI_COMM_WORLD, &pid); - - if (pid == 0) { //only one process should output to screen - #endif - - cout << output; - out << output; - - #ifdef USE_MPI - } - #endif - } - catch(exception& e) { - errorOut(e, "MothurOut", "MothurOut"); - exit(1); - } -} -/*********************************************************************************************/ -void MothurOut::mothurOutEndLine() { - try { - #ifdef USE_MPI - int pid; - MPI_Comm_rank(MPI_COMM_WORLD, &pid); - - if (pid == 0) { //only one process should output to screen - #endif - - cout << endl; - out << endl; - - #ifdef USE_MPI - } - #endif - } - catch(exception& e) { - errorOut(e, "MothurOut", "MothurOutEndLine"); - exit(1); - } -} -/*********************************************************************************************/ -void MothurOut::mothurOutJustToLog(string output) { - try { - #ifdef USE_MPI - int pid; - MPI_Comm_rank(MPI_COMM_WORLD, &pid); - - if (pid == 0) { //only one process should output to screen - #endif - - out << output; - - #ifdef USE_MPI - } - #endif - } - catch(exception& e) { - errorOut(e, "MothurOut", "MothurOutJustToLog"); - exit(1); - } -} -/*********************************************************************************************/ -void MothurOut::errorOut(exception& e, string object, string function) { - double vm, rss; - //mem_usage(vm, rss); - - mothurOut("Error: "); - mothurOut(toString(e.what())); - mothurOut(" has occurred in the " + object + " class function " + function + ". Please contact Pat Schloss at mothur.bugs@gmail.com, and be sure to include the mothur.logFile with your inquiry."); - mothurOutEndLine(); -} -/*********************************************************************************************/ -//The following was originally from http://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-run-time-in-c -// process_mem_usage(double &, double &) - takes two doubles by reference, -// attempts to read the system-dependent data for a process' virtual memory -// size and resident set size, and return the results in KB. -// -// On failure, returns 0.0, 0.0 -int MothurOut::mem_usage(double& vm_usage, double& resident_set) { - #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) - - vm_usage = 0.0; - resident_set = 0.0; - - // 'file' stat seems to give the most reliable results - // - ifstream stat_stream("/proc/self/stat",ios_base::in); - - // dummy vars for leading entries in stat that we don't care about - // - string pid, comm, state, ppid, pgrp, session, tty_nr; - string tpgid, flags, minflt, cminflt, majflt, cmajflt; - string utime, stime, cutime, cstime, priority, nice; - string O, itrealvalue, starttime; - - // the two fields we want - // - unsigned long vsize; - long rss; - - stat_stream >> pid >> comm >> state >> ppid >> pgrp >> session >> tty_nr - >> tpgid >> flags >> minflt >> cminflt >> majflt >> cmajflt - >> utime >> stime >> cutime >> cstime >> priority >> nice - >> O >> itrealvalue >> starttime >> vsize >> rss; // don't care about the rest - - long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // in case x86-64 is configured to use 2MB pages - vm_usage = vsize / 1024.0; - resident_set = rss * page_size_kb; - - mothurOut("Memory Usage: vm = " + toString(vm_usage) + " rss = " + toString(resident_set) + "\n"); - return 0; - - #else -/* //windows memory usage - // Get the list of process identifiers. - DWORD aProcesses[1024], cbNeeded, cProcesses; - - if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ){ return 1; } - - // Calculate how many process identifiers were returned. - cProcesses = cbNeeded / sizeof(DWORD); - - // Print the memory usage for each process - for (int i = 0; i < cProcesses; i++ ) { - DWORD processID = aProcesses[i]; - - PROCESS_MEMORY_COUNTERS pmc; - - HANDLE hProcess = OpenProcess((PROCESS_QUERY_INFORMATION | PROCESS_VM_READ), FALSE, processID); - - // Print the process identifier. - printf( "\nProcess ID: %u\n", processID); - - if (NULL != hProcess) { - - if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) ) { - printf( "\tPageFaultCount: 0x%08X\n", pmc.PageFaultCount ); - printf( "\tPeakWorkingSetSize: 0x%08X\n", pmc.PeakWorkingSetSize ); - printf( "\tWorkingSetSize: 0x%08X\n", pmc.WorkingSetSize ); - printf( "\tQuotaPeakPagedPoolUsage: 0x%08X\n", pmc.QuotaPeakPagedPoolUsage ); - printf( "\tQuotaPagedPoolUsage: 0x%08X\n", pmc.QuotaPagedPoolUsage ); - printf( "\tQuotaPeakNonPagedPoolUsage: 0x%08X\n", pmc.QuotaPeakNonPagedPoolUsage ); - printf( "\tQuotaNonPagedPoolUsage: 0x%08X\n", pmc.QuotaNonPagedPoolUsage ); - printf( "\tPagefileUsage: 0x%08X\n", pmc.PagefileUsage ); - printf( "\tPeakPagefileUsage: 0x%08X\n", pmc.PeakPagefileUsage ); - } - CloseHandle(hProcess); - } - } -*/ - return 0; - - #endif -} -/*********************************************************************************************/ - - - - - - +/* + * mothurOut.cpp + * Mothur + * + * Created by westcott on 2/25/10. + * Copyright 2010 Schloss Lab. All rights reserved. + * + */ + +#include "mothurout.h" + +/******************************************************/ +MothurOut* MothurOut::getInstance() { + if( _uniqueInstance == 0) { + _uniqueInstance = new MothurOut(); + } + return _uniqueInstance; +} +/*********************************************************************************************/ +void MothurOut::setFileName(string filename) { + try { + logFileName = filename; + + #ifdef USE_MPI + int pid; + MPI_Comm_rank(MPI_COMM_WORLD, &pid); + + if (pid == 0) { //only one process should output to screen + #endif + + openOutputFile(filename, out); + + #ifdef USE_MPI + } + #endif + } + catch(exception& e) { + errorOut(e, "MothurOut", "setFileName"); + exit(1); + } +} +/*********************************************************************************************/ +void MothurOut::setDefaultPath(string pathname) { + try { + + //add / to name if needed + string lastChar = pathname.substr(pathname.length()-1); + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) + if (lastChar != "/") { pathname += "/"; } + #else + if (lastChar != "\\") { pathname += "\\"; } + #endif + + defaultPath = pathname; + + } + catch(exception& e) { + errorOut(e, "MothurOut", "setDefaultPath"); + exit(1); + } +} +/*********************************************************************************************/ +void MothurOut::closeLog() { + try { + + #ifdef USE_MPI + int pid; + MPI_Comm_rank(MPI_COMM_WORLD, &pid); + + if (pid == 0) { //only one process should output to screen + #endif + + out.close(); + + #ifdef USE_MPI + } + #endif + } + catch(exception& e) { + errorOut(e, "MothurOut", "closeLog"); + exit(1); + } +} + +/*********************************************************************************************/ +MothurOut::~MothurOut() { + try { + _uniqueInstance = 0; + + } + catch(exception& e) { + errorOut(e, "MothurOut", "MothurOut"); + exit(1); + } +} +/*********************************************************************************************/ +void MothurOut::mothurOut(string output) { + try { + + #ifdef USE_MPI + int pid; + MPI_Comm_rank(MPI_COMM_WORLD, &pid); + + if (pid == 0) { //only one process should output to screen + #endif + + cout << output; + out << output; + + #ifdef USE_MPI + } + #endif + } + catch(exception& e) { + errorOut(e, "MothurOut", "MothurOut"); + exit(1); + } +} +/*********************************************************************************************/ +void MothurOut::mothurOutEndLine() { + try { + #ifdef USE_MPI + int pid; + MPI_Comm_rank(MPI_COMM_WORLD, &pid); + + if (pid == 0) { //only one process should output to screen + #endif + + cout << endl; + out << endl; + + #ifdef USE_MPI + } + #endif + } + catch(exception& e) { + errorOut(e, "MothurOut", "MothurOutEndLine"); + exit(1); + } +} +/*********************************************************************************************/ +void MothurOut::mothurOutJustToLog(string output) { + try { + #ifdef USE_MPI + int pid; + MPI_Comm_rank(MPI_COMM_WORLD, &pid); + + if (pid == 0) { //only one process should output to screen + #endif + + out << output; + + #ifdef USE_MPI + } + #endif + } + catch(exception& e) { + errorOut(e, "MothurOut", "MothurOutJustToLog"); + exit(1); + } +} +/*********************************************************************************************/ +void MothurOut::errorOut(exception& e, string object, string function) { + //double vm, rss; + //mem_usage(vm, rss); + + mothurOut("[ERROR]: "); + mothurOut(toString(e.what())); + mothurOut(" has occurred in the " + object + " class function " + function + ". Please contact Pat Schloss at mothur.bugs@gmail.com, and be sure to include the mothur.logFile with your inquiry."); + mothurOutEndLine(); +} +/*********************************************************************************************/ +//The following was originally from http://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-run-time-in-c +// process_mem_usage(double &, double &) - takes two doubles by reference, +// attempts to read the system-dependent data for a process' virtual memory +// size and resident set size, and return the results in KB. +// +// On failure, returns 0.0, 0.0 +int MothurOut::mem_usage(double& vm_usage, double& resident_set) { + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) + + vm_usage = 0.0; + resident_set = 0.0; + + // 'file' stat seems to give the most reliable results + // + ifstream stat_stream("/proc/self/stat",ios_base::in); + + // dummy vars for leading entries in stat that we don't care about + // + string pid, comm, state, ppid, pgrp, session, tty_nr; + string tpgid, flags, minflt, cminflt, majflt, cmajflt; + string utime, stime, cutime, cstime, priority, nice; + string O, itrealvalue, starttime; + + // the two fields we want + // + unsigned long vsize; + long rss; + + stat_stream >> pid >> comm >> state >> ppid >> pgrp >> session >> tty_nr + >> tpgid >> flags >> minflt >> cminflt >> majflt >> cmajflt + >> utime >> stime >> cutime >> cstime >> priority >> nice + >> O >> itrealvalue >> starttime >> vsize >> rss; // don't care about the rest + + long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // in case x86-64 is configured to use 2MB pages + vm_usage = vsize / 1024.0; + resident_set = rss * page_size_kb; + + mothurOut("Memory Usage: vm = " + toString(vm_usage) + " rss = " + toString(resident_set) + "\n"); + return 0; + + #else +/* //windows memory usage + // Get the list of process identifiers. + DWORD aProcesses[1024], cbNeeded, cProcesses; + + if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ){ return 1; } + + // Calculate how many process identifiers were returned. + cProcesses = cbNeeded / sizeof(DWORD); + + // Print the memory usage for each process + for (int i = 0; i < cProcesses; i++ ) { + DWORD processID = aProcesses[i]; + + PROCESS_MEMORY_COUNTERS pmc; + + HANDLE hProcess = OpenProcess((PROCESS_QUERY_INFORMATION | PROCESS_VM_READ), FALSE, processID); + + // Print the process identifier. + printf( "\nProcess ID: %u\n", processID); + + if (NULL != hProcess) { + + if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) ) { + printf( "\tPageFaultCount: 0x%08X\n", pmc.PageFaultCount ); + printf( "\tPeakWorkingSetSize: 0x%08X\n", pmc.PeakWorkingSetSize ); + printf( "\tWorkingSetSize: 0x%08X\n", pmc.WorkingSetSize ); + printf( "\tQuotaPeakPagedPoolUsage: 0x%08X\n", pmc.QuotaPeakPagedPoolUsage ); + printf( "\tQuotaPagedPoolUsage: 0x%08X\n", pmc.QuotaPagedPoolUsage ); + printf( "\tQuotaPeakNonPagedPoolUsage: 0x%08X\n", pmc.QuotaPeakNonPagedPoolUsage ); + printf( "\tQuotaNonPagedPoolUsage: 0x%08X\n", pmc.QuotaNonPagedPoolUsage ); + printf( "\tPagefileUsage: 0x%08X\n", pmc.PagefileUsage ); + printf( "\tPeakPagefileUsage: 0x%08X\n", pmc.PeakPagefileUsage ); + } + CloseHandle(hProcess); + } + } +*/ + return 0; + + #endif +} + + +/***********************************************************************/ +int MothurOut::openOutputFileAppend(string fileName, ofstream& fileHandle){ + try { + fileHandle.open(fileName.c_str(), ios::app); + 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 { + char d; + while(isspace(d=f.get())) {;} + f.putback(d); + } + catch(exception& e) { + errorOut(e, "MothurOut", "gobble"); + exit(1); + } +} +/***********************************************************************/ +void MothurOut::gobble(istringstream& f){ + try { + char d; + while(isspace(d=f.get())) {;} + f.putback(d); + } + catch(exception& e) { + errorOut(e, "MothurOut", "gobble"); + exit(1); + } +} + +/***********************************************************************/ + +string MothurOut::getline(istringstream& fileHandle) { + try { + + string line = ""; + + while (!fileHandle.eof()) { + //get next character + char c = fileHandle.get(); + + //are you at the end of the line + if ((c == '\n') || (c == '\r') || (c == '\f')){ break; } + else { line += c; } + } + + return line; + + } + catch(exception& e) { + errorOut(e, "MothurOut", "getline"); + exit(1); + } +} +/***********************************************************************/ + +string MothurOut::getline(ifstream& fileHandle) { + try { + + string line = ""; + + while (!fileHandle.eof()) { + //get next character + char c = fileHandle.get(); + + //are you at the end of the line + if ((c == '\n') || (c == '\r') || (c == '\f')){ break; } + else { line += c; } + } + + return line; + + } + catch(exception& e) { + errorOut(e, "MothurOut", "getline"); + exit(1); + } +} +/***********************************************************************/ + +string MothurOut::getRootName(string longName){ + try { + + string rootName = longName; + + if(longName.find_last_of(".") != longName.npos){ + int pos = longName.find_last_of('.')+1; + rootName = longName.substr(0, pos); + } + + return rootName; + } + catch(exception& e) { + errorOut(e, "MothurOut", "getRootName"); + exit(1); + } +} +/***********************************************************************/ + +string MothurOut::getSimpleName(string longName){ + try { + string simpleName = longName; + + size_t found; + found=longName.find_last_of("/\\"); + + if(found != longName.npos){ + simpleName = longName.substr(found+1); + } + + return simpleName; + } + catch(exception& e) { + errorOut(e, "MothurOut", "getSimpleName"); + exit(1); + } +} + +/***********************************************************************/ + +string MothurOut::getPathName(string longName){ + try { + string rootPathName = longName; + + if(longName.find_last_of("/\\") != longName.npos){ + int pos = longName.find_last_of("/\\")+1; + rootPathName = longName.substr(0, pos); + } + + return rootPathName; + } + catch(exception& e) { + errorOut(e, "MothurOut", "getPathName"); + exit(1); + } + +} +/***********************************************************************/ + +string MothurOut::hasPath(string longName){ + try { + string path = ""; + + size_t found; + found=longName.find_last_of("~/\\"); + + if(found != longName.npos){ + path = longName.substr(0, found+1); + } + + return path; + } + catch(exception& e) { + errorOut(e, "MothurOut", "hasPath"); + exit(1); + } +} + +/***********************************************************************/ + +string MothurOut::getExtension(string longName){ + try { + string extension = longName; + + if(longName.find_last_of('.') != longName.npos){ + int pos = longName.find_last_of('.'); + extension = longName.substr(pos, longName.length()); + } + + return extension; + } + catch(exception& e) { + errorOut(e, "MothurOut", "getExtension"); + exit(1); + } +} +/***********************************************************************/ +bool MothurOut::isBlank(string fileName){ + try { + ifstream fileHandle; + fileHandle.open(fileName.c_str()); + if(!fileHandle) { + mothurOut("[ERROR]: Could not open " + fileName); mothurOutEndLine(); + return false; + }else { + //check for blank file + gobble(fileHandle); + if (fileHandle.eof()) { fileHandle.close(); return true; } + } + return false; + } + catch(exception& e) { + errorOut(e, "MothurOut", "isBlank"); + exit(1); + } +} +/***********************************************************************/ + +string MothurOut::getFullPathName(string fileName){ + try{ + + string path = hasPath(fileName); + string newFileName; + int pos; + + if (path == "") { return fileName; } //its a simple name + else { //we need to complete the pathname + // ex. ../../../filename + // cwd = /user/work/desktop + + string cwd; + //get current working directory + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) + + if (path.find("~") != -1) { //go to home directory + string homeDir = getenv ("HOME"); + newFileName = homeDir + fileName.substr(fileName.find("~")+1); + return newFileName; + }else { //find path + if (path.rfind("./") == -1) { return fileName; } //already complete name + else { newFileName = fileName.substr(fileName.rfind("./")+2); } //save the complete part of the name + + char* cwdpath = new char[1024]; + + size_t size; + cwdpath=getcwd(cwdpath,size); + + cwd = cwdpath; + + //rip off first '/' + string simpleCWD; + if (cwd.length() > 0) { simpleCWD = cwd.substr(1); } + + //break apart the current working directory + vector dirs; + while (simpleCWD.find_first_of('/') != -1) { + string dir = simpleCWD.substr(0,simpleCWD.find_first_of('/')); + simpleCWD = simpleCWD.substr(simpleCWD.find_first_of('/')+1, simpleCWD.length()); + dirs.push_back(dir); + } + //get last one // ex. ../../../filename = /user/work/desktop/filename + dirs.push_back(simpleCWD); //ex. dirs[0] = user, dirs[1] = work, dirs[2] = desktop + + + int index = dirs.size()-1; + + while((pos = path.rfind("./")) != -1) { //while you don't have a complete path + if (pos == 0) { break; //you are at the end + }else if (path[(pos-1)] == '.') { //you want your parent directory ../ + path = path.substr(0, pos-1); + index--; + if (index == 0) { break; } + }else if (path[(pos-1)] == '/') { //you want the current working dir ./ + path = path.substr(0, pos); + }else if (pos == 1) { break; //you are at the end + }else { cout << "cannot resolve path for " << fileName << endl; return fileName; } + } + + for (int i = index; i >= 0; i--) { + newFileName = dirs[i] + "/" + newFileName; + } + + newFileName = "/" + newFileName; + return newFileName; + } + #else + if (path.find("~") != -1) { //go to home directory + string homeDir = getenv ("HOMEPATH"); + newFileName = homeDir + fileName.substr(fileName.find("~")+1); + return newFileName; + }else { //find path + if (path.rfind(".\\") == -1) { return fileName; } //already complete name + else { newFileName = fileName.substr(fileName.rfind(".\\")+2); } //save the complete part of the name + + char *cwdpath = NULL; + cwdpath = getcwd(NULL, 0); // or _getcwd + if ( cwdpath != NULL) { cwd = cwdpath; } + else { cwd = ""; } + + //break apart the current working directory + vector dirs; + while (cwd.find_first_of('\\') != -1) { + string dir = cwd.substr(0,cwd.find_first_of('\\')); + cwd = cwd.substr(cwd.find_first_of('\\')+1, cwd.length()); + dirs.push_back(dir); + + } + //get last one + dirs.push_back(cwd); //ex. dirs[0] = user, dirs[1] = work, dirs[2] = desktop + + int index = dirs.size()-1; + + while((pos = path.rfind(".\\")) != -1) { //while you don't have a complete path + if (pos == 0) { break; //you are at the end + }else if (path[(pos-1)] == '.') { //you want your parent directory ../ + path = path.substr(0, pos-1); + index--; + if (index == 0) { break; } + }else if (path[(pos-1)] == '\\') { //you want the current working dir ./ + path = path.substr(0, pos); + }else if (pos == 1) { break; //you are at the end + }else { cout << "cannot resolve path for " << fileName << endl; return fileName; } + } + + for (int i = index; i >= 0; i--) { + newFileName = dirs[i] + "\\" + newFileName; + } + + return newFileName; + } + + #endif + } + } + catch(exception& e) { + errorOut(e, "MothurOut", "getFullPathName"); + exit(1); + } +} +/***********************************************************************/ + +int MothurOut::openInputFile(string fileName, ifstream& fileHandle, string m){ + try { + //get full path name + string completeFileName = getFullPathName(fileName); + + fileHandle.open(completeFileName.c_str()); + if(!fileHandle) { + return 1; + }else { + //check for blank file + gobble(fileHandle); + return 0; + } + } + catch(exception& e) { + errorOut(e, "MothurOut", "openInputFile - no Error"); + exit(1); + } +} +/***********************************************************************/ + +int MothurOut::openInputFile(string fileName, ifstream& fileHandle){ + try { + //get full path name + string completeFileName = getFullPathName(fileName); + + fileHandle.open(completeFileName.c_str()); + if(!fileHandle) { + mothurOut("[ERROR]: Could not open " + completeFileName); mothurOutEndLine(); + return 1; + } + else { + //check for blank file + gobble(fileHandle); + if (fileHandle.eof()) { mothurOut("[ERROR]: " + completeFileName + " is blank. Please correct."); mothurOutEndLine(); } + + return 0; + } + } + catch(exception& e) { + errorOut(e, "MothurOut", "openInputFile"); + exit(1); + } +} +/***********************************************************************/ + +int MothurOut::renameFile(string oldName, string newName){ + try { + ifstream inTest; + int exist = openInputFile(newName, inTest, ""); + + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) + if (exist == 0) { //you could open it so you want to delete it + inTest.close(); + string command = "rm " + newName; + system(command.c_str()); + } + + string command = "mv " + oldName + " " + newName; + system(command.c_str()); + #else + remove(newName.c_str()); + int renameOk = rename(oldName.c_str(), newName.c_str()); + #endif + return 0; + + } + catch(exception& e) { + errorOut(e, "MothurOut", "renameFile"); + exit(1); + } +} + +/***********************************************************************/ + +int MothurOut::openOutputFile(string fileName, ofstream& fileHandle){ + try { + + string completeFileName = getFullPathName(fileName); + + fileHandle.open(completeFileName.c_str(), ios::trunc); + if(!fileHandle) { + mothurOut("[ERROR]: Could not open " + completeFileName); mothurOutEndLine(); + return 1; + } + else { + return 0; + } + } + catch(exception& e) { + errorOut(e, "MothurOut", "openOutputFile"); + exit(1); + } + +} + +/**************************************************************************************************/ +void MothurOut::appendFiles(string temp, string filename) { + try{ + ofstream output; + ifstream input; + + //open output file in append mode + openOutputFileAppend(filename, output); + int ableToOpen = openInputFile(temp, input, "no error"); + + if (ableToOpen == 0) { //you opened it + while(char c = input.get()){ + if(input.eof()) { break; } + else { output << c; } + } + input.close(); + } + + output.close(); + } + catch(exception& e) { + errorOut(e, "MothurOut", "appendFiles"); + exit(1); + } +} + +/**************************************************************************************************/ +string MothurOut::sortFile(string distFile, string outputDir){ + try { + + //if (outputDir == "") { outputDir += hasPath(distFile); } + string outfile = getRootName(distFile) + "sorted.dist"; + + + //if you can, use the unix sort since its been optimized for years + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) + string command = "sort -n -k +3 " + distFile + " -o " + outfile; + system(command.c_str()); + #else //you are stuck with my best attempt... + //windows sort does not have a way to specify a column, only a character in the line + //since we cannot assume that the distance will always be at the the same character location on each line + //due to variable sequence name lengths, I chose to force the distance into first position, then sort and then put it back. + + //read in file line by file and put distance first + string tempDistFile = distFile + ".temp"; + ifstream input; + ofstream output; + openInputFile(distFile, input); + openOutputFile(tempDistFile, output); + + string firstName, secondName; + float dist; + while (input) { + input >> firstName >> secondName >> dist; + output << dist << '\t' << firstName << '\t' << secondName << endl; + gobble(input); + } + input.close(); + output.close(); + + + //sort using windows sort + string tempOutfile = outfile + ".temp"; + string command = "sort " + tempDistFile + " /O " + tempOutfile; + system(command.c_str()); + + //read in sorted file and put distance at end again + ifstream input2; + openInputFile(tempOutfile, input2); + openOutputFile(outfile, output); + + while (input2) { + input2 >> dist >> firstName >> secondName; + output << firstName << '\t' << secondName << '\t' << dist << endl; + gobble(input2); + } + input2.close(); + output.close(); + + //remove temp files + remove(tempDistFile.c_str()); + remove(tempOutfile.c_str()); + #endif + + return outfile; + } + catch(exception& e) { + errorOut(e, "MothurOut", "sortFile"); + exit(1); + } +} +/**************************************************************************************************/ +vector MothurOut::setFilePosFasta(string filename, int& num) { + try { + vector positions; + ifstream inFASTA; + openInputFile(filename, inFASTA); + + string input; + while(!inFASTA.eof()){ + input = getline(inFASTA); + if (input.length() != 0) { + if(input[0] == '>'){ unsigned long int pos = inFASTA.tellg(); positions.push_back(pos - input.length() - 1); } + } + gobble(inFASTA); //has to be here since windows line endings are 2 characters and mess up the positions + } + inFASTA.close(); + + num = positions.size(); + + /*FILE * pFile; + long size; + + //get num bytes in file + pFile = fopen (filename.c_str(),"rb"); + if (pFile==NULL) perror ("Error opening file"); + else{ + fseek (pFile, 0, SEEK_END); + size=ftell (pFile); + fclose (pFile); + }*/ + + unsigned long int size = positions[(positions.size()-1)]; + ifstream in; + openInputFile(filename, in); + + in.seekg(size); + + while(char c = in.get()){ + if(in.eof()) { break; } + else { size++; } + } + in.close(); + + positions.push_back(size); + + return positions; + } + catch(exception& e) { + errorOut(e, "MothurOut", "setFilePosFasta"); + exit(1); + } +} +/**************************************************************************************************/ +vector MothurOut::setFilePosEachLine(string filename, int& num) { + try { + + vector positions; + ifstream in; + openInputFile(filename, in); + + string input; + while(!in.eof()){ + unsigned long int lastpos = in.tellg(); + input = getline(in); + if (input.length() != 0) { + unsigned long int 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 + } + in.close(); + + num = positions.size(); + + FILE * pFile; + unsigned long int size; + + //get num bytes in file + pFile = fopen (filename.c_str(),"rb"); + if (pFile==NULL) perror ("Error opening file"); + else{ + fseek (pFile, 0, SEEK_END); + size=ftell (pFile); + fclose (pFile); + } + + positions.push_back(size); + + return positions; + } + catch(exception& e) { + errorOut(e, "MothurOut", "setFilePosEachLine"); + exit(1); + } +} +/**************************************************************************************************/ + +vector MothurOut::divideFile(string filename, int& proc) { + try{ + + vector filePos; + filePos.push_back(0); + + FILE * pFile; + unsigned long int size; + + //get num bytes in file + pFile = fopen (filename.c_str(),"rb"); + if (pFile==NULL) perror ("Error opening file"); + else{ + fseek (pFile, 0, SEEK_END); + size=ftell (pFile); + fclose (pFile); + } + + //estimate file breaks + unsigned long int chunkSize = 0; + chunkSize = size / proc; + + //file to small to divide by processors + if (chunkSize == 0) { proc = 1; filePos.push_back(size); return filePos; } + + //for each process seekg to closest file break and search for next '>' char. make that the filebreak + for (int i = 0; i < proc; i++) { + unsigned long int spot = (i+1) * chunkSize; + + ifstream in; + openInputFile(filename, in); + in.seekg(spot); + + //look for next '>' + unsigned long int newSpot = spot; + while (!in.eof()) { + char c = in.get(); + if (c == '>') { in.putback(c); newSpot = in.tellg(); break; } + } + + //there was not another sequence before the end of the file + unsigned long int sanityPos = in.tellg(); + if (sanityPos = -1) { break; } + else { filePos.push_back(newSpot); } + + in.close(); + } + + //save end pos + filePos.push_back(size); + + //sanity check filePos + for (int i = 0; i < (filePos.size()-1); i++) { + if (filePos[(i+1)] <= filePos[i]) { filePos.erase(filePos.begin()+(i+1)); i--; } + } + + proc = (filePos.size() - 1); + + return filePos; + } + catch(exception& e) { + errorOut(e, "MothurOut", "divideFile"); + exit(1); + } +} + +/***********************************************************************/ + +bool MothurOut::isTrue(string f){ + try { + + for (int i = 0; i < f.length(); i++) { f[i] = toupper(f[i]); } + + if ((f == "TRUE") || (f == "T")) { return true; } + else { return false; } + } + catch(exception& e) { + errorOut(e, "MothurOut", "isTrue"); + exit(1); + } +} + +/***********************************************************************/ + +float MothurOut::roundDist(float dist, int precision){ + try { + return int(dist * precision + 0.5)/float(precision); + } + catch(exception& e) { + errorOut(e, "MothurOut", "roundDist"); + exit(1); + } +} +/***********************************************************************/ + +float MothurOut::ceilDist(float dist, int precision){ + try { + return int(ceil(dist * precision))/float(precision); + } + catch(exception& e) { + errorOut(e, "MothurOut", "ceilDist"); + exit(1); + } +} + +/***********************************************************************/ + +int MothurOut::getNumNames(string names){ + try { + int count = 0; + + if(names != ""){ + count = 1; + for(int i=0;i > MothurOut::binomial(int maxOrder){ + try { + vector > binomial(maxOrder+1); + + for(int i=0;i<=maxOrder;i++){ + binomial[i].resize(maxOrder+1); + binomial[i][0]=1; + binomial[0][i]=0; + } + binomial[0][0]=1; + + binomial[1][0]=1; + binomial[1][1]=1; + + for(int i=2;i<=maxOrder;i++){ + binomial[1][i]=0; + } + + for(int i=2;i<=maxOrder;i++){ + for(int j=1;j<=maxOrder;j++){ + if(i==j){ binomial[i][j]=1; } + if(j>i) { binomial[i][j]=0; } + else { binomial[i][j]=binomial[i-1][j-1]+binomial[i-1][j]; } + } + } + + return binomial; + + } + catch(exception& e) { + errorOut(e, "MothurOut", "binomial"); + exit(1); + } +} + +/***********************************************************************/ + +int MothurOut::factorial(int num){ + try { + int total = 1; + + for (int i = 1; i <= num; i++) { + total *= i; + } + + return total; + } + catch(exception& e) { + errorOut(e, "MothurOut", "factorial"); + exit(1); + } +} +/***********************************************************************/ + +int MothurOut::getNumSeqs(ifstream& file){ + try { + int numSeqs = count(istreambuf_iterator(file),istreambuf_iterator(), '>'); + file.seekg(0); + return numSeqs; + } + catch(exception& e) { + errorOut(e, "MothurOut", "getNumSeqs"); + exit(1); + } +} +/***********************************************************************/ +void MothurOut::getNumSeqs(ifstream& file, int& numSeqs){ + try { + string input; + numSeqs = 0; + while(!file.eof()){ + input = getline(file); + if (input.length() != 0) { + if(input[0] == '>'){ numSeqs++; } + } + } + } + catch(exception& e) { + errorOut(e, "MothurOut", "getNumSeqs"); + exit(1); + } +} +/***********************************************************************/ + +//This function parses the estimator options and puts them in a vector +void MothurOut::splitAtChar(string& estim, vector& container, char symbol) { + try { + string individual; + + while (estim.find_first_of(symbol) != -1) { + individual = estim.substr(0,estim.find_first_of(symbol)); + if ((estim.find_first_of(symbol)+1) <= estim.length()) { //checks to make sure you don't have dash at end of string + estim = estim.substr(estim.find_first_of(symbol)+1, estim.length()); + container.push_back(individual); + } + } + //get last one + container.push_back(estim); + } + catch(exception& e) { + errorOut(e, "MothurOut", "splitAtChar"); + exit(1); + } +} + +/***********************************************************************/ + +//This function parses the estimator options and puts them in a vector +void MothurOut::splitAtDash(string& estim, vector& container) { + try { + 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); + } +} + +/***********************************************************************/ +//This function parses the label options and puts them in a set +void MothurOut::splitAtDash(string& estim, set& container) { + try { + 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"); + exit(1); + } +} +/***********************************************************************/ +//This function parses the line options and puts them in a set +void MothurOut::splitAtDash(string& estim, set& container) { + try { + 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); + } + } + //get last one + convert(estim, lineNum); //convert the string to int + container.insert(lineNum); + } + catch(exception& e) { + errorOut(e, "MothurOut", "splitAtDash"); + exit(1); + } +} +/***********************************************************************/ +//This function parses the a string and puts peices in a vector +void MothurOut::splitAtComma(string& estim, vector& container) { + try { + 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 comma 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", "splitAtComma"); + exit(1); + } +} +/***********************************************************************/ + +//This function splits up the various option parameters +void MothurOut::splitAtComma(string& prefix, string& suffix){ + try { + prefix = suffix.substr(0,suffix.find_first_of(',')); + if ((suffix.find_first_of(',')+2) <= suffix.length()) { //checks to make sure you don't have comma at end of string + suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length()); + string space = " "; + while(suffix.at(0) == ' ') + suffix = suffix.substr(1, suffix.length()); + } + + } + catch(exception& e) { + errorOut(e, "MothurOut", "splitAtComma"); + exit(1); + } +} +/***********************************************************************/ + +//This function separates the key value from the option value i.e. dist=96_... +void MothurOut::splitAtEquals(string& key, string& value){ + try { + if(value.find_first_of('=') != -1){ + key = value.substr(0,value.find_first_of('=')); + if ((value.find_first_of('=')+1) <= value.length()) { + value = value.substr(value.find_first_of('=')+1, value.length()); + } + }else{ + key = value; + value = 1; + } + } + catch(exception& e) { + errorOut(e, "MothurOut", "splitAtEquals"); + exit(1); + } +} + +/**************************************************************************************************/ + +bool MothurOut::inUsersGroups(string groupname, vector 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 groupnames, vector Groups) { + try { + + for (int i = 0; i < groupnames.size(); i++) { + if (inUsersGroups(groupnames[i], Groups)) { return true; } + } + return false; + } + catch(exception& e) { + errorOut(e, "MothurOut", "inUsersGroups"); + exit(1); + } +} +/***********************************************************************/ +//this function determines if the user has given us labels that are smaller than the given label. +//if so then it returns true so that the calling function can run the previous valid distance. +//it's a "smart" distance function. It also checks for invalid labels. +bool MothurOut::anyLabelsToProcess(string label, set& userLabels, string errorOff) { + try { + + set::iterator it; + vector orderFloat; + map userMap; //the conversion process removes trailing 0's which we need to put back + map::iterator it2; + float labelFloat; + bool smaller = false; + + //unique is the smallest line + if (label == "unique") { return false; } + else { + if (convertTestFloat(label, labelFloat)) { + convert(label, labelFloat); + }else { //cant convert + return false; + } + } + + //go through users set and make them floats + for(it = userLabels.begin(); it != userLabels.end(); ++it) { + + float temp; + if ((*it != "unique") && (convertTestFloat(*it, temp) == true)){ + convert(*it, temp); + orderFloat.push_back(temp); + userMap[*it] = temp; + }else if (*it == "unique") { + orderFloat.push_back(-1.0); + userMap["unique"] = -1.0; + }else { + if (errorOff == "") { cout << *it << " is not a valid label." << endl; } + userLabels.erase(*it); + it--; + } + } + + //sort order + sort(orderFloat.begin(), orderFloat.end()); + + /*************************************************/ + //is this label bigger than any of the users labels + /*************************************************/ + + //loop through order until you find a label greater than label + for (int i = 0; i < orderFloat.size(); i++) { + if (orderFloat[i] < labelFloat) { + smaller = true; + if (orderFloat[i] == -1) { + if (errorOff == "") { cout << "Your file does not include the label unique." << endl; } + userLabels.erase("unique"); + } + else { + if (errorOff == "") { cout << "Your file does not include the label " << endl; } + string s = ""; + for (it2 = userMap.begin(); it2!= userMap.end(); it2++) { + if (it2->second == orderFloat[i]) { + s = it2->first; + //remove small labels + userLabels.erase(s); + break; + } + } + if (errorOff == "") {cout << s << ". I will use the next smallest distance. " << endl; } + } + //since they are sorted once you find a bigger one stop looking + }else { break; } + } + + return smaller; + + } + catch(exception& e) { + errorOut(e, "MothurOut", "anyLabelsToProcess"); + exit(1); + } +} + +/**************************************************************************************************/ +bool MothurOut::checkReleaseVersion(ifstream& file, string version) { + try { + + bool good = true; + + string line = getline(file); + + //before we added this check + if (line[0] != '#') { good = false; } + else { + //rip off # + line = line.substr(1); + + vector versionVector; + splitAtChar(version, versionVector, '.'); + + //check file version + vector linesVector; + splitAtChar(line, linesVector, '.'); + + if (versionVector.size() != linesVector.size()) { good = false; } + else { + for (int j = 0; j < versionVector.size(); j++) { + int num1, num2; + convert(versionVector[j], num1); + convert(linesVector[j], num2); + + //if mothurs version is newer than this files version, then we want to remake it + if (num1 > num2) { good = false; break; } + } + } + + } + + if (!good) { file.close(); } + else { file.seekg(0); } + + return good; + } + catch(exception& e) { + errorOut(e, "MothurOut", "checkReleaseVersion"); + exit(1); + } +} +/**************************************************************************************************/ + + + + + diff --git a/mothurout.h b/mothurout.h index 92363f5..2244eee 100644 --- a/mothurout.h +++ b/mothurout.h @@ -32,7 +32,56 @@ class MothurOut { void setReleaseDate(string r) { releaseDate = r; } string getVersion() { return version; } void setVersion(string r) { version = r; } - + + //functions from mothur.h + //file operations + vector divideFile(string, int&); + vector setFilePosEachLine(string, int&); + vector setFilePosFasta(string, int&); + string sortFile(string, string); + void appendFiles(string, string); + int renameFile(string, string); //oldname, newname + string getFullPathName(string); + string hasPath(string); + string getExtension(string); + string getPathName(string); + string getSimpleName(string); + string getRootName(string); + bool isBlank(string); + int openOutputFile(string, ofstream&); + int openOutputFileAppend(string, ofstream&); + int openInputFile(string, ifstream&); + int openInputFile(string, ifstream&, string); //no error given + string getline(ifstream&); + string getline(istringstream&); + void gobble(istream&); + void gobble(istringstream&); + + //searchs and checks + bool checkReleaseVersion(ifstream&, string); + bool anyLabelsToProcess(string, set&, string); + bool inUsersGroups(vector, vector); + bool inUsersGroups(string, vector); + void getNumSeqs(ifstream&, int&); + int getNumSeqs(ifstream&); + int getNumNames(string); + bool isTrue(string); + + + //string manipulation + void splitAtEquals(string&, string&); + void splitAtComma(string&, string&); + void splitAtComma(string&, vector&); + void splitAtDash(string&, set&); + void splitAtDash(string&, set&); + void splitAtDash(string&, vector&); + void splitAtChar(string&, vector&, char); + + //math operation + int factorial(int num); + vector > binomial(int); + float ceilDist(float, int); + float roundDist(float, int); int control_pressed; bool executing; diff --git a/nameassignment.cpp b/nameassignment.cpp index 0a62a03..3d99551 100644 --- a/nameassignment.cpp +++ b/nameassignment.cpp @@ -6,7 +6,7 @@ NameAssignment::NameAssignment(string nameMapFile){ m = MothurOut::getInstance(); - openInputFile(nameMapFile, fileHandle); + m->openInputFile(nameMapFile, fileHandle); } @@ -34,7 +34,7 @@ void NameAssignment::readMap(){ }else{ m->mothurOut(firstCol + " is already in namesfile. I will use first definition."); m->mothurOutEndLine(); } - gobble(fileHandle); + m->gobble(fileHandle); } fileHandle.close(); diff --git a/nastreport.cpp b/nastreport.cpp index 132886b..95901a3 100644 --- a/nastreport.cpp +++ b/nastreport.cpp @@ -16,132 +16,197 @@ /******************************************************************************************************************/ NastReport::NastReport() { - output = ""; + try { + m = MothurOut::getInstance(); + output = ""; + } + catch(exception& e) { + m->errorOut(e, "NastReport", "NastReport"); + exit(1); + } } /******************************************************************************************************************/ string NastReport::getHeaders() { - output = ""; - - output += "QueryName\tQueryLength\tTemplateName\tTemplateLength\t"; - output += "SearchMethod\tSearchScore\t"; - output += "AlignmentMethod\tQueryStart\tQueryEnd\tTemplateStart\tTemplateEnd\t"; - output += "PairwiseAlignmentLength\tGapsInQuery\tGapsInTemplate\t"; - output += "LongestInsert\t"; - output += "SimBtwnQuery&Template\n"; - - return output; + try { + output = ""; + + output += "QueryName\tQueryLength\tTemplateName\tTemplateLength\t"; + output += "SearchMethod\tSearchScore\t"; + output += "AlignmentMethod\tQueryStart\tQueryEnd\tTemplateStart\tTemplateEnd\t"; + output += "PairwiseAlignmentLength\tGapsInQuery\tGapsInTemplate\t"; + output += "LongestInsert\t"; + output += "SimBtwnQuery&Template\n"; + + return output; + } + catch(exception& e) { + m->errorOut(e, "NastReport", "getHeaders"); + exit(1); + } } /******************************************************************************************************************/ NastReport::NastReport(string candidateReportFName) { - openOutputFile(candidateReportFName, candidateReportFile); - - candidateReportFile << "QueryName\tQueryLength\tTemplateName\tTemplateLength\t"; - candidateReportFile << "SearchMethod\tSearchScore\t"; - candidateReportFile << "AlignmentMethod\tQueryStart\tQueryEnd\tTemplateStart\tTemplateEnd\t"; - candidateReportFile << "PairwiseAlignmentLength\tGapsInQuery\tGapsInTemplate\t"; - candidateReportFile << "LongestInsert\t"; - candidateReportFile << "SimBtwnQuery&Template" << endl; + try { + m = MothurOut::getInstance(); + m->openOutputFile(candidateReportFName, candidateReportFile); + + candidateReportFile << "QueryName\tQueryLength\tTemplateName\tTemplateLength\t"; + candidateReportFile << "SearchMethod\tSearchScore\t"; + candidateReportFile << "AlignmentMethod\tQueryStart\tQueryEnd\tTemplateStart\tTemplateEnd\t"; + candidateReportFile << "PairwiseAlignmentLength\tGapsInQuery\tGapsInTemplate\t"; + candidateReportFile << "LongestInsert\t"; + candidateReportFile << "SimBtwnQuery&Template" << endl; + } + catch(exception& e) { + m->errorOut(e, "NastReport", "NastReport"); + exit(1); + } } /******************************************************************************************************************/ NastReport::~NastReport() { - candidateReportFile.close(); + try { + candidateReportFile.close(); + } + catch(exception& e) { + m->errorOut(e, "NastReport", "~NastReport"); + exit(1); + } } /******************************************************************************************************************/ void NastReport::print(){ - - candidateReportFile << queryName << '\t' << queryLength << '\t' << templateName << '\t' << templateLength << '\t'; - candidateReportFile << searchMethod << '\t' << setprecision(2) << fixed << searchScore << '\t'; - - candidateReportFile << alignmentMethod << '\t' << candidateStartPosition << "\t" << candidateEndPosition << '\t'; - candidateReportFile << templateStartPosition << "\t" << templateEndPosition << '\t'; - candidateReportFile << pairwiseAlignmentLength << '\t' << totalGapsInQuery << '\t' << totalGapsInTemplate << '\t'; - candidateReportFile << longestInsert << '\t'; - candidateReportFile << setprecision(2) << similarityToTemplate; - - candidateReportFile << endl; - candidateReportFile.flush(); + try { + candidateReportFile << queryName << '\t' << queryLength << '\t' << templateName << '\t' << templateLength << '\t'; + candidateReportFile << searchMethod << '\t' << setprecision(2) << fixed << searchScore << '\t'; + + candidateReportFile << alignmentMethod << '\t' << candidateStartPosition << "\t" << candidateEndPosition << '\t'; + candidateReportFile << templateStartPosition << "\t" << templateEndPosition << '\t'; + candidateReportFile << pairwiseAlignmentLength << '\t' << totalGapsInQuery << '\t' << totalGapsInTemplate << '\t'; + candidateReportFile << longestInsert << '\t'; + candidateReportFile << setprecision(2) << similarityToTemplate; + + candidateReportFile << endl; + candidateReportFile.flush(); + } + catch(exception& e) { + m->errorOut(e, "NastReport", "print"); + exit(1); + } } /******************************************************************************************************************/ string NastReport::getReport(){ - - output = ""; - - output += queryName + '\t' + toString(queryLength) + '\t' + templateName + '\t' + toString(templateLength) + '\t'; - - string temp = toString(searchScore); - int pos = temp.find_last_of('.'); //find deicmal point if their is one - - //if there is a decimal - if (pos != -1) { temp = temp.substr(0, pos+3); } //set precision to 2 places - else{ temp += ".00"; } - - output += searchMethod + '\t' + temp + '\t'; - output += alignmentMethod + '\t' + toString(candidateStartPosition) + "\t" + toString(candidateEndPosition) + '\t'; - output += toString(templateStartPosition) + "\t" + toString(templateEndPosition) + '\t'; - output += toString(pairwiseAlignmentLength) + '\t' + toString(totalGapsInQuery) + '\t' + toString(totalGapsInTemplate) + '\t'; - output += toString(longestInsert) + '\t'; - - temp = toString(similarityToTemplate); - pos = temp.find_last_of('.'); //find deicmal point if their is one - - //if there is a decimal - if (pos != -1) { temp = temp.substr(0, pos+3); } //set precision to 2 places - else{ temp += ".00"; } - - output += temp + '\n'; - - return output; + try { + output = ""; + + output += queryName + '\t' + toString(queryLength) + '\t' + templateName + '\t' + toString(templateLength) + '\t'; + + string temp = toString(searchScore); + int pos = temp.find_last_of('.'); //find deicmal point if their is one + + //if there is a decimal + if (pos != -1) { temp = temp.substr(0, pos+3); } //set precision to 2 places + else{ temp += ".00"; } + + output += searchMethod + '\t' + temp + '\t'; + output += alignmentMethod + '\t' + toString(candidateStartPosition) + "\t" + toString(candidateEndPosition) + '\t'; + output += toString(templateStartPosition) + "\t" + toString(templateEndPosition) + '\t'; + output += toString(pairwiseAlignmentLength) + '\t' + toString(totalGapsInQuery) + '\t' + toString(totalGapsInTemplate) + '\t'; + output += toString(longestInsert) + '\t'; + + temp = toString(similarityToTemplate); + pos = temp.find_last_of('.'); //find deicmal point if their is one + + //if there is a decimal + if (pos != -1) { temp = temp.substr(0, pos+3); } //set precision to 2 places + else{ temp += ".00"; } + + output += temp + '\n'; + + return output; + } + catch(exception& e) { + m->errorOut(e, "NastReport", "getReport"); + exit(1); + } } /******************************************************************************************************************/ void NastReport::setCandidate(Sequence* candSeq){ - queryName = candSeq->getName(); - queryLength = candSeq->getNumBases(); + try { + queryName = candSeq->getName(); + queryLength = candSeq->getNumBases(); + } + catch(exception& e) { + m->errorOut(e, "NastReport", "setCandidate"); + exit(1); + } } /******************************************************************************************************************/ void NastReport::setTemplate(Sequence* tempSeq){ - templateName = tempSeq->getName(); - templateLength = tempSeq->getNumBases(); + try { + templateName = tempSeq->getName(); + templateLength = tempSeq->getNumBases(); + } + catch(exception& e) { + m->errorOut(e, "NastReport", "setTemplate"); + exit(1); + } } /******************************************************************************************************************/ void NastReport::setSearchParameters(string method, float score){ - searchMethod = method; - searchScore = score; + try { + searchMethod = method; + searchScore = score; + } + catch(exception& e) { + m->errorOut(e, "NastReport", "setSearchParameters"); + exit(1); + } } /******************************************************************************************************************/ void NastReport::setAlignmentParameters(string method, Alignment* align){ - alignmentMethod = method; - - candidateStartPosition = align->getCandidateStartPos(); - candidateEndPosition = align->getCandidateEndPos(); - templateStartPosition = align->getTemplateStartPos(); - templateEndPosition = align->getTemplateEndPos(); - pairwiseAlignmentLength = align->getPairwiseLength(); - - totalGapsInQuery = pairwiseAlignmentLength - (candidateEndPosition - candidateStartPosition + 1); - totalGapsInTemplate = pairwiseAlignmentLength - (templateEndPosition - templateStartPosition + 1); + try { + alignmentMethod = method; + + candidateStartPosition = align->getCandidateStartPos(); + candidateEndPosition = align->getCandidateEndPos(); + templateStartPosition = align->getTemplateStartPos(); + templateEndPosition = align->getTemplateEndPos(); + pairwiseAlignmentLength = align->getPairwiseLength(); + + totalGapsInQuery = pairwiseAlignmentLength - (candidateEndPosition - candidateStartPosition + 1); + totalGapsInTemplate = pairwiseAlignmentLength - (templateEndPosition - templateStartPosition + 1); + } + catch(exception& e) { + m->errorOut(e, "NastReport", "setAlignmentParameters"); + exit(1); + } } /******************************************************************************************************************/ void NastReport::setNastParameters(Nast nast){ - - longestInsert = nast.getMaxInsertLength(); - similarityToTemplate = nast.getSimilarityScore(); - + try { + + longestInsert = nast.getMaxInsertLength(); + similarityToTemplate = nast.getSimilarityScore(); + } + catch(exception& e) { + m->errorOut(e, "NastReport", "setNastParameters"); + exit(1); + } } /******************************************************************************************************************/ diff --git a/nastreport.hpp b/nastreport.hpp index 80c9949..c25575a 100644 --- a/nastreport.hpp +++ b/nastreport.hpp @@ -47,6 +47,7 @@ private: int totalGapsInQuery, totalGapsInTemplate; float similarityToTemplate; ofstream candidateReportFile; + MothurOut* m; }; /******************************************************************************************************************/ diff --git a/optionparser.cpp b/optionparser.cpp index c50d5a3..08032b3 100644 --- a/optionparser.cpp +++ b/optionparser.cpp @@ -19,13 +19,13 @@ OptionParser::OptionParser(string option) { string key, value; //reads in parameters and values while((option.find_first_of(',') != -1)) { //while there are parameters - splitAtComma(value, option); - splitAtEquals(key, value); + m->splitAtComma(value, option); + m->splitAtEquals(key, value); parameters[key] = value; } //in case there is no comma and to get last parameter after comma - splitAtEquals(key, option); + m->splitAtEquals(key, option); parameters[key] = option; } } diff --git a/otuhierarchycommand.cpp b/otuhierarchycommand.cpp index 05d6443..2c71cd5 100644 --- a/otuhierarchycommand.cpp +++ b/otuhierarchycommand.cpp @@ -41,7 +41,7 @@ OtuHierarchyCommand::OtuHierarchyCommand(string option) { it = parameters.find("list"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["list"] = inputDir + it->second; } } @@ -54,7 +54,7 @@ OtuHierarchyCommand::OtuHierarchyCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(listFile); //if user entered a file with a path then preserve it + outputDir += m->hasPath(listFile); //if user entered a file with a path then preserve it } //check for optional parameter and set defaults @@ -62,7 +62,7 @@ OtuHierarchyCommand::OtuHierarchyCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { m->mothurOut("label is a required parameter for the otu.hierarchy command."); m->mothurOutEndLine(); abort = true; } else { - splitAtDash(label, labels); + m->splitAtDash(label, labels); if (labels.size() != 2) { m->mothurOut("You must provide 2 labels."); m->mothurOutEndLine(); abort = true; } } @@ -142,8 +142,8 @@ int OtuHierarchyCommand::execute(){ } ofstream out; - string outputFileName = outputDir + getRootName(getSimpleName(listFile)) + lists[0].getLabel() + "-" + lists[1].getLabel() + ".otu.hierarchy"; - openOutputFile(outputFileName, out); + string outputFileName = outputDir + m->getRootName(m->getSimpleName(listFile)) + lists[0].getLabel() + "-" + lists[1].getLabel() + ".otu.hierarchy"; + m->openOutputFile(outputFileName, out); //go through each bin in "big" otu and output the bins in "little" otu which created it for (int i = 0; i < lists[1].getNumBins(); i++) { @@ -211,7 +211,7 @@ vector OtuHierarchyCommand::getListVectors() { //open file ifstream in; - openInputFile(listFile, in); + m->openInputFile(listFile, in); //get first list vector in file ListVector* list = NULL; @@ -220,7 +220,7 @@ vector OtuHierarchyCommand::getListVectors() { pos = in.tellg(); lastPos = pos; list = new ListVector(in); - gobble(in); + m->gobble(in); lastLabel = list->getLabel(); } @@ -240,7 +240,7 @@ vector OtuHierarchyCommand::getListVectors() { } //you have a label the user want that is smaller than this label and the last label has not already been processed - if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = list->getLabel(); int savePos = in.tellg(); @@ -271,7 +271,7 @@ vector OtuHierarchyCommand::getListVectors() { if (!in.eof()) { pos = in.tellg(); list = new ListVector(in); - gobble(in); + m->gobble(in); }else { list = NULL; } } diff --git a/parselistscommand.cpp b/parselistscommand.cpp index d09910b..4b24236 100644 --- a/parselistscommand.cpp +++ b/parselistscommand.cpp @@ -42,7 +42,7 @@ ParseListCommand::ParseListCommand(string option) { it = parameters.find("list"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["list"] = inputDir + it->second; } } @@ -50,7 +50,7 @@ ParseListCommand::ParseListCommand(string option) { it = parameters.find("group"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["group"] = inputDir + it->second; } } @@ -83,7 +83,7 @@ ParseListCommand::ParseListCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; allLines = 1; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } } @@ -120,7 +120,7 @@ int ParseListCommand::execute(){ if (abort == true) { return 0; } //set fileroot - string fileroot = outputDir + getRootName(getSimpleName(listfile)); + string fileroot = outputDir + m->getRootName(m->getSimpleName(listfile)); vector outputNames; //fill filehandles with neccessary ofstreams @@ -132,7 +132,7 @@ int ParseListCommand::execute(){ string filename = fileroot + groupMap->namesOfGroups[i] + ".list"; outputNames.push_back(filename); - openOutputFile(filename, *temp); + m->openOutputFile(filename, *temp); } //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. @@ -168,7 +168,7 @@ int ParseListCommand::execute(){ userLabels.erase(list->getLabel()); } - if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = list->getLabel(); delete list; @@ -278,7 +278,7 @@ int ParseListCommand::parse(ListVector* thisList) { string bin = list->get(i); vector names; - splitAtComma(bin, names); //parses bin into individual sequence names + m->splitAtComma(bin, names); //parses bin into individual sequence names //parse bin into list of sequences in each group for (int j = 0; j < names.size(); j++) { diff --git a/parsesffcommand.cpp b/parsesffcommand.cpp index d210ce8..03d8e96 100644 --- a/parsesffcommand.cpp +++ b/parsesffcommand.cpp @@ -44,7 +44,7 @@ ParseSFFCommand::ParseSFFCommand(string option){ it = parameters.find("sff"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["sff"] = inputDir + it->second; } } @@ -52,7 +52,7 @@ ParseSFFCommand::ParseSFFCommand(string option){ it = parameters.find("oligos"); //user has given an oligos file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["oligos"] = inputDir + it->second; } } @@ -72,7 +72,7 @@ ParseSFFCommand::ParseSFFCommand(string option){ outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(sffFile); //if user entered a file with a path then preserve it + outputDir += m->hasPath(sffFile); //if user entered a file with a path then preserve it } //check for optional parameter and set defaults @@ -103,7 +103,7 @@ int ParseSFFCommand::execute(){ if (abort == true) { return 0; } ifstream inSFF; - openInputFile(sffFile, inSFF); + m->openInputFile(sffFile, inSFF); cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint); @@ -114,8 +114,8 @@ int ParseSFFCommand::execute(){ getOligos(flowFileNames); } else{ - flowFileNames.push_back(new ofstream((outputDir + getRootName(getSimpleName(sffFile)) + "flow").c_str(), ios::ate)); - outputNames.push_back((outputDir + getRootName(getSimpleName(sffFile)) + "flow")); + flowFileNames.push_back(new ofstream((outputDir + m->getRootName(m->getSimpleName(sffFile)) + "flow").c_str(), ios::ate)); + outputNames.push_back((outputDir + m->getRootName(m->getSimpleName(sffFile)) + "flow")); } for(int i=0;icontrol_pressed) { for(int i=0;iclose(); } return 0; } // ofstream fastaFile; -// openOutputFile(getRootName(sffFile) + "fasta", fastaFile); +// m->openOutputFile(m->getRootName(sffFile) + "fasta", fastaFile); // ofstream qualFile; -// openOutputFile(getRootName(sffFile) + "qual", qualFile); +// m->openOutputFile(m->getRootName(sffFile) + "qual", qualFile); - string commonHeader = getline(inSFF); - string magicNumber = getline(inSFF); - string version = getline(inSFF); - string indexOffset = getline(inSFF); - string indexLength = getline(inSFF); + string commonHeader = m->getline(inSFF); + string magicNumber = m->getline(inSFF); + string version = m->getline(inSFF); + string indexOffset = m->getline(inSFF); + string indexLength = m->getline(inSFF); int numReads = parseHeaderLineToInt(inSFF); - string headerLength = getline(inSFF); - string keyLength = getline(inSFF); + string headerLength = m->getline(inSFF); + string keyLength = m->getline(inSFF); int numFlows = parseHeaderLineToInt(inSFF); - string flowgramCode = getline(inSFF); - string flowChars = getline(inSFF); - string keySequence = getline(inSFF); - gobble(inSFF); + string flowgramCode = m->getline(inSFF); + string flowChars = m->getline(inSFF); + string keySequence = m->getline(inSFF); + m->gobble(inSFF); string seqName; bool good = 0; @@ -155,17 +155,17 @@ int ParseSFFCommand::execute(){ inSFF >> seqName; seqName = seqName.substr(1); - gobble(inSFF); + m->gobble(inSFF); string runPrefix = parseHeaderLineToString(inSFF); string regionNumber = parseHeaderLineToString(inSFF); string xyLocation = parseHeaderLineToString(inSFF); - gobble(inSFF); + m->gobble(inSFF); string runName = parseHeaderLineToString(inSFF); string analysisName = parseHeaderLineToString(inSFF); string fullPath = parseHeaderLineToString(inSFF); - gobble(inSFF); + m->gobble(inSFF); string readHeaderLen = parseHeaderLineToString(inSFF); string nameLength = parseHeaderLineToString(inSFF); @@ -174,13 +174,13 @@ int ParseSFFCommand::execute(){ int clipQualRight = parseHeaderLineToInt(inSFF); string clipAdapLeft = parseHeaderLineToString(inSFF); string clipAdapRight = parseHeaderLineToString(inSFF); - gobble(inSFF); + m->gobble(inSFF); vector flowVector = parseHeaderLineToFloatVector(inSFF, numFlows); vector flowIndices = parseHeaderLineToIntVector(inSFF, numBases); string bases = parseHeaderLineToString(inSFF); string qualityScores = parseHeaderLineToString(inSFF); - gobble(inSFF); + m->gobble(inSFF); @@ -250,7 +250,7 @@ void ParseSFFCommand::getOligos(vector& outSFFFlowVec){ try { ifstream inOligos; - openInputFile(oligoFile, inOligos); + m->openInputFile(oligoFile, inOligos); string type, oligo, group; @@ -259,7 +259,7 @@ void ParseSFFCommand::getOligos(vector& outSFFFlowVec){ while(!inOligos.eof()){ inOligos >> type; - if(type[0] == '#'){ getline(inOligos); } // get rest of line if there's any crap there + if(type[0] == '#'){ m->getline(inOligos); } // get rest of line if there's any crap there else{ inOligos >> oligo; @@ -280,11 +280,11 @@ void ParseSFFCommand::getOligos(vector& outSFFFlowVec){ barcodes[oligo]=index++; groupVector.push_back(group); - outSFFFlowVec.push_back(new ofstream((outputDir + getRootName(getSimpleName(sffFile)) + group + ".flow").c_str(), ios::ate)); - outputNames.push_back((outputDir + getRootName(getSimpleName(sffFile)) + group + "flow")); + outSFFFlowVec.push_back(new ofstream((outputDir + m->getRootName(m->getSimpleName(sffFile)) + group + ".flow").c_str(), ios::ate)); + outputNames.push_back((outputDir + m->getRootName(m->getSimpleName(sffFile)) + group + "flow")); } } - gobble(inOligos); + m->gobble(inOligos); } inOligos.close(); @@ -315,7 +315,7 @@ int ParseSFFCommand::parseHeaderLineToInt(ifstream& file){ } } - gobble(file); + m->gobble(file); return number; } @@ -329,12 +329,12 @@ string ParseSFFCommand::parseHeaderLineToString(ifstream& file){ char c = file.get(); if (c == ':'){ - gobble(file); - text = getline(file); + m->gobble(file); + text = m->getline(file); break; } } - gobble(file); + m->gobble(file); return text; } @@ -354,7 +354,7 @@ vector ParseSFFCommand::parseHeaderLineToFloatVector(ifstream& file, int break; } } - gobble(file); + m->gobble(file); return floatVector; } @@ -373,7 +373,7 @@ vector ParseSFFCommand::parseHeaderLineToIntVector(ifstream& file, int leng break; } } - gobble(file); + m->gobble(file); return intVector; } diff --git a/parsimonycommand.cpp b/parsimonycommand.cpp index b87e9c0..3295de2 100644 --- a/parsimonycommand.cpp +++ b/parsimonycommand.cpp @@ -50,7 +50,7 @@ ParsimonyCommand::ParsimonyCommand(string option) { groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; globaldata->Groups.clear(); } else { - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); globaldata->Groups = Groups; } @@ -64,20 +64,20 @@ ParsimonyCommand::ParsimonyCommand(string option) { T = globaldata->gTree; tmap = globaldata->gTreemap; - if(outputDir == "") { outputDir += hasPath(globaldata->getTreeFile()); } - output = new ColumnFile(outputDir + getSimpleName(globaldata->getTreeFile()) + ".parsimony", itersString); - outputNames.push_back(outputDir + getSimpleName(globaldata->getTreeFile()) + ".parsimony"); + if(outputDir == "") { outputDir += m->hasPath(globaldata->getTreeFile()); } + output = new ColumnFile(outputDir + m->getSimpleName(globaldata->getTreeFile()) + ".parsimony", itersString); + outputNames.push_back(outputDir + m->getSimpleName(globaldata->getTreeFile()) + ".parsimony"); - sumFile = outputDir + getSimpleName(globaldata->getTreeFile()) + ".psummary"; - openOutputFile(sumFile, outSum); + sumFile = outputDir + m->getSimpleName(globaldata->getTreeFile()) + ".psummary"; + m->openOutputFile(sumFile, outSum); outputNames.push_back(sumFile); }else { //user wants random distribution savetmap = globaldata->gTreemap; getUserInput(); - if(outputDir == "") { outputDir += hasPath(randomtree); } - output = new ColumnFile(outputDir+ getSimpleName(randomtree), itersString); - outputNames.push_back(outputDir+ getSimpleName(randomtree)); + if(outputDir == "") { outputDir += m->hasPath(randomtree); } + output = new ColumnFile(outputDir+ m->getSimpleName(randomtree), itersString); + outputNames.push_back(outputDir+ m->getSimpleName(randomtree)); } //set users groups to analyze diff --git a/pcacommand.cpp b/pcacommand.cpp index c9fecd5..c982d75 100644 --- a/pcacommand.cpp +++ b/pcacommand.cpp @@ -42,7 +42,7 @@ PCACommand::PCACommand(string option) { it = parameters.find("phylip"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["phylip"] = inputDir + it->second; } } @@ -57,7 +57,7 @@ PCACommand::PCACommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(phylipfile); //if user entered a file with a path then preserve it + outputDir += m->hasPath(phylipfile); //if user entered a file with a path then preserve it } //error checking on files @@ -97,7 +97,7 @@ int PCACommand::execute(){ vector names; vector > D; - fbase = outputDir + getRootName(getSimpleName(filename)); + fbase = outputDir + m->getRootName(m->getSimpleName(filename)); read(filename, names, D); @@ -219,11 +219,11 @@ int PCACommand::read_phylip(istream& f, int square_m, vector& name_list, void PCACommand::read(string fname, vector& names, vector >& D){ try { ifstream f; - openInputFile(fname, f); + m->openInputFile(fname, f); //check whether matrix is square char d; - int m = 1; + int q = 1; int numSeqs; string name; @@ -233,21 +233,21 @@ void PCACommand::read(string fname, vector& names, vector //is d a number meaning its square if(isalnum(d)){ - m = 1; + q = 1; break; } //is d a line return meaning its lower triangle if(d == '\n'){ - m = 2; + q = 2; break; } } f.close(); //reopen to get back to beginning - openInputFile(fname, f); - read_phylip(f, m, names, D); + m->openInputFile(fname, f); + read_phylip(f, q, names, D); } catch(exception& e) { m->errorOut(e, "PCACommand", "read"); diff --git a/phylodiversitycommand.cpp b/phylodiversitycommand.cpp index 5a2d33f..619a7f7 100644 --- a/phylodiversitycommand.cpp +++ b/phylodiversitycommand.cpp @@ -34,7 +34,7 @@ PhyloDiversityCommand::PhyloDiversityCommand(string option) { } //if the user changes the output directory command factory will send this info to us in the output parameter - outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = hasPath(globaldata->getTreeFile()); } + outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(globaldata->getTreeFile()); } if (globaldata->gTree.size() == 0) {//no trees were read m->mothurOut("You must execute the read.tree command, before you may execute the phylo.diversity command."); m->mothurOutEndLine(); abort = true; } @@ -47,22 +47,22 @@ PhyloDiversityCommand::PhyloDiversityCommand(string option) { convert(temp, iters); temp = validParameter.validFile(parameters, "rarefy", false); if (temp == "not found") { temp = "F"; } - rarefy = isTrue(temp); + rarefy = m->isTrue(temp); if (!rarefy) { iters = 1; } temp = validParameter.validFile(parameters, "summary", false); if (temp == "not found") { temp = "T"; } - summary = isTrue(temp); + summary = m->isTrue(temp); temp = validParameter.validFile(parameters, "scale", false); if (temp == "not found") { temp = "F"; } - scale = isTrue(temp); + scale = m->isTrue(temp); temp = validParameter.validFile(parameters, "collect", false); if (temp == "not found") { temp = "F"; } - collect = isTrue(temp); + collect = m->isTrue(temp); groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; Groups = globaldata->gTreemap->namesOfGroups; globaldata->Groups = Groups; } else { - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); globaldata->Groups = Groups; } @@ -124,20 +124,20 @@ int PhyloDiversityCommand::execute(){ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } ofstream outSum, outRare, outCollect; - string outSumFile = outputDir + getRootName(getSimpleName(globaldata->getTreeFile())) + toString(i+1) + ".phylodiv.summary"; - string outRareFile = outputDir + getRootName(getSimpleName(globaldata->getTreeFile())) + toString(i+1) + ".phylodiv.rarefaction"; - string outCollectFile = outputDir + getRootName(getSimpleName(globaldata->getTreeFile())) + toString(i+1) + ".phylodiv"; + string outSumFile = outputDir + m->getRootName(m->getSimpleName(globaldata->getTreeFile())) + toString(i+1) + ".phylodiv.summary"; + string outRareFile = outputDir + m->getRootName(m->getSimpleName(globaldata->getTreeFile())) + toString(i+1) + ".phylodiv.rarefaction"; + string outCollectFile = outputDir + m->getRootName(m->getSimpleName(globaldata->getTreeFile())) + toString(i+1) + ".phylodiv"; - if (summary) { openOutputFile(outSumFile, outSum); outputNames.push_back(outSumFile); } - if (rarefy) { openOutputFile(outRareFile, outRare); outputNames.push_back(outRareFile); } - if (collect) { openOutputFile(outCollectFile, outCollect); outputNames.push_back(outCollectFile); } + if (summary) { m->openOutputFile(outSumFile, outSum); outputNames.push_back(outSumFile); } + if (rarefy) { m->openOutputFile(outRareFile, outRare); outputNames.push_back(outRareFile); } + if (collect) { m->openOutputFile(outCollectFile, outCollect); outputNames.push_back(outCollectFile); } int numLeafNodes = trees[i]->getNumLeaves(); //create a vector containing indexes of leaf nodes, randomize it, select nodes to send to calculator vector randomLeaf; for (int j = 0; j < numLeafNodes; j++) { - if (inUsersGroups(trees[i]->tree[j].getGroup(), globaldata->Groups) == true) { //is this a node from the group the user selected. + if (m->inUsersGroups(trees[i]->tree[j].getGroup(), globaldata->Groups) == true) { //is this a node from the group the user selected. randomLeaf.push_back(j); } } diff --git a/phylosummary.cpp b/phylosummary.cpp index 870f35f..39bfdf3 100644 --- a/phylosummary.cpp +++ b/phylosummary.cpp @@ -48,12 +48,12 @@ void PhyloSummary::summarize(string userTfile){ try { ifstream in; - openInputFile(userTfile, in); + m->openInputFile(userTfile, in); //read in users taxonomy file and add sequences to tree string name, tax; while(!in.eof()){ - in >> name >> tax; gobble(in); + in >> name >> tax; m->gobble(in); addSeqToTree(name, tax); @@ -252,15 +252,15 @@ void PhyloSummary::readTreeStruct(ifstream& in){ try { //read version - string line = getline(in); gobble(in); + string line = m->getline(in); m->gobble(in); int num; - in >> num; gobble(in); + in >> num; m->gobble(in); tree.resize(num); - in >> maxLevel; gobble(in); + in >> maxLevel; m->gobble(in); //read the tree file for (int i = 0; i < tree.size(); i++) { @@ -284,7 +284,7 @@ void PhyloSummary::readTreeStruct(ifstream& in){ tree[i].total = 0; - gobble(in); + m->gobble(in); //if (tree[i].level > maxLevel) { maxLevel = tree[i].level; } } diff --git a/phylotree.cpp b/phylotree.cpp index 2ea2193..1fd4e5d 100644 --- a/phylotree.cpp +++ b/phylotree.cpp @@ -55,24 +55,24 @@ PhyloTree::PhyloTree(ifstream& in, string filename){ delete buffer; //read version - getline(iss); gobble(iss); + m->getline(iss); m->gobble(iss); - iss >> numNodes; gobble(iss); + iss >> numNodes; m->gobble(iss); tree.resize(numNodes); for (int i = 0; i < tree.size(); i++) { - iss >> tree[i].name >> tree[i].level >> tree[i].parent; gobble(iss); + iss >> tree[i].name >> tree[i].level >> tree[i].parent; m->gobble(iss); } //read genus nodes int numGenus = 0; - iss >> numGenus; gobble(iss); + iss >> numGenus; m->gobble(iss); int gnode, gsize; totals.clear(); for (int i = 0; i < numGenus; i++) { - iss >> gnode >> gsize; gobble(iss); + iss >> gnode >> gsize; m->gobble(iss); uniqueTaxonomies[gnode] = gnode; totals.push_back(gsize); @@ -82,24 +82,24 @@ PhyloTree::PhyloTree(ifstream& in, string filename){ #else //read version - string line = getline(in); gobble(in); + string line = m->getline(in); m->gobble(in); - in >> numNodes; gobble(in); + in >> numNodes; m->gobble(in); tree.resize(numNodes); for (int i = 0; i < tree.size(); i++) { - in >> tree[i].name >> tree[i].level >> tree[i].parent; gobble(in); + in >> tree[i].name >> tree[i].level >> tree[i].parent; m->gobble(in); } //read genus nodes int numGenus = 0; - in >> numGenus; gobble(in); + in >> numGenus; m->gobble(in); int gnode, gsize; totals.clear(); for (int i = 0; i < numGenus; i++) { - in >> gnode >> gsize; gobble(in); + in >> gnode >> gsize; m->gobble(in); uniqueTaxonomies[gnode] = gnode; totals.push_back(gsize); @@ -144,7 +144,7 @@ PhyloTree::PhyloTree(string tfile){ MPI_File_open(MPI_COMM_WORLD, inFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI); //comm, filename, mode, info, filepointer if (pid == 0) { - positions = setFilePosEachLine(tfile, num); + positions = m->setFilePosEachLine(tfile, num); //send file positions to all processes for(int i = 1; i < processors; i++) { @@ -179,11 +179,11 @@ PhyloTree::PhyloTree(string tfile){ #else ifstream in; - openInputFile(tfile, in); + m->openInputFile(tfile, in); //read in users taxonomy file and add sequences to tree while(!in.eof()){ - in >> name >> tax; gobble(in); + in >> name >> tax; m->gobble(in); addSeqToTree(name, tax); } @@ -365,7 +365,7 @@ void PhyloTree::binUnclassified(string file){ try { ofstream out; - openOutputFile(file, out); + m->openOutputFile(file, out); map::iterator itBin; map::iterator childPointer; @@ -519,7 +519,7 @@ void PhyloTree::printTreeNodes(string treefilename) { #endif ofstream outTree; - openOutputFile(treefilename, outTree); + m->openOutputFile(treefilename, outTree); //output mothur version outTree << "#" << m->getVersion() << endl; diff --git a/phylotypecommand.cpp b/phylotypecommand.cpp index d04c960..c4f367a 100644 --- a/phylotypecommand.cpp +++ b/phylotypecommand.cpp @@ -46,7 +46,7 @@ PhylotypeCommand::PhylotypeCommand(string option) { it = parameters.find("taxonomy"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["taxonomy"] = inputDir + it->second; } } @@ -54,7 +54,7 @@ PhylotypeCommand::PhylotypeCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -75,7 +75,7 @@ PhylotypeCommand::PhylotypeCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(taxonomyFileName); //if user entered a file with a path then preserve it + outputDir += m->hasPath(taxonomyFileName); //if user entered a file with a path then preserve it } string temp = validParameter.validFile(parameters, "cutoff", false); @@ -85,7 +85,7 @@ PhylotypeCommand::PhylotypeCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; allLines = 1; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -152,17 +152,17 @@ int PhylotypeCommand::execute(){ if (m->control_pressed) { delete tree; return 0; } - string fileroot = outputDir + getRootName(getSimpleName(taxonomyFileName)); + string fileroot = outputDir + m->getRootName(m->getSimpleName(taxonomyFileName)); ofstream outList; string outputListFile = fileroot + "tx.list"; - openOutputFile(outputListFile, outList); + m->openOutputFile(outputListFile, outList); ofstream outSabund; string outputSabundFile = fileroot + "tx.sabund"; - openOutputFile(outputSabundFile, outSabund); + m->openOutputFile(outputSabundFile, outSabund); ofstream outRabund; string outputRabundFile = fileroot + "tx.rabund"; - openOutputFile(outputRabundFile, outRabund); + m->openOutputFile(outputRabundFile, outRabund); outputNames.push_back(outputListFile); outputNames.push_back(outputSabundFile); @@ -270,13 +270,13 @@ int PhylotypeCommand::readNamesFile() { try { ifstream in; - openInputFile(namefile, in); + m->openInputFile(namefile, in); string first, second; map::iterator itNames; while(!in.eof()) { - in >> first >> second; gobble(in); + in >> first >> second; m->gobble(in); itNames = namemap.find(first); if (itNames == namemap.end()) { diff --git a/pintail.cpp b/pintail.cpp index 8a159ca..4ad60c5 100644 --- a/pintail.cpp +++ b/pintail.cpp @@ -92,7 +92,7 @@ int Pintail::doPrep() { m->mothurOut("Getting conservation... "); cout.flush(); if (consfile == "") { m->mothurOut("Calculating probability of conservation for your template sequences. This can take a while... I will output the frequency of the highest base in each position to a .freq file so that you can input them using the conservation parameter next time you run this command. Providing the .freq file will improve speed. "); cout.flush(); - probabilityProfile = decalc->calcFreq(templateSeqs, outputDir + getSimpleName(templateFileName)); + probabilityProfile = decalc->calcFreq(templateSeqs, outputDir + m->getSimpleName(templateFileName)); if (m->control_pressed) { return 0; } m->mothurOut("Done."); m->mothurOutEndLine(); }else { probabilityProfile = readFreq(); m->mothurOut("Done."); } @@ -170,13 +170,13 @@ int Pintail::doPrep() { string noOutliers, outliers; if ((!filter) && (seqMask == "")) { - noOutliers = outputDir + getRootName(getSimpleName(templateFileName)) + "pintail.quan"; + noOutliers = outputDir + m->getRootName(m->getSimpleName(templateFileName)) + "pintail.quan"; }else if ((!filter) && (seqMask != "")) { - noOutliers = outputDir + getRootName(getSimpleName(templateFileName)) + "pintail.masked.quan"; + noOutliers = outputDir + m->getRootName(m->getSimpleName(templateFileName)) + "pintail.masked.quan"; }else if ((filter) && (seqMask != "")) { - noOutliers = outputDir + getRootName(getSimpleName(templateFileName)) + "pintail.filtered." + getSimpleName(getRootName(fastafile)) + "masked.quan"; + noOutliers = outputDir + m->getRootName(m->getSimpleName(templateFileName)) + "pintail.filtered." + m->getSimpleName(m->getRootName(fastafile)) + "masked.quan"; }else if ((filter) && (seqMask == "")) { - noOutliers = outputDir + getRootName(getSimpleName(templateFileName)) + "pintail.filtered." + getSimpleName(getRootName(fastafile)) + "quan"; + noOutliers = outputDir + m->getRootName(m->getSimpleName(templateFileName)) + "pintail.filtered." + m->getSimpleName(m->getRootName(fastafile)) + "quan"; } decalc->removeObviousOutliers(quantilesMembers, templateSeqs.size()); @@ -450,7 +450,7 @@ vector Pintail::readFreq() { istringstream iss (tempBuf,istringstream::in); //read version - string line = getline(iss); gobble(iss); + string line = m->getline(iss); m->gobble(iss); while(!iss.eof()) { iss >> pos >> num; @@ -466,7 +466,7 @@ vector Pintail::readFreq() { prob.push_back(Pi); } - gobble(iss); + m->gobble(iss); } MPI_File_close(&inMPI); @@ -474,10 +474,10 @@ vector Pintail::readFreq() { #else ifstream in; - openInputFile(consfile, in); + m->openInputFile(consfile, in); //read version - string line = getline(in); gobble(in); + string line = m->getline(in); m->gobble(in); while(!in.eof()){ @@ -494,7 +494,7 @@ vector Pintail::readFreq() { prob.push_back(Pi); } - gobble(in); + m->gobble(in); } in.close(); @@ -546,7 +546,7 @@ void Pintail::createProcessesQuan() { //write out data to file so parent can read it ofstream out; string s = toString(getpid()) + ".temp"; - openOutputFile(s, out); + m->openOutputFile(s, out); //output observed distances @@ -574,7 +574,7 @@ void Pintail::createProcessesQuan() { for (int i=0;iopenInputFile(s, in); vector< vector > quan; quan.resize(100); @@ -584,7 +584,7 @@ void Pintail::createProcessesQuan() { int num; in >> num; - gobble(in); + m->gobble(in); vector q; float w; for (int j = 0; j < num; j++) { @@ -593,7 +593,7 @@ void Pintail::createProcessesQuan() { } quan[h] = q; - gobble(in); + m->gobble(in); } @@ -655,7 +655,7 @@ vector< vector > Pintail::readQuantiles() { delete buffer; //read version - string line = getline(iss); gobble(iss); + string line = m->getline(iss); m->gobble(iss); while(!iss.eof()) { iss >> num >> ten >> twentyfive >> fifty >> seventyfive >> ninetyfive >> ninetynine; @@ -671,7 +671,7 @@ vector< vector > Pintail::readQuantiles() { quan.push_back(temp); - gobble(iss); + m->gobble(iss); } MPI_File_close(&inMPI); @@ -679,10 +679,10 @@ vector< vector > Pintail::readQuantiles() { #else ifstream in; - openInputFile(quanfile, in); + m->openInputFile(quanfile, in); //read version - string line = getline(in); gobble(in); + string line = m->getline(in); m->gobble(in); while(!in.eof()){ @@ -699,7 +699,7 @@ vector< vector > Pintail::readQuantiles() { quan.push_back(temp); - gobble(in); + m->gobble(in); } in.close(); #endif @@ -749,7 +749,7 @@ void Pintail::printQuanFile(string file, string outputString) { //delete FileName; #else ofstream outQuan; - openOutputFile(file, outQuan); + m->openOutputFile(file, outQuan); outQuan << outputString; diff --git a/preclustercommand.cpp b/preclustercommand.cpp index c5b66a8..0bd9132 100644 --- a/preclustercommand.cpp +++ b/preclustercommand.cpp @@ -44,7 +44,7 @@ PreClusterCommand::PreClusterCommand(string option) { it = parameters.find("fasta"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } @@ -52,7 +52,7 @@ PreClusterCommand::PreClusterCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -66,7 +66,7 @@ PreClusterCommand::PreClusterCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(fastafile); //if user entered a file with a path then preserve it + outputDir += m->hasPath(fastafile); //if user entered a file with a path then preserve it } //check for optional parameter and set defaults @@ -125,14 +125,14 @@ int PreClusterCommand::execute(){ if (numSeqs == 0) { m->mothurOut("Error reading fasta file...please correct."); m->mothurOutEndLine(); return 0; } if (diffs > length) { m->mothurOut("Error: diffs is greater than your sequence length."); m->mothurOutEndLine(); return 0; } - string fileroot = outputDir + getRootName(getSimpleName(fastafile)); - string newFastaFile = fileroot + "precluster" + getExtension(fastafile); + string fileroot = outputDir + m->getRootName(m->getSimpleName(fastafile)); + string newFastaFile = fileroot + "precluster" + m->getExtension(fastafile); string newNamesFile = fileroot + "precluster.names"; ofstream outFasta; ofstream outNames; - openOutputFile(newFastaFile, outFasta); - openOutputFile(newNamesFile, outNames); + m->openOutputFile(newFastaFile, outFasta); + m->openOutputFile(newNamesFile, outNames); //sort seqs by number of identical seqs alignSeqs.sort(comparePriority); @@ -215,8 +215,8 @@ int PreClusterCommand::readFASTA(){ //ifstream inNames; ifstream inFasta; - //openInputFile(namefile, inNames); - openInputFile(fastafile, inFasta); + //m->openInputFile(namefile, inNames); + m->openInputFile(fastafile, inFasta); //string firstCol, secondCol, nameString; length = 0; @@ -228,14 +228,14 @@ int PreClusterCommand::readFASTA(){ //inNames >> firstCol >> secondCol; //nameString = secondCol; - //gobble(inNames); + //m->gobble(inNames); //int size = 1; //while (secondCol.find_first_of(',') != -1) { // size++; // secondCol = secondCol.substr(secondCol.find_first_of(',')+1, secondCol.length()); //} - Sequence seq(inFasta); gobble(inFasta); + Sequence seq(inFasta); m->gobble(inFasta); if (seq.getName() != "") { //can get "" if commented line is at end of fasta file if (namefile != "") { @@ -302,11 +302,11 @@ void PreClusterCommand::printData(ofstream& outFasta, ofstream& outNames, seqPNo void PreClusterCommand::readNameFile(){ try { ifstream in; - openInputFile(namefile, in); + m->openInputFile(namefile, in); string firstCol, secondCol; while (!in.eof()) { - in >> firstCol >> secondCol; gobble(in); + in >> firstCol >> secondCol; m->gobble(in); names[firstCol] = secondCol; int size = 1; diff --git a/qualityscores.cpp b/qualityscores.cpp index fd9459c..fa78b69 100644 --- a/qualityscores.cpp +++ b/qualityscores.cpp @@ -35,18 +35,18 @@ QualityScores::QualityScores(ifstream& qFile, int l){ int score; //string line; - //getline(qFile, line); + //m->getline(qFile, line); //istringstream nameStream(line); qFile >> seqName; while (!qFile.eof()) { char c = qFile.get(); if (c == 10 || c == 13 || c == -1){ break; } } // get rest of line - gobble(qFile); + m->gobble(qFile); if (seqName == "") { m->mothurOut("Error reading quality file, name blank at position, " + toString(qFile.tellg())); m->mothurOutEndLine(); } else { seqName = seqName.substr(1); } - //getline(qFile, line); + //m->getline(qFile, line); //istringstream qualStream(line); //while(qualStream){ @@ -61,7 +61,7 @@ QualityScores::QualityScores(ifstream& qFile, int l){ qFile >> score; qScores.push_back(score); } - gobble(qFile); + m->gobble(qFile); } catch(exception& e) { diff --git a/rarecalc.h b/rarecalc.h index d30fa16..8a0fb72 100644 --- a/rarecalc.h +++ b/rarecalc.h @@ -17,7 +17,7 @@ class RareCalc { public: - RareCalc(RAbundVector* b) : bins(b), numSeqs(b->getNumSeqs()), maxRank(b->getMaxRank()), numBins(b->getNumBins()) { bMatrix = binomial(numSeqs+1); m = MothurOut::getInstance(); } + RareCalc(RAbundVector* b) : bins(b), numSeqs(b->getNumSeqs()), maxRank(b->getMaxRank()), numBins(b->getNumBins()) { m = MothurOut::getInstance(); bMatrix = m->binomial(numSeqs+1); } EstOutput getValues(int); string getName() { return "rarecalc"; } private: diff --git a/rarefactcommand.cpp b/rarefactcommand.cpp index bb9a4fd..73d09b1 100644 --- a/rarefactcommand.cpp +++ b/rarefactcommand.cpp @@ -56,7 +56,7 @@ RareFactCommand::RareFactCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it } //make sure the user has already run the read.otu command @@ -67,7 +67,7 @@ RareFactCommand::RareFactCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -82,7 +82,7 @@ RareFactCommand::RareFactCommand(string option) { else { if (calc == "default") { calc = "sobs"; } } - splitAtDash(calc, Estimators); + m->splitAtDash(calc, Estimators); string temp; temp = validParameter.validFile(parameters, "freq", false); if (temp == "not found") { temp = "100"; } @@ -144,7 +144,7 @@ int RareFactCommand::execute(){ for (int p = 0; p < inputFileNames.size(); p++) { - string fileNameRoot = outputDir + getRootName(getSimpleName(inputFileNames[p])); + string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])); globaldata->inputFileName = inputFileNames[p]; if (m->control_pressed) { if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } return 0; } @@ -243,7 +243,7 @@ int RareFactCommand::execute(){ userLabels.erase(order->getLabel()); } - if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = order->getLabel(); delete order; @@ -339,7 +339,7 @@ vector RareFactCommand::parseSharedFile(string filename) { input = globaldata->ginput; vector lookup = input->getSharedRAbundVectors(); - string sharedFileRoot = getRootName(filename); + string sharedFileRoot = m->getRootName(filename); //clears file before we start to write to it below for (int i=0; i RareFactCommand::parseSharedFile(string filename) { for (int i = 0; i < lookup.size(); i++) { RAbundVector rav = lookup[i]->getRAbundVector(); - openOutputFileAppend(sharedFileRoot + lookup[i]->getGroup() + ".rabund", *(filehandles[lookup[i]->getGroup()])); + m->openOutputFileAppend(sharedFileRoot + lookup[i]->getGroup() + ".rabund", *(filehandles[lookup[i]->getGroup()])); rav.print(*(filehandles[lookup[i]->getGroup()])); (*(filehandles[lookup[i]->getGroup()])).close(); } diff --git a/rarefactsharedcommand.cpp b/rarefactsharedcommand.cpp index 324f028..c0f5ec0 100644 --- a/rarefactsharedcommand.cpp +++ b/rarefactsharedcommand.cpp @@ -50,7 +50,7 @@ RareFactSharedCommand::RareFactSharedCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it } @@ -59,7 +59,7 @@ RareFactSharedCommand::RareFactSharedCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -74,12 +74,12 @@ RareFactSharedCommand::RareFactSharedCommand(string option) { else { if (calc == "default") { calc = "sharedobserved"; } } - splitAtDash(calc, Estimators); + m->splitAtDash(calc, Estimators); groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); } globaldata->Groups = Groups; @@ -91,13 +91,13 @@ RareFactSharedCommand::RareFactSharedCommand(string option) { convert(temp, nIters); temp = validParameter.validFile(parameters, "jumble", false); if (temp == "not found") { temp = "T"; } - if (isTrue(temp)) { jumble = true; } + if (m->isTrue(temp)) { jumble = true; } else { jumble = false; } globaldata->jumble = jumble; if (abort == false) { - string fileNameRoot = outputDir + getRootName(getSimpleName(globaldata->inputFileName)); + string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)); // format = globaldata->getFormat(); @@ -214,7 +214,7 @@ int RareFactSharedCommand::execute(){ userLabels.erase(lookup[0]->getLabel()); } - if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = lookup[0]->getLabel(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } diff --git a/readblast.cpp b/readblast.cpp index c3dfd48..1efaf5b 100644 --- a/readblast.cpp +++ b/readblast.cpp @@ -40,7 +40,7 @@ int ReadBlast::read(NameAssignment* nameMap) { if (m->control_pressed) { return 0; } ifstream fileHandle; - openInputFile(blastfile, fileHandle); + m->openInputFile(blastfile, fileHandle); string firstName, secondName, eScore, currentRow; string repeatName = ""; @@ -56,11 +56,11 @@ int ReadBlast::read(NameAssignment* nameMap) { if (!hclusterWanted) { matrix = new SparseMatrix(); }else{ - overlapFile = getRootName(blastfile) + "overlap.dist"; - distFile = getRootName(blastfile) + "hclusterDists.dist"; + overlapFile = m->getRootName(blastfile) + "overlap.dist"; + distFile = m->getRootName(blastfile) + "hclusterDists.dist"; - openOutputFile(overlapFile, outOverlap); - openOutputFile(distFile, outDist); + m->openOutputFile(overlapFile, outOverlap); + m->openOutputFile(distFile, outDist); } if (m->control_pressed) { @@ -79,7 +79,7 @@ int ReadBlast::read(NameAssignment* nameMap) { if (!fileHandle.eof()) { //read in line from file fileHandle >> firstName >> secondName >> percentId >> numBases >> mismatch >> gap >> startQuery >> endQuery >> startRef >> endRef >> eScore >> score; - gobble(fileHandle); + m->gobble(fileHandle); currentRow = firstName; lengthThisSeq = numBases; @@ -125,7 +125,7 @@ int ReadBlast::read(NameAssignment* nameMap) { //read in line from file fileHandle >> firstName >> secondName >> percentId >> numBases >> mismatch >> gap >> startQuery >> endQuery >> startRef >> endRef >> eScore >> score; //cout << firstName << '\t' << secondName << '\t' << percentId << '\t' << numBases << '\t' << mismatch << '\t' << gap << '\t' << startQuery << '\t' << endQuery << '\t' << startRef << '\t' << endRef << '\t' << eScore << '\t' << score << endl; - gobble(fileHandle); + m->gobble(fileHandle); string temp = firstName + secondName; //to check if this file has repeat lines, ie. is this a blast instead of a blscreen file @@ -311,16 +311,16 @@ int ReadBlast::readNames(NameAssignment* nameMap) { int num = 1; ifstream in; - openInputFile(blastfile, in); + m->openInputFile(blastfile, in); //ofstream outName; - //openOutputFile((blastfile + ".tempOutNames"), outName); + //m->openOutputFile((blastfile + ".tempOutNames"), outName); //read first line in >> prevName; for (int i = 0; i < 11; i++) { in >> hold; } - gobble(in); + m->gobble(in); //save name in nameMap nameMap->push_back(prevName); @@ -332,7 +332,7 @@ int ReadBlast::readNames(NameAssignment* nameMap) { in >> name; for (int i = 0; i < 11; i++) { in >> hold; } - gobble(in); + m->gobble(in); //is this a new name? if (name != prevName) { @@ -345,9 +345,9 @@ int ReadBlast::readNames(NameAssignment* nameMap) { in.close(); //write out names file - //string outNames = getRootName(blastfile) + "names"; + //string outNames = m->getRootName(blastfile) + "names"; //ofstream out; - //openOutputFile(outNames, out); + //m->openOutputFile(outNames, out); //nameMap->print(out); //out.close(); diff --git a/readcluster.cpp b/readcluster.cpp index af71cbc..205581c 100644 --- a/readcluster.cpp +++ b/readcluster.cpp @@ -31,7 +31,7 @@ int ReadCluster::read(NameAssignment* nameMap){ if (m->control_pressed) { return 0; } - if (sortWanted) { OutPutFile = sortFile(distFile, outputDir); } + if (sortWanted) { OutPutFile = m->sortFile(distFile, outputDir); } else { OutPutFile = distFile; } //for use by clusters splitMatrix to convert a phylip matrix to column return 0; @@ -54,8 +54,8 @@ int ReadCluster::convertPhylip2Column(NameAssignment* nameMap){ ofstream out; string tempFile = distFile + ".column.temp"; - openInputFile(distFile, in); gobble(in); - openOutputFile(tempFile, out); + m->openInputFile(distFile, in); m->gobble(in); + m->openOutputFile(tempFile, out); float distance; int square, nseqs; @@ -190,9 +190,9 @@ int ReadCluster::convertPhylip2Column(NameAssignment* nameMap){ ifstream in2; ofstream out2; - string outputFile = getRootName(distFile) + "column.dist"; - openInputFile(tempFile, in2); - openOutputFile(outputFile, out2); + string outputFile = m->getRootName(distFile) + "column.dist"; + m->openInputFile(tempFile, in2); + m->openOutputFile(outputFile, out2); int first, second; float dist; @@ -202,7 +202,7 @@ int ReadCluster::convertPhylip2Column(NameAssignment* nameMap){ in2 >> first >> second >> dist; out2 << rowToName[first] << '\t' << rowToName[second] << '\t' << dist << endl; - gobble(in2); + m->gobble(in2); } in2.close(); out2.close(); diff --git a/readcolumn.cpp b/readcolumn.cpp index f29f70b..2782bd0 100644 --- a/readcolumn.cpp +++ b/readcolumn.cpp @@ -14,7 +14,7 @@ ReadColumnMatrix::ReadColumnMatrix(string df) : distFile(df){ - successOpen = openInputFile(distFile, fileHandle); + successOpen = m->openInputFile(distFile, fileHandle); } @@ -91,7 +91,7 @@ int ReadColumnMatrix::read(NameAssignment* nameMap){ } reading->update(itA->second * nseqs); } - gobble(fileHandle); + m->gobble(fileHandle); } if(lt == 0){ // oops, it was square @@ -99,7 +99,7 @@ int ReadColumnMatrix::read(NameAssignment* nameMap){ fileHandle.close(); //let's start over D->clear(); //let's start over - openInputFile(distFile, fileHandle); //let's start over + m->openInputFile(distFile, fileHandle); //let's start over while(fileHandle){ fileHandle >> firstName >> secondName >> distance; @@ -125,7 +125,7 @@ int ReadColumnMatrix::read(NameAssignment* nameMap){ reading->update(itA->second * nseqs); } - gobble(fileHandle); + m->gobble(fileHandle); } } diff --git a/readdistcommand.cpp b/readdistcommand.cpp index 4ea630f..0445eec 100644 --- a/readdistcommand.cpp +++ b/readdistcommand.cpp @@ -46,7 +46,7 @@ ReadDistCommand::ReadDistCommand(string option) { it = parameters.find("phylip"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["phylip"] = inputDir + it->second; } } @@ -54,7 +54,7 @@ ReadDistCommand::ReadDistCommand(string option) { it = parameters.find("column"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["column"] = inputDir + it->second; } } @@ -62,7 +62,7 @@ ReadDistCommand::ReadDistCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -70,7 +70,7 @@ ReadDistCommand::ReadDistCommand(string option) { it = parameters.find("group"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["group"] = inputDir + it->second; } } @@ -123,7 +123,7 @@ ReadDistCommand::ReadDistCommand(string option) { convert(temp, precision); temp = validParameter.validFile(parameters, "sim", false); if (temp == "not found") { temp = "F"; } - sim = isTrue(temp); + sim = m->isTrue(temp); globaldata->sim = sim; temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found") { temp = "10"; } @@ -212,7 +212,7 @@ int ReadDistCommand::execute(){ if (format == "matrix") { ifstream in; - openInputFile(distFileName, in); + m->openInputFile(distFileName, in); matrix = new FullMatrix(in); //reads the matrix file in.close(); @@ -222,12 +222,12 @@ int ReadDistCommand::execute(){ if (matrix->getNumSeqs() < groupMap->getNumSeqs()) { m->mothurOut("Your distance file contains " + toString(matrix->getNumSeqs()) + " sequences, and your group file contains " + toString(groupMap->getNumSeqs()) + " sequences."); m->mothurOutEndLine(); //create new group file - if(outputDir == "") { outputDir += hasPath(groupfile); } + if(outputDir == "") { outputDir += m->hasPath(groupfile); } - string newGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "editted.groups"; + string newGroupFile = outputDir + m->getRootName(m->getSimpleName(groupfile)) + "editted.groups"; outputNames.push_back(newGroupFile); ofstream outGroups; - openOutputFile(newGroupFile, outGroups); + m->openOutputFile(newGroupFile, outGroups); for (int i = 0; i < matrix->getNumSeqs(); i++) { if (m->control_pressed) { delete groupMap; delete matrix; outGroups.close(); remove(newGroupFile.c_str()); return 0; } diff --git a/readotu.cpp b/readotu.cpp index 98a63f0..3952abc 100644 --- a/readotu.cpp +++ b/readotu.cpp @@ -13,7 +13,7 @@ ReadOTUFile::ReadOTUFile(string pf): philFile(pf){ m = MothurOut::getInstance(); - //openInputFile(philFile, fileHandle); + //m->openInputFile(philFile, fileHandle); } /***********************************************************************/ diff --git a/readotucommand.cpp b/readotucommand.cpp index 5b9cde8..efd7073 100644 --- a/readotucommand.cpp +++ b/readotucommand.cpp @@ -45,7 +45,7 @@ ReadOtuCommand::ReadOtuCommand(string option) { it = parameters.find("list"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["list"] = inputDir + it->second; } } @@ -53,7 +53,7 @@ ReadOtuCommand::ReadOtuCommand(string option) { it = parameters.find("order"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["order"] = inputDir + it->second; } } @@ -61,7 +61,7 @@ ReadOtuCommand::ReadOtuCommand(string option) { it = parameters.find("shared"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["shared"] = inputDir + it->second; } } @@ -69,7 +69,7 @@ ReadOtuCommand::ReadOtuCommand(string option) { it = parameters.find("group"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["group"] = inputDir + it->second; } } @@ -77,7 +77,7 @@ ReadOtuCommand::ReadOtuCommand(string option) { it = parameters.find("sabund"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["sabund"] = inputDir + it->second; } } @@ -85,7 +85,7 @@ ReadOtuCommand::ReadOtuCommand(string option) { it = parameters.find("rabund"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["rabund"] = inputDir + it->second; } } @@ -93,7 +93,7 @@ ReadOtuCommand::ReadOtuCommand(string option) { it = parameters.find("ordergroup"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["ordergroup"] = inputDir + it->second; } } @@ -101,7 +101,7 @@ ReadOtuCommand::ReadOtuCommand(string option) { it = parameters.find("relabund"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["relabund"] = inputDir + it->second; } } @@ -159,7 +159,7 @@ ReadOtuCommand::ReadOtuCommand(string option) { groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); globaldata->Groups = Groups; } @@ -176,7 +176,7 @@ ReadOtuCommand::ReadOtuCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } globaldata->labels = labels; } diff --git a/readphylip.cpp b/readphylip.cpp index f155456..130decc 100644 --- a/readphylip.cpp +++ b/readphylip.cpp @@ -14,7 +14,7 @@ ReadPhylipMatrix::ReadPhylipMatrix(string distFile){ - successOpen = openInputFile(distFile, fileHandle); + successOpen = m->openInputFile(distFile, fileHandle); } diff --git a/readtree.cpp b/readtree.cpp index 1dd77f9..f72d698 100644 --- a/readtree.cpp +++ b/readtree.cpp @@ -25,7 +25,7 @@ ReadTree::ReadTree() { int ReadTree::readSpecialChar(istream& f, char c, string name) { try { - gobble(f); + m->gobble(f); char d = f.get(); if(d == EOF){ @@ -37,7 +37,7 @@ int ReadTree::readSpecialChar(istream& f, char c, string name) { exit(1); } if(d == ')' && f.peek() == '\n'){ - gobble(f); + m->gobble(f); } return d; } @@ -51,7 +51,7 @@ int ReadTree::readSpecialChar(istream& f, char c, string name) { int ReadTree::readNodeChar(istream& f) { try { // while(isspace(d=f.get())) {;} - gobble(f); + m->gobble(f); char d = f.get(); if(d == EOF){ @@ -76,7 +76,7 @@ float ReadTree::readBranchLength(istream& f) { m->mothurOut("Error: Missing branch length in input tree.\n"); exit(1); } - gobble(f); + m->gobble(f); return b; } catch(exception& e) { @@ -125,7 +125,7 @@ int ReadNewickTree::read() { //save trees for later commands globaldata->gTree.push_back(T); - gobble(filehandle); + m->gobble(filehandle); } //if you are a nexus file }else if ((c = filehandle.peek()) == '#') { diff --git a/readtree.h b/readtree.h index 540f80c..0c36833 100644 --- a/readtree.h +++ b/readtree.h @@ -43,7 +43,7 @@ class ReadTree { class ReadNewickTree : public ReadTree { public: - ReadNewickTree(string file) : treeFile(file) { openInputFile(file, filehandle); readOk = 0; } + ReadNewickTree(string file) : treeFile(file) { m->openInputFile(file, filehandle); readOk = 0; } ~ReadNewickTree() {}; int read(); diff --git a/readtreecommand.cpp b/readtreecommand.cpp index 07aa5b3..deae495 100644 --- a/readtreecommand.cpp +++ b/readtreecommand.cpp @@ -44,7 +44,7 @@ ReadTreeCommand::ReadTreeCommand(string option) { it = parameters.find("tree"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["tree"] = inputDir + it->second; } } @@ -52,7 +52,7 @@ ReadTreeCommand::ReadTreeCommand(string option) { it = parameters.find("group"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["group"] = inputDir + it->second; } } @@ -60,7 +60,7 @@ ReadTreeCommand::ReadTreeCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -199,13 +199,13 @@ int ReadTreeCommand::readNamesFile() { globaldata->names.clear(); ifstream in; - openInputFile(namefile, in); + m->openInputFile(namefile, in); string first, second; map::iterator itNames; while(!in.eof()) { - in >> first >> second; gobble(in); + in >> first >> second; m->gobble(in); itNames = globaldata->names.find(first); if (itNames == globaldata->names.end()) { @@ -213,7 +213,7 @@ int ReadTreeCommand::readNamesFile() { //we need a list of names in your namefile to use above when removing extra seqs above so we don't remove them vector dupNames; - splitAtComma(second, dupNames); + m->splitAtComma(second, dupNames); for (int i = 0; i < dupNames.size(); i++) { nameMap[dupNames[i]] = dupNames[i]; } }else { m->mothurOut(first + " has already been seen in namefile, disregarding names file."); m->mothurOutEndLine(); in.close(); globaldata->names.clear(); return 1; } diff --git a/removeseqscommand.cpp b/removeseqscommand.cpp index afd9dd4..b77e69f 100644 --- a/removeseqscommand.cpp +++ b/removeseqscommand.cpp @@ -47,7 +47,7 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option) { it = parameters.find("alignreport"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["alignreport"] = inputDir + it->second; } } @@ -55,7 +55,7 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option) { it = parameters.find("fasta"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } @@ -63,7 +63,7 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option) { it = parameters.find("accnos"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["accnos"] = inputDir + it->second; } } @@ -71,7 +71,7 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option) { it = parameters.find("list"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["list"] = inputDir + it->second; } } @@ -79,7 +79,7 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -87,7 +87,7 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option) { it = parameters.find("group"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["group"] = inputDir + it->second; } } @@ -95,7 +95,7 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option) { it = parameters.find("taxonomy"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["taxonomy"] = inputDir + it->second; } } @@ -133,8 +133,12 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option) { string usedDups = "true"; - string temp = validParameter.validFile(parameters, "dups", false); if (temp == "not found") { temp = "false"; usedDups = ""; } - dups = isTrue(temp); + string temp = validParameter.validFile(parameters, "dups", false); + if (temp == "not found") { + if (namefile != "") { temp = "true"; } + else { temp = "false"; usedDups = ""; } + } + dups = m->isTrue(temp); if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "") && (taxfile == "")) { m->mothurOut("You must provide at least one of the following: fasta, name, group, taxonomy, alignreport or list."); m->mothurOutEndLine(); abort = true; } @@ -154,7 +158,7 @@ void RemoveSeqsCommand::help(){ m->mothurOut("The remove.seqs command reads an .accnos file and at least one of the following file types: fasta, name, group, list, taxonomy or alignreport file.\n"); m->mothurOut("It outputs a file containing the sequences NOT in the .accnos file.\n"); m->mothurOut("The remove.seqs command parameters are accnos, fasta, name, group, list, taxonomy, alignreport and dups. You must provide accnos and at least one of the file parameters.\n"); - m->mothurOut("The dups parameter allows you to remove the entire line from a name file if you remove any name from the line. default=false. \n"); + m->mothurOut("The dups parameter allows you to remove the entire line from a name file if you remove any name from the line. default=true. \n"); m->mothurOut("The remove.seqs command should be in the following format: remove.seqs(accnos=yourAccnos, fasta=yourFasta).\n"); m->mothurOut("Example remove.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\n"); m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); @@ -206,13 +210,13 @@ int RemoveSeqsCommand::execute(){ //********************************************************************************************************************** int RemoveSeqsCommand::readFasta(){ try { - if (outputDir == "") { outputDir += hasPath(fastafile); } - string outputFileName = outputDir + getRootName(getSimpleName(fastafile)) + "pick" + getExtension(fastafile); + if (outputDir == "") { outputDir += m->hasPath(fastafile); } + string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "pick" + m->getExtension(fastafile); ofstream out; - openOutputFile(outputFileName, out); + m->openOutputFile(outputFileName, out); ifstream in; - openInputFile(fastafile, in); + m->openInputFile(fastafile, in); string name; bool wroteSomething = false; @@ -231,7 +235,7 @@ int RemoveSeqsCommand::readFasta(){ currSeq.printSequence(out); } } - gobble(in); + m->gobble(in); } in.close(); out.close(); @@ -250,13 +254,13 @@ int RemoveSeqsCommand::readFasta(){ //********************************************************************************************************************** int RemoveSeqsCommand::readList(){ try { - if (outputDir == "") { outputDir += hasPath(listfile); } - string outputFileName = outputDir + getRootName(getSimpleName(listfile)) + "pick" + getExtension(listfile); + if (outputDir == "") { outputDir += m->hasPath(listfile); } + string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" + m->getExtension(listfile); ofstream out; - openOutputFile(outputFileName, out); + m->openOutputFile(outputFileName, out); ifstream in; - openInputFile(listfile, in); + m->openInputFile(listfile, in); bool wroteSomething = false; @@ -300,7 +304,7 @@ int RemoveSeqsCommand::readList(){ newList.print(out); } - gobble(in); + m->gobble(in); } in.close(); out.close(); @@ -319,14 +323,14 @@ int RemoveSeqsCommand::readList(){ //********************************************************************************************************************** int RemoveSeqsCommand::readName(){ try { - if (outputDir == "") { outputDir += hasPath(namefile); } - string outputFileName = outputDir + getRootName(getSimpleName(namefile)) + "pick" + getExtension(namefile); + if (outputDir == "") { outputDir += m->hasPath(namefile); } + string outputFileName = outputDir + m->getRootName(m->getSimpleName(namefile)) + "pick" + m->getExtension(namefile); ofstream out; - openOutputFile(outputFileName, out); + m->openOutputFile(outputFileName, out); ifstream in; - openInputFile(namefile, in); + m->openInputFile(namefile, in); string name, firstCol, secondCol; bool wroteSomething = false; @@ -343,7 +347,6 @@ int RemoveSeqsCommand::readName(){ name = secondCol.substr(0,secondCol.find_first_of(',')); secondCol = secondCol.substr(secondCol.find_first_of(',')+1, secondCol.length()); parsedNames.push_back(name); - } //get name after last , @@ -386,7 +389,7 @@ int RemoveSeqsCommand::readName(){ } } } - gobble(in); + m->gobble(in); } in.close(); out.close(); @@ -405,13 +408,13 @@ int RemoveSeqsCommand::readName(){ //********************************************************************************************************************** int RemoveSeqsCommand::readGroup(){ try { - if (outputDir == "") { outputDir += hasPath(groupfile); } - string outputFileName = outputDir + getRootName(getSimpleName(groupfile)) + "pick" + getExtension(groupfile); + if (outputDir == "") { outputDir += m->hasPath(groupfile); } + string outputFileName = outputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile); ofstream out; - openOutputFile(outputFileName, out); + m->openOutputFile(outputFileName, out); ifstream in; - openInputFile(groupfile, in); + m->openInputFile(groupfile, in); string name, group; bool wroteSomething = false; @@ -428,7 +431,7 @@ int RemoveSeqsCommand::readGroup(){ out << name << '\t' << group << endl; } - gobble(in); + m->gobble(in); } in.close(); out.close(); @@ -446,13 +449,13 @@ int RemoveSeqsCommand::readGroup(){ //********************************************************************************************************************** int RemoveSeqsCommand::readTax(){ try { - if (outputDir == "") { outputDir += hasPath(taxfile); } - string outputFileName = outputDir + getRootName(getSimpleName(taxfile)) + "pick" + getExtension(taxfile); + if (outputDir == "") { outputDir += m->hasPath(taxfile); } + string outputFileName = outputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile); ofstream out; - openOutputFile(outputFileName, out); + m->openOutputFile(outputFileName, out); ifstream in; - openInputFile(taxfile, in); + m->openInputFile(taxfile, in); string name, tax; bool wroteSomething = false; @@ -469,7 +472,7 @@ int RemoveSeqsCommand::readTax(){ out << name << '\t' << tax << endl; } - gobble(in); + m->gobble(in); } in.close(); out.close(); @@ -488,13 +491,13 @@ int RemoveSeqsCommand::readTax(){ //alignreport file has a column header line then all other lines contain 16 columns. we just want the first column since that contains the name int RemoveSeqsCommand::readAlign(){ try { - if (outputDir == "") { outputDir += hasPath(alignfile); } - string outputFileName = outputDir + getRootName(getSimpleName(alignfile)) + "pick.align.report"; + if (outputDir == "") { outputDir += m->hasPath(alignfile); } + string outputFileName = outputDir + m->getRootName(m->getSimpleName(alignfile)) + "pick.align.report"; ofstream out; - openOutputFile(outputFileName, out); + m->openOutputFile(outputFileName, out); ifstream in; - openInputFile(alignfile, in); + m->openInputFile(alignfile, in); string name, junk; bool wroteSomething = false; @@ -533,7 +536,7 @@ int RemoveSeqsCommand::readAlign(){ } } - gobble(in); + m->gobble(in); } in.close(); out.close(); @@ -554,7 +557,7 @@ void RemoveSeqsCommand::readAccnos(){ try { ifstream in; - openInputFile(accnosfile, in); + m->openInputFile(accnosfile, in); string name; while(!in.eof()){ @@ -562,7 +565,7 @@ void RemoveSeqsCommand::readAccnos(){ names.insert(name); - gobble(in); + m->gobble(in); } in.close(); diff --git a/reversecommand.cpp b/reversecommand.cpp index 114750e..296c954 100644 --- a/reversecommand.cpp +++ b/reversecommand.cpp @@ -44,7 +44,7 @@ ReverseSeqsCommand::ReverseSeqsCommand(string option) { it = parameters.find("fasta"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } @@ -58,7 +58,7 @@ ReverseSeqsCommand::ReverseSeqsCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(fasta); //if user entered a file with a path then preserve it + outputDir += m->hasPath(fasta); //if user entered a file with a path then preserve it } } @@ -96,16 +96,16 @@ int ReverseSeqsCommand::execute(){ if (abort == true) { return 0; } ifstream inFASTA; - openInputFile(fasta, inFASTA); + m->openInputFile(fasta, inFASTA); ofstream outFASTA; - string reverseFile = outputDir + getRootName(getSimpleName(fasta)) + "rc" + getExtension(fasta); - openOutputFile(reverseFile, outFASTA); + string reverseFile = outputDir + m->getRootName(m->getSimpleName(fasta)) + "rc" + m->getExtension(fasta); + m->openOutputFile(reverseFile, outFASTA); while(!inFASTA.eof()){ if (m->control_pressed) { inFASTA.close(); outFASTA.close(); remove(reverseFile.c_str()); return 0; } - Sequence currSeq(inFASTA); gobble(inFASTA); + Sequence currSeq(inFASTA); m->gobble(inFASTA); if (currSeq.getName() != "") { currSeq.reverseComplement(); currSeq.printSequence(outFASTA); diff --git a/screenseqscommand.cpp b/screenseqscommand.cpp index b02b751..d98a4cf 100644 --- a/screenseqscommand.cpp +++ b/screenseqscommand.cpp @@ -44,7 +44,7 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option) { it = parameters.find("fasta"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } @@ -52,7 +52,7 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option) { it = parameters.find("group"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["group"] = inputDir + it->second; } } @@ -60,7 +60,7 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -68,7 +68,7 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option) { it = parameters.find("alignreport"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["alignreport"] = inputDir + it->second; } } @@ -94,7 +94,7 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(fastafile); //if user entered a file with a path then preserve it + outputDir += m->hasPath(fastafile); //if user entered a file with a path then preserve it } //check for optional parameter and set defaults @@ -168,9 +168,8 @@ int ScreenSeqsCommand::execute(){ if (abort == true) { return 0; } - string goodSeqFile = outputDir + getRootName(getSimpleName(fastafile)) + "good" + getExtension(fastafile); - string badSeqFile = outputDir + getRootName(getSimpleName(fastafile)) + "bad" + getExtension(fastafile); - string badAccnosFile = outputDir + getRootName(getSimpleName(fastafile)) + "bad.accnos"; + string goodSeqFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "good" + m->getExtension(fastafile); + string badAccnosFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "bad.accnos"; int numFastaSeqs = 0; set badSeqNames; @@ -187,7 +186,6 @@ int ScreenSeqsCommand::execute(){ MPI_File inMPI; MPI_File outMPIGood; - MPI_File outMPIBad; MPI_File outMPIBadAccnos; int outMode=MPI_MODE_CREATE|MPI_MODE_WRONLY; @@ -196,9 +194,6 @@ int ScreenSeqsCommand::execute(){ char outGoodFilename[1024]; strcpy(outGoodFilename, goodSeqFile.c_str()); - char outBadFilename[1024]; - strcpy(outBadFilename, badSeqFile.c_str()); - char outBadAccnosFilename[1024]; strcpy(outBadAccnosFilename, badAccnosFile.c_str()); @@ -207,14 +202,13 @@ int ScreenSeqsCommand::execute(){ MPI_File_open(MPI_COMM_WORLD, inFileName, inMode, MPI_INFO_NULL, &inMPI); //comm, filename, mode, info, filepointer MPI_File_open(MPI_COMM_WORLD, outGoodFilename, outMode, MPI_INFO_NULL, &outMPIGood); - MPI_File_open(MPI_COMM_WORLD, outBadFilename, outMode, MPI_INFO_NULL, &outMPIBad); MPI_File_open(MPI_COMM_WORLD, outBadAccnosFilename, outMode, MPI_INFO_NULL, &outMPIBadAccnos); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPIGood); MPI_File_close(&outMPIBad); MPI_File_close(&outMPIBadAccnos); return 0; } + if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPIGood); MPI_File_close(&outMPIBadAccnos); return 0; } if (pid == 0) { //you are the root process - MPIPos = setFilePosFasta(fastafile, numFastaSeqs); //fills MPIPos, returns numSeqs + MPIPos = m->setFilePosFasta(fastafile, numFastaSeqs); //fills MPIPos, returns numSeqs //send file positions to all processes for(int i = 1; i < processors; i++) { @@ -228,9 +222,9 @@ int ScreenSeqsCommand::execute(){ if(pid == (processors - 1)){ numSeqsPerProcessor = numFastaSeqs - pid * numSeqsPerProcessor; } //align your part - driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPIGood, outMPIBad, outMPIBadAccnos, MPIPos, badSeqNames); + driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPIGood, outMPIBadAccnos, MPIPos, badSeqNames); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPIGood); MPI_File_close(&outMPIBadAccnos); MPI_File_close(&outMPIBad); return 0; } + if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPIGood); MPI_File_close(&outMPIBadAccnos); return 0; } for (int i = 1; i < processors; i++) { @@ -261,9 +255,9 @@ int ScreenSeqsCommand::execute(){ if(pid == (processors - 1)){ numSeqsPerProcessor = numFastaSeqs - pid * numSeqsPerProcessor; } //align your part - driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPIGood, outMPIBad, outMPIBadAccnos, MPIPos, badSeqNames); + driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPIGood, outMPIBadAccnos, MPIPos, badSeqNames); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPIGood); MPI_File_close(&outMPIBad); MPI_File_close(&outMPIBadAccnos); return 0; } + if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPIGood); MPI_File_close(&outMPIBadAccnos); return 0; } //send bad list int badSize = badSeqNames.size(); @@ -285,12 +279,11 @@ int ScreenSeqsCommand::execute(){ //close files MPI_File_close(&inMPI); MPI_File_close(&outMPIGood); - MPI_File_close(&outMPIBad); MPI_File_close(&outMPIBadAccnos); MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case #else - vector positions = divideFile(fastafile, processors); + vector positions = m->divideFile(fastafile, processors); for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(new linePair(positions[i], positions[(i+1)])); @@ -298,51 +291,47 @@ int ScreenSeqsCommand::execute(){ #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) if(processors == 1){ - numFastaSeqs = driver(lines[0], goodSeqFile, badSeqFile, badAccnosFile, fastafile, badSeqNames); + numFastaSeqs = driver(lines[0], goodSeqFile, badAccnosFile, fastafile, badSeqNames); - if (m->control_pressed) { remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; } + if (m->control_pressed) { remove(goodSeqFile.c_str()); return 0; } }else{ processIDS.resize(0); - numFastaSeqs = createProcesses(goodSeqFile, badSeqFile, badAccnosFile, fastafile, badSeqNames); + numFastaSeqs = createProcesses(goodSeqFile, badAccnosFile, fastafile, badSeqNames); rename((goodSeqFile + toString(processIDS[0]) + ".temp").c_str(), goodSeqFile.c_str()); - rename((badSeqFile + toString(processIDS[0]) + ".temp").c_str(), badSeqFile.c_str()); rename((badAccnosFile + toString(processIDS[0]) + ".temp").c_str(), badAccnosFile.c_str()); //append alignment and report files for(int i=1;iappendFiles((goodSeqFile + toString(processIDS[i]) + ".temp"), goodSeqFile); remove((goodSeqFile + toString(processIDS[i]) + ".temp").c_str()); - - appendFiles((badSeqFile + toString(processIDS[i]) + ".temp"), badSeqFile); - remove((badSeqFile + toString(processIDS[i]) + ".temp").c_str()); - - appendFiles((badAccnosFile + toString(processIDS[i]) + ".temp"), badAccnosFile); + + m->appendFiles((badAccnosFile + toString(processIDS[i]) + ".temp"), badAccnosFile); remove((badAccnosFile + toString(processIDS[i]) + ".temp").c_str()); } - if (m->control_pressed) { remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; } + if (m->control_pressed) { remove(goodSeqFile.c_str()); return 0; } //read badSeqs in because root process doesnt know what other "bad" seqs the children found ifstream inBad; - int ableToOpen = openInputFile(badAccnosFile, inBad, "no error"); + int ableToOpen = m->openInputFile(badAccnosFile, inBad, "no error"); if (ableToOpen == 0) { badSeqNames.clear(); string tempName; while (!inBad.eof()) { - inBad >> tempName; gobble(inBad); + inBad >> tempName; m->gobble(inBad); badSeqNames.insert(tempName); } inBad.close(); } } #else - numFastaSeqs = driver(lines[0], goodSeqFile, badSeqFile, badAccnosFile, fastafile, badSeqNames); + numFastaSeqs = driver(lines[0], goodSeqFile, badAccnosFile, fastafile, badSeqNames); - if (m->control_pressed) { remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; } + if (m->control_pressed) { remove(goodSeqFile.c_str()); return 0; } #endif @@ -376,24 +365,24 @@ int ScreenSeqsCommand::execute(){ badSeqNames.clear(); string tempName; while (!iss.eof()) { - iss >> tempName; gobble(iss); + iss >> tempName; m->gobble(iss); badSeqNames.insert(tempName); } #endif if(namefile != "" && groupfile != "") { screenNameGroupFile(badSeqNames); - if (m->control_pressed) { remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; } + if (m->control_pressed) { remove(goodSeqFile.c_str()); return 0; } }else if(namefile != "") { screenNameGroupFile(badSeqNames); - if (m->control_pressed) { remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; } + if (m->control_pressed) { remove(goodSeqFile.c_str()); return 0; } }else if(groupfile != "") { screenGroupFile(badSeqNames); } // this screens just the group - if (m->control_pressed) { remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; } + if (m->control_pressed) { remove(goodSeqFile.c_str()); return 0; } if(alignreport != "") { screenAlignReport(badSeqNames); } - if (m->control_pressed) { remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; } + if (m->control_pressed) { remove(goodSeqFile.c_str()); return 0; } #ifdef USE_MPI } @@ -402,7 +391,6 @@ int ScreenSeqsCommand::execute(){ m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); m->mothurOut(goodSeqFile); m->mothurOutEndLine(); - m->mothurOut(badSeqFile); m->mothurOutEndLine(); m->mothurOut(badAccnosFile); m->mothurOutEndLine(); for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } m->mothurOutEndLine(); @@ -424,28 +412,25 @@ int ScreenSeqsCommand::execute(){ int ScreenSeqsCommand::screenNameGroupFile(set badSeqNames){ try { ifstream inputNames; - openInputFile(namefile, inputNames); + m->openInputFile(namefile, inputNames); set badSeqGroups; string seqName, seqList, group; set::iterator it; - string goodNameFile = outputDir + getRootName(getSimpleName(namefile)) + "good" + getExtension(namefile); - string badNameFile = outputDir + getRootName(getSimpleName(namefile)) + "bad" + getExtension(namefile); - - outputNames.push_back(goodNameFile); outputNames.push_back(badNameFile); + string goodNameFile = outputDir + m->getRootName(m->getSimpleName(namefile)) + "good" + m->getExtension(namefile); + outputNames.push_back(goodNameFile); - ofstream goodNameOut; openOutputFile(goodNameFile, goodNameOut); - ofstream badNameOut; openOutputFile(badNameFile, badNameOut); + ofstream goodNameOut; m->openOutputFile(goodNameFile, goodNameOut); while(!inputNames.eof()){ - if (m->control_pressed) { goodNameOut.close(); badNameOut.close(); inputNames.close(); remove(goodNameFile.c_str()); remove(badNameFile.c_str()); return 0; } + if (m->control_pressed) { goodNameOut.close(); inputNames.close(); remove(goodNameFile.c_str()); return 0; } inputNames >> seqName >> seqList; it = badSeqNames.find(seqName); if(it != badSeqNames.end()){ badSeqNames.erase(it); - badNameOut << seqName << '\t' << seqList << endl; + if(namefile != ""){ int start = 0; for(int i=0;i badSeqNames){ else{ goodNameOut << seqName << '\t' << seqList << endl; } - gobble(inputNames); + m->gobble(inputNames); } inputNames.close(); goodNameOut.close(); - badNameOut.close(); //we were unable to remove some of the bad sequences if (badSeqNames.size() != 0) { @@ -477,18 +461,15 @@ int ScreenSeqsCommand::screenNameGroupFile(set badSeqNames){ if(groupfile != ""){ ifstream inputGroups; - openInputFile(groupfile, inputGroups); + m->openInputFile(groupfile, inputGroups); - string goodGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "good" + getExtension(groupfile); - string badGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "bad" + getExtension(groupfile); - - outputNames.push_back(goodGroupFile); outputNames.push_back(badGroupFile); + string goodGroupFile = outputDir + m->getRootName(m->getSimpleName(groupfile)) + "good" + m->getExtension(groupfile); + outputNames.push_back(goodGroupFile); - ofstream goodGroupOut; openOutputFile(goodGroupFile, goodGroupOut); - ofstream badGroupOut; openOutputFile(badGroupFile, badGroupOut); + ofstream goodGroupOut; m->openOutputFile(goodGroupFile, goodGroupOut); while(!inputGroups.eof()){ - if (m->control_pressed) { goodGroupOut.close(); badGroupOut.close(); inputGroups.close(); remove(goodNameFile.c_str()); remove(badNameFile.c_str()); remove(goodGroupFile.c_str()); remove(badGroupFile.c_str()); return 0; } + if (m->control_pressed) { goodGroupOut.close(); inputGroups.close(); remove(goodNameFile.c_str()); remove(goodGroupFile.c_str()); return 0; } inputGroups >> seqName >> group; @@ -496,21 +477,19 @@ int ScreenSeqsCommand::screenNameGroupFile(set badSeqNames){ if(it != badSeqGroups.end()){ badSeqGroups.erase(it); - badGroupOut << seqName << '\t' << group << endl; } else{ goodGroupOut << seqName << '\t' << group << endl; } - gobble(inputGroups); + m->gobble(inputGroups); } inputGroups.close(); goodGroupOut.close(); - badGroupOut.close(); //we were unable to remove some of the bad sequences if (badSeqGroups.size() != 0) { for (it = badSeqGroups.begin(); it != badSeqGroups.end(); it++) { - m->mothurOut("Your namefile does not include the sequence " + *it + " please correct."); + m->mothurOut("Your groupfile does not include the sequence " + *it + " please correct."); m->mothurOutEndLine(); } } @@ -530,35 +509,30 @@ int ScreenSeqsCommand::screenNameGroupFile(set badSeqNames){ int ScreenSeqsCommand::screenGroupFile(set badSeqNames){ try { ifstream inputGroups; - openInputFile(groupfile, inputGroups); + m->openInputFile(groupfile, inputGroups); string seqName, group; set::iterator it; - string goodGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "good" + getExtension(groupfile); - string badGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "bad" + getExtension(groupfile); - - outputNames.push_back(goodGroupFile); outputNames.push_back(badGroupFile); - - ofstream goodGroupOut; openOutputFile(goodGroupFile, goodGroupOut); - ofstream badGroupOut; openOutputFile(badGroupFile, badGroupOut); + string goodGroupFile = outputDir + m->getRootName(m->getSimpleName(groupfile)) + "good" + m->getExtension(groupfile); + outputNames.push_back(goodGroupFile); + ofstream goodGroupOut; m->openOutputFile(goodGroupFile, goodGroupOut); while(!inputGroups.eof()){ - if (m->control_pressed) { goodGroupOut.close(); badGroupOut.close(); inputGroups.close(); remove(goodGroupFile.c_str()); remove(badGroupFile.c_str()); return 0; } + if (m->control_pressed) { goodGroupOut.close(); inputGroups.close(); remove(goodGroupFile.c_str()); return 0; } inputGroups >> seqName >> group; it = badSeqNames.find(seqName); if(it != badSeqNames.end()){ badSeqNames.erase(it); - badGroupOut << seqName << '\t' << group << endl; } else{ goodGroupOut << seqName << '\t' << group << endl; } - gobble(inputGroups); + m->gobble(inputGroups); } - if (m->control_pressed) { goodGroupOut.close(); badGroupOut.close(); inputGroups.close(); remove(goodGroupFile.c_str()); remove(badGroupFile.c_str()); return 0; } + if (m->control_pressed) { goodGroupOut.close(); inputGroups.close(); remove(goodGroupFile.c_str()); return 0; } //we were unable to remove some of the bad sequences if (badSeqNames.size() != 0) { @@ -570,10 +544,8 @@ int ScreenSeqsCommand::screenGroupFile(set badSeqNames){ inputGroups.close(); goodGroupOut.close(); - badGroupOut.close(); - if (m->control_pressed) { remove(goodGroupFile.c_str()); remove(badGroupFile.c_str()); } - + if (m->control_pressed) { remove(goodGroupFile.c_str()); } return 0; @@ -589,27 +561,22 @@ int ScreenSeqsCommand::screenGroupFile(set badSeqNames){ int ScreenSeqsCommand::screenAlignReport(set badSeqNames){ try { ifstream inputAlignReport; - openInputFile(alignreport, inputAlignReport); + m->openInputFile(alignreport, inputAlignReport); string seqName, group; set::iterator it; - string goodAlignReportFile = outputDir + getRootName(getSimpleName(alignreport)) + "good" + getExtension(alignreport); - string badAlignReportFile = outputDir + getRootName(getSimpleName(alignreport)) + "bad" + getExtension(alignreport); - - outputNames.push_back(goodAlignReportFile); outputNames.push_back(badAlignReportFile); - - ofstream goodAlignReportOut; openOutputFile(goodAlignReportFile, goodAlignReportOut); - ofstream badAlignReportOut; openOutputFile(badAlignReportFile, badAlignReportOut); + string goodAlignReportFile = outputDir + m->getRootName(m->getSimpleName(alignreport)) + "good" + m->getExtension(alignreport); + outputNames.push_back(goodAlignReportFile); + ofstream goodAlignReportOut; m->openOutputFile(goodAlignReportFile, goodAlignReportOut); while (!inputAlignReport.eof()) { // need to copy header char c = inputAlignReport.get(); goodAlignReportOut << c; - badAlignReportOut << c; if (c == 10 || c == 13){ break; } } while(!inputAlignReport.eof()){ - if (m->control_pressed) { goodAlignReportOut.close(); badAlignReportOut.close(); inputAlignReport.close(); remove(goodAlignReportFile.c_str()); remove(badAlignReportFile.c_str()); return 0; } + if (m->control_pressed) { goodAlignReportOut.close(); inputAlignReport.close(); remove(goodAlignReportFile.c_str()); return 0; } inputAlignReport >> seqName; it = badSeqNames.find(seqName); @@ -622,29 +589,27 @@ int ScreenSeqsCommand::screenAlignReport(set badSeqNames){ if(it != badSeqNames.end()){ badSeqNames.erase(it); - badAlignReportOut << seqName << '\t' << line; } else{ goodAlignReportOut << seqName << '\t' << line; } - gobble(inputAlignReport); + m->gobble(inputAlignReport); } - if (m->control_pressed) { goodAlignReportOut.close(); badAlignReportOut.close(); inputAlignReport.close(); remove(goodAlignReportFile.c_str()); remove(badAlignReportFile.c_str()); return 0; } + if (m->control_pressed) { goodAlignReportOut.close(); inputAlignReport.close(); remove(goodAlignReportFile.c_str()); return 0; } //we were unable to remove some of the bad sequences if (badSeqNames.size() != 0) { for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) { - m->mothurOut("Your file does not include the sequence " + *it + " please correct."); + m->mothurOut("Your alignreport file does not include the sequence " + *it + " please correct."); m->mothurOutEndLine(); } } inputAlignReport.close(); goodAlignReportOut.close(); - badAlignReportOut.close(); - if (m->control_pressed) { remove(goodAlignReportFile.c_str()); remove(badAlignReportFile.c_str()); return 0; } + if (m->control_pressed) { remove(goodAlignReportFile.c_str()); return 0; } return 0; @@ -657,19 +622,16 @@ int ScreenSeqsCommand::screenAlignReport(set badSeqNames){ } //********************************************************************************************************************** -int ScreenSeqsCommand::driver(linePair* filePos, string goodFName, string badFName, string badAccnosFName, string filename, set& badSeqNames){ +int ScreenSeqsCommand::driver(linePair* filePos, string goodFName, string badAccnosFName, string filename, set& badSeqNames){ try { ofstream goodFile; - openOutputFile(goodFName, goodFile); - - ofstream badFile; - openOutputFile(badFName, badFile); + m->openOutputFile(goodFName, goodFile); ofstream badAccnosFile; - openOutputFile(badAccnosFName, badAccnosFile); + m->openOutputFile(badAccnosFName, badAccnosFile); ifstream inFASTA; - openInputFile(filename, inFASTA); + m->openInputFile(filename, inFASTA); inFASTA.seekg(filePos->start); @@ -680,7 +642,7 @@ int ScreenSeqsCommand::driver(linePair* filePos, string goodFName, string badFNa if (m->control_pressed) { return 0; } - Sequence currSeq(inFASTA); gobble(inFASTA); + Sequence currSeq(inFASTA); m->gobble(inFASTA); if (currSeq.getName() != "") { bool goodSeq = 1; // innocent until proven guilty if(goodSeq == 1 && startPos != -1 && startPos < currSeq.getStartPos()) { goodSeq = 0; } @@ -694,7 +656,6 @@ int ScreenSeqsCommand::driver(linePair* filePos, string goodFName, string badFNa currSeq.printSequence(goodFile); } else{ - currSeq.printSequence(badFile); badAccnosFile << currSeq.getName() << endl; badSeqNames.insert(currSeq.getName()); } @@ -713,7 +674,6 @@ int ScreenSeqsCommand::driver(linePair* filePos, string goodFName, string badFNa goodFile.close(); inFASTA.close(); - badFile.close(); badAccnosFile.close(); return count; @@ -725,11 +685,10 @@ int ScreenSeqsCommand::driver(linePair* filePos, string goodFName, string badFNa } //********************************************************************************************************************** #ifdef USE_MPI -int ScreenSeqsCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& goodFile, MPI_File& badFile, MPI_File& badAccnosFile, vector& MPIPos, set& badSeqNames){ +int ScreenSeqsCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& goodFile, MPI_File& badAccnosFile, vector& MPIPos, set& badSeqNames){ try { string outputString = ""; MPI_Status statusGood; - MPI_Status statusBad; MPI_Status statusBadAccnos; MPI_Status status; int pid; @@ -775,15 +734,6 @@ int ScreenSeqsCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& delete buf2; } else{ - outputString = ">" + currSeq.getName() + "\n" + currSeq.getAligned() + "\n"; - - //print bad seq to fasta - length = outputString.length(); - char* buf2 = new char[length]; - memcpy(buf2, outputString.c_str(), length); - - MPI_File_write_shared(badFile, buf2, length, MPI_CHAR, &statusBad); - delete buf2; badSeqNames.insert(currSeq.getName()); @@ -810,7 +760,7 @@ int ScreenSeqsCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& #endif /**************************************************************************************************/ -int ScreenSeqsCommand::createProcesses(string goodFileName, string badFileName, string badAccnos, string filename, set& badSeqNames) { +int ScreenSeqsCommand::createProcesses(string goodFileName, string badAccnos, string filename, set& badSeqNames) { try { #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) int process = 0; @@ -824,12 +774,12 @@ int ScreenSeqsCommand::createProcesses(string goodFileName, string badFileName, processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later process++; }else if (pid == 0){ - num = driver(lines[process], goodFileName + toString(getpid()) + ".temp", badFileName + toString(getpid()) + ".temp", badAccnos + toString(getpid()) + ".temp", filename, badSeqNames); + num = driver(lines[process], goodFileName + toString(getpid()) + ".temp", badAccnos + toString(getpid()) + ".temp", filename, badSeqNames); //pass numSeqs to parent ofstream out; string tempFile = filename + toString(getpid()) + ".num.temp"; - openOutputFile(tempFile, out); + m->openOutputFile(tempFile, out); out << num << endl; out.close(); @@ -846,7 +796,7 @@ int ScreenSeqsCommand::createProcesses(string goodFileName, string badFileName, for (int i = 0; i < processIDS.size(); i++) { ifstream in; string tempFile = filename + toString(processIDS[i]) + ".num.temp"; - openInputFile(tempFile, in); + m->openInputFile(tempFile, in); if (!in.eof()) { int tempNum = 0; in >> tempNum; num += tempNum; } in.close(); remove(tempFile.c_str()); } diff --git a/screenseqscommand.h b/screenseqscommand.h index 8f62ae4..2c31ba2 100644 --- a/screenseqscommand.h +++ b/screenseqscommand.h @@ -35,11 +35,11 @@ private: int screenGroupFile(set); int screenAlignReport(set); - int driver(linePair*, string, string, string, string, set&); - int createProcesses(string, string, string, string, set&); + int driver(linePair*, string, string, string, set&); + int createProcesses(string, string, string, set&); #ifdef USE_MPI - int driverMPI(int, int, MPI_File&, MPI_File&, MPI_File&, MPI_File&, vector&, set&); + int driverMPI(int, int, MPI_File&, MPI_File&, MPI_File&, vector&, set&); #endif bool abort; diff --git a/secondarystructurecommand.cpp b/secondarystructurecommand.cpp index dc40611..c08ee6a 100644 --- a/secondarystructurecommand.cpp +++ b/secondarystructurecommand.cpp @@ -44,7 +44,7 @@ AlignCheckCommand::AlignCheckCommand(string option) { it = parameters.find("fasta"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } @@ -52,7 +52,7 @@ AlignCheckCommand::AlignCheckCommand(string option) { it = parameters.find("map"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["map"] = inputDir + it->second; } } @@ -70,7 +70,7 @@ AlignCheckCommand::AlignCheckCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(fastafile); //if user entered a file with a path then preserve it + outputDir += m->hasPath(fastafile); //if user entered a file with a path then preserve it } } @@ -109,11 +109,11 @@ int AlignCheckCommand::execute(){ readMap(); ifstream in; - openInputFile(fastafile, in); + m->openInputFile(fastafile, in); ofstream out; - string outfile = outputDir + getRootName(getSimpleName(fastafile)) + "align.check"; - openOutputFile(outfile, out); + string outfile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "align.check"; + m->openOutputFile(outfile, out); out << "name" << '\t' << "pound" << '\t' << "dash" << '\t' << "plus" << '\t' << "equal" << '\t'; out << "loop" << '\t' << "tilde" << '\t' << "total" << endl; @@ -122,7 +122,7 @@ int AlignCheckCommand::execute(){ while(!in.eof()){ if (m->control_pressed) { in.close(); out.close(); remove(outfile.c_str()); return 0; } - Sequence seq(in); gobble(in); + Sequence seq(in); m->gobble(in); if (seq.getName() != "") { statData data = getStats(seq.getAligned()); @@ -158,13 +158,13 @@ void AlignCheckCommand::readMap(){ structMap.resize(1, 0); ifstream in; - openInputFile(mapfile, in); + m->openInputFile(mapfile, in); while(!in.eof()){ int position; in >> position; structMap.push_back(position); - gobble(in); + m->gobble(in); } in.close(); diff --git a/sensspeccommand.cpp b/sensspeccommand.cpp index e647bf2..8489bfe 100644 --- a/sensspeccommand.cpp +++ b/sensspeccommand.cpp @@ -46,7 +46,7 @@ SensSpecCommand::SensSpecCommand(string option) { it = parameters.find("list"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["list"] = inputDir + it->second; } } @@ -54,7 +54,7 @@ SensSpecCommand::SensSpecCommand(string option) { it = parameters.find("phylip"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["phylip"] = inputDir + it->second; } } @@ -62,7 +62,7 @@ SensSpecCommand::SensSpecCommand(string option) { it = parameters.find("column"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["column"] = inputDir + it->second; } } @@ -70,7 +70,7 @@ SensSpecCommand::SensSpecCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -94,15 +94,15 @@ SensSpecCommand::SensSpecCommand(string option) { outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(listFile); //if user entered a file with a path then preserve it + outputDir += m->hasPath(listFile); //if user entered a file with a path then preserve it } //check for optional parameter and set defaults // ...at some point should added some additional type checking... temp = validParameter.validFile(parameters, "hard", false); if (temp == "not found"){ hard = 0; } - else if(!isTrue(temp)) { hard = 0; } - else if(isTrue(temp)) { hard = 1; } + else if(!m->isTrue(temp)) { hard = 0; } + else if(m->isTrue(temp)) { hard = 1; } // temp = validParameter.validFile(parameters, "name", true); // if (temp == "not found") { nameFile = ""; } @@ -178,7 +178,7 @@ void SensSpecCommand::processPhylip(){ //probably need some checking to confirm that the names in the distance matrix are the same as those in the list file ifstream inputListFile; - openInputFile(listFile, inputListFile); + m->openInputFile(listFile, inputListFile); string origCutoff = ""; bool getCutoff = 0; @@ -210,13 +210,13 @@ void SensSpecCommand::processPhylip(){ } seqMap[seqName] = i; } - gobble(inputListFile); + m->gobble(inputListFile); int lNumSeqs = seqMap.size(); int pNumSeqs = 0; ifstream phylipFile; - openInputFile(distFile, phylipFile); + m->openInputFile(distFile, phylipFile); phylipFile >> pNumSeqs; if(pNumSeqs != lNumSeqs){ cout << "numSeq mismatch!" << endl; } @@ -278,7 +278,7 @@ void SensSpecCommand::processPhylip(){ void SensSpecCommand::processColumn(){ try{ ifstream inputListFile; - openInputFile(listFile, inputListFile); + m->openInputFile(listFile, inputListFile); string origCutoff = ""; bool getCutoff = 0; @@ -326,12 +326,12 @@ void SensSpecCommand::processColumn(){ } } } - gobble(inputListFile); + m->gobble(inputListFile); int numDists = (numSeqs * (numSeqs-1) / 2); ifstream columnFile; - openInputFile(distFile, columnFile); + m->openInputFile(distFile, columnFile); string seqNameA, seqNameB, seqPairString; double distance; @@ -377,7 +377,7 @@ void SensSpecCommand::processColumn(){ seqPairSet.erase(it); } - gobble(columnFile); + m->gobble(columnFile); } falsePositives += seqPairSet.size(); @@ -395,7 +395,7 @@ void SensSpecCommand::processColumn(){ void SensSpecCommand::setUpOutput(){ try{ ofstream sensSpecFile; - openOutputFile(sensSpecFileName, sensSpecFile); + m->openOutputFile(sensSpecFileName, sensSpecFile); sensSpecFile << "label\tcutoff\ttp\ttn\tfp\tfn\tsensitivity\tspecificity\tppv\tnpv\tfdr\taccuracy\tmcc\tf1score\n"; @@ -440,7 +440,7 @@ void SensSpecCommand::outputStatistics(string label, string cutoff){ if(nPrime == 0) { negativePredictiveValue = 0; matthewsCorrCoef = 0; } ofstream sensSpecFile; - openOutputFileAppend(sensSpecFileName, sensSpecFile); + m->openOutputFileAppend(sensSpecFileName, sensSpecFile); sensSpecFile << label << '\t' << cutoff << '\t'; sensSpecFile << truePositives << '\t' << trueNegatives << '\t' << falsePositives << '\t' << falseNegatives << '\t'; diff --git a/seqerrorcommand.cpp b/seqerrorcommand.cpp index 82af49e..f1b9cd8 100644 --- a/seqerrorcommand.cpp +++ b/seqerrorcommand.cpp @@ -48,7 +48,7 @@ SeqErrorCommand::SeqErrorCommand(string option) { it = parameters.find("query"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["query"] = inputDir + it->second; } } @@ -56,7 +56,7 @@ SeqErrorCommand::SeqErrorCommand(string option) { it = parameters.find("reference"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["reference"] = inputDir + it->second; } } @@ -64,7 +64,7 @@ SeqErrorCommand::SeqErrorCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -87,7 +87,7 @@ SeqErrorCommand::SeqErrorCommand(string option) { outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(queryFileName); //if user entered a file with a path then preserve it + outputDir += m->hasPath(queryFileName); //if user entered a file with a path then preserve it } //check for optional parameter and set defaults @@ -96,7 +96,7 @@ SeqErrorCommand::SeqErrorCommand(string option) { convert(temp, threshold); errorFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".errors"; - openOutputFile(errorFileName, errorFile); + m->openOutputFile(errorFileName, errorFile); printErrorHeader(); } } @@ -140,7 +140,7 @@ int SeqErrorCommand::execute(){ if(namesFileName != ""){ weights = getWeights(); } ifstream queryFile; - openInputFile(queryFileName, queryFile); + m->openInputFile(queryFileName, queryFile); int totalBases = 0; int totalMatches = 0; @@ -194,7 +194,7 @@ int SeqErrorCommand::execute(){ string errorCountFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".count"; ofstream errorCountFile; - openOutputFile(errorCountFileName, errorCountFile); + m->openOutputFile(errorCountFileName, errorCountFile); m->mothurOut("Overall error rate:\t" + toString((double)(totalBases - totalMatches) / (double)totalBases) + "\n\n"); m->mothurOut("Errors\tSequences\n"); @@ -220,7 +220,7 @@ void SeqErrorCommand::getReferences(){ try { ifstream referenceFile; - openInputFile(referenceFileName, referenceFile); + m->openInputFile(referenceFileName, referenceFile); while(referenceFile){ Sequence currentSeq(referenceFile); @@ -231,7 +231,7 @@ void SeqErrorCommand::getReferences(){ currentSeq.removeAmbigBases(); } referenceSeqs.push_back(currentSeq); - gobble(referenceFile); + m->gobble(referenceFile); } numRefs = referenceSeqs.size(); @@ -335,7 +335,7 @@ Compare SeqErrorCommand::getErrors(Sequence query, Sequence reference){ map SeqErrorCommand::getWeights(){ ifstream nameFile; - openInputFile(namesFileName, nameFile); + m->openInputFile(namesFileName, nameFile); string seqName; string redundantSeqs; @@ -343,8 +343,8 @@ map SeqErrorCommand::getWeights(){ while(nameFile){ nameFile >> seqName >> redundantSeqs; - nameCountMap[seqName] = getNumNames(redundantSeqs); - gobble(nameFile); + nameCountMap[seqName] = m->getNumNames(redundantSeqs); + m->gobble(nameFile); } return nameCountMap; } diff --git a/seqsummarycommand.cpp b/seqsummarycommand.cpp index 4077619..5dbcdec 100644 --- a/seqsummarycommand.cpp +++ b/seqsummarycommand.cpp @@ -43,7 +43,7 @@ SeqSummaryCommand::SeqSummaryCommand(string option) { it = parameters.find("fasta"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } @@ -57,7 +57,7 @@ SeqSummaryCommand::SeqSummaryCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(fastafile); //if user entered a file with a path then preserve it + outputDir += m->hasPath(fastafile); //if user entered a file with a path then preserve it } string temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; } @@ -98,7 +98,7 @@ int SeqSummaryCommand::execute(){ if (abort == true) { return 0; } - string summaryFile = outputDir + getSimpleName(fastafile) + ".summary"; + string summaryFile = outputDir + m->getSimpleName(fastafile) + ".summary"; int numSeqs = 0; @@ -143,7 +143,7 @@ int SeqSummaryCommand::execute(){ MPI_File_write_shared(outMPI, buf2, length, MPI_CHAR, &statusOut); delete buf2; - MPIPos = setFilePosFasta(fastafile, numSeqs); //fills MPIPos, returns numSeqs + MPIPos = m->setFilePosFasta(fastafile, numSeqs); //fills MPIPos, returns numSeqs for(int i = 1; i < processors; i++) { MPI_Send(&numSeqs, 1, MPI_INT, i, tag, MPI_COMM_WORLD); @@ -224,7 +224,7 @@ int SeqSummaryCommand::execute(){ MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case #else - vector positions = divideFile(fastafile, processors); + vector positions = m->divideFile(fastafile, processors); for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(new linePair(positions[i], positions[(i+1)])); @@ -239,7 +239,7 @@ int SeqSummaryCommand::execute(){ rename((summaryFile + toString(processIDS[0]) + ".temp").c_str(), summaryFile.c_str()); //append files for(int i=1;iappendFiles((summaryFile + toString(processIDS[i]) + ".temp"), summaryFile); remove((summaryFile + toString(processIDS[i]) + ".temp").c_str()); } } @@ -308,7 +308,7 @@ int SeqSummaryCommand::driverCreateSummary(vector& startPosition, vectoropenOutputFile(sumFile, outSummary); //print header if you are process 0 if (filePos->start == 0) { @@ -316,7 +316,7 @@ int SeqSummaryCommand::driverCreateSummary(vector& startPosition, vectoropenInputFile(filename, in); in.seekg(filePos->start); @@ -327,7 +327,7 @@ int SeqSummaryCommand::driverCreateSummary(vector& startPosition, vectorcontrol_pressed) { in.close(); outSummary.close(); return 1; } - Sequence current(in); gobble(in); + Sequence current(in); m->gobble(in); if (current.getName() != "") { startPosition.push_back(current.getStartPos()); @@ -437,7 +437,7 @@ int SeqSummaryCommand::createProcessesCreateSummary(vector& startPosition, //pass numSeqs to parent ofstream out; string tempFile = fastafile + toString(getpid()) + ".num.temp"; - openOutputFile(tempFile, out); + m->openOutputFile(tempFile, out); out << num << endl; for (int k = 0; k < startPosition.size(); k++) { out << startPosition[k] << '\t'; } out << endl; @@ -462,15 +462,15 @@ int SeqSummaryCommand::createProcessesCreateSummary(vector& startPosition, for (int i = 0; i < processIDS.size(); i++) { string tempFilename = fastafile + toString(processIDS[i]) + ".num.temp"; ifstream in; - openInputFile(tempFilename, in); + m->openInputFile(tempFilename, in); int temp, tempNum; - in >> tempNum; gobble(in); num += tempNum; - for (int k = 0; k < tempNum; k++) { in >> temp; startPosition.push_back(temp); } gobble(in); - for (int k = 0; k < tempNum; k++) { in >> temp; endPosition.push_back(temp); } gobble(in); - for (int k = 0; k < tempNum; k++) { in >> temp; seqLength.push_back(temp); } gobble(in); - for (int k = 0; k < tempNum; k++) { in >> temp; ambigBases.push_back(temp); } gobble(in); - for (int k = 0; k < tempNum; k++) { in >> temp; longHomoPolymer.push_back(temp); } gobble(in); + in >> tempNum; m->gobble(in); num += tempNum; + for (int k = 0; k < tempNum; k++) { in >> temp; startPosition.push_back(temp); } m->gobble(in); + for (int k = 0; k < tempNum; k++) { in >> temp; endPosition.push_back(temp); } m->gobble(in); + for (int k = 0; k < tempNum; k++) { in >> temp; seqLength.push_back(temp); } m->gobble(in); + for (int k = 0; k < tempNum; k++) { in >> temp; ambigBases.push_back(temp); } m->gobble(in); + for (int k = 0; k < tempNum; k++) { in >> temp; longHomoPolymer.push_back(temp); } m->gobble(in); in.close(); remove(tempFilename.c_str()); diff --git a/sequence.cpp b/sequence.cpp index 38e9b62..04f97a8 100644 --- a/sequence.cpp +++ b/sequence.cpp @@ -253,7 +253,7 @@ string Sequence::getCommentString(ifstream& fastaFile) { while(fastaFile){ letter=fastaFile.get(); if((letter == '\r') || (letter == '\n')){ - gobble(fastaFile); //in case its a \r\n situation + m->gobble(fastaFile); //in case its a \r\n situation break; } } @@ -302,7 +302,7 @@ string Sequence::getCommentString(istringstream& fastaFile) { while(fastaFile){ letter=fastaFile.get(); if((letter == '\r') || (letter == '\n')){ - gobble(fastaFile); //in case its a \r\n situation + m->gobble(fastaFile); //in case its a \r\n situation break; } } diff --git a/sequencedb.cpp b/sequencedb.cpp index 9ddb40f..585b3b3 100644 --- a/sequencedb.cpp +++ b/sequencedb.cpp @@ -39,7 +39,7 @@ SequenceDB::SequenceDB(ifstream& filehandle) { if (newSequence.getName() != "") { data.push_back(newSequence); } //takes care of white space - gobble(filehandle); + m->gobble(filehandle); } filehandle.close(); diff --git a/setdircommand.cpp b/setdircommand.cpp index 043c0ac..a9ae730 100644 --- a/setdircommand.cpp +++ b/setdircommand.cpp @@ -106,7 +106,7 @@ int SetDirectoryCommand::execute(){ #endif //test to make sure directory exists - output = getFullPathName(output); + output = m->getFullPathName(output); string outTemp = output + "temp"; ofstream out; out.open(outTemp.c_str(), ios::trunc); @@ -139,7 +139,7 @@ int SetDirectoryCommand::execute(){ #endif //test to make sure directory exists - input = getFullPathName(input); + input = m->getFullPathName(input); string inTemp = input + "temp"; ofstream in; in.open(inTemp.c_str(), ios::trunc); diff --git a/setlogfilecommand.cpp b/setlogfilecommand.cpp index 593664e..19f3ed1 100644 --- a/setlogfilecommand.cpp +++ b/setlogfilecommand.cpp @@ -36,7 +36,7 @@ SetLogFileCommand::SetLogFileCommand(string option) { if (name == "not found") { m->mothurOut("name is a required parameter for the set.logfile command."); abort = true; } string temp = validParameter.validFile(parameters, "append", false); if (temp == "not found") { temp = "F"; } - append = isTrue(temp); + append = m->isTrue(temp); } } catch(exception& e) { diff --git a/sffinfocommand.cpp b/sffinfocommand.cpp index 4e53f69..a691a40 100644 --- a/sffinfocommand.cpp +++ b/sffinfocommand.cpp @@ -43,25 +43,25 @@ SffInfoCommand::SffInfoCommand(string option) { sffFilename = validParameter.validFile(parameters, "sff", false); if (sffFilename == "not found") { m->mothurOut("sff is a required parameter for the sffinfo command."); m->mothurOutEndLine(); abort = true; } else { - splitAtDash(sffFilename, filenames); + m->splitAtDash(sffFilename, filenames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < filenames.size(); i++) { if (inputDir != "") { - string path = hasPath(filenames[i]); + string path = m->hasPath(filenames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { filenames[i] = inputDir + filenames[i]; } } ifstream in; - int ableToOpen = openInputFile(filenames[i], in, "noerror"); + int ableToOpen = m->openInputFile(filenames[i], in, "noerror"); //if you can't open it, try default location if (ableToOpen == 1) { if (m->getDefaultPath() != "") { //default path is set - string tryPath = m->getDefaultPath() + getSimpleName(filenames[i]); + string tryPath = m->getDefaultPath() + m->getSimpleName(filenames[i]); m->mothurOut("Unable to open " + filenames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = openInputFile(tryPath, in, "noerror"); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); filenames[i] = tryPath; } } @@ -83,25 +83,25 @@ SffInfoCommand::SffInfoCommand(string option) { if (accnosName == "not found") { accnosName = ""; } else { hasAccnos = true; - splitAtDash(accnosName, accnosFileNames); + m->splitAtDash(accnosName, accnosFileNames); //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < accnosFileNames.size(); i++) { if (inputDir != "") { - string path = hasPath(accnosFileNames[i]); + string path = m->hasPath(accnosFileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { accnosFileNames[i] = inputDir + accnosFileNames[i]; } } ifstream in; - int ableToOpen = openInputFile(accnosFileNames[i], in, "noerror"); + int ableToOpen = m->openInputFile(accnosFileNames[i], in, "noerror"); //if you can't open it, try default location if (ableToOpen == 1) { if (m->getDefaultPath() != "") { //default path is set - string tryPath = m->getDefaultPath() + getSimpleName(accnosFileNames[i]); + string tryPath = m->getDefaultPath() + m->getSimpleName(accnosFileNames[i]); m->mothurOut("Unable to open " + accnosFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = openInputFile(tryPath, in, "noerror"); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); accnosFileNames[i] = tryPath; } } @@ -124,19 +124,19 @@ SffInfoCommand::SffInfoCommand(string option) { } string temp = validParameter.validFile(parameters, "qfile", false); if (temp == "not found"){ temp = "T"; } - qual = isTrue(temp); + qual = m->isTrue(temp); temp = validParameter.validFile(parameters, "fasta", false); if (temp == "not found"){ temp = "T"; } - fasta = isTrue(temp); + fasta = m->isTrue(temp); temp = validParameter.validFile(parameters, "flow", false); if (temp == "not found"){ temp = "F"; } - flow = isTrue(temp); + flow = m->isTrue(temp); temp = validParameter.validFile(parameters, "trim", false); if (temp == "not found"){ temp = "T"; } - trim = isTrue(temp); + trim = m->isTrue(temp); temp = validParameter.validFile(parameters, "sfftxt", false); if (temp == "not found"){ temp = "F"; } - sfftxt = isTrue(temp); + sfftxt = m->isTrue(temp); } } catch(exception& e) { @@ -210,27 +210,27 @@ int SffInfoCommand::execute(){ int SffInfoCommand::extractSffInfo(string input, string accnos){ try { - if (outputDir == "") { outputDir += hasPath(input); } + if (outputDir == "") { outputDir += m->hasPath(input); } if (accnos != "") { readAccnosFile(accnos); } else { seqNames.clear(); } ofstream outSfftxt, outFasta, outQual, outFlow; string outFastaFileName, outQualFileName; - string sfftxtFileName = outputDir + getRootName(getSimpleName(input)) + "sff.txt"; - string outFlowFileName = outputDir + getRootName(getSimpleName(input)) + "flow"; + string sfftxtFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "sff.txt"; + string outFlowFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "flow"; if (trim) { - outFastaFileName = outputDir + getRootName(getSimpleName(input)) + "fasta"; - outQualFileName = outputDir + getRootName(getSimpleName(input)) + "qual"; + outFastaFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "fasta"; + outQualFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "qual"; }else{ - outFastaFileName = outputDir + getRootName(getSimpleName(input)) + "raw.fasta"; - outQualFileName = outputDir + getRootName(getSimpleName(input)) + "raw.qual"; + outFastaFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "raw.fasta"; + outQualFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "raw.qual"; } - if (sfftxt) { openOutputFile(sfftxtFileName, outSfftxt); outSfftxt.setf(ios::fixed, ios::floatfield); outSfftxt.setf(ios::showpoint); outputNames.push_back(sfftxtFileName); } - if (fasta) { openOutputFile(outFastaFileName, outFasta); outputNames.push_back(outFastaFileName); } - if (qual) { openOutputFile(outQualFileName, outQual); outputNames.push_back(outQualFileName); } - if (flow) { openOutputFile(outFlowFileName, outFlow); outputNames.push_back(outFlowFileName); } + if (sfftxt) { m->openOutputFile(sfftxtFileName, outSfftxt); outSfftxt.setf(ios::fixed, ios::floatfield); outSfftxt.setf(ios::showpoint); outputNames.push_back(sfftxtFileName); } + if (fasta) { m->openOutputFile(outFastaFileName, outFasta); outputNames.push_back(outFastaFileName); } + if (qual) { m->openOutputFile(outQualFileName, outQual); outputNames.push_back(outQualFileName); } + if (flow) { m->openOutputFile(outFlowFileName, outFlow); outputNames.push_back(outFlowFileName); } ifstream in; in.open(input.c_str(), ios::binary); @@ -671,11 +671,11 @@ int SffInfoCommand::readAccnosFile(string filename) { seqNames.clear(); ifstream in; - openInputFile(filename, in); + m->openInputFile(filename, in); string name; while(!in.eof()){ - in >> name; gobble(in); + in >> name; m->gobble(in); seqNames.insert(name); diff --git a/sharedcommand.cpp b/sharedcommand.cpp index 195996e..2c1b6af 100644 --- a/sharedcommand.cpp +++ b/sharedcommand.cpp @@ -21,12 +21,12 @@ SharedCommand::SharedCommand(string o) : outputDir(o) { //getting output filename filename = globaldata->inputFileName; - if (outputDir == "") { outputDir += hasPath(filename); } + if (outputDir == "") { outputDir += m->hasPath(filename); } - filename = outputDir + getRootName(getSimpleName(filename)); + filename = outputDir + m->getRootName(m->getSimpleName(filename)); filename = filename + "shared"; - openOutputFile(filename, out); + m->openOutputFile(filename, out); pickedGroups = false; groupMap = globaldata->gGroupmap; @@ -48,7 +48,7 @@ SharedCommand::SharedCommand(string o) : outputDir(o) { } //set fileroot - fileroot = outputDir + getRootName(getSimpleName(globaldata->getListFile())); + fileroot = outputDir + m->getRootName(m->getSimpleName(globaldata->getListFile())); //clears file before we start to write to it below for (int i=0; iGroups[i] + "."; } - string newGroupFile = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + groups + "groups"; + string newGroupFile = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + groups + "groups"; ofstream outGroups; - openOutputFile(newGroupFile, outGroups); + m->openOutputFile(newGroupFile, outGroups); vector names = groupMap->getNamesSeqs(); string groupName; @@ -172,7 +172,7 @@ int SharedCommand::execute(){ userLabels.erase(SharedList->getLabel()); } - if ((anyLabelsToProcess(SharedList->getLabel(), userLabels, errorOff) == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(SharedList->getLabel(), userLabels, errorOff) == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = SharedList->getLabel(); delete SharedList; @@ -292,7 +292,7 @@ void SharedCommand::printSharedData(vector thislookup) { thislookup[i]->print(out); RAbundVector rav = thislookup[i]->getRAbundVector(); - openOutputFileAppend(fileroot + thislookup[i]->getGroup() + ".rabund", *(filehandles[thislookup[i]->getGroup()])); + m->openOutputFileAppend(fileroot + thislookup[i]->getGroup() + ".rabund", *(filehandles[thislookup[i]->getGroup()])); rav.print(*(filehandles[thislookup[i]->getGroup()])); (*(filehandles[thislookup[i]->getGroup()])).close(); } @@ -315,7 +315,7 @@ void SharedCommand::printSharedData(vector thislookup) { (myIt->second)->print(out); RAbundVector rav = (myIt->second)->getRAbundVector(); - openOutputFileAppend(fileroot + (myIt->second)->getGroup() + ".rabund", *(filehandles[(myIt->second)->getGroup()])); + m->openOutputFileAppend(fileroot + (myIt->second)->getGroup() + ".rabund", *(filehandles[(myIt->second)->getGroup()])); rav.print(*(filehandles[(myIt->second)->getGroup()])); (*(filehandles[(myIt->second)->getGroup()])).close(); }else{ @@ -377,14 +377,14 @@ int SharedCommand::eliminateZeroOTUS(vector& thislookup) { int SharedCommand::createMisMatchFile() { try { ofstream outMisMatch; - string outputMisMatchName = outputDir + getRootName(getSimpleName(globaldata->inputFileName)); + string outputMisMatchName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)); //you have sequences in your list file that are not in your group file if (SharedList->getNumSeqs() > groupMap->getNumSeqs()) { outputMisMatchName += "missing.group"; m->mothurOut("For a list of names that are in your list file and not in your group file, please refer to " + outputMisMatchName + "."); m->mothurOutEndLine(); - openOutputFile(outputMisMatchName, outMisMatch); + m->openOutputFile(outputMisMatchName, outMisMatch); map listNames; map::iterator itList; @@ -458,7 +458,7 @@ int SharedCommand::createMisMatchFile() { map::iterator itMatch; - openOutputFile(outputMisMatchName, outMisMatch); + m->openOutputFile(outputMisMatchName, outMisMatch); //loop through names in seqNames and if they aren't in namesIn list output them for (int i = 0; i < seqNames.size(); i++) { @@ -496,11 +496,11 @@ int SharedCommand::readOrderFile() { order.clear(); ifstream in; - openInputFile(globaldata->getOrderGroupFile(), in); + m->openInputFile(globaldata->getOrderGroupFile(), in); string thisGroup; while(!in.eof()){ - in >> thisGroup; gobble(in); + in >> thisGroup; m->gobble(in); order.push_back(thisGroup); diff --git a/sharedlistvector.cpp b/sharedlistvector.cpp index cc3cd8d..4978031 100644 --- a/sharedlistvector.cpp +++ b/sharedlistvector.cpp @@ -52,9 +52,9 @@ SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numB /***********************************************************************/ void SharedListVector::set(int binNumber, string seqNames){ try { - int nNames_old = getNumNames(data[binNumber]); + int nNames_old = m->getNumNames(data[binNumber]); data[binNumber] = seqNames; - int nNames_new = getNumNames(seqNames); + int nNames_new = m->getNumNames(seqNames); if(nNames_old == 0) { numBins++; } if(nNames_new == 0) { numBins--; } @@ -79,7 +79,7 @@ string SharedListVector::get(int index){ void SharedListVector::push_back(string seqNames){ try { data.push_back(seqNames); - int nNames = getNumNames(seqNames); + int nNames = m->getNumNames(seqNames); numBins++; @@ -141,7 +141,7 @@ RAbundVector SharedListVector::getRAbundVector(){ RAbundVector rav; for(int i=0;igetNumNames(data[i]); rav.push_back(binSize); } @@ -171,7 +171,7 @@ SAbundVector SharedListVector::getSAbundVector(){ SAbundVector sav(maxRank+1); for(int i=0;igetNumNames(data[i]); sav.set(binSize, sav.get(binSize) + 1); } sav.set(0, 0); @@ -194,7 +194,7 @@ SharedOrderVector* SharedListVector::getSharedOrderVector(){ order->setLabel(label); for(int i=0;igetNumNames(get(i)); //find number of individual in given bin names = get(i); while (names.find_first_of(',') != -1) { name = names.substr(0,names.find_first_of(',')); @@ -275,7 +275,7 @@ vector SharedListVector::getSharedRAbundVector() { finder[globaldata->gGroupmap->namesOfGroups[i]] = temp; finder[globaldata->gGroupmap->namesOfGroups[i]]->setLabel(label); finder[globaldata->gGroupmap->namesOfGroups[i]]->setGroup(globaldata->gGroupmap->namesOfGroups[i]); - if (inVector(globaldata->gGroupmap->namesOfGroups[i], globaldata->Groups)) { //if this group is in user groups + if (m->inUsersGroups(globaldata->gGroupmap->namesOfGroups[i], globaldata->Groups)) { //if this group is in user groups lookup.push_back(finder[globaldata->gGroupmap->namesOfGroups[i]]); } } @@ -331,7 +331,7 @@ OrderVector SharedListVector::getOrderVector(map* orderMap = NULL){ OrderVector ov; for(int i=0;igetNumNames(data[i]); for(int j=0;jgobble(f); if (f.eof() != true) { f >> nextLabel; } @@ -81,7 +81,7 @@ SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() { //reads in a } } - gobble(f); + m->gobble(f); if (f.eof() != true) { f >> nextLabel; } diff --git a/sharedrabundvector.cpp b/sharedrabundvector.cpp index d135091..c15dfac 100644 --- a/sharedrabundvector.cpp +++ b/sharedrabundvector.cpp @@ -101,7 +101,7 @@ SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), } - gobble(f); + m->gobble(f); if (f.eof() != true) { f >> nextLabel; } @@ -128,7 +128,7 @@ SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), lookup[count]->push_back(inputData, groupN); //abundance, bin, group } - gobble(f); + m->gobble(f); if (f.eof() != true) { f >> nextLabel; } } diff --git a/splitabundcommand.cpp b/splitabundcommand.cpp index 924ed69..9679642 100644 --- a/splitabundcommand.cpp +++ b/splitabundcommand.cpp @@ -42,7 +42,7 @@ SplitAbundCommand::SplitAbundCommand(string option) { it = parameters.find("list"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["list"] = inputDir + it->second; } } @@ -50,7 +50,7 @@ SplitAbundCommand::SplitAbundCommand(string option) { it = parameters.find("group"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["group"] = inputDir + it->second; } } @@ -58,7 +58,7 @@ SplitAbundCommand::SplitAbundCommand(string option) { it = parameters.find("fasta"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } @@ -66,7 +66,7 @@ SplitAbundCommand::SplitAbundCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -109,7 +109,7 @@ SplitAbundCommand::SplitAbundCommand(string option) { if (groupfile != "") { Groups = groupMap->namesOfGroups; } else { m->mothurOut("You cannot select groups without a valid groupfile, I will disregard your groups selection. "); m->mothurOutEndLine(); groups = ""; } }else { - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); } if ((groupfile == "") && (groups != "")) { m->mothurOut("You cannot select groups without a valid groupfile, I will disregard your groups selection. "); m->mothurOutEndLine(); groups = ""; Groups.clear(); } @@ -122,12 +122,12 @@ SplitAbundCommand::SplitAbundCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; allLines = 1; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } string temp = validParameter.validFile(parameters, "accnos", false); if (temp == "not found") { temp = "F"; } - accnos = isTrue(temp); + accnos = m->isTrue(temp); temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found") { temp = "0"; } convert(temp, cutoff); @@ -176,10 +176,10 @@ int SplitAbundCommand::execute(){ if (abort == true) { return 0; } if (listfile != "") { //you are using a listfile to determine abundance - if (outputDir == "") { outputDir = hasPath(listfile); } + if (outputDir == "") { outputDir = m->hasPath(listfile); } //remove old files so you can append later.... - string fileroot = outputDir + getRootName(getSimpleName(listfile)); + string fileroot = outputDir + m->getRootName(m->getSimpleName(listfile)); if (Groups.size() == 0) { remove((fileroot + "rare.list").c_str()); remove((fileroot + "abund.list").c_str()); @@ -223,7 +223,7 @@ int SplitAbundCommand::execute(){ userLabels.erase(list->getLabel()); } - if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = list->getLabel(); delete list; @@ -280,7 +280,7 @@ int SplitAbundCommand::execute(){ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } }else { //you are using the namefile to determine abundance - if (outputDir == "") { outputDir = hasPath(namefile); } + if (outputDir == "") { outputDir = m->hasPath(namefile); } splitNames(); writeNames(); @@ -316,7 +316,7 @@ int SplitAbundCommand::splitList(ListVector* thisList) { string bin = thisList->get(i); vector names; - splitAtComma(bin, names); //parses bin into individual sequence names + m->splitAtComma(bin, names); //parses bin into individual sequence names int size = names.size(); if (size <= cutoff) { @@ -364,12 +364,12 @@ int SplitAbundCommand::writeList(ListVector* thisList) { ofstream aout; ofstream rout; - string rare = outputDir + getRootName(getSimpleName(listfile)) + "rare.list"; - openOutputFileAppend(rare, rout); + string rare = outputDir + m->getRootName(m->getSimpleName(listfile)) + "rare.list"; + m->openOutputFileAppend(rare, rout); outputNames.push_back(rare); - string abund = outputDir + getRootName(getSimpleName(listfile)) + "abund.list"; - openOutputFileAppend(abund, aout); + string abund = outputDir + m->getRootName(m->getSimpleName(listfile)) + "abund.list"; + m->openOutputFileAppend(abund, aout); outputNames.push_back(abund); if (rareNames.size() != 0) { rout << thisList->getLabel() << '\t' << numRareBins << '\t'; } @@ -380,7 +380,7 @@ int SplitAbundCommand::writeList(ListVector* thisList) { string bin = list->get(i); - int size = getNumNames(bin); + int size = m->getNumNames(bin); if (size <= cutoff) { rout << bin << '\t'; } else { aout << bin << '\t'; } @@ -393,7 +393,7 @@ int SplitAbundCommand::writeList(ListVector* thisList) { aout.close(); }else{ //parse names by abundance and group - string fileroot = outputDir + getRootName(getSimpleName(listfile)); + string fileroot = outputDir + m->getRootName(m->getSimpleName(listfile)); ofstream* temp; ofstream* temp2; //map wroteFile; @@ -406,8 +406,8 @@ int SplitAbundCommand::writeList(ListVector* thisList) { temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - openOutputFileAppend(fileroot + Groups[i] + ".rare.list", *(filehandles[Groups[i]+".rare"])); - openOutputFileAppend(fileroot + Groups[i] + ".abund.list", *(filehandles[Groups[i]+".abund"])); + m->openOutputFileAppend(fileroot + Groups[i] + ".rare.list", *(filehandles[Groups[i]+".rare"])); + m->openOutputFileAppend(fileroot + Groups[i] + ".abund.list", *(filehandles[Groups[i]+".abund"])); } map groupVector; @@ -426,7 +426,7 @@ int SplitAbundCommand::writeList(ListVector* thisList) { string bin = list->get(i); vector names; - splitAtComma(bin, names); //parses bin into individual sequence names + m->splitAtComma(bin, names); //parses bin into individual sequence names //parse bin into list of sequences in each group for (int j = 0; j < names.size(); j++) { @@ -439,7 +439,7 @@ int SplitAbundCommand::writeList(ListVector* thisList) { string group = groupMap->getGroup(names[j]); - if (inUsersGroups(group, Groups)) { //only add if this is in a group we want + if (m->inUsersGroups(group, Groups)) { //only add if this is in a group we want itGroup = groupBins.find(group+rareAbund); if(itGroup == groupBins.end()) { groupBins[group+rareAbund] = names[j]; //add first name @@ -483,17 +483,17 @@ int SplitAbundCommand::splitNames() { //namefile //open input file ifstream in; - openInputFile(namefile, in); + m->openInputFile(namefile, in); while (!in.eof()) { if (m->control_pressed) { break; } string firstCol, secondCol; - in >> firstCol >> secondCol; gobble(in); + in >> firstCol >> secondCol; m->gobble(in); nameMap[firstCol] = secondCol; - int size = getNumNames(secondCol); + int size = m->getNumNames(secondCol); if (size <= cutoff) { rareNames.insert(firstCol); @@ -516,13 +516,13 @@ int SplitAbundCommand::readNamesFile() { try { //open input file ifstream in; - openInputFile(namefile, in); + m->openInputFile(namefile, in); while (!in.eof()) { if (m->control_pressed) { break; } string firstCol, secondCol; - in >> firstCol >> secondCol; gobble(in); + in >> firstCol >> secondCol; m->gobble(in); nameMap[firstCol] = secondCol; } @@ -547,7 +547,7 @@ int SplitAbundCommand::createNameMap(ListVector* thisList) { string bin = thisList->get(i); vector names; - splitAtComma(bin, names); //parses bin into individual sequence names + m->splitAtComma(bin, names); //parses bin into individual sequence names for (int j = 0; j < names.size(); j++) { nameMap[names[j]] = names[j]; } }//end for @@ -570,12 +570,12 @@ int SplitAbundCommand::writeNames() { //namefile ofstream aout; ofstream rout; - string rare = outputDir + getRootName(getSimpleName(namefile)) + "rare.names"; - openOutputFile(rare, rout); + string rare = outputDir + m->getRootName(m->getSimpleName(namefile)) + "rare.names"; + m->openOutputFile(rare, rout); outputNames.push_back(rare); - string abund = outputDir + getRootName(getSimpleName(namefile)) + "abund.names"; - openOutputFile(abund, aout); + string abund = outputDir + m->getRootName(m->getSimpleName(namefile)) + "abund.names"; + m->openOutputFile(abund, aout); outputNames.push_back(abund); if (rareNames.size() != 0) { @@ -593,7 +593,7 @@ int SplitAbundCommand::writeNames() { //namefile aout.close(); }else{ //parse names by abundance and group - string fileroot = outputDir + getRootName(getSimpleName(namefile)); + string fileroot = outputDir + m->getRootName(m->getSimpleName(namefile)); ofstream* temp; ofstream* temp2; map filehandles; @@ -605,13 +605,13 @@ int SplitAbundCommand::writeNames() { //namefile temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - openOutputFile(fileroot + Groups[i] + ".rare.names", *(filehandles[Groups[i]+".rare"])); - openOutputFile(fileroot + Groups[i] + ".abund.names", *(filehandles[Groups[i]+".abund"])); + m->openOutputFile(fileroot + Groups[i] + ".rare.names", *(filehandles[Groups[i]+".rare"])); + m->openOutputFile(fileroot + Groups[i] + ".abund.names", *(filehandles[Groups[i]+".abund"])); } for (map::iterator itName = nameMap.begin(); itName != nameMap.end(); itName++) { vector names; - splitAtComma(itName->second, names); //parses bin into individual sequence names + m->splitAtComma(itName->second, names); //parses bin into individual sequence names string rareAbund; if (rareNames.count(itName->first) != 0) { //you are a rare name @@ -626,7 +626,7 @@ int SplitAbundCommand::writeNames() { //namefile string group = groupMap->getGroup(names[i]); - if (inUsersGroups(group, Groups)) { //only add if this is in a group we want + if (m->inUsersGroups(group, Groups)) { //only add if this is in a group we want itout = outputStrings.find(group+rareAbund); if (itout == outputStrings.end()) { outputStrings[group+rareAbund] = names[i] + '\t' + names[i]; @@ -667,8 +667,8 @@ int SplitAbundCommand::writeAccnos(string tag) { ofstream rout; - string rare = outputDir + getRootName(getSimpleName(inputFile)) + tag + "rare.accnos"; - openOutputFile(rare, rout); + string rare = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "rare.accnos"; + m->openOutputFile(rare, rout); outputNames.push_back(rare); for (set::iterator itRare = rareNames.begin(); itRare != rareNames.end(); itRare++) { @@ -676,8 +676,8 @@ int SplitAbundCommand::writeAccnos(string tag) { } rout.close(); - string abund = outputDir + getRootName(getSimpleName(inputFile)) + tag + "abund.accnos"; - openOutputFile(abund, aout); + string abund = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "abund.accnos"; + m->openOutputFile(abund, aout); outputNames.push_back(abund); for (set::iterator itAbund = abundNames.begin(); itAbund != abundNames.end(); itAbund++) { @@ -686,7 +686,7 @@ int SplitAbundCommand::writeAccnos(string tag) { aout.close(); }else{ //parse names by abundance and group - string fileroot = outputDir + getRootName(getSimpleName(inputFile)); + string fileroot = outputDir + m->getRootName(m->getSimpleName(inputFile)); ofstream* temp; ofstream* temp2; map filehandles; @@ -698,15 +698,15 @@ int SplitAbundCommand::writeAccnos(string tag) { temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - openOutputFile(fileroot + tag + Groups[i] + ".rare.accnos", *(filehandles[Groups[i]+".rare"])); - openOutputFile(fileroot + tag + Groups[i] + ".abund.accnos", *(filehandles[Groups[i]+".abund"])); + m->openOutputFile(fileroot + tag + Groups[i] + ".rare.accnos", *(filehandles[Groups[i]+".rare"])); + m->openOutputFile(fileroot + tag + Groups[i] + ".abund.accnos", *(filehandles[Groups[i]+".abund"])); } //write rare for (set::iterator itRare = rareNames.begin(); itRare != rareNames.end(); itRare++) { string group = groupMap->getGroup(*itRare); - if (inUsersGroups(group, Groups)) { //only add if this is in a group we want + if (m->inUsersGroups(group, Groups)) { //only add if this is in a group we want *(filehandles[group+".rare"]) << *itRare << endl; } } @@ -715,7 +715,7 @@ int SplitAbundCommand::writeAccnos(string tag) { for (set::iterator itAbund = abundNames.begin(); itAbund != abundNames.end(); itAbund++) { string group = groupMap->getGroup(*itAbund); - if (inUsersGroups(group, Groups)) { //only add if this is in a group we want + if (m->inUsersGroups(group, Groups)) { //only add if this is in a group we want *(filehandles[group+".abund"]) << *itAbund << endl; } } @@ -746,17 +746,17 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile ofstream aout; ofstream rout; - string rare = outputDir + getRootName(getSimpleName(groupfile)) + tag + "rare.groups"; - openOutputFile(rare, rout); + string rare = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "rare.groups"; + m->openOutputFile(rare, rout); outputNames.push_back(rare); - string abund = outputDir + getRootName(getSimpleName(groupfile)) + tag + "abund.groups"; - openOutputFile(abund, aout); + string abund = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "abund.groups"; + m->openOutputFile(abund, aout); outputNames.push_back(abund); for (map::iterator itName = nameMap.begin(); itName != nameMap.end(); itName++) { vector names; - splitAtComma(itName->second, names); //parses bin into individual sequence names + m->splitAtComma(itName->second, names); //parses bin into individual sequence names for (int i = 0; i < names.size(); i++) { @@ -778,7 +778,7 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile aout.close(); }else{ //parse names by abundance and group - string fileroot = outputDir + getRootName(getSimpleName(groupfile)); + string fileroot = outputDir + m->getRootName(m->getSimpleName(groupfile)); ofstream* temp; ofstream* temp2; map filehandles; @@ -790,13 +790,13 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - openOutputFile(fileroot + tag + Groups[i] + ".rare.groups", *(filehandles[Groups[i]+".rare"])); - openOutputFile(fileroot + tag + Groups[i] + ".abund.groups", *(filehandles[Groups[i]+".abund"])); + m->openOutputFile(fileroot + tag + Groups[i] + ".rare.groups", *(filehandles[Groups[i]+".rare"])); + m->openOutputFile(fileroot + tag + Groups[i] + ".abund.groups", *(filehandles[Groups[i]+".abund"])); } for (map::iterator itName = nameMap.begin(); itName != nameMap.end(); itName++) { vector names; - splitAtComma(itName->second, names); //parses bin into individual sequence names + m->splitAtComma(itName->second, names); //parses bin into individual sequence names string rareAbund; if (rareNames.count(itName->first) != 0) { //you are a rare name @@ -809,7 +809,7 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile string group = groupMap->getGroup(names[i]); - if (inUsersGroups(group, Groups)) { //only add if this is in a group we want + if (m->inUsersGroups(group, Groups)) { //only add if this is in a group we want *(filehandles[group+rareAbund]) << names[i] << '\t' << group << endl; } } @@ -840,22 +840,22 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile ofstream aout; ofstream rout; - string rare = outputDir + getRootName(getSimpleName(fastafile)) + tag + "rare.fasta"; - openOutputFile(rare, rout); + string rare = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "rare.fasta"; + m->openOutputFile(rare, rout); outputNames.push_back(rare); - string abund = outputDir + getRootName(getSimpleName(fastafile)) + tag + "abund.fasta"; - openOutputFile(abund, aout); + string abund = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "abund.fasta"; + m->openOutputFile(abund, aout); outputNames.push_back(abund); //open input file ifstream in; - openInputFile(fastafile, in); + m->openInputFile(fastafile, in); while (!in.eof()) { if (m->control_pressed) { break; } - Sequence seq(in); gobble(in); + Sequence seq(in); m->gobble(in); if (seq.getName() != "") { @@ -879,7 +879,7 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile aout.close(); }else{ //parse names by abundance and group - string fileroot = outputDir + getRootName(getSimpleName(fastafile)); + string fileroot = outputDir + m->getRootName(m->getSimpleName(fastafile)); ofstream* temp; ofstream* temp2; map filehandles; @@ -891,18 +891,18 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - openOutputFile(fileroot + tag + Groups[i] + ".rare.fasta", *(filehandles[Groups[i]+".rare"])); - openOutputFile(fileroot + tag + Groups[i] + ".abund.fasta", *(filehandles[Groups[i]+".abund"])); + m->openOutputFile(fileroot + tag + Groups[i] + ".rare.fasta", *(filehandles[Groups[i]+".rare"])); + m->openOutputFile(fileroot + tag + Groups[i] + ".abund.fasta", *(filehandles[Groups[i]+".abund"])); } //open input file ifstream in; - openInputFile(fastafile, in); + m->openInputFile(fastafile, in); while (!in.eof()) { if (m->control_pressed) { break; } - Sequence seq(in); gobble(in); + Sequence seq(in); m->gobble(in); if (seq.getName() != "") { map::iterator itNames = nameMap.find(seq.getName()); @@ -911,7 +911,7 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile m->mothurOut(seq.getName() + " is not in your namesfile, ignoring."); m->mothurOutEndLine(); }else{ vector names; - splitAtComma(itNames->second, names); //parses bin into individual sequence names + m->splitAtComma(itNames->second, names); //parses bin into individual sequence names string rareAbund; if (rareNames.count(itNames->first) != 0) { //you are a rare name @@ -924,7 +924,7 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile string group = groupMap->getGroup(seq.getName()); - if (inUsersGroups(group, Groups)) { //only add if this is in a group we want + if (m->inUsersGroups(group, Groups)) { //only add if this is in a group we want seq.printSequence(*(filehandles[group+rareAbund])); }else if(group == "not found") { m->mothurOut(seq.getName() + " is not in your groupfile. Ignoring."); m->mothurOutEndLine(); diff --git a/splitmatrix.cpp b/splitmatrix.cpp index 6e40e97..a4e1f98 100644 --- a/splitmatrix.cpp +++ b/splitmatrix.cpp @@ -87,12 +87,12 @@ int SplitMatrix::splitClassify(){ PhyloTree* phylo = new PhyloTree(); ifstream in; - openInputFile(taxFile, in); + m->openInputFile(taxFile, in); //read in users taxonomy file and add sequences to tree string seqname, tax; while(!in.eof()){ - in >> seqname >> tax; gobble(in); + in >> seqname >> tax; m->gobble(in); phylo->addSeqToTree(seqname, tax); } in.close(); @@ -146,12 +146,12 @@ int SplitMatrix::createDistanceFilesFromTax(map& seqGroup, int numG } ifstream in; - openInputFile(fastafile, in); + m->openInputFile(fastafile, in); //parse fastafile ofstream outFile; while (!in.eof()) { - Sequence query(in); gobble(in); + Sequence query(in); m->gobble(in); if (query.getName() != "") { it = seqGroup.find(query.getName()); @@ -160,7 +160,7 @@ int SplitMatrix::createDistanceFilesFromTax(map& seqGroup, int numG if (namefile == "") { names.insert(query.getName()); } if (it != seqGroup.end()) { //not singleton - openOutputFileAppend((fastafile + "." + toString(it->second) + ".temp"), outFile); + m->openOutputFileAppend((fastafile + "." + toString(it->second) + ".temp"), outFile); query.printSequence(outFile); outFile.close(); @@ -195,22 +195,22 @@ int SplitMatrix::createDistanceFilesFromTax(map& seqGroup, int numG singleton = namefile + ".extra.temp"; ofstream remainingNames; - openOutputFile(singleton, remainingNames); + m->openOutputFile(singleton, remainingNames); bool wroteExtra = false; ifstream bigNameFile; - openInputFile(namefile, bigNameFile); + m->openInputFile(namefile, bigNameFile); string name, nameList; while(!bigNameFile.eof()){ - bigNameFile >> name >> nameList; gobble(bigNameFile); + bigNameFile >> name >> nameList; m->gobble(bigNameFile); //did this sequence get assigned a group it = seqGroup.find(name); if (it != seqGroup.end()) { - openOutputFileAppend((namefile + "." + toString(it->second) + ".temp"), outFile); + m->openOutputFileAppend((namefile + "." + toString(it->second) + ".temp"), outFile); outFile << name << '\t' << nameList << endl; outFile.close(); }else{ @@ -222,23 +222,23 @@ int SplitMatrix::createDistanceFilesFromTax(map& seqGroup, int numG for(int i=0;igetRootName(m->getSimpleName((fastafile + "." + toString(i) + ".temp"))) + "dist"; //if there are valid distances ifstream fileHandle; fileHandle.open(tempDistFile.c_str()); if(fileHandle) { - gobble(fileHandle); + m->gobble(fileHandle); if (!fileHandle.eof()) { //check for blank file - this could occur if all dists in group are above cutoff map temp; temp[tempDistFile] = tempNameFile; dists.push_back(temp); }else { ifstream in; - openInputFile(tempNameFile, in); + m->openInputFile(tempNameFile, in); while(!in.eof()) { - in >> name >> nameList; gobble(in); + in >> name >> nameList; m->gobble(in); wroteExtra = true; remainingNames << name << '\t' << nameList << endl; } @@ -271,7 +271,7 @@ int SplitMatrix::splitDistanceFileByTax(map& seqGroup, int numGroup map::iterator it2; ifstream dFile; - openInputFile(distFile, dFile); + m->openInputFile(distFile, dFile); ofstream outFile; for (int i = 0; i < numGroups; i++) { //remove old temp files, just in case @@ -294,7 +294,7 @@ int SplitMatrix::splitDistanceFileByTax(map& seqGroup, int numGroup if (m->control_pressed) { dFile.close(); for (int i = 0; i < numGroups; i++) { remove((distFile + "." + toString(i) + ".temp").c_str()); } } - dFile >> seqA >> seqB >> dist; gobble(dFile); + dFile >> seqA >> seqB >> dist; m->gobble(dFile); //if both sequences are in the same group then they are within the cutoff it = seqGroup.find(seqA); @@ -303,7 +303,7 @@ int SplitMatrix::splitDistanceFileByTax(map& seqGroup, int numGroup if ((it != seqGroup.end()) && (it2 != seqGroup.end())) { //they are both not singletons if (it->second == it2->second) { //they are from the same group so add the distance if (numOutputs[it->second] > 30) { - openOutputFileAppend((distFile + "." + toString(it->second) + ".temp"), outFile); + m->openOutputFileAppend((distFile + "." + toString(it->second) + ".temp"), outFile); outFile << outputs[it->second] << seqA << '\t' << seqB << '\t' << dist << endl; outFile.close(); outputs[it->second] = ""; @@ -323,7 +323,7 @@ int SplitMatrix::splitDistanceFileByTax(map& seqGroup, int numGroup //write out any remaining buffers if (numOutputs[i] > 0) { - openOutputFileAppend((distFile + "." + toString(i) + ".temp"), outFile); + m->openOutputFileAppend((distFile + "." + toString(i) + ".temp"), outFile); outFile << outputs[i]; outFile.close(); outputs[i] = ""; @@ -333,23 +333,23 @@ int SplitMatrix::splitDistanceFileByTax(map& seqGroup, int numGroup } ifstream bigNameFile; - openInputFile(namefile, bigNameFile); + m->openInputFile(namefile, bigNameFile); singleton = namefile + ".extra.temp"; ofstream remainingNames; - openOutputFile(singleton, remainingNames); + m->openOutputFile(singleton, remainingNames); bool wroteExtra = false; string name, nameList; while(!bigNameFile.eof()){ - bigNameFile >> name >> nameList; gobble(bigNameFile); + bigNameFile >> name >> nameList; m->gobble(bigNameFile); //did this sequence get assigned a group it = seqGroup.find(name); if (it != seqGroup.end()) { - openOutputFileAppend((namefile + "." + toString(it->second) + ".temp"), outFile); + m->openOutputFileAppend((namefile + "." + toString(it->second) + ".temp"), outFile); outFile << name << '\t' << nameList << endl; outFile.close(); }else{ @@ -370,10 +370,10 @@ int SplitMatrix::splitDistanceFileByTax(map& seqGroup, int numGroup dists.push_back(temp); }else{ ifstream in; - openInputFile(tempNameFile, in); + m->openInputFile(tempNameFile, in); while(!in.eof()) { - in >> name >> nameList; gobble(in); + in >> name >> nameList; m->gobble(in); wroteExtra = true; remainingNames << name << '\t' << nameList << endl; } @@ -419,7 +419,7 @@ int SplitMatrix::splitDistanceLarge(){ ofstream outFile; ifstream dFile; - openInputFile(distFile, dFile); + m->openInputFile(distFile, dFile); while(dFile){ string seqA, seqB; @@ -633,7 +633,7 @@ int SplitMatrix::splitDistanceLarge(){ } } } - gobble(dFile); + m->gobble(dFile); } dFile.close(); @@ -671,7 +671,7 @@ int SplitMatrix::splitNames(vector >& groups){ while(bigNameFile){ bigNameFile >> name >> nameList; nameMap[name] = nameList; - gobble(bigNameFile); + m->gobble(bigNameFile); } bigNameFile.close(); @@ -740,7 +740,7 @@ int SplitMatrix::splitDistanceRAM(){ int numGroups = 0; ifstream dFile; - openInputFile(distFile, dFile); + m->openInputFile(distFile, dFile); while(dFile){ string seqA, seqB; @@ -823,7 +823,7 @@ int SplitMatrix::splitDistanceRAM(){ } } } - gobble(dFile); + m->gobble(dFile); } dFile.close(); diff --git a/summarycommand.cpp b/summarycommand.cpp index 087e63f..70470b0 100644 --- a/summarycommand.cpp +++ b/summarycommand.cpp @@ -68,7 +68,7 @@ SummaryCommand::SummaryCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it } //check for optional parameter and set defaults @@ -76,7 +76,7 @@ SummaryCommand::SummaryCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -91,7 +91,7 @@ SummaryCommand::SummaryCommand(string option) { else { if (calc == "default") { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson"; } } - splitAtDash(calc, Estimators); + m->splitAtDash(calc, Estimators); string temp; temp = validParameter.validFile(parameters, "abund", false); if (temp == "not found") { temp = "10"; } @@ -101,7 +101,7 @@ SummaryCommand::SummaryCommand(string option) { convert(temp, size); temp = validParameter.validFile(parameters, "groupmode", false); if (temp == "not found") { temp = "F"; } - groupMode = isTrue(temp); + groupMode = m->isTrue(temp); } @@ -160,7 +160,7 @@ int SummaryCommand::execute(){ numLines = 0; numCols = 0; - string fileNameRoot = outputDir + getRootName(getSimpleName(inputFileNames[p])) + "summary"; + string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + "summary"; globaldata->inputFileName = inputFileNames[p]; outputNames.push_back(fileNameRoot); @@ -234,7 +234,7 @@ int SummaryCommand::execute(){ if (sumCalculators.size() == 0) { if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } return 0; } ofstream outputFileHandle; - openOutputFile(fileNameRoot, outputFileHandle); + m->openOutputFile(fileNameRoot, outputFileHandle); outputFileHandle << "label"; read = new ReadOTUFile(globaldata->inputFileName); @@ -285,7 +285,7 @@ int SummaryCommand::execute(){ numLines++; } - if ((anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = sabund->getLabel(); delete sabund; @@ -401,7 +401,7 @@ vector SummaryCommand::parseSharedFile(string filename) { input = globaldata->ginput; vector lookup = input->getSharedRAbundVectors(); - string sharedFileRoot = getRootName(filename); + string sharedFileRoot = m->getRootName(filename); //clears file before we start to write to it below for (int i=0; i SummaryCommand::parseSharedFile(string filename) { for (int i = 0; i < lookup.size(); i++) { RAbundVector rav = lookup[i]->getRAbundVector(); - openOutputFileAppend(sharedFileRoot + lookup[i]->getGroup() + ".rabund", *(filehandles[lookup[i]->getGroup()])); + m->openOutputFileAppend(sharedFileRoot + lookup[i]->getGroup() + ".rabund", *(filehandles[lookup[i]->getGroup()])); rav.print(*(filehandles[lookup[i]->getGroup()])); (*(filehandles[lookup[i]->getGroup()])).close(); } @@ -449,10 +449,10 @@ string SummaryCommand::createGroupSummaryFile(int numLines, int numCols, vector< try { ofstream out; - string combineFileName = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "groups.summary"; + string combineFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "groups.summary"; //open combined file - openOutputFile(combineFileName, out); + m->openOutputFile(combineFileName, out); //open each groups summary file string newLabel = ""; @@ -461,7 +461,7 @@ string SummaryCommand::createGroupSummaryFile(int numLines, int numCols, vector< for (int i=0; iopenInputFile(outputNames[i], *(temp)); //read through first line - labels string tempLabel; @@ -474,7 +474,7 @@ string SummaryCommand::createGroupSummaryFile(int numLines, int numCols, vector< } }else{ for (int j = 0; j < numCols+1; j++) { *(temp) >> tempLabel; } } - gobble(*(temp)); + m->gobble(*(temp)); } //output label line to new file @@ -496,7 +496,7 @@ string SummaryCommand::createGroupSummaryFile(int numLines, int numCols, vector< } out << endl; - gobble(*(filehandles[outputNames[i]])); + m->gobble(*(filehandles[outputNames[i]])); } } diff --git a/summarysharedcommand.cpp b/summarysharedcommand.cpp index b8956ec..cda2ef0 100644 --- a/summarysharedcommand.cpp +++ b/summarysharedcommand.cpp @@ -69,7 +69,7 @@ SummarySharedCommand::SummarySharedCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(globaldata->getSharedFile()); //if user entered a file with a path then preserve it + outputDir += m->hasPath(globaldata->getSharedFile()); //if user entered a file with a path then preserve it } //check for optional parameter and set defaults @@ -77,7 +77,7 @@ SummarySharedCommand::SummarySharedCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -92,17 +92,17 @@ SummarySharedCommand::SummarySharedCommand(string option) { else { if (calc == "default") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; } } - splitAtDash(calc, Estimators); + m->splitAtDash(calc, Estimators); groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); globaldata->Groups = Groups; } string temp = validParameter.validFile(parameters, "all", false); if (temp == "not found") { temp = "false"; } - all = isTrue(temp); + all = m->isTrue(temp); if (abort == false) { @@ -157,8 +157,8 @@ SummarySharedCommand::SummarySharedCommand(string option) { } } - outputFileName = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "shared.summary"; - openOutputFile(outputFileName, outputFileHandle); + outputFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "shared.summary"; + m->openOutputFile(outputFileName, outputFileHandle); outputNames.push_back(outputFileName); mult = false; @@ -239,8 +239,8 @@ int SummarySharedCommand::execute(){ //create file and put column headers for multiple groups file if (mult == true) { - outAllFileName = ((getRootName(globaldata->inputFileName)) + "sharedmultiple.summary"); - openOutputFile(outAllFileName, outAll); + outAllFileName = ((m->getRootName(globaldata->inputFileName)) + "sharedmultiple.summary"); + m->openOutputFile(outAllFileName, outAll); outputNames.push_back(outAllFileName); outAll << "label" <<'\t' << "comparison" << '\t'; @@ -304,7 +304,7 @@ int SummarySharedCommand::execute(){ userLabels.erase(lookup[0]->getLabel()); } - if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = lookup[0]->getLabel(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } diff --git a/taxonomyequalizer.cpp b/taxonomyequalizer.cpp index 1d2832d..d3b24d1 100644 --- a/taxonomyequalizer.cpp +++ b/taxonomyequalizer.cpp @@ -16,7 +16,7 @@ TaxEqualizer::TaxEqualizer(string tfile, int c, string o) : cutoff(c), outputDir containsConfidence = false; ifstream inTax; - openInputFile(tfile, inTax); + m->openInputFile(tfile, inTax); highestLevel = getHighestLevel(inTax); @@ -32,11 +32,11 @@ TaxEqualizer::TaxEqualizer(string tfile, int c, string o) : cutoff(c), outputDir inTax.close(); ifstream in; - openInputFile(tfile, in); + m->openInputFile(tfile, in); ofstream out; - equalizedFile = outputDir + getRootName(getSimpleName(tfile)) + "equalized.taxonomy"; - openOutputFile(equalizedFile, out); + equalizedFile = outputDir + m->getRootName(m->getSimpleName(tfile)) + "equalized.taxonomy"; + m->openOutputFile(equalizedFile, out); string name, tax; @@ -44,7 +44,7 @@ TaxEqualizer::TaxEqualizer(string tfile, int c, string o) : cutoff(c), outputDir if (m->control_pressed) { break; } - in >> name >> tax; gobble(in); + in >> name >> tax; m->gobble(in); if (containsConfidence) { removeConfidences(tax); } @@ -78,7 +78,7 @@ int TaxEqualizer::getHighestLevel(ifstream& in) { string name, tax; while (in) { - in >> name >> tax; gobble(in); + in >> name >> tax; m->gobble(in); //count levels in this taxonomy int thisLevel = 0; diff --git a/tree.cpp b/tree.cpp index 8e45981..14d86e6 100644 --- a/tree.cpp +++ b/tree.cpp @@ -78,7 +78,7 @@ void Tree::addNamesToCounts() { if (itNames == globaldata->names.end()) { m->mothurOut(name + " is not in your name file, please correct."); m->mothurOutEndLine(); exit(1); } else { vector dupNames; - splitAtComma(globaldata->names[name], dupNames); + m->splitAtComma(globaldata->names[name], dupNames); map::iterator itCounts; int maxPars = 1; @@ -292,14 +292,14 @@ map Tree::mergeUserGroups(int i, vector g) { //loop through nodes groups removing the ones the user doesn't want for(it=tree[lc].pGroups.begin();it!=tree[lc].pGroups.end();){ - if (inUsersGroups(it->first, g) != true) { + if (m->inUsersGroups(it->first, g) != true) { tree[lc].pGroups.erase(it++); }else { it++; } } //loop through nodes groups removing the ones the user doesn't want for(it=tree[rc].pGroups.begin();it!=tree[rc].pGroups.end();){ - if (inUsersGroups(it->first, g) != true) { + if (m->inUsersGroups(it->first, g) != true) { tree[rc].pGroups.erase(it++); }else { it++; } } @@ -381,8 +381,8 @@ void Tree::randomLabels(vector g) { //if either of the leaf nodes you are about to switch are not in the users groups then you don't want to switch them. bool treez, treei; - treez = inUsersGroups(tree[z].getGroup(), g); - treei = inUsersGroups(tree[i].getGroup(), g); + treez = m->inUsersGroups(tree[z].getGroup(), g); + treei = m->inUsersGroups(tree[i].getGroup(), g); if ((treez == true) && (treei == true)) { //switches node i and node z's info. @@ -542,10 +542,10 @@ void Tree::printForBoot(ostream& out) { void Tree::createNewickFile(string f) { try { int root = findRoot(); - //filename = getRootName(globaldata->getTreeFile()) + "newick"; + //filename = m->getRootName(globaldata->getTreeFile()) + "newick"; filename = f; - openOutputFile(filename, out); + m->openOutputFile(filename, out); printBranch(root, out, "branch"); @@ -643,7 +643,7 @@ void Tree::parseTreeFile() { try { string filename = globaldata->getTreeFile(); ifstream filehandle; - openInputFile(filename, filehandle); + m->openInputFile(filename, filehandle); int c, comment; comment = 0; int done = 1; diff --git a/treegroupscommand.cpp b/treegroupscommand.cpp index c4e58c2..eb3c334 100644 --- a/treegroupscommand.cpp +++ b/treegroupscommand.cpp @@ -58,7 +58,7 @@ TreeGroupCommand::TreeGroupCommand(string option) { it = parameters.find("phylip"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["phylip"] = inputDir + it->second; } } @@ -66,7 +66,7 @@ TreeGroupCommand::TreeGroupCommand(string option) { it = parameters.find("column"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["column"] = inputDir + it->second; } } @@ -74,7 +74,7 @@ TreeGroupCommand::TreeGroupCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -111,7 +111,7 @@ TreeGroupCommand::TreeGroupCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -124,7 +124,7 @@ TreeGroupCommand::TreeGroupCommand(string option) { groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); globaldata->Groups = Groups; } @@ -133,7 +133,7 @@ TreeGroupCommand::TreeGroupCommand(string option) { else { if (calc == "default") { calc = "jclass-thetayc"; } } - splitAtDash(calc, Estimators); + m->splitAtDash(calc, Estimators); string temp; temp = validParameter.validFile(parameters, "precision", false); if (temp == "not found") { temp = "100"; } @@ -146,7 +146,7 @@ TreeGroupCommand::TreeGroupCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it } @@ -322,7 +322,7 @@ int TreeGroupCommand::execute(){ if (m->control_pressed) { return 0; } //create a new filename - outputFile = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "tre"; + outputFile = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "tre"; outputNames.push_back(outputFile); createTree(); @@ -512,7 +512,7 @@ int TreeGroupCommand::makeSimsShared() { userLabels.erase(lookup[0]->getLabel()); } - if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = lookup[0]->getLabel(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } @@ -593,7 +593,7 @@ int TreeGroupCommand::process(vector thisLookup) { for (int g = 0; g < numGroups; g++) { index[g] = g; } //create a new filename - outputFile = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".tre"; + outputFile = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".tre"; outputNames.push_back(outputFile); for (int k = 0; k < thisLookup.size(); k++) { diff --git a/treemap.cpp b/treemap.cpp index dcef7f7..b2fc591 100644 --- a/treemap.cpp +++ b/treemap.cpp @@ -13,7 +13,7 @@ TreeMap::TreeMap(string filename) { groupFileName = filename; - openInputFile(filename, fileHandle); + m->openInputFile(filename, fileHandle); } /************************************************************/ @@ -39,7 +39,7 @@ void TreeMap::readMap() { seqsPerGroup[seqGroup]++; } - gobble(fileHandle); + m->gobble(fileHandle); } fileHandle.close(); } diff --git a/trimseqscommand.cpp b/trimseqscommand.cpp index daf0ece..8a767f6 100644 --- a/trimseqscommand.cpp +++ b/trimseqscommand.cpp @@ -47,7 +47,7 @@ TrimSeqsCommand::TrimSeqsCommand(string option) { it = parameters.find("fasta"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } @@ -55,7 +55,7 @@ TrimSeqsCommand::TrimSeqsCommand(string option) { it = parameters.find("oligos"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["oligos"] = inputDir + it->second; } } @@ -63,7 +63,7 @@ TrimSeqsCommand::TrimSeqsCommand(string option) { it = parameters.find("qfile"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["qfile"] = inputDir + it->second; } } @@ -78,7 +78,7 @@ TrimSeqsCommand::TrimSeqsCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(fastaFile); //if user entered a file with a path then preserve it + outputDir += m->hasPath(fastaFile); //if user entered a file with a path then preserve it } @@ -87,7 +87,7 @@ TrimSeqsCommand::TrimSeqsCommand(string option) { string temp; temp = validParameter.validFile(parameters, "flip", false); if (temp == "not found"){ flip = 0; } - else if(isTrue(temp)) { flip = 1; } + else if(m->isTrue(temp)) { flip = 1; } temp = validParameter.validFile(parameters, "oligos", true); if (temp == "not found"){ oligoFile = ""; } @@ -126,7 +126,7 @@ TrimSeqsCommand::TrimSeqsCommand(string option) { convert(temp, qThreshold); temp = validParameter.validFile(parameters, "qtrim", false); if (temp == "not found") { temp = "F"; } - qtrim = isTrue(temp); + qtrim = m->isTrue(temp); temp = validParameter.validFile(parameters, "rollaverage", false); if (temp == "not found") { temp = "0"; } convert(temp, qRollAverage); @@ -144,7 +144,7 @@ TrimSeqsCommand::TrimSeqsCommand(string option) { convert(temp, qAverage); temp = validParameter.validFile(parameters, "allfiles", false); if (temp == "not found") { temp = "F"; } - allFiles = isTrue(temp); + allFiles = m->isTrue(temp); temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found") { temp = "1"; } convert(temp, processors); @@ -219,15 +219,15 @@ int TrimSeqsCommand::execute(){ numFPrimers = 0; //this needs to be initialized numRPrimers = 0; - string trimSeqFile = outputDir + getRootName(getSimpleName(fastaFile)) + "trim.fasta"; + string trimSeqFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "trim.fasta"; outputNames.push_back(trimSeqFile); - string scrapSeqFile = outputDir + getRootName(getSimpleName(fastaFile)) + "scrap.fasta"; + string scrapSeqFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "scrap.fasta"; outputNames.push_back(scrapSeqFile); - string trimQualFile = outputDir + getRootName(getSimpleName(fastaFile)) + "trim.qual"; + string trimQualFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "trim.qual"; outputNames.push_back(trimQualFile); - string scrapQualFile = outputDir + getRootName(getSimpleName(fastaFile)) + "scrap.qual"; + string scrapQualFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "scrap.qual"; outputNames.push_back(scrapQualFile); - string groupFile = outputDir + getRootName(getSimpleName(fastaFile)) + "groups"; + string groupFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "groups"; vector fastaFileNames; vector qualFileNames; @@ -285,26 +285,26 @@ int TrimSeqsCommand::execute(){ //append files for(int i=1;iappendFiles((trimSeqFile + toString(processIDS[i]) + ".temp"), trimSeqFile); remove((trimSeqFile + toString(processIDS[i]) + ".temp").c_str()); - appendFiles((scrapSeqFile + toString(processIDS[i]) + ".temp"), scrapSeqFile); + m->appendFiles((scrapSeqFile + toString(processIDS[i]) + ".temp"), scrapSeqFile); remove((scrapSeqFile + toString(processIDS[i]) + ".temp").c_str()); - appendFiles((trimQualFile + toString(processIDS[i]) + ".temp"), trimQualFile); + m->appendFiles((trimQualFile + toString(processIDS[i]) + ".temp"), trimQualFile); remove((trimQualFile + toString(processIDS[i]) + ".temp").c_str()); - appendFiles((scrapQualFile + toString(processIDS[i]) + ".temp"), scrapQualFile); + m->appendFiles((scrapQualFile + toString(processIDS[i]) + ".temp"), scrapQualFile); remove((scrapQualFile + toString(processIDS[i]) + ".temp").c_str()); - appendFiles((groupFile + toString(processIDS[i]) + ".temp"), groupFile); + m->appendFiles((groupFile + toString(processIDS[i]) + ".temp"), groupFile); remove((groupFile + toString(processIDS[i]) + ".temp").c_str()); for (int j = 0; j < fastaFileNames.size(); j++) { - appendFiles((fastaFileNames[j] + toString(processIDS[i]) + ".temp"), fastaFileNames[j]); + m->appendFiles((fastaFileNames[j] + toString(processIDS[i]) + ".temp"), fastaFileNames[j]); remove((fastaFileNames[j] + toString(processIDS[i]) + ".temp").c_str()); } if(qFileName != ""){ for (int j = 0; j < qualFileNames.size(); j++) { - appendFiles((qualFileNames[j] + toString(processIDS[i]) + ".temp"), qualFileNames[j]); + m->appendFiles((qualFileNames[j] + toString(processIDS[i]) + ".temp"), qualFileNames[j]); remove((qualFileNames[j] + toString(processIDS[i]) + ".temp").c_str()); } } @@ -331,15 +331,15 @@ int TrimSeqsCommand::execute(){ for(int i=0;iisBlank(fastaFileNames[i])) { remove(fastaFileNames[i].c_str()); } else if (filesToRemove.count(fastaFileNames[i]) > 0) { remove(fastaFileNames[i].c_str()); } else { ifstream inFASTA; string seqName; - openInputFile(fastaFileNames[i], inFASTA); + m->openInputFile(fastaFileNames[i], inFASTA); ofstream outGroups; - string outGroupFilename = outputDir + getRootName(getSimpleName(fastaFileNames[i])) + "groups"; - openOutputFile(outGroupFilename, outGroups); + string outGroupFilename = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[i])) + "groups"; + m->openOutputFile(outGroupFilename, outGroups); outputNames.push_back(outGroupFilename); string thisGroup = ""; @@ -364,12 +364,12 @@ int TrimSeqsCommand::execute(){ if(qFileName != ""){ for(int i=0;iisBlank(qualFileNames[i])) { remove(qualFileNames[i].c_str()); } else if (filesToRemove.count(qualFileNames[i]) > 0) { remove(qualFileNames[i].c_str()); } else { ifstream inQual; string seqName; - openInputFile(qualFileNames[i], inQual); + m->openInputFile(qualFileNames[i], inQual); // ofstream outGroups; // // string thisGroup = ""; @@ -413,16 +413,16 @@ int TrimSeqsCommand::driverCreateTrim(string filename, string qFileName, string try { ofstream outFASTA; - int able = openOutputFile(trimFile, outFASTA); + int able = m->openOutputFile(trimFile, outFASTA); ofstream scrapFASTA; - openOutputFile(scrapFile, scrapFASTA); + m->openOutputFile(scrapFile, scrapFASTA); ofstream outQual; ofstream scrapQual; if(qFileName != ""){ - openOutputFile(trimQFile, outQual); - openOutputFile(scrapQFile, scrapQual); + m->openOutputFile(trimQFile, outQual); + m->openOutputFile(scrapQFile, scrapQual); } ofstream outGroups; @@ -431,7 +431,7 @@ int TrimSeqsCommand::driverCreateTrim(string filename, string qFileName, string if (oligoFile != "") { - openOutputFile(groupFile, outGroups); + m->openOutputFile(groupFile, outGroups); for (int i = 0; i < fastaNames.size(); i++) { #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) fastaFileNames.push_back(new ofstream((fastaNames[i] + toString(getpid()) + ".temp").c_str(), ios::ate)); @@ -448,11 +448,11 @@ int TrimSeqsCommand::driverCreateTrim(string filename, string qFileName, string } ifstream inFASTA; - openInputFile(filename, inFASTA); + m->openInputFile(filename, inFASTA); inFASTA.seekg(line->start); ifstream qFile; - if(qFileName != "") { openInputFile(qFileName, qFile); qFile.seekg(qline->start); } + if(qFileName != "") { m->openInputFile(qFileName, qFile); qFile.seekg(qline->start); } bool done = false; int count = 0; @@ -477,11 +477,11 @@ int TrimSeqsCommand::driverCreateTrim(string filename, string qFileName, string int success = 1; - Sequence currSeq(inFASTA); gobble(inFASTA); + Sequence currSeq(inFASTA); m->gobble(inFASTA); QualityScores currQual; if(qFileName != ""){ - currQual = QualityScores(qFile, currSeq.getNumBases()); gobble(qFile); + currQual = QualityScores(qFile, currSeq.getNumBases()); m->gobble(qFile); } string origSeq = currSeq.getUnaligned(); @@ -652,7 +652,7 @@ int TrimSeqsCommand::setLines(string filename, string qfilename, vectordivideFile(filename, processors); if (qfilename == "") { return processors; } @@ -660,7 +660,7 @@ int TrimSeqsCommand::setLines(string filename, string qfilename, vector firstSeqNames; for (int i = 0; i < (fastaFilePos.size()-1); i++) { ifstream in; - openInputFile(filename, in); + m->openInputFile(filename, in); in.seekg(fastaFilePos[i]); Sequence temp(in); @@ -671,11 +671,11 @@ int TrimSeqsCommand::setLines(string filename, string qfilename, vectoropenInputFile(qfilename, inQual); string input; while(!inQual.eof()){ - input = getline(inQual); + input = m->getline(inQual); if (input.length() != 0) { if(input[0] == '>'){ //this is a sequence name line @@ -733,7 +733,7 @@ int TrimSeqsCommand::setLines(string filename, string qfilename, vector& outFASTAVec, vector& outQualVec){ try { ifstream inOligos; - openInputFile(oligoFile, inOligos); + m->openInputFile(oligoFile, inOligos); ofstream test; @@ -777,19 +777,19 @@ void TrimSeqsCommand::getOligos(vector& outFASTAVec, vector& out groupVector.push_back(group); if(allFiles){ - outFASTAVec.push_back((outputDir + getRootName(getSimpleName(fastaFile)) + group + ".fasta")); + outFASTAVec.push_back((outputDir + m->getRootName(m->getSimpleName(fastaFile)) + group + ".fasta")); if(qFileName != ""){ - outQualVec.push_back((outputDir + getRootName(getSimpleName(qFileName)) + group + ".qual")); + outQualVec.push_back((outputDir + m->getRootName(m->getSimpleName(qFileName)) + group + ".qual")); } if (group == "") { //if there is not a group for this primer, then this file will not get written to, but we add it to keep the indexes correct - filesToRemove.insert((outputDir + getRootName(getSimpleName(fastaFile)) + group + ".fasta")); + filesToRemove.insert((outputDir + m->getRootName(m->getSimpleName(fastaFile)) + group + ".fasta")); if(qFileName != ""){ - filesToRemove.insert((outputDir + getRootName(getSimpleName(qFileName)) + group + ".qual")); + filesToRemove.insert((outputDir + m->getRootName(m->getSimpleName(qFileName)) + group + ".qual")); } }else { - outputNames.push_back((outputDir + getRootName(getSimpleName(fastaFile)) + group + ".fasta")); + outputNames.push_back((outputDir + m->getRootName(m->getSimpleName(fastaFile)) + group + ".fasta")); if(qFileName != ""){ - outputNames.push_back((outputDir + getRootName(getSimpleName(qFileName)) + group + ".qual")); + outputNames.push_back((outputDir + m->getRootName(m->getSimpleName(qFileName)) + group + ".qual")); } } } @@ -811,16 +811,16 @@ void TrimSeqsCommand::getOligos(vector& outFASTAVec, vector& out groupVector.push_back(group); if(allFiles){ - outputNames.push_back((outputDir + getRootName(getSimpleName(fastaFile)) + group + ".fasta")); - outFASTAVec.push_back((outputDir + getRootName(getSimpleName(fastaFile)) + group + ".fasta")); + outputNames.push_back((outputDir + m->getRootName(m->getSimpleName(fastaFile)) + group + ".fasta")); + outFASTAVec.push_back((outputDir + m->getRootName(m->getSimpleName(fastaFile)) + group + ".fasta")); if(qFileName != ""){ - outQualVec.push_back((outputDir + getRootName(getSimpleName(qFileName)) + group + ".qual")); - outputNames.push_back((outputDir + getRootName(getSimpleName(qFileName)) + group + ".qual")); + outQualVec.push_back((outputDir + m->getRootName(m->getSimpleName(qFileName)) + group + ".qual")); + outputNames.push_back((outputDir + m->getRootName(m->getSimpleName(qFileName)) + group + ".qual")); } } }else{ m->mothurOut(type + " is not recognized as a valid type. Choices are forward, reverse, and barcode. Ignoring " + oligo + "."); m->mothurOutEndLine(); } } - gobble(inOligos); + m->gobble(inOligos); } inOligos.close(); @@ -831,13 +831,13 @@ void TrimSeqsCommand::getOligos(vector& outFASTAVec, vector& out for (map::iterator itBar = barcodes.begin(); itBar != barcodes.end(); itBar++) { for (map::iterator itPrime = primers.begin(); itPrime != primers.end(); itPrime++) { if (groupVector[itPrime->second] != "") { //there is a group for this primer - outputNames.push_back((outputDir + getRootName(getSimpleName(qFileName)) + groupVector[itBar->second] + "." + groupVector[itPrime->second] + ".fasta")); - outFASTAVec.push_back((outputDir + getRootName(getSimpleName(fastaFile)) + groupVector[itBar->second] + "." + groupVector[itPrime->second] + ".fasta")); + outputNames.push_back((outputDir + m->getRootName(m->getSimpleName(qFileName)) + groupVector[itBar->second] + "." + groupVector[itPrime->second] + ".fasta")); + outFASTAVec.push_back((outputDir + m->getRootName(m->getSimpleName(fastaFile)) + groupVector[itBar->second] + "." + groupVector[itPrime->second] + ".fasta")); combos[(groupVector[itBar->second] + "." + groupVector[itPrime->second])] = outFASTAVec.size()-1; if(qFileName != ""){ - outQualVec.push_back((outputDir + getRootName(getSimpleName(qFileName)) + groupVector[itBar->second] + "." + groupVector[itPrime->second] + ".qual")); - outputNames.push_back((outputDir + getRootName(getSimpleName(qFileName)) + groupVector[itBar->second] + "." + groupVector[itPrime->second] + ".qual")); + outQualVec.push_back((outputDir + m->getRootName(m->getSimpleName(qFileName)) + groupVector[itBar->second] + "." + groupVector[itPrime->second] + ".qual")); + outputNames.push_back((outputDir + m->getRootName(m->getSimpleName(qFileName)) + groupVector[itBar->second] + "." + groupVector[itPrime->second] + ".qual")); } } } diff --git a/unifracunweightedcommand.cpp b/unifracunweightedcommand.cpp index 77cd4d7..848c85c 100644 --- a/unifracunweightedcommand.cpp +++ b/unifracunweightedcommand.cpp @@ -40,7 +40,7 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it } //check for optional parameter and set defaults @@ -48,7 +48,7 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) { groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); globaldata->Groups = Groups; } @@ -56,26 +56,26 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) { convert(itersString, iters); string temp = validParameter.validFile(parameters, "distance", false); if (temp == "not found") { temp = "false"; } - phylip = isTrue(temp); + phylip = m->isTrue(temp); temp = validParameter.validFile(parameters, "random", false); if (temp == "not found") { temp = "true"; } - random = isTrue(temp); + random = m->isTrue(temp); if (!random) { iters = 0; } //turn off random calcs //if user selects distance = true and no groups it won't calc the pairwise if ((phylip) && (Groups.size() == 0)) { groups = "all"; - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); globaldata->Groups = Groups; } if (abort == false) { T = globaldata->gTree; tmap = globaldata->gTreemap; - sumFile = outputDir + getSimpleName(globaldata->getTreeFile()) + ".uwsummary"; + sumFile = outputDir + m->getSimpleName(globaldata->getTreeFile()) + ".uwsummary"; outputNames.push_back(sumFile); - openOutputFile(sumFile, outSum); + m->openOutputFile(sumFile, outSum); util = new SharedUtil(); util->setGroups(globaldata->Groups, tmap->namesOfGroups, allGroups, numGroups, "unweighted"); //sets the groups the user wants to analyze @@ -143,8 +143,8 @@ int UnifracUnweightedCommand::execute() { counter = 0; if (random) { - output = new ColumnFile(outputDir + getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted", itersString); - outputNames.push_back(outputDir + getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted"); + output = new ColumnFile(outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted", itersString); + outputNames.push_back(outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted"); } @@ -317,11 +317,11 @@ void UnifracUnweightedCommand::printUWSummaryFile(int i) { /***********************************************************/ void UnifracUnweightedCommand::createPhylipFile(int i) { try { - string phylipFileName = outputDir + getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted.dist"; + string phylipFileName = outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted.dist"; outputNames.push_back(phylipFileName); ofstream out; - openOutputFile(phylipFileName, out); + m->openOutputFile(phylipFileName, out); //output numSeqs out << globaldata->Groups.size() << endl; diff --git a/unifracweightedcommand.cpp b/unifracweightedcommand.cpp index f092b0f..28d94d0 100644 --- a/unifracweightedcommand.cpp +++ b/unifracweightedcommand.cpp @@ -40,7 +40,7 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it } //check for optional parameter and set defaults @@ -48,7 +48,7 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); globaldata->Groups = Groups; } @@ -56,10 +56,10 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { convert(itersString, iters); string temp = validParameter.validFile(parameters, "distance", false); if (temp == "not found") { temp = "false"; } - phylip = isTrue(temp); + phylip = m->isTrue(temp); temp = validParameter.validFile(parameters, "random", false); if (temp == "not found") { temp = "true"; } - random = isTrue(temp); + random = m->isTrue(temp); if (!random) { iters = 0; } //turn off random calcs @@ -67,8 +67,8 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { if (abort == false) { T = globaldata->gTree; tmap = globaldata->gTreemap; - sumFile = outputDir + getSimpleName(globaldata->getTreeFile()) + ".wsummary"; - openOutputFile(sumFile, outSum); + sumFile = outputDir + m->getSimpleName(globaldata->getTreeFile()) + ".wsummary"; + m->openOutputFile(sumFile, outSum); outputNames.push_back(sumFile); util = new SharedUtil(); @@ -142,8 +142,8 @@ int UnifracWeightedCommand::execute() { uScores.resize(numComp); //data[0] = weightedscore AB, data[1] = weightedscore AC... if (random) { - output = new ColumnFile(outputDir + getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted", itersString); - outputNames.push_back(outputDir + getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted"); + output = new ColumnFile(outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted", itersString); + outputNames.push_back(outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted"); } userData = weighted->getValues(T[i]); //userData[0] = weightedscore @@ -348,10 +348,10 @@ void UnifracWeightedCommand::createPhylipFile() { //for each tree for (int i = 0; i < T.size(); i++) { - string phylipFileName = outputDir + getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted.dist"; + string phylipFileName = outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted.dist"; outputNames.push_back(phylipFileName); ofstream out; - openOutputFile(phylipFileName, out); + m->openOutputFile(phylipFileName, out); //output numSeqs out << globaldata->Groups.size() << endl; diff --git a/unweighted.cpp b/unweighted.cpp index 2a2a41c..1f6ad96 100644 --- a/unweighted.cpp +++ b/unweighted.cpp @@ -53,7 +53,7 @@ EstOutput Unweighted::getValues(Tree* t) { copyIpcount = t->tree[i].pcount; for (it = copyIpcount.begin(); it != copyIpcount.end();) { - if (inUsersGroups(it->first, groups) != true) { + if (m->inUsersGroups(it->first, groups) != true) { copyIpcount.erase(it++); }else { it++; } } @@ -107,7 +107,7 @@ EstOutput Unweighted::getValues(Tree* t) { copyIpcount = t->tree[i].pcount; for (it = copyIpcount.begin(); it != copyIpcount.end();) { - if (inUsersGroups(it->first, groups) != true) { + if (m->inUsersGroups(it->first, groups) != true) { copyIpcount.erase(it++); }else { it++; } } @@ -197,7 +197,7 @@ EstOutput Unweighted::getValues(Tree* t, string groupA, string groupB) { //This section adds in all lengths that are non leaf copyIpcount = copyTree->tree[i].pcount; for (it = copyIpcount.begin(); it != copyIpcount.end();) { - if (inUsersGroups(it->first, groups) != true) { + if (m->inUsersGroups(it->first, groups) != true) { copyIpcount.erase(it++); }else { it++; } } @@ -257,7 +257,7 @@ EstOutput Unweighted::getValues(Tree* t, string groupA, string groupB) { copyIpcount = copyTree->tree[i].pcount; for (it = copyIpcount.begin(); it != copyIpcount.end();) { - if (inUsersGroups(it->first, groups) != true) { + if (m->inUsersGroups(it->first, groups) != true) { copyIpcount.erase(it++); }else { it++; } } diff --git a/validparameter.cpp b/validparameter.cpp index 1faa651..38a9094 100644 --- a/validparameter.cpp +++ b/validparameter.cpp @@ -69,7 +69,7 @@ bool ValidParameters::isValidParameter(string parameter, vector cParams, vector range = parameterRanges[parameter]; vector values; - splitAtDash(value, values); + m->splitAtDash(value, values); for(int i = 0; i < values.size(); i++) { value = values.at(i); @@ -233,14 +233,14 @@ string ValidParameters::validFile(map& container, string paramet if (pid == 0) { #endif - ableToOpen = openInputFile(it->second, in, "noerror"); + ableToOpen = m->openInputFile(it->second, in, "noerror"); //if you can't open it, try default location if (ableToOpen == 1) { if (m->getDefaultPath() != "") { //default path is set - string tryPath = m->getDefaultPath() + getSimpleName(it->second); + string tryPath = m->getDefaultPath() + m->getSimpleName(it->second); m->mothurOut("Unable to open " + it->second + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = openInputFile(tryPath, in, "noerror"); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); container[parameter] = tryPath; } } diff --git a/venn.cpp b/venn.cpp index 443c36c..dfa5519 100644 --- a/venn.cpp +++ b/venn.cpp @@ -34,9 +34,9 @@ vector Venn::getPic(SAbundVector* sabund, vector vCalcs) { vector outputNames; for(int i=0;iinputFileName)) + "." + sabund->getLabel() + "." + vCalcs[i]->getName() + ".svg"; + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "." + sabund->getLabel() + "." + vCalcs[i]->getName() + ".svg"; outputNames.push_back(filenamesvg); - openOutputFile(filenamesvg, outsvg); + m->openOutputFile(filenamesvg, outsvg); if (m->control_pressed) { outsvg.close(); return outputNames; } @@ -88,9 +88,9 @@ vector Venn::getPic(vector lookup, vectorinputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + ".svg"; + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + ".svg"; outputNames.push_back(filenamesvg); - openOutputFile(filenamesvg, outsvg); + m->openOutputFile(filenamesvg, outsvg); if (m->control_pressed) { outsvg.close(); return outputNames; } @@ -140,10 +140,10 @@ vector Venn::getPic(vector lookup, vectorinputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + ".svg"; + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + ".svg"; outputNames.push_back(filenamesvg); - openOutputFile(filenamesvg, outsvg); + m->openOutputFile(filenamesvg, outsvg); if (m->control_pressed) { outsvg.close(); return outputNames; } @@ -215,10 +215,10 @@ vector Venn::getPic(vector lookup, vectorinputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + ".svg"; + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + ".svg"; outputNames.push_back(filenamesvg); - openOutputFile(filenamesvg, outsvg); + m->openOutputFile(filenamesvg, outsvg); if (m->control_pressed) { outsvg.close(); return outputNames; } @@ -477,9 +477,9 @@ vector Venn::getPic(vector lookup, vectorgetName() != "sharedsobs") && (vCalcs[i]->getName() != "sharedchao")) { m->mothurOut(vCalcs[i]->getName() + " is not a valid calculator with four groups. It will be disregarded. "); m->mothurOutEndLine(); } else{ - string filenamesvg = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + "-" + lookup[3]->getGroup() + ".svg"; + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + "-" + lookup[3]->getGroup() + ".svg"; outputNames.push_back(filenamesvg); - openOutputFile(filenamesvg, outsvg); + m->openOutputFile(filenamesvg, outsvg); if (m->control_pressed) { outsvg.close(); return outputNames; } diff --git a/venncommand.cpp b/venncommand.cpp index 192611d..608c0a0 100644 --- a/venncommand.cpp +++ b/venncommand.cpp @@ -52,7 +52,7 @@ VennCommand::VennCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it } //check for optional parameter and set defaults @@ -60,7 +60,7 @@ VennCommand::VennCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -73,7 +73,7 @@ VennCommand::VennCommand(string option) { groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); globaldata->Groups = Groups; } @@ -89,7 +89,7 @@ VennCommand::VennCommand(string option) { else { calc = "sharedsobs"; } } } - splitAtDash(calc, Estimators); + m->splitAtDash(calc, Estimators); string temp; temp = validParameter.validFile(parameters, "abund", false); if (temp == "not found") { temp = "10"; } @@ -240,7 +240,7 @@ int VennCommand::execute(){ for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); } } } - if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = lookup[0]->getLabel(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } @@ -342,7 +342,7 @@ int VennCommand::execute(){ userLabels.erase(sabund->getLabel()); } - if ((anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = sabund->getLabel(); delete sabund; diff --git a/weighted.cpp b/weighted.cpp index a114d2c..faa1ff7 100644 --- a/weighted.cpp +++ b/weighted.cpp @@ -55,9 +55,9 @@ EstOutput Weighted::getValues(Tree* t) { } //is this sum from a sequence which is in one of the users groups - if (inUsersGroups(t->tree[v].getGroup(), globaldata->Groups) == true) { + if (m->inUsersGroups(t->tree[v].getGroup(), globaldata->Groups) == true) { //is this sum from a sequence which is in this groupCombo - if (inUsersGroups(t->tree[v].getGroup(), groups)) { + if (m->inUsersGroups(t->tree[v].getGroup(), groups)) { int numSeqsInGroupI, numSeqsInGroupL; map::iterator it; @@ -174,7 +174,7 @@ EstOutput Weighted::getValues(Tree* t, string groupA, string groupB) { sum += abs(t->tree[index].getBranchLength()); } - if (inUsersGroups(t->tree[v].getGroup(), groups)) { + if (m->inUsersGroups(t->tree[v].getGroup(), groups)) { int numSeqsInGroupI, numSeqsInGroupL; map::iterator it;