]> git.donarmstrong.com Git - mothur.git/blobdiff - subsamplecommand.cpp
fixed get.lienage and remove.lineage bug with confidence scores that are floats....
[mothur.git] / subsamplecommand.cpp
index 6b0e4f991f01f7d3a6e323f2670819e00ded79f9..d24bcc5ad616b324b444f929ec3be57716dd05de 100644 (file)
@@ -295,7 +295,44 @@ int SubSampleCommand::execute(){
                if (fastafile != "")    {   getSubSampleFasta();        }
                if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str()); return 0; } }
                        
-                               
+               //set fasta file as new current fastafile
+               string current = "";
+               itTypes = outputTypes.find("fasta");
+               if (itTypes != outputTypes.end()) {
+                       if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
+               }
+               
+               itTypes = outputTypes.find("name");
+               if (itTypes != outputTypes.end()) {
+                       if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setNameFile(current); }
+               }
+               
+               itTypes = outputTypes.find("group");
+               if (itTypes != outputTypes.end()) {
+                       if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setGroupFile(current); }
+               }
+               
+               itTypes = outputTypes.find("list");
+               if (itTypes != outputTypes.end()) {
+                       if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setListFile(current); }
+               }
+               
+               itTypes = outputTypes.find("shared");
+               if (itTypes != outputTypes.end()) {
+                       if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSharedFile(current); }
+               }
+               
+               itTypes = outputTypes.find("rabund");
+               if (itTypes != outputTypes.end()) {
+                       if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setRabundFile(current); }
+               }
+               
+               itTypes = outputTypes.find("sabund");
+               if (itTypes != outputTypes.end()) {
+                       if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSabundFile(current); }
+               }
+               
+               
                m->mothurOutEndLine();
                m->mothurOut("Output File Names: "); m->mothurOutEndLine();
                for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
@@ -413,7 +450,7 @@ int SubSampleCommand::getSubSampleFasta() {
                                        bool done = false;
                                        int myrand;
                                        while (!done) {
-                                               myrand = (int)((float)(rand()) / (RAND_MAX / (thisSize-1) + 1));
+                                               myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0));
                                                
                                                if (subset.count(names[myrand]) == 0)  { 
                                                        
@@ -426,6 +463,7 @@ int SubSampleCommand::getSubSampleFasta() {
                                }
                        }
                }else {
+                       
                        //randomly select a subset of those names to include in the subsample
                        for (int j = 0; j < size; j++) {
                                
@@ -435,7 +473,7 @@ int SubSampleCommand::getSubSampleFasta() {
                                bool done = false;
                                int myrand;
                                while (!done) {
-                                       myrand = (int)((float)(rand()) / (RAND_MAX / (thisSize-1) + 1));
+                                       myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0));
                                        
                                        if (subset.count(names[myrand]) == 0)  { 
                                                
@@ -762,7 +800,7 @@ int SubSampleCommand::processShared(vector<SharedRAbundVector*>& thislookup, ofs
                                        if (m->control_pressed) { delete order; return 0; }
                                        
                                        //get random number to sample from order between 0 and thisSize-1.
-                                       int myrand = (int)((float)(rand()) / (RAND_MAX / (thisSize-1) + 1));
+                                       int myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0));
                                        
                                        int bin = order->get(myrand);
                                        
@@ -959,7 +997,7 @@ int SubSampleCommand::getSubSampleList() {
                                        bool done = false;
                                        int myrand;
                                        while (!done) {
-                                               myrand = (int)((float)(rand()) / (RAND_MAX / (names.size()-1) + 1));
+                                               myrand = int((float)(names.size()) * (float)(rand()) / ((float)RAND_MAX+1.0));
                                                
                                                if (subset.count(names[myrand]) == 0) { //you are not already added
                                                        if (groupMap->getGroup(names[myrand]) == Groups[i])  { subset.insert(names[myrand]); break;     }
@@ -976,7 +1014,7 @@ int SubSampleCommand::getSubSampleList() {
                                bool done = false;
                                int myrand;
                                while (!done) {
-                                       myrand = (int)((float)(rand()) / (RAND_MAX / (names.size()-1) + 1));
+                                       myrand = int((float)(names.size()) * (float)(rand()) / ((float)RAND_MAX+1.0));
                                        
                                        if (subset.count(names[myrand]) == 0)  { subset.insert(names[myrand]); break;   }
                                }
@@ -1262,7 +1300,7 @@ int SubSampleCommand::processRabund(RAbundVector*& rabund, ofstream& out) {
                                if (m->control_pressed) { delete order; return 0; }
                                
                                //get random number to sample from order between 0 and thisSize-1.
-                               int myrand = (int)((float)(rand()) / (RAND_MAX / (thisSize-1) + 1));
+                               int myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0));
                                
                                int bin = order->get(myrand);
                                
@@ -1422,7 +1460,7 @@ int SubSampleCommand::processSabund(SAbundVector*& sabund, ofstream& out) {
                                if (m->control_pressed) { delete order; return 0; }
                                
                                //get random number to sample from order between 0 and thisSize-1.
-                               int myrand = (int)((float)(rand()) / (RAND_MAX / (thisSize-1) + 1));
+                               int myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0));
                                
                                int bin = order->get(myrand);