]> git.donarmstrong.com Git - mothur.git/commitdiff
changes to dist.seqs and pairwise.seqs and cluster.classic no longer resizes
authorwestcott <westcott>
Mon, 8 Nov 2010 14:40:33 +0000 (14:40 +0000)
committerwestcott <westcott>
Mon, 8 Nov 2010 14:40:33 +0000 (14:40 +0000)
clusterclassic.cpp
distancecommand.cpp
distancecommand.h
mothur
mothur.h
pairwiseseqscommand.cpp
pairwiseseqscommand.h
screenseqscommand.cpp

index 0e48690dc57059bb2ab1af1df3da5df0ea71efa4..287332ad628e33a6a460aee903ba8f7955027c85 100644 (file)
@@ -279,10 +279,10 @@ void ClusterClassic::clusterBins(){
 
                rabund->set(smallRow, rabund->get(smallRow)+rabund->get(smallCol));     
                rabund->set(smallCol, 0);       
-               for (int i = smallCol+1; i < rabund->size(); i++) {
+               /*for (int i = smallCol+1; i < rabund->size(); i++) {
                        rabund->set((i-1), rabund->get(i));
                }
-               rabund->resize((rabund->size()-1));
+               rabund->resize((rabund->size()-1));*/
                rabund->setLabel(toString(smallDist));
 
        //      cout << '\t' << rabund->get(smallRow) << '\t' << rabund->get(smallCol) << endl;
@@ -300,10 +300,10 @@ void ClusterClassic::clusterNames(){
                
                list->set(smallRow, list->get(smallRow)+','+list->get(smallCol));
                list->set(smallCol, "");        
-               for (int i = smallCol+1; i < list->size(); i++) {
+               /*for (int i = smallCol+1; i < list->size(); i++) {
                        list->set((i-1), list->get(i));
                }
-               list->resize((list->size()-1));
+               list->resize((list->size()-1));*/
                list->setLabel(toString(smallDist));
        
        //      cout << '\t' << list->get(smallRow) << '\t' << list->get(smallCol) << endl;
@@ -356,7 +356,7 @@ void ClusterClassic::update(double& cutOFF){
                clusterNames();
                
                //resize each row
-               for(int i=0;i<nseqs;i++){
+               /*for(int i=0;i<nseqs;i++){
                        for(int j=c+1;j<dMatrix[i].size();j++){
                                dMatrix[i][j-1]=dMatrix[i][j];
                        }
@@ -370,7 +370,7 @@ void ClusterClassic::update(double& cutOFF){
                }       
                
                nseqs--;
-               dMatrix.pop_back();
+               dMatrix.pop_back();*/
 
        }
        catch(exception& e) {
index 70c0a7806c2902b73f20601ff1fda5b330aa8c10..cf7939ca233ff2a150e1c7589baed81d151d54d7 100644 (file)
@@ -14,6 +14,7 @@
 #include "onegapdist.h"
 #include "onegapignore.h"
 
+
 //**********************************************************************************************************************
 vector<string> DistanceCommand::getValidParameters(){  
        try {
@@ -210,13 +211,7 @@ DistanceCommand::DistanceCommand(string option) {
 
 //**********************************************************************************************************************
 
-DistanceCommand::~DistanceCommand(){
-       
-       for(int i=0;i<lines.size();i++){
-               delete lines[i];
-       }
-       
-}
+DistanceCommand::~DistanceCommand(){}
        
 //**********************************************************************************************************************
 
@@ -439,17 +434,18 @@ int DistanceCommand::execute(){
                        if (numDists < processors) { processors = numDists; }
                        
                        for (int i = 0; i < processors; i++) {
-                               lines.push_back(new linePair());
+                               distlinePair tempLine;
+                               lines.push_back(tempLine);
                                if (output != "square") {
-                                       lines[i]->start = int (sqrt(float(i)/float(processors)) * numSeqs);
-                                       lines[i]->end = int (sqrt(float(i+1)/float(processors)) * numSeqs);
+                                       lines[i].start = int (sqrt(float(i)/float(processors)) * numSeqs);
+                                       lines[i].end = int (sqrt(float(i+1)/float(processors)) * numSeqs);
                                }else{
-                                       lines[i]->start = int ((float(i)/float(processors)) * numSeqs);
-                                       lines[i]->end = int ((float(i+1)/float(processors)) * numSeqs);
+                                       lines[i].start = int ((float(i)/float(processors)) * numSeqs);
+                                       lines[i].end = int ((float(i+1)/float(processors)) * numSeqs);
                                }
-                               //cout << i << '\t' << lines[i]->start << '\t' << lines[i]->end << endl;
+                               
                        }
-
+                       
                        createProcesses(outputFile); 
                }
        #else
@@ -543,8 +539,8 @@ void DistanceCommand::createProcesses(string filename) {
                                processIDS.push_back(pid);  //create map from line number to pid so you can append files in correct order later
                                process++;
                        }else if (pid == 0){
-                               if (output != "square") {  driver(lines[process]->start, lines[process]->end, filename + toString(getpid()) + ".temp", cutoff); }
-                               else { driver(lines[process]->start, lines[process]->end, filename + toString(getpid()) + ".temp", "square"); }
+                               if (output != "square") {  driver(lines[process].start, lines[process].end, filename + toString(getpid()) + ".temp", cutoff); }
+                               else { driver(lines[process].start, lines[process].end, filename + toString(getpid()) + ".temp", "square"); }
                                exit(0);
                        }else { 
                                m->mothurOut("[ERROR]: unable to spawn the necessary processes. Error code: " + toString(pid)); m->mothurOutEndLine(); 
@@ -555,8 +551,8 @@ void DistanceCommand::createProcesses(string filename) {
                }
                
                //parent does its part
-               if (output != "square") {  driver(lines[0]->start, lines[0]->end, filename, cutoff); }
-               else { driver(lines[0]->start, lines[0]->end, filename, "square"); }
+               if (output != "square") {  driver(lines[0].start, lines[0].end, filename, cutoff); }
+               else { driver(lines[0].start, lines[0].end, filename, "square"); }
                
                
                //force parent to wait until all the processes are done
@@ -1157,7 +1153,7 @@ bool DistanceCommand::sanityCheck() {
                
        }
        catch(exception& e) {
-               m->errorOut(e, "DistanceCommand", "m->appendFiles");
+               m->errorOut(e, "DistanceCommand", "sanityCheck");
                exit(1);
        }
 }
index 3e3dc7098a768461c67dc1d45751e50891ccc9c2..595483d2b3e84aef55478a78bd84906771949e5d 100644 (file)
@@ -31,9 +31,10 @@ public:
        void help();
        
 private:
-       struct linePair {
+       struct distlinePair {
                int start;
                int end;
+               
        };
        
        Dist* distCalculator;
@@ -44,7 +45,7 @@ private:
        int processors, numNewFasta;
        float cutoff;
        vector<int> processIDS;   //end line, processid
-       vector<linePair*> lines;
+       vector<distlinePair> lines;
        
        bool abort;
        vector<string>  Estimators, outputNames; //holds estimators to be used
diff --git a/mothur b/mothur
index 607932c98a801c4a3a026780c00eb011c9471e1e..e33ddcdab4f21edda480caba41e96a0e983028dc 100755 (executable)
Binary files a/mothur and b/mothur differ
index bfe0692cf035a8c96a933da2ce70ced46ca98429..337e5b33a6b1d8100effe484c230d42c7fd93f58 100644 (file)
--- a/mothur.h
+++ b/mothur.h
@@ -116,6 +116,17 @@ struct seqDist {
        seqDist(int s1, int s2, float d) : seq1(s1), seq2(s2), dist(d) {}
        ~seqDist() {}
 };
+/************************************************************/
+struct distlinePair {
+       int start;
+       int end;
+       
+};
+/************************************************************/
+//sorts lowest to highest
+inline bool compareDistLinePairs(distlinePair left, distlinePair right){
+       return (left.end < right.end);  
+} 
 //********************************************************************************************************************
 //sorts lowest to highest
 inline bool compareSequenceDistance(seqDist left, seqDist right){
index 18412fdeac778159551d32e8573edd1dddc321bf..f261dd91ff256f953fed82114e42e3d79ff7f5cc 100644 (file)
@@ -442,27 +442,18 @@ int PairwiseSeqsCommand::execute(){
                        }else{ //you have multiple processors
                                
                                for (int i = 0; i < processors; i++) {
-                                       lines.push_back(new linePair());
+                                       distlinePair tempLine;
+                                       lines.push_back(tempLine);
                                        if (output != "square") {
-                                               lines[i]->start = int (sqrt(float(i)/float(processors)) * numSeqs);
-                                               lines[i]->end = int (sqrt(float(i+1)/float(processors)) * numSeqs);
+                                               lines[i].start = int (sqrt(float(i)/float(processors)) * numSeqs);
+                                               lines[i].end = int (sqrt(float(i+1)/float(processors)) * numSeqs);
                                        }else{
-                                               lines[i]->start = int ((float(i)/float(processors)) * numSeqs);
-                                               lines[i]->end = int ((float(i+1)/float(processors)) * numSeqs);
+                                               lines[i].start = int ((float(i)/float(processors)) * numSeqs);
+                                               lines[i].end = int ((float(i+1)/float(processors)) * numSeqs);
                                        }
                                }
-
-                               createProcesses(outputFile); 
-                       
-                               map<int, int>::iterator it = processIDS.begin();
-                               rename((outputFile + toString(it->second) + ".temp").c_str(), outputFile.c_str());
-                               it++;
                                
-                               //append and remove temp files
-                               for (; it != processIDS.end(); it++) {
-                                       m->appendFiles((outputFile + toString(it->second) + ".temp"), outputFile);
-                                       remove((outputFile + toString(it->second) + ".temp").c_str());
-                               }
+                               createProcesses(outputFile); 
                        }
                #else
                        //ifstream inFASTA;
@@ -522,7 +513,7 @@ int PairwiseSeqsCommand::execute(){
 void PairwiseSeqsCommand::createProcesses(string filename) {
        try {
 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
-               int process = 0;
+               int process = 1;
                processIDS.clear();
                
                //loop through and create all the processes you want
@@ -530,24 +521,35 @@ void PairwiseSeqsCommand::createProcesses(string filename) {
                        int pid = fork();
                        
                        if (pid > 0) {
-                               processIDS[lines[process]->end] = pid;  //create map from line number to pid so you can append files in correct order later
+                               processIDS.push_back(pid); 
                                process++;
                        }else if (pid == 0){
-                               if (output != "square") {  driver(lines[process]->start, lines[process]->end, filename + toString(getpid()) + ".temp", cutoff); }
-                               else { driver(lines[process]->start, lines[process]->end, filename + toString(getpid()) + ".temp", "square"); }
+                               if (output != "square") {  driver(lines[process].start, lines[process].end, filename + toString(getpid()) + ".temp", cutoff); }
+                               else { driver(lines[process].start, lines[process].end, filename + toString(getpid()) + ".temp", "square"); }
                                exit(0);
                        }else { 
                                m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); 
-                               for (map<int, int>::iterator it = processIDS.begin(); it != processIDS.end(); it++) { int temp = it->second; kill (temp, SIGINT); }
+                               for (int i=0;i<processIDS.size();i++) { int temp = processIDS[i]; kill (temp, SIGINT); }
                                exit(0);
                        }
                }
-       
+               
+               //parent do my part
+               if (output != "square") {  driver(lines[0].start, lines[0].end, filename, cutoff); }
+               else { driver(lines[0].start, lines[0].end, filename, "square"); }
+
+               
                //force parent to wait until all the processes are done
-               for (map<int, int>::iterator it = processIDS.begin(); it != processIDS.end(); it++) { 
-                       int temp = it->second;
+               for (int i=0;i<processIDS.size();i++) { 
+                       int temp = processIDS[i];
                        wait(&temp);
                }
+               
+               //append and remove temp files
+               for (int i=0;i<processIDS.size();i++) { 
+                       m->appendFiles((filename + toString(processIDS[i]) + ".temp"), filename);
+                       remove((filename + toString(processIDS[i]) + ".temp").c_str());
+               }
 #endif
        }
        catch(exception& e) {
index b40d6c97ea10bbc708ddc2c4985be7b960843fab..cf73f3e82a2c0bd59bfff9fad48ee4628a2b1917 100644 (file)
@@ -32,12 +32,14 @@ public:
        void help();    
        
 private:
-       struct linePair {
+       struct distlinePair {
                int start;
                int end;
        };
-       map<int, int> processIDS;   //end line, processid
-       vector<linePair*> lines;
+       
+       
+       vector<int> processIDS;   //end line, processid
+       vector<distlinePair> lines;
        map<string, vector<string> > outputTypes;
        
        Alignment* alignment;
index 98b6681d5091ffbb30b80172c0a36d12a531d130..bdc665881fca22a7451d691812889572430724af 100644 (file)
@@ -507,13 +507,13 @@ int ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
                outputNames.push_back(goodNameFile);  outputTypes["name"].push_back(goodNameFile);
                
                ofstream goodNameOut;   m->openOutputFile(goodNameFile, goodNameOut);
-       
+               
                while(!inputNames.eof()){
                        if (m->control_pressed) { goodNameOut.close();  inputNames.close(); remove(goodNameFile.c_str());  return 0; }
 
                        inputNames >> seqName >> seqList;
                        it = badSeqNames.find(seqName);
-                       
+                               
                        if(it != badSeqNames.end()){
                                badSeqNames.erase(it);
                                
@@ -558,7 +558,7 @@ int ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
                                if (m->control_pressed) { goodGroupOut.close(); inputGroups.close(); remove(goodNameFile.c_str());  remove(goodGroupFile.c_str()); return 0; }
 
                                inputGroups >> seqName >> group;
-
+                               
                                it = badSeqGroups.find(seqName);
                                
                                if(it != badSeqGroups.end()){
@@ -580,7 +580,8 @@ int ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
                                }
                        }
                }
-                       
+               
+               
                return 0;
        
        }