]> git.donarmstrong.com Git - mothur.git/blobdiff - sharedcommand.cpp
changed normalize.shared and sub.sample commands to fix bug in normalize.shared and...
[mothur.git] / sharedcommand.cpp
index cb4b4e6ced702b08d2b1dda3668f376a82e1e624..2928214c2e671e366553439504c4e78d572a1f1b 100644 (file)
@@ -73,6 +73,7 @@ SharedCommand::SharedCommand(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 {
                        
@@ -130,7 +131,7 @@ SharedCommand::SharedCommand(string option)  {
                                 listfile = m->getListFile(); 
                                 if (listfile != "") { m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); }
                                 else {         m->mothurOut("You have no current list file and the list parameter is required."); m->mothurOutEndLine(); abort = true; }
-                        }      
+                        }else { m->setListFile(listfile); }    
                                                        
                         ordergroupfile = validParameter.validFile(parameters, "ordergroup", true);
                         if (ordergroupfile == "not open") { abort = true; }    
@@ -218,7 +219,7 @@ int SharedCommand::execute(){
                
                //clears file before we start to write to it below
                for (int i=0; i<Groups.size(); i++) {
-                       remove((fileroot + Groups[i] + ".rabund").c_str());
+                       m->mothurRemove((fileroot + Groups[i] + ".rabund"));
                        outputNames.push_back((fileroot + Groups[i] + ".rabund"));
                        outputTypes["rabund"].push_back((fileroot + Groups[i] + ".rabund"));
                }
@@ -238,8 +239,8 @@ int SharedCommand::execute(){
                if (m->control_pressed) { 
                        delete input; delete SharedList; delete groupMap; 
                        for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {  delete it3->second;  }
-                       out.close(); remove(filename.c_str()); 
-                       for (int i=0; i<Groups.size(); i++) {  remove((fileroot + Groups[i] + ".rabund").c_str());              }
+                       out.close(); m->mothurRemove(filename); 
+                       for (int i=0; i<Groups.size(); i++) {  m->mothurRemove((fileroot + Groups[i] + ".rabund"));             }
                        return 0; 
                }
                                
@@ -247,7 +248,7 @@ int SharedCommand::execute(){
                        m->mothurOut("Your group file contains " + toString(groupMap->getNumSeqs()) + " sequences and list file contains " + toString(SharedList->getNumSeqs()) + " sequences. Please correct."); m->mothurOutEndLine(); 
                        
                        out.close();
-                       remove(filename.c_str()); //remove blank shared file you made
+                       m->mothurRemove(filename); //remove blank shared file you made
                        
                        createMisMatchFile();
                        
@@ -295,8 +296,8 @@ int SharedCommand::execute(){
                        if (m->control_pressed) { 
                                delete input; delete SharedList; delete groupMap;
                                for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {  delete it3->second;  }
-                               out.close(); remove(filename.c_str()); 
-                               for (int i=0; i<Groups.size(); i++) {  remove((fileroot + Groups[i] + ".rabund").c_str());              }
+                               out.close(); m->mothurRemove(filename); 
+                               for (int i=0; i<Groups.size(); i++) {  m->mothurRemove((fileroot + Groups[i] + ".rabund"));             }
                                return 0; 
                        }
                
@@ -313,11 +314,12 @@ int SharedCommand::execute(){
                                                delete input; delete SharedList; delete groupMap; 
                                                for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
                                                for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {  delete it3->second;  }
-                                               out.close(); remove(filename.c_str()); 
-                                               for (int i=0; i<Groups.size(); i++) {  remove((fileroot + Groups[i] + ".rabund").c_str());              }
+                                               out.close(); m->mothurRemove(filename); 
+                                               for (int i=0; i<Groups.size(); i++) {  m->mothurRemove((fileroot + Groups[i] + ".rabund"));             }
                                                return 0; 
                                        }
                                        
+                                       if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
                                        printSharedData(lookup); //prints info to the .shared file
                                        for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
                                
@@ -342,11 +344,12 @@ int SharedCommand::execute(){
                                                delete input; delete SharedList; delete groupMap; 
                                                for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
                                                for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {  delete it3->second;  }
-                                               out.close(); remove(filename.c_str()); 
-                                               for (int i=0; i<Groups.size(); i++) {  remove((fileroot + Groups[i] + ".rabund").c_str());              }
+                                               out.close(); m->mothurRemove(filename); 
+                                               for (int i=0; i<Groups.size(); i++) {  m->mothurRemove((fileroot + Groups[i] + ".rabund"));             }
                                                return 0; 
                                        }
                                        
+                                       if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
                                        printSharedData(lookup); //prints info to the .shared file
                                        for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
                                        
@@ -387,11 +390,12 @@ int SharedCommand::execute(){
                        if (m->control_pressed) { 
                                delete input;  delete groupMap;
                                        for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {  delete it3->second;   }
-                                       out.close(); remove(filename.c_str()); 
-                                       for (int i=0; i<Groups.size(); i++) {  remove((fileroot + Groups[i] + ".rabund").c_str());              }
+                                       out.close(); m->mothurRemove(filename); 
+                                       for (int i=0; i<Groups.size(); i++) {  m->mothurRemove((fileroot + Groups[i] + ".rabund"));             }
                                        return 0; 
                        }
                        
+                       if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
                        printSharedData(lookup); //prints info to the .shared file
                        for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
                        delete SharedList;
@@ -406,8 +410,8 @@ int SharedCommand::execute(){
                delete input; delete groupMap;
                
                if (m->control_pressed) { 
-                               remove(filename.c_str()); 
-                               for (int i=0; i<Groups.size(); i++) {  remove((fileroot + Groups[i] + ".rabund").c_str());              }
+                               m->mothurRemove(filename); 
+                               for (int i=0; i<Groups.size(); i++) {  m->mothurRemove((fileroot + Groups[i] + ".rabund"));             }
                                return 0; 
                }
                
@@ -527,6 +531,7 @@ int SharedCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thislookup) {
                                for (int j = 0; j < thislookup.size(); j++) {
                                        newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup());
                                }
+                               //if there is a bin label use it otherwise make one
                        }
                        //else{  cout << "bin # " << i << " is all zeros" << endl;  }
                }
@@ -560,7 +565,7 @@ int SharedCommand::createMisMatchFile() {
                        
                        //go through list and if group returns "not found" output it
                        for (int i = 0; i < SharedList->getNumBins(); i++) {
-                               if (m->control_pressed) { outMisMatch.close(); remove(outputMisMatchName.c_str()); return 0; } 
+                               if (m->control_pressed) { outMisMatch.close(); m->mothurRemove(outputMisMatchName); return 0; } 
                        
                                string names = SharedList->get(i); 
                                
@@ -631,7 +636,7 @@ int SharedCommand::createMisMatchFile() {
                        
                        //loop through names in seqNames and if they aren't in namesIn list output them
                        for (int i = 0; i < seqNames.size(); i++) {
-                               if (m->control_pressed) { outMisMatch.close(); remove(outputMisMatchName.c_str()); return 0; } 
+                               if (m->control_pressed) { outMisMatch.close(); m->mothurRemove(outputMisMatchName); return 0; } 
                                
                                itMatch = namesInList.find(seqNames[i]);