]> git.donarmstrong.com Git - mothur.git/commitdiff
fixed bug in hcluster command
authorwestcott <westcott>
Tue, 24 Nov 2009 12:41:40 +0000 (12:41 +0000)
committerwestcott <westcott>
Tue, 24 Nov 2009 12:41:40 +0000 (12:41 +0000)
hclustercommand.cpp
nameassignment.hpp
readcluster.cpp
readcluster.h

index 38559500b0a81f25716b983b2274b88332e3ff56..dbc0e1bb9917b0d2cfdebfa83a5a97a17b6eb905 100644 (file)
@@ -21,7 +21,7 @@ HClusterCommand::HClusterCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"cutoff","precision","method","showabund","timing","phylip","column","name","sorted"};
+                       string Array[] =  {"cutoff","precision","method","phylip","column","name","sorted","showabund","timing"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -114,7 +114,7 @@ HClusterCommand::HClusterCommand(string option){
 
 void HClusterCommand::help(){
        try {
-               mothurOut("The hcluster command parameter options are cutoff, precision, method, showabund, timing, phylip, column, name and sorted. Phylip or column and name are required.\n");
+               mothurOut("The hcluster command parameter options are cutoff, precision, method, phylip, column, name, showabund, timing and sorted. Phylip or column and name are required.\n");
                mothurOut("The phylip and column parameter allow you to enter your distance file, and sorted indicates whether your column distance file is already sorted. \n");
                mothurOut("The name parameter allows you to enter your name file and is required if your distance file is in column format. \n");
                mothurOut("The hcluster command should be in the following format: \n");
@@ -161,7 +161,7 @@ int HClusterCommand::execute(){
        
                mothurOut("It took " + toString(time(NULL) - estart) + " seconds to sort. "); mothurOutEndLine();
                estart = time(NULL);
-               
+       
                //list vector made by read contains all sequence names
                if(list != NULL){
                        rabund = new RAbundVector(list->getRAbundVector());
@@ -177,7 +177,7 @@ int HClusterCommand::execute(){
                print_start = true;
                start = time(NULL);
                
-//cout << "here" << endl;      
+       
                ifstream in;
                openInputFile(distfile, in);
                string firstName, secondName;
@@ -187,7 +187,7 @@ int HClusterCommand::execute(){
                bool clusteredSomething;
                vector<seqDist> seqs; seqs.resize(1); // to start loop
                exitedBreak = false;  //lets you know if there is a distance stored in next
-               
+       
                while (seqs.size() != 0){
                
                        seqs = getSeqs(in);
@@ -205,12 +205,12 @@ int HClusterCommand::execute(){
                                        print_start = false;
                                }
                                
-       ///cout << "before cluster update" << endl;
+       //cout << "before cluster update" << endl;
                                if (seqs[i].seq1 != seqs[i].seq2) {
                                        clusteredSomething = cluster->update(seqs[i].seq1, seqs[i].seq2, seqs[i].dist);
                                        
                                        float rndDist = roundDist(seqs[i].dist, precision);
-                                       //cout << "after cluster update clusterSomething = " << clusteredSomething << " rndDist = " << rndDist << " rndPreviousDist = " << rndPreviousDist << endl;                     
+               //cout << "after cluster update clusterSomething = " << clusteredSomething << " rndDist = " << rndDist << " rndPreviousDist = " << rndPreviousDist << endl;                     
                                        
                                        
                                        if((previousDist <= 0.0000) && (seqs[i].dist != previousDist)){
@@ -325,7 +325,8 @@ vector<seqDist> HClusterCommand::getSeqs(ifstream& filehandle){
                        
                        //save first one
                        if (prevDistance == -1) { prevDistance = distance; }
-                       
+       //cout << prevDistance << endl; 
+//if (globaldata->nameMap == NULL) { cout << "null" << endl; }
                        map<string,int>::iterator itA = globaldata->nameMap->find(firstName);
                        map<string,int>::iterator itB = globaldata->nameMap->find(secondName);
                        
@@ -335,7 +336,7 @@ vector<seqDist> HClusterCommand::getSeqs(ifstream& filehandle){
                        if(itB == globaldata->nameMap->end()){
                                cerr << "ABError: Sequence '" << secondName << "' was not found in the names file, please correct\n"; exit(1);
                        }
-                       
+       //cout << "here" << endl;               
                        //using cutoff
                        if (distance > cutoff) { break; }
                        
index a9bf06b423c5a263f6e48722e4a125982c4385da..2470a84a630406eb8ecf61893398477b95c22c57 100644 (file)
@@ -7,6 +7,7 @@
 class NameAssignment : public map<string,int> {
 public:
        NameAssignment(string);
+       NameAssignment(){};
        void readMap();
        ListVector getListVector();
        int get(string);
index 50787e984bd2a3c45cbce0af354fea178771a6b0..233b8e13094cf560ef295522a7cd6a8d552dd55a 100644 (file)
@@ -12,6 +12,7 @@
 /***********************************************************************/
 
 ReadCluster::ReadCluster(string distfile, float c){
+               globaldata = GlobalData::getInstance();
         distFile = distfile;
                cutoff = c;
 }
@@ -185,24 +186,22 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
                        }
                }
                else{
-                       
                        for(int i=1;i<nseqs;i++){
                                in >> name;                
                                rowToName[i] = name;
                                matrixNames.push_back(name);
-                               
+               
                                if(nameMap == NULL){
                                        list->set(i, name);
                                        for(int j=0;j<nseqs;j++){
                                                in >> distance;
-                                               
+                                       
                                                if (distance == -1) { distance = 1000000; }
                                                
                                                if(distance < cutoff && j < i){
                                                        out << i << '\t' << j << '\t' << distance << endl;
                                                }
                                        }
-                                       
                                }
                                else{
                                        if(nameMap->count(name)==0){        mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); mothurOutEndLine(); }
@@ -226,11 +225,14 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
                out.close();
                
                if(nameMap == NULL){
+                       nameMap = new NameAssignment();
                        for(int i=0;i<matrixNames.size();i++){
                                nameMap->push_back(matrixNames[i]);
                        }
+                       globaldata->nameMap = nameMap;
                }
                
+       
                ifstream in2;
                ofstream out2;
                
index c81b1dd1b9f1684f54c70d666e1b3868076c1802..9e62e92aea46e04120c0992e12414d70b6207bba 100644 (file)
@@ -13,6 +13,7 @@
 #include "mothur.h"
 #include "nameassignment.hpp"
 #include "listvector.hpp"
+#include "globaldata.hpp"
 
 
 /******************************************************/
@@ -26,12 +27,15 @@ public:
        string getOutputFile() { return OutPutFile; }
        void setFormat(string f) { format = f;  }
        ListVector* getListVector()             {       return list;    }
+       //NameAssignment* getNameMap()  {       return nameMap; }
        
 private:
+       GlobalData* globaldata;
        string distFile;
        string OutPutFile, format;
        ListVector* list;
        float cutoff;
+       //NameAssignment* nameMap;
        
        void createHClusterFile();
        void convertPhylip2Column(NameAssignment*);