From: westcott Date: Mon, 19 Jul 2010 16:20:25 +0000 (+0000) Subject: added ordergroup parameter to read.otu X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=5df1b242d9c2b604eb414da44b28de81d52567d7 added ordergroup parameter to read.otu --- diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index a3e57af..74520c4 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -544,8 +544,6 @@ A7DA2174113FECD400BF472F /* validparameter.h */, A7DA2175113FECD400BF472F /* venn.cpp */, A7DA2176113FECD400BF472F /* venn.h */, - 7E84528511EF4BEB00564975 /* seqerrorcommand.h */, - 7E84528611EF4BEB00564975 /* seqerrorcommand.cpp */, ); name = mothur; sourceTree = ""; @@ -792,6 +790,8 @@ A7DA20FA113FECD400BF472F /* secondarystructurecommand.cpp */, 7EA299BA11E384940022D8D3 /* sensspeccommand.h */, 7EA299BB11E384940022D8D3 /* sensspeccommand.cpp */, + 7E84528511EF4BEB00564975 /* seqerrorcommand.h */, + 7E84528611EF4BEB00564975 /* seqerrorcommand.cpp */, A7DA20FD113FECD400BF472F /* seqsummarycommand.h */, A7DA20FC113FECD400BF472F /* seqsummarycommand.cpp */, A7DA2103113FECD400BF472F /* setdircommand.h */, diff --git a/globaldata.cpp b/globaldata.cpp index 69dccb5..affa463 100644 --- a/globaldata.cpp +++ b/globaldata.cpp @@ -26,6 +26,7 @@ string GlobalData::getSabundFile() { return sabundfile; } string GlobalData::getNameFile() { return namefile; } string GlobalData::getGroupFile() { return groupfile; } string GlobalData::getOrderFile() { return orderfile; } +string GlobalData::getOrderGroupFile() { return ordergroup; } string GlobalData::getTreeFile() { return treefile; } string GlobalData::getSharedFile() { return sharedfile; } string GlobalData::getFormat() { return format; } @@ -40,6 +41,7 @@ void GlobalData::setGroupFile(string file) { groupfile = file; } void GlobalData::setSharedFile(string file) { sharedfile = file; inputFileName = file; } void GlobalData::setNameFile(string file) { namefile = file; } void GlobalData::setOrderFile(string file) { orderfile = file; } +void GlobalData::setOrderGroupFile(string file) { ordergroup = file; } void GlobalData::setFormat(string Format) { format = Format; } @@ -77,6 +79,7 @@ void GlobalData::clear() { namefile = ""; //do we need this? groupfile = ""; //do we need this? orderfile = ""; + ordergroup = ""; // fastafile = ""; //do we need this? treefile = ""; sharedfile = ""; diff --git a/globaldata.hpp b/globaldata.hpp index 35415c7..301527a 100644 --- a/globaldata.hpp +++ b/globaldata.hpp @@ -58,6 +58,7 @@ public: string getNameFile(); //do we need this? string getGroupFile(); //do we need this? string getOrderFile(); + string getOrderGroupFile(); string getTreeFile(); string getSharedFile(); string getFormat(); //do we need this? @@ -73,6 +74,7 @@ public: void setSabundFile(string); void setSharedFile(string); void setOrderFile(string file); + void setOrderGroupFile(string file); void setFormat(string); //do we need this? NameAssignment* nameMap; @@ -85,7 +87,7 @@ public: private: MothurOut* m; - string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, treefile, sharedfile, format, distfile; + string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, treefile, sharedfile, format, distfile, ordergroup; static GlobalData* _uniqueInstance; GlobalData( const GlobalData& ); // Disable copy constructor diff --git a/makefile b/makefile index 3f0893c..b3bc136 100644 --- a/makefile +++ b/makefile @@ -13,7 +13,7 @@ CXXFLAGS += -O3 -MOTHUR_FILES = "\"Enter_your_default_path_here\"" +MOTHUR_FILES = "\"/Users/SarahsWork/desktop//Release\"" ifeq ($(strip $(MOTHUR_FILES)),"\"Enter_your_default_path_here\"") else CXXFLAGS += -DMOTHUR_FILES=${MOTHUR_FILES} diff --git a/readotucommand.cpp b/readotucommand.cpp index 30dc553..c4bf523 100644 --- a/readotucommand.cpp +++ b/readotucommand.cpp @@ -21,7 +21,7 @@ ReadOtuCommand::ReadOtuCommand(string option) { else { //valid paramters for this command - string Array[] = {"list","order","shared", "label","group","sabund", "rabund","groups","outputdir","inputdir"}; + string Array[] = {"list","order","shared", "label","group","sabund", "rabund","groups","ordergroup","outputdir","inputdir"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); OptionParser parser(option); @@ -89,6 +89,14 @@ ReadOtuCommand::ReadOtuCommand(string option) { //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["rabund"] = inputDir + it->second; } } + + it = parameters.find("ordergroup"); + //user has given a template file + if(it != parameters.end()){ + path = 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; } + } } @@ -112,6 +120,11 @@ ReadOtuCommand::ReadOtuCommand(string option) { else if (rabundfile == "not found") { rabundfile = ""; } else { globaldata->setRabundFile(rabundfile); globaldata->setFormat("rabund");} + ordergroupfile = validParameter.validFile(parameters, "ordergroup", true); + if (ordergroupfile == "not open") { abort = true; } + else if (ordergroupfile == "not found") { ordergroupfile = ""; } + else { globaldata->setOrderGroupFile(ordergroupfile); } + sharedfile = validParameter.validFile(parameters, "shared", true); if (sharedfile == "not open") { abort = true; } else if (sharedfile == "not found") { sharedfile = ""; } @@ -180,8 +193,8 @@ ReadOtuCommand::ReadOtuCommand(string option) { void ReadOtuCommand::help(){ try { m->mothurOut("The read.otu command must be run before you execute a collect.single, rarefaction.single, summary.single, \n"); - m->mothurOut("collect.shared, rarefaction.shared or summary.shared command. Mothur will generate a .list, .rabund and .sabund upon completion of the cluster command \n"); - m->mothurOut("or you may use your own. The read.otu command parameter options are list, rabund, sabund, shared, group, order, label and groups.\n"); + m->mothurOut("collect.shared, rarefaction.shared, summary.shared heatmap.bin, heatmap.sim or venn command. Mothur will generate a .list, .rabund and .sabund upon completion of the cluster command \n"); + m->mothurOut("or you may use your own. The read.otu command parameter options are list, rabund, sabund, shared, group, order, ordergroup, label and groups.\n"); m->mothurOut("The read.otu command can be used in two ways. The first is to read a list, rabund or sabund and run the collect.single, rarefaction.single or summary.single.\n"); m->mothurOut("For this use the read.otu command should be in the following format: read.otu(list=yourListFile, order=yourOrderFile, label=yourLabels).\n"); m->mothurOut("The list, rabund or sabund parameter is required, but you may only use one of them.\n"); @@ -191,6 +204,7 @@ void ReadOtuCommand::help(){ m->mothurOut("The list parameter and group paramaters or the shared paremeter is required. When using the command the second way with a list and group file read.otu command parses the .list file\n"); m->mothurOut("and separates it into groups. It outputs a .shared file containing the OTU information for each group. The read.otu command also outputs a .rabund file for each group. \n"); m->mothurOut("You can use the groups parameter to choose only specific groups to be used in the .shared and .rabund files. \n"); + m->mothurOut("You can use the ordergroup parameter to provide a file containing a list of group names in the order you would like them to appear in your shared file. \n"); m->mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n"); } diff --git a/readotucommand.h b/readotucommand.h index beb2f4b..b5e32d8 100644 --- a/readotucommand.h +++ b/readotucommand.h @@ -29,7 +29,7 @@ private: InputData* input; Command* shared; GroupMap* groupMap; - string filename, listfile, orderfile, sharedfile, label, groupfile, sabundfile, rabundfile, format, groups, outputDir; + string filename, listfile, orderfile, sharedfile, label, groupfile, sabundfile, rabundfile, format, groups, outputDir, ordergroupfile; vector Groups; bool abort, allLines; diff --git a/sffinfocommand.cpp b/sffinfocommand.cpp index 37ab0ba..07334f6 100644 --- a/sffinfocommand.cpp +++ b/sffinfocommand.cpp @@ -148,9 +148,16 @@ SffInfoCommand::SffInfoCommand(string option) { void SffInfoCommand::help(){ try { - m->mothurOut("The sffinfo command reads a sff file and outputs a .sff.txt file.\n"); - - m->mothurOut("Example sffinfo(sff=...).\n"); + m->mothurOut("The sffinfo command reads a sff file and extracts the sequence data.\n"); + m->mothurOut("The sffinfo command parameters are sff, fasta, qfile, accnos, flow, sfftxt, and trim. sff is required. \n"); + m->mothurOut("The sff parameter allows you to enter the sff file you would like to extract data from. You may enter multiple files by separating them by -'s.\n"); + m->mothurOut("The fasta parameter allows you to indicate if you would like a fasta formatted file generated. Default=True. \n"); + m->mothurOut("The qfile parameter allows you to indicate if you would like a quality file generated. Default=True. \n"); + m->mothurOut("The flow parameter allows you to indicate if you would like a flowgram file generated. Default=False. \n"); + m->mothurOut("The sfftxt parameter allows you to indicate if you would like a sff.txt file generated. Default=False. \n"); + m->mothurOut("The trim parameter allows you to indicate if you would like a sequences and quality scores trimmed to the clipQualLeft and clipQualRight values. Default=True. \n"); + m->mothurOut("The accnos parameter allows you to provide a accnos file containing the names of the sequences you would like extracted. You may enter multiple files by separating them by -'s. \n"); + m->mothurOut("Example sffinfo(sff=mySffFile.sff, trim=F).\n"); m->mothurOut("Note: No spaces between parameter labels (i.e. sff), '=' and parameters (i.e.yourSffFileName).\n\n"); } catch(exception& e) { diff --git a/sharedcommand.cpp b/sharedcommand.cpp index 91bb8e1..195996e 100644 --- a/sharedcommand.cpp +++ b/sharedcommand.cpp @@ -71,6 +71,9 @@ int SharedCommand::execute(){ string errorOff = "no error"; //errorOff = ""; + //if user provided an order file containing the order the shared file should be in read it + if (globaldata->getOrderGroupFile() != "") { readOrderFile(); } + //read in listfile read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); @@ -280,18 +283,46 @@ int SharedCommand::execute(){ void SharedCommand::printSharedData(vector thislookup) { try { - sort(thislookup.begin(), thislookup.end(), compareSharedRabunds); - - //initialize bin values - for (int i = 0; i < thislookup.size(); i++) { -//cout << "in printData " << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << endl; - out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t'; - thislookup[i]->print(out); + if (order.size() == 0) { //user has not specified an order so do aplabetically + sort(thislookup.begin(), thislookup.end(), compareSharedRabunds); + + //initialize bin values + for (int i = 0; i < thislookup.size(); i++) { + out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t'; + thislookup[i]->print(out); + + RAbundVector rav = thislookup[i]->getRAbundVector(); + openOutputFileAppend(fileroot + thislookup[i]->getGroup() + ".rabund", *(filehandles[thislookup[i]->getGroup()])); + rav.print(*(filehandles[thislookup[i]->getGroup()])); + (*(filehandles[thislookup[i]->getGroup()])).close(); + } + }else{ + //create a map from groupName to each sharedrabund + map myMap; + map::iterator myIt; + + for (int i = 0; i < thislookup.size(); i++) { + myMap[thislookup[i]->getGroup()] = thislookup[i]; + } + - RAbundVector rav = thislookup[i]->getRAbundVector(); - openOutputFileAppend(fileroot + thislookup[i]->getGroup() + ".rabund", *(filehandles[thislookup[i]->getGroup()])); - rav.print(*(filehandles[thislookup[i]->getGroup()])); - (*(filehandles[thislookup[i]->getGroup()])).close(); + //loop through ordered list and print the rabund + for (int i = 0; i < order.size(); i++) { + myIt = myMap.find(order[i]); + + if(myIt != myMap.end()) { //we found it + out << (myIt->second)->getLabel() << '\t' << (myIt->second)->getGroup() << '\t'; + (myIt->second)->print(out); + + RAbundVector rav = (myIt->second)->getRAbundVector(); + openOutputFileAppend(fileroot + (myIt->second)->getGroup() + ".rabund", *(filehandles[(myIt->second)->getGroup()])); + rav.print(*(filehandles[(myIt->second)->getGroup()])); + (*(filehandles[(myIt->second)->getGroup()])).close(); + }else{ + m->mothurOut("Can't find shared info for " + order[i] + ", skipping."); m->mothurOutEndLine(); + } + } + } } @@ -458,7 +489,32 @@ SharedCommand::~SharedCommand(){ } - +//********************************************************************************************************************** +int SharedCommand::readOrderFile() { + try { + //remove old names + order.clear(); + + ifstream in; + openInputFile(globaldata->getOrderGroupFile(), in); + string thisGroup; + + while(!in.eof()){ + in >> thisGroup; gobble(in); + + order.push_back(thisGroup); + + if (m->control_pressed) { order.clear(); break; } + } + in.close(); + + return 0; + } + catch(exception& e) { + m->errorOut(e, "SharedCommand", "readOrderFile"); + exit(1); + } +} //********************************************************************************************************************** bool SharedCommand::isValidGroup(string groupname, vector groups) { diff --git a/sharedcommand.h b/sharedcommand.h index 399f3d3..0f3e7ef 100644 --- a/sharedcommand.h +++ b/sharedcommand.h @@ -34,6 +34,7 @@ public: private: void printSharedData(vector); int createMisMatchFile(); + int readOrderFile(); bool isValidGroup(string, vector); int eliminateZeroOTUS(vector&); @@ -42,7 +43,7 @@ private: SharedListVector* SharedList; InputData* input; GroupMap* groupMap; - vector groups, outputNames; + vector groups, outputNames, order; ofstream out; string filename, fileroot, outputDir; bool firsttime, pickedGroups;