]> git.donarmstrong.com Git - mothur.git/commitdiff
added name parameter to phylotype command
authorwestcott <westcott>
Tue, 27 Apr 2010 18:53:09 +0000 (18:53 +0000)
committerwestcott <westcott>
Tue, 27 Apr 2010 18:53:09 +0000 (18:53 +0000)
phylosummary.cpp
phylotypecommand.cpp
phylotypecommand.h

index 1e8d1bc6c6b2497b85838aeebd4c31c30104a70d..a5f67c082945a9955feb2897e16b242d60533ffa 100644 (file)
@@ -126,8 +126,8 @@ int PhyloSummary::addSeqToTree(string seqName, string seqTaxonomy){
                                tree[currentNode].total++;
 
                                currentNode = childPointer->second;
-                       }else{                                                                                  //otherwise, create it
-                               m->mothurOut("Error: cannot find taxonomy in tree for " + seqName + "."); m->mothurOutEndLine();
+                       }else{  //otherwise, error
+                               m->mothurOut("Warning: cannot find taxon " + taxon + " in reference taxonomy tree at level " + toString(tree[currentNode].level) + " for " + seqName + ". This may cause totals of daughter levels not to add up in summary file."); m->mothurOutEndLine();
                                seqTaxonomy = "";
                        }
                        
index 1828eb193c0a6e0dcc625df9cc36ef7fb78f931c..d04c9604170cf0d5c0f440132d25747b9193ba4c 100644 (file)
@@ -24,7 +24,7 @@ PhylotypeCommand::PhylotypeCommand(string option)  {
                else {
                        
                        //valid paramters for this command
-                       string AlignArray[] =  {"taxonomy","cutoff","label","outputdir","inputdir"};
+                       string AlignArray[] =  {"taxonomy","cutoff","label","name","outputdir","inputdir"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -50,6 +50,14 @@ PhylotypeCommand::PhylotypeCommand(string option)  {
                                        //if the user has not given a path then, add inputdir. else leave path alone.
                                        if (path == "") {       parameters["taxonomy"] = inputDir + it->second;         }
                                }
+                               
+                               it = parameters.find("name");
+                               //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["name"] = inputDir + it->second;             }
+                               }
                        }
 
                        taxonomyFileName = validParameter.validFile(parameters, "taxonomy", true);
@@ -59,6 +67,11 @@ PhylotypeCommand::PhylotypeCommand(string option)  {
                                abort = true; 
                        }else if (taxonomyFileName == "not open") { abort = true; }     
                        
+                       namefile = validParameter.validFile(parameters, "name", true);
+                       if (namefile == "not open") { abort = true; }
+                       else if (namefile == "not found") { namefile = ""; }
+                       else { readNamesFile(); }       
+                       
                        //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 = ""; 
@@ -187,7 +200,15 @@ int PhylotypeCommand::execute(){
                                        
                                        //make the names compatable with listvector
                                        string name = "";
-                                       for (int i = 0; i < names.size(); i++) {  name += names[i] + ",";       }
+                                       for (int i = 0; i < names.size(); i++) {  
+                                               if (namefile != "") {   
+                                                       map<string, string>::iterator itNames = namemap.find(names[i]);  //make sure this name is in namefile
+               
+                                                       if (itNames != namemap.end()) {  name += namemap[names[i]] + ",";   } //you found it in namefile
+                                                       else { m->mothurOut(names[i] + " is not in your namefile, please correct."); m->mothurOutEndLine(); exit(1);  }
+                                                       
+                                               }else{   name += names[i] + ",";        }
+                                       }
                                        name = name.substr(0, name.length()-1);  //rip off extra ','
                                        
                                        //add bin to list vector
@@ -244,4 +265,32 @@ int PhylotypeCommand::execute(){
                exit(1);
        }
 }
+/*****************************************************************/
+int PhylotypeCommand::readNamesFile() {
+       try {
+                               
+               ifstream in;
+               openInputFile(namefile, in);
+               
+               string first, second;
+               map<string, string>::iterator itNames;
+               
+               while(!in.eof()) {
+                       in >> first >> second; gobble(in);
+                       
+                       itNames = namemap.find(first);
+                       if (itNames == namemap.end()) {  
+                               namemap[first] = second; 
+                       }else {  m->mothurOut(first + " has already been seen in namefile, disregarding names file."); m->mothurOutEndLine(); in.close(); namemap.clear(); namefile = ""; return 1; }                   
+               }
+               in.close();
+               
+               return 0;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "PhylotypeCommand", "readNamesFile");
+               exit(1);
+       }
+}
+
 /**********************************************************************************************************************/
index b61c03939492fe4147225fadb159e00b9a0ef71e..c5aea714714d2f95e5f57ced3fb8289f3039a481 100644 (file)
@@ -26,13 +26,16 @@ public:
        
 private:
        bool abort, allLines;
-       string taxonomyFileName, label, outputDir;
+       string taxonomyFileName, label, outputDir, namefile;
        set<string> labels; //holds labels to be used
        int cutoff;
+       map<string, string> namemap;
        
        map<int, int> currentNodes;
        map<int, int> parentNodes;
        map<int, int>::iterator itCurrent;
+       
+       int readNamesFile();
 
 };