]> git.donarmstrong.com Git - mothur.git/blobdiff - readcluster.cpp
precluster command finished
[mothur.git] / readcluster.cpp
index 233b8e13094cf560ef295522a7cd6a8d552dd55a..11b8d012a22e592d99bb71e3063c0c89a710252a 100644 (file)
@@ -25,7 +25,7 @@ void ReadCluster::read(NameAssignment* nameMap){
                if (format == "phylip") { convertPhylip2Column(nameMap); }
                else { list = new ListVector(nameMap->getListVector());  }
                
-               createHClusterFile();
+               OutPutFile = sortFile(distFile);
                        
        }
        catch(exception& e) {
@@ -35,71 +35,6 @@ void ReadCluster::read(NameAssignment* nameMap){
 }
 /***********************************************************************/
 
-void ReadCluster::createHClusterFile(){
-       try {   
-               string outfile = getRootName(distFile) + "sorted.dist";
-               
-               //if you can, use the unix sort since its been optimized for years
-               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
-                       string command = "sort -n -k +3 " + distFile + " -o " + outfile;
-                       system(command.c_str());
-               #else //you are stuck with my best attempt...
-                       //windows sort does not have a way to specify a column, only a character in the line
-                       //since we cannot assume that the distance will always be at the the same character location on each line
-                       //due to variable sequence name lengths, I chose to force the distance into first position, then sort and then put it back.
-               
-                       //read in file line by file and put distance first
-                       string tempDistFile = distFile + ".temp";
-                       ifstream input;
-                       ofstream output;
-                       openInputFile(distFile, input);
-                       openOutputFile(tempDistFile, output);
-
-                       string firstName, secondName;
-                       float dist;
-                       while (input) {
-                               input >> firstName >> secondName >> dist;
-                               output << dist << '\t' << firstName << '\t' << secondName << endl;
-                               gobble(input);
-                       }
-                       input.close();
-                       output.close();
-               
-       
-                       //sort using windows sort
-                       string tempOutfile = outfile + ".temp";
-                       string command = "sort " + tempDistFile + " /O " + tempOutfile;
-                       system(command.c_str());
-               
-                       //read in sorted file and put distance at end again
-                       ifstream input2;
-                       openInputFile(tempOutfile, input2);
-                       openOutputFile(outfile, output);
-               
-                       while (input2) {
-                               input2 >> dist >> firstName >> secondName;
-                               output << firstName << '\t' << secondName << '\t' << dist << endl;
-                               gobble(input2);
-                       }
-                       input2.close();
-                       output.close();
-               
-                       //remove temp files
-                       remove(tempDistFile.c_str());
-                       remove(tempOutfile.c_str());
-               #endif
-               
-               OutPutFile = outfile;
-       }
-       catch(exception& e) {
-               errorOut(e, "ReadCluster", "createHClusterFile");
-               exit(1);
-       }
-}
-
-
-/***********************************************************************/
-
 void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
        try {   
                //convert phylip file to column file