]> git.donarmstrong.com Git - mothur.git/commitdiff
added ordergroup parameter to read.otu
authorwestcott <westcott>
Mon, 19 Jul 2010 16:20:25 +0000 (16:20 +0000)
committerwestcott <westcott>
Mon, 19 Jul 2010 16:20:25 +0000 (16:20 +0000)
Mothur.xcodeproj/project.pbxproj
globaldata.cpp
globaldata.hpp
makefile
readotucommand.cpp
readotucommand.h
sffinfocommand.cpp
sharedcommand.cpp
sharedcommand.h

index a3e57afdee5fb693f9dc9d96b3bf646982aff7d3..74520c4da64f35434b89bb742e2bdd6c0e366288 100644 (file)
                                A7DA2174113FECD400BF472F /* validparameter.h */,
                                A7DA2175113FECD400BF472F /* venn.cpp */,
                                A7DA2176113FECD400BF472F /* venn.h */,
-                               7E84528511EF4BEB00564975 /* seqerrorcommand.h */,
-                               7E84528611EF4BEB00564975 /* seqerrorcommand.cpp */,
                        );
                        name = mothur;
                        sourceTree = "<group>";
                                A7DA20FA113FECD400BF472F /* secondarystructurecommand.cpp */,
                                7EA299BA11E384940022D8D3 /* sensspeccommand.h */,
                                7EA299BB11E384940022D8D3 /* sensspeccommand.cpp */,
+                               7E84528511EF4BEB00564975 /* seqerrorcommand.h */,
+                               7E84528611EF4BEB00564975 /* seqerrorcommand.cpp */,
                                A7DA20FD113FECD400BF472F /* seqsummarycommand.h */,
                                A7DA20FC113FECD400BF472F /* seqsummarycommand.cpp */,
                                A7DA2103113FECD400BF472F /* setdircommand.h */,
index 69dccb5226638a3af2a2bb9936b774f6dc90169e..affa4636ab4716746665b6b7c73ccccf1f7b9354 100644 (file)
@@ -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              =       "";
index 35415c70c874039c99c758c24a77b7b43eeb6079..301527a3f9b1e07d7f82ecbd4a04778ec0f39c37 100644 (file)
@@ -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
index 3f0893c5ad82d811fb4c5cf05f86f0326b4561c8..b3bc136f1b57cbf5f4e96954a4d7350452cbbef6 100644 (file)
--- 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}
index 30dc55343d46e0656c7123aba7afddea7f4b3a77..c4bf523fb30be6f1bd84dc81eac85e3e92c9e6f8 100644 (file)
@@ -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<string> 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");
 
        }
index beb2f4bcbfe31ed89bdb2f9c393585a4ffae3667..b5e32d897b2dd824d81b257fff12517a6a90bc6f 100644 (file)
@@ -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<string> Groups;
 
        bool abort, allLines;
index 37ab0ba8fe01887c026311b7f03838b67dba563f..07334f656d3aaff14c653a14a38d1e0eac38bba9 100644 (file)
@@ -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) {
index 91bb8e19604d3d9446016c4b9eaf82f566172c0a..195996e50d41ff81953f5715704964398b9715e9 100644 (file)
@@ -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<SharedRAbundVector*> 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<string, SharedRAbundVector*> myMap;
+                       map<string, SharedRAbundVector*>::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<string> groups) {
index 399f3d3966bf828ec32cd790dd0d7d14c7e08c25..0f3e7ef2289b39f9ab4807ccda5cbe179ff51d04 100644 (file)
@@ -34,6 +34,7 @@ public:
 private:
        void printSharedData(vector<SharedRAbundVector*>);
        int createMisMatchFile();
+       int readOrderFile();
        bool isValidGroup(string, vector<string>);
        int eliminateZeroOTUS(vector<SharedRAbundVector*>&);
        
@@ -42,7 +43,7 @@ private:
        SharedListVector* SharedList;
        InputData* input;
        GroupMap* groupMap;
-       vector<string> groups, outputNames;
+       vector<string> groups, outputNames, order;
        ofstream out;
        string filename, fileroot, outputDir;
        bool firsttime, pickedGroups;