From: westcott Date: Mon, 29 Jun 2009 13:01:52 +0000 (+0000) Subject: modified read.otu and shared command X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=29c0d3ec01be5372807eb86261100d77de253787 modified read.otu and shared command --- diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index 9da05bc..b04bf2a 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -105,7 +105,6 @@ 37D928700F21331F001D4494 /* nameassignment.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927F00F21331F001D4494 /* nameassignment.cpp */; }; 37D928720F21331F001D4494 /* npshannon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927F40F21331F001D4494 /* npshannon.cpp */; }; 37D928730F21331F001D4494 /* ordervector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927F70F21331F001D4494 /* ordervector.cpp */; }; - 37D928740F21331F001D4494 /* parselistcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927F90F21331F001D4494 /* parselistcommand.cpp */; }; 37D928750F21331F001D4494 /* progress.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927FB0F21331F001D4494 /* progress.cpp */; }; 37D928760F21331F001D4494 /* quitcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927FD0F21331F001D4494 /* quitcommand.cpp */; }; 37D928770F21331F001D4494 /* rabundvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927FF0F21331F001D4494 /* rabundvector.cpp */; }; @@ -385,8 +384,6 @@ 37D927F60F21331F001D4494 /* observable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = observable.h; sourceTree = SOURCE_ROOT; }; 37D927F70F21331F001D4494 /* ordervector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ordervector.cpp; sourceTree = SOURCE_ROOT; }; 37D927F80F21331F001D4494 /* ordervector.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ordervector.hpp; sourceTree = SOURCE_ROOT; }; - 37D927F90F21331F001D4494 /* parselistcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = parselistcommand.cpp; sourceTree = SOURCE_ROOT; }; - 37D927FA0F21331F001D4494 /* parselistcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = parselistcommand.h; sourceTree = SOURCE_ROOT; }; 37D927FB0F21331F001D4494 /* progress.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = progress.cpp; sourceTree = SOURCE_ROOT; }; 37D927FC0F21331F001D4494 /* progress.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = progress.hpp; sourceTree = SOURCE_ROOT; }; 37D927FD0F21331F001D4494 /* quitcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = quitcommand.cpp; sourceTree = SOURCE_ROOT; }; @@ -790,8 +787,6 @@ 7E5A17AE0FE57292003C6A03 /* mergefilecommand.cpp */, 375873F70F7D649C0040F377 /* nocommands.h */, 375873F60F7D649C0040F377 /* nocommands.cpp */, - 37D927FA0F21331F001D4494 /* parselistcommand.h */, - 37D927F90F21331F001D4494 /* parselistcommand.cpp */, 3792946E0F2E191800B9034A /* parsimonycommand.h */, 3792946F0F2E191800B9034A /* parsimonycommand.cpp */, 37D927FE0F21331F001D4494 /* quitcommand.h */, @@ -984,7 +979,6 @@ 37D928700F21331F001D4494 /* nameassignment.cpp in Sources */, 37D928720F21331F001D4494 /* npshannon.cpp in Sources */, 37D928730F21331F001D4494 /* ordervector.cpp in Sources */, - 37D928740F21331F001D4494 /* parselistcommand.cpp in Sources */, 37D928750F21331F001D4494 /* progress.cpp in Sources */, 37D928760F21331F001D4494 /* quitcommand.cpp in Sources */, 37D928770F21331F001D4494 /* rabundvector.cpp in Sources */, diff --git a/engine.cpp b/engine.cpp index f0fd05a..55617bc 100644 --- a/engine.cpp +++ b/engine.cpp @@ -20,8 +20,6 @@ InteractEngine::InteractEngine(string path){ globaldata = GlobalData::getInstance(); globaldata->argv = path; - string logFileName = "mothur.logFile"; - remove(logFileName.c_str()); system("clear"); } @@ -41,33 +39,7 @@ bool InteractEngine::getInput(){ string options = ""; int quitCommandCalled = 0; - mothurOut("mothur v.1.4.1"); - mothurOutEndLine(); - mothurOut("Last updated: 6/23/2009"); - mothurOutEndLine(); - mothurOutEndLine(); - mothurOut("by"); - mothurOutEndLine(); - mothurOut("Patrick D. Schloss"); - mothurOutEndLine(); - mothurOutEndLine(); - mothurOut("Department of Microbiology"); - mothurOutEndLine(); - mothurOut("pschloss@micro.umass.edu"); - mothurOutEndLine(); - mothurOut("http://schloss.micro.umass.edu/mothur"); - mothurOutEndLine(); - mothurOutEndLine(); - mothurOutEndLine(); - mothurOut("Distributed under the GNU General Public License"); - mothurOutEndLine(); - mothurOutEndLine(); - mothurOut("Type 'help()' for information on the commands that are available"); - mothurOutEndLine(); - mothurOutEndLine(); - mothurOut("Type 'quit()' to exit program"); - mothurOutEndLine(); - + while(quitCommandCalled != 1){ mothurOutEndLine(); @@ -113,9 +85,7 @@ BatchEngine::BatchEngine(string path, string batchFileName){ openedBatch = openInputFile(batchFileName, inputBatchFile); globaldata->argv = path; - string logFileName = "mothur.logFile"; - remove(logFileName.c_str()); - + system("clear"); // char buffer = ' '; @@ -211,9 +181,7 @@ ScriptEngine::ScriptEngine(string path, string commandString){ listOfCommands = commandString.substr(1, (commandString.length()-1)); globaldata->argv = path; - string logFileName = "mothur.logFile"; - remove(logFileName.c_str()); - + system("clear"); } diff --git a/mothur.cpp b/mothur.cpp index 0314331..88caa25 100644 --- a/mothur.cpp +++ b/mothur.cpp @@ -17,6 +17,56 @@ GlobalData* GlobalData::_uniqueInstance = 0; int main(int argc, char *argv[]){ try { + + //remove old logfile + string logFileName = "mothur.logFile"; + remove(logFileName.c_str()); + + //version + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) + #if defined (__APPLE__) || (__MACH__) + mothurOutJustToLog("Mac version"); + mothurOutEndLine(); mothurOutEndLine(); + #else + mothurOutJustToLog("Linux version"); + mothurOutEndLine(); mothurOutEndLine(); + #endif + + #else + mothurOutJustToLog("Windows version"); + mothurOutEndLine(); mothurOutEndLine(); + #endif + + + //header + mothurOut("mothur v.1.4.1"); + mothurOutEndLine(); + mothurOut("Last updated: 6/23/2009"); + mothurOutEndLine(); + mothurOutEndLine(); + mothurOut("by"); + mothurOutEndLine(); + mothurOut("Patrick D. Schloss"); + mothurOutEndLine(); + mothurOutEndLine(); + mothurOut("Department of Microbiology"); + mothurOutEndLine(); + mothurOut("pschloss@micro.umass.edu"); + mothurOutEndLine(); + mothurOut("http://schloss.micro.umass.edu/mothur"); + mothurOutEndLine(); + mothurOutEndLine(); + mothurOutEndLine(); + mothurOut("Distributed under the GNU General Public License"); + mothurOutEndLine(); + mothurOutEndLine(); + mothurOut("Type 'help()' for information on the commands that are available"); + mothurOutEndLine(); + mothurOutEndLine(); + mothurOut("Type 'quit()' to exit program"); + mothurOutEndLine(); + + //srand(54321); srand( (unsigned)time( NULL ) ); diff --git a/parselistcommand.cpp b/parselistcommand.cpp deleted file mode 100644 index 0fdcf9a..0000000 --- a/parselistcommand.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/* - * parselistcommand.cpp - * Dotur - * - * Created by Sarah Westcott on 1/2/09. - * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "parselistcommand.h" - -//********************************************************************************************************************** -ParseListCommand::ParseListCommand(){ - try { - globaldata = GlobalData::getInstance(); - - //read in group map info. - //groupMap = new GroupMap(globaldata->getGroupFile()); - //groupMap->readMap(); - groupMap = globaldata->gGroupmap; - - //fill filehandles with neccessary ofstreams - int i; - ofstream* temp; - SharedListVector* templist; - for (i=0; igetNumGroups(); i++) { - temp = new ofstream; - templist = new SharedListVector(); - filehandles[groupMap->namesOfGroups[i]] = temp; - mapOfLists[groupMap->namesOfGroups[i]] = templist; - } - - //set fileroot - fileroot = getRootName(globaldata->getListFile()); - - //clears file before we start to write to it below - for (int i=0; igetNumGroups(); i++) { - remove((fileroot + groupMap->namesOfGroups[i] + ".list").c_str()); - } - - } - catch(exception& e) { - errorOut(e, "ParseListCommand", "ParseListCommand"); - exit(1); - } - -} -/***********************************************************************/ -void ParseListCommand::parse(int index, SharedListVector* list) { - try { - string member, bin, groupName; - bin = list->get(index); - - while (bin.find_first_of(',') != -1) {//while you still have sequences - member = bin.substr(0,bin.find_first_of(',')); - if ((bin.find_first_of(',')+1) <= bin.length()) { //checks to make sure you don't have comma at end of string - bin = bin.substr(bin.find_first_of(',')+1, bin.length()); - } - - groupName = groupMap->getGroup(member); - if (groupName != "not found") { - listGroups[groupName] = listGroups[groupName] + "," + member; //adds prefix to the correct group. - }else { - mothurOut("Error: Sequence '" + toString(member) + "' was not found in the group file, please correct\n"); - } - } - - //save last name after comma - groupName = groupMap->getGroup(bin); - if (groupName != "not found") { - listGroups[groupName] = listGroups[groupName] + "," + bin; //adds prefix to the correct group. - }else { - mothurOut("Error: Sequence '" + toString(bin) + "' was not found in the group file, please correct\n"); - } - } - catch(exception& e) { - errorOut(e, "ParseListCommand", "parse"); - exit(1); - } -} - -//********************************************************************************************************************** - -int ParseListCommand::execute(){ - try{ - - int count = 1; - - //read in listfile - read = new ReadOTUFile(globaldata->inputFileName); - read->read(&*globaldata); - input = globaldata->ginput; - list = globaldata->gSharedList; - string lastLabel = list->getLabel(); - - //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. - set processedLabels; - set userLabels = globaldata->labels; - set userLines = globaldata->lines; - - //parses and sets each groups listvector - //as long as you are not at the end of the file or done wih the lines you want - while((list != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) { - - if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lastLabel) == 1){ - mothurOut(list->getLabel() + "\t" + toString(count)); mothurOutEndLine(); - process(list); - - processedLabels.insert(list->getLabel()); - userLabels.erase(list->getLabel()); - userLines.erase(count); - } - - if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - delete list; - list = input->getSharedListVector(lastLabel); - - mothurOut(list->getLabel() + "\t" + toString(count)); mothurOutEndLine(); - process(list); - - processedLabels.insert(list->getLabel()); - userLabels.erase(list->getLabel()); - } - - - lastLabel = list->getLabel(); - - delete list; - list = input->getSharedListVector(); - count++; - } - - //output error messages about any remaining user labels - set::iterator it; - bool needToRun = false; - for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); - if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); - needToRun = true; - }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); - } - } - - //run last line if you need to - if (needToRun == true) { - delete list; - list = input->getSharedListVector(lastLabel); - - mothurOut(list->getLabel() + "\t" + toString(count)); mothurOutEndLine(); - process(list); - delete list; - } - - globaldata->gSharedList = NULL; - //delete list vectors to fill with parsed data - for (it2 = mapOfLists.begin(); it2 != mapOfLists.end(); it2++) { - delete it2->second; - } - for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { - delete it2->second; - } - - delete input; globaldata->ginput = NULL; - delete read; - - - return 0; - } - catch(exception& e) { - errorOut(e, "ParseListCommand", "execute"); - exit(1); - } -} -//********************************************************************************************************************** - -ParseListCommand::~ParseListCommand(){ - - -} -//********************************************************************************************************************** -void ParseListCommand::process(SharedListVector* thisList) { - try { - string seq; - - for(int i=0; isize(); i++) { - parse(i, thisList); //parses data[i] list of sequence names - for (it=listGroups.begin(); it != listGroups.end(); it++) { //loop through map and set new list vectors - seq = it->second; - seq = seq.substr(1, seq.length()); //rips off extra comma - mapOfLists[it->first]->push_back(seq); //sets new listvector for each group - } - listGroups.clear(); - } - //prints each new list file - for (int i=0; igetNumGroups(); i++) { - openOutputFileAppend(fileroot + groupMap->namesOfGroups[i] + ".list", *(filehandles[groupMap->namesOfGroups[i]])); - mapOfLists[groupMap->namesOfGroups[i]]->setLabel(thisList->getLabel()); - mapOfLists[groupMap->namesOfGroups[i]]->print(*(filehandles[groupMap->namesOfGroups[i]])); - mapOfLists[groupMap->namesOfGroups[i]]->clear(); - (*(filehandles[groupMap->namesOfGroups[i]])).close(); - } - - } - catch(exception& e) { - errorOut(e, "ParseListCommand", "process"); - exit(1); - } -} diff --git a/parselistcommand.h b/parselistcommand.h deleted file mode 100644 index 9e9e968..0000000 --- a/parselistcommand.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef PARSELISTCOMMAND_H -#define PARSELISTCOMMAND_H -/* - * parselistcommand.h - * Dotur - * - * Created by Sarah Westcott on 1/2/09. - * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "command.hpp" -#include "rabundvector.hpp" -#include "sharedlistvector.h" -#include "inputdata.h" -#include "groupmap.h" -#include "readotu.h" - - -/* The parselist() command: - The parselist command is similar to the shared command. - It parses a list file and separates it into groups. It outputs a .list file for each group. - The parselist command parameter options are listfile and groupfile. - The parselist command should be in the following format: parselist(listfile=yourListFile, groupfile=yourGroupFile). - The listfile parameter and groupfile paramater are required. */ - -class GlobalData; - -class ParseListCommand : public Command { - -public: - ParseListCommand(); - ~ParseListCommand(); - int execute(); - void help() {} - -private: - GlobalData* globaldata; - GroupMap* groupMap; - InputData* input; - ReadOTUFile* read; - map filehandles; - map mapOfLists; - SharedListVector* list; - map listGroups; //maps group name to sequences from that group in a specific OTU - map::iterator it; - map::iterator it2; - map::iterator it3; - void parse(int, SharedListVector*); - void process(SharedListVector*); - string fileroot; -}; - -#endif diff --git a/readotucommand.cpp b/readotucommand.cpp index 07fe251..bb866ed 100644 --- a/readotucommand.cpp +++ b/readotucommand.cpp @@ -158,10 +158,6 @@ int ReadOtuCommand::execute(){ if (globaldata->getFormat() == "shared") { - parselist = new ParseListCommand(); - parselist->execute(); - delete parselist; - shared = new SharedCommand(); shared->execute(); delete shared; diff --git a/readotucommand.h b/readotucommand.h index e07dadc..6ec3541 100644 --- a/readotucommand.h +++ b/readotucommand.h @@ -14,7 +14,6 @@ #include "inputdata.h" #include "groupmap.h" #include "sharedcommand.h" -#include "parselistcommand.h" /* The read.otu must be run before you execute a collect.single, rarefaction.single, summary.single, collect.shared, rarefaction.shared or summary.shared command. Mothur will generate a .list, .rabund and .sabund @@ -43,7 +42,6 @@ private: //ReadOTUFile* read; InputData* input; Command* shared; - Command* parselist; GroupMap* groupMap; string filename, listfile, orderfile, sharedfile, line, label, groupfile, sabundfile, rabundfile, format; diff --git a/sharedcommand.cpp b/sharedcommand.cpp index 4857a34..26ba221 100644 --- a/sharedcommand.cpp +++ b/sharedcommand.cpp @@ -20,6 +20,25 @@ SharedCommand::SharedCommand(){ filename = getRootName(filename); filename = filename + "shared"; openOutputFile(filename, out); + + groupMap = globaldata->gGroupmap; + + //fill filehandles with neccessary ofstreams + int i; + ofstream* temp; + for (i=0; igetNumGroups(); i++) { + temp = new ofstream; + filehandles[groupMap->namesOfGroups[i]] = temp; + } + + //set fileroot + fileroot = getRootName(globaldata->getListFile()); + + //clears file before we start to write to it below + for (int i=0; igetNumGroups(); i++) { + remove((fileroot + groupMap->namesOfGroups[i] + ".rabund").c_str()); + } + } catch(exception& e) { errorOut(e, "SharedCommand", "SharedCommand"); @@ -31,7 +50,6 @@ SharedCommand::SharedCommand(){ int SharedCommand::execute(){ try { - mothurOut("creating sharedfile..."); mothurOutEndLine(); //lookup.clear(); int count = 1; string errorOff = "no error"; @@ -55,7 +73,10 @@ int SharedCommand::execute(){ if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(SharedList->getLabel()) == 1){ + lookup = SharedList->getSharedRAbundVector(); + mothurOut(lookup[0]->getLabel() + "\t" + toString(count)); mothurOutEndLine(); + printSharedData(lookup); //prints info to the .shared file for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } @@ -69,6 +90,8 @@ int SharedCommand::execute(){ SharedList = input->getSharedListVector(lastLabel); //get new list vector to process lookup = SharedList->getSharedRAbundVector(); + mothurOut(lookup[0]->getLabel() + "\t" + toString(count)); mothurOutEndLine(); + printSharedData(lookup); //prints info to the .shared file for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } @@ -100,6 +123,8 @@ int SharedCommand::execute(){ SharedList = input->getSharedListVector(lastLabel); //get new list vector to process lookup = SharedList->getSharedRAbundVector(); + mothurOut(lookup[0]->getLabel() + "\t" + toString(count)); mothurOutEndLine(); + printSharedData(lookup); //prints info to the .shared file for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } delete SharedList; @@ -110,7 +135,11 @@ int SharedCommand::execute(){ out.close(); - mothurOut("complete."); mothurOutEndLine(); + for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { + delete it3->second; + } + + return 0; } catch(exception& e) { @@ -126,6 +155,11 @@ void SharedCommand::printSharedData(vector thislookup) { for (int i = 0; i < thislookup.size(); i++) { out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t'; thislookup[i]->print(out); + + openOutputFileAppend(fileroot + thislookup[i]->getGroup() + ".rabund", *(filehandles[thislookup[i]->getGroup()])); + (*filehandles[thislookup[i]->getGroup()]) << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t'; + thislookup[i]->print(*(filehandles[thislookup[i]->getGroup()])); + (*(filehandles[thislookup[i]->getGroup()])).close(); } } diff --git a/sharedcommand.h b/sharedcommand.h index ca0ddd8..3467c7b 100644 --- a/sharedcommand.h +++ b/sharedcommand.h @@ -37,11 +37,12 @@ private: ReadOTUFile* read; SharedListVector* SharedList; InputData* input; - //map::iterator it; - //vector lookup; + GroupMap* groupMap; ofstream out; - string filename; + string filename, fileroot; bool firsttime; + map filehandles; + map::iterator it3; };