]> git.donarmstrong.com Git - mothur.git/commitdiff
modifications to commands to add headers to list file.
authorSarah Westcott <mothur.westcott@gmail.com>
Fri, 18 Oct 2013 18:34:29 +0000 (14:34 -0400)
committerSarah Westcott <mothur.westcott@gmail.com>
Fri, 18 Oct 2013 18:34:29 +0000 (14:34 -0400)
24 files changed:
Mothur.xcodeproj/project.pbxproj
commandfactory.cpp
commandfactory.hpp
getotulabelscommand.cpp
getseqscommand.cpp
makefile
mothurout.cpp
mothurout.h
parselistscommand.cpp
parselistscommand.h
phylotypecommand.cpp
primerdesigncommand.cpp
primerdesigncommand.h
removegroupscommand.cpp
removelineagecommand.cpp
removeotulabelscommand.cpp
removeotuscommand.cpp
removerarecommand.cpp
removeseqscommand.cpp
sensspeccommand.cpp
seqnoise.cpp
splitabundcommand.cpp
subsamplecommand.cpp
subsamplecommand.h

index a26db6132837d72ef08bce41b1e06d971c321865..2314b5dc1469993f1d60473d7828a4e1fda633ee 100644 (file)
                                GCC_ENABLE_SSE3_EXTENSIONS = NO;
                                GCC_ENABLE_SSE41_EXTENSIONS = NO;
                                GCC_ENABLE_SSE42_EXTENSIONS = NO;
