]> git.donarmstrong.com Git - mothur.git/blobdiff - parsimonycommand.cpp
added sequence name to error string in fastq.info. Changed np_shannon to npshannon.
[mothur.git] / parsimonycommand.cpp
index a8c2d156be775455c729d9341386ecfb952323e4..2d46efc9efebcfbe7807292cb814cf58686f9ac4 100644 (file)
@@ -43,7 +43,7 @@ string ParsimonyCommand::getHelpString(){
                helpString += "Example parsimony(random=out, iters=500).\n";
                helpString += "The default value for random is "" (meaning you want to use the trees in your inputfile, randomtree=out means you just want the random distribution of trees outputted to out.rd_parsimony),\n";
                helpString += "and iters is 1000.  The parsimony command output two files: .parsimony and .psummary their descriptions are in the manual.\n";
-               helpString += "Note: No spaces between parameter labels (i.e. random), '=' and parameters (i.e.yourOutputFilename).\n\n";
+               helpString += "Note: No spaces between parameter labels (i.e. random), '=' and parameters (i.e.yourOutputFilename).\n";
                return helpString;
        }
        catch(exception& e) {
@@ -74,6 +74,7 @@ ParsimonyCommand::ParsimonyCommand(string option)  {
                        
                //allow user to run help
                if(option == "help") { help(); abort = true; calledHelp = true; }
+               else if(option == "citation") { citation(); abort = true; calledHelp = true;}
                
                else {
                        vector<string> myArray = setParameters();
@@ -125,6 +126,10 @@ ParsimonyCommand::ParsimonyCommand(string option)  {
                        }
                        
                        m->runParse = true;
+                       m->clearGroups();
+                       m->clearAllGroups();
+                       m->Treenames.clear();
+                       m->names.clear();
                        
                        outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = ""; }
                        
@@ -134,21 +139,23 @@ ParsimonyCommand::ParsimonyCommand(string option)  {
                        if (randomtree == "")  {
                                //check for required parameters
                                treefile = validParameter.validFile(parameters, "tree", true);
-                               if (treefile == "not open") { abort = true; }
+                               if (treefile == "not open") { treefile = ""; abort = true; }
                                else if (treefile == "not found") {                             //if there is a current design file, use it
                                        treefile = m->getTreeFile(); 
                                        if (treefile != "") { m->mothurOut("Using " + treefile + " as input file for the tree parameter."); m->mothurOutEndLine(); }
                                        else {  m->mothurOut("You have no current tree file and the tree parameter is required."); m->mothurOutEndLine(); abort = true; }                                                               
-                               }       
+                               }else { m->setTreeFile(treefile); }     
                                
                                //check for required parameters
                                groupfile = validParameter.validFile(parameters, "group", true);
                                if (groupfile == "not open") { abort = true; }
                                else if (groupfile == "not found") { groupfile = ""; }
+                               else { m->setGroupFile(groupfile); }
                                
                                namefile = validParameter.validFile(parameters, "name", true);
-                               if (namefile == "not open") { abort = true; }
+                               if (namefile == "not open") { namefile = ""; abort = true; }
                                else if (namefile == "not found") { namefile = ""; }
+                               else { m->setNameFile(namefile); }
                        }
                        
                        //if the user changes the output directory command factory will send this info to us in the output parameter 
@@ -157,18 +164,23 @@ ParsimonyCommand::ParsimonyCommand(string option)  {
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
                        groups = validParameter.validFile(parameters, "groups", false);                 
-                       if (groups == "not found") { groups = ""; m->Groups.clear(); }
+                       if (groups == "not found") { groups = ""; m->clearGroups(); }
                        else { 
                                m->splitAtDash(groups, Groups);
-                               m->Groups = Groups;
+                               m->setGroups(Groups);
                        }
                                
                        itersString = validParameter.validFile(parameters, "iters", false);                     if (itersString == "not found") { itersString = "1000"; }
-                       convert(itersString, iters); 
+                       m->mothurConvert(itersString, iters); 
                        
                        string temp = validParameter.validFile(parameters, "processors", false);        if (temp == "not found"){       temp = m->getProcessors();      }
                        m->setProcessors(temp);
-                       convert(temp, processors);
+                       m->mothurConvert(temp, processors);
+                       
+                       if (namefile == "") {
+                               vector<string> files; files.push_back(treefile);
+                               parser.getNameFile(files);
+                       }
                        
                }
 
@@ -188,6 +200,9 @@ int ParsimonyCommand::execute() {
                //randomtree will tell us if user had their own treefile or if they just want the random distribution
                //user has entered their own tree
                if (randomtree == "") { 
+                       
+                       m->setTreeFile(treefile);
+                       
                        if (groupfile != "") {
                                //read in group map info.
                                tmap = new TreeMap(groupfile);
@@ -209,7 +224,7 @@ int ParsimonyCommand::execute() {
                        read->AssembleTrees();
                        T = read->getTrees();
                        delete read;
-                       
+
                        //make sure all files match
                        //if you provide a namefile we will use the numNames in the namefile as long as the number of unique match the tree names size.
                        int numNamesInTree;
@@ -231,8 +246,8 @@ int ParsimonyCommand::execute() {
                                        
                                        if (m->control_pressed) { 
                                                delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; }
-                                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } outputTypes.clear();
-                                               m->Groups.clear();
+                                               for (int i = 0; i < outputNames.size(); i++) {  m->mothurRemove(outputNames[i]); } outputTypes.clear();
+                                               m->clearGroups();
                                                return 0;
                                        }
                                        
@@ -270,8 +285,11 @@ int ParsimonyCommand::execute() {
                        
                //set users groups to analyze
                util = new SharedUtil();
-               util->setGroups(m->Groups, tmap->namesOfGroups, allGroups, numGroups, "parsimony");     //sets the groups the user wants to analyze
-               util->getCombos(groupComb, m->Groups, numComp);
+               vector<string> mGroups = m->getGroups();
+               vector<string> tGroups = tmap->getNamesOfGroups();
+               util->setGroups(mGroups, tGroups, allGroups, numGroups, "parsimony");   //sets the groups the user wants to analyze
+               util->getCombos(groupComb, mGroups, numComp);
+               m->setGroups(mGroups);
                delete util;
                        
                if (numGroups == 1) { numComp++; groupComb.push_back(allGroups); }
@@ -286,8 +304,8 @@ int ParsimonyCommand::execute() {
                        delete reading; delete pars; delete output;
                        delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; }
                        if (randomtree == "") {  outSum.close();  }
-                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } outputTypes.clear();
-                       m->Groups.clear();
+                       for (int i = 0; i < outputNames.size(); i++) {  m->mothurRemove(outputNames[i]); } outputTypes.clear();
+                       m->clearGroups();
                        return 0;
                }
                        
@@ -311,8 +329,8 @@ int ParsimonyCommand::execute() {
                                        delete reading; delete pars; delete output;
                                        delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; }
                                        if (randomtree == "") {  outSum.close();  }
-                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } outputTypes.clear();
-                                       m->Groups.clear();
+                                       for (int i = 0; i < outputNames.size(); i++) {  m->mothurRemove(outputNames[i]); } outputTypes.clear();
+                                       m->clearGroups();
                                        return 0;
                                }
 
@@ -349,9 +367,9 @@ int ParsimonyCommand::execute() {
                                if (m->control_pressed) { 
                                        delete reading; delete pars; delete output; delete randT;
                                        if (randomtree == "") {  outSum.close();  }
-                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } outputTypes.clear();
+                                       for (int i = 0; i < outputNames.size(); i++) {  m->mothurRemove(outputNames[i]); } outputTypes.clear();
                                        delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; }
-                                       m->Groups.clear();
+                                       m->clearGroups();
                                        return 0;
                                }
                                        
@@ -387,8 +405,8 @@ int ParsimonyCommand::execute() {
                                if (m->control_pressed) { 
                                        delete reading; delete pars; delete output; delete randT;
                                        delete tmap; 
-                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } outputTypes.clear();
-                                       m->Groups.clear();
+                                       for (int i = 0; i < outputNames.size(); i++) {  m->mothurRemove(outputNames[i]); } outputTypes.clear();
+                                       m->clearGroups();
                                        return 0;
                                }
 
@@ -399,8 +417,8 @@ int ParsimonyCommand::execute() {
                                if (m->control_pressed) { 
                                        delete reading; delete pars;  delete output; delete randT;
                                        delete tmap; 
-                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } outputTypes.clear();
-                                       m->Groups.clear();
+                                       for (int i = 0; i < outputNames.size(); i++) {  m->mothurRemove(outputNames[i]); } outputTypes.clear();
+                                       m->clearGroups();
                                        return 0;
                                }
                        
@@ -456,8 +474,8 @@ int ParsimonyCommand::execute() {
                                delete reading; delete pars; delete output;
                                delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; }
                                if (randomtree == "") {  outSum.close();  }
-                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } outputTypes.clear();
-                               m->Groups.clear();
+                               for (int i = 0; i < outputNames.size(); i++) {  m->mothurRemove(outputNames[i]); } outputTypes.clear();
+                               m->clearGroups();
                                return 0;
                }
                
@@ -470,12 +488,12 @@ int ParsimonyCommand::execute() {
                if (randomtree == "") { printUSummaryFile(); }
                
                //reset groups parameter
-               m->Groups.clear(); 
+               m->clearGroups(); 
                
                delete pars; delete output; 
                delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; }
                
-               if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        remove(outputNames[i].c_str()); } outputTypes.clear(); return 0;}
+               if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0;}
                
                m->mothurOutEndLine();
                m->mothurOut("Output File Names: "); m->mothurOutEndLine();
@@ -575,6 +593,7 @@ void ParsimonyCommand::getUserInput() {
                count = 1;
                numEachGroup.resize(numGroups, 0);  
                
+               
                for (int i = 1; i <= numGroups; i++) {
                        m->mothurOut("Please enter the number of sequences in group " + toString(i) +  ": ");
                        cin >> num;
@@ -582,7 +601,7 @@ void ParsimonyCommand::getUserInput() {
                                
                        //set tmaps seqsPerGroup
                        tmap->seqsPerGroup[toString(i)] = num;
-                       tmap->namesOfGroups.push_back(toString(i));
+                       tmap->addGroup(toString(i));
                        
                        //set tmaps namesOfSeqs
                        for (int j = 0; j < num; j++) {