-                               GCC_OPTIMIZATION_LEVEL = s;
+                               GCC_OPTIMIZATION_LEVEL = 3;
                                GCC_PREPROCESSOR_DEFINITIONS = (
                                        "MOTHUR_FILES=\"\\\"../../release\\\"\"",
                                        "VERSION=\"\\\"1.31.0\\\"\"",
                                GCC_C_LANGUAGE_STANDARD = gnu99;
                                GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
                                GCC_MODEL_TUNING = "";
-                               GCC_OPTIMIZATION_LEVEL = s;
+                               GCC_OPTIMIZATION_LEVEL = 3;
                                GCC_PREPROCESSOR_DEFINITIONS = (
-                                       "VERSION=\"\\\"1.32.0\\\"\"",
-                                       "RELEASE_DATE=\"\\\"10/01/2013\\\"\"",
+                                       "VERSION=\"\\\"1.32.1\\\"\"",
+                                       "RELEASE_DATE=\"\\\"10/16/2013\\\"\"",
                                );
                                GCC_VERSION = "";
                                GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
index 8ab0a9529ba697aece318c7e11301f9e465b19c3..c247f908ca190087e4a30bb05ea31d88a0e7fd6b 100644 (file)
@@ -408,7 +408,7 @@ Command* CommandFactory::getCommand(string commandName, string optionString){
                        else { optionString += "inputdir=" + inputDir; }
                }
                
-               if(commandName == "cluster")                            {       command = new ClusterCommand(optionString);                                     }
+               if(commandName == "cluster")                    {       command = new ClusterCommand(optionString);                                     }
                else if(commandName == "unique.seqs")                   {       command = new DeconvoluteCommand(optionString);                         }
                else if(commandName == "parsimony")                             {       command = new ParsimonyCommand(optionString);                           }
                else if(commandName == "help")                                  {       command = new HelpCommand(optionString);                                        }
index 36e8f462b146fc7846ee6cf9ead1eb42e9757a36..eb85c68513bc43ece5cf9802917ebe336bc03d5a 100644 (file)
@@ -27,8 +27,8 @@ public:
        bool isValidCommand(string, string);\r
        void printCommands(ostream&);\r
     void printCommandsCategories(ostream&);\r
-       void setOutputDirectory(string o)               {       outputDir = o;  m->setOutputDir(o);     }\r
-       void setInputDirectory(string i)                {       inputDir = i;           }\r
+       void setOutputDirectory(string o)               {       if(m->dirCheck(o) || (o == "")) {  outputDir = o; m->setOutputDir(o); } }\r
+       void setInputDirectory(string i)                {       if(m->dirCheck(i) || (i == "")) {  inputDir = i;        }       }\r
        void setLogfileName(string n, bool a)   {       logFileName = n;  append = a;           }\r
        string getLogfileName()                                 {       return logFileName;     }\r
        bool getAppend()                                                {       return append;                  }\r
index 452d7f605cdf489e03196ab2237dc187f63fa26c..a1413d244171ea6fa6d68c58969cce4afa86d1b6 100644 (file)
@@ -521,7 +521,6 @@ int GetOtuLabelsCommand::readList(){
         newList.setLabel(list->getLabel());
         int selectedCount = 0;
         bool wroteSomething = false;
-        string snumBins = toString(list->getNumBins());
         
         vector<string> binLabels = list->getLabels();
         vector<string> newLabels;
index 44c4042073636f1c3419075dfcacea8bdd4f72e9..a1cf493f9e515f91ed962726b392426db9efd978 100644 (file)
@@ -737,8 +737,8 @@ int GetSeqsCommand::readList(){
                 m->splitAtComma(binnames, bnames);
                                
                                string newNames = "";
-                for (int i = 0; i < bnames.size(); i++) {
-                                       string name = bnames[i];
+                for (int j = 0; j < bnames.size(); j++) {
+                                       string name = bnames[j];
                                        //if that name is in the .accnos file, add it
                                        if (names.count(name) != 0) {  newNames += name + ",";  selectedCount++; if (m->debug) { sanity["list"].insert(name); } }
                                }
index 7fc8608be4176f7e8360ea58ee36412e074bdae5..42e71a0e42bb0341c3cff63a8c616d6572537f4b 100644 (file)
--- a/makefile
+++ b/makefile
@@ -15,8 +15,8 @@ USEREADLINE ?= yes
 CYGWIN_BUILD ?= no
 USECOMPRESSION ?= no
 MOTHUR_FILES="\"Enter_your_default_path_here\""
-RELEASE_DATE = "\"10/01/2013\""
-VERSION = "\"1.32.0\""
+RELEASE_DATE = "\"10/16/2013\""
+VERSION = "\"1.32.1\""
 FORTAN_COMPILER = gfortran
 FORTRAN_FLAGS = 
 
index 66ee704dd59d0221d1a0a7a40de65ecf42d762b2..e7f0c8e3b764c66362f0004b7dbabc4f4c6fdaa3 100644 (file)
@@ -797,7 +797,7 @@ bool MothurOut::dirCheck(string& dirName){
 
         //test to make sure directory exists
         dirName = getFullPathName(dirName);
-        string outTemp = dirName + tag + "temp";
+        string outTemp = dirName + tag + "temp"+ toString(time(NULL));
         ofstream out;
         out.open(outTemp.c_str(), ios::trunc);
         if(!out) {
index ee602f404bd102f46f41214a3c3d938a51730a0c..1caa1fe5814679a86e8026f1ec7a54d228dee44e 100644 (file)
@@ -66,11 +66,9 @@ class MothurOut {
        
                vector<string> getAllGroups() { sort(namesOfGroups.begin(), namesOfGroups.end()); return namesOfGroups; }
                vector<string> Treenames;
-               //map<string, string> names;
                vector<string> sharedBinLabelsInFile;
                vector<string> currentSharedBinLabels;
         vector<string> listBinLabelsInFile;
-        //vector<string> currentListBinLabels;
                string saveNextLabel, argv, sharedHeaderMode, groupMode;
                bool printedSharedHeaders, printedListHeaders, commandInputsConvertError, changedSeqNames, modifyNames;
                
index 32a7e0828ff143d8f414bacf66c52a205bbf27c7..cfd1b6b9705ccb131e050ce132547192892d12ea 100644 (file)
@@ -53,7 +53,7 @@ string ParseListCommand::getOutputPattern(string type) {
     try {
         string pattern = "";
         
-        if (type == "list") {  pattern = "[filename],[group],list"; } 
+        if (type == "list") {  pattern = "[filename],[group],[distance],list"; } 
         else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true;  }
         
         return pattern;
@@ -205,27 +205,6 @@ int ParseListCommand::execute(){
        
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
                
-               //set fileroot
-               map<string, string> variables; 
-        variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile));
-               
-               //fill filehandles with neccessary ofstreams
-               int i;
-               ofstream* temp;
-               vector<string> gGroups;
-        if (groupfile != "") { gGroups = groupMap->getNamesOfGroups(); }
-        else { gGroups = ct.getNamesOfGroups(); }
-        
-               for (i=0; i<gGroups.size(); i++) {
-                       temp = new ofstream;
-                       filehandles[gGroups[i]] = temp;
-                       
-            variables["[group]"] = gGroups[i];
-                       string filename = getOutputFileName("list",variables);
-                       outputNames.push_back(filename); outputTypes["list"].push_back(filename);
-                       m->openOutputFile(filename, *temp);
-               }
-               
                //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
                set<string> processedLabels;
                set<string> userLabels = labels;        
@@ -236,16 +215,13 @@ int ParseListCommand::execute(){
                
                if (m->control_pressed) { 
                        delete list; if (groupfile != "") { delete groupMap; }
-                       for (i=0; i<gGroups.size(); i++) {  (*(filehandles[gGroups[i]])).close();  delete filehandles[gGroups[i]]; } 
-                       for (int i = 0; i < outputNames.size(); i++) {  m->mothurRemove(outputNames[i]); } outputTypes.clear();
-                       return 0;
+                       for (int i = 0; i < outputNames.size(); i++) {  m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0;
                }
                
                while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
                
                        if (m->control_pressed) { 
                                delete list; if (groupfile != "") { delete groupMap; }
-                               for (i=0; i<gGroups.size(); i++) {  (*(filehandles[gGroups[i]])).close();  delete filehandles[gGroups[i]]; } 
                                for (int i = 0; i < outputNames.size(); i++) {  m->mothurRemove(outputNames[i]); } outputTypes.clear();
                                return 0;
                        }
@@ -283,7 +259,6 @@ int ParseListCommand::execute(){
                
                if (m->control_pressed) { 
                        if (groupfile != "") { delete groupMap; }
-                       for (i=0; i<gGroups.size(); i++) {  (*(filehandles[gGroups[i]])).close();  delete filehandles[gGroups[i]]; } 
                        for (int i = 0; i < outputNames.size(); i++) {  m->mothurRemove(outputNames[i]); } outputTypes.clear();
                        return 0;
                }
@@ -304,7 +279,6 @@ int ParseListCommand::execute(){
                
                if (m->control_pressed) { 
                        if (groupfile != "") { delete groupMap; }
-                       for (i=0; i<gGroups.size(); i++) {  (*(filehandles[gGroups[i]])).close();  delete filehandles[gGroups[i]]; } 
                        for (int i = 0; i < outputNames.size(); i++) {  m->mothurRemove(outputNames[i]); } outputTypes.clear();
                        return 0;
                }
@@ -320,11 +294,6 @@ int ParseListCommand::execute(){
                        delete list;
                }
                
-               for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
-                       (*(filehandles[it3->first])).close();
-                       delete it3->second;
-               }
-               
                if (groupfile != "") { delete groupMap; }
                
                if (m->control_pressed) { 
@@ -354,8 +323,33 @@ int ParseListCommand::execute(){
 /**********************************************************************************************************************/
 int ParseListCommand::parse(ListVector* thisList) {
        try {
+        map<string, ofstream*> filehandles;
+        map<string, ofstream*>::iterator it3;
+        
+        //set fileroot
+               map<string, string> variables;
+        variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile));
+        variables["[distance]"] = thisList->getLabel();
+               
+               //fill filehandles with neccessary ofstreams
+               ofstream* temp;
+               vector<string> gGroups;
+        if (groupfile != "") { gGroups = groupMap->getNamesOfGroups(); }
+        else { gGroups = ct.getNamesOfGroups(); }
+        
+               for (int i=0; i<gGroups.size(); i++) {
+                       temp = new ofstream;
+                       filehandles[gGroups[i]] = temp;
+                       
+            variables["[group]"] = gGroups[i];
+                       string filename = getOutputFileName("list",variables);
+                       m->openOutputFile(filename, *temp);
+            outputNames.push_back(filename); outputTypes["list"].push_back(filename);
+               }
+
        
                map<string, string> groupVector;
+        map<string, string> groupLabels;
                map<string, string>::iterator itGroup;
                map<string, int> groupNumBins;
                
@@ -363,11 +357,12 @@ int ParseListCommand::parse(ListVector* thisList) {
                for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
                        groupNumBins[it3->first] = 0;
                        groupVector[it3->first] = "";
+            groupLabels[it3->first] = "label\tnumOtus\t";
                }
 
-               
+               vector<string> binLabels = thisList->getLabels();
                for (int i = 0; i < thisList->getNumBins(); i++) {
-                       if (m->control_pressed) { return 0; }
+                       if (m->control_pressed) { break; }
                        
                        map<string, string> groupBins;
                        string bin = list->get(i); 
@@ -408,14 +403,26 @@ int ParseListCommand::parse(ListVector* thisList) {
                        
                        //print parsed bin info to files
                        for (itGroup = groupBins.begin(); itGroup != groupBins.end(); itGroup++) {
-                               groupVector[itGroup->first] +=  itGroup->second + '\t'; 
+                               groupVector[itGroup->first] +=  itGroup->second + '\t';
+                groupLabels[itGroup->first] +=  binLabels[i] + '\t';
                        }
                
                }
                
+        if (m->control_pressed) {
+            for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
+                (*(filehandles[it3->first])).close();
+                delete it3->second;
+            }
+            return 0;
+        }
+        
                //end list vector
                for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
+            (*(filehandles[it3->first])) << groupLabels[it3->first] << endl;
                        (*(filehandles[it3->first])) << thisList->getLabel() << '\t' << groupNumBins[it3->first] << '\t' << groupVector[it3->first] << endl;  // label numBins  listvector for that group
+            (*(filehandles[it3->first])).close();
+            delete it3->second;
                }
                
                return 0;
index 84abc85d46e0bc3fddd916a0095c4b45aa44dbd1..48b53a69d8141efbedc7373de2d770d53bace282 100644 (file)
@@ -47,9 +47,6 @@ private:
        set<string> labels;
        bool abort, allLines;
        vector<string> outputNames;
-       
-       map<string, ofstream*> filehandles;
-       map<string, ofstream*>::iterator it3;
 
 };
 
index 16117053fc7c0a8147c7f00fcdd935324ff66edb..b21865abb54472b29473a76e2a9898939f7904c5 100644 (file)
@@ -303,7 +303,9 @@ int PhylotypeCommand::execute(){
                                }       
                                
                                //print listvector
-                               list.print(outList);
+                               if (!m->printedListHeaders) { list.printHeaders(outList); }
+                list.print(outList);
+                
                 if (countfile == "") {
                     //print rabund
                     list.getRAbundVector().print(outRabund);
index 960da85e8ce7ab4922f6afc38c728f2be5288ca2..bd68e2c97721b4451f7fe51a559a22a50710885f 100644 (file)
@@ -20,7 +20,7 @@ vector<string> PrimerDesignCommand::setParameters(){
         CommandParameter pmintm("mintm", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(pmintm);
         CommandParameter pmaxtm("maxtm", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(pmaxtm);
         CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false); parameters.push_back(pprocessors);
-        CommandParameter potunumber("otunumber", "Number", "", "-1", "", "", "","",false,true,true); parameters.push_back(potunumber);
+        CommandParameter potunumber("otulabel", "String", "", "", "", "", "","",false,true,true); parameters.push_back(potunumber);
         CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "","",false,false,true); parameters.push_back(ppdiffs);
         CommandParameter pcutoff("cutoff", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pcutoff);
                CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
@@ -40,13 +40,13 @@ string PrimerDesignCommand::getHelpString(){
        try {
                string helpString = "";
                helpString += "The primer.design allows you to identify sequence fragments that are specific to particular OTUs.\n";
-               helpString += "The primer.design command parameters are: list, fasta, name, count, otunumber, cutoff, length, pdiffs, mintm, maxtm, processors and label.\n";
+               helpString += "The primer.design command parameters are: list, fasta, name, count, otulabel, cutoff, length, pdiffs, mintm, maxtm, processors and label.\n";
                helpString += "The list parameter allows you to provide a list file and is required.\n";
         helpString += "The fasta parameter allows you to provide a fasta file and is required.\n";
         helpString += "The name parameter allows you to provide a name file associated with your fasta file.\n";
         helpString += "The count parameter allows you to provide a count file associated with your fasta file.\n";
         helpString += "The label parameter is used to indicate the label you want to use from your list file.\n";
-        helpString += "The otunumber parameter is used to indicate the otu you want to use from your list file. It is required.\n";
+        helpString += "The otulabel parameter is used to indicate the otu you want to use from your list file. It is required.\n";
         helpString += "The pdiffs parameter is used to specify the number of differences allowed in the primer. The default is 0.\n";
         helpString += "The length parameter is used to indicate the length of the primer. The default is 18.\n";
         helpString += "The mintm parameter is used to indicate minimum melting temperature.\n";
@@ -216,9 +216,8 @@ PrimerDesignCommand::PrimerDesignCommand(string option)  {
             temp = validParameter.validFile(parameters, "maxtm", false);  if (temp == "not found") { temp = "-1"; }
                        m->mothurConvert(temp, maxTM); 
             
-            temp = validParameter.validFile(parameters, "otunumber", false);  if (temp == "not found") { temp = "-1"; }
-                       m->mothurConvert(temp, otunumber); 
-            if (otunumber < 1) {  m->mothurOut("[ERROR]: You must provide an OTU number, aborting.\n"); abort = true; }
+            otulabel = validParameter.validFile(parameters, "otulabel", false);  if (otulabel == "not found") { temp = ""; }
+            if (otulabel == "") {  m->mothurOut("[ERROR]: You must provide an OTU label, aborting.\n"); abort = true; }
             
             temp = validParameter.validFile(parameters, "processors", false);  if (temp == "not found"){       temp = m->getProcessors();      }
                        m->setProcessors(temp);
@@ -253,7 +252,9 @@ int PrimerDesignCommand::execute(){
         
         //reads list file and selects the label the users specified or the first label
         getListVector();
-        if (otunumber > list->getNumBins()) { m->mothurOut("[ERROR]: You selected an OTU number larger than the number of OTUs you have in your list file, quitting.\n"); return 0; }
+        vector<string> binLabels = list->getLabels();
+        int binIndex = findIndex(otulabel, binLabels);
+        if (binIndex == -1) { m->mothurOut("[ERROR]: You selected an OTU label that is not in your in your list file, quitting.\n"); return 0; }
         
         map<string, int> nameMap;
         unsigned long int numSeqs;  //used to sanity check the files. numSeqs = total seqs for namefile and uniques for count.
@@ -293,7 +294,7 @@ int PrimerDesignCommand::execute(){
         
         m->mothurOut("Done.\n\n");
         
-        set<string> primers = getPrimer(conSeqs[otunumber-1]);  
+        set<string> primers = getPrimer(conSeqs[binIndex]);
         
         if (m->control_pressed) { delete list; for (int i = 0; i < outputNames.size(); i++) {  m->mothurRemove(outputNames[i]); } return 0; }
         
@@ -302,7 +303,7 @@ int PrimerDesignCommand::execute(){
         ofstream outSum;
         m->openOutputFile(consSummaryFile, outSum);
         
-        outSum << "PrimerOtu: " << otunumber << " Members: " << list->get(otunumber-1) << endl << "Primers\tminTm\tmaxTm" << endl;
+        outSum << "PrimerOtu: " << otulabel << " Members: " << list->get(binIndex) << endl << "Primers\tminTm\tmaxTm" << endl;
         
         //find min and max melting points
         vector<double> minTms;
@@ -339,7 +340,7 @@ int PrimerDesignCommand::execute(){
         outSum.close();
         
         //check each otu's conseq for each primer in otunumber
-        set<int> otuToRemove = createProcesses(consSummaryFile, minTms, maxTms, primers, conSeqs);
+        set<int> otuToRemove = createProcesses(consSummaryFile, minTms, maxTms, primers, conSeqs, binIndex);
         
         if (m->control_pressed) { delete list; for (int i = 0; i < outputNames.size(); i++) {  m->mothurRemove(outputNames[i]); } return 0; }
         
@@ -348,21 +349,29 @@ int PrimerDesignCommand::execute(){
         mvariables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile));
         mvariables["[extension]"] = m->getExtension(listfile);
         string newListFile = getOutputFileName("list", mvariables);
-        outputNames.push_back(newListFile); outputTypes["list"].push_back(newListFile);
-        ofstream outList;
-        m->openOutputFile(newListFile, outList);
+        ofstream outListTemp;
+        m->openOutputFile(newListFile+".temp", outListTemp);
         
-        outList << list->getLabel() << '\t' << (list->getNumBins()-otuToRemove.size()) << '\t';
+        outListTemp << list->getLabel() << '\t' << (list->getNumBins()-otuToRemove.size()) << '\t';
+        string headers = "label\tnumOtus\t";
         for (int j = 0; j < list->getNumBins(); j++) {
             if (m->control_pressed) { break; }
             //good otus
             if (otuToRemove.count(j) == 0) {  
                 string bin = list->get(j);
-                if (bin != "") {  outList << bin << '\t';  } 
+                if (bin != "") {  outListTemp << bin << '\t';  headers += binLabels[j] + '\t'; }
             }
         }
-        outList << endl;
+        outListTemp << endl;
+        outListTemp.close();
+        
+        ofstream outList;
+        m->openOutputFile(newListFile, outList);
+        outList << headers << endl;
         outList.close();
+        m->appendFiles(newListFile+".temp", newListFile);
+        m->mothurRemove(newListFile+".temp");
+        outputNames.push_back(newListFile); outputTypes["list"].push_back(newListFile);
         
         if (m->control_pressed) { delete list; for (int i = 0; i < outputNames.size(); i++) {  m->mothurRemove(outputNames[i]); } return 0; }
         
@@ -525,7 +534,7 @@ set<string> PrimerDesignCommand::getPrimer(Sequence primerSeq){
        }
 }
 /**************************************************************************************************/
-set<int> PrimerDesignCommand::createProcesses(string newSummaryFile, vector<double>& minTms, vector<double>& maxTms, set<string>& primers, vector<Sequence>& conSeqs) {
+set<int> PrimerDesignCommand::createProcesses(string newSummaryFile, vector<double>& minTms, vector<double>& maxTms, set<string>& primers, vector<Sequence>& conSeqs, int binIndex) {
        try {
                
                vector<int> processIDS;
@@ -560,7 +569,7 @@ set<int> PrimerDesignCommand::createProcesses(string newSummaryFile, vector<doub
                 //clear old file because we append in driver
                 m->mothurRemove(newSummaryFile + toString(getpid()) + ".temp");
                 
-                               otusToRemove = driver(newSummaryFile + toString(getpid()) + ".temp", minTms, maxTms, primers, conSeqs, lines[process].start, lines[process].end, numBinsProcessed);
+                               otusToRemove = driver(newSummaryFile + toString(getpid()) + ".temp", minTms, maxTms, primers, conSeqs, lines[process].start, lines[process].end, numBinsProcessed, binIndex);
                 
                 string tempFile = toString(getpid()) + ".otus2Remove.temp";
                 ofstream outTemp;
@@ -580,7 +589,7 @@ set<int> PrimerDesignCommand::createProcesses(string newSummaryFile, vector<doub
                }
                
                //do my part
-               otusToRemove = driver(newSummaryFile, minTms, maxTms, primers, conSeqs, lines[0].start, lines[0].end, numBinsProcessed);
+               otusToRemove = driver(newSummaryFile, minTms, maxTms, primers, conSeqs, lines[0].start, lines[0].end, numBinsProcessed, binIndex);
                
                //force parent to wait until all the processes are done
                for (int i=0;i<processIDS.size();i++) { 
@@ -624,7 +633,7 @@ set<int> PrimerDesignCommand::createProcesses(string newSummaryFile, vector<doub
                        string extension = toString(i) + ".temp";
                        m->mothurRemove(newSummaryFile+extension);
             
-                       primerDesignData* tempPrimer = new primerDesignData((newSummaryFile+extension), m, lines[i].start, lines[i].end, minTms, maxTms, primers, conSeqs, pdiffs, otunumber, length, i);
+                       primerDesignData* tempPrimer = new primerDesignData((newSummaryFile+extension), m, lines[i].start, lines[i].end, minTms, maxTms, primers, conSeqs, pdiffs, binIndex, length, i);
                        pDataArray.push_back(tempPrimer);
                        processIDS.push_back(i);
                        
@@ -635,7 +644,7 @@ set<int> PrimerDesignCommand::createProcesses(string newSummaryFile, vector<doub
                
         
                //using the main process as a worker saves time and memory
-               otusToRemove = driver(newSummaryFile, minTms, maxTms, primers, conSeqs, lines[0].start, lines[0].end, numBinsProcessed);
+               otusToRemove = driver(newSummaryFile, minTms, maxTms, primers, conSeqs, lines[0].start, lines[0].end, numBinsProcessed, binIndex);
                
                //Wait until all threads have terminated.
                WaitForMultipleObjects(processors-1, hThreadArray, TRUE, INFINITE);
@@ -668,7 +677,7 @@ set<int> PrimerDesignCommand::createProcesses(string newSummaryFile, vector<doub
        }
 }
 //**********************************************************************************************************************
-set<int> PrimerDesignCommand::driver(string summaryFileName, vector<double>& minTms, vector<double>& maxTms, set<string>& primers, vector<Sequence>& conSeqs, int start, int end, int& numBinsProcessed){
+set<int> PrimerDesignCommand::driver(string summaryFileName, vector<double>& minTms, vector<double>& maxTms, set<string>& primers, vector<Sequence>& conSeqs, int start, int end, int& numBinsProcessed, int binIndex){
        try {
         set<int> otuToRemove;
         
@@ -679,7 +688,7 @@ set<int> PrimerDesignCommand::driver(string summaryFileName, vector<double>& min
         
             if (m->control_pressed) { break; }
             
-            if (i != (otunumber-1)) {
+            if (i != (binIndex)) {
                 int primerIndex = 0;
                 for (set<string>::iterator it = primers.begin(); it != primers.end(); it++) {
                     vector<int> primerStarts;
@@ -1236,6 +1245,21 @@ int PrimerDesignCommand::countDiffs(string oligo, string seq){
        }
 }
 //**********************************************************************************************************************
+int PrimerDesignCommand::findIndex(string binLabel, vector<string> binLabels){
+       try {
+        int index = -1;
+        for (int i = 0; i < binLabels.size(); i++){
+            if (m->control_pressed) { return index; }
+            if (m->isLabelEquivalent(binLabel, binLabels[i])) { index = i; break; }
+        }
+        return index;
+    }
+       catch(exception& e) {
+               m->errorOut(e, "PrimerDesignCommand", "findIndex");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
 
 
 
index 2879d2b47003b2c166c7d7b3d5887d2e62a0843d..ff1ddf23ca8edf0438e240c25c69baaa4dcd96b1 100644 (file)
@@ -50,8 +50,8 @@ private:
        };
     
     bool abort, allLines, large;
-    int cutoff, pdiffs, length, otunumber, processors, alignedLength;
-    string outputDir, listfile, namefile, countfile, fastafile, label;
+    int cutoff, pdiffs, length, processors, alignedLength;
+    string outputDir, listfile, otulabel, namefile, countfile, fastafile, label;
     double minTM, maxTM;
     ListVector* list;
     vector<string> outputNames;
@@ -65,10 +65,11 @@ private:
     bool findPrimer(string, string, vector<int>&, vector<int>&, vector<int>&);
     int findMeltingPoint(string primer, double&, double&);
     
-    set<int> createProcesses(string, vector<double>&, vector<double>&, set<string>&, vector<Sequence>&);
-    set<int> driver(string, vector<double>&, vector<double>&, set<string>&, vector<Sequence>&, int, int, int&);
+    set<int> createProcesses(string, vector<double>&, vector<double>&, set<string>&, vector<Sequence>&, int);
+    set<int> driver(string, vector<double>&, vector<double>&, set<string>&, vector<Sequence>&, int, int, int&, int);
     vector< vector< vector<unsigned int> > > driverGetCounts(map<string, int>&, unsigned long int&, vector<unsigned int>&, unsigned long long&, unsigned long long&);
     vector<Sequence> createProcessesConSeqs(map<string, int>&, unsigned long int&);
+    int findIndex(string binLabel, vector<string> binLabels);
     
 };
 
@@ -81,7 +82,7 @@ struct primerDesignData {
        MothurOut* m;
        int start;
        int end;
-       int pdiffs, threadID, otunumber, length;
+       int pdiffs, threadID,  length, binIndex;
        set<string> primers;
        vector<double> minTms, maxTms;
     set<int> otusToRemove;
@@ -99,7 +100,7 @@ struct primerDesignData {
         maxTms = max;
         primers = pri;
         consSeqs = seqs;
-        otunumber = otun;
+        binIndex = otun;
         length = l;
                threadID = tid;
         numBinsProcessed = 0;
@@ -121,7 +122,7 @@ static DWORD WINAPI MyPrimerThreadFunction(LPVOID lpParam){
             
             if (pDataArray->m->control_pressed) { break; }
             
-            if (i != (pDataArray->otunumber-1)) {
+            if (i != (pDataArray->binIndex)) {
                 int primerIndex = 0;
                 for (set<string>::iterator it = pDataArray->primers.begin(); it != pDataArray->primers.end(); it++) {
                     vector<int> primerStarts;
index 9db35cb4bcb1fb78daa9545ecf4464b29c09d2e2..42f088b953d2f3657dd98dcec4f184f87eb8a70b 100644 (file)
@@ -70,7 +70,7 @@ string RemoveGroupsCommand::getOutputPattern(string type) {
         else if (type == "count")       {   pattern = "[filename],pick,[extension]";    }
         else if (type == "list")        {   pattern = "[filename],pick,[extension]";    }
         else if (type == "shared")      {   pattern = "[filename],[tag],pick,[extension]";    }
-        else if (type == "design")      {   pattern = "[filename],pick,[extension]";    }
+        else if (type == "design")      {   pattern = "[filename],[tag],pick,[extension]";    }
         else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true;  }
         
         return pattern;
@@ -623,12 +623,7 @@ int RemoveGroupsCommand::readList(){
                map<string, string> variables; 
         variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile));
         variables["[extension]"] = m->getExtension(listfile);
-               string outputFileName = getOutputFileName("list", variables);
-
-               
-               ofstream out;
-               m->openOutputFile(outputFileName, out);
-               
+                               
                ifstream in;
                m->openInputFile(listfile, in);
                
@@ -641,6 +636,16 @@ int RemoveGroupsCommand::readList(){
                        
                        //read in list vector
                        ListVector list(in);
+            
+            variables["[tag]"] = list.getLabel();
+            string outputFileName = getOutputFileName("list", variables);
+                       
+                       ofstream out;
+                       m->openOutputFile(outputFileName, out);
+                       outputTypes["list"].push_back(outputFileName);  outputNames.push_back(outputFileName);
+            
+            vector<string> binLabels = list.getLabels();
+            vector<string> newBinLabels;
                        
                        //make a new list vector
                        ListVector newList;
@@ -681,24 +686,26 @@ int RemoveGroupsCommand::readList(){
                                //if there are names in this bin add to new list
                                if (newNames != "") {  
                                        newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
-                                       newList.push_back(newNames);    
+                                       newList.push_back(newNames);
+                    newBinLabels.push_back(binLabels[i]);
                                }
                        }
                        
                        //print new listvector
                        if (newList.getNumBins() != 0) {
                                wroteSomething = true;
+                               newList.setLabels(newBinLabels);
+                newList.printHeaders(out);
                                newList.print(out);
                        }
                        
                        m->gobble(in);
+            out.close();
                }
                in.close();     
-               out.close();
                
-               if (wroteSomething == false) {  m->mothurOut("Your file contains only sequences from the groups you wish to remove."); m->mothurOutEndLine();  }
-               outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
                
+               if (wroteSomething == false) {  m->mothurOut("Your file contains only sequences from the groups you wish to remove."); m->mothurOutEndLine();  }
                m->mothurOut("Removed " + toString(removedCount) + " sequences from your list file."); m->mothurOutEndLine();
                
                return 0;
index 761de1426f180ed84986ce012625a26cdaf04016..7349203007d90b4228502680b95b93b7ab9c3240 100644 (file)
@@ -75,7 +75,7 @@ string RemoveLineageCommand::getOutputPattern(string type) {
         else if (type == "name")            {   pattern = "[filename],pick,[extension]";    }
         else if (type == "group")           {   pattern = "[filename],pick,[extension]";    }
         else if (type == "count")           {   pattern = "[filename],pick,[extension]";    }
-        else if (type == "list")            {   pattern = "[filename],pick,[extension]-[filename],[distance],pick,[extension]";    }
+        else if (type == "list")            {   pattern = "[filename],[distance],pick,[extension]";    }
         else if (type == "shared")          {   pattern = "[filename],[distance],pick,[extension]";    }
         else if (type == "alignreport")     {   pattern = "[filename],pick.align.report";    }
         else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true;  }
@@ -481,9 +481,6 @@ int RemoveLineageCommand::readList(){
                map<string, string> variables; 
         variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile));
         variables["[extension]"] = m->getExtension(listfile);
-               string outputFileName = getOutputFileName("list", variables);   
-               ofstream out;
-               m->openOutputFile(outputFileName, out);
                
                ifstream in;
                m->openInputFile(listfile, in);
@@ -491,12 +488,25 @@ int RemoveLineageCommand::readList(){
                bool wroteSomething = false;
                
                while(!in.eof()){
+            
                        //read in list vector
                        ListVector list(in);
                        
                        //make a new list vector
                        ListVector newList;
                        newList.setLabel(list.getLabel());
+            
+            variables["[distance]"] = list.getLabel();
+            string outputFileName = getOutputFileName("list", variables);
+                       
+                       ofstream out;
+                       m->openOutputFile(outputFileName, out);
+                       outputTypes["list"].push_back(outputFileName);  outputNames.push_back(outputFileName);
+            
+            if (m->control_pressed) { in.close(); out.close(); return 0; }
+            
+            vector<string> binLabels = list.getLabels();
+            vector<string> newBinLabels;
                        
                        //for each bin
                        for (int i = 0; i < list.getNumBins(); i++) {
@@ -517,23 +527,26 @@ int RemoveLineageCommand::readList(){
                                //if there are names in this bin add to new list
                                if (newNames != "") {  
                                        newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
-                                       newList.push_back(newNames);    
+                                       newList.push_back(newNames);
+                    newBinLabels.push_back(binLabels[i]);
                                }
                        }
                                
                        //print new listvector
                        if (newList.getNumBins() != 0) {
                                wroteSomething = true;
+                               newList.setLabels(newBinLabels);
+                newList.printHeaders(out);
                                newList.print(out);
                        }
                        
                        m->gobble(in);
+            out.close();
                }
                in.close();     
-               out.close();
+               
                
                if (wroteSomething == false) {  m->mothurOut("Your list file contains only sequences from " + taxons + "."); m->mothurOutEndLine();  }
-               outputNames.push_back(outputFileName); outputTypes["list"].push_back(outputFileName); 
                                
                return 0;
 
@@ -692,6 +705,8 @@ int RemoveLineageCommand::readConsList(){
         bool wroteSomething = false;
         string snumBins = toString(list->getNumBins());
         
+        vector<string> binLabels = list->getLabels();
+        vector<string> newBinLabels;
         for (int i = 0; i < list->getNumBins(); i++) {
             
             if (m->control_pressed) { delete list; return 0;}
@@ -707,6 +722,7 @@ int RemoveLineageCommand::readConsList(){
             
             if (names.count(m->getSimpleLabel(otuLabel)) == 0) {
                 newList.push_back(list->get(i));
+                newBinLabels.push_back(binLabels[i]);
             }else { removedCount++; }
         }
         
@@ -724,6 +740,8 @@ int RemoveLineageCommand::readConsList(){
         //print new listvector
         if (newList.getNumBins() != 0) {
             wroteSomething = true;
+            newList.setLabels(newBinLabels);
+            newList.printHeaders(out);
             newList.print(out);
         }
                out.close();
index a882f6bdd3cc1a5588fa4cc18476eca09e6f2153..18322f1bcb46d0eeeb698b3e759c885e8b923437 100644 (file)
@@ -518,23 +518,16 @@ int RemoveOtuLabelsCommand::readList(){
         newList.setLabel(list->getLabel());
         int removedCount = 0;
         bool wroteSomething = false;
-        string snumBins = toString(list->getNumBins());
         
+        vector<string> binLabels = list->getLabels();
+        vector<string> newLabels;
         for (int i = 0; i < list->getNumBins(); i++) {
             
             if (m->control_pressed) { delete list; return 0;}
             
-            //create a label for this otu
-            string otuLabel = "Otu";
-            string sbinNumber = toString(i+1);
-            if (sbinNumber.length() < snumBins.length()) { 
-                int diff = snumBins.length() - sbinNumber.length();
-                for (int h = 0; h < diff; h++) { otuLabel += "0"; }
-            }
-            otuLabel += sbinNumber; 
-            
-            if (labels.count(m->getSimpleLabel(otuLabel)) == 0) {
+            if (labels.count(m->getSimpleLabel(binLabels[i])) == 0) {
                 newList.push_back(list->get(i));
+                newLabels.push_back(binLabels[i]);
             }else { removedCount++; }
         }
         
@@ -552,6 +545,8 @@ int RemoveOtuLabelsCommand::readList(){
         //print new listvector
         if (newList.getNumBins() != 0) {
             wroteSomething = true;
+            newList.setLabels(newLabels);
+            newList.printHeaders(out);
             newList.print(out);
         }
                out.close();
index 16fd8dce8bab96b030a57effd81d218e122628a5..a840bba6d8d91c94cc34350e944a02aa01613ee8 100644 (file)
@@ -243,6 +243,13 @@ int RemoveOtusCommand::execute(){
 //**********************************************************************************************************************
 int RemoveOtusCommand::readListGroup(){
        try {
+        InputData* input = new InputData(listfile, "list");
+               ListVector* list = input->getListVector();
+               string lastLabel = list->getLabel();
+               
+               //using first label seen if none is provided
+               if (label == "") { label = lastLabel; }
+        
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(listfile);  }
                map<string, string> variables; 
@@ -263,13 +270,6 @@ int RemoveOtusCommand::readListGroup(){
                ofstream outGroup;
                m->openOutputFile(outputGroupFileName, outGroup);
                
-               InputData* input = new InputData(listfile, "list");
-               ListVector* list = input->getListVector();
-               string lastLabel = list->getLabel();
-               
-               //using first label seen if none is provided
-               if (label == "") { label = lastLabel; }
-               
                //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
                set<string> labels; labels.insert(label);
                set<string> processedLabels;
@@ -365,6 +365,8 @@ int RemoveOtusCommand::processList(ListVector*& list, GroupMap*& groupMap, ofstr
                
                int numOtus = 0;
                //for each bin
+        vector<string> binLabels = list->getLabels();
+        vector<string> newBinLabels;
                for (int i = 0; i < list->getNumBins(); i++) {
                        if (m->control_pressed) { return 0; }
                        
@@ -400,7 +402,8 @@ int RemoveOtusCommand::processList(ListVector*& list, GroupMap*& groupMap, ofstr
                                
                                if (!removeBin) {
                                        //if there are no sequences from the groups we want to remove in this bin add to new list, output to groupfile
-                                       newList.push_back(binnames);    
+                                       newList.push_back(binnames);
+                    newBinLabels.push_back(binLabels[i]);
                                        outGroup << groupFileOutput;
                                }else {
                                        numOtus++;
@@ -414,7 +417,9 @@ int RemoveOtusCommand::processList(ListVector*& list, GroupMap*& groupMap, ofstr
                //print new listvector
                if (newList.getNumBins() != 0) {
                        wroteSomething = true;
-                       newList.print(out);
+                       newList.setLabels(newBinLabels);
+            newList.printHeaders(out);
+            newList.print(out);
                }
                
                m->mothurOut(newList.getLabel() + " - removed " + toString(numOtus) + " of the " + toString(list->getNumBins()) + " OTUs."); m->mothurOutEndLine();
index c378e41447013ba021935d07e76af3ae029ad1b0..24d5bef750e32e06493f7e91351bbf8af0b3099b 100644 (file)
@@ -68,7 +68,7 @@ string RemoveRareCommand::getOutputPattern(string type) {
         else if (type == "sabund")    {   pattern = "[filename],pick,[extension]";    }
         else if (type == "group")       {   pattern = "[filename],pick,[extension]";    }
         else if (type == "count")       {   pattern = "[filename],pick,[extension]";    }
-        else if (type == "list")        {   pattern = "[filename],pick,[extension]";    }
+        else if (type == "list")        {   pattern = "[filename],[tag],pick,[extension]";    }
         else if (type == "shared")      {   pattern = "[filename],[tag],pick,[extension]";    }
         else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true;  }
         
@@ -344,24 +344,7 @@ int RemoveRareCommand::execute(){
 //**********************************************************************************************************************
 int RemoveRareCommand::processList(){
        try {
-               string thisOutputDir = outputDir;
-               if (outputDir == "") {  thisOutputDir += m->hasPath(listfile);  }
-        map<string, string> variables; 
-        variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile));
-        variables["[extension]"] = m->getExtension(listfile);
-               string outputFileName = getOutputFileName("list", variables);
-        variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile));
-        variables["[extension]"] = m->getExtension(groupfile);
-               string outputGroupFileName = getOutputFileName("group", variables);
-        variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(countfile));
-        variables["[extension]"] = m->getExtension(countfile);
-        string outputCountFileName = getOutputFileName("count", variables);
-        
-               ofstream out, outGroup;
-               m->openOutputFile(outputFileName, out);
-               
-               bool wroteSomething = false;
-               
+                               
                //you must provide a label because the names in the listfile need to be consistent
                string thisLabel = "";
                if (allLines) { m->mothurOut("For the listfile you must select one label, using first label in your listfile."); m->mothurOutEndLine(); }
@@ -400,6 +383,26 @@ int RemoveRareCommand::processList(){
                                list = input.getListVector(lastLabel); 
                        }
                }
+        
+        string thisOutputDir = outputDir;
+               if (outputDir == "") {  thisOutputDir += m->hasPath(listfile);  }
+        map<string, string> variables;
+        variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile));
+        variables["[extension]"] = m->getExtension(listfile);
+        variables["[tag]"] = list->getLabel();
+               string outputFileName = getOutputFileName("list", variables);
+        variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile));
+        variables["[extension]"] = m->getExtension(groupfile);
+               string outputGroupFileName = getOutputFileName("group", variables);
+        variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(countfile));
+        variables["[extension]"] = m->getExtension(countfile);
+        string outputCountFileName = getOutputFileName("count", variables);
+        
+               ofstream out, outGroup;
+               m->openOutputFile(outputFileName, out);
+               
+               bool wroteSomething = false;
+
                
                //if groupfile is given then use it
                GroupMap* groupMap;
@@ -420,7 +423,11 @@ int RemoveRareCommand::processList(){
         }
                
                
-               if (list != NULL) {     
+               if (list != NULL) {
+            
+            vector<string> binLabels = list->getLabels();
+            vector<string> newLabels;
+            
                        //make a new list vector
                        ListVector newList;
                        newList.setLabel(list->getLabel());
@@ -479,6 +486,7 @@ int RemoveRareCommand::processList(){
 
                                if (binsize > nseqs) { //keep bin
                                        newList.push_back(saveBinNames);
+                    newLabels.push_back(binLabels[i]);
                                        if (groupfile != "") {  for(int k = 0; k < newGroupFile.size(); k++) { outGroup << newGroupFile[k] << endl; }  }
                     else if (countfile != "") { for(int k = 0; k < newGroupFile.size(); k++) {  ct.remove(newGroupFile[k]); } }  
                                }else {  if (countfile != "") {  for(int k = 0; k < names.size(); k++) {  ct.remove(names[k]); } }  }
@@ -487,7 +495,9 @@ int RemoveRareCommand::processList(){
                        //print new listvector
                        if (newList.getNumBins() != 0) {
                                wroteSomething = true;
-                               newList.print(out);
+                               newList.setLabels(newLabels);
+                newList.printHeaders(out);
+                newList.print(out);
                        }
                }       
                
index 019a659f44f446be2d3c87e5c195ab93663f1773..25d45a7c578c47167fac24164cac3322f3462772 100644 (file)
@@ -67,7 +67,7 @@ string RemoveSeqsCommand::getOutputPattern(string type) {
         else if (type == "name")        {   pattern = "[filename],pick,[extension]";    }
         else if (type == "group")       {   pattern = "[filename],pick,[extension]";    }
         else if (type == "count")       {   pattern = "[filename],pick,[extension]";    }
-        else if (type == "list")        {   pattern = "[filename],pick,[extension]";    }
+        else if (type == "list")        {   pattern = "[filename],[distance],pick,[extension]";    }
         else if (type == "qfile")       {   pattern = "[filename],pick,[extension]";    }
         else if (type == "alignreport")      {   pattern = "[filename],pick.align.report";    }
         else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true;  }
@@ -664,10 +664,7 @@ int RemoveSeqsCommand::readList(){
                map<string, string> variables; 
                variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile));
         variables["[extension]"] = m->getExtension(listfile);
-               string outputFileName = getOutputFileName("list", variables);   
-               ofstream out;
-               m->openOutputFile(outputFileName, out);
-               
+                               
                ifstream in;
                m->openInputFile(listfile, in);
                
@@ -684,48 +681,60 @@ int RemoveSeqsCommand::readList(){
                        //make a new list vector
                        ListVector newList;
                        newList.setLabel(list.getLabel());
+            
+                       variables["[distance]"] = list.getLabel();
+            string outputFileName = getOutputFileName("list", variables);
                        
+                       ofstream out;
+                       m->openOutputFile(outputFileName, out);
+                       outputTypes["list"].push_back(outputFileName);  outputNames.push_back(outputFileName);
+            
+            vector<string> binLabels = list.getLabels();
+            vector<string> newBinLabels;
+            
+            if (m->control_pressed) { in.close(); out.close();  return 0; }
+
                        //for each bin
                        for (int i = 0; i < list.getNumBins(); i++) {
                                if (m->control_pressed) { in.close();  out.close();  m->mothurRemove(outputFileName);  return 0; }
                        
                                //parse out names that are in accnos file
-                               string binnames = list.get(i);
+                               string bin = list.get(i);
+                vector<string> bnames;
+                m->splitAtComma(bin, bnames);
                                
                                string newNames = "";
-                               while (binnames.find_first_of(',') != -1) { 
-                                       string name = binnames.substr(0,binnames.find_first_of(','));
-                                       binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length());
-                                       
-                                       //if that name is in the .accnos file, add it
+                for (int j = 0; j < bnames.size(); j++) {
+                                       string name = bnames[j];
+                    //if that name is in the .accnos file, add it
                                        if (names.count(name) == 0) {  newNames += name + ",";  }
                                        else {  removedCount++;  }
-                               }
-                       
-                               //get last name
-                               if (names.count(binnames) == 0) {  newNames += binnames + ",";  }
-                               else {  removedCount++;  }
+                }
 
                                //if there are names in this bin add to new list
                                if (newNames != "") {  
                                        newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
-                                       newList.push_back(newNames);    
+                                       newList.push_back(newNames);
+                    newBinLabels.push_back(binLabels[i]);
                                }
                        }
                                
                        //print new listvector
                        if (newList.getNumBins() != 0) {
                                wroteSomething = true;
+                               newList.setLabels(newBinLabels);
+                newList.printHeaders(out);
                                newList.print(out);
+
                        }
                        
                        m->gobble(in);
+            out.close();
                }
                in.close();     
-               out.close();
+               
                
                if (wroteSomething == false) {  m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine();  }
-               outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
                
                m->mothurOut("Removed " + toString(removedCount) + " sequences from your list file."); m->mothurOutEndLine();
                
index 12786ca41c848d967ffda72e2d06f382881d8eed..5746cdabc2161d094dcde6ab24b864d69db9ee8e 100644 (file)
@@ -793,6 +793,8 @@ string SensSpecCommand::preProcessList(){
                        //make a new list vector
                        ListVector newList;
                        newList.setLabel(list.getLabel());
+            vector<string> binLabels = list.getLabels();
+            vector<string> newLabels;
                        
                        //for each bin
                        for (int i = 0; i < list.getNumBins(); i++) {
@@ -812,13 +814,16 @@ string SensSpecCommand::preProcessList(){
                                //if there are names in this bin add to new list
                                if (newNames != "") { 
                                        newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
-                                       newList.push_back(newNames);    
+                                       newList.push_back(newNames);
+                    newLabels.push_back(binLabels[i]);
                                }
                        }
             
                        //print new listvector
                        if (newList.getNumBins() != 0) {
                                wroteSomething = true;
+                newList.setLabels(newLabels);
+                if (!m->printedListHeaders) { newList.printHeaders(out); }
                                newList.print(out);
                        }
                        
index 8e7a4395fbf20009d135502fde3774b2592a9440..8c712c3ab8bb08c8b8e9282e59e97b03c77d29fc 100644 (file)
@@ -9,6 +9,8 @@
 
 #include "seqnoise.h"
 #include "sequence.hpp"
+#include "listvector.hpp"
+#include "inputdata.h"
 
 #define MIN_DELTA 1.0e-6
 #define MIN_ITER 20
@@ -138,91 +140,93 @@ int seqNoise::getListData(string listFileName, double cutOff, vector<int>& otuDa
                
                ifstream listFile;
                m->openInputFile(listFileName, listFile);
-               double threshold;
-               int numOTUs;
-               string line = "";
-               bool adjustCutoff = true;
-               
-               if(listFile.peek() == 'u'){     m->getline(listFile);   }
                
-               while(listFile){
-                       listFile >> threshold;
-                       
-                       if(threshold < cutOff){
-                               line = m->getline(listFile); m->gobble(listFile);
-                       }
-                       else{
-                               adjustCutoff = false;
-                               listFile >> numOTUs;
-                               otuFreq.resize(numOTUs, 0);
-                               
-                               for(int i=0;i<numOTUs;i++){
-                                       
-                                       if (m->control_pressed) { return 0; }
-                                       
-                                       string otu;
-                                       listFile >> otu;
-                                       
-                                       int count = 0;
-                                       
-                                       string number = "";
-                                       
-                                       for(int j=0;j<otu.size();j++){
-                                               if(otu[j] != ','){
-                                                       number += otu[j];
-                                               }
-                                               else{
-                                                       int index = atoi(number.c_str());
-                                                       otuData[index] = i;
-                                                       count++;
-                                                       number = "";
-                                               }
-                                       }
-                                       
-                                       int index = atoi(number.c_str());
-                                       otuData[index] = i;
-                                       count++;
-                                       
-                                       otuFreq[i] = count;
-                               }
-                               
-                               otuBySeqLookUp.resize(numOTUs);
-                               
-                               int numSeqs = otuData.size();
-                               
-                               for(int i=0;i<numSeqs;i++){
-                                       if (m->control_pressed) { return 0; }
-                                       otuBySeqLookUp[otuData[i]].push_back(i);
-                               }
-                               for(int i=0;i<numOTUs;i++){
-                                       if (m->control_pressed) { return 0; }
-                                       for(int j=otuBySeqLookUp[i].size();j<numSeqs;j++){
-                                               otuBySeqLookUp[i].push_back(0);
-                                       }
-                               }
-                               
-                               break;
-                       }
+               bool adjustCutoff = true;
+        string lastLabel = "";
+        
+               while(!listFile.eof()){
+            
+            ListVector list(listFile); m->gobble(listFile); //10/18/13 - change to reading with listvector to accomodate changes to the listfiel format. ie. adding header labels.
+            
+            string thisLabel = list.getLabel();
+            lastLabel = thisLabel;
+            
+            if (thisLabel == "unique") {} //skip to next label in listfile
+            else {
+                double threshold;
+                m->mothurConvert(thisLabel, threshold);
+                
+                if(threshold < cutOff){} //skip to next label in listfile
+                else{
+                    adjustCutoff = false;
+                    int numOTUs = list.getNumBins();
+                    otuFreq.resize(numOTUs, 0);
+                    
+                    for(int i=0;i<numOTUs;i++){
+                        
+                        if (m->control_pressed) { return 0; }
+                        
+                        string otu = list.get(i);
+                        int count = 0;
+                        string number = "";
+                        
+                        for(int j=0;j<otu.size();j++){
+                            if(otu[j] != ','){
+                                number += otu[j];
+                            }
+                            else{
+                                int index = atoi(number.c_str());
+                                otuData[index] = i;
+                                count++;
+                                number = "";
+                            }
+                        }
+                        
+                        int index = atoi(number.c_str());
+                        otuData[index] = i;
+                        count++;
+                        
+                        otuFreq[i] = count;
+                    }
+                    
+                    otuBySeqLookUp.resize(numOTUs);
+                    
+                    int numSeqs = otuData.size();
+                    
+                    for(int i=0;i<numSeqs;i++){
+                        if (m->control_pressed) { return 0; }
+                        otuBySeqLookUp[otuData[i]].push_back(i);
+                    }
+                    for(int i=0;i<numOTUs;i++){
+                        if (m->control_pressed) { return 0; }
+                        for(int j=otuBySeqLookUp[i].size();j<numSeqs;j++){
+                            otuBySeqLookUp[i].push_back(0);
+                        }
+                    }
+                    
+                    break;
+                }
+            }
                }
                
                listFile.close();
                
                //the listfile does not contain a threshold greater than the cutoff so use highest value
                if (adjustCutoff) {
-                       istringstream iss (line,istringstream::in);
-                       
-                       iss >> numOTUs;
-                       otuFreq.resize(numOTUs, 0);
+            
+            InputData input(listFileName, "list");
+            ListVector* list = input.getListVector(lastLabel);
+            
+            int numOTUs = list->getNumBins();
+            otuFreq.resize(numOTUs, 0);
                        
                        for(int i=0;i<numOTUs;i++){
                                
                                if (m->control_pressed) { return 0; }
                                
-                               string otu;
-                               iss >> otu;
+                               string otu = list->get(i);
                                
                                int count = 0;
-                               
                                string number = "";
                                
                                for(int j=0;j<otu.size();j++){
@@ -259,6 +263,7 @@ int seqNoise::getListData(string listFileName, double cutOff, vector<int>& otuDa
                                }
                        }
                        
+            delete list;
                }
                
                return 0;
index 0fff42804cf702b0ba74cbbe245b51a0f91c1bff..47372cce680a9fa907200db12926194afe8c6b00 100644 (file)
@@ -501,17 +501,19 @@ int SplitAbundCommand::writeList(ListVector* thisList, string tag, int numRareBi
             variables["[tag]"] = tag;
             variables["[tag2]"] = "rare";
                        string rare = getOutputFileName("list",variables);
-                       m->openOutputFile(rare, rout);
+                       m->openOutputFile(rare+".temp", rout);
                        outputNames.push_back(rare); outputTypes["list"].push_back(rare);
                        
             variables["[tag2]"] = "abund";
                        string abund = getOutputFileName("list",variables);
-                       m->openOutputFile(abund, aout);
+                       m->openOutputFile(abund+".temp", aout);
                        outputNames.push_back(abund); outputTypes["list"].push_back(abund);
 
                        if (rareNames.size() != 0)      {  rout << thisList->getLabel() << '\t' << numRareBins << '\t';         }
                        if (abundNames.size() != 0) {   aout << thisList->getLabel() << '\t' << numAbundBins << '\t';   }
-
+            
+            vector<string> binLabels = thisList->getLabels();
+            string rareHeader = "label\tnumOtus\t"; string abundHeader = "label\tnumOtus\t";
                        for (int i = 0; i < thisList->getNumBins(); i++) {
                                if (m->control_pressed) { break; }
                        
@@ -525,8 +527,8 @@ int SplitAbundCommand::writeList(ListVector* thisList, string tag, int numRareBi
                     for (int j = 0; j < names.size(); j++) {  size += ct.getNumSeqs(names[j]); }
                 }
                        
-                               if (size <= cutoff) {  rout << bin << '\t';  }
-                               else                            {  aout << bin << '\t'; }
+                               if (size <= cutoff) {  rout << bin << '\t';  rareHeader += binLabels[i] + '\t'; }
+                               else                            {  aout << bin << '\t';  abundHeader += binLabels[i] + '\t'; }
                        }
                        
                        if (rareNames.size() != 0)      { rout << endl; }
@@ -534,6 +536,21 @@ int SplitAbundCommand::writeList(ListVector* thisList, string tag, int numRareBi
                        
                        rout.close();
                        aout.close();
+            
+            //add headers
+            ofstream r;
+            m->openOutputFile(rare, r);
+            r << rareHeader << endl;
+            r.close();
+            m->appendFiles(rare+".temp", rare);
+            m->mothurRemove(rare+".temp");
+            
+            ofstream a;
+            m->openOutputFile(abund, a);
+            a << abundHeader << endl;
+            a.close();
+            m->appendFiles(abund+".temp", abund);
+            m->mothurRemove(abund+".temp");
                        
                }else{ //parse names by abundance and group
                        string fileroot =  outputDir + m->getRootName(m->getSimpleName(listfile));
@@ -564,14 +581,16 @@ int SplitAbundCommand::writeList(ListVector* thisList, string tag, int numRareBi
                        }
                        
                        map<string, string> groupVector;
+            map<string, string> groupLabels;
                        map<string, string>::iterator itGroup;
                        map<string, int> groupNumBins;
                
                        for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
                                groupNumBins[it3->first] = 0;
                                groupVector[it3->first] = "";
+                groupLabels[it3->first] = "label\tnumOtus\t";
                        }
-               
+            vector<string> binLabels = thisList->getLabels();
                        for (int i = 0; i < thisList->getNumBins(); i++) {
                                if (m->control_pressed) { break; }
                        
@@ -622,12 +641,14 @@ int SplitAbundCommand::writeList(ListVector* thisList, string tag, int numRareBi
                        
                        
                                for (itGroup = groupBins.begin(); itGroup != groupBins.end(); itGroup++) {
-                                       groupVector[itGroup->first] +=  itGroup->second + '\t'; 
+                                       groupVector[itGroup->first] +=  itGroup->second + '\t';
+                    groupLabels[itGroup->first] += binLabels[i] + '\t';
                                }
                        }
                        
                        //end list vector
                        for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
+                (*(filehandles[it3->first])) << groupLabels[it3->first] << endl;
                                (*(filehandles[it3->first])) << thisList->getLabel() << '\t' << groupNumBins[it3->first] << '\t' << groupVector[it3->first] << endl;  // label numBins  listvector for that group
                                (*(filehandles[it3->first])).close();
                                delete it3->second;
index a89d191a9127065922c3d498edce5cab41030f27..3e954759b078ff9371f5c28b64b3de86ef3c89cc 100644 (file)
@@ -76,7 +76,7 @@ string SubSampleCommand::getOutputPattern(string type) {
         else if (type == "name")        {   pattern = "[filename],subsample,[extension]";    }
         else if (type == "group")       {   pattern = "[filename],subsample,[extension]";    }
         else if (type == "count")       {   pattern = "[filename],subsample,[extension]";    }
-        else if (type == "list")        {   pattern = "[filename],subsample,[extension]";    }
+        else if (type == "list")        {   pattern = "[filename],[distance],subsample,[extension]";    }
         else if (type == "taxonomy")    {   pattern = "[filename],subsample,[extension]";    }
         else if (type == "shared")      {   pattern = "[filename],[distance],subsample,[extension]";    }
         else if (type == "rabund")      {   pattern = "[filename],subsample,[extension]";    }
@@ -993,16 +993,6 @@ int SubSampleCommand::getSubSampleList() {
         
                if (namefile != "") { m->readNames(namefile, nameMap); }
         
-               string thisOutputDir = outputDir;
-               if (outputDir == "") {  thisOutputDir += m->hasPath(listfile);  }
-               map<string, string> variables; 
-        variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile));
-        variables["[extension]"] = m->getExtension(listfile);
-               string outputFileName = getOutputFileName("list", variables);   
-               ofstream out;
-               m->openOutputFile(outputFileName, out);
-               outputTypes["list"].push_back(outputFileName);  outputNames.push_back(outputFileName);
-               
                InputData* input = new InputData(listfile, "list");
                ListVector* list = input->getListVector();
                string lastLabel = list->getLabel();
@@ -1029,7 +1019,7 @@ int SubSampleCommand::getSubSampleList() {
                        //file mismatch quit
                        if (list->getNumSeqs() != groupMap.getNumSeqs()) { 
                                m->mothurOut("[ERROR]: your list file contains " + toString(list->getNumSeqs()) + " sequences, and your groupfile contains " + toString(groupMap.getNumSeqs()) + ", please correct."); 
-                               m->mothurOutEndLine(); delete list; delete input; out.close(); outGroup.close(); return 0;
+                               m->mothurOutEndLine(); delete list; delete input;  outGroup.close(); return 0;
                        }                       
                }else if (countfile != "") {
             if (ct.hasGroupInfo()) {
@@ -1193,13 +1183,13 @@ int SubSampleCommand::getSubSampleList() {
                //as long as you are not at the end of the file or done wih the lines you want
                while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
                        
-                       if (m->control_pressed) {  delete list; delete input;  out.close();  return 0;  }
+                       if (m->control_pressed) {  delete list; delete input;  return 0;  }
                        
                        if(allLines == 1 || labels.count(list->getLabel()) == 1){                       
                                
                                m->mothurOut(list->getLabel()); m->mothurOutEndLine();
                                
-                               processList(list, out, subset);
+                               processList(list,  subset);
                                
                                processedLabels.insert(list->getLabel());
                                userLabels.erase(list->getLabel());
@@ -1213,7 +1203,7 @@ int SubSampleCommand::getSubSampleList() {
                                list = input->getListVector(lastLabel);
                                m->mothurOut(list->getLabel()); m->mothurOutEndLine();
                                
-                               processList(list, out, subset);
+                               processList(list,  subset);
                                
                                processedLabels.insert(list->getLabel());
                                userLabels.erase(list->getLabel());
@@ -1231,7 +1221,7 @@ int SubSampleCommand::getSubSampleList() {
                }
                
                
-               if (m->control_pressed) {  if (list != NULL) { delete list; } delete input; out.close(); return 0;  }
+               if (m->control_pressed) {  if (list != NULL) { delete list; } delete input;  return 0;  }
                
                //output error messages about any remaining user labels
                set<string>::iterator it;
@@ -1254,12 +1244,11 @@ int SubSampleCommand::getSubSampleList() {
                        
                        m->mothurOut(list->getLabel()); m->mothurOutEndLine();
                        
-                       processList(list, out, subset);
+                       processList(list, subset);
                        
                        delete list; list = NULL;
                }
                
-               out.close();  
                if (list != NULL) { delete list; }
                delete input;
         
@@ -1336,14 +1325,26 @@ int SubSampleCommand::getSubSampleList() {
        }
 }
 //**********************************************************************************************************************
-int SubSampleCommand::processList(ListVector*& list, ofstream& out, set<string>& subset) {
+int SubSampleCommand::processList(ListVector*& list, set<string>& subset) {
        try {
-                               
+               string thisOutputDir = outputDir;
+               if (outputDir == "") {  thisOutputDir += m->hasPath(listfile);  }
+               map<string, string> variables;
+        variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile));
+        variables["[extension]"] = m->getExtension(listfile);
+        variables["[distance]"] = list->getLabel();
+               string outputFileName = getOutputFileName("list", variables);
+               ofstream out;
+               m->openOutputFile(outputFileName, out);
+               outputTypes["list"].push_back(outputFileName);  outputNames.push_back(outputFileName);
+               
                int numBins = list->getNumBins();
 
                ListVector* temp = new ListVector();
                temp->setLabel(list->getLabel());
                
+        vector<string> binLabels = list->getLabels();
+        vector<string> newLabels;
                for (int i = 0; i < numBins; i++) {
                        
                        if (m->control_pressed) { break; }
@@ -1359,15 +1360,19 @@ int SubSampleCommand::processList(ListVector*& list, ofstream& out, set<string>&
                        if (newNames != "") { 
                                newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
                                temp->push_back(newNames);
+                newLabels.push_back(binLabels[i]);
                        }
                }
                
+        temp->setLabels(newLabels);
                delete list;
                list = temp;
                
-               if (m->control_pressed) { return 0; }
+               if (m->control_pressed) { out.close(); return 0; }
                
+        list->printHeaders(out);
                list->print(out);
+        out.close();
                
                return 0;
                
index 7b251eee11c2fa7ad5be7baa6cea4427c90265c7..db4001a5c07337d51ea96aedfa9d3f20458b6685 100644 (file)
@@ -57,7 +57,7 @@ private:
        int processShared(vector<SharedRAbundVector*>&);
        int processRabund(RAbundVector*&, ofstream&);
        int processSabund(SAbundVector*&, ofstream&);
-       int processList(ListVector*&, ofstream&, set<string>&);
+       int processList(ListVector*&, set<string>&);
        int getNames();
        int readNames();
     int getTax(set<string>&);